mirror of
https://github.com/loot/libloot.git
synced 2026-07-27 14:16:01 -07:00
Move yaml headers out of API
LOOT no longer needs them, so don't expose implementation details.
This commit is contained in:
@@ -1,98 +0,0 @@
|
||||
/* LOOT
|
||||
|
||||
A load order optimisation tool for Oblivion, Skyrim, Fallout 3 and
|
||||
Fallout: New Vegas.
|
||||
|
||||
Copyright (C) 2012-2016 WrinklyNinja
|
||||
|
||||
This file is part of LOOT.
|
||||
|
||||
LOOT is free software: you can redistribute
|
||||
it and/or modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
LOOT is distributed in the hope that it will
|
||||
be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LOOT. If not, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef LOOT_YAML_FILE
|
||||
#define LOOT_YAML_FILE
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <yaml-cpp/yaml.h>
|
||||
|
||||
#include "loot/metadata/file.h"
|
||||
|
||||
namespace YAML {
|
||||
template<>
|
||||
struct convert<loot::File> {
|
||||
static Node encode(const loot::File& rhs) {
|
||||
Node node;
|
||||
node["name"] = rhs.GetName();
|
||||
|
||||
if (rhs.IsConditional())
|
||||
node["condition"] = rhs.GetCondition();
|
||||
|
||||
if (rhs.GetDisplayName() != rhs.GetName())
|
||||
node["display"] = rhs.GetDisplayName();
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
static bool decode(const Node& node, loot::File& rhs) {
|
||||
if (!node.IsMap() && !node.IsScalar())
|
||||
throw RepresentationException(node.Mark(), "bad conversion: 'file' object must be a map or scalar");
|
||||
|
||||
if (node.IsMap()) {
|
||||
if (!node["name"])
|
||||
throw RepresentationException(node.Mark(), "bad conversion: 'name' key missing from 'file' map object");
|
||||
|
||||
std::string name = node["name"].as<std::string>();
|
||||
std::string condition, display;
|
||||
if (node["condition"])
|
||||
condition = node["condition"].as<std::string>();
|
||||
if (node["display"])
|
||||
display = node["display"].as<std::string>();
|
||||
rhs = loot::File(name, display, condition);
|
||||
} else
|
||||
rhs = loot::File(node.as<std::string>());
|
||||
|
||||
// Test condition syntax.
|
||||
try {
|
||||
rhs.ParseCondition();
|
||||
} catch (std::exception& e) {
|
||||
throw RepresentationException(node.Mark(), std::string("bad conversion: invalid condition syntax: ") + e.what());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
inline Emitter& operator << (Emitter& out, const loot::File& rhs) {
|
||||
if (!rhs.IsConditional() && (rhs.GetDisplayName().empty() || rhs.GetDisplayName() == rhs.GetName()))
|
||||
out << YAML::SingleQuoted << rhs.GetName();
|
||||
else {
|
||||
out << BeginMap
|
||||
<< Key << "name" << Value << YAML::SingleQuoted << rhs.GetName();
|
||||
|
||||
if (rhs.IsConditional())
|
||||
out << Key << "condition" << Value << YAML::SingleQuoted << rhs.GetCondition();
|
||||
|
||||
if (rhs.GetDisplayName() != rhs.GetName())
|
||||
out << Key << "display" << Value << YAML::SingleQuoted << rhs.GetDisplayName();
|
||||
|
||||
out << EndMap;
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,83 +0,0 @@
|
||||
/* LOOT
|
||||
|
||||
A load order optimisation tool for Oblivion, Skyrim, Fallout 3 and
|
||||
Fallout: New Vegas.
|
||||
|
||||
Copyright (C) 2012-2016 WrinklyNinja
|
||||
|
||||
This file is part of LOOT.
|
||||
|
||||
LOOT is free software: you can redistribute
|
||||
it and/or modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
LOOT is distributed in the hope that it will
|
||||
be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LOOT. If not, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef LOOT_YAML_LOCATION
|
||||
#define LOOT_YAML_LOCATION
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <yaml-cpp/yaml.h>
|
||||
|
||||
#include "loot/metadata/location.h"
|
||||
|
||||
namespace YAML {
|
||||
template<>
|
||||
struct convert<loot::Location> {
|
||||
static Node encode(const loot::Location& rhs) {
|
||||
Node node;
|
||||
|
||||
node["link"] = rhs.GetURL();
|
||||
if (!rhs.GetName().empty())
|
||||
node["name"] = rhs.GetName();
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
static bool decode(const Node& node, loot::Location& rhs) {
|
||||
if (!node.IsMap() && !node.IsScalar())
|
||||
throw RepresentationException(node.Mark(), "bad conversion: 'location' object must be a map or scalar");
|
||||
|
||||
std::string url;
|
||||
std::string name;
|
||||
|
||||
if (node.IsMap()) {
|
||||
if (!node["link"])
|
||||
throw RepresentationException(node.Mark(), "bad conversion: 'link' key missing from 'location' map object");
|
||||
|
||||
url = node["link"].as<std::string>();
|
||||
if (node["name"])
|
||||
name = node["name"].as<std::string>();
|
||||
} else
|
||||
url = node.as<std::string>();
|
||||
|
||||
rhs = loot::Location(url, name);
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
inline Emitter& operator << (Emitter& out, const loot::Location& rhs) {
|
||||
if (rhs.GetName().empty())
|
||||
out << YAML::SingleQuoted << rhs.GetURL();
|
||||
else {
|
||||
out << BeginMap
|
||||
<< Key << "link" << Value << YAML::SingleQuoted << rhs.GetURL()
|
||||
<< Key << "name" << Value << YAML::SingleQuoted << rhs.GetName()
|
||||
<< EndMap;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,150 +0,0 @@
|
||||
/* LOOT
|
||||
|
||||
A load order optimisation tool for Oblivion, Skyrim, Fallout 3 and
|
||||
Fallout: New Vegas.
|
||||
|
||||
Copyright (C) 2012-2016 WrinklyNinja
|
||||
|
||||
This file is part of LOOT.
|
||||
|
||||
LOOT is free software: you can redistribute
|
||||
it and/or modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
LOOT is distributed in the hope that it will
|
||||
be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LOOT. If not, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef LOOT_YAML_MESSAGE
|
||||
#define LOOT_YAML_MESSAGE
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/format.hpp>
|
||||
#include <yaml-cpp/yaml.h>
|
||||
|
||||
#include "loot/metadata/message.h"
|
||||
|
||||
namespace YAML {
|
||||
template<>
|
||||
struct convert<loot::Message> {
|
||||
static Node encode(const loot::Message& rhs) {
|
||||
Node node;
|
||||
node["content"] = rhs.GetContent();
|
||||
|
||||
if (rhs.GetType() == loot::MessageType::say)
|
||||
node["type"] = "say";
|
||||
else if (rhs.GetType() == loot::MessageType::warn)
|
||||
node["type"] = "warn";
|
||||
else
|
||||
node["type"] = "error";
|
||||
|
||||
if (rhs.IsConditional())
|
||||
node["condition"] = rhs.GetCondition();
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
static bool decode(const Node& node, loot::Message& rhs) {
|
||||
if (!node.IsMap())
|
||||
throw RepresentationException(node.Mark(), "bad conversion: 'message' object must be a map");
|
||||
if (!node["type"])
|
||||
throw RepresentationException(node.Mark(), "bad conversion: 'type' key missing from 'message' object");
|
||||
if (!node["content"])
|
||||
throw RepresentationException(node.Mark(), "bad conversion: 'content' key missing from 'message' object");
|
||||
|
||||
std::string type;
|
||||
type = node["type"].as<std::string>();
|
||||
|
||||
loot::MessageType typeNo = loot::MessageType::say;
|
||||
if (boost::iequals(type, "warn"))
|
||||
typeNo = loot::MessageType::warn;
|
||||
else if (boost::iequals(type, "error"))
|
||||
typeNo = loot::MessageType::error;
|
||||
|
||||
std::vector<loot::MessageContent> content;
|
||||
if (node["content"].IsSequence())
|
||||
content = node["content"].as< std::vector<loot::MessageContent> >();
|
||||
else {
|
||||
content.push_back(loot::MessageContent(node["content"].as<std::string>()));
|
||||
}
|
||||
|
||||
//Check now that at least one item in content is English if there are multiple items.
|
||||
if (content.size() > 1) {
|
||||
bool found = false;
|
||||
for (const auto &mc : content) {
|
||||
if (mc.GetLanguage() == loot::MessageContent::defaultLanguage)
|
||||
found = true;
|
||||
}
|
||||
if (!found)
|
||||
throw RepresentationException(node.Mark(), "bad conversion: multilingual messages must contain an English content string");
|
||||
}
|
||||
|
||||
// Make any substitutions at this point.
|
||||
if (node["subs"]) {
|
||||
std::vector<std::string> subs = node["subs"].as<std::vector<std::string>>();
|
||||
for (auto& mc : content) {
|
||||
boost::format f(mc.GetText());
|
||||
|
||||
for (const auto& sub : subs) {
|
||||
f = f % sub;
|
||||
}
|
||||
|
||||
try {
|
||||
mc = loot::MessageContent(f.str(), mc.GetLanguage());
|
||||
} catch (boost::io::format_error& e) {
|
||||
throw RepresentationException(node.Mark(), std::string("bad conversion: content substitution error: ") + e.what());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string condition;
|
||||
if (node["condition"])
|
||||
condition = node["condition"].as<std::string>();
|
||||
|
||||
rhs = loot::Message(typeNo, content, condition);
|
||||
|
||||
// Test condition syntax.
|
||||
try {
|
||||
rhs.ParseCondition();
|
||||
} catch (std::exception& e) {
|
||||
throw RepresentationException(node.Mark(), std::string("bad conversion: invalid condition syntax: ") + e.what());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
inline Emitter& operator << (Emitter& out, const loot::Message& rhs) {
|
||||
out << BeginMap;
|
||||
|
||||
if (rhs.GetType() == loot::MessageType::say)
|
||||
out << Key << "type" << Value << "say";
|
||||
else if (rhs.GetType() == loot::MessageType::warn)
|
||||
out << Key << "type" << Value << "warn";
|
||||
else
|
||||
out << Key << "type" << Value << "error";
|
||||
|
||||
if (rhs.GetContent().size() == 1)
|
||||
out << Key << "content" << Value << YAML::SingleQuoted << rhs.GetContent().front().GetText();
|
||||
else
|
||||
out << Key << "content" << Value << rhs.GetContent();
|
||||
|
||||
if (rhs.IsConditional())
|
||||
out << Key << "condition" << Value << YAML::SingleQuoted << rhs.GetCondition();
|
||||
|
||||
out << EndMap;
|
||||
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,74 +0,0 @@
|
||||
/* LOOT
|
||||
|
||||
A load order optimisation tool for Oblivion, Skyrim, Fallout 3 and
|
||||
Fallout: New Vegas.
|
||||
|
||||
Copyright (C) 2012-2016 WrinklyNinja
|
||||
|
||||
This file is part of LOOT.
|
||||
|
||||
LOOT is free software: you can redistribute
|
||||
it and/or modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
LOOT is distributed in the hope that it will
|
||||
be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LOOT. If not, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef LOOT_YAML_MESSAGE_CONTENT
|
||||
#define LOOT_YAML_MESSAGE_CONTENT
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <yaml-cpp/yaml.h>
|
||||
|
||||
#include "loot/metadata/message_content.h"
|
||||
|
||||
namespace YAML {
|
||||
template<>
|
||||
struct convert<loot::MessageContent> {
|
||||
static Node encode(const loot::MessageContent& rhs) {
|
||||
Node node;
|
||||
node["text"] = rhs.GetText();
|
||||
node["lang"] = rhs.GetLanguage();
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
static bool decode(const Node& node, loot::MessageContent& rhs) {
|
||||
if (!node.IsMap())
|
||||
throw RepresentationException(node.Mark(), "bad conversion: 'message content' object must be a map");
|
||||
if (!node["text"])
|
||||
throw RepresentationException(node.Mark(), "bad conversion: 'text' key missing from 'message content' object");
|
||||
if (!node["lang"])
|
||||
throw RepresentationException(node.Mark(), "bad conversion: 'lang' key missing from 'message content' object");
|
||||
|
||||
std::string text = node["text"].as<std::string>();
|
||||
std::string lang = node["lang"].as<std::string>();
|
||||
|
||||
rhs = loot::MessageContent(text, lang);
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
inline Emitter& operator << (Emitter& out, const loot::MessageContent& rhs) {
|
||||
out << BeginMap;
|
||||
|
||||
out << Key << "lang" << Value << rhs.GetLanguage();
|
||||
|
||||
out << Key << "text" << Value << YAML::SingleQuoted << rhs.GetText();
|
||||
|
||||
out << EndMap;
|
||||
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,125 +0,0 @@
|
||||
/* LOOT
|
||||
|
||||
A load order optimisation tool for Oblivion, Skyrim, Fallout 3 and
|
||||
Fallout: New Vegas.
|
||||
|
||||
Copyright (C) 2012-2016 WrinklyNinja
|
||||
|
||||
This file is part of LOOT.
|
||||
|
||||
LOOT is free software: you can redistribute
|
||||
it and/or modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
LOOT is distributed in the hope that it will
|
||||
be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LOOT. If not, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef LOOT_YAML_PLUGIN_CLEANING_DATA
|
||||
#define LOOT_YAML_PLUGIN_CLEANING_DATA
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
#include <yaml-cpp/yaml.h>
|
||||
|
||||
#include "loot/metadata/plugin_cleaning_data.h"
|
||||
|
||||
namespace YAML {
|
||||
template<>
|
||||
struct convert<loot::PluginCleaningData> {
|
||||
static Node encode(const loot::PluginCleaningData& rhs) {
|
||||
Node node;
|
||||
node["crc"] = rhs.GetCRC();
|
||||
node["util"] = rhs.GetCleaningUtility();
|
||||
node["info"] = rhs.GetInfo();
|
||||
|
||||
if (rhs.GetITMCount() > 0)
|
||||
node["itm"] = rhs.GetITMCount();
|
||||
if (rhs.GetDeletedReferenceCount() > 0)
|
||||
node["udr"] = rhs.GetDeletedReferenceCount();
|
||||
if (rhs.GetDeletedNavmeshCount() > 0)
|
||||
node["nav"] = rhs.GetDeletedNavmeshCount();
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
static bool decode(const Node& node, loot::PluginCleaningData& rhs) {
|
||||
if (!node.IsMap())
|
||||
throw RepresentationException(node.Mark(), "bad conversion: 'cleaning data' object must be a map");
|
||||
if (!node["crc"])
|
||||
throw RepresentationException(node.Mark(), "bad conversion: 'crc' key missing from 'cleaning data' object");
|
||||
if (!node["util"])
|
||||
throw RepresentationException(node.Mark(), "bad conversion: 'util' key missing from 'cleaning data' object");
|
||||
|
||||
uint32_t crc = node["crc"].as<uint32_t>();
|
||||
int itm = 0, ref = 0, nav = 0;
|
||||
|
||||
if (node["itm"])
|
||||
itm = node["itm"].as<unsigned int>();
|
||||
if (node["udr"])
|
||||
ref = node["udr"].as<unsigned int>();
|
||||
if (node["nav"])
|
||||
nav = node["nav"].as<unsigned int>();
|
||||
|
||||
std::string utility = node["util"].as<std::string>();
|
||||
|
||||
std::vector<loot::MessageContent> info;
|
||||
if (node["info"]) {
|
||||
if (node["info"].IsSequence())
|
||||
info = node["info"].as<std::vector<loot::MessageContent>>();
|
||||
else {
|
||||
info.push_back(loot::MessageContent(node["info"].as<std::string>()));
|
||||
}
|
||||
}
|
||||
|
||||
//Check now that at least one item in info is English if there are multiple items.
|
||||
if (info.size() > 1) {
|
||||
bool found = false;
|
||||
for (const auto &mc : info) {
|
||||
if (mc.GetLanguage() == loot::MessageContent::defaultLanguage)
|
||||
found = true;
|
||||
}
|
||||
if (!found)
|
||||
throw RepresentationException(node.Mark(), "bad conversion: multilingual messages must contain an English info string");
|
||||
}
|
||||
|
||||
rhs = loot::PluginCleaningData(crc, utility, info, itm, ref, nav);
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
inline Emitter& operator << (Emitter& out, const loot::PluginCleaningData& rhs) {
|
||||
out << BeginMap
|
||||
<< Key << "crc" << Value << Hex << rhs.GetCRC() << Dec
|
||||
<< Key << "util" << Value << YAML::SingleQuoted << rhs.GetCleaningUtility();
|
||||
|
||||
if (!rhs.GetInfo().empty()) {
|
||||
if (rhs.GetInfo().size() == 1)
|
||||
out << Key << "info" << Value << YAML::SingleQuoted << rhs.GetInfo().front().GetText();
|
||||
else
|
||||
out << Key << "info" << Value << rhs.GetInfo();
|
||||
}
|
||||
|
||||
if (rhs.GetITMCount() > 0)
|
||||
out << Key << "itm" << Value << rhs.GetITMCount();
|
||||
if (rhs.GetDeletedReferenceCount() > 0)
|
||||
out << Key << "udr" << Value << rhs.GetDeletedReferenceCount();
|
||||
if (rhs.GetDeletedNavmeshCount() > 0)
|
||||
out << Key << "nav" << Value << rhs.GetDeletedNavmeshCount();
|
||||
|
||||
out << EndMap;
|
||||
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,188 +0,0 @@
|
||||
/* LOOT
|
||||
|
||||
A load order optimisation tool for Oblivion, Skyrim, Fallout 3 and
|
||||
Fallout: New Vegas.
|
||||
|
||||
Copyright (C) 2012-2016 WrinklyNinja
|
||||
|
||||
This file is part of LOOT.
|
||||
|
||||
LOOT is free software: you can redistribute
|
||||
it and/or modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
LOOT is distributed in the hope that it will
|
||||
be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LOOT. If not, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef LOOT_YAML_PLUGIN_METADATA
|
||||
#define LOOT_YAML_PLUGIN_METADATA
|
||||
|
||||
#include <cstdint>
|
||||
#include <list>
|
||||
#include <regex>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <yaml-cpp/yaml.h>
|
||||
|
||||
#include "loot/metadata/plugin_metadata.h"
|
||||
|
||||
#include "loot/yaml/file.h"
|
||||
#include "loot/yaml/location.h"
|
||||
#include "loot/yaml/message_content.h"
|
||||
#include "loot/yaml/message.h"
|
||||
#include "loot/yaml/plugin_cleaning_data.h"
|
||||
#include "loot/yaml/set.h"
|
||||
#include "loot/yaml/tag.h"
|
||||
|
||||
namespace YAML {
|
||||
template<>
|
||||
struct convert<loot::PluginMetadata> {
|
||||
static Node encode(const loot::PluginMetadata& rhs) {
|
||||
Node node;
|
||||
node["name"] = rhs.GetName();
|
||||
|
||||
if (!rhs.IsEnabled())
|
||||
node["enabled"] = rhs.IsEnabled();
|
||||
|
||||
if (rhs.GetLocalPriority().IsExplicit())
|
||||
node["priority"] = rhs.GetLocalPriority().GetValue();
|
||||
|
||||
if (rhs.GetGlobalPriority().IsExplicit())
|
||||
node["global_priority"] = rhs.GetGlobalPriority().GetValue();
|
||||
|
||||
if (!rhs.GetLoadAfterFiles().empty())
|
||||
node["after"] = rhs.GetLoadAfterFiles();
|
||||
if (!rhs.GetRequirements().empty())
|
||||
node["req"] = rhs.GetRequirements();
|
||||
if (!rhs.GetIncompatibilities().empty())
|
||||
node["inc"] = rhs.GetIncompatibilities();
|
||||
if (!rhs.GetMessages().empty())
|
||||
node["msg"] = rhs.GetMessages();
|
||||
if (!rhs.GetTags().empty())
|
||||
node["tag"] = rhs.GetTags();
|
||||
if (!rhs.GetDirtyInfo().empty())
|
||||
node["dirty"] = rhs.GetDirtyInfo();
|
||||
if (!rhs.GetCleanInfo().empty())
|
||||
node["clean"] = rhs.GetCleanInfo();
|
||||
if (!rhs.GetLocations().empty())
|
||||
node["url"] = rhs.GetLocations();
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
static bool decode(const Node& node, loot::PluginMetadata& rhs) {
|
||||
if (!node.IsMap())
|
||||
throw RepresentationException(node.Mark(), "bad conversion: 'plugin metadata' object must be a map");
|
||||
if (!node["name"])
|
||||
throw RepresentationException(node.Mark(), "bad conversion: 'name' key missing from 'plugin metadata' object");
|
||||
|
||||
rhs = loot::PluginMetadata(node["name"].as<std::string>());
|
||||
|
||||
// Test for valid regex.
|
||||
if (rhs.IsRegexPlugin()) {
|
||||
try {
|
||||
std::regex(rhs.GetName(), std::regex::ECMAScript | std::regex::icase);
|
||||
} catch (std::regex_error& e) {
|
||||
throw RepresentationException(node.Mark(), std::string("bad conversion: invalid regex in 'name' key: ") + e.what());
|
||||
}
|
||||
}
|
||||
|
||||
if (node["enabled"])
|
||||
rhs.SetEnabled(node["enabled"].as<bool>());
|
||||
|
||||
// Read priority values as int to prevent values that are too large from
|
||||
// being converted to -128.
|
||||
if (node["priority"]) {
|
||||
rhs.SetLocalPriority(loot::Priority(node["priority"].as<int>()));
|
||||
}
|
||||
|
||||
if (node["global_priority"]) {
|
||||
rhs.SetGlobalPriority(loot::Priority(node["global_priority"].as<int>()));
|
||||
}
|
||||
|
||||
if (node["after"])
|
||||
rhs.SetLoadAfterFiles(node["after"].as<std::set<loot::File>>());
|
||||
if (node["req"])
|
||||
rhs.SetRequirements(node["req"].as<std::set<loot::File>>());
|
||||
if (node["inc"])
|
||||
rhs.SetIncompatibilities(node["inc"].as<std::set<loot::File>>());
|
||||
if (node["msg"])
|
||||
rhs.SetMessages(node["msg"].as<std::vector<loot::Message>>());
|
||||
if (node["tag"])
|
||||
rhs.SetTags(node["tag"].as<std::set<loot::Tag>>());
|
||||
if (node["dirty"]) {
|
||||
if (rhs.IsRegexPlugin())
|
||||
throw RepresentationException(node.Mark(), "bad conversion: 'dirty' key must not be present in a regex 'plugin metadata' object");
|
||||
else
|
||||
rhs.SetDirtyInfo(node["dirty"].as<std::set<loot::PluginCleaningData>>());
|
||||
}
|
||||
if (node["clean"]) {
|
||||
if (rhs.IsRegexPlugin())
|
||||
throw RepresentationException(node.Mark(), "bad conversion: 'clean' key must not be present in a regex 'plugin metadata' object");
|
||||
else
|
||||
rhs.SetCleanInfo(node["clean"].as<std::set<loot::PluginCleaningData>>());
|
||||
}
|
||||
if (node["url"])
|
||||
rhs.SetLocations(node["url"].as<std::set<loot::Location>>());
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
inline Emitter& operator << (Emitter& out, const loot::PluginMetadata& rhs) {
|
||||
if (!rhs.HasNameOnly()) {
|
||||
out << BeginMap
|
||||
<< Key << "name" << Value << YAML::SingleQuoted << rhs.GetName();
|
||||
|
||||
if (!rhs.IsEnabled())
|
||||
out << Key << "enabled" << Value << rhs.IsEnabled();
|
||||
|
||||
if (rhs.GetLocalPriority().IsExplicit()) {
|
||||
out << Key << "priority" << Value << rhs.GetLocalPriority().GetValue();
|
||||
}
|
||||
|
||||
if (rhs.GetGlobalPriority().IsExplicit()) {
|
||||
out << Key << "global_priority" << Value << rhs.GetGlobalPriority().GetValue();
|
||||
}
|
||||
|
||||
if (!rhs.GetLoadAfterFiles().empty())
|
||||
out << Key << "after" << Value << rhs.GetLoadAfterFiles();
|
||||
|
||||
if (!rhs.GetRequirements().empty())
|
||||
out << Key << "req" << Value << rhs.GetRequirements();
|
||||
|
||||
if (!rhs.GetIncompatibilities().empty())
|
||||
out << Key << "inc" << Value << rhs.GetIncompatibilities();
|
||||
|
||||
if (!rhs.GetMessages().empty())
|
||||
out << Key << "msg" << Value << rhs.GetMessages();
|
||||
|
||||
if (!rhs.GetTags().empty())
|
||||
out << Key << "tag" << Value << rhs.GetTags();
|
||||
|
||||
if (!rhs.GetDirtyInfo().empty())
|
||||
out << Key << "dirty" << Value << rhs.GetDirtyInfo();
|
||||
|
||||
if (!rhs.GetCleanInfo().empty())
|
||||
out << Key << "clean" << Value << rhs.GetCleanInfo();
|
||||
|
||||
if (!rhs.GetLocations().empty())
|
||||
out << Key << "url" << Value << rhs.GetLocations();
|
||||
|
||||
out << EndMap;
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,103 +0,0 @@
|
||||
/* LOOT
|
||||
|
||||
A load order optimisation tool for Oblivion, Skyrim, Fallout 3 and
|
||||
Fallout: New Vegas.
|
||||
|
||||
Copyright (C) 2012-2016 WrinklyNinja
|
||||
|
||||
This file is part of LOOT.
|
||||
|
||||
LOOT is free software: you can redistribute
|
||||
it and/or modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
LOOT is distributed in the hope that it will
|
||||
be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LOOT. If not, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef LOOT_YAML_SET
|
||||
#define LOOT_YAML_SET
|
||||
|
||||
#include <set>
|
||||
#include <unordered_set>
|
||||
|
||||
#include <yaml-cpp/yaml.h>
|
||||
|
||||
namespace YAML {
|
||||
template<class T, class Compare>
|
||||
struct convert<std::set<T, Compare>> {
|
||||
static Node encode(const std::set<T, Compare>& rhs) {
|
||||
Node node;
|
||||
for (const auto &element : rhs) {
|
||||
node.push_back(element);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
static bool decode(const Node& node, std::set<T, Compare>& rhs) {
|
||||
if (!node.IsSequence())
|
||||
throw RepresentationException(node.Mark(), "bad conversion: set must be a sequence of elements");
|
||||
|
||||
rhs.clear();
|
||||
for (const auto &element : node) {
|
||||
if (!rhs.insert(element.template as<T>()).second)
|
||||
throw RepresentationException(node.Mark(), "bad conversion: set elements must be unique");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
template<class T, class Compare>
|
||||
Emitter& operator << (Emitter& out, const std::set<T, Compare>& rhs) {
|
||||
out << BeginSeq;
|
||||
for (const auto &element : rhs) {
|
||||
out << element;
|
||||
}
|
||||
out << EndSeq;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
template<class T, class Hash>
|
||||
struct convert<std::unordered_set<T, Hash>> {
|
||||
static Node encode(const std::unordered_set<T, Hash>& rhs) {
|
||||
Node node;
|
||||
for (const auto &element : rhs) {
|
||||
node.push_back(element);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
static bool decode(const Node& node, std::unordered_set<T, Hash>& rhs) {
|
||||
if (!node.IsSequence())
|
||||
throw RepresentationException(node.Mark(), "bad conversion: unordered set must be a sequence of elements");
|
||||
|
||||
rhs.clear();
|
||||
for (const auto &element : node) {
|
||||
if (!rhs.insert(element.template as<T>()).second)
|
||||
throw RepresentationException(node.Mark(), "bad conversion: unordered set elements must be unique");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
template<class T, class Hash>
|
||||
Emitter& operator << (Emitter& out, const std::unordered_set<T, Hash>& rhs) {
|
||||
out << BeginSeq;
|
||||
for (const auto &element : rhs) {
|
||||
out << element;
|
||||
}
|
||||
out << EndSeq;
|
||||
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,99 +0,0 @@
|
||||
/* LOOT
|
||||
|
||||
A load order optimisation tool for Oblivion, Skyrim, Fallout 3 and
|
||||
Fallout: New Vegas.
|
||||
|
||||
Copyright (C) 2012-2016 WrinklyNinja
|
||||
|
||||
This file is part of LOOT.
|
||||
|
||||
LOOT is free software: you can redistribute
|
||||
it and/or modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
LOOT is distributed in the hope that it will
|
||||
be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LOOT. If not, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef LOOT_YAML_TAG
|
||||
#define LOOT_YAML_TAG
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <yaml-cpp/yaml.h>
|
||||
|
||||
#include "loot/metadata/tag.h"
|
||||
|
||||
namespace YAML {
|
||||
template<>
|
||||
struct convert<loot::Tag> {
|
||||
static Node encode(const loot::Tag& rhs) {
|
||||
Node node;
|
||||
if (rhs.IsConditional())
|
||||
node["condition"] = rhs.GetCondition();
|
||||
if (rhs.IsAddition())
|
||||
node["name"] = rhs.GetName();
|
||||
else
|
||||
node["name"] = "-" + rhs.GetName();
|
||||
return node;
|
||||
}
|
||||
|
||||
static bool decode(const Node& node, loot::Tag& rhs) {
|
||||
if (!node.IsMap() && !node.IsScalar())
|
||||
throw RepresentationException(node.Mark(), "bad conversion: 'tag' object must be a map or scalar");
|
||||
|
||||
std::string condition, tag;
|
||||
if (node.IsMap()) {
|
||||
if (!node["name"])
|
||||
throw RepresentationException(node.Mark(), "bad conversion: 'name' key missing from 'tag' map object");
|
||||
|
||||
tag = node["name"].as<std::string>();
|
||||
if (node["condition"])
|
||||
condition = node["condition"].as<std::string>();
|
||||
} else
|
||||
tag = node.as<std::string>();
|
||||
|
||||
if (tag[0] == '-')
|
||||
rhs = loot::Tag(tag.substr(1), false, condition);
|
||||
else
|
||||
rhs = loot::Tag(tag, true, condition);
|
||||
|
||||
// Test condition syntax.
|
||||
try {
|
||||
rhs.ParseCondition();
|
||||
} catch (std::exception& e) {
|
||||
throw RepresentationException(node.Mark(), std::string("bad conversion: invalid condition syntax: ") + e.what());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
inline Emitter& operator << (Emitter& out, const loot::Tag& rhs) {
|
||||
if (!rhs.IsConditional()) {
|
||||
if (rhs.IsAddition())
|
||||
out << rhs.GetName();
|
||||
else
|
||||
out << ('-' + rhs.GetName());
|
||||
} else {
|
||||
out << BeginMap;
|
||||
if (rhs.IsAddition())
|
||||
out << Key << "name" << Value << rhs.GetName();
|
||||
else
|
||||
out << Key << "name" << Value << ('-' + rhs.GetName());
|
||||
|
||||
out << Key << "condition" << Value << YAML::SingleQuoted << rhs.GetCondition()
|
||||
<< EndMap;
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user