From 42d9cee02d4a3f601a93b0986801e4e54044da0a Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Wed, 16 May 2018 17:04:29 +0200 Subject: [PATCH] feat(PathsWindows): use a compilable code... --- coreapi/logging.c | 2 +- src/core/paths/paths-windows.cpp | 39 +++++++++++++++++--------------- src/core/paths/paths-windows.h | 4 ++-- 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/coreapi/logging.c b/coreapi/logging.c index 7c4a213b3..f707a37dc 100644 --- a/coreapi/logging.c +++ b/coreapi/logging.c @@ -95,7 +95,7 @@ unsigned int _bctbx_log_mask_to_linphone_log_mask(unsigned int mask) { BctbxLogLevel _linphone_log_level_to_bctbx_log_level(LinphoneLogLevel level) { try { return _linphone_log_level_to_bctbx_log_level_map.at(level); - } catch (const std::out_of_range &e) { + } catch (const std::out_of_range &) { ms_fatal("%s(): invalid argument [%d]", __FUNCTION__, level); return BCTBX_LOG_LOGLEV_END; } diff --git a/src/core/paths/paths-windows.cpp b/src/core/paths/paths-windows.cpp index 351d0b304..827db3500 100644 --- a/src/core/paths/paths-windows.cpp +++ b/src/core/paths/paths-windows.cpp @@ -17,11 +17,9 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#include - -#include "shlobj.h" - -#include "linphone/utils/utils.h" +#include +#include +#include #include "core/platform-helpers/platform-helpers.h" @@ -33,23 +31,28 @@ using namespace std; LINPHONE_BEGIN_NAMESPACE -string SysPaths::getDataPath (PlatformHelpers *platformHelper) { - TCHAR szPath[MAX_PATH]; - // Get path for each computer, non-user specific and non-roaming data. - if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0, szPath))) { - stringstream path; - path << boost::lexical_cast(szPath) << "\\linphone\\"; - string ret = path.str(); - boost::replace_all(ret, "\\", "\\\\"); - return ret; +static string getPath (const GUID &id) { + string strPath; + + LPWSTR path; + if (SHGetKnownFolderPath(id, KF_FLAG_DONT_VERIFY, 0, &path) == S_OK) { + strPath = _bstr_t(path); + replace(strPath.begin(), strPath.end(), '\\', '/'); + CoTaskMemFree(path); } - return Utils::getEmptyConstRefObject(); + return strPath; } -string SysPaths::getConfigPath (PlatformHelpers *platformHelper) { - // Seems to be the same directory. - return getDataPath(platformHelper); + +string SysPaths::getDataPath (PlatformHelpers *) { + static string dataPath = getPath(FOLDERID_LocalAppData); + return dataPath; +} + +string SysPaths::getConfigPath (PlatformHelpers *platformHelpers) { + // Yes, same path. + return getDataPath(platformHelpers); } LINPHONE_END_NAMESPACE diff --git a/src/core/paths/paths-windows.h b/src/core/paths/paths-windows.h index 2429bb46d..1ee9d92f7 100644 --- a/src/core/paths/paths-windows.h +++ b/src/core/paths/paths-windows.h @@ -31,8 +31,8 @@ LINPHONE_BEGIN_NAMESPACE class PlatformHelpers; namespace SysPaths { - LINPHONE_PUBLIC std::string getDataPath (PlatformHelpers *platformHelper); - LINPHONE_PUBLIC std::string getConfigPath (PlatformHelpers *platformHelper); + LINPHONE_PUBLIC std::string getDataPath (PlatformHelpers *platformHelpers); + LINPHONE_PUBLIC std::string getConfigPath (PlatformHelpers *platformHelpers); } LINPHONE_END_NAMESPACE