Merge pull request #586 from fabricecaruso72/fixed-shutdown

Fix shutdown on Windows & process shutdown commands after main loop is  breaked
This commit is contained in:
Tomas Jakobsson 2019-08-20 19:56:11 +02:00 committed by GitHub
commit 6d82c5e6c8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 46 additions and 13 deletions

View file

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

View file

@ -440,6 +440,8 @@ int main(int argc, char* argv[])
FreeImage_DeInitialise();
#endif
processQuitMode();
LOG(LogInfo) << "EmulationStation cleanly shutting down.";
return 0;

View file

@ -8,6 +8,8 @@
#endif
#include <fcntl.h>
#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
}
}
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;
}
}

View file

@ -21,10 +21,16 @@
#define GLHEADER <SDL_opengl.h>
#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