Added --home-path [path] argument that redirects calls to getHomePath() to some directory [path].

Changed some existing command line arguments too:
-w and -h are now just --resolution [width] [height].
-h is now synonymous with --help.
This commit is contained in:
Aloshi 2014-03-13 22:14:49 -05:00
parent 18b428f79a
commit 45ffbf978c
6 changed files with 51 additions and 27 deletions

View file

@ -8,7 +8,7 @@ Development Environment
I personally launch ES in windowed mode with a smaller resolution than my monitor and with debug text enabled.
`emulationstation --windowed --debug -w 1280 -h 720`
`emulationstation --windowed --debug --resolution 1280 720`
Creating a new GuiComponent

View file

@ -91,23 +91,22 @@ When you first start EmulationStation, you will be prompted to configure any inp
As long as ES hasn't frozen, you can always press F4 to close the application.
**Keep in mind you'll have to set up your emulator separately from EmulationStation.**
I am currently also working on a stand-alone tool, [ES-config](https://github.com/Aloshi/ES-config), that should help make configuring emulators easier.
**Keep in mind you'll have to set up your emulator separately from EmulationStation!**
After you launch a game, EmulationStation will return once your system's command terminates (i.e. your emulator closes).
You can use `--help` to view a list of command-line options. Briefly outlined here:
You can use `--help` or `-h` to view a list of command-line options. Briefly outlined here:
```
-w [width] - specify resolution width.
-h [height] - specify resolution height.
--resolution [width] [height] - try and force a particular resolution
--gamelist-only - only display games defined in a gamelist.xml file.
--ignore-gamelist - do not parse any gamelist.xml files.
--draw-framerate - draw the framerate.
--no-exit - do not display 'exit' in the ES menu.
--debug - print additional output to the console, primarily about input.
--windowed - run ES in a window.
--windowed - run ES in a window, works best in conjunction with --resolution [w] [h].
--scrape - run the interactive command-line metadata scraper.
--home-path [path] - use [path] instead of the "home" environment variable (useful for portable installations).
```
Writing an es_systems.cfg

View file

@ -25,6 +25,7 @@ public:
std::shared_ptr<Scraper> getScraper();
void setScraper(std::shared_ptr<Scraper> scraper);
private:
static Settings* sInstance;
@ -36,7 +37,9 @@ private:
std::map<std::string, bool> mBoolMap;
std::map<std::string, int> mIntMap;
std::map<std::string, float> mFloatMap;
std::shared_ptr<Scraper> mScraper;
std::string mHomePathOverride;
};
#endif

View file

@ -26,14 +26,17 @@ bool parseArgs(int argc, char* argv[], unsigned int* width, unsigned int* height
{
for(int i = 1; i < argc; i++)
{
if(strcmp(argv[i], "-w") == 0)
if(strcmp(argv[i], "--resolution") == 0)
{
if(i >= argc - 2)
{
std::cerr << "Invalid resolution supplied.";
return false;
}
*width = atoi(argv[i + 1]);
i++; //skip the argument value
}else if(strcmp(argv[i], "-h") == 0)
{
*height = atoi(argv[i + 1]);
i++; //skip the argument value
*height = atoi(argv[i + 2]);
i += 2; // skip the argument value
}else if(strcmp(argv[i], "--gamelist-only") == 0)
{
Settings::getInstance()->setBool("ParseGamelistOnly", true);
@ -56,20 +59,30 @@ bool parseArgs(int argc, char* argv[], unsigned int* width, unsigned int* height
}else if(strcmp(argv[i], "--scrape") == 0)
{
scrape_cmdline = true;
}else if(strcmp(argv[i], "--help") == 0)
}else if(strcmp(argv[i], "--home-path") == 0)
{
if(i >= argc - 1)
{
std::cerr << "No home path specified!\n";
return false;
}
setHomePathOverride(argv[i + 1]);
}else if(strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-h") == 0)
{
std::cout << "EmulationStation, a graphical front-end for ROM browsing.\n";
std::cout << "Written by Alec \"Aloshi\" Lofquist.\n";
std::cout << "Command line arguments:\n";
std::cout << "-w [width in pixels] set screen width\n";
std::cout << "-h [height in pixels] set screen height\n";
std::cout << "--resolution [width] [height] try and force a particular resolution\n";
std::cout << "--gamelist-only skip automatic game detection, only read from gamelist.xml\n";
std::cout << "--ignore-gamelist ignore the gamelist (useful for troubleshooting)\n";
std::cout << "--draw-framerate display the framerate\n";
std::cout << "--no-exit don't show the exit option in the menu\n";
std::cout << "--debug even more logging\n";
std::cout << "--scrape scrape using command line interface\n";
std::cout << "--windowed not fullscreen, should be used in conjunction with -w and -h\n";
std::cout << "--help summon a sentient, angry tuba\n\n";
std::cout << "--windowed not fullscreen, should be used in conjunction with --resolution\n";
std::cout << "--home-path [path] use [path] instead of the \"home\" environment variable (for portable installations)\n";
std::cout << "--help, -h summon a sentient, angry tuba\n\n";
std::cout << "More information available in README.md.\n";
return false; //exit after printing help
}

View file

@ -2,16 +2,28 @@
#include <stdlib.h>
#include <boost/filesystem.hpp>
std::string sHomePathOverride;
void setHomePathOverride(const std::string& path)
{
// make it use generic directory separators
sHomePathOverride = boost::filesystem::path(path).generic_string();
}
std::string getHomePath()
{
if(!sHomePathOverride.empty())
return sHomePathOverride;
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) {
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()) {
@ -26,10 +38,6 @@ std::string getHomePath()
homePath[i] = '/';
}
}
#else
if (homePath.empty()) {
homePath = "~";
}
#endif
// convert path to generic directory seperators

View file

@ -18,3 +18,4 @@
#include <string>
std::string getHomePath();
void setHomePathOverride(const std::string& path);