Qt: Fix relative directories not being canonicalized

This commit is contained in:
Stenzek 2022-12-24 14:11:09 +10:00 committed by refractionpcsx2
parent a3d02b8702
commit 9f461253a8
2 changed files with 15 additions and 8 deletions

View File

@ -974,15 +974,15 @@ namespace SettingWidgetBinder
template <typename WidgetType> template <typename WidgetType>
static void BindWidgetToFolderSetting(SettingsInterface* sif, WidgetType* widget, QAbstractButton* browse_button, QAbstractButton* open_button, static void BindWidgetToFolderSetting(SettingsInterface* sif, WidgetType* widget, QAbstractButton* browse_button, QAbstractButton* open_button,
QAbstractButton* reset_button, std::string section, std::string key, std::string default_value) QAbstractButton* reset_button, std::string section, std::string key, std::string default_value, bool use_relative = true)
{ {
using Accessor = SettingAccessor<WidgetType>; using Accessor = SettingAccessor<WidgetType>;
std::string current_path(Host::GetBaseStringSettingValue(section.c_str(), key.c_str(), default_value.c_str())); std::string current_path(Host::GetBaseStringSettingValue(section.c_str(), key.c_str(), default_value.c_str()));
if (current_path.empty()) if (current_path.empty())
current_path = default_value; current_path = default_value;
else if (!Path::IsAbsolute(current_path)) else if (use_relative && !Path::IsAbsolute(current_path))
current_path = Path::Combine(EmuFolders::DataRoot, current_path); current_path = Path::Canonicalize(Path::Combine(EmuFolders::DataRoot, current_path));
const QString value(QString::fromStdString(current_path)); const QString value(QString::fromStdString(current_path));
Accessor::setStringValue(widget, value); Accessor::setStringValue(widget, value);
@ -998,14 +998,21 @@ namespace SettingWidgetBinder
return; return;
} }
Accessor::connectValueChanged(widget, [widget, section = std::move(section), key = std::move(key)]() { Accessor::connectValueChanged(widget, [widget, section = std::move(section), key = std::move(key), use_relative]() {
const std::string new_value(Accessor::getStringValue(widget).toStdString()); const std::string new_value(Accessor::getStringValue(widget).toStdString());
if (!new_value.empty()) if (!new_value.empty())
{ {
std::string relative_path(Path::MakeRelative(new_value, EmuFolders::DataRoot)); if (use_relative)
{
const std::string relative_path(Path::MakeRelative(new_value, EmuFolders::DataRoot));
Host::SetBaseStringSettingValue(section.c_str(), key.c_str(), relative_path.c_str()); Host::SetBaseStringSettingValue(section.c_str(), key.c_str(), relative_path.c_str());
} }
else else
{
Host::SetBaseStringSettingValue(section.c_str(), key.c_str(), new_value.c_str());
}
}
else
{ {
Host::RemoveBaseSettingValue(section.c_str(), key.c_str()); Host::RemoveBaseSettingValue(section.c_str(), key.c_str());
} }

View File

@ -42,9 +42,9 @@ DebugSettingsWidget::DebugSettingsWidget(SettingsDialog* dialog, QWidget* parent
SettingWidgetBinder::BindWidgetToIntSetting(sif, m_ui.startDraw, "EmuCore/GS", "saven", 0); SettingWidgetBinder::BindWidgetToIntSetting(sif, m_ui.startDraw, "EmuCore/GS", "saven", 0);
SettingWidgetBinder::BindWidgetToIntSetting(sif, m_ui.dumpCount, "EmuCore/GS", "savel", 5000); SettingWidgetBinder::BindWidgetToIntSetting(sif, m_ui.dumpCount, "EmuCore/GS", "savel", 5000);
SettingWidgetBinder::BindWidgetToFolderSetting( SettingWidgetBinder::BindWidgetToFolderSetting(
sif, m_ui.hwDumpDirectory, m_ui.hwDumpBrowse, m_ui.hwDumpOpen, nullptr, "EmuCore/GS", "HWDumpDirectory", std::string()); sif, m_ui.hwDumpDirectory, m_ui.hwDumpBrowse, m_ui.hwDumpOpen, nullptr, "EmuCore/GS", "HWDumpDirectory", std::string(), false);
SettingWidgetBinder::BindWidgetToFolderSetting( SettingWidgetBinder::BindWidgetToFolderSetting(
sif, m_ui.swDumpDirectory, m_ui.swDumpBrowse, m_ui.swDumpOpen, nullptr, "EmuCore/GS", "SWDumpDirectory", std::string()); sif, m_ui.swDumpDirectory, m_ui.swDumpBrowse, m_ui.swDumpOpen, nullptr, "EmuCore/GS", "SWDumpDirectory", std::string(), false);
connect(m_ui.dumpGSDraws, &QCheckBox::stateChanged, this, &DebugSettingsWidget::onDrawDumpingChanged); connect(m_ui.dumpGSDraws, &QCheckBox::stateChanged, this, &DebugSettingsWidget::onDrawDumpingChanged);
onDrawDumpingChanged(); onDrawDumpingChanged();