Check for write permissions for some key files (#1972)

* check if an nds save file can be opened for writing

also add the ability to open a file in append mode

* fix multi-instance saves

also move the check for file writability into a separate function (probably uneeded?)

* implement check for gba roms

* move rom load error messages into the functions

also finish gba slot (oops)

* improve error string

* check write perms before saving path settings

* fix memory leak

* check for writability of firmware/nand/sds

* add secondary checks for nand/firmware

* add check for config file being writable

* Return the file write error as a QString to avoid the invalid char*
causing a garbled error message.

Qt wants it as QString either way.
This commit is contained in:
Jaklyy
2024-02-07 17:04:36 -05:00
committed by GitHub
parent 71e1ba8c40
commit 5ffa642980
10 changed files with 199 additions and 50 deletions

View File

@ -19,6 +19,7 @@
#include <stdio.h>
#include <QFileDialog>
#include <QMessageBox>
#include <QTemporaryFile>
#include "types.h"
#include "Config.h"
@ -37,6 +38,7 @@ extern bool RunningSomething;
bool PathSettingsDialog::needsReset = false;
constexpr char errordialog[] = "melonDS cannot write to that directory.";
PathSettingsDialog::PathSettingsDialog(QWidget* parent) : QDialog(parent), ui(new Ui::PathSettingsDialog)
{
@ -101,6 +103,12 @@ void PathSettingsDialog::on_btnSaveFileBrowse_clicked()
QString::fromStdString(EmuDirectory));
if (dir.isEmpty()) return;
if (!QTemporaryFile(dir).open())
{
QMessageBox::critical(this, "melonDS", errordialog);
return;
}
ui->txtSaveFilePath->setText(dir);
}
@ -112,6 +120,12 @@ void PathSettingsDialog::on_btnSavestateBrowse_clicked()
QString::fromStdString(EmuDirectory));
if (dir.isEmpty()) return;
if (!QTemporaryFile(dir).open())
{
QMessageBox::critical(this, "melonDS", errordialog);
return;
}
ui->txtSavestatePath->setText(dir);
}
@ -123,6 +137,12 @@ void PathSettingsDialog::on_btnCheatFileBrowse_clicked()
QString::fromStdString(EmuDirectory));
if (dir.isEmpty()) return;
if (!QTemporaryFile(dir).open())
{
QMessageBox::critical(this, "melonDS", errordialog);
return;
}
ui->txtCheatFilePath->setText(dir);
}