optional stormlib (#546)

This commit is contained in:
briaguya
2024-05-02 11:41:25 -04:00
committed by GitHub
parent 33ede26529
commit dc2a398297
6 changed files with 28 additions and 8 deletions
+6
View File
@@ -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)
+1 -1
View File
@@ -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
+7 -5
View File
@@ -167,12 +167,14 @@ target_include_directories(libultraship
)
#=================== Linking ===================
if (NOT CMAKE_SYSTEM_NAME STREQUAL "Windows")
target_link_libraries(libultraship PUBLIC "$<LINK_LIBRARY:WHOLE_ARCHIVE,storm>")
else()
target_link_libraries(libultraship PUBLIC storm)
if(NOT EXCLUDE_MPQ_SUPPORT)
if (NOT CMAKE_SYSTEM_NAME STREQUAL "Windows")
target_link_libraries(libultraship PUBLIC "$<LINK_LIBRARY:WHOLE_ARCHIVE,storm>")
else()
target_link_libraries(libultraship PUBLIC storm)
endif()
endif()
target_link_libraries(libultraship
PRIVATE StrHash64
PUBLIC ImGui
+6 -2
View File
@@ -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<std::string>& archivePaths,
const std::unordered_set<uint32_t>& 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<Archive> 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<Archive>(std::make_shared<O2rArchive>(archivePath));
#ifndef EXCLUDE_MPQ_SUPPORT
} else if (StringHelper::IEquals(extension, ".otr") || StringHelper::IEquals(extension, ".mpq")) {
archive = dynamic_pointer_cast<Archive>(std::make_shared<OtrArchive>(archivePath));
#endif
} else {
// Not recognized file extension, trying with o2r
SPDLOG_WARN("File extension \"{}\" not recognized, trying to create an o2r archive.", extension);
+4
View File
@@ -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
+4
View File
@@ -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