Skip to content

Commit

Permalink
Use minizip instead of minizip-ng
Browse files Browse the repository at this point in the history
  • Loading branch information
Rosalie241 committed Oct 12, 2023
1 parent 40101eb commit 5d71015
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 60 deletions.
13 changes: 3 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,13 @@ jobs:
env:
CL: /MP
DETOURS_TARGET_PROCESSOR: x86
- name: Build minizip-ng
- name: Build zlib
run: |
cmake -S "3rdParty\minizip-ng" -B "3rdParty\minizip-ng\build" -A Win32 `
-DMZ_LZMA=OFF -DMZ_ZSTD=OFF `
-DMZ_BZIP2=OFF -DMZ_PKCRYPT=OFF `
-DMZ_WZAES=OFF -DMZ_SIGNING=OFF `
-DMZ_DECOMPRESS_ONLY=ON `
cmake -S "3rdParty\zlib" -B "3rdParty\zlib\build" -A Win32 `
-DCMAKE_POLICY_DEFAULT_CMP0091=NEW `
-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded `
-DCMAKE_BUILD_TYPE=Release
cmake --build "3rdParty\minizip-ng\build" --config Release
cmake --build "3rdParty\zlib\build" --config Release
- name: Build Spore-ModAPI
run: |
msbuild "3rdParty\Spore-ModAPI\Spore ModAPI" `
Expand Down Expand Up @@ -81,9 +77,6 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: 'true'
- name: Install Packages
run: |
sudo apt-get -y install libminizip-dev build-essential
- name: Prepare Environment
run: |
echo "GIT_REVISION=$(git describe --tags --always)" >> $GITHUB_ENV
Expand Down
20 changes: 0 additions & 20 deletions 3rdParty/BuildMinizipNG.bat

This file was deleted.

16 changes: 16 additions & 0 deletions 3rdParty/BuildZlib.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@echo off
set ZLIB_CUR_DIR=%~dp0

set ZLIB_DIR=%ZLIB_CUR_DIR%\zlib

rmdir /S /Q "%ZLIB_DIR%\build"
mkdir "%ZLIB_DIR%\build"

set PATH=%PATH%;C:\Program Files\CMake\bin

cmake -S "%ZLIB_DIR%" -B "%ZLIB_DIR%\build" -A Win32 ^
-DCMAKE_POLICY_DEFAULT_CMP0091=NEW ^
-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded ^
-DCMAKE_BUILD_TYPE=Release

cmake --build "%ZLIB_DIR%\build" --config Release
2 changes: 1 addition & 1 deletion BuildRelease.bat
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ mkdir "%OBJ_DIR%\SporeModLoader\ModLibs"
mkdir "%OBJ_DIR%\SporeModLoader\SporeModManager"

CALL "%THIRDPARTY_DIR%\BuildDetours.bat"
CALL "%THIRDPARTY_DIR%\BuildMinizipNG.bat"
CALL "%THIRDPARTY_DIR%\BuildZlib.bat"
CALL "%THIRDPARTY_DIR%\BuildSporeModAPI.bat"

msbuild "%CUR_DIR%\SporeModLoader" ^
Expand Down
33 changes: 17 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@ BINARY_DIR = bin
SOURCE_DIR = SporeModManager

PKG_CONFIG := pkg-config
CC := gcc
CXX := g++
CFLAGS := -O2 -flto \
-I$(THIRDPARTY_DIR)/zlib \
-I$(THIRDPARTY_DIR)/zlib/contrib/minizip
CXXFLAGS := -std=c++17 \
-O2 -flto \
-I$(SOURCE_DIR) \
-I$(THIRDPARTY_DIR)/tinyxml2 \
-I$(THIRDPARTY_DIR)/minizip-ng
-I$(THIRDPARTY_DIR)/zlib \
-I$(THIRDPARTY_DIR)/zlib/contrib/minizip

LDFLAGS := -s

Expand All @@ -25,14 +30,18 @@ OBJECT_FILES = \
$(SOURCE_DIR)/SporeModManagerHelpers/String.o \
$(SOURCE_DIR)/SporeModManagerHelpers/UI.o \
$(SOURCE_DIR)/SporeModManagerHelpers/Zip.o \
$(THIRDPARTY_DIR)/tinyxml2/tinyxml2.o
$(THIRDPARTY_DIR)/tinyxml2/tinyxml2.o \
$(THIRDPARTY_DIR)/zlib/contrib/minizip/unzip.o \
$(THIRDPARTY_DIR)/zlib/contrib/minizip/ioapi.o

THIRDPARTY_LIBRARIES = \
$(THIRDPARTY_DIR)/minizip-ng/build/libminizip.a \
$(THIRDPARTY_DIR)/minizip-ng/build/_deps/zlib-build/libz.a
$(THIRDPARTY_DIR)/zlib/build/libz.a

THIRDPARTY_BUILD_DIRS = \
$(THIRDPARTY_DIR)/minizip-ng/build
$(THIRDPARTY_DIR)/zlib/build

%.o: %.c
$(CC) -c $< -o $@ $(CFLAGS)

%.o: %.cpp
$(CXX) -c $< -o $@ $(CXXFLAGS)
Expand All @@ -42,20 +51,12 @@ all: $(BINARY_DIR)/SporeModManager
$(BINARY_DIR):
mkdir -p $@

$(THIRDPARTY_DIR)/minizip-ng/build/libminizip.a:
cmake -S $(THIRDPARTY_DIR)/minizip-ng -B $(THIRDPARTY_DIR)/minizip-ng/build \
-DMZ_LZMA=OFF -DMZ_ZSTD=OFF \
-DMZ_BZIP2=OFF -DMZ_PKCRYPT=OFF \
-DMZ_WZAES=OFF -DMZ_SIGNING=OFF \
-DMZ_DECOMPRESS_ONLY=ON -DMZ_ICONV=OFF \
-DMZ_OPENSSL=OFF -DMZ_LIBBSD=OFF \
-DMZ_FORCE_FETCH_LIBS=ON -DMZ_FETCH_LIBS=ON \
$(THIRDPARTY_DIR)/zlib/build/libz.a:
cmake -S $(THIRDPARTY_DIR)/zlib -B $(THIRDPARTY_DIR)/zlib/build \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_COMPILER=$(CC) \
-G "Unix Makefiles"
$(MAKE) -C $(THIRDPARTY_DIR)/minizip-ng/build

$(THIRDPARTY_DIR)/minizip-ng/build/_deps/zlib-build/libz.a: $(THIRDPARTY_DIR)/minizip-ng/build/libminizip.a
$(MAKE) -C $(THIRDPARTY_DIR)/zlib/build

$(BINARY_DIR)/SporeModManager: $(THIRDPARTY_LIBRARIES) $(BINARY_DIR) $(OBJECT_FILES)
$(CXX) $(OBJECT_FILES) -o $@ $(THIRDPARTY_LIBRARIES) $(LDFLAGS)
Expand Down
23 changes: 13 additions & 10 deletions SporeModManager/SporeModManager.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,16 @@
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>$(MSBuildProjectDirectory);$(MSBuildProjectDirectory)\..\3rdParty\minizip-ng\;$(MSBuildProjectDirectory)\..\3rdParty\tinyxml2\;$(IncludePath)</IncludePath>
<LibraryPath>$(MSBuildProjectDirectory)\..\3rdParty\minizip-ng\build\Release;$(MSBuildProjectDirectory)\..\3rdParty\minizip-ng\build\_deps\zlib-build\Release;$(LibraryPath)</LibraryPath>
<IncludePath>$(MSBuildProjectDirectory);$(MSBuildProjectDirectory)\..\3rdParty\zlib\;$(MSBuildProjectDirectory)\..\3rdParty\zlib\build\;$(MSBuildProjectDirectory)\..\3rdParty\zlib\contrib\minizip;$(MSBuildProjectDirectory)\..\3rdParty\tinyxml2\;$(IncludePath)</IncludePath>
<LibraryPath>$(MSBuildProjectDirectory)\..\3rdParty\zlib\build\Release;$(LibraryPath)</LibraryPath>
<OutDir>$(MSBuildProjectDirectory)\Bin\$(Configuration)\</OutDir>
<IntDir>$(MSBuildProjectDirectory)\Obj\$(Configuration)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(MSBuildProjectDirectory)\Bin\$(Configuration)\</OutDir>
<IncludePath>$(MSBuildProjectDirectory);$(MSBuildProjectDirectory)\..\3rdParty\minizip-ng\;$(MSBuildProjectDirectory)\..\3rdParty\tinyxml2\;$(IncludePath)</IncludePath>
<LibraryPath>$(MSBuildProjectDirectory)\..\3rdParty\minizip-ng\build\Release\;$(MSBuildProjectDirectory)\..\3rdParty\minizip-ng\build\_deps\zlib-build\Release;$(LibraryPath)</LibraryPath>
<IncludePath>$(MSBuildProjectDirectory);$(MSBuildProjectDirectory)\..\3rdParty\zlib\;$(MSBuildProjectDirectory)\..\3rdParty\zlib\build\;$(MSBuildProjectDirectory)\..\3rdParty\zlib\contrib\minizip;$(MSBuildProjectDirectory)\..\3rdParty\tinyxml2\;$(IncludePath)</IncludePath>
<LibraryPath>$(MSBuildProjectDirectory)\..\3rdParty\zlib\build\Release;$(LibraryPath)</LibraryPath>
<IntDir>$(MSBuildProjectDirectory)\Obj\$(Configuration)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
Expand All @@ -102,11 +102,11 @@
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>zlibstatic.lib;libminizip.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>zlibstatic.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PreBuildEvent>
<Command>if NOT EXIST "$(MSBuildProjectDirectory)\..\3rdParty\minizip-ng\build\Release\libminizip.lib" (
"$(MSBuildProjectDirectory)\..\3rdParty\BuildMinizipNG.bat"
<Command>if NOT EXIST "$(MSBuildProjectDirectory)\..\3rdParty\zlib\build\Release\zlibstatic.lib" (
"$(MSBuildProjectDirectory)\..\3rdParty\BuildZlib.bat"
)</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
Expand All @@ -126,11 +126,11 @@
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>zlibstatic.lib;libminizip.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>zlibstatic.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PreBuildEvent>
<Command>if NOT EXIST "$(MSBuildProjectDirectory)\..\3rdParty\minizip-ng\build\Release\libminizip.lib" (
"$(MSBuildProjectDirectory)\..\3rdParty\BuildMinizipNG.bat"
<Command>if NOT EXIST "$(MSBuildProjectDirectory)\..\3rdParty\zlib\build\Release\zlibstatic.lib" (
"$(MSBuildProjectDirectory)\..\3rdParty\BuildZlib.bat"
)</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
Expand Down Expand Up @@ -164,6 +164,8 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\3rdParty\tinyxml2\tinyxml2.cpp" />
<ClCompile Include="..\3rdParty\zlib\contrib\minizip\unzip.c" />
<ClCompile Include="..\3rdParty\zlib\contrib\minizip\ioapi.c" />
<ClCompile Include="main.cpp" />
<ClCompile Include="SporeModManager.cpp" />
<ClCompile Include="SporeModManagerHelpers\FileVersion.cpp" />
Expand All @@ -176,6 +178,7 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\3rdParty\tinyxml2\tinyxml2.h" />
<ClInclude Include="..\3rdParty\zlib\contrib\minizip\unzip.h" />
<ClInclude Include="SporeModManager.hpp" />
<ClInclude Include="SporeModManagerHelpers.hpp" />
</ItemGroup>
Expand Down
9 changes: 9 additions & 0 deletions SporeModManager/SporeModManager.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@
<ClCompile Include="SporeModManagerHelpers\FileVersion.cpp">
<Filter>Source Files\SporeModManagerHelpers</Filter>
</ClCompile>
<ClCompile Include="..\3rdParty\zlib\contrib\minizip\unzip.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\3rdParty\zlib\contrib\minizip\ioapi.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\3rdParty\tinyxml2\tinyxml2.h">
Expand All @@ -59,5 +65,8 @@
<ClInclude Include="SporeModManagerHelpers.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\3rdParty\zlib\contrib\minizip\unzip.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
6 changes: 3 additions & 3 deletions SporeModManager/SporeModManagerHelpers/Zip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <fstream>
#include <cstring>

#include <mz_compat.h>
#include <unzip.h>

using namespace SporeModManagerHelpers;

Expand Down Expand Up @@ -87,7 +87,7 @@ bool Zip::ExtractFile(ZipFile zipFile, std::filesystem::path file, std::filesyst
std::ofstream outputFileStream;

// try to find file in zip
if (unzLocateFile(zipFile, file.string().c_str(), nullptr) != UNZ_OK)
if (unzLocateFile(zipFile, file.string().c_str(), 2) != UNZ_OK)
{
std::cerr << "Failed to find \"" << file << "\" in zip file!" << std::endl;
return false;
Expand Down Expand Up @@ -145,7 +145,7 @@ bool Zip::ExtractFile(ZipFile zipFile, std::filesystem::path file, char** outBuf
size_t bytesRead = 0;

// try to find file in zip
if (unzLocateFile(zipFile, file.string().c_str(), nullptr) != UNZ_OK)
if (unzLocateFile(zipFile, file.string().c_str(), 2) != UNZ_OK)
{
std::cerr << "Failed to find \"" << file << "\" in zip file!" << std::endl;
return false;
Expand Down

0 comments on commit 5d71015

Please sign in to comment.