Skip to content

Commit

Permalink
added fast shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
digitalLumberjack committed May 5, 2016
1 parent 8fd7961 commit f7b7a5e
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 45 deletions.
66 changes: 38 additions & 28 deletions es-app/src/RecalboxSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ RecalboxSystem::RecalboxSystem() {

RecalboxSystem *RecalboxSystem::instance = NULL;


RecalboxSystem *RecalboxSystem::getInstance() {
if (RecalboxSystem::instance == NULL) {
RecalboxSystem::instance = new RecalboxSystem();
Expand Down Expand Up @@ -117,8 +118,7 @@ bool RecalboxSystem::createLastVersionFileIfNotExisting() {
std::string versionFile = Settings::getInstance()->getString("LastVersionFile");

FILE *file;
if (file = fopen(versionFile.c_str(), "r"))
{
if (file = fopen(versionFile.c_str(), "r")) {
fclose(file);
return true;
}
Expand Down Expand Up @@ -265,13 +265,13 @@ bool RecalboxSystem::launchKodi(Window *window) {
VolumeControl::getInstance()->deinit();

std::string commandline = InputManager::getInstance()->configureEmulators();
std::string command = "configgen -system kodi -rom '' "+commandline;
std::string command = "configgen -system kodi -rom '' " + commandline;

window->deinit();

int exitCode = system(command.c_str());
if(WIFEXITED(exitCode)) {
exitCode = WEXITSTATUS(exitCode);
if (WIFEXITED(exitCode)) {
exitCode = WEXITSTATUS(exitCode);
}

window->init();
Expand All @@ -280,17 +280,17 @@ bool RecalboxSystem::launchKodi(Window *window) {
window->normalizeNextUpdate();

// handle end of kodi
switch(exitCode) {
case 10: // reboot code
reboot();
return true;
break;
case 11: // shutdown code
shutdown();
return true;
break;
switch (exitCode) {
case 10: // reboot code
reboot();
return true;
break;
case 11: // shutdown code
shutdown();
return true;
break;
}

return exitCode == 0;

}
Expand Down Expand Up @@ -331,23 +331,31 @@ bool RecalboxSystem::disableWifi() {
}



bool RecalboxSystem::reboot() {
bool success = system("touch /tmp/reboot.please") == 0;
bool RecalboxSystem::halt(bool reboot, bool fast) {
bool success = reboot ? system("touch /tmp/reboot.please") == 0 : system("touch /tmp/shutdown.please") == 0;
SDL_Event *quit = new SDL_Event();
quit->type = SDL_QUIT;
quit->type = fast ? SDL_FAST_QUIT : SDL_QUIT;
SDL_PushEvent(quit);
return success;
}

bool RecalboxSystem::reboot() {
return halt(true, false);
}

bool RecalboxSystem::fastReboot() {
return halt(true, true);
}

bool RecalboxSystem::shutdown() {
bool success = system("touch /tmp/shutdown.please") == 0;
SDL_Event *quit = new SDL_Event();
quit->type = SDL_QUIT;
SDL_PushEvent(quit);
return success;
return halt(false, false);
}

bool RecalboxSystem::fastShutdown() {
return halt(false, true);
}


std::string RecalboxSystem::getIpAdress() {
struct ifaddrs *ifAddrStruct = NULL;
struct ifaddrs *ifa = NULL;
Expand All @@ -366,7 +374,8 @@ std::string RecalboxSystem::getIpAdress() {
char addressBuffer[INET_ADDRSTRLEN];
inet_ntop(AF_INET, tmpAddrPtr, addressBuffer, INET_ADDRSTRLEN);
printf("%s IP Address %s\n", ifa->ifa_name, addressBuffer);
if (std::string(ifa->ifa_name).find("eth") != std::string::npos || std::string(ifa->ifa_name).find("wlan") != std::string::npos) {
if (std::string(ifa->ifa_name).find("eth") != std::string::npos ||
std::string(ifa->ifa_name).find("wlan") != std::string::npos) {
result = std::string(addressBuffer);
}
}
Expand All @@ -383,7 +392,8 @@ std::string RecalboxSystem::getIpAdress() {
char addressBuffer[INET6_ADDRSTRLEN];
inet_ntop(AF_INET6, tmpAddrPtr, addressBuffer, INET6_ADDRSTRLEN);
printf("%s IP Address %s\n", ifa->ifa_name, addressBuffer);
if (std::string(ifa->ifa_name).find("eth") != std::string::npos || std::string(ifa->ifa_name).find("wlan") != std::string::npos) {
if (std::string(ifa->ifa_name).find("eth") != std::string::npos ||
std::string(ifa->ifa_name).find("wlan") != std::string::npos) {
return std::string(addressBuffer);
}
}
Expand Down Expand Up @@ -452,7 +462,7 @@ std::string RecalboxSystem::getCurrentStorage() {
return "";
}

if(fgets(line, 1024, pipe)){
if (fgets(line, 1024, pipe)) {
strtok(line, "\n");
pclose(pipe);
return std::string(line);
Expand Down
53 changes: 37 additions & 16 deletions es-app/src/RecalboxSystem.h
Original file line number Diff line number Diff line change
@@ -1,45 +1,63 @@
/*
* File: RetroboxSystem.h
* Author: matthieu
*
* Created on 29 novembre 2014, 03:15
*/

#ifndef RETROBOXSYSTEM_H
#define RETROBOXSYSTEM_H
#ifndef RECALBOX_SYSTEM
#define RECALBOX_SYSTEM

#include <string>
#include "Window.h"


class RecalboxSystem {
public:


static RecalboxSystem * getInstance();

static RecalboxSystem *getInstance();

const static Uint32 SDL_FAST_QUIT = 0x800F;

unsigned long getFreeSpaceGB(std::string mountpoint);

std::string getFreeSpaceInfo();

bool isFreeSpaceLimit();

std::string getVersion();

bool setAudioOutputDevice(std::string device);

bool setOverscan(bool enable);

bool setOverclock(std::string mode);

bool createLastVersionFileIfNotExisting();

bool updateLastVersionFile();

bool needToShowVersionMessage();

std::string getVersionMessage();

bool updateSystem();

bool ping();

bool canUpdate();
bool launchKodi(Window * window);

bool launchKodi(Window *window);

bool enableWifi(std::string ssid, std::string key);

bool disableWifi();

bool reboot();

bool shutdown();

bool fastReboot();

bool fastShutdown();

std::string getIpAdress();


std::vector<std::string> * scanBluetooth();
std::vector<std::string> *scanBluetooth();

bool pairBluetooth(std::string &basic_string);

Expand All @@ -52,10 +70,13 @@ class RecalboxSystem {
bool forgetBluetoothControllers();

private:
static RecalboxSystem * instance;
static RecalboxSystem *instance;

RecalboxSystem();

bool halt(bool reboot, bool fast);

};

#endif /* RETROBOXSYSTEM_Hm */
#endif

2 changes: 1 addition & 1 deletion es-app/src/SystemData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ bool deleteSystem(SystemData * system){
void SystemData::deleteSystems()
{
if(sSystemVector.size()) {
// THE CREATION OF EACH SYSTEM
// THE DELETION OF EACH SYSTEM
boost::asio::io_service ioService;
boost::thread_group threadpool;
boost::asio::io_service::work work(ioService);
Expand Down
13 changes: 13 additions & 0 deletions es-app/src/guis/GuiMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,19 @@ GuiMenu::GuiMenu(Window *window) : GuiComponent(window), mMenu(window, _("MAIN M
0x777777FF), true);
s->addRow(row);

row.elements.clear();
row.makeAcceptInputHandler([window] {
window->pushGui(new GuiMsgBox(window, _("REALLY SHUTDOWN WITHOUT SAVING METADATAS?"), _("YES"),
[] {
if (RecalboxSystem::getInstance()->fastShutdown() != 0) {
LOG(LogWarning) <<
"Shutdown terminated with non-zero result!";
}
}, _("NO"), nullptr));
});
row.addElement(std::make_shared<TextComponent>(window, _("FAST SHUTDOWN SYSTEM"), Font::get(FONT_SIZE_MEDIUM),
0x777777FF), true);
s->addRow(row);
/*if(Settings::getInstance()->getBool("ShowExit"))
{
row.elements.clear();
Expand Down
4 changes: 4 additions & 0 deletions es-app/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,10 @@ int main(int argc, char* argv[])
case SDL_QUIT:
running = false;
break;
case RecalboxSystem::SDL_FAST_QUIT:
running = false;
Settings::getInstance()->setBool("IgnoreGamelist", true);
break;
}
}

Expand Down
13 changes: 13 additions & 0 deletions es-app/src/views/SystemView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,19 @@ bool SystemView::input(InputConfig* config, Input input)
row.addElement(std::make_shared<TextComponent>(window, _("SHUTDOWN SYSTEM"), Font::get(FONT_SIZE_MEDIUM),
0x777777FF), true);
s->addRow(row);
row.elements.clear();
row.makeAcceptInputHandler([window] {
window->pushGui(new GuiMsgBox(window, _("REALLY SHUTDOWN WITHOUT SAVING METADATAS?"), _("YES"),
[] {
if (RecalboxSystem::getInstance()->fastShutdown() != 0) {
LOG(LogWarning) <<
"Shutdown terminated with non-zero result!";
}
}, _("NO"), nullptr));
});
row.addElement(std::make_shared<TextComponent>(window, _("FAST SHUTDOWN SYSTEM"), Font::get(FONT_SIZE_MEDIUM),
0x777777FF), true);
s->addRow(row);
mWindow->pushGui(s);
}

Expand Down
6 changes: 6 additions & 0 deletions locale/emulationstation2.pot
Original file line number Diff line number Diff line change
Expand Up @@ -770,3 +770,9 @@ msgstr ""

msgid "PLEASE WAIT..."
msgstr ""

msgid "REALLY SHUTDOWN WITHOUT SAVING METADATAS?"
msgstr ""

msgid "FAST SHUTDOWN SYSTEM"
msgstr ""
6 changes: 6 additions & 0 deletions locale/lang/fr/LC_MESSAGES/emulationstation2.po
Original file line number Diff line number Diff line change
Expand Up @@ -787,3 +787,9 @@ msgstr "VEUILLEZ PATIENTER..."

#~ msgid "Original"
#~ msgstr "Original"

msgid "REALLY SHUTDOWN WITHOUT SAVING METADATAS?"
msgstr "VOULEZ-VOUS VRAIMENT ÉTEINDRE SANS SAUVEGARDER LES METADATAS ?"

msgid "FAST SHUTDOWN SYSTEM"
msgstr "EXCTINCTION RAPIDE"

0 comments on commit f7b7a5e

Please sign in to comment.