2013-05-13 19:53:28 +00:00
|
|
|
#include "platform.h"
|
2013-05-13 20:06:18 +00:00
|
|
|
#include <stdlib.h>
|
2013-07-03 12:27:06 +00:00
|
|
|
#include <boost/filesystem.hpp>
|
2013-05-13 19:53:28 +00:00
|
|
|
|
2013-05-16 19:29:41 +00:00
|
|
|
|
2013-05-13 19:53:28 +00:00
|
|
|
std::string getHomePath()
|
|
|
|
{
|
2013-05-16 19:29:41 +00:00
|
|
|
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;
|
2013-06-14 15:16:16 +00:00
|
|
|
|
|
|
|
for(unsigned int i = 0; i < homePath.length(); i++)
|
|
|
|
if(homePath[i] == '\\')
|
|
|
|
homePath[i] = '/';
|
2013-05-16 19:29:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
if (homePath.empty()) {
|
|
|
|
homePath = "~";
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-07-03 12:27:06 +00:00
|
|
|
//convert path to generic directory seperators
|
|
|
|
boost::filesystem::path genericPath(homePath);
|
|
|
|
return genericPath.generic_string();
|
2013-05-13 19:53:28 +00:00
|
|
|
}
|