diff options
Diffstat (limited to 'src/emu/clifront.cpp')
-rw-r--r-- | src/emu/clifront.cpp | 99 |
1 files changed, 36 insertions, 63 deletions
diff --git a/src/emu/clifront.cpp b/src/emu/clifront.cpp index 7c6c974cce7..975c3c8f71b 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) @@ -1618,7 +1617,7 @@ void cli_frontend::execute_commands(const char *exename) { // attempt to open the output file emu_file file(OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS); - if (file.open(emulator_info::get_configname(), ".ini") != FILERR_NONE) + if (file.open(emulator_info::get_configname(), ".ini") != osd_file::error::NONE) throw emu_fatalerror("Unable to create file %s.ini\n",emulator_info::get_configname()); // generate the updated INI @@ -1626,7 +1625,7 @@ void cli_frontend::execute_commands(const char *exename) ui_options ui_opts; emu_file file_ui(OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS); - if (file_ui.open("ui.ini") != FILERR_NONE) + if (file_ui.open("ui.ini") != osd_file::error::NONE) throw emu_fatalerror("Unable to create file ui.ini\n"); // generate the updated INI @@ -1758,71 +1757,45 @@ void media_identifier::identify(const char *filename) } // if that failed, and the filename ends with .zip, identify as a ZIP file - if (core_filename_ends_with(filename, ".7z")) + if (core_filename_ends_with(filename, ".7z") || core_filename_ends_with(filename, ".zip")) { // first attempt to examine it as a valid _7Z file - _7z_file *_7z = nullptr; - _7z_error _7zerr = _7z_file_open(filename, &_7z); - if (_7zerr == _7ZERR_NONE && _7z != nullptr) + util::archive_file::ptr archive; + util::archive_file::error err; + if (core_filename_ends_with(filename, ".7z")) + err = util::archive_file::open_7z(filename, archive); + else + err = util::archive_file::open_zip(filename, archive); + if ((err == util::archive_file::error::NONE) && archive) { + std::vector<std::uint8_t> data; + // loop over entries in the .7z, skipping empty files and directories - for (int i = 0; i < _7z->db.db.NumFiles; i++) + for (int i = archive->first_file(); i >= 0; i = archive->next_file()) { - const CSzFileItem *f = _7z->db.db.Files + i; - _7z->curr_file_idx = i; - int namelen = SzArEx_GetFileNameUtf16(&_7z->db, i, nullptr); - std::vector<UINT16> temp(namelen); - dynamic_buffer temp2(namelen+1); - UINT8* temp3 = &temp2[0]; - memset(temp3, 0x00, namelen); - SzArEx_GetFileNameUtf16(&_7z->db, i, &temp[0]); - // crude, need real UTF16->UTF8 conversion ideally - for (int j=0;j<namelen;j++) - { - temp3[j] = (UINT8)temp[j]; - } - - if (!(f->IsDir) && (f->Size != 0)) + const std::uint64_t length(archive->current_uncompressed_length()); + if (!archive->current_is_directory() && (length != 0) && (std::uint32_t(length) == length)) { // decompress data into RAM and identify it - dynamic_buffer data(f->Size); - _7zerr = _7z_file_decompress(_7z, &data[0], f->Size); - if (_7zerr == _7ZERR_NONE) - identify_data((const char*)&temp2[0], &data[0], f->Size); + try + { + data.resize(std::size_t(length)); + err = archive->decompress(&data[0], std::uint32_t(length)); + if (err == util::archive_file::error::NONE) + identify_data(archive->current_name().c_str(), &data[0], length); + } + catch (...) + { + // resizing the buffer could cause a bad_alloc if archive contains large files + } + data.clear(); } } - - // close up - _7z_file_close(_7z); - } - - // clear out any cached files - _7z_file_cache_clear(); - } - else if (core_filename_ends_with(filename, ".zip")) - { - // first attempt to examine it as a valid ZIP file - zip_file *zip = nullptr; - zip_error ziperr = zip_file_open(filename, &zip); - if (ziperr == ZIPERR_NONE && zip != nullptr) - { - // loop over entries in the ZIP, skipping empty files and directories - for (const zip_file_header *entry = zip_file_first_file(zip); entry != nullptr; entry = zip_file_next_file(zip)) - if (entry->uncompressed_length != 0) - { - // decompress data into RAM and identify it - dynamic_buffer data(entry->uncompressed_length); - ziperr = zip_file_decompress(zip, &data[0], entry->uncompressed_length); - if (ziperr == ZIPERR_NONE) - identify_data(entry->filename, &data[0], entry->uncompressed_length); - } - - // close up - zip_file_close(zip); } // clear out any cached files - zip_file_cache_clear(); + archive.reset(); + util::archive_file::cache_clear(); } // otherwise, identify as a raw file @@ -1880,8 +1853,8 @@ void media_identifier::identify_file(const char *name) // load the file and process if it opens and has a valid length UINT32 length; void *data; - const file_error filerr = util::core_file::load(name, &data, length); - if (filerr == FILERR_NONE && length > 0) + const osd_file::error filerr = util::core_file::load(name, &data, length); + if (filerr == osd_file::error::NONE && length > 0) { identify_data(name, reinterpret_cast<UINT8 *>(data), length); osd_free(data); |