diff --git a/src/QtUtils.cpp b/src/QtUtils.cpp index 80508263f79..6a25209259e 100644 --- a/src/QtUtils.cpp +++ b/src/QtUtils.cpp @@ -7,6 +7,8 @@ #include #include +#include + namespace Mumble { namespace QtUtils { void deleteQObject(QObject *object) { object->deleteLater(); } @@ -23,6 +25,13 @@ namespace QtUtils { return QString(); } + boost::filesystem::path qstring_to_path(const QString &input) { +#ifdef _WIN32 + return boost::filesystem::path(input.toStdWString()); +#else + return boost::filesystem::path(input.toUtf8()); +#endif + } } // namespace QtUtils } // namespace Mumble diff --git a/src/QtUtils.h b/src/QtUtils.h index 84fed7b7679..02aa0680e1a 100644 --- a/src/QtUtils.h +++ b/src/QtUtils.h @@ -10,6 +10,8 @@ #include #include +#include + #include class QObject; @@ -34,6 +36,11 @@ namespace QtUtils { */ QString decode_first_utf8_qssl_string(const QStringList &list); + /** + * Creates a platform agnostic path from a QString + */ + boost::filesystem::path qstring_to_path(const QString &input); + } // namespace QtUtils } // namespace Mumble diff --git a/src/mumble/PluginInstaller.cpp b/src/mumble/PluginInstaller.cpp index 4740acb0f64..377909a6495 100644 --- a/src/mumble/PluginInstaller.cpp +++ b/src/mumble/PluginInstaller.cpp @@ -6,6 +6,7 @@ #include "PluginInstaller.h" #include "PluginManager.h" #include "PluginManifest.h" +#include "QtUtils.h" #include "Global.h" #include @@ -18,9 +19,10 @@ #include #include -#include #include +#include + #include #include #include @@ -127,7 +129,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::ofstream out(Mumble::QtUtils::qstring_to_path(tmpPluginPath), + 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..a6adfb8a1ab 100644 --- a/src/mumble/Settings.cpp +++ b/src/mumble/Settings.cpp @@ -10,6 +10,7 @@ #include "EnvUtils.h" #include "JSONSerialization.h" #include "Log.h" +#include "QtUtils.h" #include "SSL.h" #include "SettingsKeys.h" #include "SettingsMacros.h" @@ -33,12 +34,12 @@ #include #include +#include #include #include #include #include -#include #include #include @@ -155,11 +156,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::ofstream stream(Mumble::QtUtils::qstring_to_path(tmpFile.fileName())); + 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,7 @@ void Settings::load(const QString &path) { settingsLocation = path; } - std::ifstream stream(path.toUtf8()); + boost::filesystem::ifstream stream(Mumble::QtUtils::qstring_to_path(path)); nlohmann::json settingsJSON; try { @@ -611,13 +613,13 @@ 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::ofstream stream(Mumble::QtUtils::qstring_to_path(filename)); stream << settingsJSON.dump(4) << std::endl; } void OverlaySettings::load(const QString &filename) { - std::ifstream stream(filename.toUtf8()); + boost::filesystem::ifstream stream(Mumble::QtUtils::qstring_to_path(filename)); nlohmann::json settingsJSON; try {