mirror of
https://github.com/debauchee/barrier.git
synced 2026-07-05 19:36:16 +08:00
link gui with common; reimplement finding personal and profile directories on windows (not yet used)
This commit is contained in:
54
src/lib/common/win32/DataDirectories.cpp
Normal file
54
src/lib/common/win32/DataDirectories.cpp
Normal file
@@ -0,0 +1,54 @@
|
||||
#include "DataDirectories.h"
|
||||
|
||||
#include <Shlobj.h>
|
||||
|
||||
// static member
|
||||
std::string DataDirectories::_personal;
|
||||
std::string DataDirectories::_profile;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
std::string known_folder_path(const KNOWNFOLDERID& id)
|
||||
{
|
||||
std::string path;
|
||||
WCHAR* buffer;
|
||||
HRESULT result = SHGetKnownFolderPath(id, 0, NULL, &buffer);
|
||||
if (result == S_OK) {
|
||||
path = unicode_to_mb(buffer);
|
||||
CoTaskMemFree(buffer);
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
const std::string& DataDirectories::personal()
|
||||
{
|
||||
if (_personal.empty())
|
||||
_personal = known_folder_path(FOLDERID_Documents);
|
||||
return _personal;
|
||||
}
|
||||
|
||||
const std::string& DataDirectories::personal(const std::string& path)
|
||||
{
|
||||
_personal = path;
|
||||
return _personal;
|
||||
}
|
||||
|
||||
const std::string& DataDirectories::profile()
|
||||
{
|
||||
if (_profile.empty())
|
||||
_profile = known_folder_path(FOLDERID_LocalAppData) + "\\Barrier";
|
||||
return _profile;
|
||||
}
|
||||
|
||||
const std::string& DataDirectories::profile(const std::string& path)
|
||||
{
|
||||
_profile = path;
|
||||
return _profile;
|
||||
}
|
||||
Reference in New Issue
Block a user