mirror of
https://github.com/loot/libloot.git
synced 2026-07-27 14:16:01 -07:00
Make Plugin.IsValid a static member
This commit is contained in:
@@ -123,7 +123,7 @@ namespace loot {
|
||||
// First find out how many plugins there are, and their sizes.
|
||||
BOOST_LOG_TRIVIAL(trace) << "Scanning for plugins in " << this->DataPath();
|
||||
for (fs::directory_iterator it(this->DataPath()); it != fs::directory_iterator(); ++it) {
|
||||
if (fs::is_regular_file(it->status()) && Plugin(it->path().filename().string()).IsValid(*this)) {
|
||||
if (fs::is_regular_file(it->status()) && Plugin::IsValid(it->path().filename().string(), *this)) {
|
||||
Plugin temp(it->path().filename().string());
|
||||
BOOST_LOG_TRIVIAL(info) << "Found plugin: " << temp.Name();
|
||||
|
||||
|
||||
@@ -326,7 +326,7 @@ namespace loot {
|
||||
Version trueVersion;
|
||||
if (file == "LOOT")
|
||||
trueVersion = Version(boost::filesystem::absolute("LOOT.exe"));
|
||||
else if (Plugin(file).IsValid(*_game)) {
|
||||
else if (Plugin::IsValid(file, *_game)) {
|
||||
Plugin plugin(*_game, file, true);
|
||||
trueVersion = Version(plugin.Version());
|
||||
}
|
||||
|
||||
@@ -224,24 +224,29 @@ namespace loot {
|
||||
return _isEmpty;
|
||||
}
|
||||
|
||||
bool Plugin::IsValid(const Game& game) const {
|
||||
BOOST_LOG_TRIVIAL(trace) << "Checking to see if \"" << name << "\" is a valid plugin.";
|
||||
// Check the extension, because only plugins with the .esm or .esp
|
||||
// extension (or .ghost, which is trimmed) should be handled by LOOT,
|
||||
// even if the file content is valid.
|
||||
bool Plugin::IsValid(const std::string& filename, const Game& game) {
|
||||
BOOST_LOG_TRIVIAL(trace) << "Checking to see if \"" << filename << "\" is a valid plugin.";
|
||||
|
||||
//If the filename passed ends in '.ghost', that should be trimmed.
|
||||
std::string name;
|
||||
if (boost::iends_with(filename, ".ghost"))
|
||||
name = filename.substr(0, filename.length() - 6);
|
||||
else
|
||||
name = filename;
|
||||
|
||||
// Check that the file has a valid extension.
|
||||
if (!boost::iends_with(name, ".esm") && !boost::iends_with(name, ".esp"))
|
||||
return false;
|
||||
|
||||
// Add the ".ghost" file extension if the plugin is ghosted.
|
||||
boost::filesystem::path filepath = game.DataPath() / name;
|
||||
|
||||
// In case the plugin is ghosted.
|
||||
if (!boost::filesystem::exists(filepath) && boost::filesystem::exists(filepath.string() + ".ghost"))
|
||||
filepath += ".ghost";
|
||||
|
||||
if (libespm::Plugin::isValid(filepath, game.LibespmId(), true))
|
||||
return true;
|
||||
|
||||
BOOST_LOG_TRIVIAL(warning) << "The .es(p|m) file \"" << name << "\" is not a valid plugin.";
|
||||
BOOST_LOG_TRIVIAL(warning) << "The .es(p|m) file \"" << filename << "\" is not a valid plugin.";
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -54,7 +54,6 @@ namespace loot {
|
||||
size_t NumOverrideFormIDs() const;
|
||||
|
||||
bool LoadsBSA(const Game& game) const;
|
||||
bool IsValid(const Game& game) const;
|
||||
bool IsActive(const Game& game) const;
|
||||
|
||||
//Compare name strings.
|
||||
@@ -67,6 +66,7 @@ namespace loot {
|
||||
|
||||
//Validity checks.
|
||||
bool CheckInstallValidity(const Game& game); //Checks that reqs and masters are all present, and that no incs are present. Returns true if the plugin is dirty.
|
||||
static bool IsValid(const std::string& filename, const Game& game);
|
||||
private:
|
||||
bool _isEmpty; // Does the plugin contain any records other than the TES4 header?
|
||||
std::vector<std::string> masters;
|
||||
|
||||
@@ -119,14 +119,9 @@ TEST_F(Plugin, IsValid) {
|
||||
game.SetGamePath(dataPath.parent_path());
|
||||
ASSERT_NO_THROW(game.Init(false, localPath));
|
||||
|
||||
loot::Plugin plugin("Blank.esm");
|
||||
EXPECT_TRUE(plugin.IsValid(game));
|
||||
|
||||
plugin = loot::Plugin("NotAPlugin.esm");
|
||||
EXPECT_FALSE(plugin.IsValid(game));
|
||||
|
||||
plugin = loot::Plugin("EmptyFile.esm");
|
||||
EXPECT_FALSE(plugin.IsValid(game));
|
||||
EXPECT_TRUE(loot::Plugin::IsValid("Blank.esm", game));
|
||||
EXPECT_FALSE(loot::Plugin::IsValid("NotAPlugin.esm", game));
|
||||
EXPECT_FALSE(loot::Plugin::IsValid("EmptyFile.esm", game));
|
||||
}
|
||||
|
||||
TEST_F(Plugin, IsActive) {
|
||||
|
||||
Reference in New Issue
Block a user