summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/util/un7z.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/util/un7z.h')
-rw-r--r--src/lib/util/un7z.h152
1 files changed, 46 insertions, 106 deletions
diff --git a/src/lib/util/un7z.h b/src/lib/util/un7z.h
index d2c0c9f098a..d2d2e18e25f 100644
--- a/src/lib/util/un7z.h
+++ b/src/lib/util/un7z.h
@@ -1,5 +1,5 @@
// license:BSD-3-Clause
-// copyright-holders:Aaron Giles
+// copyright-holders:Aaron Giles, Vas Crabb
/***************************************************************************
un7z.h
@@ -12,132 +12,72 @@
#pragma once
-#ifndef __UN_7Z_H__
-#define __UN_7Z_H__
+#ifndef MAME_LIB_UTIL_UN7Z_H
+#define MAME_LIB_UTIL_UN7Z_H
#include "osdcore.h"
-#include "lzma/C/7z.h"
-#include "lzma/C/7zCrc.h"
-#include "lzma/C/7zVersion.h"
-
-
-void *SZipAlloc(void *p, size_t size);
-void SZipFree(void *p, void *address);
-void *SZipAllocTemp(void *p, size_t size);
-void SZipFreeTemp(void *p, void *address);
-
-struct CSzFile
-{
- long _7z_currfpos;
- UINT64 _7z_length;
- osd_file * _7z_osdfile; /* OSD file handle */
-
-};
-
-
-struct CFileSeqInStream
-{
- ISeqInStream s;
- CSzFile file;
-};
-
-void FileSeqInStream_CreateVTable(CFileSeqInStream *p);
-
-
-struct CFileInStream
-{
- ISeekInStream s;
- CSzFile file;
-};
-
-void FileInStream_CreateVTable(CFileInStream *p);
-
-
-struct CFileOutStream
-{
- ISeqOutStream s;
- CSzFile file;
-} ;
-
-void FileOutStream_CreateVTable(CFileOutStream *p);
-
-
-
-/***************************************************************************
- CONSTANTS
-***************************************************************************/
-
-
-/* Error types */
-enum _7z_error
-{
- _7ZERR_NONE = 0,
- _7ZERR_OUT_OF_MEMORY,
- _7ZERR_FILE_ERROR,
- _7ZERR_BAD_SIGNATURE,
- _7ZERR_DECOMPRESS_ERROR,
- _7ZERR_FILE_TRUNCATED,
- _7ZERR_FILE_CORRUPT,
- _7ZERR_UNSUPPORTED,
- _7ZERR_BUFFER_TOO_SMALL
-};
-
+#include <cstdint>
+#include <memory>
+#include <string>
/***************************************************************************
TYPE DEFINITIONS
***************************************************************************/
-/* describes an open _7Z file */
-struct _7z_file
+// describes an open _7Z file
+class _7z_file
{
- const char * filename; /* copy of _7Z filename (for caching) */
-
- int curr_file_idx; /* current file index */
- UINT64 uncompressed_length; /* current file uncompressed length */
- UINT64 crc; /* current file crc */
-
- CFileInStream archiveStream;
- CLookToRead lookStream;
- CSzArEx db;
- SRes res;
- ISzAlloc allocImp;
- ISzAlloc allocTempImp;
- bool inited;
-
- // cached stuff for solid blocks
- UInt32 blockIndex;// = 0xFFFFFFFF; /* it can have any value before first call (if outBuffer = 0) */
- Byte *outBuffer;// = 0; /* it must be 0 before first call for each new archive. */
- size_t outBufferSize;// = 0; /* it can have any value before first call (if outBuffer = 0) */
-};
+public:
+ // Error types
+ enum class error
+ {
+ NONE = 0,
+ OUT_OF_MEMORY,
+ FILE_ERROR,
+ BAD_SIGNATURE,
+ DECOMPRESS_ERROR,
+ FILE_TRUNCATED,
+ FILE_CORRUPT,
+ UNSUPPORTED,
+ BUFFER_TOO_SMALL
+ };
+ typedef std::unique_ptr<_7z_file> ptr;
-/***************************************************************************
- FUNCTION PROTOTYPES
-***************************************************************************/
+ virtual ~_7z_file();
-/* ----- _7Z file access ----- */
+ /* ----- 7Z file access ----- */
-/* open a _7Z file and parse its central directory */
-_7z_error _7z_file_open(const char *filename, _7z_file **_7z);
+ // open a 7Z file and parse its central directory
+ static error open(const std::string &filename, ptr &result);
-/* close a _7Z file (may actually be left open due to caching) */
-void _7z_file_close(_7z_file *_7z);
+ // clear out all open 7Z files from the cache
+ static void cache_clear();
-/* clear out all open _7Z files from the cache */
-void _7z_file_cache_clear(void);
+ /* ----- contained file access ----- */
-/* ----- contained file access ----- */
+ // iterating over files
+ virtual int first_file() = 0;
+ virtual int next_file() = 0;
-/* find a file index by crc, filename or both */
-int _7z_search_crc_match(_7z_file *new_7z, UINT32 crc, const char *search_filename, int search_filename_length, bool matchcrc, bool matchname);
+ // find a file index by crc, filename or both
+ virtual int search(std::uint32_t crc) = 0;
+ virtual int search(const std::string &filename) = 0;
+ virtual int search(std::uint32_t crc, const std::string &filename) = 0;
-/* decompress the most recently found file in the _7Z */
-_7z_error _7z_file_decompress(_7z_file *_7z, void *buffer, UINT32 length);
+ // information on most recently found file
+ virtual const std::string &current_name() const = 0;
+ virtual std::uint64_t current_uncompressed_length() const = 0;
+ virtual std::uint32_t current_crc() const = 0;
+ // decompress the most recently found file in the _7Z
+ virtual error decompress(void *buffer, std::uint32_t length) = 0;
+
+};
-#endif /* __UN_7Z_H__ */
+#endif // MAME_LIB_UTIL_UN7Z_H