Skip to content

Commit

Permalink
Accept a nonexistent game local path when creating game handle
Browse files Browse the repository at this point in the history
This gives a better user experience when LOOT is launched before the
game's launcher has been run.
  • Loading branch information
Ortham committed Aug 20, 2023
1 parent 2141576 commit d6a40a1
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ endif()

ExternalProject_Add(libloadorder
PREFIX "external"
URL "https://github.com/Ortham/libloadorder/archive/14.1.0.tar.gz"
URL_HASH "SHA256=9ff9c73612bc9e375759e122bfd56a4a45d8a4ca36837f610c05ab52fef9d67b"
URL "https://github.com/Ortham/libloadorder/archive/14.2.0.tar.gz"
URL_HASH "SHA256=247969e3fb67ad0a883ac81ac52a4258ee92b8417d11f45308cc23ccc0d61b36"
CONFIGURE_COMMAND ""
BUILD_IN_SOURCE 1
BUILD_COMMAND cargo build --release --manifest-path ffi/Cargo.toml --target ${RUST_TARGET} &&
Expand Down
13 changes: 8 additions & 5 deletions src/api/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,18 @@ LOOT_API std::unique_ptr<GameInterface> CreateGameHandle(
}

auto resolvedGamePath = ResolvePath(gamePath);
if (!fs::is_directory(resolvedGamePath))
if (!fs::is_directory(resolvedGamePath)) {
throw std::invalid_argument("Given game path \"" + gamePath.u8string() +
"\" does not resolve to a valid directory.");
}

auto resolvedGameLocalPath = ResolvePath(gameLocalPath);
if (!gameLocalPath.empty() && !fs::is_directory(resolvedGameLocalPath))
throw std::invalid_argument("Given game local path \"" +
gameLocalPath.u8string() +
"\" does not resolve to a valid directory.");
if (!gameLocalPath.empty() && fs::exists(resolvedGameLocalPath) &&
!fs::is_directory(resolvedGameLocalPath)) {
throw std::invalid_argument(
"Given game local path \"" + gameLocalPath.u8string() +
"\" resolves to a path that exists but is not a valid directory.");
}

return std::make_unique<Game>(game, resolvedGamePath, resolvedGameLocalPath);
}
Expand Down
10 changes: 8 additions & 2 deletions src/tests/api/interface/create_game_handle_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,15 @@ TEST_P(CreateGameHandleTest, shouldThrowIfPassedAGamePathThatDoesNotExist) {
std::invalid_argument);
}

TEST_P(CreateGameHandleTest, shouldThrowIfPassedALocalPathThatDoesNotExist) {
TEST_P(CreateGameHandleTest, shouldSucceedIfPassedALocalPathThatDoesNotExist) {
EXPECT_NO_THROW(handle_ = CreateGameHandle(
GetParam(), dataPath.parent_path(), missingPath));
EXPECT_TRUE(handle_);
}

TEST_P(CreateGameHandleTest, shouldThrowIfPassedALocalPathThatIsNotADirectory) {
EXPECT_THROW(
CreateGameHandle(GetParam(), dataPath.parent_path(), missingPath),
CreateGameHandle(GetParam(), dataPath.parent_path(), dataPath / blankEsm),
std::invalid_argument);
}

Expand Down
7 changes: 2 additions & 5 deletions src/tests/api/internals/game/load_order_handler_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,9 @@ TEST_P(LoadOrderHandlerTest, constructorShouldThrowIfNoGamePathIsSet) {
std::invalid_argument);
}

#ifndef _WIN32
TEST_P(LoadOrderHandlerTest, constructorShouldThrowOnLinuxIfNoLocalPathIsSet) {
EXPECT_THROW(LoadOrderHandler(GetParam(), dataPath.parent_path()),
std::system_error);
TEST_P(LoadOrderHandlerTest, constructorShouldNotThrowIfNoLocalPathIsSet) {
EXPECT_NO_THROW(LoadOrderHandler(GetParam(), dataPath.parent_path()));
}
#endif

TEST_P(LoadOrderHandlerTest,
constructorShouldNotThrowIfAValidGameIdAndGamePathAndLocalPathAreSet) {
Expand Down

0 comments on commit d6a40a1

Please sign in to comment.