summaryrefslogtreecommitdiff
path: root/Source/Core
diff options
context:
space:
mode:
authorJoshua Vandaƫle <joshua@vandaele.software>2025-02-25 11:12:08 +0100
committerJoshua Vandaƫle <joshua@vandaele.software>2025-05-22 12:51:55 +0200
commit2ed5f166009bf64ee1b1a222c9bb0ca7d6b638da (patch)
treedd6ae7c9e163ba22e65e55deddb4c31bb1b15e84 /Source/Core
parent1dc4dc6b6d660f29226bdff29d0b1bae122dda7e (diff)
minizip-ng: Stop using compatibility mode
Diffstat (limited to 'Source/Core')
-rw-r--r--Source/Core/Common/CMakeLists.txt2
-rw-r--r--Source/Core/Common/MinizipUtil.h16
-rw-r--r--Source/Core/Core/HW/GBACore.cpp28
-rw-r--r--Source/Core/DiscIO/CMakeLists.txt2
-rw-r--r--Source/Core/DiscIO/VolumeVerifier.cpp28
-rw-r--r--Source/Core/UICommon/CMakeLists.txt2
-rw-r--r--Source/Core/UICommon/ResourcePack/ResourcePack.cpp89
7 files changed, 101 insertions, 66 deletions
diff --git a/Source/Core/Common/CMakeLists.txt b/Source/Core/Common/CMakeLists.txt
index aca142b9cd..bbc3721a19 100644
--- a/Source/Core/Common/CMakeLists.txt
+++ b/Source/Core/Common/CMakeLists.txt
@@ -176,7 +176,7 @@ PUBLIC
enet::enet
fmt::fmt
MbedTLS::mbedtls
- minizip::minizip
+ minizip-ng::minizip-ng
sfml-network
PRIVATE
diff --git a/Source/Core/Common/MinizipUtil.h b/Source/Core/Common/MinizipUtil.h
index bf681cb8cf..c8e529effe 100644
--- a/Source/Core/Common/MinizipUtil.h
+++ b/Source/Core/Common/MinizipUtil.h
@@ -5,7 +5,9 @@
#include <algorithm>
-#include <unzip.h>
+#include <mz.h>
+#include <mz_zip.h>
+#include <mz_zip_rw.h>
#include "Common/CommonTypes.h"
#include "Common/ScopeGuard.h"
@@ -13,14 +15,14 @@
namespace Common
{
// Reads all of the current file. destination must be big enough to fit the whole file.
-inline bool ReadFileFromZip(unzFile file, u8* destination, u64 len)
+inline bool ReadFileFromZip(void* zip_reader, u8* destination, u64 len)
{
const u64 MAX_BUFFER_SIZE = 65535;
- if (unzOpenCurrentFile(file) != UNZ_OK)
+ if (mz_zip_reader_entry_open(zip_reader) != MZ_OK)
return false;
- Common::ScopeGuard guard{[&] { unzCloseCurrentFile(file); }};
+ Common::ScopeGuard guard{[&] { mz_zip_reader_entry_close(zip_reader); }};
u64 bytes_to_go = len;
while (bytes_to_go > 0)
@@ -28,7 +30,7 @@ inline bool ReadFileFromZip(unzFile file, u8* destination, u64 len)
// NOTE: multiples of 4G can't cause read_len == 0 && bytes_to_go > 0, as MAX_BUFFER_SIZE is
// small.
const u32 read_len = static_cast<u32>(std::min(bytes_to_go, MAX_BUFFER_SIZE));
- const int rv = unzReadCurrentFile(file, destination, read_len);
+ const int rv = mz_zip_reader_entry_read(zip_reader, destination, read_len);
if (rv < 0)
return false;
@@ -37,11 +39,11 @@ inline bool ReadFileFromZip(unzFile file, u8* destination, u64 len)
destination += bytes_read;
}
- return unzEndOfFile(file) == 1;
+ return bytes_to_go == 0;
}
template <typename ContiguousContainer>
-bool ReadFileFromZip(unzFile file, ContiguousContainer* destination)
+bool ReadFileFromZip(void* file, ContiguousContainer* destination)
{
return ReadFileFromZip(file, reinterpret_cast<u8*>(destination->data()), destination->size());
}
diff --git a/Source/Core/Core/HW/GBACore.cpp b/Source/Core/Core/HW/GBACore.cpp
index 9e81914524..cd379a17a6 100644
--- a/Source/Core/Core/HW/GBACore.cpp
+++ b/Source/Core/Core/HW/GBACore.cpp
@@ -12,6 +12,10 @@
#include <mgba/core/timing.h>
#include <mgba/internal/gb/gb.h>
#include <mgba/internal/gba/gba.h>
+#include <mz.h>
+#include <mz_strm.h>
+#include <mz_zip.h>
+#include <mz_zip_rw.h>
#include "AudioCommon/AudioCommon.h"
#include "Common/ChunkFile.h"
@@ -88,21 +92,26 @@ static VFile* OpenROM_Archive(const char* path)
static VFile* OpenROM_Zip(const char* path)
{
VFile* vf{};
- unzFile zip = unzOpen(path);
- if (!zip)
+ void* zip_reader = mz_zip_reader_create();
+ if (!zip_reader)
+ return {};
+
+ Common::ScopeGuard file_guard{[&] { mz_zip_reader_delete(&zip_reader); }};
+
+ if (mz_zip_reader_open_file(zip_reader, path) != MZ_OK)
return nullptr;
+
do
{
- unz_file_info info{};
- if (unzGetCurrentFileInfo(zip, &info, nullptr, 0, nullptr, 0, nullptr, 0) != UNZ_OK ||
- !info.uncompressed_size)
+ mz_zip_file* info;
+ if (mz_zip_reader_entry_get_info(zip_reader, &info) != MZ_OK || !info->uncompressed_size)
continue;
- std::vector<u8> buffer(info.uncompressed_size);
- if (!Common::ReadFileFromZip(zip, &buffer))
+ std::vector<u8> buffer(info->uncompressed_size);
+ if (!Common::ReadFileFromZip(zip_reader, &buffer))
continue;
- vf = VFileMemChunk(buffer.data(), info.uncompressed_size);
+ vf = VFileMemChunk(buffer.data(), info->uncompressed_size);
if (mCoreIsCompatible(vf) == mPLATFORM_GBA)
{
vf->seek(vf, 0, SEEK_SET);
@@ -111,8 +120,7 @@ static VFile* OpenROM_Zip(const char* path)
vf->close(vf);
vf = nullptr;
- } while (unzGoToNextFile(zip) == UNZ_OK);
- unzClose(zip);
+ } while (mz_zip_reader_goto_next_entry(zip_reader) != MZ_END_OF_LIST);
return vf;
}
diff --git a/Source/Core/DiscIO/CMakeLists.txt b/Source/Core/DiscIO/CMakeLists.txt
index 11fb5cf52a..884f3de4f2 100644
--- a/Source/Core/DiscIO/CMakeLists.txt
+++ b/Source/Core/DiscIO/CMakeLists.txt
@@ -75,7 +75,7 @@ PUBLIC
PRIVATE
fmt::fmt
- minizip::minizip
+ minizip-ng::minizip-ng
pugixml
ZLIB::ZLIB
)
diff --git a/Source/Core/DiscIO/VolumeVerifier.cpp b/Source/Core/DiscIO/VolumeVerifier.cpp
index db42bf6874..40e71d48dd 100644
--- a/Source/Core/DiscIO/VolumeVerifier.cpp
+++ b/Source/Core/DiscIO/VolumeVerifier.cpp
@@ -13,8 +13,11 @@
#include <unordered_set>
#include <mbedtls/md5.h>
+#include <mz.h>
+#include <mz_strm.h>
+#include <mz_zip.h>
+#include <mz_zip_rw.h>
#include <pugixml.hpp>
-#include <unzip.h>
#include "Common/Align.h"
#include "Common/Assert.h"
@@ -157,25 +160,28 @@ RedumpVerifier::DownloadStatus RedumpVerifier::DownloadDatfile(const std::string
std::vector<u8> RedumpVerifier::ReadDatfile(const std::string& system)
{
- unzFile file = unzOpen(GetPathForSystem(system).c_str());
- if (!file)
+ void* zip_reader = mz_zip_reader_create();
+ if (!zip_reader)
return {};
- Common::ScopeGuard file_guard{[&] { unzClose(file); }};
+ Common::ScopeGuard file_guard{[&] { mz_zip_reader_delete(&zip_reader); }};
+
+ if (mz_zip_reader_open_file(zip_reader, GetPathForSystem(system).c_str()) != MZ_OK)
+ return {};
// Check that the zip file contains exactly one file
- if (unzGoToFirstFile(file) != UNZ_OK)
+ if (mz_zip_reader_goto_first_entry(zip_reader) != MZ_OK)
return {};
- if (unzGoToNextFile(file) != UNZ_END_OF_LIST_OF_FILE)
+ if (mz_zip_reader_goto_next_entry(zip_reader) != MZ_END_OF_LIST)
return {};
// Read the file
- if (unzGoToFirstFile(file) != UNZ_OK)
+ if (mz_zip_reader_goto_first_entry(zip_reader) != MZ_OK)
return {};
- unz_file_info file_info;
- unzGetCurrentFileInfo(file, &file_info, nullptr, 0, nullptr, 0, nullptr, 0);
- std::vector<u8> data(file_info.uncompressed_size);
- if (!Common::ReadFileFromZip(file, &data))
+ mz_zip_file* file_info;
+ mz_zip_reader_entry_get_info(zip_reader, &file_info);
+ std::vector<u8> data(file_info->uncompressed_size);
+ if (!Common::ReadFileFromZip(zip_reader, data.data(), file_info->uncompressed_size))
return {};
return data;
diff --git a/Source/Core/UICommon/CMakeLists.txt b/Source/Core/UICommon/CMakeLists.txt
index 7200bd500f..d57fdb811a 100644
--- a/Source/Core/UICommon/CMakeLists.txt
+++ b/Source/Core/UICommon/CMakeLists.txt
@@ -28,7 +28,7 @@ PUBLIC
common
core
cpp-optparse
- minizip::minizip
+ minizip-ng::minizip-ng
pugixml
PRIVATE
diff --git a/Source/Core/UICommon/ResourcePack/ResourcePack.cpp b/Source/Core/UICommon/ResourcePack/ResourcePack.cpp
index 94c8a367ad..73f271c6bc 100644
--- a/Source/Core/UICommon/ResourcePack/ResourcePack.cpp
+++ b/Source/Core/UICommon/ResourcePack/ResourcePack.cpp
@@ -8,7 +8,9 @@
#include <mz.h>
#include <mz_os.h>
-#include <unzip.h>
+#include <mz_strm.h>
+#include <mz_zip.h>
+#include <mz_zip_rw.h>
#include "Common/CommonPaths.h"
#include "Common/Contains.h"
@@ -28,34 +30,45 @@ constexpr char TEXTURE_PATH[] = HIRES_TEXTURES_DIR DIR_SEP;
ResourcePack::ResourcePack(const std::string& path) : m_path(path)
{
- auto file = unzOpen(path.c_str());
- Common::ScopeGuard file_guard{[&] { unzClose(file); }};
+ void* zip_reader = mz_zip_reader_create();
+ if (!zip_reader)
+ {
+ m_valid = false;
+ m_error = "Failed to create zip reader";
+ return;
+ }
+
+ Common::ScopeGuard file_guard{[&] { mz_zip_reader_delete(&zip_reader); }};
- if (file == nullptr)
+ if (mz_zip_reader_open_file(zip_reader, path.c_str()) != MZ_OK)
{
m_valid = false;
m_error = "Failed to open resource pack";
return;
}
- if (unzLocateFile(file, "manifest.json", 0) == UNZ_END_OF_LIST_OF_FILE)
+ if (mz_zip_reader_locate_entry(zip_reader, "manifest.json", 0) != MZ_OK)
{
m_valid = false;
m_error = "Resource pack is missing a manifest.";
return;
}
- unz_file_info64 manifest_info{};
- unzGetCurrentFileInfo64(file, &manifest_info, nullptr, 0, nullptr, 0, nullptr, 0);
+ mz_zip_file* manifest_info;
+ if (mz_zip_reader_entry_get_info(zip_reader, &manifest_info) != MZ_OK)
+ {
+ m_valid = false;
+ m_error = "Failed to access manifest.json";
+ return;
+ }
- std::string manifest_contents(manifest_info.uncompressed_size, '\0');
- if (!Common::ReadFileFromZip(file, &manifest_contents))
+ std::string manifest_contents(manifest_info->uncompressed_size, '\0');
+ if (!Common::ReadFileFromZip(zip_reader, &manifest_contents))
{
m_valid = false;
m_error = "Failed to read manifest.json";
return;
}
- unzCloseCurrentFile(file);
m_manifest = std::make_shared<Manifest>(manifest_contents);
if (!m_manifest->IsValid())
@@ -65,14 +78,14 @@ ResourcePack::ResourcePack(const std::string& path) : m_path(path)
return;
}
- if (unzLocateFile(file, "logo.png", 0) != UNZ_END_OF_LIST_OF_FILE)
+ if (mz_zip_reader_locate_entry(zip_reader, "logo.png", 0) == MZ_OK)
{
- unz_file_info64 logo_info{};
- unzGetCurrentFileInfo64(file, &logo_info, nullptr, 0, nullptr, 0, nullptr, 0);
+ mz_zip_file* logo_info;
+ mz_zip_reader_entry_get_info(zip_reader, &logo_info);
- m_logo_data.resize(logo_info.uncompressed_size);
+ m_logo_data.resize(logo_info->uncompressed_size);
- if (!Common::ReadFileFromZip(file, &m_logo_data))
+ if (!Common::ReadFileFromZip(zip_reader, &m_logo_data))
{
m_valid = false;
m_error = "Failed to read logo.png";
@@ -80,21 +93,20 @@ ResourcePack::ResourcePack(const std::string& path) : m_path(path)
}
}
- unzGoToFirstFile(file);
+ mz_zip_reader_goto_first_entry(zip_reader);
do
{
std::string filename(256, '\0');
- unz_file_info64 texture_info{};
- unzGetCurrentFileInfo64(file, &texture_info, filename.data(), static_cast<u16>(filename.size()),
- nullptr, 0, nullptr, 0);
+ mz_zip_file* texture_info;
+ mz_zip_reader_entry_get_info(zip_reader, &texture_info);
- if (!filename.starts_with("textures/") || texture_info.uncompressed_size == 0)
+ if (!filename.starts_with("textures/") || texture_info->uncompressed_size == 0)
continue;
// If a texture is compressed and the manifest doesn't state that, abort.
- if (!m_manifest->IsCompressed() && texture_info.compression_method != 0)
+ if (!m_manifest->IsCompressed() && texture_info->compression_method != 0)
{
m_valid = false;
m_error = "Texture " + filename + " is compressed!";
@@ -102,7 +114,7 @@ ResourcePack::ResourcePack(const std::string& path) : m_path(path)
}
m_textures.push_back(filename.substr(9));
- } while (unzGoToNextFile(file) != UNZ_END_OF_LIST_OF_FILE);
+ } while (mz_zip_reader_goto_next_entry(zip_reader) != MZ_END_OF_LIST);
}
bool ResourcePack::IsValid() const
@@ -143,29 +155,35 @@ bool ResourcePack::Install(const std::string& path)
return false;
}
- auto file = unzOpen(m_path.c_str());
- if (file == nullptr)
+ void* zip_reader = mz_zip_reader_create();
+ if (!zip_reader)
+ {
+ m_valid = false;
+ m_error = "Failed to create zip reader";
+ return false;
+ }
+
+ Common::ScopeGuard file_guard{[&] { mz_zip_reader_delete(&zip_reader); }};
+
+ if (mz_zip_reader_open_file(zip_reader, m_path.c_str()) != MZ_OK)
{
m_valid = false;
m_error = "Failed to open resource pack";
return false;
}
- Common::ScopeGuard file_guard{[&] { unzClose(file); }};
- if (unzGoToFirstFile(file) != MZ_OK)
+ if (mz_zip_reader_goto_first_entry(zip_reader) != MZ_OK)
return false;
- std::string texture_zip_path;
do
{
- texture_zip_path.resize(UINT16_MAX + 1, '\0');
- unz_file_info64 texture_info{};
- if (unzGetCurrentFileInfo64(file, &texture_info, texture_zip_path.data(), UINT16_MAX, nullptr,
- 0, nullptr, 0) != MZ_OK)
+ mz_zip_file* texture_info{};
+ if (mz_zip_reader_entry_get_info(zip_reader, &texture_info) != MZ_OK)
{
return false;
}
- TruncateToCString(&texture_zip_path);
+
+ const std::string texture_zip_path = texture_info->filename;
const std::string texture_zip_path_prefix = "textures/";
if (!texture_zip_path.starts_with(texture_zip_path_prefix))
@@ -203,9 +221,9 @@ bool ResourcePack::Install(const std::string& path)
return false;
}
- const size_t data_size = static_cast<size_t>(texture_info.uncompressed_size);
+ const size_t data_size = static_cast<size_t>(texture_info->uncompressed_size);
auto data = std::make_unique<u8[]>(data_size);
- if (!Common::ReadFileFromZip(file, data.get(), data_size))
+ if (!Common::ReadFileFromZip(zip_reader, data.get(), data_size))
{
m_error = "Failed to read texture " + texture;
return false;
@@ -222,7 +240,8 @@ bool ResourcePack::Install(const std::string& path)
m_error = "Failed to write " + texture;
return false;
}
- } while (unzGoToNextFile(file) == MZ_OK);
+
+ } while (mz_zip_reader_goto_next_entry(zip_reader) == MZ_OK);
SetInstalled(*this, true);
return true;