Skip to content

Commit

Permalink
Added support for disabling stormlib
Browse files Browse the repository at this point in the history
  • Loading branch information
KiritoDv committed Jan 15, 2025
1 parent 8c3802a commit 5066e9d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
12 changes: 8 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
12 changes: 12 additions & 0 deletions src/archive/SWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -23,9 +26,13 @@ int32_t SWrapper::CreateArchive() {
}

return 0;
#endif
}

bool SWrapper::CreateFile(const std::string& path, std::vector<char> 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;
Expand Down Expand Up @@ -74,9 +81,13 @@ bool SWrapper::CreateFile(const std::string& path, std::vector<char> 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;
Expand All @@ -86,4 +97,5 @@ int32_t SWrapper::Close(void) {
return -1;
}
return 0;
#endif
}
6 changes: 5 additions & 1 deletion src/archive/SWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

#include <vector>
#include <string>
#include <StormLib/src/StormLib.h>
#include "BinaryWrapper.h"
#ifdef USE_STORMLIB
#include <StormLib/src/StormLib.h>
#endif

class SWrapper : public BinaryWrapper {
public:
Expand All @@ -12,6 +14,8 @@ class SWrapper : public BinaryWrapper {
int32_t CreateArchive(void) override;
bool CreateFile(const std::string& path, std::vector<char> data) override;
int32_t Close(void) override;
#ifdef USE_STORMLIB
private:
HANDLE hMpq{};
#endif
};

0 comments on commit 5066e9d

Please sign in to comment.