diff --git a/es-app/src/RecalboxSystem.cpp b/es-app/src/RecalboxSystem.cpp index 07fbbdb9d..e6957084b 100644 --- a/es-app/src/RecalboxSystem.cpp +++ b/es-app/src/RecalboxSystem.cpp @@ -33,6 +33,7 @@ RecalboxSystem::RecalboxSystem() { RecalboxSystem *RecalboxSystem::instance = NULL; + RecalboxSystem *RecalboxSystem::getInstance() { if (RecalboxSystem::instance == NULL) { RecalboxSystem::instance = new RecalboxSystem(); @@ -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; } @@ -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(); @@ -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; } @@ -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; @@ -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); } } @@ -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); } } @@ -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); diff --git a/es-app/src/RecalboxSystem.h b/es-app/src/RecalboxSystem.h index 14a41179c..8eb32d317 100644 --- a/es-app/src/RecalboxSystem.h +++ b/es-app/src/RecalboxSystem.h @@ -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 #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 * scanBluetooth(); + std::vector *scanBluetooth(); bool pairBluetooth(std::string &basic_string); @@ -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 diff --git a/es-app/src/SystemData.cpp b/es-app/src/SystemData.cpp index 9376acaa4..ae0b5b1f2 100644 --- a/es-app/src/SystemData.cpp +++ b/es-app/src/SystemData.cpp @@ -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); diff --git a/es-app/src/guis/GuiMenu.cpp b/es-app/src/guis/GuiMenu.cpp index dcfa97a1b..86cdf7681 100644 --- a/es-app/src/guis/GuiMenu.cpp +++ b/es-app/src/guis/GuiMenu.cpp @@ -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(window, _("FAST SHUTDOWN SYSTEM"), Font::get(FONT_SIZE_MEDIUM), + 0x777777FF), true); + s->addRow(row); /*if(Settings::getInstance()->getBool("ShowExit")) { row.elements.clear(); diff --git a/es-app/src/main.cpp b/es-app/src/main.cpp index c941626e9..69500de59 100644 --- a/es-app/src/main.cpp +++ b/es-app/src/main.cpp @@ -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; } } diff --git a/es-app/src/views/SystemView.cpp b/es-app/src/views/SystemView.cpp index 4f18d37cd..e741dbc51 100644 --- a/es-app/src/views/SystemView.cpp +++ b/es-app/src/views/SystemView.cpp @@ -169,6 +169,19 @@ bool SystemView::input(InputConfig* config, Input input) row.addElement(std::make_shared(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(window, _("FAST SHUTDOWN SYSTEM"), Font::get(FONT_SIZE_MEDIUM), + 0x777777FF), true); + s->addRow(row); mWindow->pushGui(s); } diff --git a/locale/emulationstation2.pot b/locale/emulationstation2.pot index 80fe26f39..dbece222f 100644 --- a/locale/emulationstation2.pot +++ b/locale/emulationstation2.pot @@ -770,3 +770,9 @@ msgstr "" msgid "PLEASE WAIT..." msgstr "" + +msgid "REALLY SHUTDOWN WITHOUT SAVING METADATAS?" +msgstr "" + +msgid "FAST SHUTDOWN SYSTEM" +msgstr "" diff --git a/locale/lang/fr/LC_MESSAGES/emulationstation2.po b/locale/lang/fr/LC_MESSAGES/emulationstation2.po index f0ff0c1b4..bfcfcb8ce 100644 --- a/locale/lang/fr/LC_MESSAGES/emulationstation2.po +++ b/locale/lang/fr/LC_MESSAGES/emulationstation2.po @@ -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"