mirror of https://github.com/PCSX2/pcsx2.git
SettingsInterface: Add Key+Value setting support
This commit is contained in:
parent
1b50fb982a
commit
e2c3a8b1e1
|
@ -47,6 +47,9 @@ public:
|
|||
virtual bool RemoveFromStringList(const char* section, const char* key, const char* item) = 0;
|
||||
virtual bool AddToStringList(const char* section, const char* key, const char* item) = 0;
|
||||
|
||||
virtual std::vector<std::pair<std::string, std::string>> GetKeyValueList(const char* section) const = 0;
|
||||
virtual void SetKeyValueList(const char* section, const std::vector<std::pair<std::string, std::string>>& items) = 0;
|
||||
|
||||
virtual bool ContainsValue(const char* section, const char* key) const = 0;
|
||||
virtual void DeleteValue(const char* section, const char* key) = 0;
|
||||
virtual void ClearSection(const char* section) = 0;
|
||||
|
@ -217,4 +220,9 @@ public:
|
|||
else
|
||||
DeleteValue(section, key);
|
||||
}
|
||||
|
||||
__fi void CopyKeysAndValues(const SettingsInterface& si, const char* section)
|
||||
{
|
||||
SetKeyValueList(section, si.GetKeyValueList(section));
|
||||
}
|
||||
};
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
#include "LayeredSettingsInterface.h"
|
||||
#include "common/Assertions.h"
|
||||
|
||||
#include <unordered_set>
|
||||
|
||||
LayeredSettingsInterface::LayeredSettingsInterface() = default;
|
||||
|
||||
LayeredSettingsInterface::~LayeredSettingsInterface() = default;
|
||||
|
@ -203,3 +205,32 @@ bool LayeredSettingsInterface::AddToStringList(const char* section, const char*
|
|||
pxFailRel("Attempt to call AddToStringList() on layered settings interface");
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<std::pair<std::string, std::string>> LayeredSettingsInterface::GetKeyValueList(const char* section) const
|
||||
{
|
||||
std::unordered_set<std::string_view> seen;
|
||||
std::vector<std::pair<std::string, std::string>> ret;
|
||||
for (u32 layer = FIRST_LAYER; layer <= LAST_LAYER; layer++)
|
||||
{
|
||||
if (SettingsInterface* sif = m_layers[layer])
|
||||
{
|
||||
const size_t newly_added_begin = ret.size();
|
||||
std::vector<std::pair<std::string, std::string>> entries = sif->GetKeyValueList(section);
|
||||
for (std::pair<std::string, std::string>& entry : entries)
|
||||
{
|
||||
if (seen.find(entry.first) != seen.end())
|
||||
continue;
|
||||
ret.push_back(std::move(entry));
|
||||
}
|
||||
// Mark keys as seen after processing all entries in case the layer has multiple entries for a specific key
|
||||
for (auto cur = ret.begin() + newly_added_begin, end = ret.end(); cur < end; cur++)
|
||||
seen.insert(cur->first);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void LayeredSettingsInterface::SetKeyValueList(const char* section, const std::vector<std::pair<std::string, std::string>>& items)
|
||||
{
|
||||
pxFailRel("Attempt to call SetKeyValueList() on layered settings interface");
|
||||
}
|
||||
|
|
|
@ -61,6 +61,9 @@ public:
|
|||
bool RemoveFromStringList(const char* section, const char* key, const char* item) override;
|
||||
bool AddToStringList(const char* section, const char* key, const char* item) override;
|
||||
|
||||
std::vector<std::pair<std::string, std::string>> GetKeyValueList(const char* section) const override;
|
||||
void SetKeyValueList(const char* section, const std::vector<std::pair<std::string, std::string>>& items) override;
|
||||
|
||||
// default parameter overloads
|
||||
using SettingsInterface::GetBoolValue;
|
||||
using SettingsInterface::GetDoubleValue;
|
||||
|
|
|
@ -298,3 +298,39 @@ bool INISettingsInterface::AddToStringList(const char* section, const char* key,
|
|||
m_ini.SetValue(section, key, item, nullptr, false);
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<std::pair<std::string, std::string>> INISettingsInterface::GetKeyValueList(const char* section) const
|
||||
{
|
||||
using Entry = CSimpleIniA::Entry;
|
||||
using KVEntry = std::pair<const char*, Entry>;
|
||||
std::vector<KVEntry> entries;
|
||||
std::vector<std::pair<std::string, std::string>> output;
|
||||
std::list<Entry> keys, values;
|
||||
if (m_ini.GetAllKeys(section, keys))
|
||||
{
|
||||
for (Entry& key : keys)
|
||||
{
|
||||
if (!m_ini.GetAllValues(section, key.pItem, values)) [[unlikely]]
|
||||
{
|
||||
Console.Error("Got no values for a key returned from GetAllKeys!");
|
||||
continue;
|
||||
}
|
||||
for (const Entry& value : values)
|
||||
entries.emplace_back(key.pItem, value);
|
||||
}
|
||||
}
|
||||
std::sort(entries.begin(), entries.end(), [](const KVEntry& a, const KVEntry& b)
|
||||
{
|
||||
return a.second.nOrder < b.second.nOrder;
|
||||
});
|
||||
for (const KVEntry& entry : entries)
|
||||
output.emplace_back(entry.first, entry.second.pItem);
|
||||
return output;
|
||||
}
|
||||
|
||||
void INISettingsInterface::SetKeyValueList(const char* section, const std::vector<std::pair<std::string, std::string>>& items)
|
||||
{
|
||||
m_ini.Delete(section, nullptr);
|
||||
for (const std::pair<std::string, std::string>& item : items)
|
||||
m_ini.SetValue(section, item.first.c_str(), item.second.c_str(), nullptr, false);
|
||||
}
|
||||
|
|
|
@ -58,6 +58,9 @@ public:
|
|||
bool RemoveFromStringList(const char* section, const char* key, const char* item) override;
|
||||
bool AddToStringList(const char* section, const char* key, const char* item) override;
|
||||
|
||||
std::vector<std::pair<std::string, std::string>> GetKeyValueList(const char* section) const override;
|
||||
void SetKeyValueList(const char* section, const std::vector<std::pair<std::string, std::string>>& items) override;
|
||||
|
||||
// default parameter overloads
|
||||
using SettingsInterface::GetBoolValue;
|
||||
using SettingsInterface::GetDoubleValue;
|
||||
|
|
|
@ -163,6 +163,17 @@ bool wxSettingsInterface::AddToStringList(const char* section, const char* key,
|
|||
return false;
|
||||
}
|
||||
|
||||
std::vector<std::pair<std::string, std::string>> wxSettingsInterface::GetKeyValueList(const char* section) const
|
||||
{
|
||||
pxFailRel("Not implemented");
|
||||
return {};
|
||||
}
|
||||
|
||||
void wxSettingsInterface::SetKeyValueList(const char* section, const std::vector<std::pair<std::string, std::string>>& items)
|
||||
{
|
||||
pxFailRel("Not implemented");
|
||||
}
|
||||
|
||||
bool wxSettingsInterface::ContainsValue(const char* section, const char* key) const
|
||||
{
|
||||
CheckPath(section);
|
||||
|
|
|
@ -49,6 +49,9 @@ public:
|
|||
bool RemoveFromStringList(const char* section, const char* key, const char* item) override;
|
||||
bool AddToStringList(const char* section, const char* key, const char* item) override;
|
||||
|
||||
std::vector<std::pair<std::string, std::string>> GetKeyValueList(const char* section) const override;
|
||||
void SetKeyValueList(const char* section, const std::vector<std::pair<std::string, std::string>>& items) override;
|
||||
|
||||
bool ContainsValue(const char* section, const char* key) const override;
|
||||
void DeleteValue(const char* section, const char* key) override;
|
||||
void ClearSection(const char* section) override;
|
||||
|
|
Loading…
Reference in New Issue