| 4 | |
| 5 | |
| 6 | std::string getHomePath() |
| 7 | { |
| 8 | std::string homePath; |
| 9 | |
| 10 | //this should give you something like "/home/YOUR_USERNAME" on Linux and "C:\Users\YOUR_USERNAME\" on Windows |
| 11 | const char * envHome = getenv("HOME"); |
| 12 | if(envHome != nullptr) { |
| 13 | homePath = envHome; |
| 14 | } |
| 15 | #ifdef WIN32 |
| 16 | //but does not seem to work for Windwos XP or Vista, so try something else |
| 17 | if (homePath.empty()) { |
| 18 | const char * envDir = getenv("HOMEDRIVE"); |
| 19 | const char * envPath = getenv("HOMEPATH"); |
| 20 | if (envDir != nullptr && envPath != nullptr) { |
| 21 | homePath = envDir; |
| 22 | homePath += envPath; |
| 23 | |
| 24 | for(unsigned int i = 0; i < homePath.length(); i++) |
| 25 | if(homePath[i] == '\\') |
| 26 | homePath[i] = '/'; |
| 27 | } |
| 28 | } |
| 29 | #else |
| 30 | if (homePath.empty()) { |
| 31 | homePath = "~"; |
| 32 | } |
| 33 | #endif |
| 34 | |
| 35 | //convert path to generic directory seperators |
| 36 | boost::filesystem::path genericPath(homePath); |
| 37 | return genericPath.generic_string(); |
| 38 | } |
no test coverage detected