diff --git a/CMakeLists.txt b/CMakeLists.txt index 28a52ed..d70217d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,6 +23,12 @@ endif() include(cmake/Utils.cmake) set(ADDITIONAL_LIB_INCLUDES "") +# ========= Configuration Options ========= +set(EXCLUDE_MPQ_SUPPORT FALSE CACHE BOOL "Exclude StormLib and MPQ archive support") +if(EXCLUDE_MPQ_SUPPORT) + add_compile_definitions(EXCLUDE_MPQ_SUPPORT) +endif() + # =========== Dependencies ============= include(cmake/dependencies/common.cmake) diff --git a/cmake/dependencies/common.cmake b/cmake/dependencies/common.cmake index a2ec37b..116f0f0 100644 --- a/cmake/dependencies/common.cmake +++ b/cmake/dependencies/common.cmake @@ -32,7 +32,7 @@ target_sources(ImGui target_include_directories(ImGui PUBLIC ${imgui_SOURCE_DIR} ${imgui_SOURCE_DIR}/backends PRIVATE ${SDL2_INCLUDE_DIRS}) # ========= StormLib ============= -if(TRUE) +if(NOT EXCLUDE_MPQ_SUPPORT) FetchContent_Declare( StormLib GIT_REPOSITORY https://github.com/ladislav-zezula/StormLib.git diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fe9dd42..fb65f57 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -167,12 +167,14 @@ target_include_directories(libultraship ) #=================== Linking =================== - -if (NOT CMAKE_SYSTEM_NAME STREQUAL "Windows") - target_link_libraries(libultraship PUBLIC "$") -else() - target_link_libraries(libultraship PUBLIC storm) +if(NOT EXCLUDE_MPQ_SUPPORT) + if (NOT CMAKE_SYSTEM_NAME STREQUAL "Windows") + target_link_libraries(libultraship PUBLIC "$") + else() + target_link_libraries(libultraship PUBLIC storm) + endif() endif() + target_link_libraries(libultraship PRIVATE StrHash64 PUBLIC ImGui diff --git a/src/resource/archive/ArchiveManager.cpp b/src/resource/archive/ArchiveManager.cpp index 677a282..a4dc8d2 100644 --- a/src/resource/archive/ArchiveManager.cpp +++ b/src/resource/archive/ArchiveManager.cpp @@ -4,7 +4,9 @@ #include "spdlog/spdlog.h" #include "resource/archive/Archive.h" +#ifndef EXCLUDE_MPQ_SUPPORT #include "resource/archive/OtrArchive.h" +#endif #include "resource/archive/O2rArchive.h" #include "utils/StringHelper.h" #include "utils/glob.h" @@ -22,7 +24,7 @@ void ArchiveManager::Init(const std::vector& archivePaths, const std::unordered_set& validGameVersions) { mValidGameVersions = validGameVersions; auto archives = GetArchiveListInPaths(archivePaths); - for (const auto archive : archives) { + for (const auto& archive : archives) { AddArchive(archive); } } @@ -149,10 +151,12 @@ std::shared_ptr ArchiveManager::AddArchive(const std::string& archivePa SPDLOG_INFO("Reading archive: {}", path.string()); - if (StringHelper::IEquals(extension, ".zip") || StringHelper::IEquals(extension, ".zip")) { + if (StringHelper::IEquals(extension, ".o2r") || StringHelper::IEquals(extension, ".zip")) { archive = dynamic_pointer_cast(std::make_shared(archivePath)); +#ifndef EXCLUDE_MPQ_SUPPORT } else if (StringHelper::IEquals(extension, ".otr") || StringHelper::IEquals(extension, ".mpq")) { archive = dynamic_pointer_cast(std::make_shared(archivePath)); +#endif } else { // Not recognized file extension, trying with o2r SPDLOG_WARN("File extension \"{}\" not recognized, trying to create an o2r archive.", extension); diff --git a/src/resource/archive/OtrArchive.cpp b/src/resource/archive/OtrArchive.cpp index 2e4d17b..80632dd 100644 --- a/src/resource/archive/OtrArchive.cpp +++ b/src/resource/archive/OtrArchive.cpp @@ -1,3 +1,5 @@ +#ifndef EXCLUDE_MPQ_SUPPORT + #include "OtrArchive.h" #include "Context.h" @@ -100,3 +102,5 @@ bool OtrArchive::Close() { } } // namespace Ship + +#endif // EXCLUDE_MPQ_SUPPORT diff --git a/src/resource/archive/OtrArchive.h b/src/resource/archive/OtrArchive.h index 63e23a3..99c4a2b 100644 --- a/src/resource/archive/OtrArchive.h +++ b/src/resource/archive/OtrArchive.h @@ -1,3 +1,5 @@ +#ifndef EXCLUDE_MPQ_SUPPORT + #pragma once #undef _DLL @@ -35,3 +37,5 @@ class OtrArchive : virtual public Archive { HANDLE mHandle; }; } // namespace Ship + +#endif // EXCLUDE_MPQ_SUPPORT