diff options
Diffstat (limited to 'src/frontend/mame/media_ident.cpp')
-rw-r--r-- | src/frontend/mame/media_ident.cpp | 84 |
1 files changed, 42 insertions, 42 deletions
diff --git a/src/frontend/mame/media_ident.cpp b/src/frontend/mame/media_ident.cpp index b5ae8ef578a..d09858198ea 100644 --- a/src/frontend/mame/media_ident.cpp +++ b/src/frontend/mame/media_ident.cpp @@ -2,7 +2,7 @@ // copyright-holders:Aaron Giles /*************************************************************************** - media_ident.c + media_ident.cpp Media identify. @@ -11,10 +11,12 @@ #include "emu.h" #include "drivenum.h" #include "media_ident.h" -#include "unzip.h" -#include "jedparse.h" #include "softlist_dev.h" +#include "jedparse.h" +#include "path.h" +#include "unzip.h" + //************************************************************************** // MEDIA IDENTIFIER @@ -102,6 +104,8 @@ void media_identifier::identify_file(const char *name) void media_identifier::identify_data(const char *name, const uint8_t *data, std::size_t length) { + assert(data != nullptr && length != 0); + std::vector<file_info> info; digest_data(info, name, data, length); match_hashes(info); @@ -130,17 +134,17 @@ void media_identifier::collect_files(std::vector<file_info> &info, char const *p } } } - else if (core_filename_ends_with(path, ".7z") || core_filename_ends_with(path, ".zip")) + else if (core_filename_ends_with(path, ".7z") || core_filename_ends_with(path, ".zip") || core_filename_ends_with(path, ".imz")) { // first attempt to examine it as a valid zip/7z file util::archive_file::ptr archive; - util::archive_file::error err; + std::error_condition err; if (core_filename_ends_with(path, ".7z")) err = util::archive_file::open_7z(path, archive); else err = util::archive_file::open_zip(path, archive); - if ((util::archive_file::error::NONE == err) && archive) + if (!err && archive) { std::vector<std::uint8_t> data; @@ -158,10 +162,10 @@ void media_identifier::collect_files(std::vector<file_info> &info, char const *p { data.resize(std::size_t(length)); err = archive->decompress(&data[0], std::uint32_t(length)); - if (util::archive_file::error::NONE == err) + if (!err) digest_data(info, curfile.c_str(), &data[0], length); else - osd_printf_error("%s: error decompressing file\n", curfile); + osd_printf_error("%s: error decompressing file (%s:%d %s)\n", curfile, err.category().name(), err.value(), err.message()); } catch (...) { @@ -205,16 +209,16 @@ void media_identifier::digest_file(std::vector<file_info> &info, char const *pat { // attempt to open as a CHD; fail if not chd_file chd; - chd_error const err = chd.open(path); + std::error_condition const err = chd.open(path); m_total++; - if (err != CHDERR_NONE) + if (err) { - osd_printf_info("%-20sNOT A CHD\n", core_filename_extract_base(path)); + osd_printf_info("%-20s NOT A CHD\n", core_filename_extract_base(path)); m_nonroms++; } else if (!chd.compressed()) { - osd_printf_info("%-20sis a writeable CHD\n", core_filename_extract_base(path)); + osd_printf_info("%-20s is a writeable CHD\n", core_filename_extract_base(path)); } else { @@ -231,12 +235,11 @@ void media_identifier::digest_file(std::vector<file_info> &info, char const *pat if (core_filename_ends_with(path, ".jed")) { // load the file and process if it opens and has a valid length - uint32_t length; - void *data; - if (osd_file::error::NONE == util::core_file::load(path, &data, length)) + util::core_file::ptr file; + if (!util::core_file::open(path, OPEN_FLAG_READ, file)) { jed_data jed; - if (JEDERR_NONE == jed_parse(data, length, &jed)) + if (JEDERR_NONE == jed_parse(*file, &jed)) { try { @@ -246,7 +249,6 @@ void media_identifier::digest_file(std::vector<file_info> &info, char const *pat util::hash_collection hashes; hashes.compute(&tempjed[0], tempjed.size(), util::hash_collection::HASH_TYPES_CRC_SHA1); info.emplace_back(path, tempjed.size(), std::move(hashes), file_flavour::JED); - free(data); m_total++; return; } @@ -254,36 +256,34 @@ void media_identifier::digest_file(std::vector<file_info> &info, char const *pat { } } - free(data); } } // load the file and process if it opens and has a valid length util::core_file::ptr file; - if ((osd_file::error::NONE == util::core_file::open(path, OPEN_FLAG_READ, file)) && file) + std::error_condition err = util::core_file::open(path, OPEN_FLAG_READ, file); + if (err || !file) { - util::hash_collection hashes; - hashes.begin(util::hash_collection::HASH_TYPES_CRC_SHA1); - std::uint8_t buf[1024]; - for (std::uint64_t remaining = file->size(); remaining; ) - { - std::uint32_t const block = std::min<std::uint64_t>(remaining, sizeof(buf)); - if (file->read(buf, block) < block) - { - osd_printf_error("%s: error reading file\n", path); - return; - } - remaining -= block; - hashes.buffer(buf, block); - } - hashes.end(); - info.emplace_back(path, file->size(), std::move(hashes), file_flavour::RAW); - m_total++; + osd_printf_error("%s: error opening file (%s)\n", path, err ? err.message() : std::string("could not allocate pointer")); + return; } - else + std::uint64_t length; + err = file->length(length); + if (err) { - osd_printf_error("%s: error opening file\n", path); + osd_printf_error("%s: error getting file length (%s)\n", path, err.message()); + return; } + util::hash_collection hashes; + std::size_t actual; + err = hashes.compute(*file, 0U, length, actual, util::hash_collection::HASH_TYPES_CRC_SHA1); + if (err) + { + osd_printf_error("%s: error reading file (%s)\n", path, err.message()); + return; + } + info.emplace_back(path, length, std::move(hashes), file_flavour::RAW); + m_total++; } } @@ -301,7 +301,7 @@ void media_identifier::digest_data(std::vector<file_info> &info, char const *nam if (core_filename_ends_with(name, ".jed")) { jed_data jed; - if (JEDERR_NONE == jed_parse(data, length, &jed)) + if (JEDERR_NONE == jed_parse(*util::ram_read(data, length), &jed)) { try { @@ -404,7 +404,7 @@ void media_identifier::print_results(std::vector<file_info> const &info) { for (file_info const &file : info) { - osd_printf_info("%-20s", core_filename_extract_base(file.name())); + osd_printf_info("%-20s ", core_filename_extract_base(file.name())); if (file.matches().empty()) { osd_printf_info("NO MATCH\n"); @@ -416,10 +416,10 @@ void media_identifier::print_results(std::vector<file_info> const &info) for (match_data const &match : file.matches()) { if (!first) - osd_printf_info("%-20s", ""); + osd_printf_info("%-20s ", ""); first = false; osd_printf_info( - "= %s%-20s %-10s %s%s\n", + "= %s%-20s %-10s %s%s\n", match.bad() ? "(BAD) " : "", match.romname().c_str(), match.shortname().c_str(), |