aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorMax Horn2008-03-14 13:59:31 +0000
committerMax Horn2008-03-14 13:59:31 +0000
commit8a9a14002ecee554082eb4f23ef245173950b363 (patch)
tree1f25dae4db32a9dce92b10393bfb8850deef2b98 /common
parent1e6f59e2dcc601eb5e67e47af18ffd975ab86157 (diff)
downloadscummvm-rg350-8a9a14002ecee554082eb4f23ef245173950b363.tar.gz
scummvm-rg350-8a9a14002ecee554082eb4f23ef245173950b363.tar.bz2
scummvm-rg350-8a9a14002ecee554082eb4f23ef245173950b363.zip
Advanced Detector: Changed fallback detector from a callback function pointer to an overrideable method of AdvancedMetaEngine
svn-id: r31119
Diffstat (limited to 'common')
-rw-r--r--common/advancedDetector.cpp51
-rw-r--r--common/advancedDetector.h33
2 files changed, 40 insertions, 44 deletions
diff --git a/common/advancedDetector.cpp b/common/advancedDetector.cpp
index 5ff124a43c..ccb32a5188 100644
--- a/common/advancedDetector.cpp
+++ b/common/advancedDetector.cpp
@@ -34,6 +34,8 @@
namespace Common {
+using namespace AdvancedDetector;
+
namespace AdvancedDetector {
// FIXME/TODO: Rename this function to something more sensible.
@@ -209,16 +211,15 @@ static void updateGameDescriptor(GameDescriptor &desc, const ADGameDescription *
desc["extra"] = realDesc->extra;
}
-GameList detectAllGames(
- const FSList &fslist,
- const Common::ADParams &params
- ) {
+} // End of namespace AdvancedDetector
+
+GameList AdvancedMetaEngine::detectGames(const FSList &fslist) const {
ADGameDescList matches = detectGame(&fslist, params, Common::UNK_LANG, Common::kPlatformUnknown, "");
GameList detectedGames;
// Use fallback detector if there were no matches by other means
- if (matches.empty() && params.fallbackDetectFunc != NULL) {
- EncapsulatedADGameDesc fallbackDesc = (*params.fallbackDetectFunc)(&fslist);
+ if (matches.empty()) {
+ EncapsulatedADGameDesc fallbackDesc = fallbackDetect(&fslist);
if (fallbackDesc.realDesc != 0) {
GameDescriptor desc(toGameDescriptor(fallbackDesc, params.list));
updateGameDescriptor(desc, fallbackDesc.realDesc, params);
@@ -233,9 +234,10 @@ GameList detectAllGames(
return detectedGames;
}
-EncapsulatedADGameDesc detectBestMatchingGame(
- const Common::ADParams &params
- ) {
+PluginError AdvancedMetaEngine::createInstance(OSystem *syst, Engine **engine) const {
+ assert(engine);
+ Common::AdvancedDetector::upgradeTargetIfNecessary(params);
+
const ADGameDescription *agdDesc = 0;
EncapsulatedADGameDesc result;
Common::Language language = Common::UNK_LANG;
@@ -267,8 +269,9 @@ EncapsulatedADGameDesc detectBestMatchingGame(
if (agdDesc != 0) { // Check if we found a match without fallback detection
result = EncapsulatedADGameDesc(agdDesc);
- } else if (params.fallbackDetectFunc != NULL) { // Use fallback detector if there were no matches by other means
- EncapsulatedADGameDesc fallbackDesc = (*params.fallbackDetectFunc)(NULL);
+ } else {
+ // Use fallback detector if there were no matches by other means
+ EncapsulatedADGameDesc fallbackDesc = fallbackDetect(NULL);
if (fallbackDesc.realDesc != 0 && (params.singleid != NULL || fallbackDesc.getGameID() == gameid)) {
result = fallbackDesc; // Found a fallback match
}
@@ -278,9 +281,17 @@ EncapsulatedADGameDesc detectBestMatchingGame(
debug(2, "Running %s", toGameDescriptor(result, params.list).description().c_str());
}
- return result;
+ if (result.realDesc == 0) {
+ return kNoGameDataFoundError;
+ }
+ if (!createInstance(syst, engine, result)) {
+ return kNoGameDataFoundError;
+ }
+ return kNoError;
}
+namespace AdvancedDetector {
+
void reportUnknown(StringMap &filesMD5, HashMap<String, int32, Common::CaseSensitiveString_Hash, Common::CaseSensitiveString_EqualTo> &filesSize) {
// TODO: This message should be cleaned up / made more specific.
// For example, we should specify at least which engine triggered this.
@@ -571,21 +582,5 @@ GameList AdvancedMetaEngine::getSupportedGames() const {
GameDescriptor AdvancedMetaEngine::findGame(const char *gameid) const {
return Common::AdvancedDetector::findGameID(gameid, params.list, params.obsoleteList);
}
-GameList AdvancedMetaEngine::detectGames(const FSList &fslist) const {
- return Common::AdvancedDetector::detectAllGames(fslist, params);
-}
-
-PluginError AdvancedMetaEngine::createInstance(OSystem *syst, Engine **engine) const {
- assert(engine);
- Common::AdvancedDetector::upgradeTargetIfNecessary(params);
- Common::EncapsulatedADGameDesc encapsulatedDesc = Common::AdvancedDetector::detectBestMatchingGame(params);
- if (encapsulatedDesc.realDesc == 0) {
- return kNoGameDataFoundError;
- }
- if (!createInstance(syst,engine,encapsulatedDesc)) {
- return kNoGameDataFoundError;
- }
- return kNoError;
-}
} // End of namespace Common
diff --git a/common/advancedDetector.h b/common/advancedDetector.h
index f694e9896a..5702243484 100644
--- a/common/advancedDetector.h
+++ b/common/advancedDetector.h
@@ -67,6 +67,8 @@ struct ADGameDescription {
/**
* Encapsulates ADGameDescription and makes gameid and extra strings dynamic.
* Used in fallback detection when dynamically creating string content.
+ *
+ * @todo Get rid of this once the fallback detection is a member of AdvancedMetaEngine.
*/
struct EncapsulatedADGameDesc {
Common::String gameid;
@@ -76,8 +78,8 @@ struct EncapsulatedADGameDesc {
// Constructor for the EncapsulatedADGameDesc
EncapsulatedADGameDesc() : realDesc(0) {}
EncapsulatedADGameDesc(const ADGameDescription *paramRealDesc,
- Common::String paramGameID = Common::String(""),
- Common::String paramExtra = Common::String(""))
+ Common::String paramGameID = Common::String(),
+ Common::String paramExtra = Common::String())
: realDesc(paramRealDesc), gameid(paramGameID), extra(paramExtra) {
assert(paramRealDesc != NULL);
}
@@ -193,20 +195,6 @@ struct ADParams {
const ADFileBasedFallback *fileBasedFallback;
/**
- * A callback pointing to an (optional) generic fallback detect
- * function. If present, this callback is invoked if both the regular
- * MD5 based detection as well as the file based fallback failed
- * to detect anything.
- *
- * @note The fslist parameter may be 0 -- in that case, it is assumed
- * that the callback searchs the current directory.
- *
- * @todo Change this to a member method of AdvancedMetaEngine which can
- * be overriden via subclassing.
- */
- EncapsulatedADGameDesc (*fallbackDetectFunc)(const FSList *fslist);
-
- /**
* A bitmask of flags which can be used to configure the behavior
* of the AdvancedDetector. Refer to ADFlags for a list of flags
* that can be ORed together and passed here.
@@ -245,6 +233,19 @@ public:
// To be provided by subclasses
virtual bool createInstance(OSystem *syst, Engine **engine, const Common::EncapsulatedADGameDesc &encapsulatedDesc) const = 0;
+
+
+ /**
+ * An (optional) generic fallback detect function which is invoked
+ * if both the regular MD5 based detection as well as the file
+ * based fallback failed to detect anything.
+ *
+ * @note The fslist parameter may be 0 -- in that case, it is assumed
+ * that the callback searchs the current directory.
+ */
+ EncapsulatedADGameDesc fallbackDetect(const FSList *fslist) const {
+ return EncapsulatedADGameDesc();
+ }
};
} // End of namespace Common