Fix shutdown/restart commands on Windows.

This commit is contained in:
Aloshi 2014-08-02 14:19:57 -05:00
parent 01923f38e5
commit fb16dd8a91
3 changed files with 23 additions and 3 deletions

View file

@ -180,7 +180,7 @@ GuiMenu::GuiMenu(Window* window) : GuiComponent(window), mMenu(window, "MAIN MEN
row.makeAcceptInputHandler([window] {
window->pushGui(new GuiMsgBox(window, "REALLY RESTART?", "YES",
[] {
if(system("sudo shutdown -r now") != 0)
if(runRestartCommand() != 0)
LOG(LogWarning) << "Restart terminated with non-zero result!";
}, "NO", nullptr));
});
@ -191,7 +191,7 @@ GuiMenu::GuiMenu(Window* window) : GuiComponent(window), mMenu(window, "MAIN MEN
row.makeAcceptInputHandler([window] {
window->pushGui(new GuiMsgBox(window, "REALLY SHUTDOWN?", "YES",
[] {
if(system("sudo shutdown -h now") != 0)
if(runShutdownCommand() != 0)
LOG(LogWarning) << "Shutdown terminated with non-zero result!";
}, "NO", nullptr));
});

View file

@ -34,3 +34,21 @@ std::string getHomePath()
boost::filesystem::path genericPath(homePath);
return genericPath.generic_string();
}
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
}

View file

@ -18,4 +18,6 @@
#include <string>
std::string getHomePath();
void setHomePathOverride(const std::string& path);
int runShutdownCommand(); // shut down the system (returns 0 if successful)
int runRestartCommand(); // restart the system (returns 0 if successful)