From 45ffbf978c9eec544bb29af391d12f7c460aac02 Mon Sep 17 00:00:00 2001 From: Aloshi Date: Thu, 13 Mar 2014 22:14:49 -0500 Subject: [PATCH] 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. --- DEVNOTES.md | 2 +- README.md | 11 +++++------ src/Settings.h | 3 +++ src/main.cpp | 35 ++++++++++++++++++++++++----------- src/platform.cpp | 24 ++++++++++++++++-------- src/platform.h | 3 ++- 6 files changed, 51 insertions(+), 27 deletions(-) diff --git a/DEVNOTES.md b/DEVNOTES.md index 7ec034477..d9d207aec 100644 --- a/DEVNOTES.md +++ b/DEVNOTES.md @@ -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 diff --git a/README.md b/README.md index 926b81f09..c68daaf24 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/Settings.h b/src/Settings.h index 9f7e69d24..1ea193572 100644 --- a/src/Settings.h +++ b/src/Settings.h @@ -25,6 +25,7 @@ public: std::shared_ptr getScraper(); void setScraper(std::shared_ptr scraper); + private: static Settings* sInstance; @@ -36,7 +37,9 @@ private: std::map mBoolMap; std::map mIntMap; std::map mFloatMap; + std::shared_ptr mScraper; + std::string mHomePathOverride; }; #endif diff --git a/src/main.cpp b/src/main.cpp index 6b1df845b..6b9479917 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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 } diff --git a/src/platform.cpp b/src/platform.cpp index 856161302..be7752d91 100644 --- a/src/platform.cpp +++ b/src/platform.cpp @@ -2,18 +2,30 @@ #include #include +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 + // 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 + // 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"); @@ -26,13 +38,9 @@ std::string getHomePath() homePath[i] = '/'; } } -#else - if (homePath.empty()) { - homePath = "~"; - } #endif - //convert path to generic directory seperators + // convert path to generic directory seperators boost::filesystem::path genericPath(homePath); return genericPath.generic_string(); } diff --git a/src/platform.h b/src/platform.h index a0bb68251..aa94d313f 100644 --- a/src/platform.h +++ b/src/platform.h @@ -17,4 +17,5 @@ #include -std::string getHomePath(); \ No newline at end of file +std::string getHomePath(); +void setHomePathOverride(const std::string& path);