From 633836774368a40545be944b82a2ff1bb87f1e6f Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Thu, 5 Oct 2017 08:18:13 +0100 Subject: [PATCH] Update to the latest Rust libloadorder Libloadorder is being rewritten in Rust and the rewrite will be released as v10. There is some API breakage involved, and the Rust rewrite exposes cache management to the client, so the LOOT API will need to reload state as appropriate to avoid performance issues. --- CMakeLists.txt | 19 ++++++++++++------- src/api/game/load_order_handler.cpp | 28 +++++++++++++--------------- src/api/game/load_order_handler.h | 2 +- 3 files changed, 26 insertions(+), 23 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9d71cfcd..5870f78f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -100,14 +100,19 @@ set(LIBGIT2_LIBRARIES "${BINARY_DIR}/${CMAKE_CFG_INTDIR}/${CMAKE_STATIC_LIBRARY_ ExternalProject_Add(libloadorder PREFIX "external" - DEPENDS libespm - URL "https://github.com/WrinklyNinja/libloadorder/archive/9.5.5.tar.gz" - CMAKE_ARGS -DBOOST_ROOT=${BOOST_ROOT} -DBOOST_LIBRARYDIR=${BOOST_LIBRARYDIR} -DMSVC_STATIC_RUNTIME=${MSVC_STATIC_RUNTIME} -DCMAKE_POSITION_INDEPENDENT_CODE=${CMAKE_POSITION_INDEPENDENT_CODE} -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS} - BUILD_COMMAND ${CMAKE_COMMAND} --build . --target loadorder --config $(CONFIGURATION) + URL "https://github.com/WrinklyNinja/libloadorder/archive/rust-rewrite.tar.gz" + CONFIGURE_COMMAND "" + BUILD_IN_SOURCE 1 + BUILD_COMMAND cargo build --release --all --all-features --target ${RUST_TARGET} INSTALL_COMMAND "") -ExternalProject_Get_Property(libloadorder SOURCE_DIR BINARY_DIR) -set(LIBLOADORDER_INCLUDE_DIRS "${SOURCE_DIR}/include") -set(LIBLOADORDER_LIBRARIES "${BINARY_DIR}/${CMAKE_CFG_INTDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}loadorder${CMAKE_STATIC_LIBRARY_SUFFIX}") +ExternalProject_Get_Property(libloadorder SOURCE_DIR) +set(LIBLOADORDER_INCLUDE_DIRS "${SOURCE_DIR}/ffi/include") +set(LIBLOADORDER_LIBRARIES "${SOURCE_DIR}/target/${RUST_TARGET}/release/${CMAKE_STATIC_LIBRARY_PREFIX}loadorder_ffi${CMAKE_STATIC_LIBRARY_SUFFIX}") +IF (CMAKE_SYSTEM_NAME MATCHES "Windows") + set (LIBLOADORDER_LIBRARIES ${LIBLOADORDER_LIBRARIES} Userenv) +ELSE () + set (LIBLOADORDER_LIBRARIES ${LIBLOADORDER_LIBRARIES} dl) +ENDIF () ExternalProject_Add(pseudosem PREFIX "external" diff --git a/src/api/game/load_order_handler.cpp b/src/api/game/load_order_handler.cpp index a1426cfe..06c29178 100644 --- a/src/api/game/load_order_handler.cpp +++ b/src/api/game/load_order_handler.cpp @@ -40,8 +40,8 @@ LoadOrderHandler::~LoadOrderHandler() { lo_destroy_handle(gh_); } -void LoadOrderHandler::Init(const GameType& gameType, - const boost::filesystem::path& gamePath, +void LoadOrderHandler::Init(const GameType& gameType, + const boost::filesystem::path& gamePath, const boost::filesystem::path& gameLocalAppData) { if (gamePath.empty()) { throw std::invalid_argument("Game path is not initialised."); @@ -52,7 +52,7 @@ void LoadOrderHandler::Init(const GameType& gameType, if (!tempPathString.empty()) gameLocalDataPath = tempPathString.c_str(); -// If the handle has already been initialised, close it and open another. + // If the handle has already been initialised, close it and open another. if (gh_ != nullptr) { lo_destroy_handle(gh_); gh_ = nullptr; @@ -74,7 +74,7 @@ void LoadOrderHandler::Init(const GameType& gameType, else ret = LIBLO_ERROR_INVALID_ARGS; - if (ret != LIBLO_OK && ret != LIBLO_WARN_BAD_FILENAME && ret != LIBLO_WARN_INVALID_LIST && ret != LIBLO_WARN_LO_MISMATCH) { + if (ret != LIBLO_OK && ret != LIBLO_WARN_LO_MISMATCH) { const char * e = nullptr; string err; lo_get_error_message(&e); @@ -83,7 +83,7 @@ void LoadOrderHandler::Init(const GameType& gameType, } else { err = (format("libloadorder failed to create a game handle. Details: %1%") % e).str(); } - lo_cleanup(); + throw std::system_error(ret, libloadorder_category(), err); } } @@ -93,7 +93,7 @@ bool LoadOrderHandler::IsPluginActive(const std::string& pluginName) const { bool result = false; unsigned int ret = lo_get_plugin_active(gh_, pluginName.c_str(), &result); - if (ret != LIBLO_OK && ret != LIBLO_WARN_BAD_FILENAME) { + if (ret != LIBLO_OK) { const char * e = nullptr; string err; lo_get_error_message(&e); @@ -102,7 +102,7 @@ bool LoadOrderHandler::IsPluginActive(const std::string& pluginName) const { } else { err = (format("libloadorder failed to check if a plugin is active. Details: %1%") % e).str(); } - lo_cleanup(); + throw std::system_error(ret, libloadorder_category(), err); } @@ -116,7 +116,7 @@ std::vector LoadOrderHandler::GetLoadOrder() const { size_t pluginArrSize; unsigned int ret = lo_get_load_order(gh_, &pluginArr, &pluginArrSize); - if (ret != LIBLO_OK && ret != LIBLO_WARN_BAD_FILENAME && ret != LIBLO_WARN_INVALID_LIST && ret != LIBLO_WARN_LO_MISMATCH) { + if (ret != LIBLO_OK && ret != LIBLO_WARN_LO_MISMATCH) { const char * e = nullptr; string err; lo_get_error_message(&e); @@ -125,14 +125,13 @@ std::vector LoadOrderHandler::GetLoadOrder() const { } else { err = (format("libloadorder failed to get the load order. Details: %1%") % e).str(); } - lo_cleanup(); + throw std::system_error(ret, libloadorder_category(), err); } - std::vector loadOrder; - for (size_t i = 0; i < pluginArrSize; ++i) { - loadOrder.push_back(string(pluginArr[i])); - } + std::vector loadOrder(pluginArr, pluginArr + pluginArrSize); + lo_free_string_array(pluginArr, pluginArrSize); + return loadOrder; } @@ -154,7 +153,7 @@ void LoadOrderHandler::SetLoadOrder(const std::vector& loadOrder) c delete[] pluginArr[i]; delete[] pluginArr; - if (ret != LIBLO_OK && ret != LIBLO_WARN_BAD_FILENAME && ret != LIBLO_WARN_INVALID_LIST && ret != LIBLO_WARN_LO_MISMATCH) { + if (ret != LIBLO_OK && ret != LIBLO_WARN_LO_MISMATCH) { const char * e = nullptr; string err; lo_get_error_message(&e); @@ -163,7 +162,6 @@ void LoadOrderHandler::SetLoadOrder(const std::vector& loadOrder) c } else { err = (format("libloadorder failed to set the load order. Details: %1%") % e).str(); } - lo_cleanup(); throw std::system_error(ret, libloadorder_category(), err); } diff --git a/src/api/game/load_order_handler.h b/src/api/game/load_order_handler.h index 00b68d92..a2e9e999 100644 --- a/src/api/game/load_order_handler.h +++ b/src/api/game/load_order_handler.h @@ -30,7 +30,7 @@ #include #include -#include +#include #include "loot/enum/game_type.h"