Skip to content

Commit

Permalink
FIX(client): Fix Windows unicode paths on writing files with ofstream
Browse files Browse the repository at this point in the history
  • Loading branch information
Hartmnt committed Nov 25, 2024
1 parent 9c48561 commit ae295fd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
6 changes: 4 additions & 2 deletions src/mumble/PluginInstaller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
#include <QtGui/QIcon>

#include <exception>
#include <fstream>
#include <string>

#include <boost/filesystem/fstream.hpp>

#include <Poco/Exception.h>
#include <Poco/FileStream.h>
#include <Poco/StreamCopier.h>
Expand Down Expand Up @@ -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);
Expand Down
20 changes: 12 additions & 8 deletions src/mumble/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@
#include <QStandardPaths>
#include <QSystemTrayIcon>

#include <boost/filesystem/fstream.hpp>
#include <boost/typeof/typeof.hpp>

#include <algorithm>
#include <cassert>
#include <cstring>
#include <fstream>
#include <limits>
#include <memory>

Expand Down Expand Up @@ -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", qUtf8Printable(tmpFile.fileName()));
}

QFile targetFile(path);
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit ae295fd

Please sign in to comment.