mirror of
https://github.com/loot/libloot.git
synced 2026-07-27 14:16:01 -07:00
Fix initialising a game with an empty path setting
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user