mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-11-25 23:55:38 +00:00
Merge pull request #587 from fabricecaruso72/home-enhancements
Add --home command line to set custom home path + make windows version natively portable by detecting if .emulationstation is a subfolder of the exe.
This commit is contained in:
commit
4b4c207208
|
@ -31,7 +31,23 @@ bool scrape_cmdline = false;
|
||||||
|
|
||||||
bool parseArgs(int argc, char* argv[])
|
bool parseArgs(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
Settings::getInstance()->setString("ExePath", argv[0]);
|
Utils::FileSystem::setExePath(argv[0]);
|
||||||
|
|
||||||
|
// We need to process --home before any call to Settings::getInstance(), because settings are loaded from homepath
|
||||||
|
for(int i = 1; i < argc; i++)
|
||||||
|
{
|
||||||
|
if (strcmp(argv[i], "--home") == 0)
|
||||||
|
{
|
||||||
|
if (i >= argc - 1)
|
||||||
|
{
|
||||||
|
std::cerr << "Invalid home path supplied.";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Utils::FileSystem::setHomePath(argv[i + 1]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for(int i = 1; i < argc; i++)
|
for(int i = 1; i < argc; i++)
|
||||||
{
|
{
|
||||||
|
@ -168,6 +184,7 @@ bool parseArgs(int argc, char* argv[])
|
||||||
"--force-kid Force the UI mode to be Kid\n"
|
"--force-kid Force the UI mode to be Kid\n"
|
||||||
"--force-kiosk Force the UI mode to be Kiosk\n"
|
"--force-kiosk Force the UI mode to be Kiosk\n"
|
||||||
"--force-disable-filters Force the UI to ignore applied filters in gamelist\n"
|
"--force-disable-filters Force the UI to ignore applied filters in gamelist\n"
|
||||||
|
"--home [path] Directory to use as home path\n"
|
||||||
"--help, -h summon a sentient, angry tuba\n\n"
|
"--help, -h summon a sentient, angry tuba\n\n"
|
||||||
"More information available in README.md.\n";
|
"More information available in README.md.\n";
|
||||||
return false; //exit after printing help
|
return false; //exit after printing help
|
||||||
|
|
|
@ -33,8 +33,7 @@ std::vector<const char*> settings_dont_save {
|
||||||
{ "ScreenHeight" },
|
{ "ScreenHeight" },
|
||||||
{ "ScreenOffsetX" },
|
{ "ScreenOffsetX" },
|
||||||
{ "ScreenOffsetY" },
|
{ "ScreenOffsetY" },
|
||||||
{ "ScreenRotate" },
|
{ "ScreenRotate" }
|
||||||
{ "ExePath" }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Settings::Settings()
|
Settings::Settings()
|
||||||
|
@ -161,8 +160,6 @@ void Settings::setDefaults()
|
||||||
mIntMap["ScreenOffsetX"] = 0;
|
mIntMap["ScreenOffsetX"] = 0;
|
||||||
mIntMap["ScreenOffsetY"] = 0;
|
mIntMap["ScreenOffsetY"] = 0;
|
||||||
mIntMap["ScreenRotate"] = 0;
|
mIntMap["ScreenRotate"] = 0;
|
||||||
|
|
||||||
mStringMap["ExePath"] = "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename K, typename V>
|
template <typename K, typename V>
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
#include "utils/FileSystemUtil.h"
|
#include "utils/FileSystemUtil.h"
|
||||||
|
|
||||||
#include "Settings.h"
|
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
@ -26,6 +25,8 @@ namespace Utils
|
||||||
{
|
{
|
||||||
namespace FileSystem
|
namespace FileSystem
|
||||||
{
|
{
|
||||||
|
static std::string homePath;
|
||||||
|
static std::string exePath;
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
static std::string convertFromWideString(const std::wstring wstring)
|
static std::string convertFromWideString(const std::wstring wstring)
|
||||||
|
@ -138,36 +139,46 @@ namespace Utils
|
||||||
|
|
||||||
} // getPathList
|
} // getPathList
|
||||||
|
|
||||||
|
void setHomePath(const std::string& _path)
|
||||||
|
{
|
||||||
|
homePath = getGenericPath(_path);
|
||||||
|
}
|
||||||
|
|
||||||
std::string getHomePath()
|
std::string getHomePath()
|
||||||
{
|
{
|
||||||
static std::string path;
|
if(homePath.length())
|
||||||
|
return homePath;
|
||||||
|
|
||||||
// only construct the homepath once
|
// Is it a portable installation ? Check if ".emulationstation/es_systems.cfg" exists in the exe's path
|
||||||
if(!path.length())
|
if(Utils::FileSystem::exists(getExePath() + "/.emulationstation/es_systems.cfg"))
|
||||||
|
homePath = getExePath();
|
||||||
|
|
||||||
|
// Check for HOME environment variable
|
||||||
|
if(!homePath.length())
|
||||||
{
|
{
|
||||||
// this should give us something like "/home/YOUR_USERNAME" on Linux and "C:/Users/YOUR_USERNAME/" on Windows
|
|
||||||
char* envHome = getenv("HOME");
|
char* envHome = getenv("HOME");
|
||||||
if(envHome)
|
if(envHome)
|
||||||
path = getGenericPath(envHome);
|
homePath = getGenericPath(envHome);
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
// but does not seem to work for Windows XP or Vista, so try something else
|
// On Windows, HOME is not the system's user path but a user environment variable.
|
||||||
if(!path.length())
|
// Instead we get the home user's path using %HOMEDRIVE%/%HOMEPATH% which are system variables.
|
||||||
|
if(!homePath.length())
|
||||||
{
|
{
|
||||||
char* envHomeDrive = getenv("HOMEDRIVE");
|
char* envHomeDrive = getenv("HOMEDRIVE");
|
||||||
char* envHomePath = getenv("HOMEPATH");
|
char* envHomePath = getenv("HOMEPATH");
|
||||||
if(envHomeDrive && envHomePath)
|
if(envHomeDrive && envHomePath)
|
||||||
path = getGenericPath(std::string(envHomeDrive) + "/" + envHomePath);
|
homePath = getGenericPath(std::string(envHomeDrive) + "/" + envHomePath);
|
||||||
}
|
}
|
||||||
#endif // _WIN32
|
#endif // _WIN32
|
||||||
|
|
||||||
// no homepath found, fall back to current working directory
|
// no homepath found, fall back to current working directory
|
||||||
if(!path.length())
|
if(!homePath.length())
|
||||||
path = getCWDPath();
|
homePath = getCWDPath();
|
||||||
}
|
|
||||||
|
|
||||||
// return constructed homepath
|
// return constructed homepath
|
||||||
return path;
|
return homePath;
|
||||||
|
|
||||||
} // getHomePath
|
} // getHomePath
|
||||||
|
|
||||||
|
@ -180,23 +191,18 @@ namespace Utils
|
||||||
|
|
||||||
} // getCWDPath
|
} // getCWDPath
|
||||||
|
|
||||||
|
void setExePath(const std::string& _path)
|
||||||
|
{
|
||||||
|
std::string path = getCanonicalPath(_path);
|
||||||
|
if(isRegularFile(path))
|
||||||
|
path = getParent(path);
|
||||||
|
|
||||||
|
exePath = path;
|
||||||
|
} // setExePath
|
||||||
|
|
||||||
std::string getExePath()
|
std::string getExePath()
|
||||||
{
|
{
|
||||||
static std::string path;
|
return exePath;
|
||||||
|
|
||||||
// only construct the exepath once
|
|
||||||
if(!path.length())
|
|
||||||
{
|
|
||||||
path = getCanonicalPath(Settings::getInstance()->getString("ExePath"));
|
|
||||||
|
|
||||||
if(isRegularFile(path))
|
|
||||||
{
|
|
||||||
path = getParent(path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// return constructed exepath
|
|
||||||
return path;
|
|
||||||
|
|
||||||
} // getExePath
|
} // getExePath
|
||||||
|
|
||||||
|
|
|
@ -13,8 +13,10 @@ namespace Utils
|
||||||
|
|
||||||
stringList getDirContent (const std::string& _path, const bool _recursive = false);
|
stringList getDirContent (const std::string& _path, const bool _recursive = false);
|
||||||
stringList getPathList (const std::string& _path);
|
stringList getPathList (const std::string& _path);
|
||||||
|
void setHomePath (const std::string& _path);
|
||||||
std::string getHomePath ();
|
std::string getHomePath ();
|
||||||
std::string getCWDPath ();
|
std::string getCWDPath ();
|
||||||
|
void setExePath (const std::string& _path);
|
||||||
std::string getExePath ();
|
std::string getExePath ();
|
||||||
std::string getPreferredPath (const std::string& _path);
|
std::string getPreferredPath (const std::string& _path);
|
||||||
std::string getGenericPath (const std::string& _path);
|
std::string getGenericPath (const std::string& _path);
|
||||||
|
@ -37,7 +39,6 @@ namespace Utils
|
||||||
bool isDirectory (const std::string& _path);
|
bool isDirectory (const std::string& _path);
|
||||||
bool isSymlink (const std::string& _path);
|
bool isSymlink (const std::string& _path);
|
||||||
bool isHidden (const std::string& _path);
|
bool isHidden (const std::string& _path);
|
||||||
|
|
||||||
} // FileSystem::
|
} // FileSystem::
|
||||||
|
|
||||||
} // Utils::
|
} // Utils::
|
||||||
|
|
Loading…
Reference in a new issue