2013-05-13 19:53:28 +00:00
|
|
|
#include "platform.h"
|
2015-02-22 03:35:50 +00:00
|
|
|
|
2017-11-01 22:21:10 +00:00
|
|
|
#include <SDL_events.h>
|
2015-02-22 03:35:50 +00:00
|
|
|
#ifdef WIN32
|
2015-02-21 22:48:56 +00:00
|
|
|
#include <codecvt>
|
2018-01-27 20:04:08 +00:00
|
|
|
#else
|
|
|
|
#include <unistd.h>
|
2015-02-22 03:35:50 +00:00
|
|
|
#endif
|
2017-11-01 22:21:10 +00:00
|
|
|
#include <fcntl.h>
|
2013-05-13 19:53:28 +00:00
|
|
|
|
2019-08-14 23:50:23 +00:00
|
|
|
#include "Log.h"
|
|
|
|
|
2020-05-15 15:58:25 +00:00
|
|
|
int runRebootCommand()
|
2014-08-02 19:19:57 +00:00
|
|
|
{
|
|
|
|
#ifdef WIN32 // windows
|
2020-05-15 15:58:25 +00:00
|
|
|
return system("shutdown -r -t 0");
|
2014-08-02 19:19:57 +00:00
|
|
|
#else // osx / linux
|
2020-05-15 15:58:25 +00:00
|
|
|
return system("shutdown --reboot now");
|
2014-08-02 19:19:57 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2020-05-15 15:58:25 +00:00
|
|
|
int runPoweroffCommand()
|
2014-08-02 19:19:57 +00:00
|
|
|
{
|
|
|
|
#ifdef WIN32 // windows
|
2020-05-15 15:58:25 +00:00
|
|
|
return system("shutdown -s -t 0");
|
2014-08-02 19:19:57 +00:00
|
|
|
#else // osx / linux
|
2020-05-15 15:58:25 +00:00
|
|
|
return system("shutdown --poweroff now");
|
2014-08-02 19:19:57 +00:00
|
|
|
#endif
|
2015-02-21 22:48:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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<wchar_t> convert_type;
|
|
|
|
std::wstring_convert<convert_type, wchar_t> converter;
|
|
|
|
std::wstring wchar_str = converter.from_bytes(cmd_utf8);
|
|
|
|
return _wsystem(wchar_str.c_str());
|
|
|
|
#else
|
|
|
|
return system(cmd_utf8.c_str());
|
|
|
|
#endif
|
2016-01-17 04:24:28 +00:00
|
|
|
}
|
|
|
|
|
2019-08-14 23:50:23 +00:00
|
|
|
QuitMode quitMode = QuitMode::QUIT;
|
|
|
|
|
|
|
|
int quitES(QuitMode mode)
|
2016-01-17 04:24:28 +00:00
|
|
|
{
|
2019-08-14 23:50:23 +00:00
|
|
|
quitMode = mode;
|
|
|
|
|
|
|
|
SDL_Event *quit = new SDL_Event();
|
2016-01-17 04:24:28 +00:00
|
|
|
quit->type = SDL_QUIT;
|
|
|
|
SDL_PushEvent(quit);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void touch(const std::string& filename)
|
|
|
|
{
|
2016-11-17 20:37:44 +00:00
|
|
|
#ifdef WIN32
|
|
|
|
FILE* fp = fopen(filename.c_str(), "ab+");
|
|
|
|
if (fp != NULL)
|
|
|
|
fclose(fp);
|
|
|
|
#else
|
2016-01-17 04:24:28 +00:00
|
|
|
int fd = open(filename.c_str(), O_CREAT|O_WRONLY, 0644);
|
|
|
|
if (fd >= 0)
|
|
|
|
close(fd);
|
2016-11-17 20:37:44 +00:00
|
|
|
#endif
|
2019-08-14 23:50:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void processQuitMode()
|
|
|
|
{
|
|
|
|
switch (quitMode)
|
|
|
|
{
|
2019-08-25 15:23:02 +00:00
|
|
|
case QuitMode::REBOOT:
|
2019-08-14 23:50:23 +00:00
|
|
|
LOG(LogInfo) << "Rebooting system";
|
2020-05-15 15:58:25 +00:00
|
|
|
runRebootCommand();
|
2019-08-25 15:23:02 +00:00
|
|
|
break;
|
2020-05-15 15:58:25 +00:00
|
|
|
case QuitMode::POWEROFF:
|
|
|
|
LOG(LogInfo) << "Powering off system";
|
|
|
|
runPoweroffCommand();
|
2019-08-14 23:50:23 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|