Fix initialising a game with an empty path setting

This commit is contained in:
Oliver Hamlet
2017-02-06 18:03:18 +00:00
parent d5f926a55d
commit 93a47e517e
3 changed files with 11 additions and 10 deletions
+8 -8
View File
@@ -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 {
+1
View File
@@ -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));
+2 -2
View File
@@ -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) {