diff --git a/src/gba/supervisor/config.c b/src/gba/supervisor/config.c index c32d72e42..e8a92dd11 100644 --- a/src/gba/supervisor/config.c +++ b/src/gba/supervisor/config.c @@ -126,6 +126,30 @@ bool GBAConfigSave(const struct GBAConfig* config) { return ConfigurationWrite(&config->configTable, path); } +void GBAConfigMakePortable(const struct GBAConfig* config) { + struct VFile* portable; +#ifndef _WIN32 + char out[PATH_MAX]; + getcwd(out, PATH_MAX); + strncat(out, PATH_SEP "portable.ini", PATH_MAX - strlen(out)); + portable = VFileOpen(out, O_WRONLY | O_CREAT); +#else + wchar_t wpath[MAX_PATH]; + wchar_t wprojectName[MAX_PATH]; + MultiByteToWideChar(CP_UTF8, 0, projectName, -1, wprojectName, MAX_PATH); + HMODULE hModule = GetModuleHandleW(NULL); + GetModuleFileNameW(hModule, wpath, MAX_PATH); + PathRemoveFileSpecW(wpath); + WideCharToMultiByte(CP_UTF8, 0, wpath, -1, out, outLength, 0, 0); + StringCchCatA(out, outLength, "\\portable.ini"); + portable = VFileOpen(out, O_WRONLY | O_CREAT); +#endif + if (portable) { + portable->close(portable); + GBAConfigSave(config); + } +} + void GBAConfigDirectory(char* out, size_t outLength) { struct VFile* portable; #ifndef _WIN32 diff --git a/src/gba/supervisor/config.h b/src/gba/supervisor/config.h index 86c5a93cc..c4183e122 100644 --- a/src/gba/supervisor/config.h +++ b/src/gba/supervisor/config.h @@ -52,6 +52,7 @@ void GBAConfigDeinit(struct GBAConfig*); bool GBAConfigLoad(struct GBAConfig*); bool GBAConfigSave(const struct GBAConfig*); +void GBAConfigMakePortable(const struct GBAConfig*); void GBAConfigDirectory(char* out, size_t outLength); const char* GBAConfigGetValue(const struct GBAConfig*, const char* key); diff --git a/src/platform/qt/ConfigController.cpp b/src/platform/qt/ConfigController.cpp index 1996160a9..a5859fc83 100644 --- a/src/platform/qt/ConfigController.cpp +++ b/src/platform/qt/ConfigController.cpp @@ -258,3 +258,19 @@ void ConfigController::write() { GBAConfigSave(&m_config); m_settings->sync(); } + +void ConfigController::makePortable() { + GBAConfigMakePortable(&m_config); + + char path[PATH_MAX]; + GBAConfigDirectory(path, sizeof(path)); + QString fileName(path); + fileName.append(QDir::separator()); + fileName.append("qt.ini"); + QSettings* settings2 = new QSettings(fileName, QSettings::IniFormat, this); + for (const auto& key : m_settings->allKeys()) { + settings2->setValue(key, m_settings->value(key)); + } + delete m_settings; + m_settings = settings2; +} diff --git a/src/platform/qt/ConfigController.h b/src/platform/qt/ConfigController.h index eb26fa896..3b0de11b2 100644 --- a/src/platform/qt/ConfigController.h +++ b/src/platform/qt/ConfigController.h @@ -89,6 +89,7 @@ public slots: void setOption(const char* key, const QVariant& value); void setQtOption(const QString& key, const QVariant& value, const QString& group = QString()); + void makePortable(); void write(); private: diff --git a/src/platform/qt/Window.cpp b/src/platform/qt/Window.cpp index 2feb07d6d..e94aec4d1 100644 --- a/src/platform/qt/Window.cpp +++ b/src/platform/qt/Window.cpp @@ -642,6 +642,10 @@ void Window::setupMenu(QMenuBar* menubar) { fileMenu->addSeparator(); + addControlledAction(fileMenu, fileMenu->addAction(tr("Make portable"), m_config, SLOT(makePortable())), "makePortable"); + + fileMenu->addSeparator(); + QAction* loadState = new QAction(tr("&Load state"), fileMenu); loadState->setShortcut(tr("F10")); connect(loadState, &QAction::triggered, [this]() { this->openStateWindow(LoadSave::LOAD); });