Find proper home path

Should work on more systems now.
This commit is contained in:
Bim Overbohm 2013-05-16 21:29:41 +02:00
parent 42829b3b6d
commit 4b4c891b30

View file

@ -1,12 +1,31 @@
#include "platform.h" #include "platform.h"
#include <stdlib.h> #include <stdlib.h>
std::string getHomePath() std::string getHomePath()
{ {
//this gives you something like "/home/YOUR_USERNAME" on Linux and "C:\Users\YOUR_USERNAME\" on Windows std::string homePath;
const char* home = getenv("HOME");
if(home == NULL) //this should give you something like "/home/YOUR_USERNAME" on Linux and "C:\Users\YOUR_USERNAME\" on Windows
return ""; const char * envHome = getenv("HOME");
else if(envHome != nullptr) {
return home; 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;
} }