Allow getting unicode environment variables in windows
This commit is contained in:
parent
bc555ac514
commit
b3200937da
@ -348,12 +348,19 @@ void PlayerManager::addDefaultPlayer()
|
||||
{
|
||||
std::string username = "Player";
|
||||
|
||||
if(getenv("USERNAME")!=NULL) // for windows
|
||||
username = getenv("USERNAME");
|
||||
else if(getenv("USER")!=NULL) // Linux, Macs
|
||||
#if defined(WIN32)
|
||||
std::vector<wchar_t> env;
|
||||
// An environment variable has a maximum size limit of 32,767 characters
|
||||
env.resize(32767, 0);
|
||||
DWORD length = GetEnvironmentVariable(L"USERNAME", env.data(), 32767);
|
||||
if (length != 0)
|
||||
username = StringUtils::wideToUtf8(env.data());
|
||||
#else
|
||||
if (getenv("USER") != NULL) // Linux, Macs
|
||||
username = getenv("USER");
|
||||
else if(getenv("LOGNAME")!=NULL) // Linux, Macs
|
||||
else if (getenv("LOGNAME") != NULL) // Linux, Macs
|
||||
username = getenv("LOGNAME");
|
||||
#endif
|
||||
|
||||
// Set the name as the default name, but don't mark it as 'default'
|
||||
// yet, since not having a default player forces the player selection
|
||||
|
@ -859,9 +859,13 @@ void FileManager::checkAndCreateConfigDir()
|
||||
|
||||
// Try to use the APPDATA directory to store config files and highscore
|
||||
// lists. If not defined, used the current directory.
|
||||
if (getenv("APPDATA") != NULL)
|
||||
std::vector<wchar_t> env;
|
||||
// An environment variable has a maximum size limit of 32,767 characters
|
||||
env.resize(32767, 0);
|
||||
DWORD length = GetEnvironmentVariable(L"APPDATA", env.data(), 32767);
|
||||
if (length != 0)
|
||||
{
|
||||
m_user_config_dir = getenv("APPDATA");
|
||||
m_user_config_dir = StringUtils::wideToUtf8(env.data());
|
||||
if (!checkAndCreateDirectory(m_user_config_dir))
|
||||
{
|
||||
Log::error("[FileManager]", "Can't create config dir '%s"
|
||||
|
@ -89,12 +89,19 @@ void RegisterScreen::init()
|
||||
}
|
||||
else if (PlayerManager::get()->getNumPlayers() == 0)
|
||||
{
|
||||
if (getenv("USERNAME") != NULL) // for windows
|
||||
username = getenv("USERNAME");
|
||||
else if (getenv("USER") != NULL) // Linux, Macs
|
||||
#if defined(WIN32)
|
||||
std::vector<wchar_t> env;
|
||||
// An environment variable has a maximum size limit of 32,767 characters
|
||||
env.resize(32767, 0);
|
||||
DWORD length = GetEnvironmentVariable(L"USERNAME", env.data(), 32767);
|
||||
if (length != 0)
|
||||
username = env.data();
|
||||
#else
|
||||
if (getenv("USER") != NULL) // Linux, Macs
|
||||
username = getenv("USER");
|
||||
else if (getenv("LOGNAME") != NULL) // Linux, Macs
|
||||
else if (getenv("LOGNAME") != NULL) // Linux, Macs
|
||||
username = getenv("LOGNAME");
|
||||
#endif
|
||||
}
|
||||
|
||||
TextBoxWidget* local_username = getWidget<TextBoxWidget>("local_username");
|
||||
|
Loading…
Reference in New Issue
Block a user