mirror of
https://github.com/libretro/scummvm.git
synced 2025-01-23 19:16:21 +00:00
ENGINES: Change mac resource fork file detection to use the file cache
Common::MacResMan is now able to open files from a specified Common::Archive. This is a bit hacky as dynamic_cast is used to break the Archive encapsulation to retreive the underlying FSNode. It should however be more correct than the previous code that assumed files were at the root of the currently running game's path. AdvancedDetector constructs a Common::Archive from its FileMap based filesystem cache and uses it to detect the mac resource fork files. This cuts the time it takes to run the detection code with all the engines enabled as dynamic plugins on the 3DS to 30 s from 280 s.
This commit is contained in:
parent
9a1e2368b2
commit
0f2c6cd9ea
@ -116,15 +116,20 @@ String MacResManager::computeResForkMD5AsString(uint32 length) const {
|
||||
}
|
||||
|
||||
bool MacResManager::open(const String &fileName) {
|
||||
return open(fileName, SearchMan);
|
||||
}
|
||||
|
||||
bool MacResManager::open(const String &fileName, Archive &archive) {
|
||||
close();
|
||||
|
||||
#ifdef MACOSX
|
||||
// Check the actual fork on a Mac computer
|
||||
String fullPath = ConfMan.get("path") + "/" + fileName + "/..namedfork/rsrc";
|
||||
FSNode resFsNode = FSNode(fullPath);
|
||||
if (resFsNode.exists()) {
|
||||
const ArchiveMemberPtr archiveMember = archive.getMember(fileName);
|
||||
const Common::FSNode *plainFsNode = dynamic_cast<const Common::FSNode *>(archiveMember.get());
|
||||
if (plainFsNode) {
|
||||
String fullPath = plainFsNode->getPath() + "/..namedfork/rsrc";
|
||||
FSNode resFsNode = FSNode(fullPath);
|
||||
SeekableReadStream *macResForkRawStream = resFsNode.createReadStream();
|
||||
|
||||
if (macResForkRawStream && loadFromRawFork(*macResForkRawStream)) {
|
||||
_baseFileName = fileName;
|
||||
return true;
|
||||
@ -134,111 +139,37 @@ bool MacResManager::open(const String &fileName) {
|
||||
}
|
||||
#endif
|
||||
|
||||
File *file = new File();
|
||||
|
||||
// Prefer standalone files first, starting with raw forks
|
||||
if (file->open(fileName + ".rsrc") && loadFromRawFork(*file)) {
|
||||
SeekableReadStream *stream = archive.createReadStreamForMember(fileName + ".rsrc");
|
||||
if (stream && loadFromRawFork(*stream)) {
|
||||
_baseFileName = fileName;
|
||||
return true;
|
||||
}
|
||||
file->close();
|
||||
delete stream;
|
||||
|
||||
// Then try for AppleDouble using Apple's naming
|
||||
if (file->open(constructAppleDoubleName(fileName)) && loadFromAppleDouble(*file)) {
|
||||
stream = archive.createReadStreamForMember(constructAppleDoubleName(fileName));
|
||||
if (stream && loadFromAppleDouble(*stream)) {
|
||||
_baseFileName = fileName;
|
||||
return true;
|
||||
}
|
||||
file->close();
|
||||
delete stream;
|
||||
|
||||
// Check .bin for MacBinary next
|
||||
if (file->open(fileName + ".bin") && loadFromMacBinary(*file)) {
|
||||
stream = archive.createReadStreamForMember(fileName + ".bin");
|
||||
if (stream && loadFromMacBinary(*stream)) {
|
||||
_baseFileName = fileName;
|
||||
return true;
|
||||
}
|
||||
file->close();
|
||||
delete stream;
|
||||
|
||||
// As a last resort, see if just the data fork exists
|
||||
if (file->open(fileName)) {
|
||||
stream = archive.createReadStreamForMember(fileName);
|
||||
if (stream) {
|
||||
_baseFileName = fileName;
|
||||
|
||||
// Maybe file is in MacBinary but without .bin extension?
|
||||
// Check it here
|
||||
if (isMacBinary(*file)) {
|
||||
file->seek(0);
|
||||
if (loadFromMacBinary(*file))
|
||||
return true;
|
||||
}
|
||||
|
||||
file->seek(0);
|
||||
_stream = file;
|
||||
return true;
|
||||
}
|
||||
|
||||
delete file;
|
||||
|
||||
// The file doesn't exist
|
||||
return false;
|
||||
}
|
||||
|
||||
bool MacResManager::open(const FSNode &path, const String &fileName) {
|
||||
close();
|
||||
|
||||
#ifdef MACOSX
|
||||
// Check the actual fork on a Mac computer
|
||||
String fullPath = path.getPath() + "/" + fileName + "/..namedfork/rsrc";
|
||||
FSNode resFsNode = FSNode(fullPath);
|
||||
if (resFsNode.exists()) {
|
||||
SeekableReadStream *macResForkRawStream = resFsNode.createReadStream();
|
||||
|
||||
if (macResForkRawStream && loadFromRawFork(*macResForkRawStream)) {
|
||||
_baseFileName = fileName;
|
||||
return true;
|
||||
}
|
||||
|
||||
delete macResForkRawStream;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Prefer standalone files first, starting with raw forks
|
||||
FSNode fsNode = path.getChild(fileName + ".rsrc");
|
||||
if (fsNode.exists() && !fsNode.isDirectory()) {
|
||||
SeekableReadStream *stream = fsNode.createReadStream();
|
||||
if (loadFromRawFork(*stream)) {
|
||||
_baseFileName = fileName;
|
||||
return true;
|
||||
}
|
||||
delete stream;
|
||||
}
|
||||
|
||||
// Then try for AppleDouble using Apple's naming
|
||||
fsNode = path.getChild(constructAppleDoubleName(fileName));
|
||||
if (fsNode.exists() && !fsNode.isDirectory()) {
|
||||
SeekableReadStream *stream = fsNode.createReadStream();
|
||||
if (loadFromAppleDouble(*stream)) {
|
||||
_baseFileName = fileName;
|
||||
return true;
|
||||
}
|
||||
delete stream;
|
||||
}
|
||||
|
||||
// Check .bin for MacBinary next
|
||||
fsNode = path.getChild(fileName + ".bin");
|
||||
if (fsNode.exists() && !fsNode.isDirectory()) {
|
||||
SeekableReadStream *stream = fsNode.createReadStream();
|
||||
if (loadFromMacBinary(*stream)) {
|
||||
_baseFileName = fileName;
|
||||
return true;
|
||||
}
|
||||
delete stream;
|
||||
}
|
||||
|
||||
// As a last resort, see if just the data fork exists
|
||||
fsNode = path.getChild(fileName);
|
||||
if (fsNode.exists() && !fsNode.isDirectory()) {
|
||||
SeekableReadStream *stream = fsNode.createReadStream();
|
||||
_baseFileName = fileName;
|
||||
|
||||
// FIXME: Is this really needed?
|
||||
if (isMacBinary(*stream)) {
|
||||
stream->seek(0);
|
||||
if (loadFromMacBinary(*stream))
|
||||
|
@ -68,14 +68,14 @@ public:
|
||||
bool open(const String &fileName);
|
||||
|
||||
/**
|
||||
* Open a Mac data/resource fork pair.
|
||||
* Open a Mac data/resource fork pair from within the given archive.
|
||||
*
|
||||
* @param path The path that holds the forks
|
||||
* @param fileName The base file name of the file
|
||||
* @note This will check for the raw resource fork, MacBinary, and AppleDouble formats.
|
||||
* @return True on success
|
||||
*/
|
||||
bool open(const FSNode &path, const String &fileName);
|
||||
bool open(const String &fileName, Archive &archive);
|
||||
|
||||
/**
|
||||
* See if a Mac data/resource fork pair exists.
|
||||
|
@ -35,6 +35,45 @@
|
||||
#include "engines/advancedDetector.h"
|
||||
#include "engines/obsolete.h"
|
||||
|
||||
/**
|
||||
* Adapter to be able to use Common::Archive based code from the AD.
|
||||
*/
|
||||
class FileMapArchive : public Common::Archive {
|
||||
public:
|
||||
FileMapArchive(const AdvancedMetaEngine::FileMap &fileMap) : _fileMap(fileMap) {}
|
||||
|
||||
bool hasFile(const Common::String &name) const override {
|
||||
return _fileMap.contains(name);
|
||||
}
|
||||
|
||||
int listMembers(Common::ArchiveMemberList &list) const override {
|
||||
int files = 0;
|
||||
for (AdvancedMetaEngine::FileMap::const_iterator it = _fileMap.begin(); it != _fileMap.end(); ++it) {
|
||||
list.push_back(Common::ArchiveMemberPtr(new Common::FSNode(it->_value)));
|
||||
++files;
|
||||
}
|
||||
|
||||
return files;
|
||||
}
|
||||
|
||||
const Common::ArchiveMemberPtr getMember(const Common::String &name) const override {
|
||||
AdvancedMetaEngine::FileMap::const_iterator it = _fileMap.find(name);
|
||||
if (it == _fileMap.end()) {
|
||||
return Common::ArchiveMemberPtr();
|
||||
}
|
||||
|
||||
return Common::ArchiveMemberPtr(new Common::FSNode(it->_value));
|
||||
}
|
||||
|
||||
Common::SeekableReadStream *createReadStreamForMember(const Common::String &name) const override {
|
||||
Common::FSNode fsNode = _fileMap[name];
|
||||
return fsNode.createReadStream();
|
||||
}
|
||||
|
||||
private:
|
||||
const AdvancedMetaEngine::FileMap &_fileMap;
|
||||
};
|
||||
|
||||
static Common::String sanitizeName(const char *name) {
|
||||
Common::String res;
|
||||
|
||||
@ -355,14 +394,16 @@ void AdvancedMetaEngine::composeFileHashMap(FileMap &allFiles, const Common::FSL
|
||||
}
|
||||
}
|
||||
|
||||
bool AdvancedMetaEngine::getFileProperties(const Common::FSNode &parent, const FileMap &allFiles, const ADGameDescription &game, const Common::String fname, FileProperties &fileProps) const {
|
||||
bool AdvancedMetaEngine::getFileProperties(const FileMap &allFiles, const ADGameDescription &game, const Common::String fname, FileProperties &fileProps) const {
|
||||
// FIXME/TODO: We don't handle the case that a file is listed as a regular
|
||||
// file and as one with resource fork.
|
||||
|
||||
if (game.flags & ADGF_MACRESFORK) {
|
||||
FileMapArchive fileMapArchive(allFiles);
|
||||
|
||||
Common::MacResManager macResMan;
|
||||
|
||||
if (!macResMan.open(parent, fname))
|
||||
if (!macResMan.open(fname, fileMapArchive))
|
||||
return false;
|
||||
|
||||
fileProps.md5 = macResMan.computeResForkMD5AsString(_md5Bytes);
|
||||
@ -407,7 +448,7 @@ ADDetectedGames AdvancedMetaEngine::detectGame(const Common::FSNode &parent, con
|
||||
continue;
|
||||
|
||||
FileProperties tmp;
|
||||
if (getFileProperties(parent, allFiles, *g, fname, tmp)) {
|
||||
if (getFileProperties(allFiles, *g, fname, tmp)) {
|
||||
debug(3, "> '%s': '%s'", fname.c_str(), tmp.md5.c_str());
|
||||
}
|
||||
|
||||
@ -510,7 +551,7 @@ ADDetectedGames AdvancedMetaEngine::detectGame(const Common::FSNode &parent, con
|
||||
return matched;
|
||||
}
|
||||
|
||||
ADDetectedGame AdvancedMetaEngine::detectGameFilebased(const FileMap &allFiles, const Common::FSList &fslist, const ADFileBasedFallback *fileBasedFallback) const {
|
||||
ADDetectedGame AdvancedMetaEngine::detectGameFilebased(const FileMap &allFiles, const ADFileBasedFallback *fileBasedFallback) const {
|
||||
const ADFileBasedFallback *ptr;
|
||||
const char* const* filenames;
|
||||
|
||||
@ -546,7 +587,7 @@ ADDetectedGame AdvancedMetaEngine::detectGameFilebased(const FileMap &allFiles,
|
||||
for (filenames = ptr->filenames; *filenames; ++filenames) {
|
||||
FileProperties tmp;
|
||||
|
||||
if (getFileProperties(fslist.begin()->getParent(), allFiles, *agdesc, *filenames, tmp))
|
||||
if (getFileProperties(allFiles, *agdesc, *filenames, tmp))
|
||||
game.matchedFiles[*filenames] = tmp;
|
||||
}
|
||||
|
||||
|
@ -305,7 +305,7 @@ protected:
|
||||
* @param fileBasedFallback a list of ADFileBasedFallback records, zero-terminated
|
||||
* @param filesProps if not 0, return a map of properties for all detected files here
|
||||
*/
|
||||
ADDetectedGame detectGameFilebased(const FileMap &allFiles, const Common::FSList &fslist, const ADFileBasedFallback *fileBasedFallback) const;
|
||||
ADDetectedGame detectGameFilebased(const FileMap &allFiles, const ADFileBasedFallback *fileBasedFallback) const;
|
||||
|
||||
/**
|
||||
* Compose a hashmap of all files in fslist.
|
||||
@ -314,10 +314,12 @@ protected:
|
||||
void composeFileHashMap(FileMap &allFiles, const Common::FSList &fslist, int depth, const Common::String &parentName = Common::String()) const;
|
||||
|
||||
/** Get the properties (size and MD5) of this file. */
|
||||
bool getFileProperties(const Common::FSNode &parent, const FileMap &allFiles, const ADGameDescription &game, const Common::String fname, FileProperties &fileProps) const;
|
||||
bool getFileProperties(const FileMap &allFiles, const ADGameDescription &game, const Common::String fname, FileProperties &fileProps) const;
|
||||
|
||||
/** Convert an AD game description into the shared game description format */
|
||||
virtual DetectedGame toDetectedGame(const ADDetectedGame &adGame) const;
|
||||
|
||||
friend class FileMapArchive; // for FileMap
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -164,7 +164,7 @@ static const ADFileBasedFallback fileBasedFallback[] = {
|
||||
};
|
||||
|
||||
ADDetectedGame CGEMetaEngine::fallbackDetect(const FileMap &allFiles, const Common::FSList &fslist) const {
|
||||
ADDetectedGame game = detectGameFilebased(allFiles, fslist, CGE::fileBasedFallback);
|
||||
ADDetectedGame game = detectGameFilebased(allFiles, CGE::fileBasedFallback);
|
||||
|
||||
if (!game.desc)
|
||||
return ADDetectedGame();
|
||||
|
@ -162,7 +162,7 @@ static const ADFileBasedFallback fileBasedFallback[] = {
|
||||
// This fallback detection looks identical to the one used for CGE. In fact, the difference resides
|
||||
// in the ResourceManager which handles a different archive format. The rest of the detection is identical.
|
||||
ADDetectedGame CGE2MetaEngine::fallbackDetect(const FileMap &allFiles, const Common::FSList &fslist) const {
|
||||
ADDetectedGame game = detectGameFilebased(allFiles, fslist, CGE2::fileBasedFallback);
|
||||
ADDetectedGame game = detectGameFilebased(allFiles, CGE2::fileBasedFallback);
|
||||
|
||||
if (!game.desc)
|
||||
return ADDetectedGame();
|
||||
|
@ -91,7 +91,7 @@ public:
|
||||
|
||||
ADDetectedGame fallbackDetect(const FileMap &allFiles,
|
||||
const Common::FSList &fslist) const override {
|
||||
return detectGameFilebased(allFiles, fslist, fileBased);
|
||||
return detectGameFilebased(allFiles, fileBased);
|
||||
}
|
||||
|
||||
const char *getEngineId() const override {
|
||||
|
@ -384,7 +384,7 @@ ADDetectedGame DirectorMetaEngine::fallbackDetect(const FileMap &allFiles, const
|
||||
ADDetectedGame game(&desc->desc);
|
||||
|
||||
FileProperties tmp;
|
||||
if (getFileProperties(file->getParent(), allFiles, desc->desc, file->getName(), tmp)) {
|
||||
if (getFileProperties(allFiles, desc->desc, file->getName(), tmp)) {
|
||||
game.hasUnknownFiles = true;
|
||||
game.matchedFiles[file->getName()] = tmp;
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ GobMetaEngine::GobMetaEngine() :
|
||||
}
|
||||
|
||||
ADDetectedGame GobMetaEngine::fallbackDetect(const FileMap &allFiles, const Common::FSList &fslist) const {
|
||||
ADDetectedGame detectedGame = detectGameFilebased(allFiles, fslist, Gob::fileBased);
|
||||
ADDetectedGame detectedGame = detectGameFilebased(allFiles, Gob::fileBased);
|
||||
if (!detectedGame.desc) {
|
||||
return ADDetectedGame();
|
||||
}
|
||||
|
@ -179,7 +179,7 @@ public:
|
||||
}
|
||||
|
||||
ADDetectedGame fallbackDetect(const FileMap &allFiles, const Common::FSList &fslist) const override {
|
||||
return detectGameFilebased(allFiles, fslist, Mohawk::fileBased);
|
||||
return detectGameFilebased(allFiles, Mohawk::fileBased);
|
||||
}
|
||||
|
||||
const char *getEngineId() const override {
|
||||
|
@ -159,7 +159,7 @@ ADDetectedGame SludgeMetaEngine::fallbackDetect(const FileMap &allFiles, const C
|
||||
game.desc = &s_fallbackDesc.desc;
|
||||
|
||||
FileProperties tmp;
|
||||
if (getFileProperties(file->getParent(), allFiles, s_fallbackDesc.desc, fileName, tmp)) {
|
||||
if (getFileProperties(allFiles, s_fallbackDesc.desc, fileName, tmp)) {
|
||||
game.hasUnknownFiles = true;
|
||||
game.matchedFiles[fileName] = tmp;
|
||||
}
|
||||
|
@ -142,7 +142,7 @@ public:
|
||||
}
|
||||
|
||||
ADDetectedGame fallbackDetect(const FileMap &allFiles, const Common::FSList &fslist) const override {
|
||||
return detectGameFilebased(allFiles, fslist, Toon::fileBasedFallback);
|
||||
return detectGameFilebased(allFiles, Toon::fileBasedFallback);
|
||||
}
|
||||
|
||||
const char *getEngineId() const override {
|
||||
|
@ -133,7 +133,7 @@ public:
|
||||
}
|
||||
|
||||
ADDetectedGame fallbackDetect(const FileMap &allFiles, const Common::FSList &fslist) const override {
|
||||
return detectGameFilebased(allFiles, fslist, Touche::fileBasedFallback);
|
||||
return detectGameFilebased(allFiles, Touche::fileBasedFallback);
|
||||
}
|
||||
|
||||
const char *getEngineId() const override {
|
||||
|
@ -148,7 +148,7 @@ public:
|
||||
if (!file->getName().hasSuffixIgnoreCase(".dcp")) continue;
|
||||
|
||||
FileProperties tmp;
|
||||
if (getFileProperties(file->getParent(), allFiles, s_fallbackDesc, file->getName(), tmp)) {
|
||||
if (getFileProperties(allFiles, s_fallbackDesc, file->getName(), tmp)) {
|
||||
game.hasUnknownFiles = true;
|
||||
game.matchedFiles[file->getName()] = tmp;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user