summaryrefslogtreecommitdiffstats
path: root/src/lib/common/win32/DataDirectories.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/common/win32/DataDirectories.cpp')
-rw-r--r--src/lib/common/win32/DataDirectories.cpp36
1 files changed, 16 insertions, 20 deletions
diff --git a/src/lib/common/win32/DataDirectories.cpp b/src/lib/common/win32/DataDirectories.cpp
index 15cb64e..31a428f 100644
--- a/src/lib/common/win32/DataDirectories.cpp
+++ b/src/lib/common/win32/DataDirectories.cpp
@@ -16,66 +16,62 @@
*/
#include "../DataDirectories.h"
+#include "encoding_utilities.h"
#include <Shlobj.h>
-std::string unicode_to_mb(const WCHAR* utfStr)
-{
- int utfLength = lstrlenW(utfStr);
- int mbLength = WideCharToMultiByte(CP_UTF8, 0, utfStr, utfLength, NULL, 0, NULL, NULL);
- std::string mbStr(mbLength, 0);
- WideCharToMultiByte(CP_UTF8, 0, utfStr, utfLength, &mbStr[0], mbLength, NULL, NULL);
- return mbStr;
-}
+namespace barrier {
-std::string known_folder_path(const KNOWNFOLDERID& id)
+fs::path known_folder_path(const KNOWNFOLDERID& id)
{
- std::string path;
+ fs::path path;
WCHAR* buffer;
HRESULT result = SHGetKnownFolderPath(id, 0, NULL, &buffer);
if (result == S_OK) {
- path = unicode_to_mb(buffer);
+ path = fs::path(std::wstring(buffer));
CoTaskMemFree(buffer);
}
return path;
}
-const std::string& DataDirectories::profile()
+const fs::path& DataDirectories::profile()
{
if (_profile.empty())
- _profile = known_folder_path(FOLDERID_LocalAppData) + "\\Barrier";
+ _profile = known_folder_path(FOLDERID_LocalAppData) / "Barrier";
return _profile;
}
-const std::string& DataDirectories::profile(const std::string& path)
+const fs::path& DataDirectories::profile(const fs::path& path)
{
_profile = path;
return _profile;
}
-const std::string& DataDirectories::global()
+const fs::path& DataDirectories::global()
{
if (_global.empty())
- _global = known_folder_path(FOLDERID_ProgramData) + "\\Barrier";
+ _global = known_folder_path(FOLDERID_ProgramData) / "Barrier";
return _global;
}
-const std::string& DataDirectories::global(const std::string& path)
+const fs::path& DataDirectories::global(const fs::path& path)
{
_global = path;
return _global;
}
-const std::string& DataDirectories::systemconfig()
+const fs::path& DataDirectories::systemconfig()
{
// systemconfig() is a special case in that it will track the current value
- // of global() unless and until it is explictly set otherwise
+ // of global() unless and until it is explicitly set otherwise
// previously it would default to the windows folder which was horrible!
if (_systemconfig.empty())
return global();
return _systemconfig;
}
-const std::string& DataDirectories::systemconfig(const std::string& path)
+const fs::path& DataDirectories::systemconfig(const fs::path& path)
{
_systemconfig = path;
return _systemconfig;
}
+
+} // namespace barrier