summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/util/unzip.h
diff options
context:
space:
mode:
author Vas Crabb <cuavas@users.noreply.github.com>2021-08-22 09:06:15 +1000
committer GitHub <noreply@github.com>2021-08-22 09:06:15 +1000
commite8bbea1fc6e94e14768509d322f6c624403ffb36 (patch)
tree74dd1606a900d83de8aecff17a6737af4113308d /src/lib/util/unzip.h
parente319bde5fc3696d7f48f62b15b6366c4377fe5d1 (diff)
formats, osd, util: Started refactoring file I/O stuff. (#8456)
Added more modern generic I/O interfaces with implementation backed by stdio, osd_file and core_file, replacing io_generic. Also replaced core_file's build-in zlib compression with a filter. unzip.cpp, un7z.cpp: Added option to supply abstract I/O interface rather than filename. Converted osd_file, core_file, archive_file, chd_file and device_image_interface to use std::error_condition rather than their own error enums. Allow mounting TI-99 RPK from inside archives.
Diffstat (limited to 'src/lib/util/unzip.h')
-rw-r--r--src/lib/util/unzip.h58
1 files changed, 37 insertions, 21 deletions
diff --git a/src/lib/util/unzip.h b/src/lib/util/unzip.h
index b1ddb7a27d1..2108eadee28 100644
--- a/src/lib/util/unzip.h
+++ b/src/lib/util/unzip.h
@@ -7,19 +7,24 @@
archive file management.
***************************************************************************/
+#ifndef MAME_LIB_UTIL_UNZIP_H
+#define MAME_LIB_UTIL_UNZIP_H
#pragma once
-#ifndef MAME_LIB_UTIL_UNZIP_H
-#define MAME_LIB_UTIL_UNZIP_H
+#include "utilfwd.h"
#include <chrono>
#include <cstdint>
#include <memory>
#include <string>
+#include <string_view>
+#include <system_error>
+#include <type_traits>
namespace util {
+
/***************************************************************************
TYPE DEFINITIONS
***************************************************************************/
@@ -30,12 +35,9 @@ class archive_file
public:
// Error types
- enum class error
+ enum class error : int
{
- NONE = 0,
- OUT_OF_MEMORY,
- FILE_ERROR,
- BAD_SIGNATURE,
+ BAD_SIGNATURE = 1,
DECOMPRESS_ERROR,
FILE_TRUNCATED,
FILE_CORRUPT,
@@ -49,40 +51,54 @@ public:
/* ----- archive file access ----- */
// open a ZIP file and parse its central directory
- static error open_zip(const std::string &filename, ptr &zip);
+ static std::error_condition open_zip(std::string_view filename, ptr &result) noexcept;
+ static std::error_condition open_zip(std::unique_ptr<random_read> &&file, ptr &result) noexcept;
// open a 7Z file and parse its central directory
- static error open_7z(const std::string &filename, ptr &result);
+ static std::error_condition open_7z(std::string_view filename, ptr &result) noexcept;
+ static std::error_condition open_7z(std::unique_ptr<random_read> &&file, ptr &result) noexcept;
// close an archive file (may actually be left open due to caching)
virtual ~archive_file();
// clear out all open files from the cache
- static void cache_clear();
+ static void cache_clear() noexcept;
/* ----- contained file access ----- */
// iterating over files - returns negative on reaching end
- virtual int first_file() = 0;
- virtual int next_file() = 0;
+ virtual int first_file() noexcept = 0;
+ virtual int next_file() noexcept = 0;
// find a file index by crc, filename or both - returns non-negative on match
- virtual int search(std::uint32_t crc) = 0;
- virtual int search(const std::string &filename, bool partialpath) = 0;
- virtual int search(std::uint32_t crc, const std::string &filename, bool partialpath) = 0;
+ virtual int search(std::uint32_t crc) noexcept = 0;
+ virtual int search(std::string_view filename, bool partialpath) noexcept = 0;
+ virtual int search(std::uint32_t crc, std::string_view filename, bool partialpath) noexcept = 0;
// information on most recently found file
- virtual bool current_is_directory() const = 0;
- virtual const std::string &current_name() const = 0;
- virtual std::uint64_t current_uncompressed_length() const = 0;
- virtual std::chrono::system_clock::time_point current_last_modified() const = 0;
- virtual std::uint32_t current_crc() const = 0;
+ virtual bool current_is_directory() const noexcept = 0;
+ virtual const std::string &current_name() const noexcept = 0;
+ virtual std::uint64_t current_uncompressed_length() const noexcept = 0;
+ virtual std::chrono::system_clock::time_point current_last_modified() const noexcept = 0;
+ virtual std::uint32_t current_crc() const noexcept = 0;
// decompress the most recently found file in the ZIP
- virtual error decompress(void *buffer, std::uint32_t length) = 0;
+ virtual std::error_condition decompress(void *buffer, std::size_t length) noexcept = 0;
};
+
+// error category for archive errors
+std::error_category const &archive_category() noexcept;
+inline std::error_condition make_error_condition(archive_file::error err) noexcept { return std::error_condition(int(err), archive_category()); }
+
} // namespace util
+
+namespace std {
+
+template <> struct is_error_condition_enum<util::archive_file::error> : public std::true_type { };
+
+} // namespace std
+
#endif // MAME_LIB_UTIL_UNZIP_H