Skip to content

Commit

Permalink
COMMON: fix MacResManager native resource forks
Browse files Browse the repository at this point in the history
These broke in the archive refactor,
b8acbe6/#5108, because it removed
the ability to directly convert an `ArchiveMember` to an `FSNode`.
As a result, it was no longer possible to directly open a resource
fork as a stream.
  • Loading branch information
mistydemeo authored and sev- committed Jul 27, 2023
1 parent 39a496d commit b975da2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
12 changes: 12 additions & 0 deletions common/fs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,18 @@ void FSDirectory::cacheDirectoryRecursive(FSNode node, int depth, const Path& pr
}
} else {
_fileCache[name] = *it;

#ifdef MACOSX
// On Mac, check for native resource fork
String rsrcName = it->getPath() + "/..namedfork/rsrc";
FSNode rsrc = FSNode(rsrcName);

Path cacheName = prefix.join(it->getRealName() + "/..namedfork/rsrc");

if (rsrc.exists()) {
_fileCache[cacheName] = rsrc;
}
#endif
}
}
}
Expand Down
8 changes: 3 additions & 5 deletions common/macresman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,7 @@ bool MacResManager::open(const Path &fileName, Archive &archive) {
// Check the actual fork on a Mac computer. It's even worse than __MACOSX as
// it's present on any HFS(+) and appears even after copying macbin on HFS(+).
const ArchiveMemberPtr archiveMember = archive.getMember(fileName);
const Common::FSNode *plainFsNode = dynamic_cast<const Common::FSNode *>(archiveMember.get());
if (plainFsNode) {
if (archiveMember.get()) {
// This could be a MacBinary file that still has a
// resource fork; if it is, it needs to get opened as MacBinary
// and not treated as raw.
Expand All @@ -286,9 +285,8 @@ bool MacResManager::open(const Path &fileName, Archive &archive) {
}
delete stream;

String fullPath = plainFsNode->getPath() + "/..namedfork/rsrc";
FSNode resFsNode = FSNode(fullPath);
SeekableReadStream *macResForkRawStream = resFsNode.createReadStream();
Path fullPath = archiveMember.get()->getPathInArchive().join("/..namedfork/rsrc");
SeekableReadStream *macResForkRawStream = archive.createReadStreamForMember(fullPath);
if (!isMacBinaryFile && macResForkRawStream && loadFromRawFork(macResForkRawStream)) {
_baseFileName = fileName;
return true;
Expand Down

0 comments on commit b975da2

Please sign in to comment.