rpcsx/rpcs3/rpcs3qt/config_adapter.cpp

77 lines
1.9 KiB
C++
Raw Normal View History

#include "config_adapter.h"
#include "Emu/system_config.h"
LOG_CHANNEL(cfg_log, "CFG");
// Helper methods to interact with YAML and the config settings.
namespace cfg_adapter
{
static cfg::_base& get_cfg(cfg::_base& root, const std::string& name)
{
if (root.get_type() == cfg::type::node)
{
2021-03-20 18:06:45 +01:00
for (const auto& node : static_cast<cfg::node&>(root).get_nodes())
{
2021-03-20 18:06:45 +01:00
if (node->get_name() == name)
{
2021-03-20 18:06:45 +01:00
return *node;
}
}
}
fmt::throw_exception("Node not found: %s", name);
}
2021-04-07 23:05:18 +02:00
static cfg::_base& get_cfg(cfg::_base& root, const cfg_location::const_iterator begin, const cfg_location::const_iterator end)
{
return begin == end ? root : get_cfg(get_cfg(root, *begin), begin + 1, end);
}
2021-04-07 23:05:18 +02:00
YAML::Node get_node(const YAML::Node& node, const cfg_location::const_iterator begin, const cfg_location::const_iterator end)
{
if (begin == end)
{
return node;
}
if (!node || !node.IsMap())
{
cfg_log.fatal("Node error. A cfg_location does not match its cfg::node (location: %s)", get_yaml_node_location(node));
return YAML::Node();
}
return get_node(node[*begin], begin + 1, end); // TODO
}
2021-04-07 23:05:18 +02:00
YAML::Node get_node(const YAML::Node& node, const cfg_location& location)
{
2021-04-07 23:05:18 +02:00
return get_node(node, location.cbegin(), location.cend());
}
2021-04-07 23:05:18 +02:00
QStringList get_options(const cfg_location& location)
{
QStringList values;
for (const std::string& value : cfg_adapter::get_cfg(g_cfg, location.cbegin(), location.cend()).to_list())
{
values.append(QString::fromStdString(value));
}
return values;
}
2023-01-21 00:53:49 +01:00
2021-04-07 23:05:18 +02:00
static bool get_is_dynamic(const cfg_location& location)
{
2021-04-07 23:05:18 +02:00
return cfg_adapter::get_cfg(g_cfg, location.cbegin(), location.cend()).get_is_dynamic();
}
2023-01-21 00:53:49 +01:00
bool get_is_dynamic(emu_settings_type type)
{
return get_is_dynamic(::at32(settings_location, type));
}
2020-04-20 22:22:34 +02:00
std::string get_setting_name(emu_settings_type type)
{
const cfg_location& loc = ::at32(settings_location, type);
return ::at32(loc, loc.size() - 1);
2020-04-20 22:22:34 +02:00
}
}