summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/clifront.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/emu/clifront.cpp')
-rw-r--r--src/emu/clifront.cpp56
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