int audit_images(int game, UINT32 validation, audit_record **audit) { const game_driver *gamedrv = drivers[game]; const rom_entry *region, *rom; audit_record *record; int foundany = FALSE; int allshared = TRUE; int records; /* determine the number of records we will generate */ records = 0; for (region = rom_first_region(gamedrv); region != NULL; region = rom_next_region(region)) for (rom = rom_first_file(region); rom != NULL; rom = rom_next_file(rom)) if (ROMREGION_ISROMDATA(region) || ROMREGION_ISDISKDATA(region)) { if (allshared && !rom_used_by_parent(gamedrv, rom, NULL)) allshared = FALSE; records++; } if (records > 0) { /* allocate memory for the records */ *audit = malloc_or_die(sizeof(**audit) * records); memset(*audit, 0, sizeof(**audit) * records); record = *audit; /* iterate over regions and ROMs */ for (region = rom_first_region(drivers[game]); region; region = rom_next_region(region)) for (rom = rom_first_file(region); rom; rom = rom_next_file(rom)) { int shared = rom_used_by_parent(gamedrv, rom, NULL); /* audit a file */ if (ROMREGION_ISROMDATA(region)) { if (audit_one_rom(rom, gamedrv, validation, record++) && (!shared || allshared)) foundany = TRUE; } /* audit a disk */ else if (ROMREGION_ISDISKDATA(region)) { if (audit_one_disk(rom, gamedrv, validation, record++) && (!shared || allshared)) foundany = TRUE; } } /* if we found nothing, we don't have the set at all */ if (!foundany) { free(*audit); *audit = NULL; records = 0; } } return records; }
int audit_images(core_options *options, const game_driver *gamedrv, UINT32 validation, audit_record **audit) { machine_config *config = global_alloc(machine_config(gamedrv->machine_config)); const rom_entry *region, *rom; const rom_source *source; audit_record *record; int anyfound = FALSE; int anyrequired = FALSE; int allshared = TRUE; int records; /* determine the number of records we will generate */ records = 0; for (source = rom_first_source(gamedrv, config); source != NULL; source = rom_next_source(gamedrv, config, source)) { int source_is_gamedrv = rom_source_is_gamedrv(gamedrv, source); for (region = rom_first_region(gamedrv, source); region != NULL; region = rom_next_region(region)) for (rom = rom_first_file(region); rom != NULL; rom = rom_next_file(rom)) if (ROMREGION_ISROMDATA(region) || ROMREGION_ISDISKDATA(region)) { if (source_is_gamedrv && !ROM_ISOPTIONAL(rom) && !ROM_NOGOODDUMP(rom)) { anyrequired = TRUE; if (allshared && !rom_used_by_parent(gamedrv, rom, NULL)) allshared = FALSE; } records++; } } if (records > 0) { /* allocate memory for the records */ *audit = global_alloc_array_clear(audit_record, records); record = *audit; /* iterate over ROM sources and regions */ for (source = rom_first_source(gamedrv, config); source != NULL; source = rom_next_source(gamedrv, config, source)) { int source_is_gamedrv = rom_source_is_gamedrv(gamedrv, source); for (region = rom_first_region(gamedrv, source); region != NULL; region = rom_next_region(region)) { const char *regiontag = ROMREGION_ISLOADBYNAME(region) ? ROM_GETNAME(region) : NULL; for (rom = rom_first_file(region); rom; rom = rom_next_file(rom)) { /* audit a file */ if (ROMREGION_ISROMDATA(region)) { audit_one_rom(options, rom, regiontag, gamedrv, validation, record); } /* audit a disk */ else if (ROMREGION_ISDISKDATA(region)) { audit_one_disk(options, rom, gamedrv, validation, record); } else { continue; } if (source_is_gamedrv && record->status != AUDIT_STATUS_NOT_FOUND && (allshared || !rom_used_by_parent(gamedrv, rom, NULL))) anyfound = TRUE; record++; } } } } /* if we found nothing, we don't have the set at all */ if (!anyfound && anyrequired) { global_free(*audit); *audit = NULL; records = 0; } global_free(config); return records; }
static void audit_one_rom(core_options *options, const rom_entry *rom, const char *regiontag, const game_driver *gamedrv, UINT32 validation, audit_record *record) { const game_driver *drv; UINT32 crc = 0; UINT8 crcs[4]; int has_crc; /* fill in the record basics */ record->type = AUDIT_FILE_ROM; record->name = ROM_GETNAME(rom); record->exphash = ROM_GETHASHDATA(rom); record->length = 0; record->explength = rom_file_size(rom); /* see if we have a CRC and extract it if so */ has_crc = hash_data_extract_binary_checksum(record->exphash, HASH_CRC, crcs); if (has_crc) crc = (crcs[0] << 24) | (crcs[1] << 16) | (crcs[2] << 8) | crcs[3]; /* find the file and checksum it, getting the file length along the way */ for (drv = gamedrv; drv != NULL; drv = driver_get_clone(drv)) { file_error filerr; mame_file *file; /* open the file if we can */ astring fname(drv->name, PATH_SEPARATOR, ROM_GETNAME(rom)); if (has_crc) filerr = mame_fopen_crc_options(options, libretro_content_directory, fname, crc, OPEN_FLAG_READ | OPEN_FLAG_NO_PRELOAD, &file); else filerr = mame_fopen_options(options, libretro_content_directory, fname, OPEN_FLAG_READ | OPEN_FLAG_NO_PRELOAD, &file); /* if we got it, extract the hash and length */ if (filerr == FILERR_NONE) { hash_data_copy(record->hash, mame_fhash(file, validation)); record->length = (UINT32)mame_fsize(file); mame_fclose(file); break; } } /* if not found, check the region as a backup */ if (record->length == 0 && regiontag != NULL) { file_error filerr; mame_file *file; /* open the file if we can */ astring fname(regiontag, PATH_SEPARATOR, ROM_GETNAME(rom)); if (has_crc) filerr = mame_fopen_crc_options(options, libretro_content_directory, fname, crc, OPEN_FLAG_READ | OPEN_FLAG_NO_PRELOAD, &file); else filerr = mame_fopen_options(options, libretro_content_directory, fname, OPEN_FLAG_READ | OPEN_FLAG_NO_PRELOAD, &file); /* if we got it, extract the hash and length */ if (filerr == FILERR_NONE) { hash_data_copy(record->hash, mame_fhash(file, validation)); record->length = (UINT32)mame_fsize(file); mame_fclose(file); } } /* if we failed to find the file, set the appropriate status */ if (record->length == 0) { const game_driver *parent; /* no good dump */ if (hash_data_has_info(record->exphash, HASH_INFO_NO_DUMP)) set_status(record, AUDIT_STATUS_NOT_FOUND, SUBSTATUS_NOT_FOUND_NODUMP); /* optional ROM */ else if (ROM_ISOPTIONAL(rom)) set_status(record, AUDIT_STATUS_NOT_FOUND, SUBSTATUS_NOT_FOUND_OPTIONAL); /* not found and used by parent */ else if (rom_used_by_parent(gamedrv, rom, &parent)) set_status(record, AUDIT_STATUS_NOT_FOUND, (parent->flags & GAME_IS_BIOS_ROOT) ? SUBSTATUS_NOT_FOUND_BIOS : SUBSTATUS_NOT_FOUND_PARENT); /* just plain old not found */ else set_status(record, AUDIT_STATUS_NOT_FOUND, SUBSTATUS_NOT_FOUND); } /* if we did find the file, do additional verification */ else { /* length mismatch */ if (record->explength != record->length) set_status(record, AUDIT_STATUS_FOUND_INVALID, SUBSTATUS_FOUND_WRONG_LENGTH); /* found but needs a dump */ else if (hash_data_has_info(record->exphash, HASH_INFO_NO_DUMP)) set_status(record, AUDIT_STATUS_GOOD, SUBSTATUS_FOUND_NODUMP); /* incorrect hash */ else if (!hash_data_is_equal(record->exphash, record->hash, 0)) set_status(record, AUDIT_STATUS_FOUND_INVALID, SUBSTATUS_FOUND_BAD_CHECKSUM); /* correct hash but needs a redump */ else if (hash_data_has_info(record->exphash, HASH_INFO_BAD_DUMP)) set_status(record, AUDIT_STATUS_GOOD, SUBSTATUS_GOOD_NEEDS_REDUMP); /* just plain old good */ else set_status(record, AUDIT_STATUS_GOOD, SUBSTATUS_GOOD); } }
static int audit_one_rom(const rom_entry *rom, const game_driver *gamedrv, UINT32 validation, audit_record *record) { const game_driver *drv; const rom_entry *chunk; UINT32 crc = 0; UINT8 crcs[4]; int has_crc; /* fill in the record basics */ record->type = AUDIT_FILE_ROM; record->name = ROM_GETNAME(rom); record->exphash = ROM_GETHASHDATA(rom); /* compute the expected length by summing the chunks */ for (chunk = rom_first_chunk(rom); chunk; chunk = rom_next_chunk(chunk)) record->explength += ROM_GETLENGTH(chunk); /* see if we have a CRC and extract it if so */ has_crc = hash_data_extract_binary_checksum(record->exphash, HASH_CRC, crcs); if (has_crc) crc = (crcs[0] << 24) | (crcs[1] << 16) | (crcs[2] << 8) | crcs[3]; /* find the file and checksum it, getting the file length along the way */ for (drv = gamedrv; drv != NULL; drv = driver_get_clone(drv)) { mame_file_error filerr; mame_file *file; char *fname; /* open the file if we can */ fname = assemble_3_strings(drv->name, PATH_SEPARATOR, ROM_GETNAME(rom)); if (has_crc) filerr = mame_fopen_crc(SEARCHPATH_ROM, fname, crc, OPEN_FLAG_READ, &file); else filerr = mame_fopen(SEARCHPATH_ROM, fname, OPEN_FLAG_READ, &file); free(fname); /* if we got it, extract the hash and length */ if (filerr == FILERR_NONE) { hash_data_copy(record->hash, mame_fhash(file, validation)); record->length = (UINT32)mame_fsize(file); mame_fclose(file); break; } } /* if we failed to find the file, set the appropriate status */ if (drv == NULL) { const game_driver *parent; /* no good dump */ if (hash_data_has_info(record->exphash, HASH_INFO_NO_DUMP)) set_status(record, AUDIT_STATUS_NOT_FOUND, SUBSTATUS_NOT_FOUND_NODUMP); /* optional ROM */ else if (ROM_ISOPTIONAL(rom)) set_status(record, AUDIT_STATUS_NOT_FOUND, SUBSTATUS_NOT_FOUND_OPTIONAL); /* not found and used by parent */ else if (rom_used_by_parent(gamedrv, rom, &parent)) set_status(record, AUDIT_STATUS_NOT_FOUND, (parent->flags & NOT_A_DRIVER) ? SUBSTATUS_NOT_FOUND_BIOS : SUBSTATUS_NOT_FOUND_PARENT); /* just plain old not found */ else set_status(record, AUDIT_STATUS_NOT_FOUND, SUBSTATUS_NOT_FOUND); } /* if we did find the file, do additional verification */ else { /* length mismatch */ if (record->explength != record->length) set_status(record, AUDIT_STATUS_FOUND_INVALID, SUBSTATUS_FOUND_WRONG_LENGTH); /* found but needs a dump */ else if (hash_data_has_info(record->exphash, HASH_INFO_NO_DUMP)) set_status(record, AUDIT_STATUS_GOOD, SUBSTATUS_FOUND_NODUMP); /* incorrect hash */ else if (!hash_data_is_equal(record->exphash, record->hash, 0)) set_status(record, AUDIT_STATUS_FOUND_INVALID, SUBSTATUS_FOUND_BAD_CHECKSUM); /* correct hash but needs a redump */ else if (hash_data_has_info(record->exphash, HASH_INFO_BAD_DUMP)) set_status(record, AUDIT_STATUS_GOOD, SUBSTATUS_GOOD_NEEDS_REDUMP); /* just plain old good */ else set_status(record, AUDIT_STATUS_GOOD, SUBSTATUS_GOOD); } /* return TRUE if we found anything at all */ return (drv != NULL); }