diff options
Diffstat (limited to 'src/frontend/qt_sdl/Platform.cpp')
-rw-r--r-- | src/frontend/qt_sdl/Platform.cpp | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/src/frontend/qt_sdl/Platform.cpp b/src/frontend/qt_sdl/Platform.cpp index 0cd4f61..7ffabfd 100644 --- a/src/frontend/qt_sdl/Platform.cpp +++ b/src/frontend/qt_sdl/Platform.cpp @@ -216,9 +216,30 @@ std::string InstanceFileSuffix() return suffix; } -constexpr char AccessMode(FileMode mode, bool file_exists) +static QIODevice::OpenMode GetQMode(FileMode mode) { + QIODevice::OpenMode qmode = 0; + if (mode & FileMode::Read) + qmode |= QIODevice::OpenModeFlag::ReadOnly; + if (mode & FileMode::Write) + qmode |= QIODevice::OpenModeFlag::WriteOnly; + if (mode & FileMode::Append) + qmode |= QIODevice::OpenModeFlag::Append; + + if ((mode & FileMode::Write) && !(mode & FileMode::Preserve)) + qmode |= QIODevice::OpenModeFlag::Truncate; + + if (mode & FileMode::NoCreate) + qmode |= QIODevice::OpenModeFlag::ExistingOnly; + + if (mode & FileMode::Text) + qmode |= QIODevice::OpenModeFlag::Text; + return qmode; +} + +constexpr char AccessMode(FileMode mode, bool file_exists) +{ if (mode & FileMode::Append) return 'a'; @@ -266,10 +287,15 @@ FileHandle* OpenFile(const std::string& path, FileMode mode) return nullptr; } - bool file_exists = QFile::exists(QString::fromStdString(path)); - std::string modeString = GetModeString(mode, file_exists); + QString qpath{QString::fromStdString(path)}; + + std::string modeString = GetModeString(mode, QFile::exists(qpath)); + QIODevice::OpenMode qmode = GetQMode(mode); + QFile qfile{qpath}; + qfile.open(qmode); + FILE* file = fdopen(dup(qfile.handle()), modeString.c_str()); + qfile.close(); - FILE* file = fopen(path.c_str(), modeString.c_str()); if (file) { Log(LogLevel::Debug, "Opened \"%s\" with FileMode 0x%x (effective mode \"%s\")\n", path.c_str(), mode, modeString.c_str()); |