diff --git a/CMakeModules/DuckStationDependencies.cmake b/CMakeModules/DuckStationDependencies.cmake index fe3df91ae..f7e592bb0 100644 --- a/CMakeModules/DuckStationDependencies.cmake +++ b/CMakeModules/DuckStationDependencies.cmake @@ -20,6 +20,7 @@ find_package(lunasvg 2.4.1 REQUIRED) find_package(cpuinfo REQUIRED) find_package(DiscordRPC 3.4.0 REQUIRED) find_package(SoundTouch 2.3.3 REQUIRED) +find_package(libzip 1.11.1 REQUIRED) if(NOT WIN32) find_package(CURL REQUIRED) diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 53799dc22..d0c339cc9 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -140,7 +140,7 @@ target_precompile_headers(core PRIVATE "pch.h") target_include_directories(core PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/..") target_include_directories(core PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/..") target_link_libraries(core PUBLIC Threads::Threads common util) -target_link_libraries(core PRIVATE xxhash imgui minizip rapidyaml rcheevos cpuinfo::cpuinfo ZLIB::ZLIB Zstd::Zstd) +target_link_libraries(core PRIVATE xxhash imgui rapidyaml rcheevos cpuinfo::cpuinfo ZLIB::ZLIB Zstd::Zstd libzip::zip) if(CPU_ARCH_X64) target_compile_definitions(core PUBLIC "ENABLE_RECOMPILER=1" "ENABLE_NEWREC=1" "ENABLE_MMAP_FASTMEM=1") diff --git a/src/core/cheats.cpp b/src/core/cheats.cpp index d39953736..cc6099858 100644 --- a/src/core/cheats.cpp +++ b/src/core/cheats.cpp @@ -16,10 +16,10 @@ #include "common/error.h" #include "common/file_system.h" #include "common/log.h" -#include "common/minizip_helpers.h" #include "common/path.h" #include "common/small_string.h" #include "common/string_util.h" +#include "common/zip_helpers.h" #include "IconsEmoji.h" #include "IconsFontAwesome5.h" @@ -99,29 +99,31 @@ class CheatArchive public: ~CheatArchive() { - if (m_unz_file) - unzClose(m_unz_file); + // zip has to be destroyed before data + m_zip.reset(); + m_data.deallocate(); } - ALWAYS_INLINE bool IsOpen() const { return (m_unz_file != nullptr); } + ALWAYS_INLINE bool IsOpen() const { return static_cast(m_zip); } bool Open(const char* name) { - if (m_unz_file) + if (m_zip) return true; - std::optional> data = Host::ReadResourceFile(name, false); + Error error; + std::optional> data = Host::ReadResourceFile(name, false, &error); if (!data.has_value()) { - ERROR_LOG("Failed to read cheat archive {}.", name); + ERROR_LOG("Failed to read cheat archive {}: {}", name, error.GetDescription()); return false; } m_data = std::move(data.value()); - m_unz_file = MinizipHelpers::OpenUnzMemoryFile(m_data.data(), m_data.size()); - if (!m_unz_file) [[unlikely]] + m_zip = ZipHelpers::OpenManagedZipBuffer(m_data.data(), m_data.size(), 0, false, &error); + if (!m_zip) [[unlikely]] { - ERROR_LOG("Failed to open cheat archive {}.", name); + ERROR_LOG("Failed to open cheat archive {}: {}", name, error.GetDescription()); return false; } @@ -131,7 +133,7 @@ public: std::optional ReadFile(const char* name) const { Error error; - std::optional ret = MinizipHelpers::ReadZipFileToString(m_unz_file, name, false, &error); + std::optional ret = ZipHelpers::ReadFileInZipToString(m_zip.get(), name, true, &error); if (!ret.has_value()) DEV_LOG("Failed to read {} from zip: {}", name, error.GetDescription()); return ret; @@ -141,7 +143,7 @@ private: // Maybe counter-intuitive, but it ends up faster for reading a single game's cheats if we keep a // copy of the archive in memory, as opposed to reading from disk. DynamicHeapArray m_data; - unzFile m_unz_file = nullptr; + ZipHelpers::ManagedZipT m_zip; }; } // namespace diff --git a/src/core/core.props b/src/core/core.props index 674147160..f841d9719 100644 --- a/src/core/core.props +++ b/src/core/core.props @@ -22,4 +22,10 @@ %(AdditionalIncludeDirectories);$(SolutionDir)dep\vixl\include + + + + %(AdditionalDependencies);cpuinfo.lib;zip.lib + + diff --git a/src/core/core.vcxproj b/src/core/core.vcxproj index 11f87d0ea..14819076d 100644 --- a/src/core/core.vcxproj +++ b/src/core/core.vcxproj @@ -174,9 +174,6 @@ {bb08260f-6fbc-46af-8924-090ee71360c6} - - {8bda439c-6358-45fb-9994-2ff083babe06} - {e4357877-d459-45c7-b8f6-dcbb587bb528} @@ -214,7 +211,6 @@ ZYDIS_DISABLE_ENCODER;ZYDIS_DISABLE_AVX512;ZYDIS_DISABLE_KNC;ZYDIS_STATIC_BUILD;ZYCORE_STATIC_BUILD;%(PreprocessorDefinitions) %(AdditionalIncludeDirectories);$(SolutionDir)dep\zydis\include;$(SolutionDir)dep\zydis\dependencies\zycore\include - %(AdditionalIncludeDirectories);$(SolutionDir)dep\minizip\include $(IntDir)/%(RelativeDir)/ Use pch.h diff --git a/src/util/util.props b/src/util/util.props index e984ee4e4..d6203cd79 100644 --- a/src/util/util.props +++ b/src/util/util.props @@ -25,7 +25,7 @@ %(AdditionalIncludeDirectories);$(DepsIncludeDir)SDL2;$(DepsIncludeDir)spirv_cross - %(AdditionalDependencies);cpuinfo.lib;freetype.lib;jpeg.lib;libpng16.lib;libwebp.lib;lunasvg.lib;SDL2.lib;soundtouch.lib;zlib.lib;zstd.lib + %(AdditionalDependencies);freetype.lib;jpeg.lib;libpng16.lib;libwebp.lib;lunasvg.lib;SDL2.lib;soundtouch.lib;zlib.lib;zstd.lib @@ -44,6 +44,7 @@ +