diff --git a/src/gui/state/game.cpp b/src/gui/state/game.cpp index c613f090..8598c55a 100644 --- a/src/gui/state/game.cpp +++ b/src/gui/state/game.cpp @@ -66,10 +66,16 @@ Game::Game(const GameSettings& gameSettings, const boost::filesystem::path& localDataPath) : GameSettings(gameSettings), lootDataPath_(lootDataPath), - gameHandle_(CreateGameHandle(gameSettings.Type(), gameSettings.GamePath().string(), localDataPath.string())), pluginsFullyLoaded_(false), loadOrderSortCount_(0) { - gameHandle_->IdentifyMainMasterFile(gameSettings.Master()); + SetGamePath(DetectGamePath(*this)); + + if (GamePath().empty()) { + throw GameDetectionError("Game path could not be detected."); + } + + gameHandle_ = CreateGameHandle(Type(), GamePath().string(), localDataPath.string()); + gameHandle_->IdentifyMainMasterFile(Master()); } Game::Game(const Game& game) : @@ -103,12 +109,6 @@ bool Game::IsInstalled(const GameSettings& gameSettings) { void Game::Init() { BOOST_LOG_TRIVIAL(info) << "Initialising filesystem-related data for game: " << Name(); - SetGamePath(DetectGamePath(*this)); - - if (GamePath().empty()) { - throw GameDetectionError("Game path could not be detected."); - } - if (!lootDataPath_.empty()) { //Make sure that the LOOT game path exists. try { diff --git a/src/tests/common_game_test_fixture.h b/src/tests/common_game_test_fixture.h index a52a2833..1989322d 100644 --- a/src/tests/common_game_test_fixture.h +++ b/src/tests/common_game_test_fixture.h @@ -62,6 +62,7 @@ protected: void assertInitialState() { ASSERT_NO_THROW(boost::filesystem::create_directories(localPath)); + ASSERT_NO_THROW(boost::filesystem::create_directories(lootDataPath)); ASSERT_TRUE(boost::filesystem::exists(localPath)); ASSERT_FALSE(boost::filesystem::exists(missingPath)); diff --git a/src/tests/gui/state/game_test.h b/src/tests/gui/state/game_test.h index dfb4da9c..35c6756a 100644 --- a/src/tests/gui/state/game_test.h +++ b/src/tests/gui/state/game_test.h @@ -83,7 +83,7 @@ TEST_P(GameTest, constructingFromGameSettingsShouldUseTheirValues) { settings.SetRegistryKey("foo"); settings.SetRepoURL("foo"); settings.SetRepoBranch("foo"); - settings.SetGamePath(localPath); + settings.SetGamePath(dataPath.parent_path()); Game game(settings, lootDataPath, localPath); EXPECT_EQ(GetParam(), game.Type()); @@ -103,7 +103,7 @@ TEST_P(GameTest, constructingFromGameSettingsShouldUseTheirValues) { // Testing on Windows will find real game installs in the Registry, so cannot // test autodetection fully unless on Linux. TEST_P(GameTest, constructingShouldThrowOnLinuxIfGamePathIsNotGiven) { - EXPECT_THROW(Game(GameSettings(GetParam()), "", localPath), std::invalid_argument); + EXPECT_THROW(Game(GameSettings(GetParam()), "", localPath), GameDetectionError); } TEST_P(GameTest, constructingShouldThrowOnLinuxIfLocalPathIsNotGiven) {