summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/fileio.cpp
diff options
context:
space:
mode:
author Antonio Giner <estudio@antonioginer.com>2016-03-18 22:41:17 +0100
committer Antonio Giner <estudio@antonioginer.com>2016-03-18 22:41:17 +0100
commite39daaf5bdcf21d64abf239e1133963643dc6df1 (patch)
tree1f1b5f333e84bf056ce82c27bebdbad933f26c0d /src/emu/fileio.cpp
parent421656e108e7091ee9e1b14c84f0a3f6efc2ad2e (diff)
parentb79020559ea3617b2d6bd4c92041d314045e2938 (diff)
Merge remote-tracking branch 'refs/remotes/mamedev/master'
Diffstat (limited to 'src/emu/fileio.cpp')
-rw-r--r--src/emu/fileio.cpp154
1 files changed, 35 insertions, 119 deletions
diff --git a/src/emu/fileio.cpp b/src/emu/fileio.cpp
index e0d7cdd7772..812f2a7007f 100644
--- a/src/emu/fileio.cpp
+++ b/src/emu/fileio.cpp
@@ -10,7 +10,6 @@
#include "emu.h"
#include "unzip.h"
-#include "un7z.h"
#include "fileio.h"
@@ -146,8 +145,6 @@ emu_file::emu_file(UINT32 openflags)
m_openflags(openflags),
m_zipfile(nullptr),
m_ziplength(0),
- m__7zfile(),
- m__7zlength(0),
m_remove_on_close(false),
m_restrict_to_mediapath(false)
{
@@ -164,8 +161,6 @@ emu_file::emu_file(const char *searchpath, UINT32 openflags)
m_openflags(openflags),
m_zipfile(nullptr),
m_ziplength(0),
- m__7zfile(),
- m__7zlength(0),
m_remove_on_close(false),
m_restrict_to_mediapath(false)
{
@@ -228,12 +223,6 @@ hash_collection &emu_file::hashes(const char *types)
return m_hashes;
// if we have ZIP data, just hash that directly
- if (!m__7zdata.empty())
- {
- m_hashes.compute(&m__7zdata[0], m__7zdata.size(), needed.c_str());
- return m_hashes;
- }
-
if (!m_zipdata.empty())
{
m_hashes.compute(&m_zipdata[0], m_zipdata.size(), needed.c_str());
@@ -338,7 +327,7 @@ osd_file::error emu_file::open_next()
while (m_iterator.next(m_fullpath, m_filename.c_str()))
{
// attempt to open the file directly
- filerr = util::core_file::open(m_fullpath.c_str(), m_openflags, m_file);
+ filerr = util::core_file::open(m_fullpath, m_openflags, m_file);
if (filerr == osd_file::error::NONE)
break;
@@ -386,11 +375,9 @@ osd_file::error emu_file::open_ram(const void *data, UINT32 length)
void emu_file::close()
{
// close files and free memory
- m__7zfile.reset();
m_zipfile.reset();
m_file.reset();
- m__7zdata.clear();
m_zipdata.clear();
if (m_remove_on_close)
@@ -423,10 +410,7 @@ osd_file::error emu_file::compress(int level)
bool emu_file::compressed_file_ready(void)
{
// load the ZIP file now if we haven't yet
- if (m__7zfile != nullptr && load__7zped_file() != osd_file::error::NONE)
- return true;
-
- if (m_zipfile != nullptr && load_zipped_file() != osd_file::error::NONE)
+ if (m_zipfile && (load_zipped_file() != osd_file::error::NONE))
return true;
return false;
@@ -493,9 +477,6 @@ bool emu_file::eof()
UINT64 emu_file::size()
{
// use the ZIP length if present
- if (m__7zfile != nullptr)
- return m__7zlength;
-
if (m_zipfile != nullptr)
return m_ziplength;
@@ -676,44 +657,37 @@ osd_file::error emu_file::attempt_zipped()
m_fullpath = m_fullpath.substr(0, dirsep).append(".zip");
// attempt to open the ZIP file
- zip_file::ptr zip;
- zip_file::error ziperr = zip_file::open(m_fullpath, zip);
+ util::archive_file::ptr zip;
+ util::archive_file::error ziperr = util::archive_file::open_zip(m_fullpath, zip);
// chop the .zip back off the filename before continuing
m_fullpath = m_fullpath.substr(0, dirsep);
// if we failed to open this file, continue scanning
- if (ziperr != zip_file::error::NONE)
+ if (ziperr != util::archive_file::error::NONE)
continue;
+ int header = -1;
+
// see if we can find a file with the right name and (if available) crc
- const zip_file::file_header *header;
- for (header = zip->first_file(); header != nullptr; header = zip->next_file())
- if (zip_filename_match(*header, filename) && (!(m_openflags & OPEN_FLAG_HAS_CRC) || header->crc == m_crc))
- break;
+ if (m_openflags & OPEN_FLAG_HAS_CRC) header = zip->search(m_crc, filename);
// if that failed, look for a file with the right crc, but the wrong filename
- if (header == nullptr && (m_openflags & OPEN_FLAG_HAS_CRC))
- for (header = zip->first_file(); header != nullptr; header = zip->next_file())
- if (header->crc == m_crc && !zip_header_is_path(*header))
- break;
+ if (header < 0 && (m_openflags & OPEN_FLAG_HAS_CRC)) header = zip->search(m_crc);
// if that failed, look for a file with the right name; reporting a bad checksum
// is more helpful and less confusing than reporting "rom not found"
- if (header == nullptr)
- for (header = zip->first_file(); header != nullptr; header = zip->next_file())
- if (zip_filename_match(*header, filename))
- break;
+ if (header < 0) header = zip->search(filename);
// if we got it, read the data
- if (header != nullptr)
+ if (header >= 0)
{
m_zipfile = std::move(zip);
- m_ziplength = header->uncompressed_length;
+ m_ziplength = m_zipfile->current_uncompressed_length();
// build a hash with just the CRC
m_hashes.reset();
- m_hashes.add_crc(header->crc);
+ m_hashes.add_crc(m_zipfile->current_crc());
return (m_openflags & OPEN_FLAG_NO_PRELOAD) ? osd_file::error::NONE : load_zipped_file();
}
@@ -724,64 +698,6 @@ osd_file::error emu_file::attempt_zipped()
//-------------------------------------------------
-// load_zipped_file - load a ZIPped file
-//-------------------------------------------------
-
-osd_file::error emu_file::load_zipped_file()
-{
- assert(m_file == nullptr);
- assert(m_zipdata.empty());
- assert(m_zipfile != nullptr);
-
- // allocate some memory
- m_zipdata.resize(m_ziplength);
-
- // read the data into our buffer and return
- zip_file::error ziperr = m_zipfile->decompress(&m_zipdata[0], m_zipdata.size());
- if (ziperr != zip_file::error::NONE)
- {
- m_zipdata.clear();
- return osd_file::error::FAILURE;
- }
-
- // convert to RAM file
- osd_file::error filerr = util::core_file::open_ram(&m_zipdata[0], m_zipdata.size(), m_openflags, m_file);
- if (filerr != osd_file::error::NONE)
- {
- m_zipdata.clear();
- return osd_file::error::FAILURE;
- }
-
- // close out the ZIP file
- m_zipfile.reset();
- return osd_file::error::NONE;
-}
-
-
-//-------------------------------------------------
-// zip_filename_match - compare zip filename
-// to expected filename, ignoring any directory
-//-------------------------------------------------
-
-bool emu_file::zip_filename_match(const zip_file::file_header &header, const std::string &filename)
-{
- const char *zipfile = header.filename + header.filename_length - filename.length();
- return (zipfile >= header.filename && core_stricmp(filename.c_str(),zipfile) == 0 && (zipfile == header.filename || zipfile[-1] == '/'));
-}
-
-
-//-------------------------------------------------
-// zip_header_is_path - check whether filename
-// in header is a path
-//-------------------------------------------------
-
-bool emu_file::zip_header_is_path(const zip_file::file_header &header)
-{
- const char *zipfile = header.filename + header.filename_length - 1;
- return (zipfile >= header.filename && zipfile[0] == '/');
-}
-
-//-------------------------------------------------
// attempt__7zped - attempt to open a .7z file
//-------------------------------------------------
@@ -810,14 +726,14 @@ osd_file::error emu_file::attempt__7zped()
m_fullpath = m_fullpath.substr(0, dirsep).append(".7z");
// attempt to open the _7Z file
- _7z_file::ptr _7z;
- _7z_file::error _7zerr = _7z_file::open(m_fullpath, _7z);
+ util::archive_file::ptr _7z;
+ util::archive_file::error _7zerr = util::archive_file::open_7z(m_fullpath, _7z);
// chop the ._7z back off the filename before continuing
m_fullpath = m_fullpath.substr(0, dirsep);
// if we failed to open this file, continue scanning
- if (_7zerr != _7z_file::error::NONE)
+ if (_7zerr != util::archive_file::error::NONE)
continue;
int fileno = -1;
@@ -826,21 +742,21 @@ osd_file::error emu_file::attempt__7zped()
if (m_openflags & OPEN_FLAG_HAS_CRC) fileno = _7z->search(m_crc, filename);
// if that failed, look for a file with the right crc, but the wrong filename
- if ((fileno == -1) && (m_openflags & OPEN_FLAG_HAS_CRC)) fileno = _7z->search(m_crc);
+ if ((fileno < 0) && (m_openflags & OPEN_FLAG_HAS_CRC)) fileno = _7z->search(m_crc);
// if that failed, look for a file with the right name; reporting a bad checksum
// is more helpful and less confusing than reporting "rom not found"
- if (fileno == -1) fileno = _7z->search(filename);
+ if (fileno < 0) fileno = _7z->search(filename);
- if (fileno != -1)
+ if (fileno >= 0)
{
- m__7zfile = std::move(_7z);
- m__7zlength = m__7zfile->current_uncompressed_length();
+ m_zipfile = std::move(_7z);
+ m_ziplength = m_zipfile->current_uncompressed_length();
// build a hash with just the CRC
m_hashes.reset();
- m_hashes.add_crc(m__7zfile->current_crc());
- return (m_openflags & OPEN_FLAG_NO_PRELOAD) ? osd_file::error::NONE : load__7zped_file();
+ m_hashes.add_crc(m_zipfile->current_crc());
+ return (m_openflags & OPEN_FLAG_NO_PRELOAD) ? osd_file::error::NONE : load_zipped_file();
}
// close up the _7Z file and try the next level
@@ -850,35 +766,35 @@ osd_file::error emu_file::attempt__7zped()
//-------------------------------------------------
-// load__7zped_file - load a _7Zped file
+// load_zipped_file - load a ZIPped file
//-------------------------------------------------
-osd_file::error emu_file::load__7zped_file()
+osd_file::error emu_file::load_zipped_file()
{
assert(m_file == nullptr);
- assert(m__7zdata.empty());
- assert(m__7zfile);
+ assert(m_zipdata.empty());
+ assert(m_zipfile);
// allocate some memory
- m__7zdata.resize(m__7zlength);
+ m_zipdata.resize(m_ziplength);
// read the data into our buffer and return
- _7z_file::error _7zerr = m__7zfile->decompress(&m__7zdata[0], m__7zdata.size());
- if (_7zerr != _7z_file::error::NONE)
+ auto const ziperr = m_zipfile->decompress(&m_zipdata[0], m_zipdata.size());
+ if (ziperr != util::archive_file::error::NONE)
{
- m__7zdata.clear();
+ m_zipdata.clear();
return osd_file::error::FAILURE;
}
// convert to RAM file
- osd_file::error filerr = util::core_file::open_ram(&m__7zdata[0], m__7zdata.size(), m_openflags, m_file);
+ osd_file::error filerr = util::core_file::open_ram(&m_zipdata[0], m_zipdata.size(), m_openflags, m_file);
if (filerr != osd_file::error::NONE)
{
- m__7zdata.clear();
+ m_zipdata.clear();
return osd_file::error::FAILURE;
}
- // close out the _7Z file
- m__7zfile.reset();
+ // close out the ZIP file
+ m_zipfile.reset();
return osd_file::error::NONE;
}