From 5506ea5b654c8bb007a757f76a4d852b74e07522 Mon Sep 17 00:00:00 2001 From: Hartmnt Date: Mon, 25 Nov 2024 20:43:13 +0000 Subject: [PATCH] FIX(client): Fix Windows unicode paths on writing files with ofstream --- src/mumble/PluginInstaller.cpp | 6 ++++-- src/mumble/Settings.cpp | 20 ++++++++++++-------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/mumble/PluginInstaller.cpp b/src/mumble/PluginInstaller.cpp index 4740acb0f64..aa1e303ba3f 100644 --- a/src/mumble/PluginInstaller.cpp +++ b/src/mumble/PluginInstaller.cpp @@ -18,9 +18,10 @@ #include #include -#include #include +#include + #include #include #include @@ -127,7 +128,8 @@ void PluginInstaller::init() { zipInput.clear(); Poco::Zip::ZipInputStream zipin(zipInput, pluginIt->second); - std::ofstream out(tmpPluginPath.toStdString(), std::ios::out | std::ios::binary); + boost::filesystem::path nativePath(tmpPluginPath.toStdString()); + boost::filesystem::ofstream out(nativePath, std::ios::out | std::ios::binary); Poco::StreamCopier::copyStream(zipin, out); m_pluginSource = QFileInfo(tmpPluginPath); diff --git a/src/mumble/Settings.cpp b/src/mumble/Settings.cpp index 4fa802ce4c5..1dfbed93ae4 100644 --- a/src/mumble/Settings.cpp +++ b/src/mumble/Settings.cpp @@ -33,12 +33,12 @@ #include #include +#include #include #include #include #include -#include #include #include @@ -155,11 +155,12 @@ void Settings::save(const QString &path) const { QFile tmpFile(QString::fromLatin1("%1/mumble_settings.json.tmp") .arg(QStandardPaths::writableLocation(QStandardPaths::TempLocation))); - { - // The separate scope makes sure, the stream is closed again after the write has finished - std::ofstream stream(tmpFile.fileName().toUtf8()); + boost::filesystem::path nativePath(tmpFile.fileName().toUtf8()) boost::filesystem::ofstream stream(nativePath); + stream << settingsJSON.dump(4) << std::endl; + stream.close(); - stream << settingsJSON.dump(4) << std::endl; + if (stream.fail()) { + qWarning("Failed at writing temporary settings file: %s", tmpFile.fileName()); } QFile targetFile(path); @@ -222,7 +223,8 @@ void Settings::load(const QString &path) { settingsLocation = path; } - std::ifstream stream(path.toUtf8()); + boost::filesystem::path nativePath(path.toUtf8()); + boost::filesystem::ifstream stream(nativePath); nlohmann::json settingsJSON; try { @@ -611,13 +613,15 @@ void OverlaySettings::savePresets(const QString &filename) { settingsJSON.erase(SettingsKeys::OVERLAY_LAUNCHERS_KEY); settingsJSON.erase(SettingsKeys::OVERLAY_LAUNCHERS_EXCLUDE_KEY); - std::ofstream stream(filename.toUtf8()); + boost::filesystem::path nativePath(filename.toUtf8()); + boost::filesystem::ofstream stream(nativePath); stream << settingsJSON.dump(4) << std::endl; } void OverlaySettings::load(const QString &filename) { - std::ifstream stream(filename.toUtf8()); + boost::filesystem::path nativePath(filename.toUtf8()); + boost::filesystem::ifstream stream(nativePath); nlohmann::json settingsJSON; try {