From 9f461253a864abb98eff8af7633e6d96a344ffbe Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sat, 24 Dec 2022 14:11:09 +1000 Subject: [PATCH] Qt: Fix relative directories not being canonicalized --- pcsx2-qt/SettingWidgetBinder.h | 19 +++++++++++++------ pcsx2-qt/Settings/DebugSettingsWidget.cpp | 4 ++-- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/pcsx2-qt/SettingWidgetBinder.h b/pcsx2-qt/SettingWidgetBinder.h index 39a14b2f2c..3ed50b5037 100644 --- a/pcsx2-qt/SettingWidgetBinder.h +++ b/pcsx2-qt/SettingWidgetBinder.h @@ -974,15 +974,15 @@ namespace SettingWidgetBinder template 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; std::string current_path(Host::GetBaseStringSettingValue(section.c_str(), key.c_str(), default_value.c_str())); if (current_path.empty()) current_path = default_value; - else if (!Path::IsAbsolute(current_path)) - current_path = Path::Combine(EmuFolders::DataRoot, current_path); + else if (use_relative && !Path::IsAbsolute(current_path)) + current_path = Path::Canonicalize(Path::Combine(EmuFolders::DataRoot, current_path)); const QString value(QString::fromStdString(current_path)); Accessor::setStringValue(widget, value); @@ -998,12 +998,19 @@ namespace SettingWidgetBinder 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()); if (!new_value.empty()) { - std::string relative_path(Path::MakeRelative(new_value, EmuFolders::DataRoot)); - Host::SetBaseStringSettingValue(section.c_str(), key.c_str(), relative_path.c_str()); + 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()); + } + else + { + Host::SetBaseStringSettingValue(section.c_str(), key.c_str(), new_value.c_str()); + } } else { diff --git a/pcsx2-qt/Settings/DebugSettingsWidget.cpp b/pcsx2-qt/Settings/DebugSettingsWidget.cpp index 6356813cd0..74a9f92c0b 100644 --- a/pcsx2-qt/Settings/DebugSettingsWidget.cpp +++ b/pcsx2-qt/Settings/DebugSettingsWidget.cpp @@ -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.dumpCount, "EmuCore/GS", "savel", 5000); 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( - 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); onDrawDumpingChanged();