dont make a save file on launching a game (#1974)

avoids the issue of saves being created for roms that dont use save files.
This commit is contained in:
Jaklyy 2024-02-13 14:17:29 -05:00 committed by GitHub
parent 3415e23105
commit a8429af131
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 20 additions and 3 deletions

View File

@ -31,6 +31,7 @@
#include <QMutex> #include <QMutex>
#include <QOpenGLContext> #include <QOpenGLContext>
#include <QSharedMemory> #include <QSharedMemory>
#include <QTemporaryFile>
#include <SDL_loadso.h> #include <SDL_loadso.h>
#include "Platform.h" #include "Platform.h"
@ -333,13 +334,29 @@ bool LocalFileExists(const std::string& name)
bool CheckFileWritable(const std::string& filepath) bool CheckFileWritable(const std::string& filepath)
{ {
FileHandle* file = Platform::OpenFile(filepath.c_str(), FileMode::Append); FileHandle* file = Platform::OpenFile(filepath.c_str(), FileMode::Read);
if (file)
{
// if the file exists, check if it can be opened for writing.
Platform::CloseFile(file);
file = Platform::OpenFile(filepath.c_str(), FileMode::Append);
if (file) if (file)
{ {
Platform::CloseFile(file); Platform::CloseFile(file);
return true; return true;
} }
else return false; else return false;
}
else
{
// if the file does not exist, create a temporary file to check, to avoid creating an empty file.
if (QTemporaryFile(filepath.c_str()).open())
{
return true;
}
else return false;
}
} }
bool CheckLocalFileWritable(const std::string& name) bool CheckLocalFileWritable(const std::string& name)