mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-11-25 23:55:38 +00:00
Fix shutdown on Windows + process shutdown commands after main loop
This commit is contained in:
parent
e6660475e3
commit
f47fb048d5
|
@ -476,7 +476,7 @@ void GuiMenu::openQuitMenu()
|
||||||
window->pushGui(new GuiMsgBox(window, "REALLY RESTART?", "YES",
|
window->pushGui(new GuiMsgBox(window, "REALLY RESTART?", "YES",
|
||||||
[] {
|
[] {
|
||||||
Scripting::fireEvent("quit");
|
Scripting::fireEvent("quit");
|
||||||
if(quitES("/tmp/es-restart") != 0)
|
if(quitES(QuitMode::RESTART) != 0)
|
||||||
LOG(LogWarning) << "Restart terminated with non-zero result!";
|
LOG(LogWarning) << "Restart terminated with non-zero result!";
|
||||||
}, "NO", nullptr));
|
}, "NO", nullptr));
|
||||||
});
|
});
|
||||||
|
@ -492,7 +492,7 @@ void GuiMenu::openQuitMenu()
|
||||||
window->pushGui(new GuiMsgBox(window, "REALLY QUIT?", "YES",
|
window->pushGui(new GuiMsgBox(window, "REALLY QUIT?", "YES",
|
||||||
[] {
|
[] {
|
||||||
Scripting::fireEvent("quit");
|
Scripting::fireEvent("quit");
|
||||||
quitES("");
|
quitES();
|
||||||
}, "NO", nullptr));
|
}, "NO", nullptr));
|
||||||
});
|
});
|
||||||
row.addElement(std::make_shared<TextComponent>(window, "QUIT EMULATIONSTATION", Font::get(FONT_SIZE_MEDIUM), 0x777777FF), true);
|
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("quit", "reboot");
|
||||||
Scripting::fireEvent("reboot");
|
Scripting::fireEvent("reboot");
|
||||||
if (quitES("/tmp/es-sysrestart") != 0)
|
if (quitES(QuitMode::REBOOT) != 0)
|
||||||
LOG(LogWarning) << "Restart terminated with non-zero result!";
|
LOG(LogWarning) << "Restart terminated with non-zero result!";
|
||||||
}, "NO", nullptr));
|
}, "NO", nullptr));
|
||||||
});
|
});
|
||||||
|
@ -518,7 +518,7 @@ void GuiMenu::openQuitMenu()
|
||||||
[] {
|
[] {
|
||||||
Scripting::fireEvent("quit", "shutdown");
|
Scripting::fireEvent("quit", "shutdown");
|
||||||
Scripting::fireEvent("shutdown");
|
Scripting::fireEvent("shutdown");
|
||||||
if (quitES("/tmp/es-shutdown") != 0)
|
if (quitES(QuitMode::SHUTDOWN) != 0)
|
||||||
LOG(LogWarning) << "Shutdown terminated with non-zero result!";
|
LOG(LogWarning) << "Shutdown terminated with non-zero result!";
|
||||||
}, "NO", nullptr));
|
}, "NO", nullptr));
|
||||||
});
|
});
|
||||||
|
|
|
@ -440,6 +440,8 @@ int main(int argc, char* argv[])
|
||||||
FreeImage_DeInitialise();
|
FreeImage_DeInitialise();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
processQuitMode();
|
||||||
|
|
||||||
LOG(LogInfo) << "EmulationStation cleanly shutting down.";
|
LOG(LogInfo) << "EmulationStation cleanly shutting down.";
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
#endif
|
#endif
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
|
||||||
|
#include "Log.h"
|
||||||
|
|
||||||
int runShutdownCommand()
|
int runShutdownCommand()
|
||||||
{
|
{
|
||||||
#ifdef WIN32 // windows
|
#ifdef WIN32 // windows
|
||||||
|
@ -40,11 +42,13 @@ int runSystemCommand(const std::string& cmd_utf8)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int quitES(const std::string& filename)
|
QuitMode quitMode = QuitMode::QUIT;
|
||||||
|
|
||||||
|
int quitES(QuitMode mode)
|
||||||
{
|
{
|
||||||
if (!filename.empty())
|
quitMode = mode;
|
||||||
touch(filename);
|
|
||||||
SDL_Event* quit = new SDL_Event();
|
SDL_Event *quit = new SDL_Event();
|
||||||
quit->type = SDL_QUIT;
|
quit->type = SDL_QUIT;
|
||||||
SDL_PushEvent(quit);
|
SDL_PushEvent(quit);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -61,4 +65,25 @@ void touch(const std::string& filename)
|
||||||
if (fd >= 0)
|
if (fd >= 0)
|
||||||
close(fd);
|
close(fd);
|
||||||
#endif
|
#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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -21,10 +21,16 @@
|
||||||
#define GLHEADER <SDL_opengl.h>
|
#define GLHEADER <SDL_opengl.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int runShutdownCommand(); // shut down the system (returns 0 if successful)
|
enum QuitMode
|
||||||
int runRestartCommand(); // restart the system (returns 0 if successful)
|
{
|
||||||
|
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 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);
|
int quitES(QuitMode mode = QuitMode::QUIT);
|
||||||
void touch(const std::string& filename);
|
void processQuitMode();
|
||||||
|
|
||||||
#endif // ES_CORE_PLATFORM_H
|
#endif // ES_CORE_PLATFORM_H
|
||||||
|
|
Loading…
Reference in a new issue