diff --git a/es-app/src/guis/GuiMenu.cpp b/es-app/src/guis/GuiMenu.cpp index 59d8ae415..800a4918a 100644 --- a/es-app/src/guis/GuiMenu.cpp +++ b/es-app/src/guis/GuiMenu.cpp @@ -476,7 +476,7 @@ void GuiMenu::openQuitMenu() window->pushGui(new GuiMsgBox(window, "REALLY RESTART?", "YES", [] { Scripting::fireEvent("quit"); - if(quitES("/tmp/es-restart") != 0) + if(quitES(QuitMode::RESTART) != 0) LOG(LogWarning) << "Restart terminated with non-zero result!"; }, "NO", nullptr)); }); @@ -492,7 +492,7 @@ void GuiMenu::openQuitMenu() window->pushGui(new GuiMsgBox(window, "REALLY QUIT?", "YES", [] { Scripting::fireEvent("quit"); - quitES(""); + quitES(); }, "NO", nullptr)); }); row.addElement(std::make_shared(window, "QUIT EMULATIONSTATION", Font::get(FONT_SIZE_MEDIUM), 0x777777FF), true); @@ -505,7 +505,7 @@ void GuiMenu::openQuitMenu() [] { Scripting::fireEvent("quit", "reboot"); Scripting::fireEvent("reboot"); - if (quitES("/tmp/es-sysrestart") != 0) + if (quitES(QuitMode::REBOOT) != 0) LOG(LogWarning) << "Restart terminated with non-zero result!"; }, "NO", nullptr)); }); @@ -518,7 +518,7 @@ void GuiMenu::openQuitMenu() [] { Scripting::fireEvent("quit", "shutdown"); Scripting::fireEvent("shutdown"); - if (quitES("/tmp/es-shutdown") != 0) + if (quitES(QuitMode::SHUTDOWN) != 0) LOG(LogWarning) << "Shutdown terminated with non-zero result!"; }, "NO", nullptr)); }); diff --git a/es-app/src/main.cpp b/es-app/src/main.cpp index 6c1fe80ef..d25e910bc 100644 --- a/es-app/src/main.cpp +++ b/es-app/src/main.cpp @@ -440,6 +440,8 @@ int main(int argc, char* argv[]) FreeImage_DeInitialise(); #endif + processQuitMode(); + LOG(LogInfo) << "EmulationStation cleanly shutting down."; return 0; diff --git a/es-core/src/platform.cpp b/es-core/src/platform.cpp index 81722a549..d3b87fb27 100644 --- a/es-core/src/platform.cpp +++ b/es-core/src/platform.cpp @@ -8,6 +8,8 @@ #endif #include +#include "Log.h" + int runShutdownCommand() { #ifdef WIN32 // windows @@ -40,11 +42,13 @@ int runSystemCommand(const std::string& cmd_utf8) #endif } -int quitES(const std::string& filename) +QuitMode quitMode = QuitMode::QUIT; + +int quitES(QuitMode mode) { - if (!filename.empty()) - touch(filename); - SDL_Event* quit = new SDL_Event(); + quitMode = mode; + + SDL_Event *quit = new SDL_Event(); quit->type = SDL_QUIT; SDL_PushEvent(quit); return 0; @@ -61,4 +65,25 @@ void touch(const std::string& filename) if (fd >= 0) close(fd); #endif -} \ No newline at end of file +} + +void processQuitMode() +{ + switch (quitMode) + { + case QuitMode::RESTART: + LOG(LogInfo) << "Restarting EmulationStation"; + touch("/tmp/es-restart"); + break; + case QuitMode::REBOOT: + LOG(LogInfo) << "Rebooting system"; + touch("/tmp/es-sysrestart"); + runRestartCommand(); + break; + case QuitMode::SHUTDOWN: + LOG(LogInfo) << "Shutting system down"; + touch("/tmp/es-shutdown"); + runShutdownCommand(); + break; + } +} diff --git a/es-core/src/platform.h b/es-core/src/platform.h index 7ffaf5d31..7c09d8e37 100644 --- a/es-core/src/platform.h +++ b/es-core/src/platform.h @@ -21,10 +21,16 @@ #define GLHEADER #endif -int runShutdownCommand(); // shut down the system (returns 0 if successful) -int runRestartCommand(); // restart the system (returns 0 if successful) +enum QuitMode +{ + QUIT = 0, + RESTART = 1, + SHUTDOWN = 2, + REBOOT = 3 +}; + int runSystemCommand(const std::string& cmd_utf8); // run a utf-8 encoded in the shell (requires wstring conversion on Windows) -int quitES(const std::string& filename); -void touch(const std::string& filename); +int quitES(QuitMode mode = QuitMode::QUIT); +void processQuitMode(); #endif // ES_CORE_PLATFORM_H