Ticket #8730: ADunknown.patch

File ADunknown.patch, 3.5 KB (added by jvprat, 17 years ago)
  • common/advancedDetector.h

     
    240240// Only used by ADVANCED_DETECTOR_DEFINE_PLUGIN_WITH_FUNC
    241241PluginError detectGameForEngineCreation(const Common::ADParams &params);
    242242
     243// Helper function to announce an unknown version of the game (useful for
     244// fallback detection functions).
     245void reportUnknown(StringList &files, int md5Bytes);
    243246
    244247// FIXME: It would probably be good to merge detectBestMatchingGame
    245248// and detectGameForEngineCreation into a single function. Right now, the
  • common/advancedDetector.cpp

     
    301301        return kNoGameDataFoundError;
    302302}
    303303
     304void reportUnknown(StringMap &filesMD5, HashMap<String, int32, Common::CaseSensitiveString_Hash, Common::CaseSensitiveString_EqualTo> &filesSize) {
     305        // TODO: This message should be cleaned up / made more specific.
     306        // For example, we should specify at least which engine triggered this.
     307        //
     308        // Might also be helpful to display the full path (for when this is used
     309        // from the mass detector).
     310        printf("Your game version appears to be unknown. Please, report the following\n");
     311        printf("data to the ScummVM team along with name of the game you tried to add\n");
     312        printf("and its version/language/etc.:\n");
     313
     314        for (StringMap::const_iterator file = filesMD5.begin(); file != filesMD5.end(); ++file)
     315                printf("  \"%s\", \"%s\", %d\n", file->_key.c_str(), file->_value.c_str(), filesSize[file->_key]);
     316
     317        printf("\n");
     318}
     319
     320void reportUnknown(StringList &files, int md5Bytes) {
     321        StringMap filesMD5;
     322        HashMap<String, int32, Common::CaseSensitiveString_Hash, Common::CaseSensitiveString_EqualTo> filesSize;
     323
     324        char md5str[32+1];
     325        File testFile;
     326
     327        // Fill the data structures for the requested files
     328        for (StringList::iterator file = files.begin(); file != files.end(); file++) {
     329
     330                if (testFile.open(*file)) {
     331                        filesSize[*file] = (int32)testFile.size();
     332
     333                        if (md5_file_string(testFile, md5str, md5Bytes))
     334                                filesMD5[*file] = md5str;
     335
     336                        testFile.close();
     337                }
     338        }
     339
     340        reportUnknown(filesMD5, filesSize);
     341}
     342
    304343static ADGameDescList detectGame(const FSList *fslist, const Common::ADParams &params, Language language, Platform platform) {
    305344        typedef HashMap<String, bool, CaseSensitiveString_Hash, CaseSensitiveString_EqualTo> StringSet;
    306345        StringSet filesList;
     
    460499        if (!matched.empty())
    461500                return matched;
    462501
    463         if (!filesMD5.empty()) {
    464                 // TODO: This message should be cleaned up / made more specific.
    465                 // For example, we should specify at least which engine triggered this.
    466                 //
    467                 // Might also be helpful to display the full path (for when this is used
    468                 // from the mass detector).
    469                 printf("Your game version appears to be unknown. Please, report the following\n");
    470                 printf("data to the ScummVM team along with name of the game you tried to add\n");
    471                 printf("and its version/language/etc.:\n");
     502        if (!filesMD5.empty())
     503                reportUnknown(filesMD5, filesSize);
    472504
    473                 for (StringMap::const_iterator file = filesMD5.begin(); file != filesMD5.end(); ++file)
    474                         printf("  \"%s\", \"%s\", %d\n", file->_key.c_str(), file->_value.c_str(), filesSize[file->_key]);
    475 
    476                 printf("\n");
    477         }
    478 
    479505        // Filename based fallback
    480506        if (params.fileBasedFallback != 0) {
    481507                const ADFileBasedFallback *ptr = params.fileBasedFallback;