Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FIX(client): Fix Windows unicode paths on writing files with ofstream
Browse files Browse the repository at this point in the history
Hartmnt committed Nov 29, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 9ee2f4b commit 8cfc527
Showing 3 changed files with 19 additions and 10 deletions.
2 changes: 2 additions & 0 deletions src/mumble/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -597,6 +597,7 @@ if(WIN32)

find_pkg(Boost
COMPONENTS
filesystem
system
thread
REQUIRED
@@ -630,6 +631,7 @@ if(WIN32)

target_link_libraries(mumble_client_object_lib
PUBLIC
Boost::filesystem
Boost::system
Boost::thread
)
6 changes: 4 additions & 2 deletions src/mumble/PluginInstaller.cpp
Original file line number Diff line number Diff line change
@@ -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>
@@ -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.toUtf8().data());
boost::filesystem::ofstream out(nativePath, std::ios::out | std::ios::binary);
Poco::StreamCopier::copyStream(zipin, out);

m_pluginSource = QFileInfo(tmpPluginPath);
21 changes: 13 additions & 8 deletions src/mumble/Settings.cpp
Original file line number Diff line number Diff line change
@@ -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>

@@ -155,11 +155,13 @@ 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().data());
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);
@@ -222,7 +224,8 @@ void Settings::load(const QString &path) {
settingsLocation = path;
}

std::ifstream stream(path.toUtf8());
boost::filesystem::path nativePath(path.toUtf8().data());
boost::filesystem::ifstream stream(nativePath);

nlohmann::json settingsJSON;
try {
@@ -611,13 +614,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().data());
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().data());
boost::filesystem::ifstream stream(nativePath);

nlohmann::json settingsJSON;
try {

0 comments on commit 8cfc527

Please sign in to comment.