diff options
author | Jaklyy <102590697+Jaklyy@users.noreply.github.com> | 2024-02-07 17:04:36 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-07 23:04:36 +0100 |
commit | 5ffa6429804a5668edf198a26a1595c170149798 (patch) | |
tree | c8265c1d9d975ef525848c8d5977998b763f191d /src/frontend/qt_sdl/Platform.cpp | |
parent | 71e1ba8c40468385f2e66142cdbc943c4efb8f55 (diff) |
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.
Diffstat (limited to 'src/frontend/qt_sdl/Platform.cpp')
-rw-r--r-- | src/frontend/qt_sdl/Platform.cpp | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/src/frontend/qt_sdl/Platform.cpp b/src/frontend/qt_sdl/Platform.cpp index 222e512..9bb19d1 100644 --- a/src/frontend/qt_sdl/Platform.cpp +++ b/src/frontend/qt_sdl/Platform.cpp @@ -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; |