summaryrefslogtreecommitdiffstatshomepage
path: root/src/frontend
diff options
context:
space:
mode:
author AJR <ajrhacker@users.noreply.github.com>2022-04-19 14:22:04 -0400
committer AJR <ajrhacker@users.noreply.github.com>2022-04-19 14:28:45 -0400
commitb45569d964aa8fae416d2049ba70699f5b2d7837 (patch)
tree522b58375072a7b7f3acc36081de7daa9302417d /src/frontend
parent7780f53ffd266ad7a88058ecda056e5eeea3bc9f (diff)
File handling cleanup
- Remove fgetc, fgets and ptr methods from device_image_interface. - Remove the core_file::buffer method to read an entire file into memory and rewrite emu_file::hashes to not depend on it. - Make core_in_memory_file a final class; now that buffering is gone, core_osd_file no longer subclasses it but a new superclass that retains some common methods. - Rename the offset and length methods used internally in core_file implementations to index and size due to frequent clashes with parameter names. - Convert comments in util/corefile.cpp to C++ style. - Add a new overload of the hash_collection::compute method which hashes data from a random_read stream, reading it into memory one chunk at a time. As a result, the hash_collection::begin and hash_collection::end methods have been removed as obsolete (similar methods are now used internally only). - Enhance error messages for the frontend media identifier when it encounters file errors.
Diffstat (limited to 'src/frontend')
-rw-r--r--src/frontend/mame/media_ident.cpp30
1 files changed, 12 insertions, 18 deletions
diff --git a/src/frontend/mame/media_ident.cpp b/src/frontend/mame/media_ident.cpp
index 549420192c1..7e6665bc765 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.
@@ -260,33 +260,27 @@ 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)
+ std::error_condition err = util::core_file::open(path, OPEN_FLAG_READ, file);
+ if (err || !file)
{
- osd_printf_error("%s: error opening file\n", path);
+ osd_printf_error("%s: error opening file (%s)\n", path, err ? err.message() : std::string("could not allocate pointer"));
return;
}
std::uint64_t length;
- if (file->length(length))
+ err = file->length(length);
+ if (err)
{
- osd_printf_error("%s: error getting file length\n", path);
+ osd_printf_error("%s: error getting file length (%s)\n", path, err.message());
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 actual;
+ err = hashes.compute(*file, 0U, length, actual, util::hash_collection::HASH_TYPES_CRC_SHA1);
+ if (err)
{
- 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);
+ osd_printf_error("%s: error reading file (%s)\n", path, err.message());
+ return;
}
- hashes.end();
info.emplace_back(path, length, std::move(hashes), file_flavour::RAW);
m_total++;
}