From 89a8f7bbcd3209e0b9c4ecd6042499e6631324bf Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Sun, 3 Apr 2016 09:59:12 +0100 Subject: [PATCH] Refactor archive file extension detail to Game --- src/backend/game/game.cpp | 7 +++++++ src/backend/game/game.h | 2 ++ src/backend/plugin/plugin.cpp | 6 +----- src/tests/backend/game/game_test.h | 8 ++++++++ 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/backend/game/game.cpp b/src/backend/game/game.cpp index 02c5ab68..67dc4904 100644 --- a/src/backend/game/game.cpp +++ b/src/backend/game/game.cpp @@ -191,4 +191,11 @@ namespace loot { return LoadOrderHandler::IsPluginActive(pluginName); } } + + std::string Game::getArchiveFileExtension() const { + if (Id() == Game::fo4) + return ".ba2"; + else + return ".bsa"; + } } diff --git a/src/backend/game/game.h b/src/backend/game/game.h index f5229058..1daf9d4e 100644 --- a/src/backend/game/game.h +++ b/src/backend/game/game.h @@ -51,6 +51,8 @@ namespace loot { // Check if the plugin is active by using the cached value if // available, and otherwise asking the load order handler. bool IsPluginActive(const std::string& pluginName) const; + + std::string getArchiveFileExtension() const; private: bool _pluginsFullyLoaded; }; diff --git a/src/backend/plugin/plugin.cpp b/src/backend/plugin/plugin.cpp index ac54106c..63788182 100644 --- a/src/backend/plugin/plugin.cpp +++ b/src/backend/plugin/plugin.cpp @@ -92,11 +92,7 @@ namespace loot { _isActive = game.IsPluginActive(Name()); // Get whether the plugin loads an archive (BSA/BA2) or not. - string archiveExtension; - if (game.Id() == Game::fo4) - archiveExtension = ".ba2"; - else - archiveExtension = ".bsa"; + 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. diff --git a/src/tests/backend/game/game_test.h b/src/tests/backend/game/game_test.h index 4ad16b99..e4dd63c1 100644 --- a/src/tests/backend/game/game_test.h +++ b/src/tests/backend/game/game_test.h @@ -100,6 +100,14 @@ namespace loot { EXPECT_THROW(game.Init(true, localPath), error); } + TEST_P(GameTest, getArchiveFileExtensionShouldReturnDotBa2ForFallout4AndDotBsaForOtherGames) { + Game game(GetParam()); + if (game.Id() == Game::fo4) + EXPECT_EQ(".ba2", game.getArchiveFileExtension()); + else + EXPECT_EQ(".bsa", game.getArchiveFileExtension()); + } + #ifndef _WIN32 // Testing on Windows will find real game installs in the Registry, so cannot // test autodetection fully unless on Linux.