mirror of https://github.com/mgba-emu/mgba.git
Qt: Menu option to make portable
This commit is contained in:
parent
d9778a98d4
commit
38ec77b803
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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); });
|
||||
|
|
Loading…
Reference in New Issue