audit_record *media_auditor::audit_one_disk(const rom_entry *rom) { // allocate and append a new record audit_record &record = m_record_list.append(*global_alloc(audit_record(*rom, audit_record::MEDIA_DISK))); // open the disk emu_file *source_file; chd_file *source; chd_error err = open_disk_image(m_enumerator.options(), &m_enumerator.driver(), rom, &source_file, &source, NULL); // if we succeeded, get the hashes if (err == CHDERR_NONE) { static const UINT8 nullhash[20] = { 0 }; chd_header header = *chd_get_header(source); hash_collection hashes; // if there's an MD5 or SHA1 hash, add them to the output hash if (memcmp(nullhash, header.md5, sizeof(header.md5)) != 0) hashes.add_from_buffer(hash_collection::HASH_MD5, header.md5, sizeof(header.md5)); if (memcmp(nullhash, header.sha1, sizeof(header.sha1)) != 0) hashes.add_from_buffer(hash_collection::HASH_SHA1, header.sha1, sizeof(header.sha1)); // update the actual values record.set_actual(hashes); // close the file and release the source chd_close(source); global_free(source_file); } // compute the final status compute_status(record, rom, err == CHDERR_NONE); return &record; }
audit_record *media_auditor::audit_one_rom(const rom_entry *rom) { // allocate and append a new record audit_record &record = m_record_list.append(*global_alloc(audit_record(*rom, audit_record::MEDIA_ROM))); // see if we have a CRC and extract it if so UINT32 crc = 0; bool has_crc = record.expected_hashes().crc(crc); // find the file and checksum it, getting the file length along the way emu_file file(m_enumerator.options().media_path(), OPEN_FLAG_READ | OPEN_FLAG_NO_PRELOAD); path_iterator path(m_searchpath); astring curpath; while (path.next(curpath, record.name())) { // open the file if we can file_error filerr; if (has_crc) filerr = file.open(curpath, crc); else filerr = file.open(curpath); // if it worked, get the actual length and hashes, then stop if (filerr == FILERR_NONE) { record.set_actual(file.hashes(m_validation), file.size()); break; } } // compute the final status compute_status(record, rom, record.actual_length() != 0); return &record; }
audit_record *media_auditor::audit_one_disk(const rom_entry *rom, const char *locationtag) { // allocate and append a new record audit_record &record = m_record_list.append(*global_alloc(audit_record(*rom, audit_record::MEDIA_DISK))); // open the disk chd_file source; chd_error err = chd_error(open_disk_image(m_enumerator.options(), &m_enumerator.driver(), rom, source, locationtag)); // if we succeeded, get the hashes if (err == CHDERR_NONE) { hash_collection hashes; // if there's a SHA1 hash, add them to the output hash if (source.sha1() != sha1_t::null) hashes.add_sha1(source.sha1()); // update the actual values record.set_actual(hashes); } // compute the final status compute_status(record, rom, err == CHDERR_NONE); return &record; }
media_auditor::summary media_auditor::audit_samples() { // start fresh m_record_list.reset(); int required = 0; int found = 0; // iterate over sample entries samples_device_iterator iterator(m_enumerator.config().root_device()); for (samples_device *device = iterator.first(); device != nullptr; device = iterator.next()) { // by default we just search using the driver name std::string searchpath(m_enumerator.driver().name); // add the alternate path if present samples_iterator iter(*device); if (iter.altbasename() != nullptr) searchpath.append(";").append(iter.altbasename()); // iterate over samples in this entry for (const char *samplename = iter.first(); samplename != nullptr; samplename = iter.next()) { required++; // create a new record audit_record &record = m_record_list.append(*global_alloc(audit_record(samplename, audit_record::MEDIA_SAMPLE))); // look for the files emu_file file(m_enumerator.options().sample_path(), OPEN_FLAG_READ | OPEN_FLAG_NO_PRELOAD); path_iterator path(searchpath.c_str()); std::string curpath; while (path.next(curpath, samplename)) { // attempt to access the file (.flac) or (.wav) osd_file::error filerr = file.open(curpath.c_str(), ".flac"); if (filerr != osd_file::error::NONE) filerr = file.open(curpath.c_str(), ".wav"); if (filerr == osd_file::error::NONE) { record.set_status(audit_record::STATUS_GOOD, audit_record::SUBSTATUS_GOOD); found++; } else record.set_status(audit_record::STATUS_NOT_FOUND, audit_record::SUBSTATUS_NOT_FOUND); } } } if (found == 0 && required > 0) { m_record_list.reset(); return NOTFOUND; } // return a summary return summarize(m_enumerator.driver().name); }
media_auditor::summary media_auditor::audit_samples() { // start fresh m_record_list.reset(); // iterate over sample entries for (const device_t *device = m_enumerator.config().first_device(); device != NULL; device = device->next()) if (device->type() == SAMPLES) { const samples_interface *intf = reinterpret_cast<const samples_interface *>(device->static_config()); if (intf->samplenames != NULL) { // by default we just search using the driver name astring searchpath(m_enumerator.driver().name); // iterate over samples in this entry for (int sampnum = 0; intf->samplenames[sampnum] != NULL; sampnum++) { // starred entries indicate an additional searchpath if (intf->samplenames[sampnum][0] == '*') { searchpath.cat(";").cat(&intf->samplenames[sampnum][1]); continue; } // create a new record audit_record &record = m_record_list.append(*global_alloc(audit_record(intf->samplenames[sampnum], audit_record::MEDIA_SAMPLE))); // look for the files emu_file file(m_enumerator.options().sample_path(), OPEN_FLAG_READ | OPEN_FLAG_NO_PRELOAD); path_iterator path(searchpath); astring curpath; while (path.next(curpath, intf->samplenames[sampnum])) { // attempt to access the file file_error filerr = file.open(curpath); if (filerr == FILERR_NONE) record.set_status(audit_record::STATUS_GOOD, audit_record::SUBSTATUS_GOOD); else record.set_status(audit_record::STATUS_NOT_FOUND, audit_record::SUBSTATUS_NOT_FOUND); } } } } // return a summary return summarize(); }