mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-11-26 16:15:39 +00:00
Merge pull request #380 from tomaz82/getHomePath_fix
Fix getHomePath crash when the environment variable isn't set
This commit is contained in:
commit
0a945ba556
|
@ -143,21 +143,24 @@ namespace Utils
|
||||||
if(!path.length())
|
if(!path.length())
|
||||||
{
|
{
|
||||||
// this should give us something like "/home/YOUR_USERNAME" on Linux and "C:/Users/YOUR_USERNAME/" on Windows
|
// this should give us something like "/home/YOUR_USERNAME" on Linux and "C:/Users/YOUR_USERNAME/" on Windows
|
||||||
std::string envHome(getenv("HOME"));
|
char* envHome = getenv("HOME");
|
||||||
if(envHome.length())
|
if(envHome)
|
||||||
path = getGenericPath(envHome);
|
path = getGenericPath(envHome);
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
// but does not seem to work for Windows XP or Vista, so try something else
|
// but does not seem to work for Windows XP or Vista, so try something else
|
||||||
if(!path.length())
|
if(!path.length())
|
||||||
{
|
{
|
||||||
std::string envDir(getenv("HOMEDRIVE"));
|
char* envHomeDrive = getenv("HOMEDRIVE");
|
||||||
std::string envPath(getenv("HOMEPATH"));
|
char* envHomePath = getenv("HOMEPATH");
|
||||||
if(envDir.length() && envPath.length())
|
if(envHomeDrive && envHomePath)
|
||||||
path = getGenericPath(envDir + "/" + envPath);
|
path = getGenericPath(std::string(envHomeDrive) + "/" + envHomePath);
|
||||||
}
|
}
|
||||||
#endif // _WIN32
|
#endif // _WIN32
|
||||||
|
|
||||||
|
// no homepath found, fall back to current working directory
|
||||||
|
if(!path.length())
|
||||||
|
path = getCWDPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
// return constructed homepath
|
// return constructed homepath
|
||||||
|
|
Loading…
Reference in a new issue