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 a726894
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 58 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
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
21 changes: 12 additions & 9 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\tinyxml2\;$(IncludePath)</IncludePath>
<LibraryPath>$(MSBuildProjectDirectory)\..\3rdParty\zlib\build;$(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\tinyxml2\;$(IncludePath)</IncludePath>
<LibraryPath>$(MSBuildProjectDirectory)\..\3rdParty\zlib\build;$(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\zlibstatic.lib" (
"$(MSBuildProjectDirectory)\..\3rdParty\BuildZlib.bat"
)</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
Expand All @@ -129,8 +129,8 @@
<AdditionalDependencies>zlibstatic.lib;libminizip.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\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
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 a726894

Please sign in to comment.