link gui with common; reimplement finding personal and profile directories on windows (not yet used)
This commit is contained in:
parent
fe818a4955
commit
72cc7e3d89
|
@ -45,6 +45,8 @@ if (HAVE_X11)
|
|||
target_link_libraries (barrier X11)
|
||||
endif()
|
||||
|
||||
target_link_libraries (barrier common)
|
||||
|
||||
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
||||
install (TARGETS barrier DESTINATION ${BARRIER_BUNDLE_BINARY_DIR})
|
||||
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
||||
|
|
|
@ -17,6 +17,17 @@
|
|||
file(GLOB headers "*.h")
|
||||
file(GLOB sources "*.cpp")
|
||||
|
||||
if (WIN32)
|
||||
file(GLOB arch_headers "win32/*.h")
|
||||
file(GLOB arch_sources "win32/*.cpp")
|
||||
elseif (UNIX)
|
||||
file(GLOB arch_headers "unix/*.h")
|
||||
file(GLOB arch_sources "unix/*.cpp")
|
||||
endif()
|
||||
|
||||
list(APPEND headers ${arch_headers})
|
||||
list(APPEND sources ${arch_sources})
|
||||
|
||||
if (BARRIER_ADD_HEADERS)
|
||||
list(APPEND sources ${headers})
|
||||
endif()
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "win32/DataDirectories.h"
|
||||
#else
|
||||
#include "unix/DataDirectories.h"
|
||||
#endif
|
|
@ -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;
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
class DataDirectories
|
||||
{
|
||||
public:
|
||||
static const std::string& personal();
|
||||
static const std::string& personal(const std::string& path);
|
||||
|
||||
static const std::string& profile();
|
||||
static const std::string& profile(const std::string& path);
|
||||
|
||||
private:
|
||||
// static class
|
||||
DataDirectories() {}
|
||||
|
||||
static std::string _personal;
|
||||
static std::string _profile;
|
||||
};
|
Loading…
Reference in New Issue