mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-11-25 15:45:38 +00:00
Find proper home path
Should work on more systems now.
This commit is contained in:
parent
42829b3b6d
commit
4b4c891b30
|
@ -1,12 +1,31 @@
|
|||
#include "platform.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
std::string getHomePath()
|
||||
{
|
||||
//this gives you something like "/home/YOUR_USERNAME" on Linux and "C:\Users\YOUR_USERNAME\" on Windows
|
||||
const char* home = getenv("HOME");
|
||||
if(home == NULL)
|
||||
return "";
|
||||
else
|
||||
return home;
|
||||
std::string homePath;
|
||||
|
||||
//this should give you something like "/home/YOUR_USERNAME" on Linux and "C:\Users\YOUR_USERNAME\" on Windows
|
||||
const char * envHome = getenv("HOME");
|
||||
if(envHome != nullptr) {
|
||||
homePath = envHome;
|
||||
}
|
||||
#ifdef WIN32
|
||||
//but does not seem to work for Windwos XP or Vista, so try something else
|
||||
if (homePath.empty()) {
|
||||
const char * envDir = getenv("HOMEDRIVE");
|
||||
const char * envPath = getenv("HOMEPATH");
|
||||
if (envDir != nullptr && envPath != nullptr) {
|
||||
homePath = envDir;
|
||||
homePath += envPath;
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (homePath.empty()) {
|
||||
homePath = "~";
|
||||
}
|
||||
#endif
|
||||
|
||||
return homePath;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue