2020-09-13 18:32:22 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-05-25 19:34:42 +00:00
|
|
|
//
|
2020-06-21 12:25:28 +00:00
|
|
|
// EmulationStation Desktop Edition, an emulator front-end
|
|
|
|
// with controller navigation and theming support.
|
2020-05-25 19:34:42 +00:00
|
|
|
//
|
2020-06-21 12:25:28 +00:00
|
|
|
// Originally created by Alec "Aloshi" Lofquist.
|
|
|
|
// http://www.aloshi.com
|
|
|
|
// Improved and extended by the RetroPie community.
|
|
|
|
// Desktop Edition fork by Leon Styhre.
|
2020-05-25 19:34:42 +00:00
|
|
|
//
|
2020-06-21 12:25:28 +00:00
|
|
|
// The line length limit is 100 characters and the indentations are 4 spaces.
|
2020-09-16 20:14:35 +00:00
|
|
|
// Line breaks are Unix-style (line feed only).
|
2020-05-26 16:34:33 +00:00
|
|
|
//
|
2020-06-21 12:25:28 +00:00
|
|
|
// main.cpp
|
2020-05-25 19:34:42 +00:00
|
|
|
//
|
2020-06-21 12:25:28 +00:00
|
|
|
// Main program loop. Interprets command-line arguments, checks for the
|
|
|
|
// home folder and es_settings.cfg configuration file, sets up the application
|
|
|
|
// environment and starts listening to SDL events.
|
2020-05-25 19:34:42 +00:00
|
|
|
//
|
2014-06-25 16:29:58 +00:00
|
|
|
|
|
|
|
#include "guis/GuiDetectDevice.h"
|
|
|
|
#include "guis/GuiMsgBox.h"
|
2020-08-15 08:12:19 +00:00
|
|
|
#include "guis/GuiComplexTextEditPopup.h"
|
2018-01-09 22:55:09 +00:00
|
|
|
#include "utils/FileSystemUtil.h"
|
2020-07-10 16:32:23 +00:00
|
|
|
#include "utils/StringUtil.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
#include "views/ViewController.h"
|
|
|
|
#include "CollectionSystemManager.h"
|
2014-06-25 16:29:58 +00:00
|
|
|
#include "EmulationStation.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
#include "InputManager.h"
|
|
|
|
#include "Log.h"
|
2018-02-09 17:23:58 +00:00
|
|
|
#include "MameNames.h"
|
2020-06-21 10:26:21 +00:00
|
|
|
#include "Platform.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
#include "Settings.h"
|
|
|
|
#include "SystemData.h"
|
2020-11-10 21:33:57 +00:00
|
|
|
#include "SystemScreensaver.h"
|
2020-06-26 16:03:55 +00:00
|
|
|
|
|
|
|
#include <SDL2/SDL_events.h>
|
|
|
|
#include <SDL2/SDL_main.h>
|
|
|
|
#include <SDL2/SDL_timer.h>
|
2020-08-23 14:15:06 +00:00
|
|
|
|
|
|
|
#if defined(_WIN64)
|
|
|
|
#include <cstring>
|
|
|
|
#include <windows.h>
|
2020-06-26 16:03:55 +00:00
|
|
|
#endif
|
|
|
|
|
2020-06-23 18:07:00 +00:00
|
|
|
#include <FreeImage.h>
|
2017-11-01 22:21:10 +00:00
|
|
|
#include <iostream>
|
2018-01-29 22:50:10 +00:00
|
|
|
#include <time.h>
|
2014-11-25 02:49:11 +00:00
|
|
|
|
2020-08-03 09:39:04 +00:00
|
|
|
bool forceInputConfig = false;
|
|
|
|
|
2020-08-15 08:12:19 +00:00
|
|
|
enum returnCode {
|
2020-08-23 19:27:01 +00:00
|
|
|
NO_LOADING_ERROR,
|
2020-08-15 08:12:19 +00:00
|
|
|
NO_SYSTEMS_FILE,
|
|
|
|
NO_ROMS
|
|
|
|
};
|
|
|
|
|
2020-08-23 15:04:30 +00:00
|
|
|
#if defined(_WIN64)
|
2020-08-23 19:27:01 +00:00
|
|
|
enum win64ConsoleType {
|
2020-07-03 18:23:51 +00:00
|
|
|
NO_CONSOLE,
|
|
|
|
PARENT_CONSOLE,
|
|
|
|
ALLOCATED_CONSOLE
|
|
|
|
};
|
|
|
|
|
|
|
|
// Console output for Windows. The handling of consoles is a mess on this operating system,
|
|
|
|
// and this is the best solution I could find. EmulationStation is built using the WINDOWS
|
|
|
|
// subsystem (using the -mwindows compiler flag). The idea is to attach to or allocate a new
|
|
|
|
// console as needed. However some console types such as the 'Git Bash' shell simply doesn't
|
|
|
|
// work properly. Windows thinks it's attaching to a console but is unable to redirect the
|
|
|
|
// standard input and output. Output also can't be redirected or piped by the user for any
|
|
|
|
// console type and PowerShell behaves quite strange. Still, it works well enough to be
|
|
|
|
// somewhat usable, at least for the moment. If the allocConsole argument is set to true
|
|
|
|
// and there is no console available, a new console window will be spawned.
|
2020-08-23 19:27:01 +00:00
|
|
|
win64ConsoleType outputToConsole(bool allocConsole)
|
2020-07-03 18:23:51 +00:00
|
|
|
{
|
|
|
|
HANDLE outputHandle = nullptr;
|
|
|
|
HWND consoleWindow = nullptr;
|
2020-08-23 19:27:01 +00:00
|
|
|
win64ConsoleType consoleType = NO_CONSOLE;
|
2020-07-03 18:23:51 +00:00
|
|
|
|
|
|
|
// Try to attach to a parent console process.
|
|
|
|
if (AttachConsole(ATTACH_PARENT_PROCESS))
|
|
|
|
outputHandle = GetStdHandle(STD_OUTPUT_HANDLE);
|
|
|
|
|
|
|
|
// If there is a parent console process, then attempt to retrieve its handle.
|
|
|
|
if (outputHandle != INVALID_HANDLE_VALUE && outputHandle != nullptr) {
|
|
|
|
consoleWindow = GetConsoleWindow();
|
2020-08-23 19:27:01 +00:00
|
|
|
consoleType = PARENT_CONSOLE;
|
2020-07-03 18:23:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// If we couldn't retrieve the handle, it means we need to allocate a new console window.
|
|
|
|
if (!consoleWindow && allocConsole) {
|
|
|
|
AllocConsole();
|
2020-08-23 19:27:01 +00:00
|
|
|
consoleType = ALLOCATED_CONSOLE;
|
2020-07-03 18:23:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// If we are attached to the parent console or we have opened a new console window,
|
|
|
|
// then redirect stdin, stdout and stderr accordingly.
|
2020-08-23 19:27:01 +00:00
|
|
|
if (consoleType == PARENT_CONSOLE || consoleType == ALLOCATED_CONSOLE) {
|
2020-07-03 18:23:51 +00:00
|
|
|
FILE* fp = nullptr;
|
|
|
|
freopen_s(&fp, "CONIN$", "rb", stdin);
|
|
|
|
freopen_s(&fp, "CONOUT$", "wb", stdout);
|
2020-11-30 19:42:16 +00:00
|
|
|
setvbuf(stdout, 0, _IONBF, 0);
|
2020-07-03 18:23:51 +00:00
|
|
|
freopen_s(&fp, "CONOUT$", "wb", stderr);
|
2020-11-30 19:42:16 +00:00
|
|
|
setvbuf(stderr, 0, _IONBF, 0);
|
2020-07-03 18:23:51 +00:00
|
|
|
|
|
|
|
// Point the standard streams to the console.
|
|
|
|
std::ios::sync_with_stdio(true);
|
|
|
|
|
|
|
|
// Clear the error state for each standard stream.
|
|
|
|
std::wcout.clear();
|
|
|
|
std::cout.clear();
|
|
|
|
std::wcerr.clear();
|
|
|
|
std::cerr.clear();
|
|
|
|
std::wcin.clear();
|
|
|
|
std::cin.clear();
|
|
|
|
|
|
|
|
std::cout << "\n";
|
|
|
|
}
|
|
|
|
|
2020-08-23 19:27:01 +00:00
|
|
|
return consoleType;
|
2020-07-03 18:23:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void closeConsole()
|
|
|
|
{
|
|
|
|
FILE* fp;
|
|
|
|
|
|
|
|
// Redirect stdin, stdout and stderr to NUL.
|
|
|
|
freopen_s(&fp, "NUL:", "r", stdin);
|
|
|
|
freopen_s(&fp, "NUL:", "w", stdout);
|
|
|
|
freopen_s(&fp, "NUL:", "w", stderr);
|
|
|
|
|
|
|
|
FreeConsole();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-12-01 17:42:27 +00:00
|
|
|
bool parseArgs(int argc, char* argv[])
|
2014-06-25 16:29:58 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
Utils::FileSystem::setExePath(argv[0]);
|
|
|
|
|
2020-08-23 15:04:30 +00:00
|
|
|
#if defined(_WIN64)
|
2020-07-03 18:23:51 +00:00
|
|
|
// Print any command line output to the console.
|
|
|
|
if (argc > 1)
|
2020-08-23 19:27:01 +00:00
|
|
|
win64ConsoleType consoleType = outputToConsole(false);
|
2020-07-03 18:23:51 +00:00
|
|
|
#endif
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// We need to process --home before any call to Settings::getInstance(),
|
|
|
|
// because settings are loaded from the home path.
|
|
|
|
for (int i = 1; i < argc; i++) {
|
|
|
|
if (strcmp(argv[i], "--home") == 0) {
|
|
|
|
if (i >= argc - 1) {
|
|
|
|
std::cerr << "Error: No home path supplied with \'--home'.\n";
|
|
|
|
return false;
|
|
|
|
}
|
2020-08-23 15:04:30 +00:00
|
|
|
#if defined(_WIN64)
|
2020-07-27 12:23:40 +00:00
|
|
|
if (!Utils::FileSystem::exists(argv[i + 1]) &&
|
|
|
|
(!Utils::FileSystem::driveExists(argv[i + 1]))) {
|
|
|
|
#else
|
2020-07-13 18:58:25 +00:00
|
|
|
if (!Utils::FileSystem::exists(argv[i + 1])) {
|
2020-07-27 12:23:40 +00:00
|
|
|
#endif
|
2020-05-25 19:34:42 +00:00
|
|
|
std::cerr << "Error: Home path \'" << argv[i + 1] << "\' does not exist.\n";
|
|
|
|
return false;
|
|
|
|
}
|
2020-07-13 18:58:25 +00:00
|
|
|
if (Utils::FileSystem::isRegularFile(argv[i + 1])) {
|
2020-05-25 19:34:42 +00:00
|
|
|
std::cerr << "Error: Home path \'" << argv[i + 1] <<
|
|
|
|
"\' is a file and not a directory.\n";
|
|
|
|
return false;
|
|
|
|
}
|
2020-06-21 12:25:28 +00:00
|
|
|
Utils::FileSystem::setHomePath(argv[i + 1]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-08-25 15:23:02 +00:00
|
|
|
|
2020-07-13 18:58:25 +00:00
|
|
|
for (int i = 1; i < argc; i++) {
|
2020-05-25 19:34:42 +00:00
|
|
|
// Skip past --home flag as we already processed it.
|
|
|
|
if (strcmp(argv[i], "--home") == 0) {
|
|
|
|
i++;
|
|
|
|
continue;
|
|
|
|
}
|
2020-06-21 12:25:28 +00:00
|
|
|
if (strcmp(argv[i], "--resolution") == 0) {
|
|
|
|
if (i >= argc - 2) {
|
|
|
|
std::cerr << "Error: Invalid resolution values supplied.\n";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int width = atoi(argv[i + 1]);
|
|
|
|
int height = atoi(argv[i + 2]);
|
|
|
|
i += 2; // skip the argument value
|
|
|
|
Settings::getInstance()->setInt("WindowWidth", width);
|
|
|
|
Settings::getInstance()->setInt("WindowHeight", height);
|
|
|
|
}
|
|
|
|
else if (strcmp(argv[i], "--screensize") == 0) {
|
|
|
|
if (i >= argc - 2) {
|
|
|
|
std::cerr << "Error: Invalid screensize values supplied.\n";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int width = atoi(argv[i + 1]);
|
|
|
|
int height = atoi(argv[i + 2]);
|
|
|
|
i += 2; // skip the argument value
|
|
|
|
Settings::getInstance()->setInt("ScreenWidth", width);
|
|
|
|
Settings::getInstance()->setInt("ScreenHeight", height);
|
|
|
|
}
|
|
|
|
else if (strcmp(argv[i], "--screenoffset") == 0) {
|
|
|
|
if (i >= argc - 2) {
|
|
|
|
std::cerr << "Error: Invalid screenoffset values supplied.\n";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int x = atoi(argv[i + 1]);
|
|
|
|
int y = atoi(argv[i + 2]);
|
|
|
|
i += 2; // skip the argument value
|
|
|
|
Settings::getInstance()->setInt("ScreenOffsetX", x);
|
|
|
|
Settings::getInstance()->setInt("ScreenOffsetY", y);
|
|
|
|
}
|
|
|
|
else if (strcmp(argv[i], "--screenrotate") == 0) {
|
|
|
|
if (i >= argc - 1) {
|
|
|
|
std::cerr << "Error: Invalid screenrotate value supplied.\n";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int rotate = atoi(argv[i + 1]);
|
|
|
|
++i; // skip the argument value
|
|
|
|
Settings::getInstance()->setInt("ScreenRotate", rotate);
|
|
|
|
}
|
|
|
|
else if (strcmp(argv[i], "--max-vram") == 0) {
|
2020-05-25 19:34:42 +00:00
|
|
|
if (i >= argc - 1) {
|
|
|
|
std::cerr << "Error: Invalid VRAM value supplied.\n";
|
2020-06-21 12:25:28 +00:00
|
|
|
return false;
|
2020-05-25 19:34:42 +00:00
|
|
|
}
|
2020-06-21 12:25:28 +00:00
|
|
|
int maxVRAM = atoi(argv[i + 1]);
|
|
|
|
Settings::getInstance()->setInt("MaxVRAM", maxVRAM);
|
2020-05-25 19:34:42 +00:00
|
|
|
++i; // skip the argument value
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
else if (strcmp(argv[i], "--gamelist-only") == 0) {
|
|
|
|
Settings::getInstance()->setBool("ParseGamelistOnly", true);
|
|
|
|
}
|
|
|
|
else if (strcmp(argv[i], "--ignore-gamelist") == 0) {
|
|
|
|
Settings::getInstance()->setBool("IgnoreGamelist", true);
|
|
|
|
}
|
|
|
|
else if (strcmp(argv[i], "--show-hidden-files") == 0) {
|
|
|
|
Settings::getInstance()->setBool("ShowHiddenFiles", true);
|
|
|
|
}
|
2020-07-26 20:19:29 +00:00
|
|
|
else if (strcmp(argv[i], "--show-hidden-games") == 0) {
|
|
|
|
Settings::getInstance()->setBool("ShowHiddenGames", true);
|
|
|
|
}
|
2020-06-21 12:25:28 +00:00
|
|
|
else if (strcmp(argv[i], "--no-splash") == 0) {
|
|
|
|
Settings::getInstance()->setBool("SplashScreen", false);
|
|
|
|
}
|
|
|
|
else if (strcmp(argv[i], "--debug") == 0) {
|
|
|
|
Settings::getInstance()->setBool("Debug", true);
|
|
|
|
Log::setReportingLevel(LogDebug);
|
|
|
|
}
|
2020-08-23 19:53:21 +00:00
|
|
|
// On Unix, enable settings for the fullscreen mode.
|
|
|
|
// On macOS and Windows only windowed mode is supported.
|
|
|
|
#if defined(__unix__)
|
2020-06-21 12:25:28 +00:00
|
|
|
else if (strcmp(argv[i], "--fullscreen-normal") == 0) {
|
|
|
|
Settings::getInstance()->setString("FullscreenMode", "normal");
|
|
|
|
}
|
|
|
|
else if (strcmp(argv[i], "--fullscreen-borderless") == 0) {
|
|
|
|
Settings::getInstance()->setString("FullscreenMode", "borderless");
|
|
|
|
}
|
|
|
|
else if (strcmp(argv[i], "--windowed") == 0) {
|
|
|
|
Settings::getInstance()->setBool("Windowed", true);
|
|
|
|
}
|
2020-07-18 11:21:44 +00:00
|
|
|
#endif
|
2020-06-21 12:25:28 +00:00
|
|
|
else if (strcmp(argv[i], "--vsync") == 0) {
|
|
|
|
bool vsync = (strcmp(argv[i + 1], "on") == 0 ||
|
|
|
|
strcmp(argv[i + 1], "1") == 0) ? true : false;
|
|
|
|
Settings::getInstance()->setBool("VSync", vsync);
|
|
|
|
i++; // Skip vsync value.
|
|
|
|
}
|
2020-08-08 13:14:33 +00:00
|
|
|
else if (strcmp(argv[i], "--gpu-statistics") == 0) {
|
2020-08-15 07:33:08 +00:00
|
|
|
Settings::getInstance()->setBool("DisplayGPUStatistics", "true");
|
2020-08-08 13:14:33 +00:00
|
|
|
}
|
2020-07-26 20:19:29 +00:00
|
|
|
else if (strcmp(argv[i], "--force-full") == 0) {
|
2020-07-27 10:11:30 +00:00
|
|
|
Settings::getInstance()->setString("UIMode", "full");
|
2020-12-17 22:45:29 +00:00
|
|
|
Settings::getInstance()->setBool("ForceFull", true);
|
2020-07-26 20:19:29 +00:00
|
|
|
}
|
2020-06-21 12:25:28 +00:00
|
|
|
else if (strcmp(argv[i], "--force-kiosk") == 0) {
|
|
|
|
Settings::getInstance()->setBool("ForceKiosk", true);
|
|
|
|
}
|
|
|
|
else if (strcmp(argv[i], "--force-kid") == 0) {
|
|
|
|
Settings::getInstance()->setBool("ForceKid", true);
|
|
|
|
}
|
2020-08-03 09:39:04 +00:00
|
|
|
else if (strcmp(argv[i], "--force-input-config") == 0) {
|
|
|
|
forceInputConfig = true;
|
|
|
|
}
|
2020-05-25 19:34:42 +00:00
|
|
|
else if (strcmp(argv[i], "--version") == 0 || strcmp(argv[i], "-v") == 0) {
|
2020-06-21 12:25:28 +00:00
|
|
|
std::cout <<
|
2020-05-25 19:34:42 +00:00
|
|
|
"EmulationStation Desktop Edition v" << PROGRAM_VERSION_STRING << "\n";
|
|
|
|
return false;
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
else if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-h") == 0) {
|
|
|
|
std::cout <<
|
2020-07-16 12:24:48 +00:00
|
|
|
"Usage: emulationstation [options]\n"
|
|
|
|
"EmulationStation Desktop Edition, Emulator Front-end\n\n"
|
2020-05-25 19:34:42 +00:00
|
|
|
"Options:\n"
|
2020-07-16 12:24:48 +00:00
|
|
|
" --resolution [width] [height] Try to force a particular resolution\n"
|
|
|
|
" --gamelist-only Skip automatic game ROM search, only read from gamelist.xml\n"
|
|
|
|
" --ignore-gamelist Ignore the gamelist files (useful for troubleshooting)\n"
|
2020-07-26 11:58:49 +00:00
|
|
|
" --show-hidden-files Show hidden files and folders\n"
|
2020-07-26 20:19:29 +00:00
|
|
|
" --show-hidden-games Show hidden games\n"
|
2020-07-16 12:24:48 +00:00
|
|
|
" --no-splash Don't show the splash screen\n"
|
|
|
|
" --debug Print debug information\n"
|
2020-08-23 19:53:21 +00:00
|
|
|
#if defined(__unix__)
|
2020-07-16 12:24:48 +00:00
|
|
|
" --windowed Windowed mode, should be combined with --resolution\n"
|
|
|
|
" --fullscreen-normal Normal fullscreen mode\n"
|
|
|
|
" --fullscreen-borderless Borderless fullscreen mode (always on top)\n"
|
2020-07-18 11:21:44 +00:00
|
|
|
#endif
|
2020-07-16 12:24:48 +00:00
|
|
|
" --vsync [1/on or 0/off] Turn vsync on or off (default is on)\n"
|
2020-08-08 13:14:33 +00:00
|
|
|
" --max-vram [size] Max VRAM to use (in mebibytes) before swapping\n"
|
2020-08-15 07:33:08 +00:00
|
|
|
" --gpu-statistics Display framerate and VRAM usage overlay\n"
|
2020-07-26 20:19:29 +00:00
|
|
|
" --force-full Force the UI mode to Full\n"
|
2020-07-16 12:24:48 +00:00
|
|
|
" --force-kid Force the UI mode to Kid\n"
|
|
|
|
" --force-kiosk Force the UI mode to Kiosk\n"
|
2020-08-03 09:39:04 +00:00
|
|
|
" --force-input-config Force configuration of input device\n"
|
2020-07-16 12:24:48 +00:00
|
|
|
" --home [path] Directory to use as home path\n"
|
|
|
|
" --version, -v Display version information\n"
|
|
|
|
" --help, -h Summon a sentient, angry tuba\n";
|
2020-06-21 12:25:28 +00:00
|
|
|
return false; // Exit after printing help.
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
std::string argv_unknown = argv[i];
|
|
|
|
std::cout << "Unknown option '" << argv_unknown << "'.\n";
|
|
|
|
std::cout << "Try 'emulationstation --help' for more information.\n";
|
|
|
|
return false; // Exit after printing message.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool verifyHomeFolderExists()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
// Make sure the config directory exists.
|
|
|
|
std::string home = Utils::FileSystem::getHomePath();
|
|
|
|
std::string configDir = home + "/.emulationstation";
|
|
|
|
if (!Utils::FileSystem::exists(configDir)) {
|
|
|
|
std::cout << "Creating config directory \"" << configDir << "\"\n";
|
|
|
|
Utils::FileSystem::createDirectory(configDir);
|
|
|
|
if (!Utils::FileSystem::exists(configDir)) {
|
|
|
|
std::cerr << "Config directory could not be created!\n";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
2020-08-23 19:27:01 +00:00
|
|
|
// Returns NO_LOADING_ERROR if everything is OK.
|
2020-06-18 17:49:47 +00:00
|
|
|
// Otherwise returns either NO_SYSTEMS_FILE or NO_ROMS.
|
2020-08-15 08:12:19 +00:00
|
|
|
returnCode loadSystemConfigFile(std::string& errorMsg)
|
2014-06-25 16:29:58 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
if (!SystemData::loadConfig()) {
|
2020-10-19 15:28:20 +00:00
|
|
|
LOG(LogError) << "Could not parse systems configuration file";
|
2020-06-21 12:25:28 +00:00
|
|
|
errorMsg = "COULDN'T FIND THE SYSTEMS CONFIGURATION FILE.\n"
|
2020-07-09 17:26:48 +00:00
|
|
|
"ATTEMPTED TO COPY A TEMPLATE ES_SYSTEMS.CFG FILE\n"
|
|
|
|
"FROM THE EMULATIONSTATION RESOURCES DIRECTORY,\n"
|
|
|
|
"BUT THIS FAILED. HAS EMULATIONSTATION BEEN PROPERLY\n"
|
|
|
|
"INSTALLED AND DO YOU HAVE WRITE PERMISSIONS TO \n"
|
|
|
|
"YOUR HOME DIRECTORY?";
|
2020-08-15 08:12:19 +00:00
|
|
|
return NO_SYSTEMS_FILE;
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
|
2020-07-10 16:32:23 +00:00
|
|
|
if (SystemData::sSystemVector.size() == 0) {
|
2020-07-26 21:30:45 +00:00
|
|
|
LOG(LogError) << "No systems found, does at least one system have a game present? "
|
2020-10-19 15:28:20 +00:00
|
|
|
"(Check that the file extensions are supported)";
|
2020-07-09 17:26:48 +00:00
|
|
|
errorMsg = "THE SYSTEMS CONFIGURATION FILE EXISTS, BUT NO\n"
|
2020-08-15 08:12:19 +00:00
|
|
|
"GAME FILES WERE FOUND. EITHER PLACE YOUR GAMES\n"
|
|
|
|
"IN THE CURRENTLY CONFIGURED ROM DIRECTORY OR\n"
|
|
|
|
"CHANGE IT USING THE BUTTON BELOW. MAKE SURE\n"
|
|
|
|
"THAT YOUR FILE EXTENSIONS AND SYSTEMS DIRECTORY\n"
|
|
|
|
"NAMES ARE SUPPORTED BY EMULATIONSTATION-DE.\n"
|
2020-06-21 12:25:28 +00:00
|
|
|
"THIS IS THE CURRENTLY CONFIGURED ROM DIRECTORY:\n";
|
2020-08-23 15:04:30 +00:00
|
|
|
#if defined(_WIN64)
|
2020-07-10 16:32:23 +00:00
|
|
|
errorMsg += Utils::String::replace(FileData::getROMDirectory(), "/", "\\");
|
|
|
|
#else
|
2020-06-21 12:25:28 +00:00
|
|
|
errorMsg += FileData::getROMDirectory();
|
2020-07-10 16:32:23 +00:00
|
|
|
#endif
|
|
|
|
|
2020-08-15 08:12:19 +00:00
|
|
|
return NO_ROMS;
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
|
2020-08-23 19:27:01 +00:00
|
|
|
return NO_LOADING_ERROR;
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
2020-05-25 19:34:42 +00:00
|
|
|
// Called on exit, assuming we get far enough to have the log initialized.
|
2014-06-25 16:29:58 +00:00
|
|
|
void onExit()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
Log::close();
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
2020-10-18 10:45:19 +00:00
|
|
|
const auto applicationStartTime = std::chrono::system_clock::now();
|
2016-12-20 20:25:35 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
std::locale::global(std::locale("C"));
|
2014-10-18 21:31:10 +00:00
|
|
|
|
2020-07-03 18:23:51 +00:00
|
|
|
if (!parseArgs(argc, argv)) {
|
2020-08-23 15:04:30 +00:00
|
|
|
#if defined(_WIN64)
|
2020-07-03 18:23:51 +00:00
|
|
|
closeConsole();
|
|
|
|
#endif
|
2020-06-21 12:25:28 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2020-07-03 18:23:51 +00:00
|
|
|
|
2020-08-23 15:04:30 +00:00
|
|
|
#if defined(_WIN64)
|
2020-07-03 18:23:51 +00:00
|
|
|
// Send debug output to the console..
|
|
|
|
if (Settings::getInstance()->getBool("Debug"))
|
|
|
|
outputToConsole(true);
|
|
|
|
#endif
|
2014-11-25 02:49:11 +00:00
|
|
|
|
2020-08-23 15:04:30 +00:00
|
|
|
#if defined(_WIN64)
|
2020-07-18 11:21:44 +00:00
|
|
|
// Hide taskbar if the setting for this is enabled.
|
|
|
|
bool taskbarStateChanged = false;
|
|
|
|
unsigned int taskbarState;
|
|
|
|
|
|
|
|
if (Settings::getInstance()->getBool("HideTaskbar")) {
|
|
|
|
taskbarStateChanged = true;
|
|
|
|
taskbarState = getTaskbarState();
|
|
|
|
hideTaskbar();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// Call this ONLY when linking with FreeImage as a static library.
|
2020-08-23 15:04:30 +00:00
|
|
|
#if defined(FREEIMAGE_LIB)
|
2020-06-21 12:25:28 +00:00
|
|
|
FreeImage_Initialise();
|
2020-07-03 18:23:51 +00:00
|
|
|
#endif
|
2017-10-17 20:05:12 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// If ~/.emulationstation doesn't exist and cannot be created, bail.
|
|
|
|
if (!verifyHomeFolderExists())
|
|
|
|
return 1;
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// Start the logger.
|
|
|
|
Log::init();
|
|
|
|
Log::open();
|
2020-09-13 18:07:02 +00:00
|
|
|
LOG(LogInfo) << "EmulationStation Desktop Edition v" << PROGRAM_VERSION_STRING <<
|
2020-05-25 19:34:42 +00:00
|
|
|
", built " << PROGRAM_BUILT_STRING;
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// Always close the log on exit.
|
|
|
|
atexit(&onExit);
|
|
|
|
|
2020-07-11 08:10:07 +00:00
|
|
|
// Check if the configuration file exists, and if not, create it.
|
|
|
|
// This should only happen on first application startup.
|
|
|
|
if (!Utils::FileSystem::exists(Utils::FileSystem::getHomePath() +
|
|
|
|
"/.emulationstation/es_settings.cfg")) {
|
|
|
|
LOG(LogInfo) << "Settings file es_settings.cfg does not exist, creating it...";
|
|
|
|
Settings::getInstance()->saveFile();
|
|
|
|
}
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
Window window;
|
2020-11-10 21:18:20 +00:00
|
|
|
SystemScreensaver screensaver(&window);
|
2020-06-21 12:25:28 +00:00
|
|
|
ViewController::init(&window);
|
|
|
|
CollectionSystemManager::init(&window);
|
|
|
|
window.pushGui(ViewController::get());
|
|
|
|
|
|
|
|
bool splashScreen = Settings::getInstance()->getBool("SplashScreen");
|
|
|
|
bool splashScreenProgress = Settings::getInstance()->getBool("SplashScreenProgress");
|
2020-10-11 16:57:37 +00:00
|
|
|
SDL_Event event {};
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
if (!window.init()) {
|
2020-10-19 15:28:20 +00:00
|
|
|
LOG(LogError) << "Window failed to initialize";
|
2020-06-21 12:25:28 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2020-07-08 15:01:47 +00:00
|
|
|
InputManager::getInstance()->parseEvent(event, &window);
|
|
|
|
if (event.type == SDL_QUIT)
|
|
|
|
return 1;
|
|
|
|
|
2020-10-19 15:28:20 +00:00
|
|
|
MameNames::init();
|
2020-07-08 15:01:47 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
if (splashScreen) {
|
|
|
|
std::string progressText = "Loading...";
|
|
|
|
if (splashScreenProgress)
|
|
|
|
progressText = "Loading system config...";
|
|
|
|
window.renderLoadingScreen(progressText);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string errorMsg;
|
2020-08-15 08:12:19 +00:00
|
|
|
returnCode returnCodeValue = loadSystemConfigFile(errorMsg);
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2020-08-15 08:12:19 +00:00
|
|
|
if (returnCodeValue) {
|
2020-06-21 12:25:28 +00:00
|
|
|
// Something went terribly wrong.
|
2020-07-08 15:01:47 +00:00
|
|
|
if (errorMsg == "") {
|
2020-10-19 15:28:20 +00:00
|
|
|
LOG(LogError) << "Unknown error occured while parsing systems configuration file";
|
2020-06-21 12:25:28 +00:00
|
|
|
Renderer::deinit();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2020-08-15 08:12:19 +00:00
|
|
|
// If there was an issue with installing the es_systems.cfg file from the
|
|
|
|
// template directory, then display an error message and let the user quit.
|
|
|
|
// If there are no game files found, give the option to the user to quit or
|
|
|
|
// to configure a different ROM directory. The application will need to be
|
|
|
|
// restarted though, to activate any new ROM directory setting.
|
|
|
|
if (returnCodeValue == NO_SYSTEMS_FILE) {
|
2020-11-30 19:19:29 +00:00
|
|
|
window.pushGui(new GuiMsgBox(&window, HelpStyle(),
|
2020-08-15 08:12:19 +00:00
|
|
|
errorMsg.c_str(),
|
|
|
|
"QUIT", [] {
|
2020-10-17 12:32:08 +00:00
|
|
|
SDL_Event quit;
|
|
|
|
quit.type = SDL_QUIT;
|
|
|
|
SDL_PushEvent(&quit);
|
2020-08-15 08:12:19 +00:00
|
|
|
}, "", nullptr, "", nullptr, true));
|
|
|
|
}
|
|
|
|
else if (returnCodeValue == NO_ROMS) {
|
|
|
|
auto updateVal = [](const std::string& newROMDirectory) {
|
|
|
|
Settings::getInstance()->setString("ROMDirectory", newROMDirectory);
|
|
|
|
Settings::getInstance()->saveFile();
|
2020-10-17 12:32:08 +00:00
|
|
|
SDL_Event quit;
|
|
|
|
quit.type = SDL_QUIT;
|
|
|
|
SDL_PushEvent(&quit);
|
2020-08-15 08:12:19 +00:00
|
|
|
};
|
|
|
|
|
2020-11-30 19:19:29 +00:00
|
|
|
window.pushGui(new GuiMsgBox(&window, HelpStyle(), errorMsg.c_str(),
|
|
|
|
"CHANGE ROM DIRECTORY", [&window, updateVal] {
|
2020-08-15 08:12:19 +00:00
|
|
|
std::string currentROMDirectory;
|
2020-08-23 15:04:30 +00:00
|
|
|
#if defined(_WIN64)
|
2020-08-15 08:12:19 +00:00
|
|
|
currentROMDirectory =
|
|
|
|
Utils::String::replace(FileData::getROMDirectory(), "/", "\\");
|
|
|
|
#else
|
|
|
|
currentROMDirectory = FileData::getROMDirectory();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
window.pushGui(new GuiComplexTextEditPopup(
|
|
|
|
&window,
|
2020-11-30 19:19:29 +00:00
|
|
|
HelpStyle(),
|
2020-08-15 08:12:19 +00:00
|
|
|
"ENTER ROM DIRECTORY",
|
|
|
|
"Currently configured directory:",
|
|
|
|
currentROMDirectory,
|
|
|
|
currentROMDirectory,
|
|
|
|
updateVal,
|
|
|
|
false,
|
|
|
|
"SAVE AND QUIT",
|
|
|
|
"SAVE CHANGES?",
|
|
|
|
"LOAD CURRENT",
|
|
|
|
"LOAD CURRENTLY CONFIGURED VALUE",
|
|
|
|
"CLEAR",
|
|
|
|
"CLEAR (LEAVE BLANK TO RESET TO DEFAULT DIRECTORY)",
|
|
|
|
true));
|
|
|
|
},
|
2020-06-21 12:25:28 +00:00
|
|
|
"QUIT", [] {
|
2020-10-17 12:32:08 +00:00
|
|
|
SDL_Event quit;
|
|
|
|
quit.type = SDL_QUIT;
|
|
|
|
SDL_PushEvent(&quit);
|
2020-08-15 08:12:19 +00:00
|
|
|
}, "", nullptr, true));
|
|
|
|
}
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Dont generate joystick events while we're loading.
|
|
|
|
// (Hopefully fixes "automatically started emulator" bug.)
|
|
|
|
SDL_JoystickEventState(SDL_DISABLE);
|
|
|
|
|
|
|
|
// Preload what we can right away instead of waiting for the user to select it.
|
|
|
|
// This makes for no delays when accessing content, but a longer startup time.
|
|
|
|
ViewController::get()->preload();
|
|
|
|
|
|
|
|
if (splashScreen && splashScreenProgress)
|
|
|
|
window.renderLoadingScreen("Done.");
|
|
|
|
|
2020-08-03 09:39:04 +00:00
|
|
|
// Choose which GUI to open depending on if an input configuration already exists and
|
|
|
|
// whether the flag to force the input configuration was passed from the command line.
|
2020-06-21 12:25:28 +00:00
|
|
|
if (errorMsg == "") {
|
2020-08-03 09:39:04 +00:00
|
|
|
if (!forceInputConfig && Utils::FileSystem::exists(InputManager::getConfigPath()) &&
|
2020-06-21 12:25:28 +00:00
|
|
|
InputManager::getInstance()->getNumConfiguredDevices() > 0) {
|
|
|
|
ViewController::get()->goToStart();
|
|
|
|
}
|
2020-08-03 09:39:04 +00:00
|
|
|
else if (forceInputConfig) {
|
|
|
|
window.pushGui(new GuiDetectDevice(&window, true, true, [] {
|
2020-06-21 12:25:28 +00:00
|
|
|
ViewController::get()->goToStart(); }));
|
|
|
|
}
|
2020-08-03 09:39:04 +00:00
|
|
|
else {
|
|
|
|
if (InputManager::getInstance()->getNumJoysticks() > 0)
|
|
|
|
window.pushGui(new GuiDetectDevice(&window, true, false, [] {
|
|
|
|
ViewController::get()->goToStart(); }));
|
|
|
|
else
|
|
|
|
ViewController::get()->goToStart();
|
|
|
|
}
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
|
2020-08-18 15:48:21 +00:00
|
|
|
// Check if the media directory exists, otherwise log an information entry.
|
2020-07-11 08:10:07 +00:00
|
|
|
if (!Utils::FileSystem::isDirectory(FileData::getMediaDirectory()) ||
|
|
|
|
Utils::FileSystem::isSymlink(FileData::getMediaDirectory())) {
|
2020-08-18 15:48:21 +00:00
|
|
|
LOG(LogInfo) << "Game media directory does not exist "
|
2020-07-11 08:10:07 +00:00
|
|
|
"(or is not a directory or a symlink):";
|
2020-08-18 15:48:21 +00:00
|
|
|
LOG(LogInfo) << FileData::getMediaDirectory();
|
2020-07-11 08:10:07 +00:00
|
|
|
}
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// Generate joystick events since we're done loading.
|
|
|
|
SDL_JoystickEventState(SDL_ENABLE);
|
|
|
|
|
|
|
|
int lastTime = SDL_GetTicks();
|
|
|
|
int ps_time = SDL_GetTicks();
|
2020-10-18 10:45:19 +00:00
|
|
|
const auto applicationEndTime = std::chrono::system_clock::now();
|
|
|
|
|
|
|
|
LOG(LogDebug) << "Application startup time: " <<
|
|
|
|
std::chrono::duration_cast<std::chrono::milliseconds>
|
|
|
|
(applicationEndTime - applicationStartTime).count() << " ms";
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
bool running = true;
|
|
|
|
|
|
|
|
while (running) {
|
|
|
|
SDL_Event event;
|
|
|
|
|
2020-12-16 16:57:10 +00:00
|
|
|
if (SDL_PollEvent(&event)) {
|
2020-06-21 12:25:28 +00:00
|
|
|
do {
|
|
|
|
InputManager::getInstance()->parseEvent(event, &window);
|
|
|
|
|
|
|
|
if (event.type == SDL_QUIT)
|
|
|
|
running = false;
|
|
|
|
}
|
|
|
|
while (SDL_PollEvent(&event));
|
|
|
|
|
|
|
|
// Reset counter.
|
|
|
|
ps_time = SDL_GetTicks();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (window.isSleeping()) {
|
|
|
|
lastTime = SDL_GetTicks();
|
|
|
|
// This doesn't need to be accurate, we're just giving up
|
|
|
|
// our CPU time until something wakes us up.
|
|
|
|
continue;
|
|
|
|
SDL_Delay(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int curTime = SDL_GetTicks();
|
|
|
|
int deltaTime = curTime - lastTime;
|
|
|
|
lastTime = curTime;
|
|
|
|
|
|
|
|
// Cap deltaTime if it ever goes negative.
|
|
|
|
if (deltaTime < 0)
|
|
|
|
deltaTime = 1000;
|
|
|
|
|
|
|
|
window.update(deltaTime);
|
|
|
|
window.render();
|
|
|
|
Renderer::swapBuffers();
|
|
|
|
|
|
|
|
Log::flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
while (window.peekGui() != ViewController::get())
|
|
|
|
delete window.peekGui();
|
|
|
|
window.deinit();
|
|
|
|
|
|
|
|
MameNames::deinit();
|
|
|
|
CollectionSystemManager::deinit();
|
|
|
|
SystemData::deleteSystems();
|
|
|
|
|
|
|
|
// Call this ONLY when linking with FreeImage as a static library.
|
2020-08-23 15:04:30 +00:00
|
|
|
#if defined(FREEIMAGE_LIB)
|
2020-06-21 12:25:28 +00:00
|
|
|
FreeImage_DeInitialise();
|
2020-07-03 18:23:51 +00:00
|
|
|
#endif
|
2017-10-17 20:05:12 +00:00
|
|
|
|
2020-08-23 15:04:30 +00:00
|
|
|
#if defined(_WIN64)
|
2020-07-18 11:21:44 +00:00
|
|
|
// If the taskbar state was changed (taskbar was hidden), then revert it.
|
|
|
|
if (taskbarStateChanged)
|
|
|
|
revertTaskbarState(taskbarState);
|
|
|
|
#endif
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
processQuitMode();
|
2019-08-14 23:50:23 +00:00
|
|
|
|
2020-10-19 15:28:20 +00:00
|
|
|
LOG(LogInfo) << "EmulationStation cleanly shutting down";
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-08-23 15:04:30 +00:00
|
|
|
#if defined(_WIN64)
|
2020-07-03 18:23:51 +00:00
|
|
|
closeConsole();
|
|
|
|
#endif
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
return 0;
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|