From 7c48887ab375788f9d3c93761f0db2622377de87 Mon Sep 17 00:00:00 2001 From: Aloshi Date: Mon, 24 Nov 2014 20:49:11 -0600 Subject: [PATCH] Hide the console on Windows unless --debug is set. --- README.md | 16 +++++++-------- es-app/CMakeLists.txt | 12 ++++++------ es-app/src/main.cpp | 42 ++++++++++++++++++++++++++++++++++++++-- es-core/src/Settings.cpp | 2 ++ 4 files changed, 56 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 4c3773219..99c2363d7 100644 --- a/README.md +++ b/README.md @@ -36,12 +36,12 @@ Building EmulationStation uses some C++11 code, which means you'll need to use at least g++-4.7 on Linux, or VS2010 on Windows, to compile. -EmulationStation has a few dependencies. For building, you'll need SDL2, Boost (System, Filesystem, DateTime), FreeImage, FreeType, Eigen3, and cURL. +EmulationStation has a few dependencies. For building, you'll need CMake, SDL2, Boost (System, Filesystem, DateTime, Locale), FreeImage, FreeType, Eigen3, and cURL. You also should probably install the `fonts-droid` package which contains fallback fonts for Chinese/Japanese/Korean characters, but ES will still work fine without it (this package is only used at run-time). **On Debian/Ubuntu:** All of this be easily installed with apt-get: ```bash -sudo apt-get install libsdl2-dev libboost-system-dev libboost-filesystem-dev libboost-date-time-dev libboost-locale-dev libfreeimage-dev libfreetype6-dev libeigen3-dev libcurl4-openssl-dev libasound2-dev libgl1-mesa-dev +sudo apt-get install libsdl2-dev libboost-system-dev libboost-filesystem-dev libboost-date-time-dev libboost-locale-dev libfreeimage-dev libfreetype6-dev libeigen3-dev libcurl4-openssl-dev libasound2-dev libgl1-mesa-dev build-essential cmake fonts-droid ``` Then, generate and build the Makefile with CMake: @@ -59,21 +59,21 @@ Complete Raspberry Pi build instructions at [emulationstation.org](http://emulat [Boost](http://www.boost.org/users/download/) (you'll need to compile yourself or get the pre-compiled binaries) -[Eigen3](http://eigen.tuxfamily.org/index.php?title=Main_Page) +[Eigen3](http://eigen.tuxfamily.org/index.php?title=Main_Page) (header-only library) [FreeImage](http://downloads.sourceforge.net/freeimage/FreeImage3154Win32.zip) [FreeType2](http://download.savannah.gnu.org/releases/freetype/freetype-2.4.9.tar.bz2) (you'll need to compile) -[SDL2](http://www.libsdl.org/release/SDL2-devel-2.0.0-VC.zip) +[SDL2](http://www.libsdl.org/release/SDL2-devel-2.0.3-VC.zip) -[CURL](http://curl.haxx.se/download.html) (you'll need to compile or get the pre-compiled (DLL version)) +[cURL](http://curl.haxx.se/download.html) (you'll need to compile or get the pre-compiled DLL version) -(remember to copy necessary .DLLs into the same folder as the executable: FreeImage.dll, freetype6.dll, SDL2.dll, libcurl.dll, and zlib1.dll) +(Remember to copy necessary .DLLs into the same folder as the executable: probably FreeImage.dll, freetype6.dll, SDL2.dll, libcurl.dll, and zlib1.dll. Exact list depends on if you built your libraries in "static" mode or not.) [CMake](http://www.cmake.org/cmake/resources/software.html) (this is used for generating the Visual Studio project) -(If you don't know how to use CMake, here are some hints: run cmake-gui and point it at your EmulationStation folder. Point the "build" directory somewhere - I use EmulationStation/build. Click configure, choose "Visual Studio [year] Project", fill in red fields as they appear and keep clicking Configure, then click Generate.) +(If you don't know how to use CMake, here are some hints: run cmake-gui and point it at your EmulationStation folder. Point the "build" directory somewhere - I use EmulationStation/build. Click configure, choose "Visual Studio [year] Project", fill in red fields as they appear and keep clicking Configure (you may need to check "Advanced"), then click Generate.) Configuring @@ -109,7 +109,7 @@ You can use `--help` or `-h` to view a list of command-line options. Briefly out --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. +--debug - show the console window on Windows, do slightly more logging --windowed - run ES in a window, works best in conjunction with --resolution [w] [h]. --vsync [1/on or 0/off] - turn vsync on or off (default is on). --scrape - run the interactive command-line metadata scraper. diff --git a/es-app/CMakeLists.txt b/es-app/CMakeLists.txt index bac158bcf..ee7f82990 100644 --- a/es-app/CMakeLists.txt +++ b/es-app/CMakeLists.txt @@ -104,12 +104,12 @@ target_link_libraries(emulationstation ${COMMON_LIBRARIES} es-core) # special properties for Windows builds if(MSVC) - #show console in debug builds, but not in proper release builds - #Note that up to CMake 2.8.10 this feature is broken: http://public.kitware.com/Bug/view.php?id=12566 - set_target_properties(emulationstation PROPERTIES LINK_FLAGS_DEBUG "/SUBSYSTEM:CONSOLE") - set_target_properties(emulationstation PROPERTIES COMPILE_DEFINITIONS_DEBUG "_CONSOLE") - set_target_properties(emulationstation PROPERTIES LINK_FLAGS_RELWITHDEBINFO "/SUBSYSTEM:CONSOLE") - set_target_properties(emulationstation PROPERTIES COMPILE_DEFINITIONS_RELWITHDEBINFO "_CONSOLE") + # Always compile with the "WINDOWS" subsystem to avoid console window flashing at startup + # when --debug is not set (see es-core/src/main.cpp for explanation). + # The console will still be shown if launched with --debug. + # Note that up to CMake 2.8.10 this feature is broken: http://public.kitware.com/Bug/view.php?id=12566 + set_target_properties(emulationstation PROPERTIES LINK_FLAGS_DEBUG "/SUBSYSTEM:WINDOWS") + set_target_properties(emulationstation PROPERTIES LINK_FLAGS_RELWITHDEBINFO "/SUBSYSTEM:WINDOWS") set_target_properties(emulationstation PROPERTIES LINK_FLAGS_RELEASE "/SUBSYSTEM:WINDOWS") set_target_properties(emulationstation PROPERTIES LINK_FLAGS_MINSIZEREL "/SUBSYSTEM:WINDOWS") endif() diff --git a/es-app/src/main.cpp b/es-app/src/main.cpp index bc5b75761..febccf770 100644 --- a/es-app/src/main.cpp +++ b/es-app/src/main.cpp @@ -20,6 +20,10 @@ #include #include +#ifdef WIN32 +#include +#endif + namespace fs = boost::filesystem; bool scrape_cmdline = false; @@ -54,6 +58,7 @@ bool parseArgs(int argc, char* argv[], unsigned int* width, unsigned int* height }else if(strcmp(argv[i], "--debug") == 0) { Settings::getInstance()->setBool("Debug", true); + Settings::getInstance()->setBool("HideConsole", false); Log::setReportingLevel(LogDebug); }else if(strcmp(argv[i], "--windowed") == 0) { @@ -78,10 +83,10 @@ bool parseArgs(int argc, char* argv[], unsigned int* width, unsigned int* height "--ignore-gamelist ignore the gamelist (useful for troubleshooting)\n" "--draw-framerate display the framerate\n" "--no-exit don't show the exit option in the menu\n" - "--debug even more logging\n" + "--debug more logging, show console on Windows\n" "--scrape scrape using command line interface\n" "--windowed not fullscreen, should be used with --resolution\n" - "--vsync [1/on or 0/off] turn vsync on or off (default is on)\n" + "--vsync [1/on or 0/off] turn vsync on or off (default is on)\n" "--help, -h summon a sentient, angry tuba\n\n" "More information available in README.md.\n"; return false; //exit after printing help @@ -153,6 +158,39 @@ int main(int argc, char* argv[]) if(!parseArgs(argc, argv, &width, &height)) return 0; + // only show the console on Windows if HideConsole is false +#ifdef WIN32 + // MSVC has a "SubSystem" option, with two primary options: "WINDOWS" and "CONSOLE". + // In "WINDOWS" mode, no console is automatically created for us. This is good, + // because we can choose to only create the console window if the user explicitly + // asks for it, preventing it from flashing open and then closing. + // In "CONSOLE" mode, a console is always automatically created for us before we + // enter main. In this case, we can only hide the console after the fact, which + // will leave a brief flash. + // TL;DR: You should compile ES under the "WINDOWS" subsystem. + // I have no idea how this works with non-MSVC compilers. + if(!Settings::getInstance()->getBool("HideConsole")) + { + // we want to show the console + // if we're compiled in "CONSOLE" mode, this is already done. + // if we're compiled in "WINDOWS" mode, no console is created for us automatically; + // the user asked for one, so make one and then hook stdin/stdout/sterr up to it + if(AllocConsole()) // should only pass in "WINDOWS" mode + { + freopen("CONIN$", "r", stdin); + freopen("CONOUT$", "wb", stdout); + freopen("CONOUT$", "wb", stderr); + } + }else{ + // we want to hide the console + // if we're compiled with the "WINDOWS" subsystem, this is already done. + // if we're compiled with the "CONSOLE" subsystem, a console is already created; + // it'll flash open, but we hide it nearly immediately + if(GetConsoleWindow()) // should only pass in "CONSOLE" mode + ShowWindow(GetConsoleWindow(), SW_HIDE); + } +#endif + //if ~/.emulationstation doesn't exist and cannot be created, bail if(!verifyHomeFolderExists()) return 1; diff --git a/es-core/src/Settings.cpp b/es-core/src/Settings.cpp index be3d7fd62..60352d949 100644 --- a/es-core/src/Settings.cpp +++ b/es-core/src/Settings.cpp @@ -17,6 +17,7 @@ std::vector settings_dont_save = boost::assign::list_of ("ShowExit") ("Windowed") ("VSync") + ("HideConsole") ("IgnoreGamelist"); Settings::Settings() @@ -55,6 +56,7 @@ void Settings::setDefaults() mBoolMap["ShowHelpPrompts"] = true; mBoolMap["ScrapeRatings"] = true; mBoolMap["IgnoreGamelist"] = false; + mBoolMap["HideConsole"] = true; mBoolMap["QuickSystemSelect"] = true; mBoolMap["Debug"] = false;