From fb16dd8a91be0ec0c8a3b2fc37f4d001dbed98ff Mon Sep 17 00:00:00 2001 From: Aloshi Date: Sat, 2 Aug 2014 14:19:57 -0500 Subject: [PATCH] Fix shutdown/restart commands on Windows. --- es-app/src/guis/GuiMenu.cpp | 4 ++-- es-core/src/platform.cpp | 18 ++++++++++++++++++ es-core/src/platform.h | 4 +++- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/es-app/src/guis/GuiMenu.cpp b/es-app/src/guis/GuiMenu.cpp index 5eee21b8a..417d38224 100644 --- a/es-app/src/guis/GuiMenu.cpp +++ b/es-app/src/guis/GuiMenu.cpp @@ -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)); }); diff --git a/es-core/src/platform.cpp b/es-core/src/platform.cpp index 9f8f93daa..a29bba42d 100644 --- a/es-core/src/platform.cpp +++ b/es-core/src/platform.cpp @@ -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 +} \ No newline at end of file diff --git a/es-core/src/platform.h b/es-core/src/platform.h index aa94d313f..b205d5f68 100644 --- a/es-core/src/platform.h +++ b/es-core/src/platform.h @@ -18,4 +18,6 @@ #include 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)