mirror of
https://github.com/loot/libloot.git
synced 2026-07-27 14:16:01 -07:00
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.
This commit is contained in:
+3
-5
@@ -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<GameInterface> CreateGameHandle(
|
||||
const GameType game,
|
||||
const std::string& game_path = "",
|
||||
const std::string& game_path,
|
||||
const std::string& game_local_path = "");
|
||||
}
|
||||
|
||||
|
||||
+7
-1
@@ -70,8 +70,14 @@ LOOT_API std::shared_ptr<GameInterface> 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.");
|
||||
|
||||
|
||||
+1
-1
@@ -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 //
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user