Skip to content

Commit d8638c9

Browse files
JMC47Motobug
authored andcommitted
Merge pull request dolphin-emu#13379 from JoshuaVandaele/system-ng
Use minizip-ng in non-compatibility mode
1 parent 3adc475 commit d8638c9

File tree

10 files changed

+108
-77
lines changed

10 files changed

+108
-77
lines changed

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -691,8 +691,8 @@ dolphin_find_optional_system_library_pkgconfig(ZSTD libzstd>=1.4.0 zstd::zstd Ex
691691

692692
dolphin_find_optional_system_library_pkgconfig(ZLIB zlib>=1.3.1 ZLIB::ZLIB Externals/zlib-ng)
693693

694-
dolphin_find_optional_system_library_pkgconfig(MINIZIP
695-
"minizip>=4.0.4" minizip::minizip Externals/minizip-ng
694+
dolphin_find_optional_system_library_pkgconfig(minizip-ng
695+
"minizip-ng>=4.0.4" minizip-ng::minizip-ng Externals/minizip-ng
696696
)
697697

698698
dolphin_find_optional_system_library(LZO Externals/LZO)

Externals/minizip-ng/CMakeLists.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ include(CheckIncludeFile)
66
add_library(minizip STATIC
77
minizip-ng/mz.h
88
# minizip-ng/compat/crypt.h
9-
minizip-ng/compat/ioapi.c
10-
minizip-ng/compat/ioapi.h
11-
minizip-ng/compat/unzip.c
12-
minizip-ng/compat/unzip.h
9+
# minizip-ng/compat/ioapi.c
10+
# minizip-ng/compat/ioapi.h
11+
# minizip-ng/compat/unzip.c
12+
# minizip-ng/compat/unzip.h
1313
# minizip-ng/compat/zip.c
1414
# minizip-ng/compat/zip.h
1515
minizip-ng/mz_crypt.c
@@ -93,4 +93,4 @@ endif()
9393

9494
target_link_libraries(minizip PUBLIC ZLIB::ZLIB)
9595

96-
add_library(minizip::minizip ALIAS minizip)
96+
add_library(minizip-ng::minizip-ng ALIAS minizip)

Externals/minizip-ng/minizip-ng.vcxproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
</ClCompile>
2424
</ItemDefinitionGroup>
2525
<ItemGroup>
26-
<ClCompile Include="minizip-ng\compat\ioapi.c" />
27-
<ClCompile Include="minizip-ng\compat\unzip.c" />
2826
<ClCompile Include="minizip-ng\mz_crypt.c" />
2927
<ClCompile Include="minizip-ng\mz_os.c" />
3028
<ClCompile Include="minizip-ng\mz_os_win32.c" />
@@ -39,8 +37,6 @@
3937
</ItemGroup>
4038
<ItemGroup>
4139
<ClInclude Include="minizip-ng\mz.h" />
42-
<ClCompile Include="minizip-ng\compat\ioapi.h" />
43-
<ClCompile Include="minizip-ng\compat\unzip.h" />
4440
<ClInclude Include="minizip-ng\mz_crypt.h" />
4541
<ClInclude Include="minizip-ng\mz_os.h" />
4642
<ClInclude Include="minizip-ng\mz_strm.h" />

Source/Core/Common/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ PUBLIC
176176
enet::enet
177177
fmt::fmt
178178
MbedTLS::mbedtls
179-
minizip::minizip
179+
minizip-ng::minizip-ng
180180
sfml-network
181181

182182
PRIVATE

Source/Core/Common/MinizipUtil.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,32 @@
55

66
#include <algorithm>
77

8-
#include <unzip.h>
8+
#include <mz.h>
9+
#include <mz_zip.h>
10+
#include <mz_zip_rw.h>
911

1012
#include "Common/CommonTypes.h"
1113
#include "Common/ScopeGuard.h"
1214

1315
namespace Common
1416
{
1517
// Reads all of the current file. destination must be big enough to fit the whole file.
16-
inline bool ReadFileFromZip(unzFile file, u8* destination, u64 len)
18+
inline bool ReadFileFromZip(void* zip_reader, u8* destination, u64 len)
1719
{
1820
const u64 MAX_BUFFER_SIZE = 65535;
1921

20-
if (unzOpenCurrentFile(file) != UNZ_OK)
22+
if (mz_zip_reader_entry_open(zip_reader) != MZ_OK)
2123
return false;
2224

23-
Common::ScopeGuard guard{[&] { unzCloseCurrentFile(file); }};
25+
Common::ScopeGuard guard{[&] { mz_zip_reader_entry_close(zip_reader); }};
2426

2527
u64 bytes_to_go = len;
2628
while (bytes_to_go > 0)
2729
{
2830
// NOTE: multiples of 4G can't cause read_len == 0 && bytes_to_go > 0, as MAX_BUFFER_SIZE is
2931
// small.
3032
const u32 read_len = static_cast<u32>(std::min(bytes_to_go, MAX_BUFFER_SIZE));
31-
const int rv = unzReadCurrentFile(file, destination, read_len);
33+
const int rv = mz_zip_reader_entry_read(zip_reader, destination, read_len);
3234
if (rv < 0)
3335
return false;
3436

@@ -37,11 +39,11 @@ inline bool ReadFileFromZip(unzFile file, u8* destination, u64 len)
3739
destination += bytes_read;
3840
}
3941

40-
return unzEndOfFile(file) == 1;
42+
return bytes_to_go == 0;
4143
}
4244

4345
template <typename ContiguousContainer>
44-
bool ReadFileFromZip(unzFile file, ContiguousContainer* destination)
46+
bool ReadFileFromZip(void* file, ContiguousContainer* destination)
4547
{
4648
return ReadFileFromZip(file, reinterpret_cast<u8*>(destination->data()), destination->size());
4749
}

Source/Core/Core/HW/GBACore.cpp

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
#include <mgba/core/timing.h>
1313
#include <mgba/internal/gb/gb.h>
1414
#include <mgba/internal/gba/gba.h>
15+
#include <mz.h>
16+
#include <mz_strm.h>
17+
#include <mz_zip.h>
18+
#include <mz_zip_rw.h>
1519

1620
#include "AudioCommon/AudioCommon.h"
1721
#include "Common/ChunkFile.h"
@@ -88,21 +92,26 @@ static VFile* OpenROM_Archive(const char* path)
8892
static VFile* OpenROM_Zip(const char* path)
8993
{
9094
VFile* vf{};
91-
unzFile zip = unzOpen(path);
92-
if (!zip)
95+
void* zip_reader = mz_zip_reader_create();
96+
if (!zip_reader)
97+
return {};
98+
99+
Common::ScopeGuard file_guard{[&] { mz_zip_reader_delete(&zip_reader); }};
100+
101+
if (mz_zip_reader_open_file(zip_reader, path) != MZ_OK)
93102
return nullptr;
103+
94104
do
95105
{
96-
unz_file_info info{};
97-
if (unzGetCurrentFileInfo(zip, &info, nullptr, 0, nullptr, 0, nullptr, 0) != UNZ_OK ||
98-
!info.uncompressed_size)
106+
mz_zip_file* info;
107+
if (mz_zip_reader_entry_get_info(zip_reader, &info) != MZ_OK || !info->uncompressed_size)
99108
continue;
100109

101-
std::vector<u8> buffer(info.uncompressed_size);
102-
if (!Common::ReadFileFromZip(zip, &buffer))
110+
std::vector<u8> buffer(info->uncompressed_size);
111+
if (!Common::ReadFileFromZip(zip_reader, &buffer))
103112
continue;
104113

105-
vf = VFileMemChunk(buffer.data(), info.uncompressed_size);
114+
vf = VFileMemChunk(buffer.data(), info->uncompressed_size);
106115
if (mCoreIsCompatible(vf) == mPLATFORM_GBA)
107116
{
108117
vf->seek(vf, 0, SEEK_SET);
@@ -111,8 +120,7 @@ static VFile* OpenROM_Zip(const char* path)
111120

112121
vf->close(vf);
113122
vf = nullptr;
114-
} while (unzGoToNextFile(zip) == UNZ_OK);
115-
unzClose(zip);
123+
} while (mz_zip_reader_goto_next_entry(zip_reader) != MZ_END_OF_LIST);
116124
return vf;
117125
}
118126

Source/Core/DiscIO/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ PUBLIC
7575

7676
PRIVATE
7777
fmt::fmt
78-
minizip::minizip
78+
minizip-ng::minizip-ng
7979
pugixml
8080
ZLIB::ZLIB
8181
)

Source/Core/DiscIO/VolumeVerifier.cpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@
1313
#include <unordered_set>
1414

1515
#include <mbedtls/md5.h>
16+
#include <mz.h>
17+
#include <mz_strm.h>
18+
#include <mz_zip.h>
19+
#include <mz_zip_rw.h>
1620
#include <pugixml.hpp>
17-
#include <unzip.h>
1821

1922
#include "Common/Align.h"
2023
#include "Common/Assert.h"
@@ -157,25 +160,28 @@ RedumpVerifier::DownloadStatus RedumpVerifier::DownloadDatfile(const std::string
157160

158161
std::vector<u8> RedumpVerifier::ReadDatfile(const std::string& system)
159162
{
160-
unzFile file = unzOpen(GetPathForSystem(system).c_str());
161-
if (!file)
163+
void* zip_reader = mz_zip_reader_create();
164+
if (!zip_reader)
162165
return {};
163166

164-
Common::ScopeGuard file_guard{[&] { unzClose(file); }};
167+
Common::ScopeGuard file_guard{[&] { mz_zip_reader_delete(&zip_reader); }};
168+
169+
if (mz_zip_reader_open_file(zip_reader, GetPathForSystem(system).c_str()) != MZ_OK)
170+
return {};
165171

166172
// Check that the zip file contains exactly one file
167-
if (unzGoToFirstFile(file) != UNZ_OK)
173+
if (mz_zip_reader_goto_first_entry(zip_reader) != MZ_OK)
168174
return {};
169-
if (unzGoToNextFile(file) != UNZ_END_OF_LIST_OF_FILE)
175+
if (mz_zip_reader_goto_next_entry(zip_reader) != MZ_END_OF_LIST)
170176
return {};
171177

172178
// Read the file
173-
if (unzGoToFirstFile(file) != UNZ_OK)
179+
if (mz_zip_reader_goto_first_entry(zip_reader) != MZ_OK)
174180
return {};
175-
unz_file_info file_info;
176-
unzGetCurrentFileInfo(file, &file_info, nullptr, 0, nullptr, 0, nullptr, 0);
177-
std::vector<u8> data(file_info.uncompressed_size);
178-
if (!Common::ReadFileFromZip(file, &data))
181+
mz_zip_file* file_info;
182+
mz_zip_reader_entry_get_info(zip_reader, &file_info);
183+
std::vector<u8> data(file_info->uncompressed_size);
184+
if (!Common::ReadFileFromZip(zip_reader, data.data(), file_info->uncompressed_size))
179185
return {};
180186

181187
return data;

Source/Core/UICommon/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ PUBLIC
2828
common
2929
core
3030
cpp-optparse
31-
minizip::minizip
31+
minizip-ng::minizip-ng
3232
pugixml
3333

3434
PRIVATE

0 commit comments

Comments
 (0)