From 4fbc075c7125511c4bbabb69bfb9b7c0e9cda5d2 Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Thu, 8 May 2025 16:01:08 +0100 Subject: [PATCH] Refactor conversion from Rust strings to C++ paths --- cpp/src/api/game.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/cpp/src/api/game.cpp b/cpp/src/api/game.cpp index 34f05e58..fafac74d 100644 --- a/cpp/src/api/game.cpp +++ b/cpp/src/api/game.cpp @@ -67,6 +67,10 @@ loot::rust::GameType convert(loot::GameType gameType) { } } +std::filesystem::path to_path(const rust::String& string) { + return std::filesystem::u8path(string.begin(), string.end()); +} + rust::Box constructGame( const loot::GameType gameType, const std::filesystem::path& gamePath, @@ -115,9 +119,8 @@ DatabaseInterface& Game::GetDatabase() { return database_; } std::vector Game::GetAdditionalDataPaths() const { try { std::vector paths; - for (const auto& path_str : game_->additional_data_paths()) { - paths.push_back( - std::filesystem::u8path(path_str.begin(), path_str.end())); + for (const auto& path_string : game_->additional_data_paths()) { + paths.push_back(to_path(path_string)); } return paths; @@ -225,8 +228,7 @@ bool Game::IsLoadOrderAmbiguous() const { std::filesystem::path Game::GetActivePluginsFilePath() const { try { - const auto path_string = game_->active_plugins_file_path(); - return std::filesystem::u8path(path_string.begin(), path_string.end()); + return to_path(game_->active_plugins_file_path()); } catch (const ::rust::Error& e) { std::rethrow_exception(mapError(e)); }