diff --git a/src/frontend/qt_sdl/Config.cpp b/src/frontend/qt_sdl/Config.cpp index 4fefea7f..ece1c873 100644 --- a/src/frontend/qt_sdl/Config.cpp +++ b/src/frontend/qt_sdl/Config.cpp @@ -78,10 +78,6 @@ int MPRecvTimeout; std::string LANDevice; bool DirectLAN; -std::string SaveFilePath; -std::string SavestatePath; -std::string CheatFilePath; - int64_t RTCOffset; bool DSBatteryLevelOkay; diff --git a/src/frontend/qt_sdl/Config.h b/src/frontend/qt_sdl/Config.h index 5c0c01fb..2fe92da9 100644 --- a/src/frontend/qt_sdl/Config.h +++ b/src/frontend/qt_sdl/Config.h @@ -192,10 +192,6 @@ extern int MPRecvTimeout; extern std::string LANDevice; extern bool DirectLAN; -extern std::string SaveFilePath; -extern std::string SavestatePath; -extern std::string CheatFilePath; - extern int64_t RTCOffset; extern bool DSBatteryLevelOkay; diff --git a/src/frontend/qt_sdl/EmuInstance.cpp b/src/frontend/qt_sdl/EmuInstance.cpp index 078f9305..682d6a0a 100644 --- a/src/frontend/qt_sdl/EmuInstance.cpp +++ b/src/frontend/qt_sdl/EmuInstance.cpp @@ -423,7 +423,7 @@ std::string EmuInstance::getSavestateName(int slot) { std::string ext = ".ml"; ext += (char)('0'+slot); - return getAssetPath(false, Config::SavestatePath, ext); + return getAssetPath(false, globalCfg.GetString("SavestatePath"), ext); } bool EmuInstance::savestateExists(int slot) @@ -496,7 +496,7 @@ bool EmuInstance::loadState(const std::string& filename) previousSaveFile = ndsSave->GetPath(); std::string savefile = filename.substr(lastSep(filename)+1); - savefile = getAssetPath(false, Config::SaveFilePath, ".sav", savefile); + savefile = getAssetPath(false, globalCfg.GetString("SaveFilePath"), ".sav", savefile); savefile += Platform::InstanceFileSuffix(); ndsSave->SetPath(savefile, true); } @@ -547,7 +547,7 @@ bool EmuInstance::saveState(const std::string& filename) if (globalCfg.GetBool("Savestate.RelocSRAM") && ndsSave) { std::string savefile = filename.substr(lastSep(filename)+1); - savefile = getAssetPath(false, Config::SaveFilePath, ".sav", savefile); + savefile = getAssetPath(false, globalCfg.GetString("SaveFilePath"), ".sav", savefile); savefile += Platform::InstanceFileSuffix(); ndsSave->SetPath(savefile, false); } @@ -587,7 +587,7 @@ void EmuInstance::loadCheats() { unloadCheats(); - std::string filename = getAssetPath(false, Config::CheatFilePath, ".mch"); + std::string filename = getAssetPath(false, globalCfg.GetString("CheatFilePath"), ".mch"); // TODO: check for error (malformed cheat file, ...) cheatFile = new ARCodeFile(filename); @@ -1107,7 +1107,7 @@ void EmuInstance::reset() if ((cartType != -1) && ndsSave) { std::string oldsave = ndsSave->GetPath(); - std::string newsave = getAssetPath(false, Config::SaveFilePath, ".sav"); + std::string newsave = getAssetPath(false, globalCfg.GetString("SaveFilePath"), ".sav"); newsave += Platform::InstanceFileSuffix(); if (oldsave != newsave) ndsSave->SetPath(newsave, false); @@ -1116,7 +1116,7 @@ void EmuInstance::reset() if ((gbaCartType != -1) && gbaSave) { std::string oldsave = gbaSave->GetPath(); - std::string newsave = getAssetPath(true, Config::SaveFilePath, ".sav"); + std::string newsave = getAssetPath(true, globalCfg.GetString("SaveFilePath"), ".sav"); newsave += Platform::InstanceFileSuffix(); if (oldsave != newsave) gbaSave->SetPath(newsave, false); @@ -1564,7 +1564,7 @@ bool EmuInstance::loadROM(QStringList filepath, bool reset) u32 savelen = 0; std::unique_ptr savedata = nullptr; - std::string savname = getAssetPath(false, Config::SaveFilePath, ".sav"); + std::string savname = getAssetPath(false, globalCfg.GetString("SaveFilePath"), ".sav"); std::string origsav = savname; savname += Platform::InstanceFileSuffix(); @@ -1706,7 +1706,7 @@ bool EmuInstance::loadGBAROM(QStringList filepath) u32 savelen = 0; std::unique_ptr savedata = nullptr; - std::string savname = getAssetPath(true, Config::SaveFilePath, ".sav"); + std::string savname = getAssetPath(true, globalCfg.GetString("SaveFilePath"), ".sav"); std::string origsav = savname; savname += Platform::InstanceFileSuffix(); diff --git a/src/frontend/qt_sdl/PathSettingsDialog.cpp b/src/frontend/qt_sdl/PathSettingsDialog.cpp index 71342087..38222fe9 100644 --- a/src/frontend/qt_sdl/PathSettingsDialog.cpp +++ b/src/frontend/qt_sdl/PathSettingsDialog.cpp @@ -24,6 +24,7 @@ #include "types.h" #include "Config.h" #include "Platform.h" +#include "main.h" #include "PathSettingsDialog.h" #include "ui_PathSettingsDialog.h" @@ -45,15 +46,26 @@ PathSettingsDialog::PathSettingsDialog(QWidget* parent) : QDialog(parent), ui(ne ui->setupUi(this); setAttribute(Qt::WA_DeleteOnClose); - ui->txtSaveFilePath->setText(QString::fromStdString(Config::SaveFilePath)); - ui->txtSavestatePath->setText(QString::fromStdString(Config::SavestatePath)); - ui->txtCheatFilePath->setText(QString::fromStdString(Config::CheatFilePath)); + emuInstance = ((MainWindow*)parent)->getEmuInstance(); + + auto& cfg = emuInstance->getGlobalConfig(); + ui->txtSaveFilePath->setText(cfg.GetQString("SaveFilePath")); + ui->txtSavestatePath->setText(cfg.GetQString("SavestatePath")); + ui->txtCheatFilePath->setText(cfg.GetQString("CheatFilePath")); int inst = Platform::InstanceID(); if (inst > 0) ui->lblInstanceNum->setText(QString("Configuring paths for instance %1").arg(inst+1)); else ui->lblInstanceNum->hide(); + +#define SET_ORIGVAL(type, val) \ + for (type* w : findChildren(nullptr)) \ + w->setProperty("user_originalValue", w->val()); + + SET_ORIGVAL(QLineEdit, text); + +#undef SET_ORIGVAL } PathSettingsDialog::~PathSettingsDialog() @@ -67,13 +79,24 @@ void PathSettingsDialog::done(int r) if (r == QDialog::Accepted) { - std::string saveFilePath = ui->txtSaveFilePath->text().toStdString(); - std::string savestatePath = ui->txtSavestatePath->text().toStdString(); - std::string cheatFilePath = ui->txtCheatFilePath->text().toStdString(); + bool modified = false; - if ( saveFilePath != Config::SaveFilePath - || savestatePath != Config::SavestatePath - || cheatFilePath != Config::CheatFilePath) +#define CHECK_ORIGVAL(type, val) \ + if (!modified) for (type* w : findChildren(nullptr)) \ + { \ + QVariant v = w->val(); \ + if (v != w->property("user_originalValue")) \ + { \ + modified = true; \ + break; \ + }\ + } + + CHECK_ORIGVAL(QLineEdit, text); + +#undef CHECK_ORIGVAL + + if (modified) { if (RunningSomething && QMessageBox::warning(this, "Reset necessary to apply changes", @@ -81,9 +104,10 @@ void PathSettingsDialog::done(int r) QMessageBox::Ok, QMessageBox::Cancel) != QMessageBox::Ok) return; - Config::SaveFilePath = saveFilePath; - Config::SavestatePath = savestatePath; - Config::CheatFilePath = cheatFilePath; + auto& cfg = emuInstance->getGlobalConfig(); + cfg.SetQString("SaveFilePath", ui->txtSaveFilePath->text()); + cfg.SetQString("SavestatePath", ui->txtSavestatePath->text()); + cfg.SetQString("CheatFilePath", ui->txtCheatFilePath->text()); Config::Save(); diff --git a/src/frontend/qt_sdl/PathSettingsDialog.h b/src/frontend/qt_sdl/PathSettingsDialog.h index dd64d46c..4a1187b6 100644 --- a/src/frontend/qt_sdl/PathSettingsDialog.h +++ b/src/frontend/qt_sdl/PathSettingsDialog.h @@ -25,6 +25,8 @@ namespace Ui { class PathSettingsDialog; } class PathSettingsDialog; +class EmuInstance; + class PathSettingsDialog : public QDialog { Q_OBJECT @@ -62,6 +64,7 @@ private slots: private: Ui::PathSettingsDialog* ui; + EmuInstance* emuInstance; }; #endif // PATHSETTINGSDIALOG_H