aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRSDuck <RSDuck@users.noreply.github.com>2024-03-12 08:35:56 +0100
committerRSDuck <RSDuck@users.noreply.github.com>2024-03-12 08:35:56 +0100
commit18d1df606f475c49bf7bfc6cdbbbdb9208e0e7df (patch)
treeb515811baafe713a250bdd0bfa035da0fb014f6d
parentb117bb8f58938edf3da1e348ca5ff32fa68b279e (diff)
fix #1959
Use QT again for opening file so that we don't depend on locale
-rw-r--r--src/frontend/qt_sdl/Platform.cpp34
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());