I do not like if(..).
This commit is contained in:
parent
2641e4922b
commit
c6f0798196
10 changed files with 111 additions and 107 deletions
|
|
@ -30,7 +30,7 @@
|
|||
#include "common.hpp"
|
||||
|
||||
#define APP_TITLE "Universal-Updater"
|
||||
#define VERSION_STRING "2.3.0"
|
||||
#define VERSION_STRING "2.4.0"
|
||||
|
||||
// The Release Fetch struct.
|
||||
struct ReleaseFetch {
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
#pragma once
|
||||
#ifndef SOUND_H
|
||||
#define SOUND_H
|
||||
|
||||
#include <3ds.h>
|
||||
#include <string>
|
||||
|
||||
class sound
|
||||
{
|
||||
class sound {
|
||||
public:
|
||||
sound(const std::string& path, int channel = 1, bool toloop = true);
|
||||
~sound();
|
||||
|
|
@ -16,4 +16,6 @@ private:
|
|||
ndspWaveBuf waveBuf;
|
||||
u8* data = NULL;
|
||||
int chnl;
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -72,8 +72,7 @@ void Animation::DrawProgressBarExtract(u64 currentProgress, u64 totalProgress, i
|
|||
}
|
||||
}
|
||||
|
||||
void Animation::Button(int x, int y, float speed)
|
||||
{
|
||||
void Animation::Button(int x, int y, float speed) {
|
||||
static float timer = 0.0f;
|
||||
float highlight_multiplier = fmax(0.0, fabs(fmod(timer, 1.0) - 0.5) / 0.5);
|
||||
u8 r, g, b;
|
||||
|
|
|
|||
|
|
@ -257,31 +257,27 @@ static size_t handle_data(char* ptr, size_t size, size_t nmemb, void* userdata)
|
|||
(void) userdata;
|
||||
const size_t bsz = size*nmemb;
|
||||
|
||||
if (result_sz == 0 || !result_buf)
|
||||
{
|
||||
if (result_sz == 0 || !result_buf) {
|
||||
result_sz = 0x1000;
|
||||
result_buf = (char*)malloc(result_sz);
|
||||
}
|
||||
|
||||
bool need_realloc = false;
|
||||
while (result_written + bsz > result_sz)
|
||||
{
|
||||
while (result_written + bsz > result_sz) {
|
||||
result_sz <<= 1;
|
||||
need_realloc = true;
|
||||
}
|
||||
|
||||
if (need_realloc)
|
||||
{
|
||||
if (need_realloc) {
|
||||
char *new_buf = (char*)realloc(result_buf, result_sz);
|
||||
if (!new_buf)
|
||||
{
|
||||
if (!new_buf) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
result_buf = new_buf;
|
||||
}
|
||||
|
||||
if (!result_buf)
|
||||
{
|
||||
if (!result_buf) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -326,12 +322,13 @@ std::vector<ReleaseFetch> fetchReleases(nlohmann::json API) {
|
|||
// Push to the Vector.
|
||||
fetchVector.push_back(fetch[i]);
|
||||
}
|
||||
|
||||
return fetchVector;
|
||||
}
|
||||
|
||||
extern touchPosition touch;
|
||||
extern bool touching(touchPosition touch, Structs::ButtonPos button);
|
||||
std::vector<Structs::ButtonPos> arrowPos = {
|
||||
const std::vector<Structs::ButtonPos> arrowPos = {
|
||||
{295, 0, 25, 25}, // Arrow Up.
|
||||
{295, 215, 25, 25} // Arrow Down.
|
||||
};
|
||||
|
|
@ -374,23 +371,25 @@ int SelectRelease(std::vector<ReleaseFetch> bruh) {
|
|||
GFX::DrawArrow(315, 240, 180.0);
|
||||
|
||||
if (Config::viewMode == 0) {
|
||||
for(int i=0;i<ENTRIES_PER_SCREEN && i<(int)bruh.size();i++) {
|
||||
for(int i = 0; i < ENTRIES_PER_SCREEN && i < (int)bruh.size(); i++) {
|
||||
Gui::Draw_Rect(0, 40+(i*57), 320, 45, unselected);
|
||||
line1 = bruh[screenPos + i].TagName;
|
||||
line2 = bruh[screenPos + i].Published.substr(0, 10);
|
||||
if(screenPos + i == selectedRelease) {
|
||||
if (screenPos + i == selectedRelease) {
|
||||
Gui::drawAnimatedSelector(0, 40+(i*57), 320, 45, .060, TRANSPARENT, selected);
|
||||
}
|
||||
|
||||
Gui::DrawStringCentered(0, 38+(i*57), 0.7f, TextColor, line1, 320);
|
||||
Gui::DrawStringCentered(0, 62+(i*57), 0.7f, TextColor, line2, 320);
|
||||
}
|
||||
} else if (Config::viewMode == 1) {
|
||||
for(int i=0;i<ENTRIES_PER_LIST && i<(int)bruh.size();i++) {
|
||||
for(int i = 0; i < ENTRIES_PER_LIST && i < (int)bruh.size(); i++) {
|
||||
Gui::Draw_Rect(0, (i+1)*27, 320, 25, unselected);
|
||||
line1 = bruh[screenPosList + i].TagName;
|
||||
if(screenPosList + i == selectedRelease) {
|
||||
if (screenPosList + i == selectedRelease) {
|
||||
Gui::drawAnimatedSelector(0, (i+1)*27, 320, 25, .060, TRANSPARENT, selected);
|
||||
}
|
||||
|
||||
Gui::DrawStringCentered(0, ((i+1)*27)+1, 0.7f, TextColor, line1, 320);
|
||||
}
|
||||
}
|
||||
|
|
@ -504,14 +503,12 @@ Result downloadFromRelease(std::string url, std::string asset, std::string path,
|
|||
}
|
||||
|
||||
void *socubuf = memalign(0x1000, 0x100000);
|
||||
if (!socubuf)
|
||||
{
|
||||
if (!socubuf) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = socInit((u32*)socubuf, 0x100000);
|
||||
if (R_FAILED(ret))
|
||||
{
|
||||
if (R_FAILED(ret)) {
|
||||
free(socubuf);
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -562,20 +559,21 @@ Result downloadFromRelease(std::string url, std::string asset, std::string path,
|
|||
printf("Looking for asset with matching name:\n%s\n", asset.c_str());
|
||||
std::string assetUrl;
|
||||
json parsedAPI = json::parse(result_buf);
|
||||
if(showVersions) {
|
||||
if(!includePrereleases) {
|
||||
if (showVersions) {
|
||||
if (!includePrereleases) {
|
||||
for(auto it = parsedAPI.begin(); it != parsedAPI.end();) {
|
||||
if((*it)["prerelease"]) {
|
||||
if ((*it)["prerelease"]) {
|
||||
parsedAPI.erase(it);
|
||||
} else {
|
||||
it++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(parsedAPI.size() == 0) {
|
||||
if (parsedAPI.size() == 0) {
|
||||
// All were prereleases and those are being ignored
|
||||
return -2; // TODO: Maybe change this? I'm note sure what good return values are -Pk11
|
||||
}
|
||||
|
||||
std::vector<ReleaseFetch> fetchResult = fetchReleases(parsedAPI);
|
||||
int release = SelectRelease(fetchResult);
|
||||
|
||||
|
|
@ -590,9 +588,10 @@ Result downloadFromRelease(std::string url, std::string asset, std::string path,
|
|||
}
|
||||
|
||||
parsedAPI = parsedAPI[release];
|
||||
} else if(includePrereleases) {
|
||||
} else if (includePrereleases) {
|
||||
parsedAPI = parsedAPI[0];
|
||||
}
|
||||
|
||||
if (parsedAPI["assets"].is_array()) {
|
||||
for (auto jsonAsset : parsedAPI["assets"]) {
|
||||
if (jsonAsset.is_object() && jsonAsset["name"].is_string() && jsonAsset["browser_download_url"].is_string()) {
|
||||
|
|
@ -619,6 +618,7 @@ Result downloadFromRelease(std::string url, std::string asset, std::string path,
|
|||
Threads::create((ThreadFunc)displayProgressBar);
|
||||
ret = downloadToFile(assetUrl, path);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
@ -653,18 +653,15 @@ void notConnectedMsg(void) {
|
|||
Msg::DisplayWarnMsg(Lang::get("CONNECT_WIFI"));
|
||||
}
|
||||
|
||||
std::string getLatestRelease(std::string repo, std::string item)
|
||||
{
|
||||
std::string getLatestRelease(std::string repo, std::string item) {
|
||||
Result ret = 0;
|
||||
void *socubuf = memalign(0x1000, 0x100000);
|
||||
if (!socubuf)
|
||||
{
|
||||
if (!socubuf) {
|
||||
return "";
|
||||
}
|
||||
|
||||
ret = socInit((u32*)socubuf, 0x100000);
|
||||
if (R_FAILED(ret))
|
||||
{
|
||||
if (R_FAILED(ret)) {
|
||||
free(socubuf);
|
||||
return "";
|
||||
}
|
||||
|
|
@ -707,6 +704,7 @@ std::string getLatestRelease(std::string repo, std::string item)
|
|||
if (parsedAPI[item].is_string()) {
|
||||
jsonItem = parsedAPI[item];
|
||||
}
|
||||
|
||||
socExit();
|
||||
free(result_buf);
|
||||
free(socubuf);
|
||||
|
|
@ -720,14 +718,12 @@ std::string getLatestRelease(std::string repo, std::string item)
|
|||
std::string getLatestCommit(std::string repo, std::string item) {
|
||||
Result ret = 0;
|
||||
void *socubuf = memalign(0x1000, 0x100000);
|
||||
if (!socubuf)
|
||||
{
|
||||
if (!socubuf) {
|
||||
return "";
|
||||
}
|
||||
|
||||
ret = socInit((u32*)socubuf, 0x100000);
|
||||
if (R_FAILED(ret))
|
||||
{
|
||||
if (R_FAILED(ret)) {
|
||||
free(socubuf);
|
||||
return "";
|
||||
}
|
||||
|
|
@ -770,6 +766,7 @@ std::string getLatestCommit(std::string repo, std::string item) {
|
|||
if (parsedAPI[item].is_string()) {
|
||||
jsonItem = parsedAPI[item];
|
||||
}
|
||||
|
||||
socExit();
|
||||
free(result_buf);
|
||||
free(socubuf);
|
||||
|
|
@ -783,14 +780,12 @@ std::string getLatestCommit(std::string repo, std::string item) {
|
|||
std::string getLatestCommit(std::string repo, std::string array, std::string item) {
|
||||
Result ret = 0;
|
||||
void *socubuf = memalign(0x1000, 0x100000);
|
||||
if (!socubuf)
|
||||
{
|
||||
if (!socubuf) {
|
||||
return "";
|
||||
}
|
||||
|
||||
ret = socInit((u32*)socubuf, 0x100000);
|
||||
if (R_FAILED(ret))
|
||||
{
|
||||
if (R_FAILED(ret)) {
|
||||
free(socubuf);
|
||||
return "";
|
||||
}
|
||||
|
|
@ -833,6 +828,7 @@ std::string getLatestCommit(std::string repo, std::string array, std::string ite
|
|||
if (parsedAPI[array][item].is_string()) {
|
||||
jsonItem = parsedAPI[array][item];
|
||||
}
|
||||
|
||||
socExit();
|
||||
free(result_buf);
|
||||
free(socubuf);
|
||||
|
|
|
|||
|
|
@ -78,8 +78,7 @@ Structs::ButtonPos Numbers [] = {
|
|||
extern bool touching(touchPosition touch, Structs::ButtonPos button);
|
||||
|
||||
|
||||
void Input::DrawNumpad()
|
||||
{
|
||||
void Input::DrawNumpad() {
|
||||
for(uint i=0;i<(sizeof(NumpadStruct)/sizeof(NumpadStruct[0]));i++) {
|
||||
Gui::Draw_Rect(NumpadStruct[i].x, NumpadStruct[i].y, 60, 50, Config::Color1);
|
||||
char c[2] = {NumpadStruct[i].character[0]};
|
||||
|
|
@ -90,7 +89,7 @@ void Input::DrawNumpad()
|
|||
void Input::drawKeyboard() {
|
||||
for(uint i=0;i<(sizeof(keysQWERTY)/sizeof(keysQWERTY[0]));i++) {
|
||||
C2D_DrawRectSolid(keysQWERTY[i].x, keysQWERTY[i].y+103, 0.5f, 20, 20, Config::Color1 & C2D_Color32(255, 255, 255, 200));
|
||||
if(shift) {
|
||||
if (shift) {
|
||||
char c[2] = {caps ? (char)toupper(keysQWERTYShift[i].character[0]) : keysQWERTYShift[i].character[0]};
|
||||
Gui::DrawString(keysQWERTYShift[i].x+(10-(Gui::GetStringWidth(0.50, c)/2)), keysQWERTYShift[i].y+103+(10-(Gui::GetStringHeight(0.50, c)/2)), 0.50, Config::TxtColor, c);
|
||||
} else {
|
||||
|
|
@ -98,6 +97,7 @@ void Input::drawKeyboard() {
|
|||
Gui::DrawString(keysQWERTY[i].x+(10-(Gui::GetStringWidth(0.50, c)/2)), keysQWERTY[i].y+103+(10-(Gui::GetStringHeight(0.50, c)/2)), 0.50, Config::TxtColor, c);
|
||||
}
|
||||
}
|
||||
|
||||
for(uint i=0;i<(sizeof(modifierKeys)/sizeof(modifierKeys[0]));i++) {
|
||||
std::string enter = modifierKeys[2].character;
|
||||
std::string arrowUp = modifierKeys[3].character;
|
||||
|
|
@ -116,8 +116,7 @@ void Input::drawKeyboard() {
|
|||
|
||||
std::string Input::Numpad(std::string Text) { return Input::Numpad(-1, Text); }
|
||||
|
||||
std::string Input::Numpad(uint maxLength, std::string Text)
|
||||
{
|
||||
std::string Input::Numpad(uint maxLength, std::string Text) {
|
||||
int hDown;
|
||||
touchPosition touch;
|
||||
std::string string;
|
||||
|
|
@ -133,25 +132,25 @@ std::string Input::Numpad(uint maxLength, std::string Text)
|
|||
GFX::DrawTop();
|
||||
Gui::DrawString((400-Gui::GetStringWidth(0.55f, Text))/2, 2, 0.55f, Config::TxtColor, Text, 400);
|
||||
Gui::DrawString(180, 217, 0.8, Config::TxtColor, (string+(cursorBlink-- > 0 ? "_" : "")).c_str(), 400);
|
||||
if(cursorBlink < -20) cursorBlink = 20;
|
||||
if (cursorBlink < -20) cursorBlink = 20;
|
||||
Gui::ScreenDraw(Bottom);
|
||||
Gui::Draw_Rect(0, 0, 320, 240, Config::Color3);
|
||||
DrawNumpad();
|
||||
scanKeys();
|
||||
hDown = keysDown();
|
||||
if(keyDownDelay > 0) {
|
||||
if (keyDownDelay > 0) {
|
||||
keyDownDelay--;
|
||||
} else if(keyDownDelay == 0) {
|
||||
keyDownDelay--;
|
||||
}
|
||||
} while(!hDown);
|
||||
if(keyDownDelay > 0) {
|
||||
if (keyDownDelay > 0) {
|
||||
}
|
||||
keyDownDelay = 10;
|
||||
|
||||
if(hDown & KEY_TOUCH) {
|
||||
if (hDown & KEY_TOUCH) {
|
||||
touchRead(&touch);
|
||||
if(string.length() < maxLength) {
|
||||
if (string.length() < maxLength) {
|
||||
if (touching(touch, Numbers[0])) {
|
||||
string += "1";
|
||||
} else if (touching(touch, Numbers[1])) {
|
||||
|
|
@ -176,11 +175,11 @@ std::string Input::Numpad(uint maxLength, std::string Text)
|
|||
}
|
||||
}
|
||||
|
||||
if(hDown & KEY_B || touching(touch, Numbers[11])) {
|
||||
if (hDown & KEY_B || touching(touch, Numbers[11])) {
|
||||
string = string.substr(0, string.length()-1);
|
||||
}
|
||||
|
||||
if(hDown & KEY_START || touching(touch, Numbers[10]) || enter) {
|
||||
if (hDown & KEY_START || touching(touch, Numbers[10]) || enter) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -191,9 +190,9 @@ std::string Input::Numpad(uint maxLength, std::string Text)
|
|||
|
||||
int Input::getUint(int max, std::string Text) {
|
||||
std::string s = Input::Numpad(3, Text);
|
||||
if(s == "" || (atoi(s.c_str()) == 0 && s[0] != '0')) return -1;
|
||||
if (s == "" || (atoi(s.c_str()) == 0 && s[0] != '0')) return -1;
|
||||
int i = atoi(s.c_str());
|
||||
if(i>max) return 255;
|
||||
if (i > max) return 255;
|
||||
return i;
|
||||
}
|
||||
|
||||
|
|
@ -217,25 +216,25 @@ std::string Input::getString(uint maxLength, std::string Text, float inputTextSi
|
|||
drawKeyboard();
|
||||
C2D_DrawRectSolid(0, 81, 0.5f, 320, 20, Config::Color1 & C2D_Color32(200, 200, 200, 200));
|
||||
Gui::DrawString(2, 82, inputTextSize, Config::TxtColor, (string+(cursorBlink-- > 0 ? "_" : "")).c_str(), 316);
|
||||
if(cursorBlink < -20) cursorBlink = 20;
|
||||
if (cursorBlink < -20) cursorBlink = 20;
|
||||
scanKeys();
|
||||
hDown = keysDown();
|
||||
if(keyDownDelay > 0) {
|
||||
if (keyDownDelay > 0) {
|
||||
keyDownDelay--;
|
||||
} else if(keyDownDelay == 0) {
|
||||
} else if (keyDownDelay == 0) {
|
||||
keyDownDelay--;
|
||||
}
|
||||
} while(!hDown);
|
||||
if(keyDownDelay > 0) {
|
||||
if (keyDownDelay > 0) {
|
||||
}
|
||||
keyDownDelay = 10;
|
||||
|
||||
if(hDown & KEY_TOUCH) {
|
||||
if (hDown & KEY_TOUCH) {
|
||||
touchRead(&touch);
|
||||
if(string.length() < maxLength) {
|
||||
if (string.length() < maxLength) {
|
||||
// Check if a regular key was pressed
|
||||
for(uint i=0;i<(sizeof(keysQWERTY)/sizeof(keysQWERTY[0]));i++) {
|
||||
if((touch.px > keysQWERTY[i].x-2 && touch.px < keysQWERTY[i].x+18) && (touch.py > keysQWERTY[i].y+(103)-2 && touch.py < keysQWERTY[i].y+18+(103))) {
|
||||
if ((touch.px > keysQWERTY[i].x-2 && touch.px < keysQWERTY[i].x+18) && (touch.py > keysQWERTY[i].y+(103)-2 && touch.py < keysQWERTY[i].y+18+(103))) {
|
||||
char c = (shift ? keysQWERTYShift[i] : keysQWERTY[i]).character[0];
|
||||
string += (shift || caps ? toupper(c) : c);
|
||||
shift = 0;
|
||||
|
|
@ -245,23 +244,23 @@ std::string Input::getString(uint maxLength, std::string Text, float inputTextSi
|
|||
}
|
||||
// Check if a modifier key was pressed
|
||||
for(uint i=0;i<(sizeof(modifierKeys)/sizeof(modifierKeys[0]));i++) {
|
||||
if((touch.px > modifierKeys[i].x-2 && touch.px < modifierKeys[i].x+modifierKeys[i].w+2) && (touch.py > modifierKeys[i].y+(103)-2 && touch.py < modifierKeys[i].y+18+(103))) {
|
||||
if(modifierKeys[i].character == "\uE071") {
|
||||
if ((touch.px > modifierKeys[i].x-2 && touch.px < modifierKeys[i].x+modifierKeys[i].w+2) && (touch.py > modifierKeys[i].y+(103)-2 && touch.py < modifierKeys[i].y+18+(103))) {
|
||||
if (modifierKeys[i].character == "\uE071") {
|
||||
string = string.substr(0, string.length()-1);
|
||||
} else if(modifierKeys[i].character == "\uE01D") {
|
||||
} else if (modifierKeys[i].character == "\uE01D") {
|
||||
caps = !caps;
|
||||
} else if(modifierKeys[i].character == "\uE056") {
|
||||
} else if (modifierKeys[i].character == "\uE056") {
|
||||
enter = true;
|
||||
} else if(modifierKeys[i].character == "\uE01B") {
|
||||
if(shift) shift = 0;
|
||||
} else if (modifierKeys[i].character == "\uE01B") {
|
||||
if (shift) shift = 0;
|
||||
else shift = 1;
|
||||
if(shift) {
|
||||
if (shift) {
|
||||
keyDownDelay = -1;
|
||||
} else {
|
||||
keyDownDelay = 0;
|
||||
}
|
||||
} else if(modifierKeys[i].character == " ") {
|
||||
if(string.length() < maxLength) {
|
||||
} else if (modifierKeys[i].character == " ") {
|
||||
if (string.length() < maxLength) {
|
||||
shift = 0;
|
||||
string += modifierKeys[5].character[0];
|
||||
}
|
||||
|
|
@ -269,11 +268,11 @@ std::string Input::getString(uint maxLength, std::string Text, float inputTextSi
|
|||
break;
|
||||
}
|
||||
}
|
||||
} else if(hDown & KEY_B) {
|
||||
} else if (hDown & KEY_B) {
|
||||
string = string.substr(0, string.length()-1);
|
||||
}
|
||||
|
||||
if(hDown & KEY_START || enter) {
|
||||
if (hDown & KEY_START || enter) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,6 +65,7 @@ void Msg::DisplayMsg(std::string text) {
|
|||
} else if (isScriptSelected == true) {
|
||||
Gui::DrawStringCentered(0, (240-Gui::GetStringHeight(0.6f, text))/2, 0.6f, TextColor, text, 395, 70);
|
||||
}
|
||||
|
||||
GFX::DrawBottom();
|
||||
C3D_FrameEnd(0);
|
||||
}
|
||||
|
|
@ -80,6 +81,7 @@ void Msg::DisplayWarnMsg(std::string Text) {
|
|||
} else if (isScriptSelected == true) {
|
||||
Gui::DrawStringCentered(0, 1, 0.6f, TextColor, Text, 400);
|
||||
}
|
||||
|
||||
GFX::DrawBottom();
|
||||
C3D_FrameEnd(0);
|
||||
for (int i = 0; i < 60*3; i++) {
|
||||
|
|
|
|||
|
|
@ -30,8 +30,7 @@
|
|||
|
||||
#include <memory>
|
||||
|
||||
std::string Logging::format(const std::string& fmt_str, ...)
|
||||
{
|
||||
std::string Logging::format(const std::string& fmt_str, ...) {
|
||||
va_list ap;
|
||||
char* fp = NULL;
|
||||
va_start(ap, fmt_str);
|
||||
|
|
@ -41,8 +40,7 @@ std::string Logging::format(const std::string& fmt_str, ...)
|
|||
return std::string(formatted.get());
|
||||
}
|
||||
|
||||
std::string Logging::logDate(void)
|
||||
{
|
||||
std::string Logging::logDate(void) {
|
||||
time_t unixTime;
|
||||
struct tm timeStruct;
|
||||
time(&unixTime);
|
||||
|
|
@ -51,7 +49,7 @@ std::string Logging::logDate(void)
|
|||
}
|
||||
|
||||
void Logging::createLogFile(void) {
|
||||
if((access("sdmc:/3ds/Universal-Updater/Log.log", F_OK) != 0)) {
|
||||
if ((access("sdmc:/3ds/Universal-Updater/Log.log", F_OK) != 0)) {
|
||||
FILE* logFile = fopen(("sdmc:/3ds/Universal-Updater/Log.log"), "w");
|
||||
fclose(logFile);
|
||||
}
|
||||
|
|
@ -59,7 +57,7 @@ void Logging::createLogFile(void) {
|
|||
|
||||
// Only write to the Log, if it is enabled in the Settings File!
|
||||
void Logging::writeToLog(std::string debugText) {
|
||||
if (Config::getBool("LOGGING") == true) {
|
||||
if (Config::getBool("LOGGING")) {
|
||||
std::ofstream logFile;
|
||||
logFile.open(("sdmc:/3ds/Universal-Updater/Log.log"), std::ofstream::app);
|
||||
std::string writeDebug = "[ ";
|
||||
|
|
|
|||
|
|
@ -17,8 +17,7 @@ Result CIA_LaunchTitle(u64 titleId, FS_MediaType mediaType) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
Result deletePrevious(u64 titleid, FS_MediaType media)
|
||||
{
|
||||
Result deletePrevious(u64 titleid, FS_MediaType media) {
|
||||
Result ret = 0;
|
||||
|
||||
u32 titles_amount = 0;
|
||||
|
|
@ -65,8 +64,7 @@ FS_MediaType getTitleDestination(u64 titleId) {
|
|||
// Variables.
|
||||
u64 installSize = 0, installOffset = 0;
|
||||
|
||||
Result installCia(const char * ciaPath, bool updatingSelf)
|
||||
{
|
||||
Result installCia(const char * ciaPath, bool updatingSelf) {
|
||||
u32 bytes_read = 0, bytes_written;
|
||||
installSize = 0, installOffset = 0; u64 size = 0;
|
||||
Handle ciaHandle, fileHandle;
|
||||
|
|
@ -124,6 +122,7 @@ Result installCia(const char * ciaPath, bool updatingSelf)
|
|||
printf("Error in:\nAM_FinishCiaInstall\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = FSFILE_Close(fileHandle);
|
||||
if (R_FAILED(ret)) {
|
||||
printf("Error in:\nFSFILE_Close\n");
|
||||
|
|
@ -131,8 +130,8 @@ Result installCia(const char * ciaPath, bool updatingSelf)
|
|||
}
|
||||
|
||||
if (updatingSelf) {
|
||||
if (R_FAILED(ret = CIA_LaunchTitle(info.titleID, MEDIATYPE_SD)))
|
||||
return ret;
|
||||
if (R_FAILED(ret = CIA_LaunchTitle(info.titleID, MEDIATYPE_SD))) return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -53,15 +53,15 @@ Result extractArchive(std::string archivePath, std::string wantedFile, std::stri
|
|||
a = archive_read_new();
|
||||
archive_read_support_format_all(a);
|
||||
|
||||
if(archive_read_open_filename(a, archivePath.c_str(), 0x4000) != ARCHIVE_OK) {
|
||||
if (archive_read_open_filename(a, archivePath.c_str(), 0x4000) != ARCHIVE_OK) {
|
||||
return EXTRACT_ERROR_OPENFILE;
|
||||
}
|
||||
|
||||
while(archive_read_next_header(a, &entry) == ARCHIVE_OK) {
|
||||
if(archive_entry_size(entry) > 0) { // Ignore folders
|
||||
if (archive_entry_size(entry) > 0) { // Ignore folders
|
||||
std::smatch match;
|
||||
std::string entryName(archive_entry_pathname(entry));
|
||||
if(std::regex_search(entryName, match, std::regex(wantedFile))) {
|
||||
if (std::regex_search(entryName, match, std::regex(wantedFile))) {
|
||||
extractingFile = outputPath + match.suffix().str();
|
||||
|
||||
// make directories
|
||||
|
|
@ -75,12 +75,12 @@ Result extractArchive(std::string archivePath, std::string wantedFile, std::stri
|
|||
extractSize = sizeLeft;
|
||||
writeOffset = 0;
|
||||
FILE *file = fopen(extractingFile.c_str(), "wb");
|
||||
if(!file) {
|
||||
if (!file) {
|
||||
return EXTRACT_ERROR_WRITEFILE;
|
||||
}
|
||||
|
||||
u8 *buf = new u8[0x30000];
|
||||
if(buf == nullptr) {
|
||||
if (buf == nullptr) {
|
||||
return EXTRACT_ERROR_ALLOC;
|
||||
}
|
||||
|
||||
|
|
@ -91,6 +91,7 @@ Result extractArchive(std::string archivePath, std::string wantedFile, std::stri
|
|||
sizeLeft -= size;
|
||||
writeOffset += size;
|
||||
}
|
||||
|
||||
filesExtracted++;
|
||||
fclose(file);
|
||||
delete[] buf;
|
||||
|
|
|
|||
|
|
@ -45,22 +45,22 @@ extern void downloadFailed();
|
|||
|
||||
// Get String of the Script.
|
||||
std::string ScriptHelper::getString(nlohmann::json json, const std::string &key, const std::string &key2) {
|
||||
if(!json.contains(key)) return "MISSING: " + key;
|
||||
if(!json.at(key).is_object()) return "NOT OBJECT: " + key;
|
||||
if (!json.contains(key)) return "MISSING: " + key;
|
||||
if (!json.at(key).is_object()) return "NOT OBJECT: " + key;
|
||||
|
||||
if(!json.at(key).contains(key2)) return "MISSING: " + key + "." + key2;
|
||||
if(!json.at(key).at(key2).is_string()) return "NOT STRING: " + key + "." + key2;
|
||||
if (!json.at(key).contains(key2)) return "MISSING: " + key + "." + key2;
|
||||
if (!json.at(key).at(key2).is_string()) return "NOT STRING: " + key + "." + key2;
|
||||
|
||||
return json.at(key).at(key2).get_ref<const std::string&>();
|
||||
}
|
||||
|
||||
// Get int of the Script.
|
||||
int ScriptHelper::getNum(nlohmann::json json, const std::string &key, const std::string &key2) {
|
||||
if(!json.contains(key)) return 0;
|
||||
if(!json.at(key).is_object()) return 0;
|
||||
if (!json.contains(key)) return 0;
|
||||
if (!json.at(key).is_object()) return 0;
|
||||
|
||||
if(!json.at(key).contains(key2)) return 0;
|
||||
if(!json.at(key).at(key2).is_number()) return 0;
|
||||
if (!json.at(key).contains(key2)) return 0;
|
||||
if (!json.at(key).at(key2).is_number()) return 0;
|
||||
return json.at(key).at(key2).get_ref<const int64_t&>();
|
||||
}
|
||||
|
||||
|
|
@ -73,6 +73,7 @@ Result ScriptHelper::downloadRelease(std::string repo, std::string file, std::st
|
|||
ret = FAILED_DOWNLOAD;
|
||||
return ret;
|
||||
}
|
||||
|
||||
showProgressBar = false;
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -90,6 +91,7 @@ Result ScriptHelper::downloadFile(std::string file, std::string output, std::str
|
|||
ret = FAILED_DOWNLOAD;
|
||||
return ret;
|
||||
}
|
||||
|
||||
showProgressBar = false;
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -97,9 +99,10 @@ Result ScriptHelper::downloadFile(std::string file, std::string output, std::str
|
|||
// Remove a File.
|
||||
Result ScriptHelper::removeFile(std::string file, std::string message) {
|
||||
Result ret = NONE;
|
||||
if(access(file.c_str(), F_OK) != 0 ) {
|
||||
if (access(file.c_str(), F_OK) != 0 ) {
|
||||
return DELETE_ERROR;
|
||||
}
|
||||
|
||||
Msg::DisplayMsg(message);
|
||||
deleteFile(file.c_str());
|
||||
return ret;
|
||||
|
|
@ -144,10 +147,11 @@ void ScriptHelper::displayTimeMsg(std::string message, int seconds) {
|
|||
|
||||
bool ScriptHelper::checkIfValid(std::string scriptFile, int mode) {
|
||||
FILE* file = fopen(scriptFile.c_str(), "rt");
|
||||
if(!file) {
|
||||
if (!file) {
|
||||
printf("File not found\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
nlohmann::json json = nlohmann::json::parse(file, nullptr, false);
|
||||
fclose(file);
|
||||
|
||||
|
|
@ -181,28 +185,32 @@ Result ScriptHelper::prompt(std::string message) {
|
|||
if (!Msg::promptMsg(message)) {
|
||||
ret = SCRIPT_CANCELED;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
Result ScriptHelper::copyFile(std::string source, std::string destination, std::string message) {
|
||||
Result ret = NONE;
|
||||
if(access(source.c_str(), F_OK) != 0 ) {
|
||||
if (access(source.c_str(), F_OK) != 0 ) {
|
||||
return COPY_ERROR;
|
||||
}
|
||||
|
||||
Msg::DisplayMsg(message);
|
||||
// If destination does not exist, create dirs.
|
||||
if(access(destination.c_str(), F_OK) != 0 ) {
|
||||
if (access(destination.c_str(), F_OK) != 0 ) {
|
||||
makeDirs(destination.c_str());
|
||||
}
|
||||
|
||||
fcopy(source.c_str(), destination.c_str());
|
||||
return ret;
|
||||
}
|
||||
|
||||
Result ScriptHelper::renameFile(std::string oldName, std::string newName, std::string message) {
|
||||
Result ret = NONE;
|
||||
if(access(oldName.c_str(), F_OK) != 0 ) {
|
||||
if (access(oldName.c_str(), F_OK) != 0 ) {
|
||||
return MOVE_ERROR;
|
||||
}
|
||||
|
||||
Msg::DisplayMsg(message);
|
||||
// TODO: Kinda avoid that?
|
||||
makeDirs(newName.c_str());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue