Skip to content

Commit 3bd9c99

Browse files
committed
optional otr
little more ifdefy than i'd like but it's a start
1 parent 33ede26 commit 3bd9c99

File tree

5 files changed

+19
-1
lines changed

5 files changed

+19
-1
lines changed

CMakeLists.txt

+6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ endif()
2323
include(cmake/Utils.cmake)
2424
set(ADDITIONAL_LIB_INCLUDES "")
2525

26+
# ========= Configuration Options =========
27+
set(MPQ_SUPPORT FALSE CACHE BOOL "Include StormLib and support using MPQ archives")
28+
if(MPQ_SUPPORT)
29+
add_compile_definitions(MPQ_SUPPORT)
30+
endif()
31+
2632
# =========== Dependencies =============
2733
include(cmake/dependencies/common.cmake)
2834

cmake/dependencies/common.cmake

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ target_sources(ImGui
3232
target_include_directories(ImGui PUBLIC ${imgui_SOURCE_DIR} ${imgui_SOURCE_DIR}/backends PRIVATE ${SDL2_INCLUDE_DIRS})
3333

3434
# ========= StormLib =============
35-
if(TRUE)
35+
if(MPQ_SUPPORT)
3636
FetchContent_Declare(
3737
StormLib
3838
GIT_REPOSITORY https://github.com/ladislav-zezula/StormLib.git

src/resource/archive/ArchiveManager.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
#include "spdlog/spdlog.h"
55

66
#include "resource/archive/Archive.h"
7+
#ifdef MPQ_SUPPORT
78
#include "resource/archive/OtrArchive.h"
9+
#endif
810
#include "resource/archive/O2rArchive.h"
911
#include "utils/StringHelper.h"
1012
#include "utils/glob.h"
@@ -151,8 +153,10 @@ std::shared_ptr<Archive> ArchiveManager::AddArchive(const std::string& archivePa
151153

152154
if (StringHelper::IEquals(extension, ".zip") || StringHelper::IEquals(extension, ".zip")) {
153155
archive = dynamic_pointer_cast<Archive>(std::make_shared<O2rArchive>(archivePath));
156+
#ifdef MPQ_SUPPORT
154157
} else if (StringHelper::IEquals(extension, ".otr") || StringHelper::IEquals(extension, ".mpq")) {
155158
archive = dynamic_pointer_cast<Archive>(std::make_shared<OtrArchive>(archivePath));
159+
#endif
156160
} else {
157161
// Not recognized file extension, trying with o2r
158162
SPDLOG_WARN("File extension \"{}\" not recognized, trying to create an o2r archive.", extension);

src/resource/archive/OtrArchive.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#ifdef MPQ_SUPPORT
2+
13
#include "OtrArchive.h"
24

35
#include "Context.h"
@@ -100,3 +102,5 @@ bool OtrArchive::Close() {
100102
}
101103

102104
} // namespace Ship
105+
106+
#endif // MPQ_SUPPORT

src/resource/archive/OtrArchive.h

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#pragma once
22

3+
#ifdef MPQ_SUPPORT
4+
35
#undef _DLL
46

57
#include <string>
@@ -35,3 +37,5 @@ class OtrArchive : virtual public Archive {
3537
HANDLE mHandle;
3638
};
3739
} // namespace Ship
40+
41+
#endif // MPQ_SUPPORT

0 commit comments

Comments
 (0)