#include "platform.h" #include #ifdef WIN32 #include #else #include #endif #include #include "Log.h" int runShutdownCommand() { #ifdef WIN32 // windows return system("shutdown -s -t 0"); #else // osx / linux return system("sudo shutdown -h now"); #endif } int runRestartCommand() { #ifdef WIN32 // windows return system("shutdown -r -t 0"); #else // osx / linux return system("sudo shutdown -r now"); #endif } int runSystemCommand(const std::string& cmd_utf8) { #ifdef WIN32 // on Windows we use _wsystem to support non-ASCII paths // which requires converting from utf8 to a wstring typedef std::codecvt_utf8 convert_type; std::wstring_convert converter; std::wstring wchar_str = converter.from_bytes(cmd_utf8); return _wsystem(wchar_str.c_str()); #else return system(cmd_utf8.c_str()); #endif } QuitMode quitMode = QuitMode::QUIT; int quitES(QuitMode mode) { quitMode = mode; SDL_Event *quit = new SDL_Event(); quit->type = SDL_QUIT; SDL_PushEvent(quit); return 0; } void touch(const std::string& filename) { #ifdef WIN32 FILE* fp = fopen(filename.c_str(), "ab+"); if (fp != NULL) fclose(fp); #else int fd = open(filename.c_str(), O_CREAT|O_WRONLY, 0644); if (fd >= 0) close(fd); #endif } 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; } }