COMMON: Add "getPathSeparator" to Archive and return ":" for Mac archive formats

This commit is contained in:
elasota 2023-05-29 16:15:54 -04:00 committed by Filippos Karapetis
parent 7be3c8f602
commit e53d2ec594
4 changed files with 28 additions and 4 deletions

View file

@ -103,6 +103,10 @@ void Archive::dumpArchive(String destPath) {
free(data); free(data);
} }
char Archive::getPathSeparator() const {
return '/';
}
SeekableReadStream *MemcachingCaseInsensitiveArchive::createReadStreamForMember(const Path &path) const { SeekableReadStream *MemcachingCaseInsensitiveArchive::createReadStreamForMember(const Path &path) const {
String translated = translatePath(path); String translated = translatePath(path);
bool isNew = false; bool isNew = false;

View file

@ -155,6 +155,11 @@ public:
* Dump all files from the archive to the given directory * Dump all files from the archive to the given directory
*/ */
void dumpArchive(String destPath); void dumpArchive(String destPath);
/**
* Returns the separator used by internal paths in the archive
*/
virtual char getPathSeparator() const;
}; };
class MemcachingCaseInsensitiveArchive; class MemcachingCaseInsensitiveArchive;

View file

@ -53,9 +53,8 @@ public:
int listMembers(Common::ArchiveMemberList &list) const override; int listMembers(Common::ArchiveMemberList &list) const override;
const Common::ArchiveMemberPtr getMember(const Common::Path &path) const override; const Common::ArchiveMemberPtr getMember(const Common::Path &path) const override;
Common::SharedArchiveContents readContentsForPath(const Common::String& name) const override; Common::SharedArchiveContents readContentsForPath(const Common::String& name) const override;
Common::String translatePath(const Common::Path &path) const override { Common::String translatePath(const Common::Path &path) const override;
return path.toString(':'); char getPathSeparator() const override;
}
private: private:
struct FileEntry { struct FileEntry {
@ -74,6 +73,8 @@ private:
typedef Common::HashMap<Common::String, Common::MacFinderInfoData, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo> MetadataMap; typedef Common::HashMap<Common::String, Common::MacFinderInfoData, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo> MetadataMap;
MetadataMap _metadataMap; MetadataMap _metadataMap;
bool _flattenTree;
// Decompression Functions // Decompression Functions
bool decompress13(Common::SeekableReadStream *src, byte *dst, uint32 uncompressedSize) const; bool decompress13(Common::SeekableReadStream *src, byte *dst, uint32 uncompressedSize) const;
void decompress14(Common::SeekableReadStream *src, byte *dst, uint32 uncompressedSize) const; void decompress14(Common::SeekableReadStream *src, byte *dst, uint32 uncompressedSize) const;
@ -83,7 +84,7 @@ private:
void readTree14(Common::BitStream8LSB *bits, SIT14Data *dat, uint16 codesize, uint16 *result) const; void readTree14(Common::BitStream8LSB *bits, SIT14Data *dat, uint16 codesize, uint16 *result) const;
}; };
StuffItArchive::StuffItArchive() : Common::MemcachingCaseInsensitiveArchive() { StuffItArchive::StuffItArchive() : Common::MemcachingCaseInsensitiveArchive(), _flattenTree(false) {
_stream = nullptr; _stream = nullptr;
} }
@ -108,6 +109,7 @@ bool StuffItArchive::open(Common::SeekableReadStream *stream, bool flattenTree)
close(); close();
_stream = stream; _stream = stream;
_flattenTree = flattenTree;
if (!_stream) if (!_stream)
return false; return false;
@ -325,6 +327,14 @@ Common::SharedArchiveContents StuffItArchive::readContentsForPath(const Common::
return Common::SharedArchiveContents(uncompressedBlock, entry.uncompressedSize); return Common::SharedArchiveContents(uncompressedBlock, entry.uncompressedSize);
} }
Common::String StuffItArchive::translatePath(const Common::Path &path) const {
return _flattenTree ? path.getLastComponent().toString() : path.toString(':');
}
char StuffItArchive::getPathSeparator() const {
return ':';
}
void StuffItArchive::update14(uint16 first, uint16 last, byte *code, uint16 *freq) const { void StuffItArchive::update14(uint16 first, uint16 last, byte *code, uint16 *freq) const {
uint16 i, j; uint16 i, j;

View file

@ -94,6 +94,7 @@ public:
int listMembers(Common::ArchiveMemberList &list) const override; int listMembers(Common::ArchiveMemberList &list) const override;
const Common::ArchiveMemberPtr getMember(const Common::Path &path) const override; const Common::ArchiveMemberPtr getMember(const Common::Path &path) const override;
Common::SeekableReadStream *createReadStreamForMember(const Common::Path &path) const override; Common::SeekableReadStream *createReadStreamForMember(const Common::Path &path) const override;
char getPathSeparator() const override;
private: private:
bool getFileDescIndex(const Common::Path &path, uint &outIndex, ArchiveMember::SubstreamType &outSubstreamType) const; bool getFileDescIndex(const Common::Path &path, uint &outIndex, ArchiveMember::SubstreamType &outSubstreamType) const;
@ -390,6 +391,10 @@ Common::SeekableReadStream *MacVISEArchive::createReadStreamForMember(const Comm
return archiveMember->createReadStream(); return archiveMember->createReadStream();
} }
char MacVISEArchive::getPathSeparator() const {
return ':';
}
bool MacVISEArchive::getFileDescIndex(const Common::Path &path, uint &outIndex, ArchiveMember::SubstreamType &outSubstreamType) const { bool MacVISEArchive::getFileDescIndex(const Common::Path &path, uint &outIndex, ArchiveMember::SubstreamType &outSubstreamType) const {
Common::String convertedPath = path.toString(':'); Common::String convertedPath = path.toString(':');
ArchiveMember::SubstreamType substreamType = ArchiveMember::kSubstreamTypeData; ArchiveMember::SubstreamType substreamType = ArchiveMember::kSubstreamTypeData;