diff options
Diffstat (limited to 'src/frontend/mame/media_ident.cpp')
-rw-r--r-- | src/frontend/mame/media_ident.cpp | 48 |
1 files changed, 26 insertions, 22 deletions
diff --git a/src/frontend/mame/media_ident.cpp b/src/frontend/mame/media_ident.cpp index fbc160f3bcf..b1a18ed7789 100644 --- a/src/frontend/mame/media_ident.cpp +++ b/src/frontend/mame/media_ident.cpp @@ -238,8 +238,7 @@ void media_identifier::digest_file(std::vector<file_info> &info, char const *pat if (!util::core_file::open(path, OPEN_FLAG_READ, file)) { jed_data jed; - auto ptr = util::core_file_read(std::move(file)); - if (ptr && JEDERR_NONE == jed_parse(*ptr, &jed)) + if (JEDERR_NONE == jed_parse(*file, &jed)) { try { @@ -261,30 +260,35 @@ void media_identifier::digest_file(std::vector<file_info> &info, char const *pat // load the file and process if it opens and has a valid length util::core_file::ptr file; - if (!util::core_file::open(path, OPEN_FLAG_READ, file) && file) + if (util::core_file::open(path, OPEN_FLAG_READ, file) || !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\n", path); + return; } - else + std::uint64_t length; + if (file->length(length)) { - osd_printf_error("%s: error opening file\n", path); + osd_printf_error("%s: error getting file length\n", path); + return; } + util::hash_collection hashes; + hashes.begin(util::hash_collection::HASH_TYPES_CRC_SHA1); + std::uint8_t buf[1024]; + for (std::uint64_t remaining = length; remaining; ) + { + std::size_t const block = std::min<std::uint64_t>(remaining, sizeof(buf)); + std::size_t actual; + if (file->read(buf, block, actual) || !actual) + { + osd_printf_error("%s: error reading file\n", path); + return; + } + remaining -= actual; + hashes.buffer(buf, actual); + } + hashes.end(); + info.emplace_back(path, length, std::move(hashes), file_flavour::RAW); + m_total++; } } |