mirror of
https://github.com/loot/libloot.git
synced 2026-07-27 14:16:01 -07:00
Remove Game dependence from ApiDatabase
This commit is contained in:
+13
-11
@@ -36,7 +36,12 @@
|
||||
#include "api/plugin/plugin_sorter.h"
|
||||
|
||||
namespace loot {
|
||||
ApiDatabase::ApiDatabase(Game& game) : game_(game) {}
|
||||
ApiDatabase::ApiDatabase(const GameType gameType,
|
||||
const boost::filesystem::path& dataPath,
|
||||
std::shared_ptr<GameCache> gameCache,
|
||||
std::shared_ptr<LoadOrderHandler> loadOrderHandler) :
|
||||
gameCache_(gameCache),
|
||||
conditionEvaluator_(gameType, dataPath, gameCache, loadOrderHandler) {}
|
||||
|
||||
///////////////////////////////////
|
||||
// Database Loading Functions
|
||||
@@ -69,14 +74,14 @@ void ApiDatabase::LoadLists(const std::string& masterlistPath,
|
||||
|
||||
void ApiDatabase::EvalLists() {
|
||||
// Clear caches before evaluating conditions.
|
||||
game_.GetCache()->ClearCachedConditions();
|
||||
gameCache_->ClearCachedConditions();
|
||||
|
||||
Masterlist temp = masterlist_;
|
||||
MetadataList userTemp = userlist_;
|
||||
|
||||
// Refresh active plugins before evaluating conditions.
|
||||
temp.EvalAllConditions(game_);
|
||||
userTemp.EvalAllConditions(game_);
|
||||
temp.EvalAllConditions(conditionEvaluator_);
|
||||
userTemp.EvalAllConditions(conditionEvaluator_);
|
||||
|
||||
masterlist_ = temp;
|
||||
userlist_ = userTemp;
|
||||
@@ -146,10 +151,9 @@ std::vector<Message> ApiDatabase::GetGeneralMessages(bool evaluateConditions) co
|
||||
|
||||
if (evaluateConditions) {
|
||||
// Evaluate conditions from scratch.
|
||||
game_.GetCache()->ClearCachedConditions();
|
||||
ConditionEvaluator evaluator(&game_);
|
||||
gameCache_->ClearCachedConditions();
|
||||
for (auto it = std::begin(masterlistMessages); it != std::end(masterlistMessages);) {
|
||||
if (!evaluator.evaluate(it->GetCondition()))
|
||||
if (!conditionEvaluator_.evaluate(it->GetCondition()))
|
||||
it = masterlistMessages.erase(it);
|
||||
else
|
||||
++it;
|
||||
@@ -169,8 +173,7 @@ PluginMetadata ApiDatabase::GetPluginMetadata(const std::string& plugin,
|
||||
}
|
||||
|
||||
if (evaluateConditions) {
|
||||
ConditionEvaluator evaluator(&game_);
|
||||
return evaluator.evaluateAll(metadata);
|
||||
return conditionEvaluator_.evaluateAll(metadata);
|
||||
}
|
||||
|
||||
return metadata;
|
||||
@@ -181,8 +184,7 @@ PluginMetadata ApiDatabase::GetPluginUserMetadata(const std::string& plugin,
|
||||
PluginMetadata metadata = userlist_.FindPlugin(plugin);
|
||||
|
||||
if (evaluateConditions) {
|
||||
ConditionEvaluator evaluator(&game_);
|
||||
return evaluator.evaluateAll(metadata);
|
||||
return conditionEvaluator_.evaluateAll(metadata);
|
||||
}
|
||||
|
||||
return metadata;
|
||||
|
||||
+12
-3
@@ -29,12 +29,20 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "api/game/game.h"
|
||||
#include "api/game/game_cache.h"
|
||||
#include "api/game/load_order_handler.h"
|
||||
#include "api/metadata/condition_evaluator.h"
|
||||
#include "api/metadata_list.h"
|
||||
#include "api/masterlist.h"
|
||||
#include "loot/database_interface.h"
|
||||
#include "loot/enum/game_type.h"
|
||||
|
||||
namespace loot {
|
||||
struct ApiDatabase : public DatabaseInterface {
|
||||
ApiDatabase(Game& game);
|
||||
ApiDatabase(const GameType gameType,
|
||||
const boost::filesystem::path& dataPath,
|
||||
std::shared_ptr<GameCache> gameCache,
|
||||
std::shared_ptr<LoadOrderHandler> loadOrderHandler);
|
||||
|
||||
void LoadLists(const std::string& masterlist_path,
|
||||
const std::string& userlist_path = "");
|
||||
@@ -74,7 +82,8 @@ struct ApiDatabase : public DatabaseInterface {
|
||||
|
||||
void DiscardAllUserMetadata();
|
||||
private:
|
||||
Game& game_;
|
||||
std::shared_ptr<GameCache> gameCache_;
|
||||
ConditionEvaluator conditionEvaluator_;
|
||||
Masterlist masterlist_;
|
||||
MetadataList userlist_;
|
||||
};
|
||||
|
||||
@@ -70,7 +70,7 @@ Game::Game(const GameType gameType,
|
||||
|
||||
loadOrderHandler_->Init(type_, gamePath_, localDataPath_);
|
||||
|
||||
database_ = std::make_shared<ApiDatabase>(*this);
|
||||
database_ = std::make_shared<ApiDatabase>(Type(), DataPath(), GetCache(), GetLoadOrderHandler());
|
||||
}
|
||||
|
||||
GameType Game::Type() const {
|
||||
|
||||
@@ -29,8 +29,6 @@
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "api/masterlist.h"
|
||||
#include "api/metadata_list.h"
|
||||
#include "api/plugin/plugin.h"
|
||||
|
||||
namespace loot {
|
||||
|
||||
@@ -35,10 +35,18 @@
|
||||
using boost::format;
|
||||
|
||||
namespace loot {
|
||||
ConditionEvaluator::ConditionEvaluator(Game * game) : game_(game) {}
|
||||
ConditionEvaluator::ConditionEvaluator() : gameType_(GameType::tes4), gameCache_(nullptr), loadOrderHandler_(nullptr) {}
|
||||
ConditionEvaluator::ConditionEvaluator(const GameType gameType,
|
||||
const boost::filesystem::path& dataPath,
|
||||
std::shared_ptr<GameCache> gameCache,
|
||||
std::shared_ptr<LoadOrderHandler> loadOrderHandler) :
|
||||
gameType_(gameType),
|
||||
dataPath_(dataPath),
|
||||
gameCache_(gameCache),
|
||||
loadOrderHandler_(loadOrderHandler) {}
|
||||
|
||||
bool ConditionEvaluator::evaluate(const std::string& condition) {
|
||||
if (game_ == nullptr) {
|
||||
bool ConditionEvaluator::evaluate(const std::string& condition) const {
|
||||
if (shouldParseOnly()) {
|
||||
// Still check that the syntax is valid.
|
||||
parseCondition(condition);
|
||||
return false;
|
||||
@@ -49,19 +57,19 @@ bool ConditionEvaluator::evaluate(const std::string& condition) {
|
||||
|
||||
BOOST_LOG_TRIVIAL(trace) << "Evaluating condition: " << condition;
|
||||
|
||||
auto cachedValue = game_->GetCache()->GetCachedCondition(condition);
|
||||
auto cachedValue = gameCache_->GetCachedCondition(condition);
|
||||
if (cachedValue.second)
|
||||
return cachedValue.first;
|
||||
|
||||
bool result = parseCondition(condition);
|
||||
|
||||
game_->GetCache()->CacheCondition(condition, result);
|
||||
gameCache_->CacheCondition(condition, result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool ConditionEvaluator::evaluate(const PluginCleaningData& cleaningData, const std::string& pluginName) {
|
||||
if (game_ == nullptr || pluginName.empty())
|
||||
bool ConditionEvaluator::evaluate(const PluginCleaningData& cleaningData, const std::string& pluginName) const {
|
||||
if (shouldParseOnly() || pluginName.empty())
|
||||
return false;
|
||||
|
||||
// First need to get plugin's CRC.
|
||||
@@ -69,23 +77,23 @@ bool ConditionEvaluator::evaluate(const PluginCleaningData& cleaningData, const
|
||||
|
||||
// Get the CRC from the game plugin cache if possible.
|
||||
try {
|
||||
crc = game_->GetPlugin(pluginName)->GetCRC();
|
||||
crc = gameCache_->GetPlugin(pluginName)->GetCRC();
|
||||
} catch (...) {}
|
||||
|
||||
// Otherwise calculate it from the file.
|
||||
if (crc == 0) {
|
||||
if (boost::filesystem::exists(game_->DataPath() / pluginName)) {
|
||||
crc = GetCrc32(game_->DataPath() / pluginName);
|
||||
} else if (boost::filesystem::exists(game_->DataPath() / (pluginName + ".ghost"))) {
|
||||
crc = GetCrc32(game_->DataPath() / (pluginName + ".ghost"));
|
||||
if (boost::filesystem::exists(dataPath_ / pluginName)) {
|
||||
crc = GetCrc32(dataPath_ / pluginName);
|
||||
} else if (boost::filesystem::exists(dataPath_ / (pluginName + ".ghost"))) {
|
||||
crc = GetCrc32(dataPath_ / (pluginName + ".ghost"));
|
||||
}
|
||||
}
|
||||
|
||||
return cleaningData.GetCRC() == crc;
|
||||
}
|
||||
|
||||
PluginMetadata ConditionEvaluator::evaluateAll(const PluginMetadata& pluginMetadata) {
|
||||
if (game_ == nullptr)
|
||||
PluginMetadata ConditionEvaluator::evaluateAll(const PluginMetadata& pluginMetadata) const {
|
||||
if (shouldParseOnly())
|
||||
return pluginMetadata;
|
||||
|
||||
PluginMetadata evaluatedMetadata(pluginMetadata.GetName());
|
||||
@@ -151,7 +159,7 @@ PluginMetadata ConditionEvaluator::evaluateAll(const PluginMetadata& pluginMetad
|
||||
bool ConditionEvaluator::fileExists(const std::string& filePath) const {
|
||||
validatePath(filePath);
|
||||
|
||||
if (game_ == nullptr)
|
||||
if (shouldParseOnly())
|
||||
return false;
|
||||
|
||||
if (filePath == "LOOT")
|
||||
@@ -161,23 +169,23 @@ bool ConditionEvaluator::fileExists(const std::string& filePath) const {
|
||||
// for plugins.
|
||||
try {
|
||||
// GetPlugin throws if it can't find an entry.
|
||||
game_->GetPlugin(filePath);
|
||||
gameCache_->GetPlugin(filePath);
|
||||
|
||||
return true;
|
||||
} catch (...) {
|
||||
// Not a loaded plugin, check the filesystem.
|
||||
if (boost::iends_with(filePath, ".esp") || boost::iends_with(filePath, ".esm"))
|
||||
return boost::filesystem::exists(game_->DataPath() / filePath)
|
||||
|| boost::filesystem::exists(game_->DataPath() / (filePath + ".ghost"));
|
||||
return boost::filesystem::exists(dataPath_ / filePath)
|
||||
|| boost::filesystem::exists(dataPath_ / (filePath + ".ghost"));
|
||||
else
|
||||
return boost::filesystem::exists(game_->DataPath() / filePath);
|
||||
return boost::filesystem::exists(dataPath_ / filePath);
|
||||
}
|
||||
}
|
||||
|
||||
bool ConditionEvaluator::regexMatchExists(const std::string& regexString) const {
|
||||
auto pathRegex = splitRegex(regexString);
|
||||
|
||||
if (game_ == nullptr)
|
||||
if (shouldParseOnly())
|
||||
return false;
|
||||
|
||||
return isRegexMatchInDataDirectory(pathRegex,
|
||||
@@ -187,7 +195,7 @@ bool ConditionEvaluator::regexMatchExists(const std::string& regexString) const
|
||||
bool ConditionEvaluator::regexMatchesExist(const std::string& regexString) const {
|
||||
auto pathRegex = splitRegex(regexString);
|
||||
|
||||
if (game_ == nullptr)
|
||||
if (shouldParseOnly())
|
||||
return false;
|
||||
|
||||
return areRegexMatchesInDataDirectory(pathRegex,
|
||||
@@ -197,43 +205,43 @@ bool ConditionEvaluator::regexMatchesExist(const std::string& regexString) const
|
||||
bool ConditionEvaluator::isPluginActive(const std::string& pluginName) const {
|
||||
validatePath(pluginName);
|
||||
|
||||
if (game_ == nullptr)
|
||||
if (shouldParseOnly())
|
||||
return false;
|
||||
|
||||
if (pluginName == "LOOT")
|
||||
return false;
|
||||
|
||||
return game_->IsPluginActive(pluginName);
|
||||
return loadOrderHandler_->IsPluginActive(pluginName);
|
||||
}
|
||||
|
||||
bool ConditionEvaluator::isPluginMatchingRegexActive(const std::string& regexString) const {
|
||||
auto pathRegex = splitRegex(regexString);
|
||||
|
||||
if (game_ == nullptr)
|
||||
if (shouldParseOnly())
|
||||
return false;
|
||||
|
||||
return isRegexMatchInDataDirectory(pathRegex,
|
||||
[&](const std::string& filename) {
|
||||
return game_->IsPluginActive(filename);
|
||||
return loadOrderHandler_->IsPluginActive(filename);
|
||||
});
|
||||
}
|
||||
|
||||
bool ConditionEvaluator::arePluginsActive(const std::string& regexString) const {
|
||||
auto pathRegex = splitRegex(regexString);
|
||||
|
||||
if (game_ == nullptr)
|
||||
if (shouldParseOnly())
|
||||
return false;
|
||||
|
||||
return areRegexMatchesInDataDirectory(pathRegex,
|
||||
[&](const std::string& filename) {
|
||||
return game_->IsPluginActive(filename);
|
||||
return loadOrderHandler_->IsPluginActive(filename);
|
||||
});
|
||||
}
|
||||
|
||||
bool ConditionEvaluator::checksumMatches(const std::string& filePath, const uint32_t checksum) {
|
||||
bool ConditionEvaluator::checksumMatches(const std::string& filePath, const uint32_t checksum) const {
|
||||
validatePath(filePath);
|
||||
|
||||
if (game_ == nullptr)
|
||||
if (shouldParseOnly())
|
||||
return false;
|
||||
|
||||
uint32_t realChecksum = 0;
|
||||
@@ -243,14 +251,14 @@ bool ConditionEvaluator::checksumMatches(const std::string& filePath, const uint
|
||||
// CRC could be for a plugin or a file.
|
||||
// Get the CRC from the game plugin cache if possible.
|
||||
try {
|
||||
realChecksum = game_->GetPlugin(filePath)->GetCRC();
|
||||
realChecksum = gameCache_->GetPlugin(filePath)->GetCRC();
|
||||
} catch (...) {}
|
||||
|
||||
if (realChecksum == 0) {
|
||||
if (boost::filesystem::exists(game_->DataPath() / filePath))
|
||||
realChecksum = GetCrc32(game_->DataPath() / filePath);
|
||||
else if ((boost::iends_with(filePath, ".esp") || boost::iends_with(filePath, ".esm")) && boost::filesystem::exists(game_->DataPath() / (filePath + ".ghost")))
|
||||
realChecksum = GetCrc32(game_->DataPath() / (filePath + ".ghost"));
|
||||
if (boost::filesystem::exists(dataPath_ / filePath))
|
||||
realChecksum = GetCrc32(dataPath_ / filePath);
|
||||
else if ((boost::iends_with(filePath, ".esp") || boost::iends_with(filePath, ".esm")) && boost::filesystem::exists(dataPath_ / (filePath + ".ghost")))
|
||||
realChecksum = GetCrc32(dataPath_ / (filePath + ".ghost"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -339,7 +347,7 @@ std::pair<boost::filesystem::path, std::regex> ConditionEvaluator::splitRegex(co
|
||||
}
|
||||
|
||||
bool ConditionEvaluator::isGameSubdirectory(const boost::filesystem::path& path) const {
|
||||
boost::filesystem::path parentPath = game_->DataPath() / path;
|
||||
boost::filesystem::path parentPath = dataPath_ / path;
|
||||
|
||||
return boost::filesystem::exists(parentPath) && boost::filesystem::is_directory(parentPath);
|
||||
}
|
||||
@@ -353,7 +361,7 @@ bool ConditionEvaluator::isRegexMatchInDataDirectory(const std::pair<boost::file
|
||||
return false;
|
||||
}
|
||||
|
||||
return std::any_of(boost::filesystem::directory_iterator(game_->DataPath() / pathRegex.first),
|
||||
return std::any_of(boost::filesystem::directory_iterator(dataPath_ / pathRegex.first),
|
||||
boost::filesystem::directory_iterator(),
|
||||
[&](const boost::filesystem::directory_entry& entry) {
|
||||
const std::string filename = entry.path().filename().string();
|
||||
@@ -376,7 +384,7 @@ bool ConditionEvaluator::areRegexMatchesInDataDirectory(const std::pair<boost::f
|
||||
return false;
|
||||
});
|
||||
}
|
||||
bool ConditionEvaluator::parseCondition(const std::string & condition) {
|
||||
bool ConditionEvaluator::parseCondition(const std::string & condition) const {
|
||||
if (condition.empty())
|
||||
return true;
|
||||
|
||||
@@ -402,16 +410,19 @@ Version ConditionEvaluator::getVersion(const std::string& filePath) const {
|
||||
// from its description field. Try getting an entry from the
|
||||
// plugin cache.
|
||||
try {
|
||||
return Version(game_->GetPlugin(filePath)->GetVersion());
|
||||
return Version(gameCache_->GetPlugin(filePath)->GetVersion());
|
||||
} catch (...) {
|
||||
// The file wasn't in the plugin cache, load it as a plugin
|
||||
// if it appears to be valid, otherwise treat it as a non
|
||||
// plugin file.
|
||||
if (Plugin::IsValid(filePath, game_->Type(), game_->DataPath()))
|
||||
return Version(Plugin(game_->Type(), game_->DataPath(), game_->GetLoadOrderHandler(), filePath, true).GetVersion());
|
||||
if (Plugin::IsValid(filePath, gameType_, dataPath_))
|
||||
return Version(Plugin(gameType_, dataPath_, loadOrderHandler_, filePath, true).GetVersion());
|
||||
|
||||
return Version(game_->DataPath() / filePath);
|
||||
return Version(dataPath_ / filePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
bool ConditionEvaluator::shouldParseOnly() const {
|
||||
return gameCache_ == nullptr || loadOrderHandler_ == nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,8 @@
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#include "api/game/game.h"
|
||||
#include "api/game/game_cache.h"
|
||||
#include "api/game/load_order_handler.h"
|
||||
#include "api/helpers/version.h"
|
||||
#include "loot/metadata/plugin_cleaning_data.h"
|
||||
#include "loot/metadata/plugin_metadata.h"
|
||||
@@ -38,11 +39,15 @@
|
||||
namespace loot {
|
||||
class ConditionEvaluator {
|
||||
public:
|
||||
ConditionEvaluator(Game * game);
|
||||
ConditionEvaluator();
|
||||
ConditionEvaluator(const GameType gameType,
|
||||
const boost::filesystem::path& dataPath,
|
||||
std::shared_ptr<GameCache> gameCache,
|
||||
std::shared_ptr<LoadOrderHandler> loadOrderHandler);
|
||||
|
||||
bool evaluate(const std::string& condition);
|
||||
bool evaluate(const PluginCleaningData& cleaningData, const std::string& pluginName);
|
||||
PluginMetadata evaluateAll(const PluginMetadata& pluginMetadata);
|
||||
bool evaluate(const std::string& condition) const;
|
||||
bool evaluate(const PluginCleaningData& cleaningData, const std::string& pluginName) const;
|
||||
PluginMetadata evaluateAll(const PluginMetadata& pluginMetadata) const;
|
||||
|
||||
bool fileExists(const std::string& filePath) const;
|
||||
bool regexMatchExists(const std::string& regexString) const;
|
||||
@@ -53,7 +58,7 @@ public:
|
||||
bool arePluginsActive(const std::string& regexString) const;
|
||||
|
||||
bool checksumMatches(const std::string& filePath,
|
||||
const uint32_t checksum);
|
||||
const uint32_t checksum) const;
|
||||
|
||||
bool compareVersions(const std::string& filePath,
|
||||
const std::string& testVersion,
|
||||
@@ -74,11 +79,16 @@ private:
|
||||
bool areRegexMatchesInDataDirectory(const std::pair<boost::filesystem::path, std::regex>& pathRegex,
|
||||
const std::function<bool(const std::string&)> condition) const;
|
||||
|
||||
bool parseCondition(const std::string& condition);
|
||||
bool parseCondition(const std::string& condition) const;
|
||||
|
||||
Version getVersion(const std::string& filePath) const;
|
||||
|
||||
Game * game_;
|
||||
bool shouldParseOnly() const;
|
||||
|
||||
const GameType gameType_;
|
||||
const boost::filesystem::path dataPath_;
|
||||
const std::shared_ptr<GameCache> gameCache_;
|
||||
const std::shared_ptr<LoadOrderHandler> loadOrderHandler_;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -55,8 +55,7 @@ namespace loot {
|
||||
template<typename Iterator, typename Skipper>
|
||||
class ConditionGrammar : public boost::spirit::qi::grammar < Iterator, bool(), Skipper > {
|
||||
public:
|
||||
ConditionGrammar() : ConditionGrammar(nullptr) {}
|
||||
ConditionGrammar(ConditionEvaluator& evaluator) : ConditionGrammar::base_type(expression_, "condition grammar"), evaluator_(evaluator) {
|
||||
ConditionGrammar(const ConditionEvaluator& evaluator) : ConditionGrammar::base_type(expression_, "condition grammar"), evaluator_(evaluator) {
|
||||
using boost::spirit::unicode::char_;
|
||||
using boost::spirit::unicode::string;
|
||||
namespace phoenix = boost::phoenix;
|
||||
@@ -203,7 +202,7 @@ private:
|
||||
boost::spirit::qi::rule<Iterator, std::string()> quotedStr_, filePath_, comparator_;
|
||||
boost::spirit::qi::rule<Iterator, char()> invalidPathChars_;
|
||||
|
||||
ConditionEvaluator& evaluator_;
|
||||
const ConditionEvaluator& evaluator_;
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -47,8 +47,6 @@ std::string ConditionalMetadata::GetCondition() const {
|
||||
|
||||
void ConditionalMetadata::ParseCondition() const {
|
||||
BOOST_LOG_TRIVIAL(trace) << "Testing condition syntax: " << condition_;
|
||||
ConditionEvaluator evaluator(nullptr);
|
||||
|
||||
evaluator.evaluate(condition_);
|
||||
ConditionEvaluator().evaluate(condition_);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,16 +152,14 @@ void MetadataList::AppendMessage(const Message& message) {
|
||||
messages_.push_back(message);
|
||||
}
|
||||
|
||||
void MetadataList::EvalAllConditions(Game& game) {
|
||||
ConditionEvaluator evaluator(&game);
|
||||
|
||||
void MetadataList::EvalAllConditions(const ConditionEvaluator& conditionEvaluator) {
|
||||
if (unevaluatedPlugins_.empty())
|
||||
unevaluatedPlugins_.swap(plugins_);
|
||||
else
|
||||
plugins_.clear();
|
||||
|
||||
for (const auto& plugin : unevaluatedPlugins_) {
|
||||
plugins_.insert(evaluator.evaluateAll(plugin));
|
||||
plugins_.insert(conditionEvaluator.evaluateAll(plugin));
|
||||
}
|
||||
|
||||
if (unevaluatedRegexPlugins_.empty())
|
||||
@@ -170,7 +168,7 @@ void MetadataList::EvalAllConditions(Game& game) {
|
||||
regexPlugins_ = unevaluatedRegexPlugins_;
|
||||
|
||||
for (auto& plugin : regexPlugins_) {
|
||||
plugin = evaluator.evaluateAll(plugin);
|
||||
plugin = conditionEvaluator.evaluateAll(plugin);
|
||||
}
|
||||
|
||||
if (unevaluatedMessages_.empty())
|
||||
@@ -179,7 +177,7 @@ void MetadataList::EvalAllConditions(Game& game) {
|
||||
messages_.clear();
|
||||
|
||||
for (const auto& message : unevaluatedMessages_) {
|
||||
if (evaluator.evaluate(message.GetCondition()))
|
||||
if (conditionEvaluator.evaluate(message.GetCondition()))
|
||||
messages_.push_back(message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,11 +31,10 @@
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#include "api/metadata/condition_evaluator.h"
|
||||
#include "loot/metadata/plugin_metadata.h"
|
||||
|
||||
namespace loot {
|
||||
class Game;
|
||||
|
||||
class MetadataList {
|
||||
public:
|
||||
void Load(const boost::filesystem::path& filepath);
|
||||
@@ -57,7 +56,7 @@ public:
|
||||
void AppendMessage(const Message& message);
|
||||
|
||||
// Eval plugin conditions.
|
||||
void EvalAllConditions(Game& game);
|
||||
void EvalAllConditions(const ConditionEvaluator& conditionEvaluator);
|
||||
|
||||
protected:
|
||||
std::set<std::string> bashTags_;
|
||||
|
||||
@@ -39,7 +39,7 @@ protected:
|
||||
MessageContent("info"),
|
||||
})),
|
||||
game_(GetParam(), dataPath.parent_path(), localPath),
|
||||
evaluator_(&game_) {}
|
||||
evaluator_(game_.Type(), game_.DataPath(), game_.GetCache(), game_.GetLoadOrderHandler()) {}
|
||||
|
||||
const std::vector<MessageContent> info_;
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ protected:
|
||||
ConditionGrammarTest() :
|
||||
resourcePath(dataPath / "resource" / "detail" / "resource.txt"),
|
||||
game_(GetParam(), dataPath.parent_path(), localPath),
|
||||
evaluator_(&game_),
|
||||
evaluator_(game_.Type(), game_.DataPath(), game_.GetCache(), game_.GetLoadOrderHandler()),
|
||||
result_(false),
|
||||
success_(false) {}
|
||||
|
||||
@@ -103,7 +103,7 @@ INSTANTIATE_TEST_CASE_P(,
|
||||
GameType::tes5se));
|
||||
|
||||
TEST_P(ConditionGrammarTest, parsingInvalidSyntaxShouldThrow) {
|
||||
ConditionEvaluator evaluator(nullptr);
|
||||
ConditionEvaluator evaluator;
|
||||
Grammar grammar(evaluator);
|
||||
std::string condition("file(foo)");
|
||||
|
||||
@@ -126,7 +126,7 @@ TEST_P(ConditionGrammarTest, evaluatingInvalidSyntaxShouldThrow) {
|
||||
}
|
||||
|
||||
TEST_P(ConditionGrammarTest, parsingAnEmptyConditionShouldThrow) {
|
||||
ConditionEvaluator evaluator(nullptr);
|
||||
ConditionEvaluator evaluator;
|
||||
Grammar grammar(evaluator);
|
||||
std::string condition("");
|
||||
|
||||
@@ -573,7 +573,6 @@ TEST_P(ConditionGrammarTest, aVersionGreaterThanOrEqualToConditionForAPluginWith
|
||||
}
|
||||
|
||||
TEST_P(ConditionGrammarTest, anActiveConditionWithAPluginThatIsActiveShouldEvaluateToTrue) {
|
||||
|
||||
Grammar grammar(evaluator_);
|
||||
std::string condition("active(\"" + blankEsm + "\")");
|
||||
|
||||
@@ -587,7 +586,6 @@ TEST_P(ConditionGrammarTest, anActiveConditionWithAPluginThatIsActiveShouldEvalu
|
||||
}
|
||||
|
||||
TEST_P(ConditionGrammarTest, anActiveConditionWithAPluginThatIsNotActiveShouldEvaluateToFalse) {
|
||||
|
||||
Grammar grammar(evaluator_);
|
||||
std::string condition("active(\"" + blankEsp + "\")");
|
||||
|
||||
@@ -601,7 +599,6 @@ TEST_P(ConditionGrammarTest, anActiveConditionWithAPluginThatIsNotActiveShouldEv
|
||||
}
|
||||
|
||||
TEST_P(ConditionGrammarTest, anActiveConditionWithARegexMatchingAnActivePluginShouldEvaluateToTrue) {
|
||||
|
||||
Grammar grammar(evaluator_);
|
||||
std::string condition("active(\"Blank\\.esm\")");
|
||||
|
||||
@@ -615,7 +612,6 @@ TEST_P(ConditionGrammarTest, anActiveConditionWithARegexMatchingAnActivePluginSh
|
||||
}
|
||||
|
||||
TEST_P(ConditionGrammarTest, anActiveConditionWithARegexMatchingNoActivePluginsShouldEvaluateToFalse) {
|
||||
|
||||
Grammar grammar(evaluator_);
|
||||
std::string condition("active(\"Blank\\.esp\")");
|
||||
|
||||
@@ -629,7 +625,6 @@ TEST_P(ConditionGrammarTest, anActiveConditionWithARegexMatchingNoActivePluginsS
|
||||
}
|
||||
|
||||
TEST_P(ConditionGrammarTest, aManyActiveConditionWithARegexMatchingMoreThanOnePluginThatIsActiveShouldEvaluateToTrue) {
|
||||
|
||||
Grammar grammar(evaluator_);
|
||||
std::string condition("many_active(\"Blank( - Different Master Dependent)?\\.es(m|p)\")");
|
||||
|
||||
@@ -643,7 +638,6 @@ TEST_P(ConditionGrammarTest, aManyActiveConditionWithARegexMatchingMoreThanOnePl
|
||||
}
|
||||
|
||||
TEST_P(ConditionGrammarTest, aManyActiveConditionWithARegexMatchingOnlyOnePluginThatIsActiveShouldEvaluateToFalse) {
|
||||
|
||||
Grammar grammar(evaluator_);
|
||||
std::string condition("many_active(\"Blank\\.esm\")");
|
||||
|
||||
@@ -657,7 +651,6 @@ TEST_P(ConditionGrammarTest, aManyActiveConditionWithARegexMatchingOnlyOnePlugin
|
||||
}
|
||||
|
||||
TEST_P(ConditionGrammarTest, aManyActiveConditionWithARegexMatchingNoPluginsThatAreActiveShouldEvaluateToFalse) {
|
||||
|
||||
Grammar grammar(evaluator_);
|
||||
std::string condition("many_active(\"Blank\\.esp\")");
|
||||
|
||||
|
||||
@@ -285,6 +285,7 @@ TEST_P(MetadataListTest, erasePluginShouldRemoveStoredMetadataForTheGivenPlugin)
|
||||
|
||||
TEST_P(MetadataListTest, evalAllConditionsShouldEvaluateTheConditionsForThePluginsStoredInTeMetadataList) {
|
||||
Game game(GetParam(), dataPath.parent_path(), localPath);
|
||||
ConditionEvaluator evaluator(game.Type(), game.DataPath(), game.GetCache(), game.GetLoadOrderHandler());
|
||||
|
||||
MetadataList metadataList;
|
||||
ASSERT_NO_THROW(metadataList.Load(metadataPath));
|
||||
@@ -299,7 +300,7 @@ TEST_P(MetadataListTest, evalAllConditionsShouldEvaluateTheConditionsForThePlugi
|
||||
ASSERT_EQ(blankEsp, plugin.GetName());
|
||||
ASSERT_FALSE(plugin.HasNameOnly());
|
||||
|
||||
EXPECT_NO_THROW(metadataList.EvalAllConditions(game));
|
||||
EXPECT_NO_THROW(metadataList.EvalAllConditions(evaluator));
|
||||
|
||||
plugin = metadataList.FindPlugin(PluginMetadata(blankEsm));
|
||||
EXPECT_EQ(std::vector<Message>({
|
||||
|
||||
Reference in New Issue
Block a user