From 29d3a1aabf2039cf4521121085f4faad2b5a2457 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Sun, 27 Mar 2022 21:06:14 -0400 Subject: [PATCH] Improve Windows support Will now compile out of the box on Windows MSVC. Right now, out of the box game installation is not supported as per unshield being non-functional on Windows, will be porting to Windows or finding a workaround in the near future. --- CMakeLists.txt | 51 ++++++++++++++++++++++++++++++++++++++---- src/compression.cpp | 4 +++- src/gamedata.cpp | 1 + src/installextract.cpp | 11 ++++++++- src/patch.cpp | 1 + 5 files changed, 62 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5c2fa86..960fcc5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,51 @@ project(libxiv) -find_package(fmt) +find_package(fmt QUIET) + +if(TARGET fmt::fmt) + message("Using system library for fmt") + + set(LIBRARIES fmt::fmt ${LIBRARIES}) +else() + message("Using built-in fmt") + + FetchContent_Declare( + fmt + GIT_REPOSITORY https://github.com/fmtlib/fmt + GIT_TAG master + ) + + FetchContent_MakeAvailable(fmt) + + set(LIBRARIES fmt::fmt ${LIBRARIES}) +endif() + +# note: unshield does not work on windows per maintainer notice in README, so we might as well not even attempt to look +# for it. +if(NOT WIN32) + set(LIBRARIES unshield ${LIBRARIES}) +endif() + +find_package(ZLIB QUIET) + +if(TARGET ZLIB::ZLIB) + message("Using system library for zlib") + + set(LIBRARIES ZLIB::ZLIB ${LIBRARIES}) +else() + message("Using built-in zlib") + + FetchContent_Declare( + zlib + GIT_REPOSITORY https://github.com/madler/zlib.git + GIT_TAG master + ) + + FetchContent_MakeAvailable(zlib) + + set(LIBRARIES zlib ${LIBRARIES}) +endif() + add_library(libxiv STATIC src/fiinparser.cpp @@ -14,6 +59,4 @@ add_library(libxiv STATIC src/patch.cpp) target_include_directories(libxiv PUBLIC include PRIVATE src) target_link_libraries(libxiv PUBLIC - unshield - fmt::fmt - z) \ No newline at end of file + ${LIBRARIES}) \ No newline at end of file diff --git a/src/compression.cpp b/src/compression.cpp index 0f7e00b..1d31ac4 100644 --- a/src/compression.cpp +++ b/src/compression.cpp @@ -2,8 +2,10 @@ #include #include +#include -// adopted from https://github.com/ahom/ffxiv_reverse/blob/312a0af8b58929fab48438aceae8da587be9407f/xiv/utils/src/zlib.cpp#L31 +// adopted from +// https://github.com/ahom/ffxiv_reverse/blob/312a0af8b58929fab48438aceae8da587be9407f/xiv/utils/src/zlib.cpp#L31 void zlib::no_header_decompress(uint8_t* in, uint32_t in_size, uint8_t* out, uint32_t out_size) { z_stream strm = {}; strm.avail_in = in_size; diff --git a/src/gamedata.cpp b/src/gamedata.cpp index b670bb7..68bbe0a 100644 --- a/src/gamedata.cpp +++ b/src/gamedata.cpp @@ -6,6 +6,7 @@ #include #include +#include #include // TODO: should be enum? diff --git a/src/installextract.cpp b/src/installextract.cpp index 4268477..494f6cd 100644 --- a/src/installextract.cpp +++ b/src/installextract.cpp @@ -1,5 +1,6 @@ #include "installextract.h" +#ifdef UNSHIELD_SUPPORTED #include #include #include @@ -134,4 +135,12 @@ void extractBootstrapFiles(const std::string_view installer, const std::string_v } fclose(file); -} \ No newline at end of file +} + +#else + +void extractBootstrapFiles(const std::string_view installer, const std::string_view directory) { + // no op +} + +#endif \ No newline at end of file diff --git a/src/patch.cpp b/src/patch.cpp index 0408612..d282dfc 100644 --- a/src/patch.cpp +++ b/src/patch.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include "utility.h" #include "compression.h"