diff --git a/CMakeLists.txt b/CMakeLists.txt index 3dc7791..07176c1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -91,6 +91,10 @@ else() set(LINK_TYPE "MT") endif() +if (BUILD_STORMLIB) + add_definitions(-DUSE_STORMLIB) +endif() + if(NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC") set(CMAKE_CXX_FLAGS_DEBUG "-g") set(CMAKE_CXX_FLAGS_RELEASE "-O3") @@ -166,7 +170,7 @@ if (BUILD_STORMLIB) set(STORM_BUILD_TESTS OFF) set(STORMLIB_DIR ${CMAKE_CURRENT_SOURCE_DIR}/lib/StormLib) add_subdirectory(${STORMLIB_DIR}) - if(NOT USE_STANDALONE) + if(USE_STANDALONE) if((CMAKE_SYSTEM_NAME MATCHES "Windows") AND ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")) include(../cmake/HandleCompilerRT.cmake) find_compiler_rt_library(builtins CLANG_RT_BUILTINS_LIBRARY) @@ -177,10 +181,10 @@ if (BUILD_STORMLIB) else() target_link_libraries(${PROJECT_NAME} PRIVATE storm) endif() + if (CMAKE_SYSTEM_NAME STREQUAL "NintendoSwitch") + target_compile_definitions(storm PRIVATE -D_POSIX_C_SOURCE=200809L) + endif() endif () - if (CMAKE_SYSTEM_NAME STREQUAL "NintendoSwitch") - target_compile_definitions(storm PRIVATE -D_POSIX_C_SOURCE=200809L) - endif() endif() # Link YamlCpp diff --git a/src/archive/SWrapper.cpp b/src/archive/SWrapper.cpp index 087d401..3993700 100644 --- a/src/archive/SWrapper.cpp +++ b/src/archive/SWrapper.cpp @@ -13,6 +13,9 @@ SWrapper::SWrapper(const std::string& path) { } int32_t SWrapper::CreateArchive() { +#ifndef USE_STORMLIB + throw std::runtime_error("StormLib is not enabled. Cannot create archive"); +#else if(fs::exists(mPath)) { fs::remove(mPath); } @@ -23,9 +26,13 @@ int32_t SWrapper::CreateArchive() { } return 0; +#endif } bool SWrapper::CreateFile(const std::string& path, std::vector data) { +#ifndef USE_STORMLIB + throw std::runtime_error("StormLib is not enabled. Cannot create file"); +#else if(Companion::Instance != nullptr && Companion::Instance->IsDebug()){ SPDLOG_INFO("Creating debug file: debug/{}", path); std::string dpath = "debug/" + path; @@ -74,9 +81,13 @@ bool SWrapper::CreateFile(const std::string& path, std::vector data) { } return true; +#endif } int32_t SWrapper::Close(void) { +#ifndef USE_STORMLIB + throw std::runtime_error("StormLib is not enabled. Cannot close archive"); +#else if(this->hMpq == nullptr) { SPDLOG_ERROR("Archive already closed"); return -1; @@ -86,4 +97,5 @@ int32_t SWrapper::Close(void) { return -1; } return 0; +#endif } diff --git a/src/archive/SWrapper.h b/src/archive/SWrapper.h index 5182775..76909b5 100644 --- a/src/archive/SWrapper.h +++ b/src/archive/SWrapper.h @@ -2,8 +2,10 @@ #include #include -#include #include "BinaryWrapper.h" +#ifdef USE_STORMLIB +#include +#endif class SWrapper : public BinaryWrapper { public: @@ -12,6 +14,8 @@ class SWrapper : public BinaryWrapper { int32_t CreateArchive(void) override; bool CreateFile(const std::string& path, std::vector data) override; int32_t Close(void) override; +#ifdef USE_STORMLIB private: HANDLE hMpq{}; +#endif };