diff options
author | 2016-03-18 19:22:43 +1100 | |
---|---|---|
committer | 2016-03-18 19:32:10 +1100 | |
commit | 100fa28671af455853a6de1b2d7a3499fa6e185c (patch) | |
tree | e1d89e396fc7bc33b5c3b7b075f8138f9396ce3f /src/emu/clifront.cpp | |
parent | acb27808d4f00b09958e5898966d7917b1debf1a (diff) |
* Remove confusing method from vectorstreams that hide base_ios method (fixes disassembly view)
* Allow std::string to pass through core_file unmolested (reduces temporary allocations)
* Make zip/7z instances of same class with uniform interface
* zippath browsing is broken at the moment
This is another step towards transparent archive support. It's now
possible to access zip and 7z archives with the same code. Nothing is
taking advantage of it yet. There's now some very similar code in
fileio.cpp and clifront.cpp that could be folded at some point.
Diffstat (limited to 'src/emu/clifront.cpp')
-rw-r--r-- | src/emu/clifront.cpp | 56 |
1 files changed, 34 insertions, 22 deletions
diff --git a/src/emu/clifront.cpp b/src/emu/clifront.cpp index 79b53e943c7..ee2777257e2 100644 --- a/src/emu/clifront.cpp +++ b/src/emu/clifront.cpp @@ -15,7 +15,6 @@ #include "audit.h" #include "info.h" #include "unzip.h" -#include "un7z.h" #include "validity.h" #include "sound/samples.h" #include "cliopts.h" @@ -266,7 +265,7 @@ int cli_frontend::execute(int argc, char **argv) m_result = MAMERR_FATALERROR; } - _7z_file::cache_clear(); + util::archive_file::cache_clear(); global_free(manager); return m_result; @@ -1000,7 +999,7 @@ void cli_frontend::verifyroms(const char *gamename) } // clear out any cached files - zip_file::cache_clear(); + util::archive_file::cache_clear(); // return an error if none found if (matched == 0) @@ -1092,7 +1091,7 @@ void cli_frontend::verifysamples(const char *gamename) } // clear out any cached files - zip_file::cache_clear(); + util::archive_file::cache_clear(); // return an error if none found if (matched == 0) @@ -1407,7 +1406,7 @@ void cli_frontend::verifysoftware(const char *gamename) } // clear out any cached files - zip_file::cache_clear(); + util::archive_file::cache_clear(); // return an error if none found if (matched == 0) @@ -1529,7 +1528,7 @@ void cli_frontend::verifysoftlist(const char *gamename) } // clear out any cached files - zip_file::cache_clear(); + util::archive_file::cache_clear(); // return an error if none found if (matched == 0) @@ -1761,9 +1760,9 @@ void media_identifier::identify(const char *filename) if (core_filename_ends_with(filename, ".7z")) { // first attempt to examine it as a valid _7Z file - _7z_file::ptr _7z; - _7z_file::error _7zerr = _7z_file::open(filename, _7z); - if (_7zerr == _7z_file::error::NONE && _7z != nullptr) + util::archive_file::ptr _7z; + util::archive_file::error _7zerr = util::archive_file::open_7z(filename, _7z); + if ((_7zerr == util::archive_file::error::NONE) && _7z) { std::vector<std::uint8_t> data; @@ -1771,14 +1770,14 @@ void media_identifier::identify(const char *filename) for (int i = _7z->first_file(); i >= 0; i = _7z->next_file()) { const std::uint64_t length(_7z->current_uncompressed_length()); - if ((length != 0) && (std::uint32_t(length) == length)) + if (!_7z->current_is_directory() && (length != 0) && (std::uint32_t(length) == length)) { // decompress data into RAM and identify it try { data.resize(std::size_t(length)); _7zerr = _7z->decompress(&data[0], std::uint32_t(length)); - if (_7zerr == _7z_file::error::NONE) + if (_7zerr == util::archive_file::error::NONE) identify_data(_7z->current_name().c_str(), &data[0], length); } catch (...) @@ -1792,30 +1791,43 @@ void media_identifier::identify(const char *filename) // clear out any cached files _7z.reset(); - _7z_file::cache_clear(); + util::archive_file::cache_clear(); } else if (core_filename_ends_with(filename, ".zip")) { // first attempt to examine it as a valid ZIP file - zip_file::ptr zip = nullptr; - zip_file::error ziperr = zip_file::open(filename, zip); - if (ziperr == zip_file::error::NONE && zip != nullptr) + util::archive_file::ptr zip; + util::archive_file::error ziperr = util::archive_file::open_zip(filename, zip); + if (ziperr == util::archive_file::error::NONE && zip) { + std::vector<std::uint8_t> data; + // loop over entries in the ZIP, skipping empty files and directories - for (const zip_file::file_header *entry = zip->first_file(); entry != nullptr; entry = zip->next_file()) - if (entry->uncompressed_length != 0) + for (int i = zip->first_file(); i >= 0; i = zip->next_file()) + { + const std::uint64_t length(zip->current_uncompressed_length()); + if (!zip->current_is_directory() && (length != 0) && (std::uint32_t(length) == length)) { // decompress data into RAM and identify it - dynamic_buffer data(entry->uncompressed_length); - ziperr = zip->decompress(&data[0], entry->uncompressed_length); - if (ziperr == zip_file::error::NONE) - identify_data(entry->filename, &data[0], entry->uncompressed_length); + try + { + data.resize(std::size_t(length)); + ziperr = zip->decompress(&data[0], std::uint32_t(length)); + if (ziperr == util::archive_file::error::NONE) + identify_data(zip->current_name().c_str(), &data[0], length); + } + catch (...) + { + // resizing the buffer could cause a bad_alloc if archive contains large files + } + data.clear(); } + } } // clear out any cached files zip.reset(); - zip_file::cache_clear(); + util::archive_file::cache_clear(); } // otherwise, identify as a raw file |