diff options
author | Max Horn | 2008-07-29 00:50:12 +0000 |
---|---|---|
committer | Max Horn | 2008-07-29 00:50:12 +0000 |
commit | d848543ee432a11c11968af59dd1caa362a2021d (patch) | |
tree | 7fb63868dcf75e9ec14d5665b5e85818b89c7a70 | |
parent | e1520c6462b0cd465ef744a6af5a709abaea635d (diff) | |
download | scummvm-rg350-d848543ee432a11c11968af59dd1caa362a2021d.tar.gz scummvm-rg350-d848543ee432a11c11968af59dd1caa362a2021d.tar.bz2 scummvm-rg350-d848543ee432a11c11968af59dd1caa362a2021d.zip |
Changed advanced detector to *always* use the FSNode API for detection (i.e. killed second code path which used File::open trial&error directory 'scanning')
svn-id: r33388
-rw-r--r-- | common/advancedDetector.cpp | 82 |
1 files changed, 37 insertions, 45 deletions
diff --git a/common/advancedDetector.cpp b/common/advancedDetector.cpp index 4387bd199e..e328cf7787 100644 --- a/common/advancedDetector.cpp +++ b/common/advancedDetector.cpp @@ -48,7 +48,7 @@ using namespace AdvancedDetector; * @param platform restrict results to specified platform only * @return list of ADGameDescription (or subclass) pointers corresponding to matched games */ -static ADGameDescList detectGame(const FSList *fslist, const Common::ADParams ¶ms, Language language, Platform platform, const Common::String extra); +static ADGameDescList detectGame(const FSList &fslist, const Common::ADParams ¶ms, Language language, Platform platform, const Common::String extra); /** @@ -194,7 +194,7 @@ static void updateGameDescriptor(GameDescriptor &desc, const ADGameDescription * } GameList AdvancedMetaEngine::detectGames(const FSList &fslist) const { - ADGameDescList matches = detectGame(&fslist, params, Common::UNK_LANG, Common::kPlatformUnknown, ""); + ADGameDescList matches = detectGame(fslist, params, Common::UNK_LANG, Common::kPlatformUnknown, ""); GameList detectedGames; // Use fallback detector if there were no matches by other means @@ -233,7 +233,21 @@ PluginError AdvancedMetaEngine::createInstance(OSystem *syst, Engine **engine) c Common::String gameid = ConfMan.get("gameid"); - ADGameDescList matches = detectGame(0, params, language, platform, extra); + Common::String path; + if (ConfMan.hasKey("path")) { + path = ConfMan.get("path"); + } else { + path = "."; + warning("No path was provided. Assuming the data files are in the current directory"); + } + FilesystemNode dir(path); + FSList files; + if (!dir.isDirectory() || !dir.getChildren(files, FilesystemNode::kListAll)) { + warning("Game data path does not exist or is not a directory (%s)", path.c_str()); + return kNoGameDataFoundError; + } + + ADGameDescList matches = detectGame(files, params, language, platform, extra); if (params.singleid == NULL) { for (uint i = 0; i < matches.size(); i++) { @@ -287,7 +301,7 @@ static void reportUnknown(StringMap &filesMD5, IntMap &filesSize) { printf("\n"); } -static ADGameDescList detectGame(const FSList *fslist, const Common::ADParams ¶ms, Language language, Platform platform, const Common::String extra) { +static ADGameDescList detectGame(const FSList &fslist, const Common::ADParams ¶ms, Language language, Platform platform, const Common::String extra) { StringSet filesList; StringMap filesMD5; @@ -319,57 +333,35 @@ static ADGameDescList detectGame(const FSList *fslist, const Common::ADParams &p } } - // TODO/FIXME: Fingolfin says: It's not good that we have two different code paths here, - // one using a FSList, one using File::open, as that will lead to discrepancies and subtle - // problems caused by those. - if (fslist != 0) { - // Get the information of the existing files - for (FSList::const_iterator file = fslist->begin(); file != fslist->end(); ++file) { - if (file->isDirectory()) continue; - tstr = file->getName(); - tstr.toLowercase(); - - // Strip any trailing dot - if (tstr.lastChar() == '.') - tstr.deleteLastChar(); + // Get the information of the existing files + for (FSList::const_iterator file = fslist.begin(); file != fslist.end(); ++file) { + if (file->isDirectory()) continue; + tstr = file->getName(); + tstr.toLowercase(); - allFiles[tstr] = true; + // Strip any trailing dot + if (tstr.lastChar() == '.') + tstr.deleteLastChar(); - debug(3, "+ %s", tstr.c_str()); + allFiles[tstr] = true; - if (!filesList.contains(tstr)) continue; + debug(3, "+ %s", tstr.c_str()); - if (!md5_file_string(*file, md5str, params.md5Bytes)) - continue; - filesMD5[tstr] = md5str; + if (!filesList.contains(tstr)) continue; - debug(3, "> %s: %s", tstr.c_str(), md5str); - - if (testFile.open(file->getPath())) { - filesSize[tstr] = (int32)testFile.size(); - testFile.close(); - } - } - } else { - // Get the information of the requested files - for (StringSet::const_iterator file = filesList.begin(); file != filesList.end(); ++file) { - tstr = file->_key; + if (!md5_file_string(*file, md5str, params.md5Bytes)) + continue; + filesMD5[tstr] = md5str; - debug(3, "+ %s", tstr.c_str()); - if (!filesMD5.contains(tstr)) { - if (testFile.open(tstr) || testFile.open(tstr + ".")) { - filesSize[tstr] = (int32)testFile.size(); - testFile.close(); + debug(3, "> %s: %s", tstr.c_str(), md5str); - if (md5_file_string(file->_key.c_str(), md5str, params.md5Bytes)) { - filesMD5[tstr] = md5str; - debug(3, "> %s: %s", tstr.c_str(), md5str); - } - } - } + if (testFile.open(file->getPath())) { + filesSize[tstr] = (int32)testFile.size(); + testFile.close(); } } + ADGameDescList matched; int maxFilesMatched = 0; |