aboutsummaryrefslogtreecommitdiff
path: root/engines/advancedDetector.cpp
diff options
context:
space:
mode:
authorMax Horn2011-06-10 22:13:51 +0200
committerMax Horn2011-06-10 22:15:48 +0200
commiteea6f69b595be9c95f7af0f79086e0cb05fb8fa4 (patch)
treed1aee2953bb4bdbbb8e489fd21edd1c9d5989a40 /engines/advancedDetector.cpp
parent5d584bc7826317acacf1ca53afcc807b9545541e (diff)
downloadscummvm-rg350-eea6f69b595be9c95f7af0f79086e0cb05fb8fa4.tar.gz
scummvm-rg350-eea6f69b595be9c95f7af0f79086e0cb05fb8fa4.tar.bz2
scummvm-rg350-eea6f69b595be9c95f7af0f79086e0cb05fb8fa4.zip
DETECTOR: Turn some internal func of AdvancedMetaEngine into methods
The eventual goal here is to make it easier (well, *possible*) for subclasses to modify the detector behavior, e.g. to implement custom fallback detection. One immediate goal could be to move the filebased fallback detector into a subclass.
Diffstat (limited to 'engines/advancedDetector.cpp')
-rw-r--r--engines/advancedDetector.cpp104
1 files changed, 32 insertions, 72 deletions
diff --git a/engines/advancedDetector.cpp b/engines/advancedDetector.cpp
index 06f6c79db6..b0a304aad9 100644
--- a/engines/advancedDetector.cpp
+++ b/engines/advancedDetector.cpp
@@ -33,51 +33,7 @@
#include "engines/advancedDetector.h"
-/**
- * A list of pointers to ADGameDescription structs (or subclasses thereof).
- */
-typedef Common::Array<const ADGameDescription*> ADGameDescList;
-
-
-/**
- * Detect games in specified directory.
- * Parameters language and platform are used to pass on values
- * specified by the user. I.e. this is used to restrict search scope.
- *
- * @param fslist FSList to scan or NULL for scanning all specified
- * default directories.
- * @param params a ADParams struct containing various parameters
- * @param language restrict results to specified language only
- * @param platform restrict results to specified platform only
- * @return list of ADGameDescription (or subclass) pointers corresponding to matched games
- */
-static ADGameDescList detectGame(const Common::FSList &fslist, const ADParams &params, Common::Language language, Common::Platform platform, const Common::String &extra);
-
-
-/**
- * Returns list of targets supported by the engine.
- * Distinguishes engines with single ID
- */
-static GameList gameIDList(const ADParams &params) {
- if (params.singleid != NULL) {
- GameList gl;
-
- const PlainGameDescriptor *g = params.gameDescriptors;
- while (g->gameid) {
- if (0 == scumm_stricmp(params.singleid, g->gameid)) {
- gl.push_back(GameDescriptor(g->gameid, g->description));
-
- return gl;
- }
- g++;
- }
- error("Engine %s doesn't have its singleid specified in ids list", params.singleid);
- }
-
- return GameList(params.gameDescriptors);
-}
-
-static void upgradeTargetIfNecessary(const ADParams &params) {
+void AdvancedMetaEngine::upgradeTargetIfNecessary() const {
if (params.obsoleteList == 0)
return;
@@ -189,7 +145,7 @@ static Common::String generatePreferredTarget(const Common::String &id, const AD
return res;
}
-static void AdvancedMetaEngine::updateGameDescriptor(GameDescriptor &desc, const ADGameDescription *realDesc) {
+void AdvancedMetaEngine::updateGameDescriptor(GameDescriptor &desc, const ADGameDescription *realDesc) const {
if (params.singleid != NULL) {
desc["preferredtarget"] = desc["gameid"];
desc["gameid"] = params.singleid;
@@ -234,7 +190,7 @@ bool cleanupPirated(ADGameDescList &matched) {
GameList AdvancedMetaEngine::detectGames(const Common::FSList &fslist) const {
- ADGameDescList matches = detectGame(fslist, params, Common::UNK_LANG, Common::kPlatformUnknown, "");
+ ADGameDescList matches = detectGame(fslist, Common::UNK_LANG, Common::kPlatformUnknown, "");
GameList detectedGames;
if (cleanupPirated(matches))
@@ -245,14 +201,14 @@ GameList AdvancedMetaEngine::detectGames(const Common::FSList &fslist) const {
const ADGameDescription *fallbackDesc = fallbackDetect(fslist);
if (fallbackDesc != 0) {
GameDescriptor desc(toGameDescriptor(*fallbackDesc, params.gameDescriptors));
- updateGameDescriptor(desc, fallbackDesc, params);
+ updateGameDescriptor(desc, fallbackDesc);
detectedGames.push_back(desc);
}
} else {
// Otherwise use the found matches
for (uint i = 0; i < matches.size(); i++) {
GameDescriptor desc(toGameDescriptor(*matches[i], params.gameDescriptors));
- updateGameDescriptor(desc, matches[i], params);
+ updateGameDescriptor(desc, matches[i]);
detectedGames.push_back(desc);
}
}
@@ -262,7 +218,7 @@ GameList AdvancedMetaEngine::detectGames(const Common::FSList &fslist) const {
Common::Error AdvancedMetaEngine::createInstance(OSystem *syst, Engine **engine) const {
assert(engine);
- upgradeTargetIfNecessary(params);
+ upgradeTargetIfNecessary();
const ADGameDescription *agdDesc = 0;
Common::Language language = Common::UNK_LANG;
@@ -305,7 +261,7 @@ Common::Error AdvancedMetaEngine::createInstance(OSystem *syst, Engine **engine)
return Common::kNoGameDataFoundError;
}
- ADGameDescList matches = detectGame(files, params, language, platform, extra);
+ ADGameDescList matches = detectGame(files, language, platform, extra);
if (cleanupPirated(matches))
return Common::kNoGameDataFoundError;
@@ -357,7 +313,6 @@ struct SizeMD5 {
};
typedef Common::HashMap<Common::String, SizeMD5, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo> SizeMD5Map;
-typedef Common::HashMap<Common::String, Common::FSNode, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo> FileMap;
static void reportUnknown(const Common::FSNode &path, const SizeMD5Map &filesSizeMD5) {
// TODO: This message should be cleaned up / made more specific.
@@ -379,26 +334,22 @@ static void reportUnknown(const Common::FSNode &path, const SizeMD5Map &filesSiz
g_system->logMessage(LogMessageType::kInfo, report.c_str());
}
-static ADGameDescList detectGameFilebased(const FileMap &allFiles, const ADParams &params);
-
-static void composeFileHashMap(const Common::FSList &fslist, FileMap &allFiles, int depth, const char * const *directoryGlobs) {
+void AdvancedMetaEngine::composeFileHashMap(const Common::FSList &fslist, FileMap &allFiles, int depth) const {
if (depth <= 0)
return;
if (fslist.empty())
return;
- // First we compose a hashmap of all files in fslist.
- // Includes nifty stuff like removing trailing dots and ignoring case.
for (Common::FSList::const_iterator file = fslist.begin(); file != fslist.end(); ++file) {
if (file->isDirectory()) {
Common::FSList files;
- if (!directoryGlobs)
+ if (!params.directoryGlobs)
continue;
bool matched = false;
- for (const char * const *glob = directoryGlobs; *glob; glob++)
+ for (const char * const *glob = params.directoryGlobs; *glob; glob++)
if (file->getName().matchString(*glob, true)) {
matched = true;
break;
@@ -410,7 +361,7 @@ static void composeFileHashMap(const Common::FSList &fslist, FileMap &allFiles,
if (!file->getChildren(files, Common::FSNode::kListAll))
continue;
- composeFileHashMap(files, allFiles, depth - 1, directoryGlobs);
+ composeFileHashMap(files, allFiles, depth - 1);
}
Common::String tstr = file->getName();
@@ -423,7 +374,7 @@ static void composeFileHashMap(const Common::FSList &fslist, FileMap &allFiles,
}
}
-static ADGameDescList detectGame(const Common::FSList &fslist, const ADParams &params, Common::Language language, Common::Platform platform, const Common::String &extra) {
+ADGameDescList AdvancedMetaEngine::detectGame(const Common::FSList &fslist, Common::Language language, Common::Platform platform, const Common::String &extra) const {
FileMap allFiles;
SizeMD5Map filesSizeMD5;
@@ -437,8 +388,7 @@ static ADGameDescList detectGame(const Common::FSList &fslist, const ADParams &p
debug(3, "Starting detection in dir '%s'", parent.getPath().c_str());
// First we compose a hashmap of all files in fslist.
- // Includes nifty stuff like removing trailing dots and ignoring case.
- composeFileHashMap(fslist, allFiles, (params.depth == 0 ? 1 : params.depth), params.directoryGlobs);
+ composeFileHashMap(fslist, allFiles, (params.depth == 0 ? 1 : params.depth));
// Check which files are included in some ADGameDescription *and* present
// in fslist. Compute MD5s and file sizes for these files.
@@ -576,19 +526,13 @@ static ADGameDescList detectGame(const Common::FSList &fslist, const ADParams &p
// Filename based fallback
if (params.fileBasedFallback != 0)
- matched = detectGameFilebased(allFiles, params);
+ matched = detectGameFilebased(allFiles);
}
return matched;
}
-/**
- * Check for each ADFileBasedFallback record whether all files listed
- * in it are present. If multiple pass this test, we pick the one with
- * the maximal number of matching files. In case of a tie, the entry
- * coming first in the list is chosen.
- */
-static ADGameDescList detectGameFilebased(const FileMap &allFiles, const ADParams &params) {
+ADGameDescList AdvancedMetaEngine::detectGameFilebased(const FileMap &allFiles) const {
const ADFileBasedFallback *ptr;
const char* const* filenames;
@@ -642,8 +586,24 @@ static ADGameDescList detectGameFilebased(const FileMap &allFiles, const ADParam
}
GameList AdvancedMetaEngine::getSupportedGames() const {
- return gameIDList(params);
+ if (params.singleid != NULL) {
+ GameList gl;
+
+ const PlainGameDescriptor *g = params.gameDescriptors;
+ while (g->gameid) {
+ if (0 == scumm_stricmp(params.singleid, g->gameid)) {
+ gl.push_back(GameDescriptor(g->gameid, g->description));
+
+ return gl;
+ }
+ g++;
+ }
+ error("Engine %s doesn't have its singleid specified in ids list", params.singleid);
+ }
+
+ return GameList(params.gameDescriptors);
}
+
GameDescriptor AdvancedMetaEngine::findGame(const char *gameid) const {
return AdvancedDetector::findGameID(gameid, params.gameDescriptors, params.obsoleteList);
}