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)
8892static 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
0 commit comments