diff options
author | Remko Tronçon <git@el-tramo.be> | 2013-05-15 19:44:37 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2013-05-17 19:00:55 (GMT) |
commit | de39ce6ec44647cee92853e2928cf5475af992e6 (patch) | |
tree | 1f86dd075900aeeb9b91cdd120d71052458ca6ff /SwifTools | |
parent | 927d62cc54c8a5087dba6b61afa9ad30dc528a23 (diff) | |
download | swift-contrib-de39ce6ec44647cee92853e2928cf5475af992e6.zip swift-contrib-de39ce6ec44647cee92853e2928cf5475af992e6.tar.bz2 |
Fixed unicode path handling.
- Use boost::filesystem::path consistently for referring to files.
- Use boost::filesystem streams for I/O, such that paths are always handled
correctly.
- Use stringToPath and pathToString for conversion between strings and
boost::filesystem::path, to ensure we have consistent unicode handling
across platforms and environments. The default constructor and string
conversion uses platform-dependent encoding, depending on the global
locale set in the application, which causes problems. So, unless you are
in platform dependent code, the default constructor and string() function
should not be used. When constructing paths from other paths (e.g. using
operator/), also use stringToPath (instead of string arguments) if the path
can contain unicode characters.
Change-Id: If286bd9e71c8414afc0b24ba67e26ab7608ef6ea
Diffstat (limited to 'SwifTools')
-rw-r--r-- | SwifTools/Application/UnitTest/ApplicationPathProviderTest.cpp | 5 | ||||
-rw-r--r-- | SwifTools/Application/WindowsApplicationPathProvider.cpp | 10 | ||||
-rw-r--r-- | SwifTools/CrashReporter.cpp | 7 | ||||
-rw-r--r-- | SwifTools/Notifier/GNTPNotifier.cpp | 5 | ||||
-rw-r--r-- | SwifTools/Notifier/GrowlNotifier.mm | 2 |
5 files changed, 17 insertions, 12 deletions
diff --git a/SwifTools/Application/UnitTest/ApplicationPathProviderTest.cpp b/SwifTools/Application/UnitTest/ApplicationPathProviderTest.cpp index 5eb0e16..e7a47a7 100644 --- a/SwifTools/Application/UnitTest/ApplicationPathProviderTest.cpp +++ b/SwifTools/Application/UnitTest/ApplicationPathProviderTest.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2013 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ @@ -9,6 +9,7 @@ #include <string> #include <boost/algorithm/string.hpp> +#include <Swiften/Base/Path.h> #include <SwifTools/Application/PlatformApplicationPathProvider.h> using namespace Swift; @@ -40,7 +41,7 @@ class ApplicationPathProviderTest : public CppUnit::TestFixture { void testGetExecutableDir() { boost::filesystem::path dir = testling_->getExecutableDir(); CPPUNIT_ASSERT(boost::filesystem::is_directory(dir)); - CPPUNIT_ASSERT(boost::ends_with(dir.string(), "UnitTest")); + CPPUNIT_ASSERT(boost::ends_with(pathToString(dir), "UnitTest")); } private: diff --git a/SwifTools/Application/WindowsApplicationPathProvider.cpp b/SwifTools/Application/WindowsApplicationPathProvider.cpp index 730a57a..2c61208 100644 --- a/SwifTools/Application/WindowsApplicationPathProvider.cpp +++ b/SwifTools/Application/WindowsApplicationPathProvider.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2013 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ @@ -8,6 +8,7 @@ #include <windows.h> #include <cassert> +#include <Swiften/Base/String.h> namespace Swift { @@ -17,16 +18,17 @@ WindowsApplicationPathProvider::WindowsApplicationPathProvider(const std::string } boost::filesystem::path WindowsApplicationPathProvider::getDataDir() const { - char* appDirRaw = getenv("APPDATA"); + wchar_t* appDirRaw = _wgetenv(L"APPDATA"); assert(appDirRaw); - boost::filesystem::path result(boost::filesystem::path(appDirRaw) / getApplicationName()); + boost::filesystem::path result( + boost::filesystem::path(appDirRaw) / getApplicationName()); boost::filesystem::create_directory(result); return result; } boost::filesystem::path WindowsApplicationPathProvider::getHomeDir() const { //FIXME: This should be My Documents - char* homeDirRaw = getenv("USERPROFILE"); + wchar_t* homeDirRaw = _wgetenv(L"USERPROFILE"); assert(homeDirRaw); return boost::filesystem::path(homeDirRaw); } diff --git a/SwifTools/CrashReporter.cpp b/SwifTools/CrashReporter.cpp index 67377f2..f47ab33 100644 --- a/SwifTools/CrashReporter.cpp +++ b/SwifTools/CrashReporter.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012 Remko Tronçon + * Copyright (c) 2012-2013 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ @@ -7,6 +7,7 @@ #include <SwifTools/CrashReporter.h> #include <Swiften/Base/Platform.h> +#include <Swiften/Base/Path.h> #if defined(HAVE_BREAKPAD) @@ -51,7 +52,7 @@ CrashReporter::CrashReporter(const boost::filesystem::path& path) { p = boost::make_shared<Private>(); #if defined(SWIFTEN_PLATFORM_WINDOWS) // FIXME: Need UTF8 conversion from string to wstring - std::string pathString = path.string(); + std::string pathString = pathToString(path); p->handler = boost::shared_ptr<google_breakpad::ExceptionHandler>( // Not using make_shared, because 'handleDump' seems to have problems with VC2010 new google_breakpad::ExceptionHandler( @@ -62,7 +63,7 @@ CrashReporter::CrashReporter(const boost::filesystem::path& path) { google_breakpad::ExceptionHandler::HANDLER_ALL)); // Turning it off for Mac, because it doesn't really help us //#elif defined(SWIFTEN_PLATFORM_MACOSX) -// p->handler = boost::make_shared<google_breakpad::ExceptionHandler>(path.string(), (google_breakpad::ExceptionHandler::FilterCallback) 0, handleDump, (void*) 0, true, (const char*) 0); +// p->handler = boost::make_shared<google_breakpad::ExceptionHandler>(pathToString(path), (google_breakpad::ExceptionHandler::FilterCallback) 0, handleDump, (void*) 0, true, (const char*) 0); #endif } diff --git a/SwifTools/Notifier/GNTPNotifier.cpp b/SwifTools/Notifier/GNTPNotifier.cpp index 9bc05bd..757594f 100644 --- a/SwifTools/Notifier/GNTPNotifier.cpp +++ b/SwifTools/Notifier/GNTPNotifier.cpp @@ -14,6 +14,7 @@ #include <sstream> #include <Swiften/Base/foreach.h> +#include <Swiften/Base/Path.h> #include <Swiften/Network/ConnectionFactory.h> namespace Swift { @@ -23,7 +24,7 @@ GNTPNotifier::GNTPNotifier(const std::string& name, const boost::filesystem::pat std::ostringstream message; message << "GNTP/1.0 REGISTER NONE\r\n"; message << "Application-Name: " << name << "\r\n"; - message << "Application-Icon: file://" << icon.string() << "\r\n"; + message << "Application-Icon: file://" << pathToString(icon) << "\r\n"; message << "Notifications-Count: " << getAllTypes().size() << "\r\n"; std::vector<Notifier::Type> defaultTypes = getDefaultTypes(); std::vector<Notifier::Type> allTypes = getAllTypes(); @@ -59,7 +60,7 @@ void GNTPNotifier::showMessage(Type type, const std::string& subject, const std: message << "Notification-Name: " << typeToString(type) << "\r\n"; message << "Notification-Title: " << subject << "\r\n"; message << "Notification-Text: " << description << "\r\n"; - message << "Notification-Icon: " << picture.string() << "\r\n"; + message << "Notification-Icon: " << pathToString(picture) << "\r\n"; message << "\r\n"; send(message.str()); } diff --git a/SwifTools/Notifier/GrowlNotifier.mm b/SwifTools/Notifier/GrowlNotifier.mm index c1996d9..2ababf4 100644 --- a/SwifTools/Notifier/GrowlNotifier.mm +++ b/SwifTools/Notifier/GrowlNotifier.mm @@ -65,7 +65,7 @@ GrowlNotifier::~GrowlNotifier() { void GrowlNotifier::showMessage(Type type, const std::string& subject, const std::string& description, const boost::filesystem::path& picturePath, boost::function<void()> callback) { ByteArray picture; - readByteArrayFromFile(picture, picturePath.string()); + readByteArrayFromFile(picture, picturePath); Context* context = new Context(callback); // Growl sometimes sends timeout notifications twice for the same message. We therefore need |