From bc76e833570f1fdbaa6bb2a26e8f18d22731db68 Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Sun, 20 Feb 2022 20:03:43 +0000 Subject: [PATCH] Add GameInterface::IsLoadOrderAmbiguous() It exposes libloadorder's lo_is_ambiguous() function. --- CMakeLists.txt | 2 +- include/loot/game_interface.h | 11 +++++++++++ src/api/game/game.cpp | 4 ++++ src/api/game/game.h | 2 ++ src/api/game/load_order_handler.cpp | 14 ++++++++++++++ src/api/game/load_order_handler.h | 2 ++ .../api/internals/game/load_order_handler_test.h | 7 +++++++ 7 files changed, 41 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8310acc8..b60d080b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -82,7 +82,7 @@ endif() ExternalProject_Add(libloadorder PREFIX "external" - URL "https://github.com/Ortham/libloadorder/archive/13.0.0.tar.gz" + URL "https://github.com/Ortham/libloadorder/archive/13.1.0.tar.gz" CONFIGURE_COMMAND "" BUILD_IN_SOURCE 1 BUILD_COMMAND cargo build --release --manifest-path ffi/Cargo.toml --target ${RUST_TARGET} && diff --git a/include/loot/game_interface.h b/include/loot/game_interface.h index 8770a355..f2c6b707 100644 --- a/include/loot/game_interface.h +++ b/include/loot/game_interface.h @@ -144,6 +144,17 @@ public: */ virtual void LoadCurrentLoadOrderState() = 0; + /** + * @brief Check if the load order is ambiguous. + * @details This checks that all plugins in the current load order state have + * a well-defined position in the "on disk" state, and that all data + * sources are consistent. If the load order is ambiguous, different + * applications may read different load orders from the same source + * data. + * @returns True if the load order is ambiguous, false otherwise. + */ + virtual bool IsLoadOrderAmbiguous() const = 0; + /** * @brief Check if a plugin is active. * @param plugin diff --git a/src/api/game/game.cpp b/src/api/game/game.cpp index 837f975d..8e0b605c 100644 --- a/src/api/game/game.cpp +++ b/src/api/game/game.cpp @@ -216,6 +216,10 @@ void Game::LoadCurrentLoadOrderState() { loadOrderHandler_.GetActivePlugins()); } +bool Game::IsLoadOrderAmbiguous() const { + return loadOrderHandler_.IsAmbiguous(); +} + bool Game::IsPluginActive(const std::string& pluginName) const { return loadOrderHandler_.IsPluginActive(pluginName); } diff --git a/src/api/game/game.h b/src/api/game/game.h index 31322390..5a98b52c 100644 --- a/src/api/game/game.h +++ b/src/api/game/game.h @@ -72,6 +72,8 @@ public: void LoadCurrentLoadOrderState() override; + bool IsLoadOrderAmbiguous() const override; + bool IsPluginActive(const std::string& pluginName) const override; std::vector GetLoadOrder() const override; diff --git a/src/api/game/load_order_handler.cpp b/src/api/game/load_order_handler.cpp index 7b5efc2f..364ee61e 100644 --- a/src/api/game/load_order_handler.cpp +++ b/src/api/game/load_order_handler.cpp @@ -96,6 +96,20 @@ void LoadOrderHandler::LoadCurrentState() { HandleError("load the current load order state", ret); } +bool LoadOrderHandler::IsAmbiguous() const { + auto logger = getLogger(); + if (logger) { + logger->trace("Checking if the load order is ambiguous."); + } + + bool result = false; + const unsigned int ret = lo_is_ambiguous(gh_.get(), &result); + + HandleError("check if the load order is ambiguous", ret); + + return result; +} + bool LoadOrderHandler::IsPluginActive(const std::string& pluginName) const { auto logger = getLogger(); if (logger) { diff --git a/src/api/game/load_order_handler.h b/src/api/game/load_order_handler.h index ac971da5..fe744560 100644 --- a/src/api/game/load_order_handler.h +++ b/src/api/game/load_order_handler.h @@ -43,6 +43,8 @@ public: void LoadCurrentState(); + bool IsAmbiguous() const; + std::vector GetLoadOrder() const; std::vector GetActivePlugins() const; diff --git a/src/tests/api/internals/game/load_order_handler_test.h b/src/tests/api/internals/game/load_order_handler_test.h index 3f2815b4..706df1bb 100644 --- a/src/tests/api/internals/game/load_order_handler_test.h +++ b/src/tests/api/internals/game/load_order_handler_test.h @@ -135,6 +135,13 @@ TEST_P(LoadOrderHandlerTest, LoadOrderHandler(GetParam(), dataPath.parent_path(), localPath)); } +TEST_P(LoadOrderHandlerTest, + isAmbiguousShouldReturnFalseForAnUnambiguousLoadOrder) { + auto loadOrderHandler = createHandler(); + + EXPECT_FALSE(loadOrderHandler.IsAmbiguous()); +} + TEST_P(LoadOrderHandlerTest, isPluginActiveShouldReturnFalseIfLoadOrderStateHasNotBeenLoaded) { auto loadOrderHandler = createHandler();