mirror of
https://github.com/melonDS-emu/melonDS.git
synced 2025-07-26 07:39:56 -06:00
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:
@ -217,6 +217,10 @@ std::string InstanceFileSuffix()
|
||||
|
||||
constexpr char AccessMode(FileMode mode, bool file_exists)
|
||||
{
|
||||
|
||||
if (mode & FileMode::Append)
|
||||
return 'a';
|
||||
|
||||
if (!(mode & FileMode::Write))
|
||||
// If we're only opening the file for reading...
|
||||
return 'r';
|
||||
@ -255,7 +259,7 @@ static std::string GetModeString(FileMode mode, bool file_exists)
|
||||
|
||||
FileHandle* OpenFile(const std::string& path, FileMode mode)
|
||||
{
|
||||
if ((mode & FileMode::ReadWrite) == FileMode::None)
|
||||
if ((mode & (FileMode::ReadWrite | FileMode::Append)) == FileMode::None)
|
||||
{ // If we aren't reading or writing, then we can't open the file
|
||||
Log(LogLevel::Error, "Attempted to open \"%s\" in neither read nor write mode (FileMode 0x%x)\n", path.c_str(), mode);
|
||||
return nullptr;
|
||||
@ -327,6 +331,28 @@ bool LocalFileExists(const std::string& name)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CheckFileWritable(const std::string& filepath)
|
||||
{
|
||||
FileHandle* file = Platform::OpenFile(filepath.c_str(), FileMode::Append);
|
||||
if (file)
|
||||
{
|
||||
Platform::CloseFile(file);
|
||||
return true;
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
|
||||
bool CheckLocalFileWritable(const std::string& name)
|
||||
{
|
||||
FileHandle* file = Platform::OpenLocalFile(name.c_str(), FileMode::Append);
|
||||
if (file)
|
||||
{
|
||||
Platform::CloseFile(file);
|
||||
return true;
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
|
||||
bool FileSeek(FileHandle* file, s64 offset, FileSeekOrigin origin)
|
||||
{
|
||||
int stdorigin;
|
||||
|
Reference in New Issue
Block a user