Fix detection of some Fallout 4 archives

FO4 archives that start with a plugin basename are loaded, just like for
FO3 and FONV.
This commit is contained in:
Oliver Hamlet
2016-04-03 09:59:23 +01:00
parent 89a8f7bbcd
commit d7bbff888d
2 changed files with 44 additions and 22 deletions
+3 -3
View File
@@ -94,12 +94,12 @@ namespace loot {
// Get whether the plugin loads an archive (BSA/BA2) or not.
const string archiveExtension = game.getArchiveFileExtension();
if (game.Id() == Game::tes5 || game.Id() == Game::fo4) {
// Skyrim and Fallout 4 plugins only load archives that exactly match their basename.
if (game.Id() == Game::tes5) {
// Skyrim plugins only load BSAs that exactly match their basename.
_loadsArchive = boost::filesystem::exists(game.DataPath() / (Name().substr(0, Name().length() - 4) + archiveExtension));
}
else if (game.Id() != Game::tes4 || boost::iends_with(Name(), ".esp")) {
//Oblivion .esp files and FO3, FNV plugins can load BSAs which begin with the plugin basename.
//Oblivion .esp files and FO3, FNV, FO4 plugins can load archives which begin with the plugin basename.
string basename = Name().substr(0, Name().length() - 4);
for (boost::filesystem::directory_iterator it(game.DataPath()); it != boost::filesystem::directory_iterator(); ++it) {
if (boost::iequals(it->path().extension().string(), archiveExtension) && boost::istarts_with(it->path().filename().string(), basename)) {
+41 -19
View File
@@ -34,7 +34,9 @@ namespace loot {
protected:
PluginTest() :
emptyFile("EmptyFile.esm"),
nonPluginFile("NotAPlugin.esm") {}
nonPluginFile("NotAPlugin.esm"),
blankArchive("Blank" + Game(GetParam()).getArchiveFileExtension()),
blankSuffixArchive("Blank - Different - suffix" + Game(GetParam()).getArchiveFileExtension()) {}
inline void SetUp() {
BaseGameTest::SetUp();
@@ -54,11 +56,11 @@ namespace loot {
out.close();
ASSERT_TRUE(boost::filesystem::exists(dataPath / nonPluginFile));
if (GetParam() == GameSettings::tes4 || GetParam() == GameSettings::fo4) {
// Create a dummy BSA file.
out.open(dataPath / getArchiveName());
out.close();
}
// Create dummy archive files.
out.open(dataPath / blankArchive);
out.close();
out.open(dataPath / blankSuffixArchive);
out.close();
}
inline void TearDown() {
@@ -66,23 +68,16 @@ namespace loot {
boost::filesystem::remove(dataPath / emptyFile);
boost::filesystem::remove(dataPath / nonPluginFile);
if (GetParam() == GameSettings::tes4 || GetParam() == GameSettings::fo4)
boost::filesystem::remove(dataPath / getArchiveName());
boost::filesystem::remove(dataPath / blankArchive);
boost::filesystem::remove(dataPath / blankSuffixArchive);
}
Game game;
const std::string emptyFile;
const std::string nonPluginFile;
private:
inline std::string getArchiveName() {
if (GetParam() == GameSettings::fo4)
return "Blank.ba2";
else
return "Blank.bsa";
}
const std::string blankArchive;
const std::string blankSuffixArchive;
};
// Pass an empty first argument, as it's a prefix for the test instantation,
@@ -149,12 +144,39 @@ namespace loot {
}), plugin.getMasters());
}
TEST_P(PluginTest, loadsArchiveShouldReturnTrueForAPluginThatLoadsAnArchive) {
TEST_P(PluginTest, loadsArchiveForAnArchiveThatExactlyMatchesAnEsmFileBasenameShouldReturnTrueForAllGamesExceptOblivion) {
bool loadsArchive = Plugin(game, blankEsm, true).LoadsArchive();
if (GetParam() == Game::tes4)
EXPECT_FALSE(loadsArchive);
else
EXPECT_TRUE(loadsArchive);
}
TEST_P(PluginTest, loadsArchiveForAnArchiveThatExactlyMatchesAnEspFileBasenameShouldReturnTrue) {
EXPECT_TRUE(Plugin(game, blankEsp, true).LoadsArchive());
}
TEST_P(PluginTest, loadsArchiveForAnArchiveWithAFilenameWhichStartsWithTheEsmFileBasenameShouldReturnTrueForAllGamesExceptOblivionAndSkyrim) {
bool loadsArchive = Plugin(game, blankDifferentEsm, true).LoadsArchive();
if (GetParam() == Game::tes4 || GetParam() == Game::tes5)
EXPECT_FALSE(loadsArchive);
else
EXPECT_TRUE(loadsArchive);
}
TEST_P(PluginTest, loadsArchiveForAnArchiveWithAFilenameWhichStartsWithTheEspFileBasenameShouldReturnTrueForAllGamesExceptSkyrim) {
bool loadsArchive = Plugin(game, blankDifferentEsp, true).LoadsArchive();
if (GetParam() == Game::tes5)
EXPECT_FALSE(loadsArchive);
else
EXPECT_TRUE(loadsArchive);
}
TEST_P(PluginTest, loadsArchiveShouldReturnFalseForAPluginThatDoesNotLoadAnArchive) {
EXPECT_FALSE(Plugin(game, blankDifferentEsm, true).LoadsArchive());
EXPECT_FALSE(Plugin(game, blankMasterDependentEsp, true).LoadsArchive());
}
TEST_P(PluginTest, loadsArchiveShouldReturnFalseForAPluginWithARegexFilename) {