Fix crash with nonexistent config directory or writable files.

This commit is contained in:
Nadia Holmquist Pedersen 2020-05-06 03:49:20 +02:00
parent 6cfe4faa56
commit beb3b20d5e
1 changed files with 7 additions and 3 deletions

View File

@ -80,10 +80,12 @@ FILE* OpenFile(const char* path, const char* mode, bool mustexist)
{ {
QFile f(path); QFile f(path);
if (!mustexist && !f.exists()) if (mustexist && !f.exists())
{
return nullptr; return nullptr;
}
f.open(QIODevice::ReadOnly); f.open(QIODevice::ReadWrite);
FILE* file = fdopen(dup(f.handle()), mode); FILE* file = fdopen(dup(f.handle()), mode);
f.close(); f.close();
@ -105,7 +107,9 @@ FILE* OpenLocalFile(const char* path, const char* mode)
fullpath = QString("./") + path; fullpath = QString("./") + path;
#else #else
// Check user configuration directory // Check user configuration directory
fullpath = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + "/melonDS/"; QDir config(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation));
config.mkdir("melonDS");
fullpath = config.absolutePath() + "/melonDS/";
fullpath.append(path); fullpath.append(path);
#endif #endif
} }