From 93b5eb783a228bbda03f138e10d006de7536bd37 Mon Sep 17 00:00:00 2001 From: Wilbert Pol Date: Thu, 20 Sep 2012 19:34:30 +0000 Subject: [PATCH] Added -verifysoftware command. [Wilbert Pol] --- src/emu/audit.c | 66 +++++++++++++++++++++++++ src/emu/audit.h | 1 + src/emu/clifront.c | 118 +++++++++++++++++++++++++++++++++++++++++++++ src/emu/clifront.h | 2 + 4 files changed, 187 insertions(+) diff --git a/src/emu/audit.c b/src/emu/audit.c index 437be2df27d..5a6c0c588ac 100644 --- a/src/emu/audit.c +++ b/src/emu/audit.c @@ -206,6 +206,72 @@ media_auditor::summary media_auditor::audit_device(device_t *device, const char } +//------------------------------------------------- +// audit_software +//------------------------------------------------- +media_auditor::summary media_auditor::audit_software(const char *list_name, software_info *swinfo, const char *validation) +{ + // start fresh + m_record_list.reset(); + + // store validation for later + m_validation = validation; + + astring combinedpath(swinfo->shortname, ";", list_name, PATH_SEPARATOR, swinfo->shortname); + m_searchpath = combinedpath; + + int found = 0; + int required = 0; + + // now iterate over software parts + for ( software_part *part = software_find_part( swinfo, NULL, NULL ); part != NULL; part = software_part_next( part ) ) + { + // now iterate over regions + for ( const rom_entry *region = part->romdata; region; region = rom_next_region( region ) ) + { + // now iterate over rom definitions + for (const rom_entry *rom = rom_first_file(region); rom; rom = rom_next_file(rom)) + { + hash_collection hashes(ROM_GETHASHDATA(rom)); + + // count the number of files with hashes + if (!hashes.flag(hash_collection::FLAG_NO_DUMP) && !ROM_ISOPTIONAL(rom)) + { + required++; + } + + // audit a file + audit_record *record = NULL; + if (ROMREGION_ISROMDATA(region)) + { + record = audit_one_rom(rom); + } + // audit a disk + else if (ROMREGION_ISDISKDATA(region)) + { + record = audit_one_disk(rom); + } + + // count the number of files that are found. + if (record != NULL && (record->status() == audit_record::STATUS_GOOD || record->status() == audit_record::STATUS_FOUND_INVALID)) + { + found++; + } + } + } + } + + if (found == 0 && required > 0) + { + m_record_list.reset(); + return NOTFOUND; + } + + // return a summary + return summarize(list_name); +} + + //------------------------------------------------- // audit_samples - validate the samples for the // currently-enumerated driver diff --git a/src/emu/audit.h b/src/emu/audit.h index d036068a642..41f5ab1d19f 100644 --- a/src/emu/audit.h +++ b/src/emu/audit.h @@ -176,6 +176,7 @@ public: // audit operations summary audit_media(const char *validation = AUDIT_VALIDATE_FULL); summary audit_device(device_t *device, const char *validation = AUDIT_VALIDATE_FULL); + summary audit_software(const char *list_name, software_info *swinfo, const char *validation = AUDIT_VALIDATE_FULL); summary audit_samples(); summary summarize(const char *name,astring *output = NULL); diff --git a/src/emu/clifront.c b/src/emu/clifront.c index 2b376160732..a47cf14bc82 100644 --- a/src/emu/clifront.c +++ b/src/emu/clifront.c @@ -88,6 +88,7 @@ const options_entry cli_options::s_option_entries[] = { CLICOMMAND_LISTSLOTS ";lslot", "0", OPTION_COMMAND, "list available slots and slot devices" }, { CLICOMMAND_LISTMEDIA ";lm", "0", OPTION_COMMAND, "list available media for the system" }, { CLICOMMAND_LISTSOFTWARE ";lsoft", "0", OPTION_COMMAND, "list known software for the system" }, + { CLICOMMAND_VERIFYSOFTWARE ";vsoft", "0", OPTION_COMMAND, "verify known software for the system" }, { CLICOMMAND_GETSOFTLIST ";glist", "0", OPTION_COMMAND, "retrieve software list by name" }, { NULL } }; @@ -1281,6 +1282,122 @@ void cli_frontend::listsoftware(const char *gamename) } +/*------------------------------------------------- + verifysoftware - verify roms from the software + list of the specified driver(s) +-------------------------------------------------*/ +void cli_frontend::verifysoftware(const char *gamename) +{ + int_map list_map; + + int correct = 0; + int incorrect = 0; + int notfound = 0; + int matched = 0; + int nrlists = 0; + + // determine which drivers to process; return an error if none found + driver_enumerator drivlist(m_options, gamename); + if (drivlist.count() == 0) + { + throw emu_fatalerror(MAMERR_NO_SUCH_GAME, "No matching games found for '%s'", gamename); + } + + media_auditor auditor(drivlist); + while (drivlist.next()) + { + matched++; + + software_list_device_iterator iter(drivlist.config().root_device()); + for (const software_list_device *swlist = iter.first(); swlist != NULL; swlist = iter.next()) + { + if (swlist->list_type() == SOFTWARE_LIST_ORIGINAL_SYSTEM) + { + software_list *list = software_list_open(m_options, swlist->list_name(), FALSE, NULL); + + if ( list ) + { + /* Verify if we have encountered this list before */ + if (list_map.add(swlist->list_name(), 0, false) != TMERR_DUPLICATE) + { + nrlists++; + + // Get the actual software list contents + software_list_parse( list, NULL, NULL ); + + for ( software_info *swinfo = software_list_find( list, "*", NULL ); swinfo != NULL; swinfo = software_list_find( list, "*", swinfo ) ) + { + media_auditor::summary summary = auditor.audit_software(swlist->list_name(), swinfo, AUDIT_VALIDATE_FAST); + + // if not found, count that and leave it at that + if (summary == media_auditor::NOTFOUND) + { + notfound++; + } + // else display information about what we discovered + else if(summary != media_auditor::NONE_NEEDED) + { + // output the summary of the audit + astring summary_string; + auditor.summarize(swinfo->shortname,&summary_string); + mame_printf_info("%s", summary_string.cstr()); + + // display information about what we discovered + mame_printf_info("romset %s:%s ", swlist->list_name(), swinfo->shortname); + + // switch off of the result + switch (summary) + { + case media_auditor::INCORRECT: + mame_printf_info("is bad\n"); + incorrect++; + break; + + case media_auditor::CORRECT: + mame_printf_info("is good\n"); + correct++; + break; + + case media_auditor::BEST_AVAILABLE: + mame_printf_info("is best available\n"); + correct++; + break; + + default: + break; + } + } + } + } + + software_list_close( list ); + } + } + } + } + + // clear out any cached files + zip_file_cache_clear(); + + // return an error if none found + if (matched == 0) + throw emu_fatalerror(MAMERR_NO_SUCH_GAME, "No matching games found for '%s'", gamename); + + // if we didn't get anything at all, display a generic end message + if (matched > 0 && correct == 0 && incorrect == 0) + { + throw emu_fatalerror(MAMERR_MISSING_FILES, "romset \"%s\" has no software entries defined!\n", gamename); + } + // otherwise, print a summary + else + { + if (incorrect > 0) + throw emu_fatalerror(MAMERR_MISSING_FILES, "%d romsets found in %d software lists, %d were OK.\n", correct + incorrect, nrlists, correct); + mame_printf_info("%d romsets found in %d software lists, %d romsets were OK.\n", correct, nrlists, correct); + } + +} + /*------------------------------------------------- getsoftlist - retrieve software list by name -------------------------------------------------*/ @@ -1423,6 +1540,7 @@ void cli_frontend::execute_commands(const char *exename) { CLICOMMAND_VERIFYSAMPLES, &cli_frontend::verifysamples }, { CLICOMMAND_LISTMEDIA, &cli_frontend::listmedia }, { CLICOMMAND_LISTSOFTWARE, &cli_frontend::listsoftware }, + { CLICOMMAND_VERIFYSOFTWARE, &cli_frontend::verifysoftware }, { CLICOMMAND_ROMIDENT, &cli_frontend::romident }, { CLICOMMAND_GETSOFTLIST, &cli_frontend::getsoftlist }, }; diff --git a/src/emu/clifront.h b/src/emu/clifront.h index 02ec7dd2142..a353777e477 100644 --- a/src/emu/clifront.h +++ b/src/emu/clifront.h @@ -75,6 +75,7 @@ #define CLICOMMAND_LISTSLOTS "listslots" #define CLICOMMAND_LISTMEDIA "listmedia" // needed by MESS #define CLICOMMAND_LISTSOFTWARE "listsoftware" +#define CLICOMMAND_VERIFYSOFTWARE "verifysoftware" #define CLICOMMAND_GETSOFTLIST "getsoftlist" @@ -120,6 +121,7 @@ public: void listslots(const char *gamename = "*"); void listmedia(const char *gamename = "*"); void listsoftware(const char *gamename = "*"); + void verifysoftware(const char *gamename = "*"); void verifyroms(const char *gamename = "*"); void verifysamples(const char *gamename = "*"); void romident(const char *filename);