mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-11-29 09:35:39 +00:00
Find proper home path
Should work on more systems now.
This commit is contained in:
parent
42829b3b6d
commit
4b4c891b30
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue