diff --git a/src/fileutils.cpp b/src/fileutils.cpp index 437122ce0d79809c7ff42042188c69cbb47af3ad..409bcab17484b50946cfbdfa4f104505c868e9ce 100644 --- a/src/fileutils.cpp +++ b/src/fileutils.cpp @@ -242,6 +242,9 @@ bool isDirectory(const std::string& path) bool isDirectoryWritable(const std::string &directory) { +#ifdef _WIN32 + return access(decodeMultibyteString(directory).c_str(), W_OK) == 0; +#endif return access(directory.c_str(), W_OK) == 0; } diff --git a/src/manager.cpp b/src/manager.cpp index f8c74650daded6f0a27fb9bcf72ee7bf8453de9d..f07eaad4f54186b364811975fe40139293110b0a 100644 --- a/src/manager.cpp +++ b/src/manager.cpp @@ -98,7 +98,6 @@ using random_device = dht::crypto::random_device; #include <list> #include <random> - namespace ring { /** To store conference objects by conference ids */ @@ -290,13 +289,10 @@ struct Manager::ManagerPimpl void loadAccount(const YAML::Node &item, int &errorCount); - void sendTextMessageToConference(const Conference& conf, const std::map<std::string, std::string>& messages, const std::string& from) const noexcept; - - void bindCallToConference(Call& call, Conference& conf); template <class T> @@ -1128,7 +1124,6 @@ Manager::muteMediaCall(const std::string& callId, const std::string& mediaType, } } - //THREAD=Main bool Manager::transferCall(const std::string& callId, const std::string& to) @@ -2124,12 +2119,16 @@ Manager::playRingtone(const std::string& accountID) } std::string ringchoice = account->getRingtonePath(); +#ifndef _WIN32 if (ringchoice.find(DIR_SEPARATOR_STR) == std::string::npos) { // check inside global share directory static const char * const RINGDIR = "ringtones"; ringchoice = std::string(PROGSHAREDIR) + DIR_SEPARATOR_STR + RINGDIR + DIR_SEPARATOR_STR + ringchoice; } +#else + ringchoice = decodeMultibyteString(ringchoice); +#endif { std::lock_guard<std::mutex> lock(pimpl_->audioLayerMutex_); diff --git a/src/media/recordable.cpp b/src/media/recordable.cpp index 3941cd920a50fc5b36b132b0a715bb22a31f1f71..cd29930472d5208446582e71c2ac31466f250d55 100644 --- a/src/media/recordable.cpp +++ b/src/media/recordable.cpp @@ -60,6 +60,9 @@ Recordable::toggleRecording() auto startTime = *std::localtime(&t); std::stringstream ss; auto dir = Manager::instance().audioPreference.getRecordPath(); +#ifdef _WIN32 + dir = decodeMultibyteString(dir); +#endif if (dir.empty()) dir = fileutils::get_home_dir(); ss << dir; diff --git a/src/string_utils.cpp b/src/string_utils.cpp index c74b34f543dbee26f7afc83540cd919e8a0a0973..b11db5210bea4dd8a6bd81c49183befd21bbe132 100644 --- a/src/string_utils.cpp +++ b/src/string_utils.cpp @@ -35,18 +35,28 @@ namespace ring { #ifdef _WIN32 -std::wstring to_wstring(const std::string& s) +std::wstring +to_wstring(const std::string& s) { int slength = (int)s.length() + 1; - int len = MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, nullptr, 0); + int len = MultiByteToWideChar(CP_UTF8, 0, s.c_str(), slength, nullptr, 0); if (not len) throw std::runtime_error("Can't convert string to wchar"); std::wstring r((size_t)len, 0); - if (!MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, &(*r.begin()), len)) + if (!MultiByteToWideChar(CP_UTF8, 0, s.c_str(), slength, &(*r.begin()), len)) throw std::runtime_error("Can't convert string to wchar"); return r; } +std::string +decodeMultibyteString(const std::string& s) +{ + if (not s.length()) + return {}; + auto wstr = to_wstring(s); + return std::string(wstr.begin(), wstr.end()); +} + #endif std::string diff --git a/src/string_utils.h b/src/string_utils.h index fded39125fe756d02cbabe3b8b5588d65d2a78d4..62ad643ae344dd4d969dddd14170cc43a3c116f0 100644 --- a/src/string_utils.h +++ b/src/string_utils.h @@ -39,9 +39,8 @@ bool_to_str(bool b) noexcept std::string to_string(double value); #ifdef _WIN32 - std::wstring to_wstring(const std::string& s); - +std::string decodeMultibyteString(const std::string& s); #endif template <typename T>