From fe86459f9919fbc53dcad313a7c470b675eea1cb Mon Sep 17 00:00:00 2001 From: Jools Wills Date: Sun, 17 Jan 2016 04:24:28 +0000 Subject: [PATCH] don't call shutdown from ES directly - which causes it to not save the gameslists on exit. Instead create files /tmp/es-restart /tmp/es-sysrestart /tmp/es-shutdown to decide what we want to do. there is an emulationstation.sh launch script to handle this --- emulationstation.sh | 18 ++++++++++++++++++ es-app/src/guis/GuiMenu.cpp | 15 +++++++++++++-- es-core/src/platform.cpp | 18 ++++++++++++++++++ es-core/src/platform.h | 4 +++- 4 files changed, 52 insertions(+), 3 deletions(-) create mode 100755 emulationstation.sh diff --git a/emulationstation.sh b/emulationstation.sh new file mode 100755 index 000000000..cc48aed67 --- /dev/null +++ b/emulationstation.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +while true; do + rm -f /tmp/es-restart /tmp/es-sysrestart /tmp/es-shutdown + ./emulationstation "$@" + [ -f /tmp/es-restart ] && continue + if [ -f /tmp/es-sysrestart ]; then + rm -f /tmp/es-sysrestart + sudo reboot + break + fi + if [ -f /tmp/es-shutdown ]; then + rm -f /tmp/es-shutdown + sudo poweroff + break + fi + break +done diff --git a/es-app/src/guis/GuiMenu.cpp b/es-app/src/guis/GuiMenu.cpp index 417d38224..8478d98eb 100644 --- a/es-app/src/guis/GuiMenu.cpp +++ b/es-app/src/guis/GuiMenu.cpp @@ -177,10 +177,21 @@ GuiMenu::GuiMenu(Window* window) : GuiComponent(window), mMenu(window, "MAIN MEN Window* window = mWindow; ComponentListRow row; + row.makeAcceptInputHandler([window] { + window->pushGui(new GuiMsgBox(window, "REALLY RESTART?", "YES", + [] { + if(quitES("/tmp/es-restart") != 0) + LOG(LogWarning) << "Restart terminated with non-zero result!"; + }, "NO", nullptr)); + }); + row.addElement(std::make_shared(window, "RESTART EMULATIONSTATION", Font::get(FONT_SIZE_MEDIUM), 0x777777FF), true); + s->addRow(row); + + row.elements.clear(); row.makeAcceptInputHandler([window] { window->pushGui(new GuiMsgBox(window, "REALLY RESTART?", "YES", [] { - if(runRestartCommand() != 0) + if(quitES("/tmp/es-sysrestart") != 0) LOG(LogWarning) << "Restart terminated with non-zero result!"; }, "NO", nullptr)); }); @@ -191,7 +202,7 @@ GuiMenu::GuiMenu(Window* window) : GuiComponent(window), mMenu(window, "MAIN MEN row.makeAcceptInputHandler([window] { window->pushGui(new GuiMsgBox(window, "REALLY SHUTDOWN?", "YES", [] { - if(runShutdownCommand() != 0) + if(quitES("/tmp/es-shutdown") != 0) LOG(LogWarning) << "Shutdown terminated with non-zero result!"; }, "NO", nullptr)); }); diff --git a/es-core/src/platform.cpp b/es-core/src/platform.cpp index e1663a5f9..31127a9ca 100644 --- a/es-core/src/platform.cpp +++ b/es-core/src/platform.cpp @@ -1,7 +1,9 @@ #include "platform.h" #include #include +#include #include +#include #ifdef WIN32 #include @@ -69,4 +71,20 @@ int runSystemCommand(const std::string& cmd_utf8) #else return system(cmd_utf8.c_str()); #endif +} + +int quitES(const std::string& filename) +{ + touch(filename); + SDL_Event* quit = new SDL_Event(); + quit->type = SDL_QUIT; + SDL_PushEvent(quit); + return 0; +} + +void touch(const std::string& filename) +{ + int fd = open(filename.c_str(), O_CREAT|O_WRONLY, 0644); + if (fd >= 0) + close(fd); } \ No newline at end of file diff --git a/es-core/src/platform.h b/es-core/src/platform.h index a0571b32a..0760b565c 100644 --- a/es-core/src/platform.h +++ b/es-core/src/platform.h @@ -21,4 +21,6 @@ std::string getHomePath(); int runShutdownCommand(); // shut down the system (returns 0 if successful) int runRestartCommand(); // restart the system (returns 0 if successful) -int runSystemCommand(const std::string& cmd_utf8); // run a utf-8 encoded in the shell (requires wstring conversion on Windows) \ No newline at end of file +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);