forked from Aloshi/EmulationStation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplatform.cpp
More file actions
35 lines (30 loc) · 792 Bytes
/
platform.cpp
File metadata and controls
35 lines (30 loc) · 792 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "platform.h"
#include <stdlib.h>
std::string getHomePath()
{
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;
for(unsigned int i = 0; i < homePath.length(); i++)
if(homePath[i] == '\\')
homePath[i] = '/';
}
}
#else
if (homePath.empty()) {
homePath = "~";
}
#endif
return homePath;
}