Skip to content

Commit

Permalink
thcrap: fix paths format in games.js
Browse files Browse the repository at this point in the history
  • Loading branch information
brliron committed Dec 22, 2024
1 parent 10c0f97 commit 1eee061
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions thcrap/src/search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,18 @@ char *SearchDecideStoredPathForm(std::filesystem::path target, std::filesystem::
}

if (target.root_path() != self.root_path()) {
return strdup(target.u8string().c_str());
return strdup(target.generic_u8string().c_str());
}

auto [self_diff, target_diff] = std::mismatch(self.begin(), self.end(), target.begin(), target.end());
// These numbers were decided arbitrarly by making a list of path examples that seemed
// to make sense and looking at which values they need.
// These examples are available in the unit tests.
if (iter_size(self_diff, self.end()) <= 3 && iter_size(target_diff, target.end()) <= 2) {
return strdup(target.lexically_relative(self).u8string().c_str());
return strdup(target.lexically_relative(self).generic_u8string().c_str());
}
else {
return strdup(target.u8string().c_str());
return strdup(target.generic_u8string().c_str());
}
}

Expand Down
14 changes: 7 additions & 7 deletions thcrap_test/src/search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ static void test(const char *self, const char *target, const char *expected)

TEST(Search, SearchDecideStoredPathForm)
{
test("C:\\a\\1\\2\\3\\4\\5\\6\\", "C:\\b\\1\\2\\3\\4\\5\\6", nullptr);
test("D:\\thcrap\\", "E:\\th07\\th07.exe", nullptr);
test("C:\\Users\\brliron\\Downlods\\thcrap\\", "C:\\Program Files\\Steam\\common\\th07\\th07.exe", nullptr);
test("C:\\Users\\brliron\\Desktop\\games\\tools\\thcrap\\", "C:\\Users\\brliron\\Desktop\\games\\th07\\th07.exe", "..\\..\\th07\\th07.exe");
test("C:\\Users\\brliron\\Desktop\\games\\th07\\thcrap\\", "C:\\Users\\brliron\\Desktop\\games\\th07\\th07.exe", "..\\th07.exe");
test("C:\\Users\\brliron\\Desktop\\games\\", "C:\\Users\\brliron\\Desktop\\games\\th07\\th07.exe", "th07\\th07.exe");
test("D:\\thcrap\\", "D:\\th07\\th07.exe", "..\\th07\\th07.exe");
test("C:/a/1/2/3/4/5/6/", "C:/b/1/2/3/4/5/6", nullptr);
test("D:/thcrap/", "E:/th07/th07.exe", nullptr);
test("C:/Users/brliron/Downlods/thcrap/", "C:/Program Files/Steam/common/th07/th07.exe", nullptr);
test("C:/Users/brliron/Desktop/games/tools/thcrap/", "C:/Users/brliron/Desktop/games/th07/th07.exe", "../../th07/th07.exe");
test("C:/Users/brliron/Desktop/games/th07/thcrap/", "C:/Users/brliron/Desktop/games/th07/th07.exe", "../th07.exe");
test("C:/Users/brliron/Desktop/games/", "C:/Users/brliron/Desktop/games/th07/th07.exe", "th07/th07.exe");
test("D:/thcrap/", "D:/th07/th07.exe", "../th07/th07.exe");
}
2 changes: 1 addition & 1 deletion thcrap_test/src/search_for_games.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ TEST_F(SearchForGamesTest, TestSearchNormalFile)

game_search_result *found = SearchForGames(dirlist, nullptr);
ASSERT_NE(found, nullptr);
EXPECT_STREQ(found[0].path, "testdir\\abc.exe");
EXPECT_STREQ(found[0].path, "testdir/abc.exe");
EXPECT_STREQ(found[0].id, "th_abc");
EXPECT_STREQ(found[0].build, "v1.00");
EXPECT_STREQ(found[0].description, "v1.00 (original)");
Expand Down

0 comments on commit 1eee061

Please sign in to comment.