mirror of
https://github.com/loot/libloot.git
synced 2026-07-27 14:16:01 -07:00
Move masterlist and userlist caches into ApiDatabase
It's the only place they're used.
This commit is contained in:
+20
-20
@@ -63,23 +63,23 @@ void ApiDatabase::LoadLists(const std::string& masterlistPath,
|
||||
}
|
||||
}
|
||||
|
||||
game_.GetMasterlist() = temp;
|
||||
game_.GetUserlist() = userTemp;
|
||||
masterlist_ = temp;
|
||||
userlist_ = userTemp;
|
||||
}
|
||||
|
||||
void ApiDatabase::EvalLists() {
|
||||
// Clear caches before evaluating conditions.
|
||||
game_.ClearCachedConditions();
|
||||
|
||||
Masterlist temp = game_.GetMasterlist();
|
||||
MetadataList userTemp = game_.GetUserlist();
|
||||
Masterlist temp = masterlist_;
|
||||
MetadataList userTemp = userlist_;
|
||||
|
||||
// Refresh active plugins before evaluating conditions.
|
||||
temp.EvalAllConditions(game_);
|
||||
userTemp.EvalAllConditions(game_);
|
||||
|
||||
game_.GetMasterlist() = temp;
|
||||
game_.GetUserlist() = userTemp;
|
||||
masterlist_ = temp;
|
||||
userlist_ = userTemp;
|
||||
}
|
||||
|
||||
void ApiDatabase::WriteUserMetadata(const std::string& outputFile, const bool overwrite) const {
|
||||
@@ -89,7 +89,7 @@ void ApiDatabase::WriteUserMetadata(const std::string& outputFile, const bool ov
|
||||
if (boost::filesystem::exists(outputFile) && !overwrite)
|
||||
throw FileAccessError("Output file exists but overwrite is not set to true.");
|
||||
|
||||
game_.GetUserlist().Save(outputFile);
|
||||
userlist_.Save(outputFile);
|
||||
}
|
||||
|
||||
////////////////////////////////////
|
||||
@@ -104,7 +104,7 @@ bool ApiDatabase::UpdateMasterlist(const std::string& masterlistPath,
|
||||
|
||||
Masterlist masterlist;
|
||||
if (masterlist.Update(masterlistPath, remoteURL, remoteBranch)) {
|
||||
game_.GetMasterlist() = masterlist;
|
||||
masterlist_ = masterlist;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -126,8 +126,8 @@ bool ApiDatabase::IsLatestMasterlist(const std::string& masterlist_path,
|
||||
//////////////////////////
|
||||
|
||||
std::set<std::string> ApiDatabase::GetKnownBashTags() const {
|
||||
auto masterlistTags = game_.GetMasterlist().BashTags();
|
||||
auto userlistTags = game_.GetUserlist().BashTags();
|
||||
auto masterlistTags = masterlist_.BashTags();
|
||||
auto userlistTags = userlist_.BashTags();
|
||||
|
||||
if (!userlistTags.empty()) {
|
||||
masterlistTags.insert(std::begin(userlistTags), std::end(userlistTags));
|
||||
@@ -137,8 +137,8 @@ std::set<std::string> ApiDatabase::GetKnownBashTags() const {
|
||||
}
|
||||
|
||||
std::vector<Message> ApiDatabase::GetGeneralMessages(bool evaluateConditions) const {
|
||||
auto masterlistMessages = game_.GetMasterlist().Messages();
|
||||
auto userlistMessages = game_.GetUserlist().Messages();
|
||||
auto masterlistMessages = masterlist_.Messages();
|
||||
auto userlistMessages = userlist_.Messages();
|
||||
|
||||
if (!userlistMessages.empty()) {
|
||||
masterlistMessages.insert(std::end(masterlistMessages), std::begin(userlistMessages), std::end(userlistMessages));
|
||||
@@ -162,10 +162,10 @@ std::vector<Message> ApiDatabase::GetGeneralMessages(bool evaluateConditions) co
|
||||
PluginMetadata ApiDatabase::GetPluginMetadata(const std::string& plugin,
|
||||
bool includeUserMetadata,
|
||||
bool evaluateConditions) const {
|
||||
PluginMetadata metadata = game_.GetMasterlist().FindPlugin(plugin);
|
||||
PluginMetadata metadata = masterlist_.FindPlugin(plugin);
|
||||
|
||||
if (includeUserMetadata) {
|
||||
metadata.MergeMetadata(game_.GetUserlist().FindPlugin(plugin));
|
||||
metadata.MergeMetadata(userlist_.FindPlugin(plugin));
|
||||
}
|
||||
|
||||
if (evaluateConditions) {
|
||||
@@ -178,7 +178,7 @@ PluginMetadata ApiDatabase::GetPluginMetadata(const std::string& plugin,
|
||||
|
||||
PluginMetadata ApiDatabase::GetPluginUserMetadata(const std::string& plugin,
|
||||
bool evaluateConditions) const {
|
||||
PluginMetadata metadata = game_.GetUserlist().FindPlugin(plugin);
|
||||
PluginMetadata metadata = userlist_.FindPlugin(plugin);
|
||||
|
||||
if (evaluateConditions) {
|
||||
ConditionEvaluator evaluator(&game_);
|
||||
@@ -189,16 +189,16 @@ PluginMetadata ApiDatabase::GetPluginUserMetadata(const std::string& plugin,
|
||||
}
|
||||
|
||||
void ApiDatabase::SetPluginUserMetadata(const PluginMetadata& pluginMetadata) {
|
||||
game_.GetUserlist().ErasePlugin(pluginMetadata);
|
||||
game_.GetUserlist().AddPlugin(pluginMetadata);
|
||||
userlist_.ErasePlugin(pluginMetadata);
|
||||
userlist_.AddPlugin(pluginMetadata);
|
||||
}
|
||||
|
||||
void ApiDatabase::DiscardPluginUserMetadata(const std::string& plugin) {
|
||||
game_.GetUserlist().ErasePlugin(plugin);
|
||||
userlist_.ErasePlugin(plugin);
|
||||
}
|
||||
|
||||
void ApiDatabase::DiscardAllUserMetadata() {
|
||||
game_.GetUserlist().Clear();
|
||||
userlist_.Clear();
|
||||
}
|
||||
|
||||
// Writes a minimal masterlist that only contains mods that have Bash Tag suggestions,
|
||||
@@ -212,7 +212,7 @@ void ApiDatabase::WriteMinimalList(const std::string& outputFile, const bool ove
|
||||
if (boost::filesystem::exists(outputFile) && !overwrite)
|
||||
throw FileAccessError("Output file exists but overwrite is not set to true.");
|
||||
|
||||
Masterlist temp = game_.GetMasterlist();
|
||||
Masterlist temp = masterlist_;
|
||||
std::unordered_set<PluginMetadata> minimalPlugins;
|
||||
for (const auto &plugin : temp.Plugins()) {
|
||||
PluginMetadata p(plugin.GetName());
|
||||
|
||||
@@ -75,6 +75,8 @@ struct ApiDatabase : public DatabaseInterface {
|
||||
void DiscardAllUserMetadata();
|
||||
private:
|
||||
Game& game_;
|
||||
Masterlist masterlist_;
|
||||
MetadataList userlist_;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -40,15 +40,11 @@ namespace loot {
|
||||
GameCache::GameCache() {}
|
||||
|
||||
GameCache::GameCache(const GameCache& cache) :
|
||||
masterlist_(cache.masterlist_),
|
||||
userlist_(cache.userlist_),
|
||||
conditions_(cache.conditions_),
|
||||
plugins_(cache.plugins_) {}
|
||||
|
||||
GameCache& GameCache::operator=(const GameCache& cache) {
|
||||
if (&cache != this) {
|
||||
masterlist_ = cache.masterlist_;
|
||||
userlist_ = cache.userlist_;
|
||||
conditions_ = cache.conditions_;
|
||||
plugins_ = cache.plugins_;
|
||||
}
|
||||
@@ -56,14 +52,6 @@ GameCache& GameCache::operator=(const GameCache& cache) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
Masterlist & GameCache::GetMasterlist() {
|
||||
return masterlist_;
|
||||
}
|
||||
|
||||
MetadataList & GameCache::GetUserlist() {
|
||||
return userlist_;
|
||||
}
|
||||
|
||||
void GameCache::CacheCondition(const std::string& condition, bool result) {
|
||||
lock_guard<mutex> guard(mutex_);
|
||||
conditions_.insert(pair<string, bool>(to_lower(condition), result));
|
||||
|
||||
@@ -41,9 +41,6 @@ public:
|
||||
|
||||
GameCache& operator=(const GameCache& cache);
|
||||
|
||||
Masterlist& GetMasterlist();
|
||||
MetadataList& GetUserlist();
|
||||
|
||||
// Returns false for second bool if no cached condition.
|
||||
std::pair<bool, bool> GetCachedCondition(const std::string& condition) const;
|
||||
void CacheCondition(const std::string& condition, bool result);
|
||||
@@ -55,8 +52,6 @@ public:
|
||||
void ClearCachedConditions();
|
||||
void ClearCachedPlugins();
|
||||
private:
|
||||
Masterlist masterlist_;
|
||||
MetadataList userlist_;
|
||||
std::unordered_map<std::string, bool> conditions_;
|
||||
std::unordered_map<std::string, std::shared_ptr<const Plugin>> plugins_;
|
||||
|
||||
|
||||
@@ -89,7 +89,7 @@ TEST_P(PluginSorterTest, sortingShouldEvaluateRelativeGlobalPriorities) {
|
||||
ASSERT_NO_THROW(loadInstalledPlugins(game_, false));
|
||||
PluginMetadata plugin(blankDifferentMasterDependentEsp);
|
||||
plugin.SetGlobalPriority(Priority(-100));
|
||||
game_.GetUserlist().AddPlugin(plugin);
|
||||
game_.GetDatabase()->SetPluginUserMetadata(plugin);
|
||||
|
||||
PluginSorter ps;
|
||||
std::vector<std::string> expectedSortedOrder({
|
||||
@@ -116,7 +116,7 @@ TEST_P(PluginSorterTest, sortingWithGlobalPrioritiesShouldInheritRecursivelyRega
|
||||
// Set Blank.esp's priority.
|
||||
PluginMetadata plugin(blankEsp);
|
||||
plugin.SetGlobalPriority(Priority(2));
|
||||
game_.GetUserlist().AddPlugin(plugin);
|
||||
game_.GetDatabase()->SetPluginUserMetadata(plugin);
|
||||
|
||||
// Load Blank - Master Dependent.esp after Blank.esp so that it
|
||||
// inherits Blank.esp's priority.
|
||||
@@ -124,7 +124,7 @@ TEST_P(PluginSorterTest, sortingWithGlobalPrioritiesShouldInheritRecursivelyRega
|
||||
plugin.SetLoadAfterFiles({
|
||||
File(blankEsp),
|
||||
});
|
||||
game_.GetUserlist().AddPlugin(plugin);
|
||||
game_.GetDatabase()->SetPluginUserMetadata(plugin);
|
||||
|
||||
// Load Blank - Different.esp after Blank - Master Dependent.esp, so
|
||||
// that it inherits its inherited priority.
|
||||
@@ -132,14 +132,14 @@ TEST_P(PluginSorterTest, sortingWithGlobalPrioritiesShouldInheritRecursivelyRega
|
||||
plugin.SetLoadAfterFiles({
|
||||
File(blankMasterDependentEsp),
|
||||
});
|
||||
game_.GetUserlist().AddPlugin(plugin);
|
||||
game_.GetDatabase()->SetPluginUserMetadata(plugin);
|
||||
|
||||
// Set Blank - Different Master Dependent.esp to have a higher priority
|
||||
// than 0 but lower than Blank.esp. Need to also make it a global priority
|
||||
// because it doesn't otherwise conflict with the other plugins.
|
||||
plugin = PluginMetadata(blankDifferentMasterDependentEsp);
|
||||
plugin.SetGlobalPriority(Priority(1));
|
||||
game_.GetUserlist().AddPlugin(plugin);
|
||||
game_.GetDatabase()->SetPluginUserMetadata(plugin);
|
||||
|
||||
PluginSorter ps;
|
||||
std::vector<std::string> expectedSortedOrder({
|
||||
@@ -167,7 +167,7 @@ TEST_P(PluginSorterTest, sortingShouldUseLoadAfterMetadataWhenDecidingRelativePl
|
||||
File(blankDifferentEsp),
|
||||
File(blankDifferentPluginDependentEsp),
|
||||
});
|
||||
game_.GetUserlist().AddPlugin(plugin);
|
||||
game_.GetDatabase()->SetPluginUserMetadata(plugin);
|
||||
|
||||
PluginSorter ps;
|
||||
std::vector<std::string> expectedSortedOrder({
|
||||
@@ -195,7 +195,7 @@ TEST_P(PluginSorterTest, sortingShouldUseRequirementMetadataWhenDecidingRelative
|
||||
File(blankDifferentEsp),
|
||||
File(blankDifferentPluginDependentEsp),
|
||||
});
|
||||
game_.GetUserlist().AddPlugin(plugin);
|
||||
game_.GetDatabase()->SetPluginUserMetadata(plugin);
|
||||
|
||||
PluginSorter ps;
|
||||
std::vector<std::string> expectedSortedOrder({
|
||||
@@ -220,7 +220,7 @@ TEST_P(PluginSorterTest, sortingShouldThrowIfACyclicInteractionIsEncountered) {
|
||||
ASSERT_NO_THROW(loadInstalledPlugins(game_, false));
|
||||
PluginMetadata plugin(blankEsm);
|
||||
plugin.SetLoadAfterFiles({File(blankMasterDependentEsm)});
|
||||
game_.GetUserlist().AddPlugin(plugin);
|
||||
game_.GetDatabase()->SetPluginUserMetadata(plugin);
|
||||
|
||||
PluginSorter ps;
|
||||
EXPECT_THROW(ps.Sort(game_), CyclicInteractionError);
|
||||
|
||||
Reference in New Issue
Block a user