mirror of
https://github.com/loot/libloot.git
synced 2026-07-27 14:16:01 -07:00
Call MetadataList::Save() in WriteMinimalList
Don't reimplement the same logic.
This commit is contained in:
@@ -214,26 +214,15 @@ 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 = masterlist_;
|
||||
std::unordered_set<PluginMetadata> minimalPlugins;
|
||||
for (const auto &plugin : temp.Plugins()) {
|
||||
PluginMetadata p(plugin.GetName());
|
||||
p.SetTags(plugin.GetTags());
|
||||
p.SetDirtyInfo(plugin.GetDirtyInfo());
|
||||
minimalPlugins.insert(p);
|
||||
MetadataList minimalList;
|
||||
for (const auto& plugin : masterlist_.Plugins()) {
|
||||
PluginMetadata minimalPlugin(plugin.GetName());
|
||||
minimalPlugin.SetTags(plugin.GetTags());
|
||||
minimalPlugin.SetDirtyInfo(plugin.GetDirtyInfo());
|
||||
|
||||
minimalList.AddPlugin(minimalPlugin);
|
||||
}
|
||||
|
||||
YAML::Emitter yout;
|
||||
yout.SetIndent(2);
|
||||
yout << YAML::BeginMap
|
||||
<< YAML::Key << "plugins" << YAML::Value << minimalPlugins
|
||||
<< YAML::EndMap;
|
||||
|
||||
boost::filesystem::path p(outputFile);
|
||||
boost::filesystem::ofstream out(p);
|
||||
if (out.fail())
|
||||
throw FileAccessError("Couldn't open output file.");
|
||||
out << yout.c_str();
|
||||
out.close();
|
||||
minimalList.Save(outputFile);
|
||||
}
|
||||
}
|
||||
|
||||
+19
-11
@@ -69,20 +69,28 @@ void MetadataList::Load(const boost::filesystem::path& filepath) {
|
||||
|
||||
void MetadataList::Save(const boost::filesystem::path& filepath) const {
|
||||
BOOST_LOG_TRIVIAL(trace) << "Saving metadata list to: " << filepath;
|
||||
YAML::Emitter yout;
|
||||
yout.SetIndent(2);
|
||||
yout << YAML::BeginMap
|
||||
<< YAML::Key << "bash_tags" << YAML::Value << bashTags_
|
||||
<< YAML::Key << "globals" << YAML::Value << messages_
|
||||
<< YAML::Key << "plugins" << YAML::Value << Plugins()
|
||||
<< YAML::EndMap;
|
||||
YAML::Emitter emitter;
|
||||
emitter.SetIndent(2);
|
||||
emitter << YAML::BeginMap;
|
||||
|
||||
boost::filesystem::ofstream uout(filepath);
|
||||
if (uout.fail())
|
||||
if (!bashTags_.empty())
|
||||
emitter << YAML::Key << "bash_tags" << YAML::Value << bashTags_;
|
||||
|
||||
if (!messages_.empty())
|
||||
emitter << YAML::Key << "globals" << YAML::Value << messages_;
|
||||
|
||||
auto plugins = Plugins();
|
||||
if (!plugins.empty())
|
||||
emitter << YAML::Key << "plugins" << YAML::Value << plugins;
|
||||
|
||||
emitter << YAML::EndMap;
|
||||
|
||||
boost::filesystem::ofstream out(filepath);
|
||||
if (out.fail())
|
||||
throw FileAccessError("Couldn't open output file.");
|
||||
|
||||
uout << yout.c_str();
|
||||
uout.close();
|
||||
out << emitter.c_str();
|
||||
out.close();
|
||||
}
|
||||
|
||||
void MetadataList::Clear() {
|
||||
|
||||
@@ -220,9 +220,7 @@ TEST_P(DatabaseInterfaceTest, writeUserMetadataShouldShouldNotWriteMasterlistMet
|
||||
|
||||
EXPECT_NO_THROW(db_->WriteUserMetadata(minimalOutputPath_.string(), true));
|
||||
|
||||
std::string expectedContent = "bash_tags:\n []\nglobals:\n []\nplugins:\n []";
|
||||
|
||||
EXPECT_EQ(expectedContent, GetFileContent(minimalOutputPath_));
|
||||
EXPECT_EQ("{}", GetFileContent(minimalOutputPath_));
|
||||
}
|
||||
|
||||
TEST_P(DatabaseInterfaceTest, writeUserMetadataShouldShouldWriteUserMetadata) {
|
||||
|
||||
Reference in New Issue
Block a user