Skip to content

Commit

Permalink
fix #1959
Browse files Browse the repository at this point in the history
Use QT again for opening file so that we don't depend on locale
  • Loading branch information
RSDuck committed Mar 12, 2024
1 parent b117bb8 commit 18d1df6
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions src/frontend/qt_sdl/Platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Check failure on line 221 in src/frontend/qt_sdl/Platform.cpp

View workflow job for this annotation

GitHub Actions / arm64

no viable conversion from 'int' to 'QIODevice::OpenMode' (aka 'QFlags<OpenModeFlag>')
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';

Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit 18d1df6

Please sign in to comment.