From 89599664abe0004e5449ef168bc1ce8c10c41dfc Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Sat, 30 Dec 2017 14:41:49 +0000 Subject: [PATCH] Don't accept empty game path in CreateGameHandle() Add a new logging statement partially to have an easily testable message and partly because knowing the unresolved paths could be useful. --- include/loot/api.h | 8 +++----- src/api/api.cpp | 8 +++++++- src/api/game/game.h | 2 +- src/tests/api/interface/main.cpp | 7 ++++--- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/include/loot/api.h b/include/loot/api.h index 6d99865b..b8990c27 100644 --- a/include/loot/api.h +++ b/include/loot/api.h @@ -111,10 +111,8 @@ LOOT_API void InitialiseLocale(const std::string& id = ""); * @param game * A game code for which to create the handle. * @param game_path - * The relative or absolute path to the game folder, or an empty string. - * If an empty string, the API will attempt to detect the data path of - * the specified game by searching for the game's main master file in a - * sibling Data folder and by searching for the game's Registry entry. + * The relative or absolute path to the directory containing the + * game's executable. * @param game_local_path * The relative or absolute path to the game's folder in * `%%LOCALAPPDATA%` or an empty string. If an empty string, the API @@ -125,7 +123,7 @@ LOOT_API void InitialiseLocale(const std::string& id = ""); */ LOOT_API std::shared_ptr CreateGameHandle( const GameType game, - const std::string& game_path = "", + const std::string& game_path, const std::string& game_local_path = ""); } diff --git a/src/api/api.cpp b/src/api/api.cpp index b6837ed7..a0d1e588 100644 --- a/src/api/api.cpp +++ b/src/api/api.cpp @@ -70,8 +70,14 @@ LOOT_API std::shared_ptr CreateGameHandle( const GameType game, const std::string& gamePath, const std::string& gameLocalPath) { + auto logger = getLogger(); + if (logger) { + logger->info("Attempting to create a game handle with game path \"{}\" " + "and local path \"{}\"", gamePath, gameLocalPath); + } + const std::string resolvedGamePath = ResolvePath(gamePath); - if (!gamePath.empty() && !fs::is_directory(resolvedGamePath)) + if (!fs::is_directory(resolvedGamePath)) throw std::invalid_argument("Given game path \"" + gamePath + "\" does not resolve to a valid directory."); diff --git a/src/api/game/game.h b/src/api/game/game.h index 1ef73f9d..4ed8a820 100644 --- a/src/api/game/game.h +++ b/src/api/game/game.h @@ -37,7 +37,7 @@ namespace loot { class Game : public GameInterface { public: Game(const GameType gameType, - const boost::filesystem::path& gamePath = "", + const boost::filesystem::path& gamePath, const boost::filesystem::path& gameLocalDataPath = ""); // Internal Methods // diff --git a/src/tests/api/interface/main.cpp b/src/tests/api/interface/main.cpp index a6bdb7bf..e27cace0 100644 --- a/src/tests/api/interface/main.cpp +++ b/src/tests/api/interface/main.cpp @@ -51,10 +51,11 @@ TEST(SetLoggingCallback, shouldWriteMessagesToGivenCallback) { }); try { - CreateGameHandle(GameType::tes4, "", ""); + CreateGameHandle(GameType::tes4, "dummy"); } catch (...) { - EXPECT_EQ("Initialising load order data for game of type 0 at: ", - loggedMessages); + EXPECT_EQ("Attempting to create a game handle with game path \"dummy\" " + "and local path \"\"", + loggedMessages); SetLoggingCallback([](LogLevel, const char *) {}); return;