On windows, change the method we use for getting the home directory and app data directory to get it in unicode form. Partial fix for BitShares/bitshares_toolkit#791
This commit is contained in:
parent
2f066e4adf
commit
6cddd42cfe
2 changed files with 27 additions and 22 deletions
|
|
@ -56,7 +56,7 @@ IF( WIN32 )
|
||||||
SET(Boost_LIBRARIES ${BOOST_LIBRARIES_TEMP} ${Boost_LIBRARIES})
|
SET(Boost_LIBRARIES ${BOOST_LIBRARIES_TEMP} ${Boost_LIBRARIES})
|
||||||
ENDIF()
|
ENDIF()
|
||||||
|
|
||||||
set( PLATFORM_SPECIFIC_LIBS WS2_32.lib )
|
set( PLATFORM_SPECIFIC_LIBS WS2_32.lib Userenv.lib)
|
||||||
# iphlpapi.lib
|
# iphlpapi.lib
|
||||||
|
|
||||||
ELSE(WIN32)
|
ELSE(WIN32)
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,9 @@
|
||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
#include <windows.h>
|
# include <Windows.h>
|
||||||
|
# include <UserEnv.h>
|
||||||
|
# include <ShlObj.h>
|
||||||
#else
|
#else
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
|
|
@ -379,14 +381,18 @@ namespace fc {
|
||||||
{
|
{
|
||||||
static fc::path p = []()
|
static fc::path p = []()
|
||||||
{
|
{
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
char* home = getenv( "USERPROFILE" );
|
HANDLE access_token;
|
||||||
if( nullptr == home )
|
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_READ, &access_token))
|
||||||
{
|
FC_ASSERT(false, "Unable to open an access token for the current process");
|
||||||
FC_ASSERT( home != nullptr, "The USERPROFILE environment variable is not set" );
|
wchar_t user_profile_dir[MAX_PATH];
|
||||||
}
|
DWORD user_profile_dir_len = sizeof(user_profile_dir);
|
||||||
return fc::path( home );
|
BOOL success = GetUserProfileDirectoryW(access_token, user_profile_dir, &user_profile_dir_len);
|
||||||
#else
|
CloseHandle(access_token);
|
||||||
|
if (!success)
|
||||||
|
FC_ASSERT(false, "Unable to get the user profile directory");
|
||||||
|
return fc::path(std::wstring(user_profile_dir));
|
||||||
|
#else
|
||||||
char* home = getenv( "HOME" );
|
char* home = getenv( "HOME" );
|
||||||
if( nullptr == home )
|
if( nullptr == home )
|
||||||
{
|
{
|
||||||
|
|
@ -398,27 +404,26 @@ namespace fc {
|
||||||
FC_ASSERT( home != nullptr, "The HOME environment variable is not set" );
|
FC_ASSERT( home != nullptr, "The HOME environment variable is not set" );
|
||||||
}
|
}
|
||||||
return fc::path( std::string(home) );
|
return fc::path( std::string(home) );
|
||||||
#endif
|
#endif
|
||||||
}();
|
}();
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
const fc::path& app_path()
|
const fc::path& app_path()
|
||||||
{
|
{
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
static fc::path appdir = [](){ return home_path() / "Library" / "Application Support"; }();
|
static fc::path appdir = [](){ return home_path() / "Library" / "Application Support"; }();
|
||||||
#elif defined( WIN32 )
|
#elif defined( WIN32 )
|
||||||
static fc::path appdir = [](){
|
static fc::path appdir = [](){
|
||||||
char* appdata = getenv( "APPDATA" );
|
wchar_t app_data_dir[MAX_PATH];
|
||||||
if( nullptr == appdata )
|
|
||||||
{
|
if (!SUCCEEDED(SHGetFolderPathW(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, app_data_dir)))
|
||||||
FC_ASSERT( appdata != nullptr, "The APPDATA environment variable is not set" );
|
FC_ASSERT(false, "Unable to get the current AppData directory");
|
||||||
}
|
return fc::path(std::wstring(app_data_dir));
|
||||||
return fc::path( std::string(appdata) );
|
|
||||||
}();
|
}();
|
||||||
#else
|
#else
|
||||||
static fc::path appdir = home_path();
|
static fc::path appdir = home_path();
|
||||||
#endif
|
#endif
|
||||||
return appdir;
|
return appdir;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue