minizip-ng: Stop using compatibility mode

This commit is contained in:
Joshua Vandaële
2025-02-25 11:12:08 +01:00
parent 1dc4dc6b6d
commit 2ed5f16600
10 changed files with 108 additions and 77 deletions

View File

@ -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());
}