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
This commit is contained in:
Jools Wills 2016-01-17 04:24:28 +00:00
parent 6f0b63b1bb
commit fe86459f99
4 changed files with 52 additions and 3 deletions

18
emulationstation.sh Executable file
View file

@ -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

View file

@ -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<TextComponent>(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));
});

View file

@ -1,7 +1,9 @@
#include "platform.h"
#include <stdlib.h>
#include <boost/filesystem.hpp>
#include <SDL.h>
#include <iostream>
#include <fcntl.h>
#ifdef WIN32
#include <codecvt>
@ -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);
}

View file

@ -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)
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);