1
0
Fork 0
mirror of https://github.com/HamletDuFromage/aio-switch-updater.git synced 2024-11-28 12:22:02 +00:00

properly sleep

This commit is contained in:
flb 2022-05-02 01:04:05 +02:00
parent 74a9d89030
commit 1b008bacab
6 changed files with 56 additions and 59 deletions

View file

@ -22,7 +22,7 @@ DATA := data
INCLUDES := include lib/zipper/include /lib/borealis/library/include/borealis/extern/nlohmann INCLUDES := include lib/zipper/include /lib/borealis/library/include/borealis/extern/nlohmann
APP_TITLE := All-in-One Switch Updater APP_TITLE := All-in-One Switch Updater
APP_AUTHOR := HamletDuFromage APP_AUTHOR := HamletDuFromage
APP_VERSION := 2.18.0 APP_VERSION := 2.18.1
TARGET := $(notdir $(CURDIR)) TARGET := $(notdir $(CURDIR))
ROMFS := resources ROMFS := resources

View file

@ -234,6 +234,9 @@ ChangelogPage::ChangelogPage() : AppletFrame(true, true)
verTitles.push_back("v2.18.0"); verTitles.push_back("v2.18.0");
changes.push_back("\uE016 Add mega.nz support (https://github.com/aedalzotto).\n\uE016 Add Korean localization (https://github.com/DDinghoya).\n\uE016 Improve Spanish localization (https://github.com/Armi-Heavy)."); changes.push_back("\uE016 Add mega.nz support (https://github.com/aedalzotto).\n\uE016 Add Korean localization (https://github.com/DDinghoya).\n\uE016 Improve Spanish localization (https://github.com/Armi-Heavy).");
verTitles.push_back("v2.18.1");
changes.push_back("\uE016 Fix some pop-up related bugs.");
for (int i = verTitles.size() - 1; i >= 0; i--) { for (int i = verTitles.size() - 1; i >= 0; i--) {
listItem = new brls::ListItem(verTitles[i]); listItem = new brls::ListItem(verTitles[i]);

View file

@ -2,14 +2,15 @@
#include <curl/curl.h> #include <curl/curl.h>
#include <math.h> #include <math.h>
#include <mbedtls/base64.h>
#include <switch.h> #include <switch.h>
#include <time.h> #include <time.h>
#include <mbedtls/base64.h>
#include <algorithm> #include <algorithm>
#include <chrono> #include <chrono>
#include <regex> #include <regex>
#include <string> #include <string>
#include <thread>
#include "fs.hpp" #include "fs.hpp"
#include "progress_event.hpp" #include "progress_event.hpp"
@ -160,13 +161,11 @@ namespace download {
{ {
std::string id = mega_id(url); std::string id = mega_id(url);
json request = json::array({ json request = json::array({{
{
{"a", "g"}, {"a", "g"},
{"g", 1}, {"g", 1},
{"p", id}, {"p", id},
} }});
});
std::string body = request.dump(); std::string body = request.dump();
std::string output; std::string output;
@ -183,14 +182,12 @@ namespace download {
curl_easy_setopt( curl_easy_setopt(
curl, curl,
CURLOPT_WRITEFUNCTION, CURLOPT_WRITEFUNCTION,
+[](void *buffer, size_t size, size_t nmemb, void *userp) -> size_t +[](void* buffer, size_t size, size_t nmemb, void* userp) -> size_t {
{
std::string* output = reinterpret_cast<std::string*>(userp); std::string* output = reinterpret_cast<std::string*>(userp);
size_t actual_size = size * nmemb; size_t actual_size = size * nmemb;
output->append(reinterpret_cast<char*>(buffer), actual_size); output->append(reinterpret_cast<char*>(buffer), actual_size);
return actual_size; return actual_size;
} });
);
curl_easy_perform(curl); curl_easy_perform(curl);
@ -243,8 +240,7 @@ namespace download {
decoded.size(), decoded.size(),
&olen, &olen,
reinterpret_cast<const unsigned char*>(key.c_str()), reinterpret_cast<const unsigned char*>(key.c_str()),
key.size() key.size());
);
/** /**
* The encoded base64 is (usually?) 43 characters long. With padding it goes * The encoded base64 is (usually?) 43 characters long. With padding it goes
@ -265,12 +261,10 @@ namespace download {
reinterpret_cast<uint64_t*>(key.data())[0] = reinterpret_cast<uint64_t*>(key.data())[0] =
reinterpret_cast<const uint64_t*>(node_key.data())[0] ^ reinterpret_cast<const uint64_t*>(node_key.data())[0] ^
reinterpret_cast<const uint64_t*>(node_key.data())[2] reinterpret_cast<const uint64_t*>(node_key.data())[2];
;
reinterpret_cast<uint64_t*>(key.data())[1] = reinterpret_cast<uint64_t*>(key.data())[1] =
reinterpret_cast<const uint64_t*>(node_key.data())[1] ^ reinterpret_cast<const uint64_t*>(node_key.data())[1] ^
reinterpret_cast<const uint64_t*>(node_key.data())[3] reinterpret_cast<const uint64_t*>(node_key.data())[3];
;
return key; return key;
} }
@ -279,8 +273,7 @@ namespace download {
{ {
std::string iv(16, 0); std::string iv(16, 0);
reinterpret_cast<uint64_t*>(iv.data())[0] = reinterpret_cast<uint64_t*>(iv.data())[0] =
reinterpret_cast<const uint64_t*>(node_key.data())[2] reinterpret_cast<const uint64_t*>(node_key.data())[2];
;
return iv; return iv;
} }
@ -353,7 +346,7 @@ namespace download {
fclose(chunk.out); fclose(chunk.out);
if (!can_download) { if (!can_download) {
brls::Application::crash("menus/errors/insufficient_storage"_i18n); brls::Application::crash("menus/errors/insufficient_storage"_i18n);
usleep(2000000); std::this_thread::sleep_for(std::chrono::microseconds(2000000));
brls::Application::quit(); brls::Application::quit();
res = {}; res = {};
} }

View file

@ -11,6 +11,7 @@
#include <set> #include <set>
#include <sstream> #include <sstream>
#include <string> #include <string>
#include <thread>
#include <vector> #include <vector>
#include "current_cfw.hpp" #include "current_cfw.hpp"
@ -44,7 +45,7 @@ namespace extract {
if (uncompressedSize * 1.1 > freeStorage) { if (uncompressedSize * 1.1 > freeStorage) {
unzipper.close(); unzipper.close();
brls::Application::crash("menus/errors/insufficient_storage"_i18n); brls::Application::crash("menus/errors/insufficient_storage"_i18n);
usleep(2000000); std::this_thread::sleep_for(std::chrono::microseconds(2000000));
brls::Application::quit(); brls::Application::quit();
} }
} }

View file

@ -6,6 +6,7 @@
#include <filesystem> #include <filesystem>
#include <fstream> #include <fstream>
#include <iomanip> #include <iomanip>
#include <thread>
#include <json.hpp> #include <json.hpp>
#include "constants.hpp" #include "constants.hpp"
@ -166,7 +167,7 @@ NetPage::NetPage() : AppletFrame(true, true)
nifmSetNetworkProfile(&profile, &profile.uuid); nifmSetNetworkProfile(&profile, &profile.uuid);
nifmSetWirelessCommunicationEnabled(true); nifmSetWirelessCommunicationEnabled(true);
nifmExit(); nifmExit();
usleep(2500000); //Wait to avoid crashes when leaving too fast std::this_thread::sleep_for(std::chrono::microseconds(2500000)); //Wait to avoid crashes when leaving too fast
dialog->close(); dialog->close();
}; };
brls::GenericEvent::Callback callbackNo = [dialog](brls::View* view) { brls::GenericEvent::Callback callbackNo = [dialog](brls::View* view) {

View file

@ -2,8 +2,10 @@
#include <switch.h> #include <switch.h>
#include <chrono>
#include <filesystem> #include <filesystem>
#include <fstream> #include <fstream>
#include <thread>
#include "current_cfw.hpp" #include "current_cfw.hpp"
#include "download.hpp" #include "download.hpp"
@ -81,34 +83,32 @@ namespace util {
int showDialogBoxBlocking(const std::string& text, const std::string& opt) int showDialogBoxBlocking(const std::string& text, const std::string& opt)
{ {
int dialogResult = -1;
int result = -1; int result = -1;
brls::Dialog* dialog = new brls::Dialog(text); brls::Dialog* dialog = new brls::Dialog(text);
brls::GenericEvent::Callback callback = [dialog, &dialogResult](brls::View* view) { brls::GenericEvent::Callback callback = [dialog, &result](brls::View* view) {
dialogResult = 0; result = 0;
dialog->close(); dialog->close();
}; };
dialog->addButton(opt, callback); dialog->addButton(opt, callback);
dialog->setCancelable(false); dialog->setCancelable(false);
dialog->open(); dialog->open();
while (result == -1) { while (result == -1) {
usleep(1); std::this_thread::sleep_for(std::chrono::microseconds(10));
result = dialogResult;
} }
std::this_thread::sleep_for(std::chrono::microseconds(800000));
return result; return result;
} }
int showDialogBoxBlocking(const std::string& text, const std::string& opt1, const std::string& opt2) int showDialogBoxBlocking(const std::string& text, const std::string& opt1, const std::string& opt2)
{ {
int dialogResult = -1;
int result = -1; int result = -1;
brls::Dialog* dialog = new brls::Dialog(text); brls::Dialog* dialog = new brls::Dialog(text);
brls::GenericEvent::Callback callback1 = [dialog, &dialogResult](brls::View* view) { brls::GenericEvent::Callback callback1 = [dialog, &result](brls::View* view) {
dialogResult = 0; result = 0;
dialog->close(); dialog->close();
}; };
brls::GenericEvent::Callback callback2 = [dialog, &dialogResult](brls::View* view) { brls::GenericEvent::Callback callback2 = [dialog, &result](brls::View* view) {
dialogResult = 1; result = 1;
dialog->close(); dialog->close();
}; };
dialog->addButton(opt1, callback1); dialog->addButton(opt1, callback1);
@ -116,9 +116,9 @@ namespace util {
dialog->setCancelable(false); dialog->setCancelable(false);
dialog->open(); dialog->open();
while (result == -1) { while (result == -1) {
usleep(1); std::this_thread::sleep_for(std::chrono::microseconds(10));
result = dialogResult;
} }
std::this_thread::sleep_for(std::chrono::microseconds(800000));
return result; return result;
} }
@ -185,7 +185,6 @@ namespace util {
} }
case contentType::ams_cfw: { case contentType::ams_cfw: {
int overwriteInis = showDialogBoxBlocking("menus/utils/overwrite_inis"_i18n, "menus/common/no"_i18n, "menus/common/yes"_i18n); int overwriteInis = showDialogBoxBlocking("menus/utils/overwrite_inis"_i18n, "menus/common/no"_i18n, "menus/common/yes"_i18n);
usleep(1000000);
int deleteContents = showDialogBoxBlocking("menus/ams_update/delete_sysmodules_flags"_i18n, "menus/common/no"_i18n, "menus/common/yes"_i18n); int deleteContents = showDialogBoxBlocking("menus/ams_update/delete_sysmodules_flags"_i18n, "menus/common/no"_i18n, "menus/common/yes"_i18n);
if (deleteContents == 1) if (deleteContents == 1)
removeSysmodulesFlags(AMS_CONTENTS); removeSysmodulesFlags(AMS_CONTENTS);