Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More Maintenance #8059

Merged
merged 1 commit into from Apr 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions rpcs3/rpcs3.vcxproj
Expand Up @@ -1483,6 +1483,7 @@
<ClCompile Include="rpcs3qt\breakpoint_list.cpp" />
<ClCompile Include="rpcs3qt\call_stack_list.cpp" />
<ClCompile Include="rpcs3qt\cheat_manager.cpp" />
<ClCompile Include="rpcs3qt\config_adapter.cpp" />
<ClCompile Include="rpcs3qt\curl_handle.cpp" />
<ClCompile Include="rpcs3qt\custom_dialog.cpp" />
<ClCompile Include="rpcs3qt\debugger_list.cpp" />
Expand Down Expand Up @@ -2026,6 +2027,7 @@
<Command Condition="'$(Configuration)|$(Platform)'=='Debug - LLVM|x64'">"$(QTDIR)\bin\moc.exe" "%(FullPath)" -o ".\QTGeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" -D_WINDOWS -DUNICODE -DWIN32 -DWIN64 -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_WINEXTRAS_LIB -DQT_CONCURRENT_LIB -D%(PreprocessorDefinitions) "-I.\..\3rdparty\wolfssl" "-I.\..\3rdparty\curl\include" "-I.\..\3rdparty\libusb\libusb" "-I$(VULKAN_SDK)\Include" "-I.\..\3rdparty\XAudio2Redist\include" "-I$(QTDIR)\include" "-I$(QTDIR)\include\QtWidgets" "-I$(QTDIR)\include\QtGui" "-I$(QTDIR)\include\QtANGLE" "-I$(QTDIR)\include\QtCore" "-I.\debug" "-I$(QTDIR)\mkspecs\win32-msvc2015" "-I.\QTGeneratedFiles\$(ConfigurationName)" "-I.\QTGeneratedFiles" "-I$(QTDIR)\include\QtWinExtras" "-I$(QTDIR)\include\QtConcurrent"</Command>
</CustomBuild>
<ClInclude Include="rpcs3qt\category.h" />
<ClInclude Include="rpcs3qt\config_adapter.h" />
<ClInclude Include="rpcs3qt\curl_handle.h" />
<ClInclude Include="rpcs3qt\custom_dock_widget.h" />
<CustomBuild Include="rpcs3qt\debugger_list.h">
Expand Down
6 changes: 6 additions & 0 deletions rpcs3/rpcs3.vcxproj.filters
Expand Up @@ -1039,6 +1039,9 @@
<ClCompile Include="QTGeneratedFiles\Debug - LLVM\moc_render_creator.cpp">
<Filter>Generated Files\Debug - LLVM</Filter>
</ClCompile>
<ClCompile Include="rpcs3qt\config_adapter.cpp">
<Filter>Gui\settings</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="\rpcs3qt\*.h">
Expand Down Expand Up @@ -1131,6 +1134,9 @@
<ClInclude Include="rpcs3qt\emu_settings_type.h">
<Filter>Gui\settings</Filter>
</ClInclude>
<ClInclude Include="rpcs3qt\config_adapter.h">
<Filter>Gui\settings</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<CustomBuild Include="debug\moc_predefs.h.cbt">
Expand Down
1 change: 1 addition & 0 deletions rpcs3/rpcs3qt/CMakeLists.txt
Expand Up @@ -6,6 +6,7 @@
call_stack_list.cpp
cg_disasm_window.cpp
cheat_manager.cpp
config_adapter.cpp
curl_handle.cpp
custom_dialog.cpp
debugger_frame.cpp
Expand Down
66 changes: 66 additions & 0 deletions rpcs3/rpcs3qt/config_adapter.cpp
@@ -0,0 +1,66 @@
#pragma once

#include <QStringList>

#include "config_adapter.h"
#include "Emu/system_config.h"

// 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)
{
for (const auto& pair : static_cast<cfg::node&>(root).get_nodes())
{
if (pair.first == name)
{
return *pair.second;
}
}
}

fmt::throw_exception("Node not found: %s", name);
}

static cfg::_base& get_cfg(cfg::_base& root, cfg_location::const_iterator begin, cfg_location::const_iterator end)
{
return begin == end ? root : get_cfg(get_cfg(root, *begin), begin + 1, end);
}

YAML::Node get_node(const YAML::Node& node, cfg_location::const_iterator begin, cfg_location::const_iterator end)
{
return begin == end ? node : get_node(node[*begin], begin + 1, end); // TODO
}

YAML::Node get_node(const YAML::Node& node, cfg_location loc)
{
return get_node(node, loc.cbegin(), loc.cend());
}

QStringList get_options(cfg_location location)
{
QStringList values;
auto begin = location.cbegin();
auto end = location.cend();
for (const auto& v : cfg_adapter::get_cfg(g_cfg, begin, end).to_list())
{
values.append(QString::fromStdString(v));
}
return values;
}

static bool get_is_dynamic(cfg_location location)
{
auto begin = location.cbegin();
auto end = location.cend();
return cfg_adapter::get_cfg(g_cfg, begin, end).get_is_dynamic();
}

bool get_is_dynamic(emu_settings_type type)
{
const cfg_location loc = settings_location[type];
return get_is_dynamic(loc);
}
}
21 changes: 21 additions & 0 deletions rpcs3/rpcs3qt/config_adapter.h
@@ -0,0 +1,21 @@
#pragma once

#include <QStringList>

#include "emu_settings_type.h"
#include "yaml-cpp/yaml.h"

// Helper methods to interact with YAML and the config settings.
namespace cfg_adapter
{
YAML::Node get_node(const YAML::Node& node, cfg_location::const_iterator begin, cfg_location::const_iterator end);

/** Syntactic sugar to get a setting at a given config location. */
YAML::Node get_node(const YAML::Node& node, cfg_location loc);

/** Returns possible options for values for some particular setting.*/
QStringList get_options(cfg_location location);

/** Returns dynamic property for some particular setting.*/
bool get_is_dynamic(emu_settings_type type);
}
76 changes: 6 additions & 70 deletions rpcs3/rpcs3qt/emu_settings.cpp
@@ -1,6 +1,5 @@
#include "emu_settings.h"

#include "Utilities/Config.h"
#include "config_adapter.h"

#include <QMessageBox>
#include <QLineEdit>
Expand Down Expand Up @@ -56,63 +55,6 @@ namespace
}
}

// 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)
{
for (const auto& pair : static_cast<cfg::node&>(root).get_nodes())
{
if (pair.first == name)
{
return *pair.second;
}
}
}

fmt::throw_exception("Node not found: %s", name);
}

static cfg::_base& get_cfg(cfg::_base& root, cfg_location::const_iterator begin, cfg_location::const_iterator end)
{
return begin == end ? root : get_cfg(get_cfg(root, *begin), begin + 1, end);
}

static YAML::Node get_node(const YAML::Node& node, cfg_location::const_iterator begin, cfg_location::const_iterator end)
{
return begin == end ? node : get_node(node[*begin], begin + 1, end); // TODO
}

/** Syntactic sugar to get a setting at a given config location. */
static YAML::Node get_node(const YAML::Node& node, cfg_location loc)
{
return get_node(node, loc.cbegin(), loc.cend());
}
}

/** Returns possible options for values for some particular setting.*/
static QStringList get_options(cfg_location location)
{
QStringList values;
auto begin = location.cbegin();
auto end = location.cend();
for (const auto& v : cfg_adapter::get_cfg(g_cfg, begin, end).to_list())
{
values.append(qstr(v));
}
return values;
}

/** Returns dynamic property for some particular setting.*/
static bool get_is_dynamic(cfg_location location)
{
auto begin = location.cbegin();
auto end = location.cend();
return cfg_adapter::get_cfg(g_cfg, begin, end).get_is_dynamic();
}

emu_settings::emu_settings()
: QObject()
, m_render_creator(new render_creator(this))
Expand Down Expand Up @@ -515,28 +457,28 @@ void emu_settings::SaveSelectedLibraries(const std::vector<std::string>& libs)

QStringList emu_settings::GetSettingOptions(emu_settings_type type) const
{
return get_options(const_cast<cfg_location&&>(m_settings_location[type]));
return cfg_adapter::get_options(const_cast<cfg_location&&>(settings_location[type]));
}

std::string emu_settings::GetSettingName(emu_settings_type type) const
{
const cfg_location loc = m_settings_location[type];
const cfg_location loc = settings_location[type];
return loc[loc.size() - 1];
}

std::string emu_settings::GetSettingDefault(emu_settings_type type) const
{
return cfg_adapter::get_node(m_defaultSettings, m_settings_location[type]).Scalar();
return cfg_adapter::get_node(m_defaultSettings, settings_location[type]).Scalar();
}

std::string emu_settings::GetSetting(emu_settings_type type) const
{
return cfg_adapter::get_node(m_currentSettings, m_settings_location[type]).Scalar();
return cfg_adapter::get_node(m_currentSettings, settings_location[type]).Scalar();
}

void emu_settings::SetSetting(emu_settings_type type, const std::string& val)
{
cfg_adapter::get_node(m_currentSettings, m_settings_location[type]) = val;
cfg_adapter::get_node(m_currentSettings, settings_location[type]) = val;
}

void emu_settings::OpenCorrectionDialog(QWidget* parent)
Expand Down Expand Up @@ -758,9 +700,3 @@ QString emu_settings::GetLocalizedSetting(const QString& original, emu_settings_

return original;
}

bool emu_settings::GetIsDynamicConfig(emu_settings_type type)
{
const cfg_location loc = m_settings_location[type];
return get_is_dynamic(loc);
}