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>
|
2014-04-05 17:48:38 +00:00
|
|
|
#include <iostream>
|
2013-05-13 19:53:28 +00:00
|
|
|
|
2014-03-14 03:14:49 +00:00
|
|
|
std::string sHomePathOverride;
|
|
|
|
|
|
|
|
void setHomePathOverride(const std::string& path)
|
|
|
|
{
|
|
|
|
// make it use generic directory separators
|
|
|
|
sHomePathOverride = boost::filesystem::path(path).generic_string();
|
2014-04-05 17:48:38 +00:00
|
|
|
|
|
|
|
std::cout << "Using home path: " << sHomePathOverride;
|
2014-03-14 03:14:49 +00:00
|
|
|
}
|
2013-05-16 19:29:41 +00:00
|
|
|
|
2013-05-13 19:53:28 +00:00
|
|
|
std::string getHomePath()
|
|
|
|
{
|
2014-03-14 03:14:49 +00:00
|
|
|
if(!sHomePathOverride.empty())
|
|
|
|
return sHomePathOverride;
|
|
|
|
|
2013-05-16 19:29:41 +00:00
|
|
|
std::string homePath;
|
|
|
|
|
2014-03-14 03:14:49 +00:00
|
|
|
// this should give you something like "/home/YOUR_USERNAME" on Linux and "C:\Users\YOUR_USERNAME\" on Windows
|
2013-05-16 19:29:41 +00:00
|
|
|
const char * envHome = getenv("HOME");
|
2014-03-14 03:14:49 +00:00
|
|
|
if(envHome != nullptr)
|
|
|
|
{
|
2013-05-16 19:29:41 +00:00
|
|
|
homePath = envHome;
|
|
|
|
}
|
2014-03-14 03:14:49 +00:00
|
|
|
|
2013-05-16 19:29:41 +00:00
|
|
|
#ifdef WIN32
|
2014-03-14 03:14:49 +00:00
|
|
|
// but does not seem to work for Windwos XP or Vista, so try something else
|
2013-05-16 19:29:41 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-03-14 03:14:49 +00:00
|
|
|
// convert path to generic directory seperators
|
2013-07-03 12:27:06 +00:00
|
|
|
boost::filesystem::path genericPath(homePath);
|
|
|
|
return genericPath.generic_string();
|
2013-05-13 19:53:28 +00:00
|
|
|
}
|