Universal-Updater Full Rewrite based of UniStore v3.0.0. (#51)

* No Nightlies for the Full-Rewrite.

* Initial push, i guess.

* Forgot to push the Test UniStore + T3X...

* Use C2D flags for wrapping and centering

* gitignore t3x correctly

* Remove Test Store and hardcode to `sdmc:/3ds/Universal-Updater/stores/Universal-DB.unistore` for now.

* Is functional now.

* *More special checks and work.*

* const <typename T> &.

* Universal-DB, not Universal DB.

* Derp.

* Make 3DSX, NDS & Archive path configurable.

* Last fixes + Fade out screen on exit.

* See Desc. for more.

- Add QR Code scan for downloading UniStores.
- Add new Graphics.
- Some fixes + improvements.

* Fix search filtering, re-sort after search

* Fix update check

* Clear search items with X, not just reset results

* The next progress.

* PLEASE tell me, this is the only error..

Co-authored-by: Pk11 <epicpkmn11@outlook.com>
This commit is contained in:
StackZ
2020-10-30 03:31:20 +01:00
committed by GitHub
parent 5d38c98698
commit 913475eabf
142 changed files with 13937 additions and 14588 deletions
-64
View File
@@ -1,64 +0,0 @@
/*
* This file is part of Universal-Updater
* Copyright (C) 2019-2020 Universal-Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "common.hpp"
extern bool isScriptSelected;
extern u32 progressBar, selected;
extern ProgressBar progressbarType;
extern std::unique_ptr<Config> config;
extern C2D_SpriteSheet sprites;
// Draws a Rectangle as the progressbar.
void Animation::DrawProgressBar(u64 currentProgress, u64 totalProgress) {
if (config->progressDisplay()) {
// Outline of progressbar.
Gui::Draw_Rect(30, 120, 340, 30, BLACK);
Gui::Draw_Rect(31, 121, (int)(((float)currentProgress / (float)totalProgress) * 338.0f), 28, isScriptSelected ? progressBar : config->progressbarColor());
}
}
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;
r = (isScriptSelected ? selected : config->selectedColor()) & 0xFF;
g = ((isScriptSelected ? selected : config->selectedColor()) >> 8) & 0xFF;
b = ((isScriptSelected ? selected : config->selectedColor()) >> 16) & 0xFF;
u32 color = C2D_Color32(r + (255 - r) * highlight_multiplier, g + (255 - g) * highlight_multiplier, b + (255 - b) * highlight_multiplier, 255);
// The actual draw part.
C2D_ImageTint tint;
C2D_SetImageTint(&tint, C2D_TopLeft, color, 1);
C2D_SetImageTint(&tint, C2D_TopRight, color, 1);
C2D_SetImageTint(&tint, C2D_BotLeft, color, 1);
C2D_SetImageTint(&tint, C2D_BotRight, color, 1);
C2D_DrawImageAt(C2D_SpriteSheetGetImage(sprites, sprites_selector_idx), x+4, y+4, 0.5f, &tint); // +4 because to fit the button.
timer += speed; // Speed of the animation. Example : .030f / .030
}
-912
View File
@@ -1,912 +0,0 @@
/*
* This file is part of Universal-Updater
* Copyright (C) 2019-2020 Universal-Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "config.hpp"
#include "download.hpp"
#include "formatting.hpp"
#include "gui.hpp"
#include "keyboard.hpp"
#include "lang.hpp"
#include "screenCommon.hpp"
#include "thread.hpp"
#include <string>
#include <vector>
#define USER_AGENT APP_TITLE "-" VERSION_STRING
static char* result_buf = NULL;
static size_t result_sz = 0;
static size_t result_written = 0;
std::vector<std::string> _topText;
std::string jsonName;
extern std::unique_ptr<Config> config;
extern bool downloadNightlies;
extern int filesExtracted;
extern std::string extractingFile;
char progressBarMsg[128] = "";
bool showProgressBar = false;
ProgressBar progressbarType = ProgressBar::Downloading;
// That are our extract Progressbar variables.
extern u64 extractSize, writeOffset;
// That are our install Progressbar variables.
extern u64 installSize, installOffset;
#define TIME_IN_US 1
#define TIMETYPE curl_off_t
#define TIMEOPT CURLINFO_TOTAL_TIME_T
#define MINIMAL_PROGRESS_FUNCTIONALITY_INTERVAL 3000000
extern u32 progressBar;
extern bool isScriptSelected;
extern u32 TextColor;
extern u32 selected;
extern u32 unselected;
CURL *hnd; // Needed to display download speed properly?
CURLcode curlResult;
curl_off_t downloadTotal = 1; //Dont initialize with 0 to avoid division by zero later
curl_off_t downloadNow = 0;
static FILE *downfile = NULL;
static size_t file_buffer_pos = 0;
static size_t file_toCommit_size = 0;
static char* g_buffers[2] = { NULL };
static u8 g_index = 0;
static Thread fsCommitThread;
static LightEvent readyToCommit;
static LightEvent waitCommit;
static bool killThread = false;
static bool writeError = false;
#define FILE_ALLOC_SIZE 0x60000
static int curlProgress(CURL *hnd,
curl_off_t dltotal, curl_off_t dlnow,
curl_off_t ultotal, curl_off_t ulnow)
{
downloadTotal = dltotal;
downloadNow = dlnow;
return 0;
}
bool filecommit() {
if (!downfile) return false;
fseek(downfile, 0, SEEK_END);
u32 byteswritten = fwrite(g_buffers[!g_index], 1, file_toCommit_size, downfile);
if (byteswritten != file_toCommit_size) return false;
file_toCommit_size = 0;
return true;
}
static void commitToFileThreadFunc(void* args) {
LightEvent_Signal(&waitCommit);
while (true) {
LightEvent_Wait(&readyToCommit);
LightEvent_Clear(&readyToCommit);
if (killThread) threadExit(0);
writeError = !filecommit();
LightEvent_Signal(&waitCommit);
}
}
static size_t file_handle_data(char *ptr, size_t size, size_t nmemb, void *userdata) {
(void)userdata;
const size_t bsz = size * nmemb;
size_t tofill = 0;
if (writeError) return 0;
if (!g_buffers[g_index]) {
LightEvent_Init(&waitCommit, RESET_STICKY);
LightEvent_Init(&readyToCommit, RESET_STICKY);
s32 prio = 0;
svcGetThreadPriority(&prio, CUR_THREAD_HANDLE);
fsCommitThread = threadCreate(commitToFileThreadFunc, NULL, 0x1000, prio - 1, -2, true);
g_buffers[0] = (char*)memalign(0x1000, FILE_ALLOC_SIZE);
g_buffers[1] = (char*)memalign(0x1000, FILE_ALLOC_SIZE);
if (!fsCommitThread || !g_buffers[0] || !g_buffers[1]) return 0;
}
if (file_buffer_pos + bsz >= FILE_ALLOC_SIZE) {
tofill = FILE_ALLOC_SIZE - file_buffer_pos;
memcpy(g_buffers[g_index] + file_buffer_pos, ptr, tofill);
LightEvent_Wait(&waitCommit);
LightEvent_Clear(&waitCommit);
file_toCommit_size = file_buffer_pos + tofill;
file_buffer_pos = 0;
svcFlushProcessDataCache(CUR_PROCESS_HANDLE, (u32)g_buffers[g_index], file_toCommit_size);
g_index = !g_index;
LightEvent_Signal(&readyToCommit);
}
memcpy(g_buffers[g_index] + file_buffer_pos, ptr + tofill, bsz - tofill);
file_buffer_pos += bsz - tofill;
return bsz;
}
Result downloadToFile(std::string url, std::string path) {
Result retcode = 0;
downloadTotal = 1;
int res;
printf("Downloading from:\n%s\nto:\n%s\n", url.c_str(), path.c_str());
const char* filepath = path.c_str();
void *socubuf = memalign(0x1000, 0x100000);
if (!socubuf) {
retcode = -1;
goto exit;
}
res = socInit((u32*)socubuf, 0x100000);
if (R_FAILED(res)) {
retcode = res;
goto exit;
}
makeDirs(strdup(filepath));
downfile = fopen(filepath, "wb");
if (!downfile) {
retcode = -2;
goto exit;
}
hnd = curl_easy_init();
curl_easy_setopt(hnd, CURLOPT_BUFFERSIZE, FILE_ALLOC_SIZE);
curl_easy_setopt(hnd, CURLOPT_URL, url.c_str());
curl_easy_setopt(hnd, CURLOPT_NOPROGRESS, 0L);
curl_easy_setopt(hnd, CURLOPT_USERAGENT, USER_AGENT);
curl_easy_setopt(hnd, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(hnd, CURLOPT_FAILONERROR, 1L);
curl_easy_setopt(hnd, CURLOPT_ACCEPT_ENCODING, "gzip");
curl_easy_setopt(hnd, CURLOPT_MAXREDIRS, 50L);
curl_easy_setopt(hnd, CURLOPT_XFERINFOFUNCTION, curlProgress);
curl_easy_setopt(hnd, CURLOPT_HTTP_VERSION, (long)CURL_HTTP_VERSION_2TLS);
curl_easy_setopt(hnd, CURLOPT_WRITEFUNCTION, file_handle_data);
curl_easy_setopt(hnd, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(hnd, CURLOPT_VERBOSE, 1L);
curl_easy_setopt(hnd, CURLOPT_STDERR, stdout);
curlResult = curl_easy_perform(hnd);
curl_easy_cleanup(hnd);
if (curlResult != CURLE_OK) {
retcode = -curlResult;
goto exit;
}
LightEvent_Wait(&waitCommit);
LightEvent_Clear(&waitCommit);
file_toCommit_size = file_buffer_pos;
svcFlushProcessDataCache(CUR_PROCESS_HANDLE, (u32)g_buffers[g_index], file_toCommit_size);
g_index = !g_index;
if (!filecommit()) {
retcode = -3;
goto exit;
}
fflush(downfile);
exit:
if (fsCommitThread) {
killThread = true;
LightEvent_Signal(&readyToCommit);
threadJoin(fsCommitThread, U64_MAX);
killThread = false;
fsCommitThread = NULL;
}
socExit();
if (socubuf) {
free(socubuf);
}
if (downfile) {
fclose(downfile);
downfile = NULL;
}
if (g_buffers[0]) {
free(g_buffers[0]);
g_buffers[0] = NULL;
}
if (g_buffers[1]) {
free(g_buffers[1]);
g_buffers[1] = NULL;
}
g_index = 0;
file_buffer_pos = 0;
file_toCommit_size = 0;
writeError = false;
return retcode;
}
// following function is from
// https://github.com/angelsl/libctrfgh/blob/master/curl_test/src/main.c
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) {
result_sz = 0x1000;
result_buf = (char*)malloc(result_sz);
}
bool need_realloc = false;
while (result_written + bsz > result_sz) {
result_sz <<= 1;
need_realloc = true;
}
if (need_realloc) {
char *new_buf = (char*)realloc(result_buf, result_sz);
if (!new_buf) {
return 0;
}
result_buf = new_buf;
}
if (!result_buf) {
return 0;
}
memcpy(result_buf + result_written, ptr, bsz);
result_written += bsz;
return bsz;
}
static Result setupContext(CURL *hnd, const char * url) {
downloadTotal = 1;
downloadNow = 0;
curl_easy_setopt(hnd, CURLOPT_XFERINFOFUNCTION, curlProgress);
curl_easy_setopt(hnd, CURLOPT_BUFFERSIZE, 102400L);
curl_easy_setopt(hnd, CURLOPT_URL, url);
curl_easy_setopt(hnd, CURLOPT_NOPROGRESS, 0L);
curl_easy_setopt(hnd, CURLOPT_USERAGENT, USER_AGENT);
curl_easy_setopt(hnd, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(hnd, CURLOPT_MAXREDIRS, 50L);
curl_easy_setopt(hnd, CURLOPT_HTTP_VERSION, (long)CURL_HTTP_VERSION_2TLS);
curl_easy_setopt(hnd, CURLOPT_WRITEFUNCTION, handle_data);
curl_easy_setopt(hnd, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(hnd, CURLOPT_VERBOSE, 1L);
curl_easy_setopt(hnd, CURLOPT_STDERR, stdout);
return 0;
}
// Fetch GitHub Releases.
std::vector<ReleaseFetch> fetchReleases(nlohmann::json API) {
ReleaseFetch fetch[API.size()];
std::vector<ReleaseFetch> fetchVector;
for (int i = 0; i < (int)API.size(); i++) {
// Get Stuff.
fetch[i].Target = (std::string)API[i]["target_commitish"];
fetch[i].TagName = (std::string)API[i]["tag_name"];
fetch[i].ReleaseName = (std::string)API[i]["name"];
fetch[i].Created = (std::string)API[i]["created_at"];
fetch[i].Published = (std::string)API[i]["published_at"];
fetch[i].PreRelease = API[i]["prerelease"];
// Push to the Vector.
fetchVector.push_back(fetch[i]);
}
return fetchVector;
}
extern touchPosition touch;
extern bool touching(touchPosition touch, Structs::ButtonPos button);
const std::vector<Structs::ButtonPos> arrowPos = {
{295, 0, 25, 25}, // Arrow Up.
{295, 215, 25, 25} // Arrow Down.
};
int SelectRelease(std::vector<ReleaseFetch> bruh) {
std::string line1;
std::string line2;
int selectedRelease = 0;
int keyRepeatDelay = 4;
bool fastMode = false;
int screenPos = 0;
int screenPosList = 0;
while (1) {
std::string releaseAmount = std::to_string(selectedRelease+1) + " | " + std::to_string(bruh.size());
// Draw Part.
Gui::clearTextBufs();
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
C2D_TargetClear(Top, BLACK);
C2D_TargetClear(Bottom, BLACK);
GFX::DrawTop();
Gui::DrawStringCentered(0, config->useBars() ? 0 : 2, 0.7f, TextColor, Lang::get("VERSION_SELECT"), 400);
Gui::DrawString(397-Gui::GetStringWidth(0.6f, releaseAmount), (config->useBars() ? 239 : 237)-Gui::GetStringHeight(0.6f, releaseAmount), 0.6f, TextColor, releaseAmount);
// Display Informations.
Gui::DrawStringCentered(0, 35, 0.7f, TextColor, Lang::get("TAG_NAME") + std::string(bruh[selectedRelease].TagName), 400);
Gui::DrawStringCentered(0, 65, 0.7f, TextColor, Lang::get("TARGET") + std::string(bruh[selectedRelease].Target), 400);
Gui::DrawStringCentered(0, 95, 0.7f, TextColor, Lang::get("RELEASE_NAME") + std::string(bruh[selectedRelease].ReleaseName), 400);
Gui::DrawStringCentered(0, 125, 0.7f, TextColor, Lang::get("CREATED_AT") + std::string(bruh[selectedRelease].Created), 400);
Gui::DrawStringCentered(0, 155, 0.7f, TextColor, Lang::get("PUBLISHED_AT") + std::string(bruh[selectedRelease].Published), 400);
if (bruh[selectedRelease].PreRelease) Gui::DrawStringCentered(0, 185, 0.7f, TextColor, Lang::get("IS_PRERELEASE") + Lang::get("YES"), 400);
else Gui::DrawStringCentered(0, 185, 0.7f, TextColor, Lang::get("IS_PRERELEASE") + Lang::get("NO"), 400);
GFX::DrawBottom();
GFX::DrawArrow(295, -1);
GFX::DrawArrow(315, 240, 180.0);
if (config->viewMode() == 0) {
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) {
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++) {
Gui::Draw_Rect(0, (i+1)*27, 320, 25, unselected);
line1 = bruh[screenPosList + i].TagName;
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);
}
}
C3D_FrameEnd(0);
// The input part.
hidScanInput();
u32 hDown = hidKeysDown();
u32 hHeld = hidKeysHeld();
hidTouchRead(&touch);
if (keyRepeatDelay) keyRepeatDelay--;
if (hidKeysDown() & KEY_Y) {
if (config->viewMode() == 0) {
config->viewMode(1);
} else {
config->viewMode(0);
}
}
if (hDown & KEY_A) {
return (int)selectedRelease;
}
if (hDown & KEY_B) {
return 0;
}
if (hidKeysDown() & KEY_TOUCH && touching(touch, arrowPos[0])) {
if (selectedRelease > 0) selectedRelease--;
}
if (hidKeysDown() & KEY_TOUCH && touching(touch, arrowPos[1])) {
if ((uint)selectedRelease < bruh.size()-1) selectedRelease++;
}
if (hHeld & KEY_UP) {
if (selectedRelease > 0 && !keyRepeatDelay) {
selectedRelease--;
if (fastMode == true) {
keyRepeatDelay = 3;
} else if (fastMode == false){
keyRepeatDelay = 6;
}
}
} else if (hHeld & KEY_DOWN && !keyRepeatDelay) {
if ((uint)selectedRelease < bruh.size()-1) {
selectedRelease++;
if (fastMode == true) {
keyRepeatDelay = 3;
} else if (fastMode == false){
keyRepeatDelay = 6;
}
}
}
if (hidKeysDown() & KEY_R) {
fastMode = true;
}
if (hidKeysDown() & KEY_L) {
fastMode = false;
}
if (hDown & KEY_START) {
return -2; // Cancel.
}
if (hDown & KEY_TOUCH) {
if (config->viewMode() == 0) {
for(int i = 0; i < ENTRIES_PER_SCREEN && i < (int)bruh.size(); i++) {
if (touch.py > 40+(i*57) && touch.py < 40+(i*57)+45) {
if (bruh.size() != 0) {
return screenPos + i;
}
}
}
} else if (config->viewMode() == 1) {
for(int i = 0; i < ENTRIES_PER_LIST && i < (int)bruh.size(); i++) {
if (touch.py > (i+1)*27 && touch.py < (i+2)*27) {
if (bruh.size() != 0) {
return screenPosList + i;
}
}
}
}
}
if (config->viewMode() == 0) {
if (selectedRelease < screenPos) {
screenPos = selectedRelease;
} else if (selectedRelease > screenPos + ENTRIES_PER_SCREEN - 1) {
screenPos = selectedRelease - ENTRIES_PER_SCREEN + 1;
}
} else if (config->viewMode() == 1) {
if (selectedRelease < screenPosList) {
screenPosList = selectedRelease;
} else if (selectedRelease > screenPosList + ENTRIES_PER_LIST - 1) {
screenPosList = selectedRelease - ENTRIES_PER_LIST + 1;
}
}
}
}
Result downloadFromRelease(std::string url, std::string asset, std::string path, std::string Message, bool includePrereleases, bool showVersions) {
Result ret = 0;
// Do not display progressbar.
if (showVersions) {
showProgressBar = false;
Msg::DisplayMsg(Lang::get("FETCHING_RELEASES"));
}
void *socubuf = memalign(0x1000, 0x100000);
if (!socubuf) {
return -1;
}
ret = socInit((u32*)socubuf, 0x100000);
if (R_FAILED(ret)) {
free(socubuf);
return ret;
}
std::regex parseUrl("github\\.com\\/(.+)\\/(.+)");
std::smatch result;
regex_search(url, result, parseUrl);
std::string repoOwner = result[1].str(), repoName = result[2].str();
std::stringstream apiurlStream;
apiurlStream << "https://api.github.com/repos/" << repoOwner << "/" << repoName << (includePrereleases || showVersions ? "/releases" : "/releases/latest");
std::string apiurl = apiurlStream.str();
printf("Downloading latest release from repo:\n%s\nby:\n%s\n", repoName.c_str(), repoOwner.c_str());
printf("Crafted API url:\n%s\n", apiurl.c_str());
hnd = curl_easy_init();
ret = setupContext(hnd, apiurl.c_str());
if (ret != 0) {
socExit();
free(result_buf);
free(socubuf);
result_buf = NULL;
result_sz = 0;
result_written = 0;
return ret;
}
CURLcode cres = curl_easy_perform(hnd);
curl_easy_cleanup(hnd);
char* newbuf = (char*)realloc(result_buf, result_written + 1);
result_buf = newbuf;
result_buf[result_written] = 0; //nullbyte to end it as a proper C style string
if (cres != CURLE_OK) {
printf("Error in:\ncurl\n");
socExit();
free(result_buf);
free(socubuf);
result_buf = NULL;
result_sz = 0;
result_written = 0;
return -1;
}
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) {
for(auto it = parsedAPI.begin(); it != parsedAPI.end();) {
if ((*it)["prerelease"]) {
parsedAPI.erase(it);
} else {
it++;
}
}
}
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);
if (release == -2) {
socExit();
free(result_buf);
free(socubuf);
result_buf = NULL;
result_sz = 0;
result_written = 0;
return -1;
}
parsedAPI = parsedAPI[release];
} 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()) {
std::string assetName = jsonAsset["name"];
if (matchPattern(asset, assetName)) {
assetUrl = jsonAsset["browser_download_url"];
break;
}
}
}
}
socExit();
free(result_buf);
free(socubuf);
result_buf = NULL;
result_sz = 0;
result_written = 0;
if (assetUrl.empty()) {
ret = DL_ERROR_GIT;
} else {
snprintf(progressBarMsg, sizeof(progressBarMsg), Message.c_str());
showProgressBar = true;
progressbarType = ProgressBar::Downloading;
Threads::create((ThreadFunc)displayProgressBar);
ret = downloadToFile(assetUrl, path);
}
return ret;
}
/**
* Check Wi-Fi status.
* @return True if Wi-Fi is connected; false if not.
*/
bool checkWifiStatus(void) {
if (config->citra()) return true;
u32 wifiStatus;
bool res = false;
if (R_SUCCEEDED(ACU_GetWifiStatus(&wifiStatus)) && wifiStatus) {
res = true;
}
return res;
}
void downloadFailed(void) {
Msg::DisplayWarnMsg(Lang::get("DOWNLOAD_FAILED"));
}
void notImplemented(void) {
Msg::DisplayWarnMsg(Lang::get("NOT_IMPLEMENTED"));
}
void doneMsg(void) {
Msg::DisplayWarnMsg(Lang::get("DONE"));
}
void notConnectedMsg(void) {
Msg::DisplayWarnMsg(Lang::get("CONNECT_WIFI"));
}
std::string getLatestRelease(std::string repo, std::string item) {
Result ret = 0;
void *socubuf = memalign(0x1000, 0x100000);
if (!socubuf) {
return "";
}
ret = socInit((u32*)socubuf, 0x100000);
if (R_FAILED(ret)) {
free(socubuf);
return "";
}
std::stringstream apiurlStream;
apiurlStream << "https://api.github.com/repos/" << repo << "/releases/latest";
std::string apiurl = apiurlStream.str();
CURL *hnd = curl_easy_init();
ret = setupContext(hnd, apiurl.c_str());
if (ret != 0) {
socExit();
free(result_buf);
free(socubuf);
result_buf = NULL;
result_sz = 0;
result_written = 0;
return "";
}
CURLcode cres = curl_easy_perform(hnd);
curl_easy_cleanup(hnd);
char* newbuf = (char*)realloc(result_buf, result_written + 1);
result_buf = newbuf;
result_buf[result_written] = 0; //nullbyte to end it as a proper C style string
if (cres != CURLE_OK) {
printf("Error in:\ncurl\n");
socExit();
free(result_buf);
free(socubuf);
result_buf = NULL;
result_sz = 0;
result_written = 0;
return "";
}
std::string jsonItem;
json parsedAPI = json::parse(result_buf);
if (parsedAPI[item].is_string()) {
jsonItem = parsedAPI[item];
}
socExit();
free(result_buf);
free(socubuf);
result_buf = NULL;
result_sz = 0;
result_written = 0;
return jsonItem;
}
std::string getLatestCommit(std::string repo, std::string item) {
Result ret = 0;
void *socubuf = memalign(0x1000, 0x100000);
if (!socubuf) {
return "";
}
ret = socInit((u32*)socubuf, 0x100000);
if (R_FAILED(ret)) {
free(socubuf);
return "";
}
std::stringstream apiurlStream;
apiurlStream << "https://api.github.com/repos/" << repo << "/commits/master";
std::string apiurl = apiurlStream.str();
CURL *hnd = curl_easy_init();
ret = setupContext(hnd, apiurl.c_str());
if (ret != 0) {
socExit();
free(result_buf);
free(socubuf);
result_buf = NULL;
result_sz = 0;
result_written = 0;
return "";
}
CURLcode cres = curl_easy_perform(hnd);
curl_easy_cleanup(hnd);
char* newbuf = (char*)realloc(result_buf, result_written + 1);
result_buf = newbuf;
result_buf[result_written] = 0; //nullbyte to end it as a proper C style string
if (cres != CURLE_OK) {
printf("Error in:\ncurl\n");
socExit();
free(result_buf);
free(socubuf);
result_buf = NULL;
result_sz = 0;
result_written = 0;
return "";
}
std::string jsonItem;
json parsedAPI = json::parse(result_buf);
if (parsedAPI[item].is_string()) {
jsonItem = parsedAPI[item];
}
socExit();
free(result_buf);
free(socubuf);
result_buf = NULL;
result_sz = 0;
result_written = 0;
return jsonItem;
}
std::string getLatestCommit(std::string repo, std::string array, std::string item) {
Result ret = 0;
void *socubuf = memalign(0x1000, 0x100000);
if (!socubuf) {
return "";
}
ret = socInit((u32*)socubuf, 0x100000);
if (R_FAILED(ret)) {
free(socubuf);
return "";
}
std::stringstream apiurlStream;
apiurlStream << "https://api.github.com/repos/" << repo << "/commits/master";
std::string apiurl = apiurlStream.str();
CURL *hnd = curl_easy_init();
ret = setupContext(hnd, apiurl.c_str());
if (ret != 0) {
socExit();
free(result_buf);
free(socubuf);
result_buf = NULL;
result_sz = 0;
result_written = 0;
return "";
}
CURLcode cres = curl_easy_perform(hnd);
curl_easy_cleanup(hnd);
char* newbuf = (char*)realloc(result_buf, result_written + 1);
result_buf = newbuf;
result_buf[result_written] = 0; //nullbyte to end it as a proper C style string
if (cres != CURLE_OK) {
printf("Error in:\ncurl\n");
socExit();
free(result_buf);
free(socubuf);
result_buf = NULL;
result_sz = 0;
result_written = 0;
return "";
}
std::string jsonItem;
json parsedAPI = json::parse(result_buf);
if (parsedAPI[array][item].is_string()) {
jsonItem = parsedAPI[array][item];
}
socExit();
free(result_buf);
free(socubuf);
result_buf = NULL;
result_sz = 0;
result_written = 0;
return jsonItem;
}
void displayProgressBar() {
char str[256];
while(showProgressBar) {
switch(progressbarType) {
case ProgressBar::Downloading:
if (downloadTotal < 1.0f) {
downloadTotal = 1.0f;
}
if (downloadTotal < downloadNow) {
downloadTotal = downloadNow;
}
snprintf(str, sizeof(str), "%s / %s (%.2f%%)",
formatBytes(downloadNow).c_str(),
formatBytes(downloadTotal).c_str(),
((float)downloadNow/(float)downloadTotal) * 100.0f);
break;
case ProgressBar::Extracting:
snprintf(str, sizeof(str), "%s / %s (%.2f%%)",
formatBytes(writeOffset).c_str(),
formatBytes(extractSize).c_str(),
((float)writeOffset/(float)extractSize) * 100.0f);
break;
case ProgressBar::Installing:
snprintf(str, sizeof(str), "%s / %s (%.2f%%)",
formatBytes(installOffset).c_str(),
formatBytes(installSize).c_str(),
((float)installOffset/(float)installSize) * 100.0f);
break;
}
Gui::clearTextBufs();
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
C2D_TargetClear(Top, BLACK);
C2D_TargetClear(Bottom, BLACK);
GFX::DrawTop();
Gui::DrawStringCentered(0, 1, 0.7f, isScriptSelected ? TextColor : config->textColor(), progressBarMsg, 400);
// Only display this by downloading.
switch(progressbarType) {
case ProgressBar::Downloading:
Gui::DrawStringCentered(0, 80, 0.6f, isScriptSelected ? TextColor : config->textColor(), str, 400);
if (!curlResult && hnd != nullptr && config->showSpeed()) {
curl_off_t speed = 0;
curlResult = curl_easy_getinfo(hnd, CURLINFO_SPEED_DOWNLOAD_T, &speed);
if (!curlResult) {
GFX::TextFormatted(0, 170, 0.6f, "%s %lld %s", Lang::get("DOWNLOAD_SPEED").c_str(), (speed / 1000), Lang::get("KB_PER_SECOND").c_str());
} else {
Gui::DrawStringCentered(0, 170, 0.6f, isScriptSelected ? TextColor : config->textColor(), Lang::get("DOWNLOAD_SPEED") + "?");
}
}
Animation::DrawProgressBar(downloadNow, downloadTotal);
break;
case ProgressBar::Extracting:
Gui::DrawStringCentered(0, 180, 0.6f, isScriptSelected ? TextColor : config->textColor(), str, 400);
Gui::DrawStringCentered(0, 100, 0.6f, isScriptSelected ? TextColor : config->textColor(), std::to_string(filesExtracted) + " " + (filesExtracted == 1 ? (Lang::get("FILE_EXTRACTED")).c_str() :(Lang::get("FILES_EXTRACTED"))), 400);
Gui::DrawStringCentered(0, 40, 0.6f, isScriptSelected ? TextColor : config->textColor(), Lang::get("CURRENTLY_EXTRACTING") + "\n" + extractingFile, 400);
Animation::DrawProgressBar(writeOffset, extractSize);
break;
case ProgressBar::Installing:
Gui::DrawStringCentered(0, 80, 0.6f, isScriptSelected ? TextColor : config->textColor(), str, 400);
Animation::DrawProgressBar(installOffset, installSize);
break;
}
GFX::DrawBottom();
C3D_FrameEnd(0);
gspWaitForVBlank();
}
}
+64 -65
View File
@@ -27,85 +27,84 @@
#include "common.hpp"
#include "gfx.hpp"
extern std::unique_ptr<Config> config;
extern bool isScriptSelected;
extern u32 barColor, bgTopColor, bgBottomColor, TextColor;
/*
Draw the base top screen.
*/
void GFX::DrawTop(void) {
Gui::ScreenDraw(Top);
Gui::Draw_Rect(0, 0, 400, 25, isScriptSelected ? barColor : config->barColor());
Gui::Draw_Rect(0, 25, 400, 190, isScriptSelected ? bgTopColor : config->topBG());
Gui::Draw_Rect(0, 215, 400, 25, isScriptSelected ? barColor : config->barColor());
if (config->useBars()) {
DrawSprite(sprites_top_screen_top_idx, 0, 0);
DrawSprite(sprites_top_screen_bot_idx, 0, 215);
}
Gui::Draw_Rect(0, 0, 400, 25, BAR_COLOR);
Gui::Draw_Rect(0, 25, 400, 215, BG_COLOR);
Gui::Draw_Rect(0, 25, 400, 1, BAR_OUTL_COLOR);
}
void GFX::DrawBottom(void) {
/*
Draw the base bottom screen.
*/
void GFX::DrawBottom() {
Gui::ScreenDraw(Bottom);
Gui::Draw_Rect(0, 0, 320, 25, isScriptSelected ? barColor : config->barColor());
Gui::Draw_Rect(0, 25, 320, 190, isScriptSelected ? bgBottomColor : config->bottomBG());
Gui::Draw_Rect(0, 215, 320, 25, isScriptSelected ? barColor : config->barColor());
if (config->useBars()) {
DrawSprite(sprites_bottom_screen_top_idx, 0, 0);
DrawSprite(sprites_bottom_screen_bot_idx, 0, 215);
}
Gui::Draw_Rect(0, 0, 320, 240, BG_COLOR);
}
/*
Draw the box.
const float &xPos: Const Reference to the X-Position where to draw the box.
const float &yPos: Const Reference to the Y-Position where to draw the box.
const float &width: Const Reference to the Width of the button.
const float &height: Const Reference to the Height of the button.
const bool &selected: Const Reference, if outline is selected (Red) or not (Black).
const uint32_t &clr: (Optional) The color of the inside of the box.
*/
void GFX::drawBox(const float &xPos, const float &yPos, const float &width, const float &height, const bool &selected, const uint32_t &clr) {
static constexpr int w = 1;
const uint32_t outlineColor = selected ? BOX_SELECTED_COLOR : BOX_UNSELECTED_COLOR; // Get Selected | Unselected color.
Gui::Draw_Rect(xPos, yPos, width, height, clr); // Draw middle BG.
Gui::Draw_Rect(xPos, yPos, width, w, outlineColor); // Top.
Gui::Draw_Rect(xPos, yPos + w, w, height - 2 * w, outlineColor); // Left.
Gui::Draw_Rect(xPos + width - w, yPos + w, w, height - 2 * w, outlineColor); // Right.
Gui::Draw_Rect(xPos, yPos + height - w, width, w, outlineColor); // Bottom.
}
extern C2D_SpriteSheet sprites;
void GFX::DrawSprite(int img, int x, int y, float ScaleX, float ScaleY) {
/*
Draw a Sprite of the sprites SpriteSheet.
const int &img: Const Reference to the Image index.
const int &x: Const Reference to the X-Position where to draw.
const int &y: Const Reference to the Y-Position where to draw.
const float &ScaleX: (Optional) Const Reference to the X-Scale of the Sprite. (1 by default)
const float &ScaleY: (Optional) Const Reference to the Y-Scale of the Sprite. (1 by default)
*/
void GFX::DrawSprite(const int &img, const int &x, const int &y, const float &ScaleX, const float &ScaleY) {
Gui::DrawSprite(sprites, img, x, y, ScaleX, ScaleY);
}
void GFX::DrawSpriteBlend(int img, int x, int y, float ScaleX, float ScaleY) {
C2D_ImageTint tint;
C2D_SetImageTint(&tint, C2D_TopLeft, isScriptSelected ? TextColor : config->textColor(), 0.5);
C2D_SetImageTint(&tint, C2D_TopRight, isScriptSelected ? TextColor : config->textColor(), 0.5);
C2D_SetImageTint(&tint, C2D_BotLeft, isScriptSelected ? TextColor : config->textColor(), 0.5);
C2D_SetImageTint(&tint, C2D_BotRight, isScriptSelected ? TextColor : config->textColor(), 0.5);
/*
Draw a button (actually the box) with a centered string in it.
C2D_DrawImageAt(C2D_SpriteSheetGetImage(sprites, img), x, y, 0.5f, &tint, ScaleX, ScaleY);
const float &xPos: Const Reference to the X-Position where to draw the box.
const float &yPos: Const Reference to the Y-Position where to draw the box.
const float &width: Const Reference to the Width of the button.
const float &height: Const Reference to the Height of the button.
const bool &selected: Const Reference, if outline is selected (Red) or not (Black).
const std::string &Text: Const Reference of the Text which should be drawn.
*/
void GFX::DrawButton(const float &xPos, const float &yPos, const float &width, const float &height, const bool &selected, const std::string &Text) {
drawBox(xPos, yPos, width, height, selected);
Gui::DrawStringCentered(xPos - 160 + (width / 2), yPos + (height / 2) - (Gui::GetStringHeight(0.4f, Text) / 2), 0.4f, TEXT_COLOR, Text, width - 4, height - 4);
}
void GFX::DrawArrow(int x, int y, float rotation, int arrowSprite) {
C2D_Sprite sprite;
C2D_ImageTint tint;
C2D_SetImageTint(&tint, C2D_TopLeft, isScriptSelected ? TextColor : config->textColor(), 0.5);
C2D_SetImageTint(&tint, C2D_TopRight, isScriptSelected ? TextColor : config->textColor(), 0.5);
C2D_SetImageTint(&tint, C2D_BotLeft, isScriptSelected ? TextColor : config->textColor(), 0.5);
C2D_SetImageTint(&tint, C2D_BotRight, isScriptSelected ? TextColor : config->textColor(), 0.5);
/*
Draw the checkbox.
if (arrowSprite == 0) {
C2D_SpriteFromSheet(&sprite, sprites, sprites_arrow_idx);
} else {
C2D_SpriteFromSheet(&sprite, sprites, sprites_side_arrow_idx);
}
C2D_SpriteRotateDegrees(&sprite, rotation);
C2D_SpriteSetPos(&sprite, x, y);
C2D_SpriteSetDepth(&sprite, 0.5);
C2D_DrawSpriteTinted(&sprite, &tint);
}
// Draw a Button and draw Text on it.
void GFX::DrawButton(int x, int y, std::string ButtonText, u32 color) {
C2D_ImageTint tint;
C2D_SetImageTint(&tint, C2D_TopLeft, color, 0.5);
C2D_SetImageTint(&tint, C2D_TopRight, color, 0.5);
C2D_SetImageTint(&tint, C2D_BotLeft, color, 0.5);
C2D_SetImageTint(&tint, C2D_BotRight, color, 0.5);
C2D_DrawImageAt(C2D_SpriteSheetGetImage(sprites, sprites_button_idx), x, y, 0.5f, &tint);
Gui::DrawStringCentered(- (158/2) + x, y + (61/2) - (Gui::GetStringHeight(0.6f, ButtonText) / 2), 0.6f, isScriptSelected ? TextColor : config->textColor(), ButtonText, 145, 30);
}
void GFX::TextFormatted(float x, float y, float size, const char *format, ...) {
char str[512];
va_list va;
va_start(va, format);
vsnprintf(str, 512, format, va);
va_end(va);
char * Text = strtok(str, "\n");
Gui::DrawStringCentered(x, y, size, isScriptSelected ? TextColor : config->textColor(), Text);
const float &xPos: Const Reference to the X-Position where to draw the box.
const float &yPos: Const Reference to the Y-Position where to draw the box.
const bool &selected: Const Reference, checked or not.
*/
void GFX::DrawCheckbox(const float &xPos, const float &yPos, const bool &selected) {
GFX::DrawSprite((selected ? sprites_checked_idx : sprites_unchecked_idx), xPos, yPos);
}
-97
View File
@@ -1,97 +0,0 @@
/*
* This file is part of Universal-Updater
* Copyright (C) 2019-2020 Universal-Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "config.hpp"
#include "gfx.hpp"
#include "keyboard.hpp"
#include "screenCommon.hpp"
extern std::unique_ptr<Config> config;
std::string Input::setkbdString(uint maxLength, std::string Text) {
C3D_FrameEnd(0);
SwkbdState state;
swkbdInit(&state, SWKBD_TYPE_NORMAL, 2, maxLength);
char temp[maxLength] = {0};
swkbdSetHintText(&state, Text.c_str());
swkbdSetValidation(&state, SWKBD_NOTBLANK_NOTEMPTY, SWKBD_FILTER_PROFANITY, 0);
SwkbdButton ret = swkbdInputText(&state, temp, sizeof(temp));
temp[maxLength-1] = '\0';
if (ret == SWKBD_BUTTON_CONFIRM) {
return temp;
}
return "";
}
int Input::setInt(int maxValue, std::string Text) {
Gui::clearTextBufs();
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
C2D_TargetClear(Top, BLACK);
GFX::DrawTop();
Gui::DrawStringCentered(0, config->useBars() ? 0 : 2, 0.7f, config->textColor(), Text, 400);
C3D_FrameEnd(0);
SwkbdState state;
swkbdInit(&state, SWKBD_TYPE_NUMPAD, 2, 3);
swkbdSetFeatures(&state, SWKBD_FIXED_WIDTH);
swkbdSetValidation(&state, SWKBD_NOTBLANK_NOTEMPTY, 0, 0);
char input[4] = {0};
SwkbdButton ret = swkbdInputText(&state, input, sizeof(input));
input[3] = '\0';
if (ret == SWKBD_BUTTON_CONFIRM) {
return (int)std::min(std::stoi(input), maxValue);
} else {
return -1;
}
return -1;
}
std::uint8_t Input::setu8(std::string Text) {
Gui::clearTextBufs();
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
C2D_TargetClear(Top, BLACK);
GFX::DrawTop();
Gui::DrawStringCentered(0, config->useBars() ? 0 : 2, 0.7f, config->textColor(), Text, 400);
C3D_FrameEnd(0);
SwkbdState state;
swkbdInit(&state, SWKBD_TYPE_NUMPAD, 2, 3);
swkbdSetFeatures(&state, SWKBD_FIXED_WIDTH);
swkbdSetValidation(&state, SWKBD_NOTBLANK_NOTEMPTY, 0, 0);
char input[4] = {0};
SwkbdButton ret = swkbdInputText(&state, input, sizeof(input));
input[3] = '\0';
if (ret == SWKBD_BUTTON_CONFIRM) {
return (u8)std::min(std::stoi(input), 255);
} else {
return -1;
}
return -1;
}
+65 -59
View File
@@ -27,90 +27,96 @@
#include "common.hpp"
#include "msg.hpp"
extern std::unique_ptr<Config> config;
extern bool isScriptSelected;
/*
Displays just a message until the next draw frame.
extern u32 barColor, bgTopColor, bgBottomColor, TextColor;
// I do not think we need that at all.
void Msg::DisplayStartMSG() {
const std::string &Text: The Message, which should be displayed.
*/
void Msg::DisplayMsg(const std::string &Text) {
Gui::clearTextBufs();
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
C2D_TargetClear(Top, BLACK);
C2D_TargetClear(Bottom, BLACK);
Gui::ScreenDraw(Top);
Gui::Draw_Rect(0, 0, 400, 25, config->barColor());
Gui::Draw_Rect(0, 25, 400, 190, config->topBG());
Gui::Draw_Rect(0, 215, 400, 25, config->barColor());
Gui::DrawStringCentered(0, 2, 0.7f, config->textColor(), Lang::get("STARTING_UNIVERSAL_UPDATER"));
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 400, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
Gui::ScreenDraw(Bottom);
Gui::Draw_Rect(0, 0, 320, 25, config->barColor());
Gui::Draw_Rect(0, 25, 320, 190, config->topBG());
Gui::Draw_Rect(0, 215, 320, 25, config->barColor());
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 320, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
C3D_FrameEnd(0);
}
C2D_TargetClear(Top, TRANSPARENT);
C2D_TargetClear(Bottom, TRANSPARENT);
void Msg::DisplayMsg(std::string text) {
Gui::clearTextBufs();
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
C2D_TargetClear(Top, BLACK);
C2D_TargetClear(Bottom, BLACK);
GFX::DrawTop();
Gui::DrawStringCentered(0, (240-Gui::GetStringHeight(0.6f, text))/2, 0.6f, isScriptSelected ? TextColor : config->textColor(), text, 395, 70);
Gui::DrawStringCentered(0, (240 - Gui::GetStringHeight(0.6f, Text)) / 2, 0.6f, TEXT_COLOR, Text, 395, 100);
GFX::DrawBottom();
C3D_FrameEnd(0);
}
void Msg::DisplayWarnMsg(std::string Text) {
/*
Displays a warn message for 3 seconds.
const std::string &Text: The Message, which should be displayed.
*/
void Msg::DisplayWarnMsg(const std::string &Text) {
Gui::clearTextBufs();
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
C2D_TargetClear(Top, BLACK);
C2D_TargetClear(Bottom, BLACK);
C2D_TargetClear(Top, TRANSPARENT);
C2D_TargetClear(Bottom, TRANSPARENT);
GFX::DrawTop();
Gui::DrawStringCentered(0, 1, 0.6f, isScriptSelected ? TextColor : config->textColor(), Text, 400);
Gui::DrawStringCentered(0, 1, 0.6f, TEXT_COLOR, Text, 400);
GFX::DrawBottom();
C3D_FrameEnd(0);
for (int i = 0; i < 60*3; i++) {
for (int i = 0; i < 60 * 3; i++) {
gspWaitForVBlank();
}
}
/*
Display a Message, which needs to be confirmed with A/B.
const std::vector<Structs::ButtonPos> promptBtn = {
{10, 100, 140, 35}, // Yes.
{170, 100, 140, 35} // No.
};
extern touchPosition touch;
extern bool touching(touchPosition touch, Structs::ButtonPos button);
// Display a Message, which needs to be confirmed with A/B.
bool Msg::promptMsg(std::string promptMsg) {
const std::string &promptMsg: The Message, which should be displayed.
*/
bool Msg::promptMsg(const std::string &promptMsg) {
Gui::clearTextBufs();
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
C2D_TargetClear(Top, BLACK);
C2D_TargetClear(Bottom, BLACK);
C2D_TargetClear(Top, TRANSPARENT);
GFX::DrawTop();
Gui::DrawStringCentered(0, (240-Gui::GetStringHeight(0.6f, promptMsg))/2, 0.6f, isScriptSelected ? TextColor : config->textColor(), promptMsg, 395, 70);
Gui::DrawStringCentered(0, 217, 0.72f, isScriptSelected ? TextColor : config->textColor(), Lang::get("CONFIRM_OR_CANCEL"), 400);
GFX::DrawBottom();
Gui::Draw_Rect(10, 100, 140, 35, isScriptSelected ? barColor : config->barColor());
Gui::Draw_Rect(170, 100, 140, 35, isScriptSelected ? barColor : config->barColor());
Gui::DrawString((320-Gui::GetStringWidth(0.6f, Lang::get("YES")))/2-150+70, 110, 0.6f, isScriptSelected ? TextColor : config->textColor(), Lang::get("YES"), 140);
Gui::DrawString((320-Gui::GetStringWidth(0.6f, Lang::get("NO")))/2+150-70, 110, 0.6f, isScriptSelected ? TextColor : config->textColor(), Lang::get("NO"), 140);
Gui::Draw_Rect(0, 215, 400, 25, BAR_COLOR);
Gui::Draw_Rect(0, 214, 400, 1, BAR_OUTL_COLOR);
Gui::DrawStringCentered(0, (240 - Gui::GetStringHeight(0.6f, promptMsg)) / 2, 0.6f, TEXT_COLOR, promptMsg, 395, 100);
Gui::DrawStringCentered(0, 217, 0.6f, TEXT_COLOR, Lang::get("CONFIRM_OR_CANCEL"), 400);
C3D_FrameEnd(0);
for (int i = 0; i < 20; i++) gspWaitForVBlank();
while(1) {
gspWaitForVBlank();
hidScanInput();
hidTouchRead(&touch);
if ((hidKeysDown() & KEY_A) || (hidKeysDown() & KEY_TOUCH && touching(touch, promptBtn[0]))) {
return true;
} else if ((hidKeysDown() & KEY_B) || (hidKeysDown() & KEY_TOUCH && touching(touch, promptBtn[1]))) {
return false;
}
if (hidKeysDown() & KEY_A) return true;
else if (hidKeysDown() & KEY_B) return false;
}
}
/*
Display a message, which can be "confirmed" with any key.
const std::string &msg: The message which should be displayed.
*/
void Msg::waitMsg(const std::string &msg) {
bool doOut = false;
Gui::clearTextBufs();
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
C2D_TargetClear(Top, TRANSPARENT);
GFX::DrawTop();
Gui::DrawStringCentered(0, (240 - Gui::GetStringHeight(0.6f, msg)) / 2, 0.6f, TEXT_COLOR, msg, 395, 100);
Gui::Draw_Rect(0, 215, 400, 25, BAR_COLOR);
Gui::Draw_Rect(0, 214, 400, 1, BAR_OUTL_COLOR);
Gui::DrawStringCentered(0, 217, 0.6f, TEXT_COLOR, Lang::get("KEY_CONTINUE"), 400);
C3D_FrameEnd(0);
for (int i = 0; i < 20; i++) gspWaitForVBlank();
while(!doOut) {
hidScanInput();
if (hidKeysDown()) doOut = !doOut;
}
}
+85 -129
View File
@@ -24,184 +24,140 @@
* reasonable ways as different from the original version.
*/
#include "config.hpp"
#include "common.hpp"
#include "download.hpp"
#include "init.hpp"
#include "gfx.hpp"
#include "gui.hpp"
#include "lang.hpp"
#include "logging.hpp"
#include "mainMenu.hpp"
#include "screenCommon.hpp"
#include "scriptlist.hpp"
#include "startup.hpp"
#include "sound.h"
#include "unistore.hpp"
#include "mainScreen.hpp"
#include <3ds.h>
#include <dirent.h>
#include <unistd.h>
bool exiting = false;
bool dspFound = false;
bool exiting = false, is3DSX = false;
touchPosition touch;
sound *bgm = NULL;
bool songIsFound = false;
bool UniStoreAutoboot = false;
int AutobootWhat = 0; // 0 -> MainMenu ; 1 -> Store; 2 -> Script.
bool changesMade = false;
// Include all spritesheet's.
C2D_SpriteSheet sprites;
std::unique_ptr<Config> config;
int fadeAlpha = 0;
u32 old_time_limit, hDown = 0;
// If button Position pressed -> Do something.
/*
Set, if 3DSX or CIA.
*/
static void getCurrentUsage(){
u64 id;
APT_GetProgramID(&id);
is3DSX = (id != 0x0004000004391700);
}
/*
If button Position pressed -> Do something.
touchPosition touch: The TouchPosition variable.
Structs::ButtonPos button: The Button Struct.
*/
bool touching(touchPosition touch, Structs::ButtonPos button) {
if (touch.px >= button.x && touch.px <= (button.x + button.w) && touch.py >= button.y && touch.py <= (button.y + button.h))
return true;
else
return false;
if (touch.px >= button.x && touch.px <= (button.x + button.w) && touch.py >= button.y && touch.py <= (button.y + button.h)) return true;
return false;
}
void Init::loadSoundEffects(void) {
if (dspFound) {
if (access(config->musicPath().c_str(), F_OK ) != -1) {
bgm = new sound(config->musicPath(), 1, true);
songIsFound = true;
}
}
}
void Init::playMusic(void) {
if (songIsFound) {
bgm->play();
}
}
void Init::stopMusic(void) {
if (songIsFound) {
bgm->stop();
}
}
/*
Initialize Universal-Updater.
*/
Result Init::Initialize() {
gfxInitDefault();
romfsInit();
amInit();
Gui::init();
cfguInit();
amInit();
acInit();
// Create Folder if missing.
APT_GetAppCpuTimeLimit(&old_time_limit);
APT_SetAppCpuTimeLimit(30); // Needed for QR Scanner to work.
getCurrentUsage();
aptSetSleepAllowed(false);
/* Create Directories, if missing. */
mkdir("sdmc:/3ds", 0777);
mkdir("sdmc:/3ds/Universal-Updater", 0777);
mkdir("sdmc:/3ds/Universal-Updater/scripts", 0777);
mkdir("sdmc:/3ds/Universal-Updater/stores", 0777);
// We need to make sure, the file exist.
config = std::make_unique<Config>();
Lang::load(config->language());
if (config->screenFade()) {
fadein = true;
fadealpha = 255;
}
// In case it takes a bit longer to autoboot a script or so.
Msg::DisplayStartMSG();
if (config->logging()) {
Logging::createLogFile();
}
Gui::loadSheet("romfs:/gfx/sprites.t3x", sprites);
AutobootWhat = config->autoboot();
if (!config->firstStartup()) {
if (AutobootWhat == 1) {
if (access(config->autobootFile().c_str(), F_OK) == 0) {
Gui::setScreen(std::make_unique<UniStore>(true, config->autobootFile()), false, true);
} else {
AutobootWhat = 0;
config->autoboot(0);
Gui::setScreen(std::make_unique<MainMenu>(), false, true);
}
} else if (AutobootWhat == 2) {
if (access(config->autobootFile().c_str(), F_OK) == 0) {
Gui::setScreen(std::make_unique<ScriptList>(), false, true);
} else {
AutobootWhat = 0;
config->autoboot(0);
Gui::setScreen(std::make_unique<MainMenu>(), false, true);
}
} else {
AutobootWhat = 0;
config->autoboot(0);
Gui::setScreen(std::make_unique<MainMenu>(), false, true);
}
osSetSpeedupEnable(true); // Enable speed-up for New 3DS users.
/* Check here for updates. */
if (config->updatecheck()) {
if (IsUUUpdateAvailable()) UpdateAction();
}
if (config->firstStartup()) {
Gui::setScreen(std::make_unique<Startup>(AutobootWhat, config->autobootFile()), false, true);
}
osSetSpeedupEnable(true); // Enable speed-up for New 3DS users
if ( access( "sdmc:/3ds/dspfirm.cdc", F_OK ) != -1 ) {
ndspInit();
dspFound = true;
loadSoundEffects();
playMusic();
}
if (exiting) return -1; // In case the update was successful.
Gui::setScreen(std::make_unique<MainScreen>(), false, false);
return 0;
}
/*
MainLoop of Universal-Updater.
*/
Result Init::MainLoop() {
// Initialize everything.
Initialize();
// Loop as long as the status is not exiting.
while (aptMainLoop()) {
bool fullExit = false;
if (Initialize() == -1) fullExit = true;
hidSetRepeatParameters(20, 10);
/* Loop as long as the status is not fullExit. */
while (aptMainLoop() && !fullExit) {
hidScanInput();
u32 hHeld = hidKeysHeld();
u32 hDown = hidKeysDown();
hDown = hidKeysDown();
hRepeat = hidKeysDownRepeat();
hidTouchRead(&touch);
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
C2D_TargetClear(Top, BLACK);
C2D_TargetClear(Bottom, BLACK);
Gui::clearTextBufs();
Gui::DrawScreen(true);
Gui::ScreenLogic(hDown, hHeld, touch, true, true);
C3D_FrameEnd(0);
gspWaitForVBlank();
if (exiting) {
if (!fadeout) break;
}
Gui::fadeEffects(16, 16, true);
Gui::clearTextBufs();
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
C2D_TargetClear(Top, C2D_Color32(0, 0, 0, 0));
C2D_TargetClear(Bottom, C2D_Color32(0, 0, 0, 0));
Gui::DrawScreen(false);
if (!exiting) Gui::ScreenLogic(hDown, hHeld, touch, true, false);
C3D_FrameEnd(0);
if (exiting) {
if (hDown & KEY_START) fullExit = true; // Make it optionally faster.
if (fadeAlpha < 255) {
fadeAlpha += 2;
if (fadeAlpha >= 255) {
fullExit = true;
}
}
}
}
// Exit all services and exit the app.
/* Exit all services and exit the app. */
Exit();
return 0;
}
/*
Exit Universal-Updater.
*/
Result Init::Exit() {
if (songIsFound) {
stopMusic();
}
delete bgm;
if (dspFound) {
ndspExit();
}
config->save();
Gui::exit();
Gui::unloadSheet(sprites);
gfxExit();
cfguExit();
config->save();
acExit();
amExit();
if (old_time_limit != UINT32_MAX) APT_SetAppCpuTimeLimit(old_time_limit); // Restore old limit.
aptSetSleepAllowed(true);
romfsExit();
return 0;
}
+49
View File
@@ -0,0 +1,49 @@
/*
* This file is part of Universal-Updater
* Copyright (C) 2019-2020 Universal-Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "gfx.hpp"
#include "keyboard.hpp"
#include "screenCommon.hpp"
/*
Return a string of the keyboard.
const uint &maxLength: Const Reference to the max length.
const std::string &Text: Const Reference to the Text.
*/
std::string Input::setkbdString(const uint &maxLength, const std::string &Text) {
C3D_FrameEnd(0); // Needed, so the system will not freeze.
SwkbdState state;
swkbdInit(&state, SWKBD_TYPE_NORMAL, 2, maxLength);
char temp[maxLength] = { 0 };
swkbdSetHintText(&state, Text.c_str());
swkbdSetValidation(&state, SWKBD_NOTBLANK_NOTEMPTY, SWKBD_FILTER_PROFANITY, 0);
SwkbdButton ret = swkbdInputText(&state, temp, maxLength);
temp[maxLength - 1] = '\0';
return (ret == SWKBD_BUTTON_CONFIRM ? temp : "");
}
-78
View File
@@ -1,78 +0,0 @@
/*
* This file is part of Universal-Updater
* Copyright (C) 2019-2020 Universal-Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "config.hpp"
#include "lang.hpp"
#include <stdio.h>
#include <unistd.h>
extern std::unique_ptr<Config> config;
nlohmann::json appJson;
std::string Lang::get(const std::string &key) {
if (!appJson.contains(key)) {
return "MISSING: " + key;
}
return appJson.at(key).get_ref<const std::string&>();
}
std::string langs[] = {"br", "da", "de", "en", "es", "fr", "it", "lt", "pl", "pt", "ru", "jp"};
void Lang::load(const std::string lang) {
FILE* values;
if (config->langPath() == 1) {
// Check if exist.
if (access("sdmc:/3ds/Universal-Updater/app.json", F_OK) == 0) {
values = fopen(("sdmc:/3ds/Universal-Updater/app.json"), "rt");
appJson = nlohmann::json::parse(values, nullptr, false);
fclose(values);
return;
} else {
values = fopen(("romfs:/lang/en/app.json"), "rt");
appJson = nlohmann::json::parse(values, nullptr, false);
fclose(values);
return;
}
} else {
// Check if exist.
if (access(("romfs:/lang/" + lang + "/app.json").c_str(), F_OK) == 0) {
values = fopen(std::string(("romfs:/lang/" + lang + "/app.json")).c_str(), "rt");
appJson = nlohmann::json::parse(values, nullptr, false);
fclose(values);
return;
} else {
values = fopen(("romfs:/lang/en/app.json"), "rt");
appJson = nlohmann::json::parse(values, nullptr, false);
fclose(values);
return;
}
}
}
-71
View File
@@ -1,71 +0,0 @@
/*
* This file is part of Universal-Updater
* Copyright (C) 2019-2020 Universal-Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "config.hpp"
#include "logging.hpp"
#include <memory>
extern std::unique_ptr<Config> config;
std::string Logging::format(const std::string& fmt_str, ...) {
va_list ap;
char* fp = NULL;
va_start(ap, fmt_str);
vasprintf(&fp, fmt_str.c_str(), ap);
va_end(ap);
std::unique_ptr<char, decltype(free)*> formatted(fp, free);
return std::string(formatted.get());
}
std::string Logging::logDate(void) {
time_t unixTime;
struct tm timeStruct;
time(&unixTime);
localtime_r(&unixTime, &timeStruct);
return format("%04i-%02i-%02i %02i:%02i:%02i", timeStruct.tm_year + 1900, timeStruct.tm_mon + 1, timeStruct.tm_mday, timeStruct.tm_hour, timeStruct.tm_min, timeStruct.tm_sec);
}
void Logging::createLogFile(void) {
if ((access("sdmc:/3ds/Universal-Updater/Log.log", F_OK) != 0)) {
FILE* logFile = fopen(("sdmc:/3ds/Universal-Updater/Log.log"), "w");
fclose(logFile);
}
}
// Only write to the Log, if it is enabled in the Settings File!
void Logging::writeToLog(std::string debugText) {
if (config->logging()) {
std::ofstream logFile;
logFile.open(("sdmc:/3ds/Universal-Updater/Log.log"), std::ofstream::app);
std::string writeDebug = "[ ";
writeDebug += logDate();
writeDebug += " ] ";
writeDebug += debugText.c_str();
logFile << writeDebug << std::endl;
logFile.close();
}
}
+7 -3
View File
@@ -25,8 +25,12 @@
*/
#include "init.hpp"
#include <string>
int main() {
Init::MainLoop(); // Init::MainLoop() has the whole logic already. ;P
return 0;
std::string _3dsxPath = "";
int main(int argc, char *argv[]) {
if (argc > 0) _3dsxPath = argv[0];
return Init::MainLoop();
}
-179
View File
@@ -1,179 +0,0 @@
/*
* This file is part of Universal-Updater
* Copyright (C) 2019-2020 Universal-Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "colorHelper.hpp"
#include "config.hpp"
#include "gui.hpp"
#include "keyboard.hpp"
#include "overlay.hpp"
#include "structs.hpp"
extern std::unique_ptr<Config> config;
extern touchPosition touch;
extern bool touching(Structs::ButtonPos button);
// Draw RGB Colors.
static void DrawRGBColor(u8 r, u8 g, u8 b) {
// Display RGB line.
for (int i = 0; i < 256; i++) {
Gui::Draw_Rect((10 + i), 30, 1, 20, C2D_Color32(i, 0, 0, 255));
Gui::Draw_Rect((10 + i), 80, 1, 20, C2D_Color32(0, i, 0, 255));
Gui::Draw_Rect((10 + i), 130, 1, 20, C2D_Color32(0, 0, i, 255));
}
Gui::Draw_Rect((10 + r), 30, 1, 20, C2D_Color32(255, 255, 255, 255));
Gui::Draw_Rect((10 + g), 80, 1, 20, C2D_Color32(255, 255, 255, 255));
Gui::Draw_Rect((10 + b), 130, 1, 20, C2D_Color32(255, 255, 255, 255));
// Display RGB Boxes.
Gui::Draw_Rect(270, 30, 40, 20, C2D_Color32(200, 200, 200, 255));
Gui::Draw_Rect(270, 80, 40, 20, C2D_Color32(200, 200, 200, 255));
Gui::Draw_Rect(270, 130, 40, 20, C2D_Color32(200, 200, 200, 255));
// Display Values.
Gui::DrawStringCentered(-(40 / 2) + 150, 30 + (20/2) - (Gui::GetStringHeight(0.6f, std::to_string(r)) / 2), 0.6f, C2D_Color32(0, 0, 0, 255), std::to_string(r), 40, 20);
Gui::DrawStringCentered(-(40 / 2) + 150, 80 + (20/2) - (Gui::GetStringHeight(0.6f, std::to_string(g)) / 2), 0.6f, C2D_Color32(0, 0, 0, 255), std::to_string(g), 40, 20);
Gui::DrawStringCentered(-(40 / 2) + 150, 130 + (20/2) - (Gui::GetStringHeight(0.6f, std::to_string(b)) / 2), 0.6f, C2D_Color32(0, 0, 0, 255), std::to_string(b), 40, 20);
// Display as formated string.
char hexValues[16];
snprintf(hexValues, sizeof hexValues, "#%02x%02x%02x", r, g, b);
Gui::DrawStringCentered(0, 158, 0.7f, config->textColor(), "RGB: " + std::to_string(r) + ", " + std::to_string(g) + ", " + std::to_string(b) + " - Hex: " + hexValues, 310);
Gui::Draw_Rect(110, 180, 100, 30, C2D_Color32(r, g, b, 255));
}
// Draw.
static void Draw(u8 r, u8 g, u8 b) {
Gui::clearTextBufs();
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
C2D_TargetClear(Top, C2D_Color32(0, 0, 0, 0));
C2D_TargetClear(Bottom, C2D_Color32(0, 0, 0, 0));
GFX::DrawTop();
Gui::Draw_Rect(0, 0, 400, 240, C2D_Color32(0, 0, 0, 190));
Gui::DrawStringCentered(0, config->useBars() ? 0 : 2, 0.7f, config->textColor(), Lang::get("SELECT_RGB_COLOR"), 400);
Gui::DrawStringCentered(0, (240-Gui::GetStringHeight(0.7f, Lang::get("UI_COLOR_BEHAVIOUR")))/2, 0.7f, config->textColor(), Lang::get("UI_COLOR_BEHAVIOUR"), 390, 70);
Gui::ScreenDraw(Bottom);
Gui::Draw_Rect(0, 0, 320, 240, config->bottomBG() + C2D_Color32(0, 0, 0, 190));
DrawRGBColor(r, g, b);
C3D_FrameEnd(0);
}
u32 Overlays::SelectRGB(u32 oldColor) {
u8 r = ColorHelper::getColorValue(oldColor, 2);
u8 g = ColorHelper::getColorValue(oldColor, 1);
u8 b = ColorHelper::getColorValue(oldColor, 0);
int selection = 0;
while(1) {
Draw(r, g, b);
hidScanInput();
hidTouchRead(&touch);
if (hidKeysDown() & KEY_UP) {
if (selection > 0) selection--;
}
if (hidKeysDown() & KEY_DOWN) {
if (selection < 2) selection++;
}
if (hidKeysHeld() & KEY_RIGHT) {
switch(selection) {
case 0: // Red.
if (r < 255) r++;
break;
case 1: // Green.
if (g < 255) g++;
break;
case 2:
if (b < 255) b++;
break;
}
}
if (hidKeysHeld() & KEY_LEFT) {
switch(selection) {
case 0: // Red.
if (r > 0) r--;
break;
case 1: // Green.
if (g > 0) g--;
break;
case 2:
if (b > 0) b--;
break;
}
}
if (hidKeysDown() & KEY_START) {
return RGBA8(r, g, b, 255);
}
if (hidKeysDown() & KEY_B) {
return oldColor;
}
if (hidKeysHeld() & KEY_TOUCH) {
for (int i = 0; i < 256; i++) {
if (touch.px >= (10 + i) && touch.px <= (10 + i) + 1 && touch.py >= 30 && touch.py <= 30 + 20) {
r = i;
}
if (touch.px >= (10 + i) && touch.px <= (10 + i) + 1 && touch.py >= 80 && touch.py <= 80 + 20) {
g = i;
}
if (touch.px >= (10 + i) && touch.px <= (10 + i) + 1 && touch.py >= 130 && touch.py <= 130 + 20) {
b = i;
}
}
}
// Change RGB Value on the next button!
if (hidKeysDown() & KEY_TOUCH) {
if (touch.px >= 270 && touch.px <= 270 + 40 && touch.py >= 30 && touch.py <= 30 + 20) {
int temp = Input::setu8(Lang::get("ENTER_RED_RGB"));
if (temp != -1) {
r = temp;
}
} else if (touch.px >= 270 && touch.px <= 270 + 40 && touch.py >= 80 && touch.py <= 80 + 20) {
int temp = Input::setu8(Lang::get("ENTER_GREEN_RGB"));
if (temp != -1) {
g = temp;
}
} else if (touch.px >= 270 && touch.px <= 270 + 40 && touch.py >= 130 && touch.py <= 130 + 20) {
int temp = Input::setu8(Lang::get("ENTER_BLUE_RGB"));
if (temp != -1) {
b = temp;
}
}
}
}
}
+65
View File
@@ -0,0 +1,65 @@
/*
* This file is part of Universal-Updater
* Copyright (C) 2019-2020 Universal-Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "overlay.hpp"
/*
Show the Credits.
*/
void Overlays::ShowCredits() {
bool doOut = false;
while(!doOut) {
Gui::clearTextBufs();
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
C2D_TargetClear(Top, TRANSPARENT);
C2D_TargetClear(Bottom, TRANSPARENT);
GFX::DrawTop();
GFX::DrawSprite(sprites_universal_updater_idx, 220, 30);
Gui::DrawStringCentered(0, 1, 0.7f, TEXT_COLOR, "Universal-Updater - " + Lang::get("CREDITS"));
Gui::DrawString(10, 30, 0.5f, TEXT_COLOR, "- Universal-Team");
Gui::DrawString(10, 50, 0.5f, TEXT_COLOR, "- devkitPro");
Gui::DrawString(10, 70, 0.5f, TEXT_COLOR, "- dlbeer");
Gui::DrawString(10, 90, 0.5f, TEXT_COLOR, "- FlagBrew");
Gui::DrawString(10, 110, 0.5f, TEXT_COLOR, "- https://icons8.com/");
Gui::DrawString(10, 130, 0.5f, TEXT_COLOR, "- PabloMK7");
Gui::DrawString(10, 150, 0.5f, TEXT_COLOR, Lang::get("CONTRIBUTOR_TRANSLATORS"));
Gui::DrawString(10, 195, 0.5f, TEXT_COLOR, Lang::get("GITHUB"));
Gui::Draw_Rect(0, 215, 400, 25, BAR_COLOR);
Gui::Draw_Rect(0, 214, 400, 1, BAR_OUTL_COLOR);
Gui::DrawStringCentered(0, 217, 0.6f, TEXT_COLOR, Lang::get("CURRENT_VERSION") + std::string(V_STRING), 390);
GFX::DrawBottom();
GFX::DrawSprite(sprites_universal_core_idx, 0, 26);
C3D_FrameEnd(0);
hidScanInput();
if ((hidKeysDown() & KEY_START) || (hidKeysDown() & KEY_B) || (hidKeysDown() & KEY_A)) doOut = true;
}
}
+187
View File
@@ -0,0 +1,187 @@
/*
* This file is part of Universal-Updater
* Copyright (C) 2019-2020 Universal-Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "fileBrowse.hpp"
#include "overlay.hpp"
#include <unistd.h>
extern bool touching(touchPosition touch, Structs::ButtonPos button);
static const std::vector<Structs::ButtonPos> mainButtons = {
{ 10, 6, 300, 22 },
{ 10, 36, 300, 22 },
{ 10, 66, 300, 22 },
{ 10, 96, 300, 22 },
{ 10, 126, 300, 22 },
{ 10, 156, 300, 22 },
{ 10, 186, 300, 22 }
};
/*
Select a Directory.
*/
std::string Overlays::SelectDir(const std::string &oldDir, const std::string &msg) {
std::string currentPath = oldDir;
bool dirChanged = true;
int selection = 0, sPos = 0;
std::vector<DirEntry> dirContents;
if (dirChanged) {
dirChanged = false;
dirContents.clear();
chdir(oldDir.c_str());
std::vector<DirEntry> dirContentsTemp;
getDirectoryContents(dirContentsTemp, {"/"});
for(uint i = 0; i < dirContentsTemp.size(); i++) {
dirContents.push_back(dirContentsTemp[i]);
}
}
while(1) {
Gui::clearTextBufs();
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
C2D_TargetClear(Top, TRANSPARENT);
C2D_TargetClear(Bottom, TRANSPARENT);
GFX::DrawTop();
Gui::DrawStringCentered(0, 1, 0.7f, TEXT_COLOR, msg, 380);
Gui::Draw_Rect(0, 215, 400, 25, BAR_COLOR);
Gui::Draw_Rect(0, 214, 400, 1, BAR_OUTL_COLOR);
Gui::DrawStringCentered(0, 217, 0.6f, TEXT_COLOR, currentPath, 390);
GFX::DrawBottom();
Gui::Draw_Rect(0, 215, 320, 25, BAR_COLOR);
Gui::Draw_Rect(0, 214, 320, 1, BAR_OUTL_COLOR);
Gui::DrawStringCentered(0, 220, 0.5f, TEXT_COLOR, Lang::get("START_SELECT"), 390);
if (dirContents.size() > 0) {
for(int i = 0; i < 7 && i < (int)dirContents.size(); i++) {
GFX::drawBox(10, mainButtons[i].y, 300, 22, sPos + i == selection);
Gui::DrawStringCentered(10 - 160 + (300 / 2), mainButtons[i].y + 4, 0.45f, TEXT_COLOR, dirContents[sPos + i].name, 295);
}
}
C3D_FrameEnd(0);
if (dirChanged) {
dirChanged = false;
selection = 0;
sPos = 0;
dirContents.clear();
std::vector<DirEntry> dirContentsTemp;
getDirectoryContents(dirContentsTemp, {"/"});
for(uint i = 0; i < dirContentsTemp.size(); i++) {
dirContents.push_back(dirContentsTemp[i]);
}
}
hidScanInput();
touchPosition touch;
hidTouchRead(&touch);
u32 hRepeat = hidKeysDownRepeat();
if (dirContents.size() > 0) {
if (hRepeat & KEY_DOWN) {
if (selection < (int)dirContents.size() - 1) selection++;
else selection = 0;
}
if (hRepeat & KEY_UP) {
if (selection > 0) selection--;
else selection = dirContents.size() - 1;
}
if (hRepeat & KEY_RIGHT) {
if (selection + 7 < (int)dirContents.size()-1) selection += 7;
else selection = dirContents.size()-1;
}
if (hRepeat & KEY_LEFT) {
if (selection - 7 > 0) selection -= 7;
else selection = 0;
}
if (hidKeysDown() & KEY_A) {
if (dirContents[selection].isDirectory) {
chdir(dirContents[selection].name.c_str());
char path[PATH_MAX];
getcwd(path, PATH_MAX);
currentPath = path;
dirChanged = true;
}
}
if (hidKeysDown() & KEY_TOUCH) {
for (int i = 0; i < 6; i++) {
if (touching(touch, mainButtons[i])) {
if (i + sPos < (int)dirContents.size()) {
if (dirContents[i + sPos].isDirectory) {
chdir(dirContents[i + sPos].name.c_str());
char path[PATH_MAX];
getcwd(path, PATH_MAX);
currentPath = path;
dirChanged = true;
break;
}
}
}
}
}
if (selection < sPos) sPos = selection;
else if (selection > sPos + 7 - 1) sPos = selection - 7 + 1;
}
if ((hidKeysDown() & KEY_X) || (hidKeysDown() & KEY_START)) {
if (currentPath.size() > 0 && currentPath.back() == '/') currentPath.pop_back(); // Pop back the "/".
return currentPath;
}
if (hidKeysDown() & KEY_B) {
char path[PATH_MAX];
getcwd(path, PATH_MAX);
if (strcmp(path, "sdmc:/") == 0 || strcmp(path, "/") == 0) {
return "";
} else {
chdir("..");
getcwd(path, PATH_MAX);
currentPath = path;
dirChanged = true;
}
}
}
}
+124
View File
@@ -0,0 +1,124 @@
/*
* This file is part of Universal-Updater
* Copyright (C) 2019-2020 Universal-Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "fileBrowse.hpp"
#include "keyboard.hpp"
#include "overlay.hpp"
#include "scriptUtils.hpp"
#include "storeUtils.hpp"
extern bool checkWifiStatus();
extern bool touching(touchPosition touch, Structs::ButtonPos button);
static const std::vector<std::string> languages = { "Bruh", "Dansk", "Deutsch", "English", "Español", "Français", "Italiano", "Lietuvių", "Polski", "Português", "Русский", "日本語" };
static const std::string langsTemp[] = { "br", "da", "de", "en", "es", "fr", "it", "lt", "pl", "pt", "ru", "jp "};
static const std::vector<Structs::ButtonPos> mainButtons = {
{ 85, 4, 150, 22 },
{ 85, 34, 150, 22 },
{ 85, 64, 150, 22 },
{ 85, 94, 150, 22 },
{ 85, 124, 150, 22 },
{ 85, 154, 150, 22 },
{ 85, 184, 150, 22 },
{ 85, 214, 150, 22 }
};
/*
Select a Language.
Can be skipped with `B`.
*/
void Overlays::SelectLanguage() {
bool doOut = false;
int selection = 0, sPos = 0;
while(!doOut) {
Gui::clearTextBufs();
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
C2D_TargetClear(Top, TRANSPARENT);
C2D_TargetClear(Bottom, TRANSPARENT);
GFX::DrawTop();
Gui::DrawStringCentered(0, 1, 0.7f, TEXT_COLOR, Lang::get("SELECT_LANG"));
GFX::DrawBottom();
for(int i = 0; i < 8 && i < (int)languages.size(); i++) {
GFX::drawBox(85, mainButtons[i].y, 150, 22, sPos + i == selection);
Gui::DrawStringCentered(0, mainButtons[i].y + 4, 0.45f, TEXT_COLOR, languages[sPos + i], 280);
}
C3D_FrameEnd(0);
hidScanInput();
touchPosition touch;
hidTouchRead(&touch);
u32 hRepeat = hidKeysDownRepeat();
if (hRepeat & KEY_DOWN) {
if (selection < (int)languages.size() - 1) selection++;
else selection = 0;
}
if (hRepeat & KEY_UP) {
if (selection > 0) selection--;
else selection = languages.size() - 1;
}
if (hRepeat & KEY_RIGHT) {
if (selection + 8 < (int)languages.size()-1) selection += 8;
else selection = languages.size()-1;
}
if (hRepeat & KEY_LEFT) {
if (selection - 8 > 0) selection -= 8;
else selection = 0;
}
if (hidKeysDown() & KEY_A) {
const std::string l = langsTemp[selection];
config->language(l);
Lang::load(config->language());
doOut = true;
}
if (hidKeysDown() & KEY_TOUCH) {
for (int i = 0; i < 8; i++) {
if (touching(touch, mainButtons[i])) {
if (i + sPos < (int)languages.size()) {
const std::string l = langsTemp[i + sPos];
config->language(l);
Lang::load(config->language());
doOut = true;
}
}
}
}
if (selection < sPos) sPos = selection;
else if (selection > sPos + 8 - 1) sPos = selection - 8 + 1;
if (hidKeysDown() & KEY_B) doOut = true;
}
}
+322
View File
@@ -0,0 +1,322 @@
/*
* This file is part of Universal-Updater
* Copyright (C) 2019-2020 Universal-Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "download.hpp"
#include "fileBrowse.hpp"
#include "files.hpp"
#include "keyboard.hpp"
#include "overlay.hpp"
#include "qrcode.hpp"
#include "scriptUtils.hpp"
#include "storeUtils.hpp"
#include <unistd.h>
extern bool checkWifiStatus();
extern bool touching(touchPosition touch, Structs::ButtonPos button);
static const std::vector<Structs::ButtonPos> mainButtons = {
{ 10, 4, 300, 22 },
{ 10, 34, 300, 22 },
{ 10, 64, 300, 22 },
{ 10, 94, 300, 22 },
{ 10, 124, 300, 22 },
{ 10, 154, 300, 22 },
{ 10, 184, 300, 22 },
/* Add, Delete, Info.. */
{ 92, 215, 16, 16 },
{ 136, 215, 16, 16 },
{ 180, 215, 16, 16 },
{ 224, 215, 16, 16 }
};
/*
Delete a Store.. including the Spritesheets, if found.
const std::string &file: The file of the UniStore.
*/
static void DeleteStore(const std::string &file) {
FILE *temp = fopen((std::string(_STORE_PATH) + file).c_str(), "rt");
nlohmann::json storeJson = nlohmann::json::parse(temp, nullptr, false);
fclose(temp);
/* Check, if Spritesheet exist on UniStore. */
if (storeJson["storeInfo"].contains("sheet") && storeJson["storeInfo"]["sheet"].is_array()) {
const std::vector<std::string> sht = storeJson["storeInfo"]["sheet"].get<std::vector<std::string>>();
/* Cause it's an array, delete all Spritesheets which exist. */
for (int i = 0; i < (int)sht.size(); i++) {
if ((std::string(_STORE_PATH) + sht[i]) != "") {
if (!(StringUtils::lower_case(sht[i]).find(StringUtils::lower_case("/")) != std::string::npos)) {
if (access((std::string(_STORE_PATH) + sht[i]).c_str(), F_OK) == 0) {
deleteFile((std::string(_STORE_PATH) + sht[i]).c_str());
}
}
}
}
/* Else, if it's just a string.. check and delete single Spritesheet. */
} else if (storeJson["storeInfo"].contains("sheetURL") && storeJson["storeInfo"]["sheetURL"].is_string()) {
const std::string fl = storeJson["storeInfo"]["sheet"];
if ((std::string(_STORE_PATH) + fl) != "") {
if (!(StringUtils::lower_case(fl).find(StringUtils::lower_case("/")) != std::string::npos)) {
if (access((std::string(_STORE_PATH) + fl).c_str(), F_OK) == 0) {
deleteFile((std::string(_STORE_PATH) + fl).c_str());
}
}
}
}
deleteFile((std::string(_STORE_PATH) + file).c_str()); // Now delete UniStore.
}
/*
Download a Store.. including the SpriteSheets, if found.
bool Cam: if cam should be used.
*/
static bool DownloadStore(bool Cam = true) {
bool doSheet = false;
std::string file = "";
const std::string URL = Cam ? QR_Scanner::GetQRURL() : Input::setkbdString(150, Lang::get("ENTER_URL"));
if (URL != "") doSheet = DownloadUniStore(URL, -1, file, true);
if (doSheet) {
FILE *temp = fopen(file.c_str(), "rt");
nlohmann::json storeJson = nlohmann::json::parse(temp, nullptr, false);
fclose(temp);
if (doSheet) {
if (storeJson["storeInfo"].contains("sheetURL") && storeJson["storeInfo"]["sheetURL"].is_array()) {
if (storeJson["storeInfo"].contains("sheet") && storeJson["storeInfo"]["sheet"].is_array()) {
const std::vector<std::string> locs = storeJson["storeInfo"]["sheetURL"].get<std::vector<std::string>>();
const std::vector<std::string> sht = storeJson["storeInfo"]["sheet"].get<std::vector<std::string>>();
if (locs.size() == sht.size()) {
for (int i = 0; i < (int)sht.size(); i++) {
if (!(sht[i].find("/") != std::string::npos)) {
char msg[150];
snprintf(msg, sizeof(msg), Lang::get("DOWNLOADING_SPRITE_SHEET2").c_str(), i + 1, sht.size());
Msg::DisplayMsg(msg);
DownloadSpriteSheet(locs[i], sht[i]);
} else {
Msg::waitMsg(Lang::get("SHEET_SLASH"));
}
}
}
}
} else if (storeJson["storeInfo"].contains("sheetURL") && storeJson["storeInfo"]["sheetURL"].is_string()) {
if (storeJson["storeInfo"].contains("sheet") && storeJson["storeInfo"]["sheet"].is_string()) {
const std::string fl = storeJson["storeInfo"]["sheetURL"];
const std::string fl2 = storeJson["storeInfo"]["sheet"];
if (!(fl2.find("/") != std::string::npos)) {
Msg::DisplayMsg(Lang::get("DOWNLOADING_SPRITE_SHEET"));
DownloadSpriteSheet(fl, fl2);
} else {
Msg::waitMsg(Lang::get("SHEET_SLASH"));
}
}
}
}
}
return doSheet;
}
/*
This is the UniStore Manage Handle.
Here you can..
- Delete a UniStore.
- Download / Add a UniStore.
- Check for Updates for a UniStore.
- Switch the UniStore.
std::unique_ptr<Store> &store: Reference to the Store class.
std::vector<std::unique_ptr<StoreEntry>> &entries: Reference to the Store Entries.
std::unique_ptr<Meta> &meta: Reference to the Meta class.
*/
void Overlays::SelectStore(std::unique_ptr<Store> &store, std::vector<std::unique_ptr<StoreEntry>> &entries, std::unique_ptr<Meta> &meta) {
bool doOut = false;
int selection = 0, sPos = 0;
std::vector<UniStoreInfo> info = GetUniStoreInfo(_STORE_PATH);
while(!doOut) {
Gui::clearTextBufs();
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
C2D_TargetClear(Top, TRANSPARENT);
C2D_TargetClear(Bottom, TRANSPARENT);
GFX::DrawTop();
Gui::DrawStringCentered(0, 1, 0.7f, TEXT_COLOR, Lang::get("SELECT_UNISTORE_2"));
if (info.size() > 0) {
if (info[selection].StoreSize != -1) {
Gui::DrawStringCentered(0, 30, 0.6f, TEXT_COLOR, info[selection].Title, 370);
Gui::DrawStringCentered(0, 60, 0.5f, TEXT_COLOR, info[selection].Author, 370);
if (info[selection].Description != "") {
/* "\n\n" breaks C2D_WordWrap, so check here. */
if (!(info[selection].Description.find("\n\n") != std::string::npos)) {
Gui::DrawStringCentered(0, 100, 0.5f, TEXT_COLOR, info[selection].Description, 390, 95, nullptr, C2D_WordWrap);
} else {
Gui::DrawStringCentered(0, 100, 0.5f, TEXT_COLOR, info[selection].Description, 390, 95);
}
}
} else {
Gui::DrawStringCentered(0, 30, 0.6f, TEXT_COLOR, Lang::get("INVALID_UNISTORE"), 370);
}
Gui::DrawString(10, 200, 0.4, TEXT_COLOR, "- " + Lang::get("ENTRIES") + ": " + std::to_string(info[selection].StoreSize));
Gui::DrawString(10, 210, 0.4, TEXT_COLOR, "- " + Lang::get("VERSION") + ": " + std::to_string(info[selection].Version));
Gui::DrawString(10, 220, 0.4, TEXT_COLOR, "- " + Lang::get("REVISION") + ": " + std::to_string(info[selection].Revision));
GFX::DrawBottom();
for(int i = 0; i < 7 && i < (int)info.size(); i++) {
GFX::drawBox(10, mainButtons[i].y, 300, 22, sPos + i == selection);
Gui::DrawStringCentered(10 - 160 + (300 / 2), mainButtons[i].y + 4, 0.45f, TEXT_COLOR, info[sPos + i].FileName, 295);
}
}
if (info.size() <= 0) GFX::DrawBottom(); // Otherwise we'd draw on top.
GFX::DrawSprite(sprites_delete_idx, mainButtons[7].x, mainButtons[7].y);
GFX::DrawSprite(sprites_update_idx, mainButtons[8].x, mainButtons[8].y);
GFX::DrawSprite(sprites_add_idx, mainButtons[9].x, mainButtons[9].y);
GFX::DrawSprite(sprites_qr_code_idx, mainButtons[10].x, mainButtons[10].y);
C3D_FrameEnd(0);
hidScanInput();
touchPosition touch;
hidTouchRead(&touch);
u32 hRepeat = hidKeysDownRepeat();
if (info.size() > 0) {
if (hRepeat & KEY_DOWN) {
if (selection < (int)info.size() - 1) selection++;
else selection = 0;
}
if (hRepeat & KEY_UP) {
if (selection > 0) selection--;
else selection = info.size() - 1;
}
if (hRepeat & KEY_RIGHT) {
if (selection + 7 < (int)info.size()-1) selection += 7;
else selection = info.size()-1;
}
if (hRepeat & KEY_LEFT) {
if (selection - 7 > 0) selection -= 8;
else selection = 0;
}
if (hidKeysDown() & KEY_A) {
/* Load selected one. */
if (info[selection].Version == -1) Msg::waitMsg(Lang::get("UNISTORE_INVALID_ERROR"));
else if (info[selection].Version < 3) Msg::waitMsg(Lang::get("UNISTORE_TOO_OLD"));
else if (info[selection].Version > 3) Msg::waitMsg(Lang::get("UNISTORE_TOO_NEW"));
else {
store = std::make_unique<Store>(_STORE_PATH + info[selection].FileName);
StoreUtils::ResetAll(store, meta, entries);
config->lastStore(info[selection].FileName);
StoreUtils::SortEntries(false, SortType::LAST_UPDATED, entries);
doOut = true;
}
}
if (hidKeysDown() & KEY_TOUCH) {
for (int i = 0; i < 7; i++) {
if (touching(touch, mainButtons[i])) {
if (i + sPos < (int)info.size()) {
if (info[i + sPos].Version == -1) Msg::waitMsg(Lang::get("UNISTORE_INVALID_ERROR"));
else if (info[i + sPos].Version < 3) Msg::waitMsg(Lang::get("UNISTORE_TOO_OLD"));
else if (info[i + sPos].Version > 3) Msg::waitMsg(Lang::get("UNISTORE_TOO_NEW"));
else {
store = std::make_unique<Store>(_STORE_PATH + info[i + sPos].FileName);
StoreUtils::ResetAll(store, meta, entries);
config->lastStore(info[i + sPos].FileName);
doOut = true;
}
}
}
}
}
if (hidKeysDown() & KEY_TOUCH && touching(touch, mainButtons[8])) {
if (checkWifiStatus()) {
if (info[selection].Revision > 0) {
const bool result = IsUpdateAvailable(info[selection].URL, info[selection].Revision);
Msg::waitMsg((result ? Lang::get("UPDATE_AVAILABLE") : Lang::get("UPDATE_NOT_AVAILABLE")));
}
}
}
if (hidKeysDown() & KEY_TOUCH && touching(touch, mainButtons[7])) {
if (info[selection].FileName != "") {
DeleteStore(info[selection].FileName);
selection = 0;
info = GetUniStoreInfo(_STORE_PATH);
}
}
if (selection < sPos) sPos = selection;
else if (selection > sPos + 7 - 1) sPos = selection - 7 + 1;
}
if ((hidKeysDown() & KEY_Y) || (hidKeysDown() & KEY_TOUCH && touching(touch, mainButtons[9]))) {
if (checkWifiStatus()) {
if (DownloadStore(false)) {
selection = 0;
info = GetUniStoreInfo(_STORE_PATH);
}
}
}
if (hidKeysDown() & KEY_TOUCH && touching(touch, mainButtons[10])) {
if (checkWifiStatus()) {
if (DownloadStore()) {
selection = 0;
info = GetUniStoreInfo(_STORE_PATH);
}
}
}
if (hidKeysDown() & KEY_B) doOut = true;
}
}
+918
View File
@@ -0,0 +1,918 @@
/* quirc -- QR-code recognition library
* Copyright (C) 2010-2012 Daniel Beer <dlbeer@gmail.com>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "quirc_internal.hpp"
#include <string.h>
#include <stdlib.h>
#define MAX_POLY 64
/************************************************************************
* Galois fields
*/
struct galois_field {
int p;
const uint8_t *log;
const uint8_t *exp;
};
static const uint8_t gf16_exp[16] = {
0x01, 0x02, 0x04, 0x08, 0x03, 0x06, 0x0c, 0x0b,
0x05, 0x0a, 0x07, 0x0e, 0x0f, 0x0d, 0x09, 0x01
};
static const uint8_t gf16_log[16] = {
0x00, 0x0f, 0x01, 0x04, 0x02, 0x08, 0x05, 0x0a,
0x03, 0x0e, 0x09, 0x07, 0x06, 0x0d, 0x0b, 0x0c
};
static const struct galois_field gf16 = {
.p = 15,
.log = gf16_log,
.exp = gf16_exp
};
static const uint8_t gf256_exp[256] = {
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
0x1d, 0x3a, 0x74, 0xe8, 0xcd, 0x87, 0x13, 0x26,
0x4c, 0x98, 0x2d, 0x5a, 0xb4, 0x75, 0xea, 0xc9,
0x8f, 0x03, 0x06, 0x0c, 0x18, 0x30, 0x60, 0xc0,
0x9d, 0x27, 0x4e, 0x9c, 0x25, 0x4a, 0x94, 0x35,
0x6a, 0xd4, 0xb5, 0x77, 0xee, 0xc1, 0x9f, 0x23,
0x46, 0x8c, 0x05, 0x0a, 0x14, 0x28, 0x50, 0xa0,
0x5d, 0xba, 0x69, 0xd2, 0xb9, 0x6f, 0xde, 0xa1,
0x5f, 0xbe, 0x61, 0xc2, 0x99, 0x2f, 0x5e, 0xbc,
0x65, 0xca, 0x89, 0x0f, 0x1e, 0x3c, 0x78, 0xf0,
0xfd, 0xe7, 0xd3, 0xbb, 0x6b, 0xd6, 0xb1, 0x7f,
0xfe, 0xe1, 0xdf, 0xa3, 0x5b, 0xb6, 0x71, 0xe2,
0xd9, 0xaf, 0x43, 0x86, 0x11, 0x22, 0x44, 0x88,
0x0d, 0x1a, 0x34, 0x68, 0xd0, 0xbd, 0x67, 0xce,
0x81, 0x1f, 0x3e, 0x7c, 0xf8, 0xed, 0xc7, 0x93,
0x3b, 0x76, 0xec, 0xc5, 0x97, 0x33, 0x66, 0xcc,
0x85, 0x17, 0x2e, 0x5c, 0xb8, 0x6d, 0xda, 0xa9,
0x4f, 0x9e, 0x21, 0x42, 0x84, 0x15, 0x2a, 0x54,
0xa8, 0x4d, 0x9a, 0x29, 0x52, 0xa4, 0x55, 0xaa,
0x49, 0x92, 0x39, 0x72, 0xe4, 0xd5, 0xb7, 0x73,
0xe6, 0xd1, 0xbf, 0x63, 0xc6, 0x91, 0x3f, 0x7e,
0xfc, 0xe5, 0xd7, 0xb3, 0x7b, 0xf6, 0xf1, 0xff,
0xe3, 0xdb, 0xab, 0x4b, 0x96, 0x31, 0x62, 0xc4,
0x95, 0x37, 0x6e, 0xdc, 0xa5, 0x57, 0xae, 0x41,
0x82, 0x19, 0x32, 0x64, 0xc8, 0x8d, 0x07, 0x0e,
0x1c, 0x38, 0x70, 0xe0, 0xdd, 0xa7, 0x53, 0xa6,
0x51, 0xa2, 0x59, 0xb2, 0x79, 0xf2, 0xf9, 0xef,
0xc3, 0x9b, 0x2b, 0x56, 0xac, 0x45, 0x8a, 0x09,
0x12, 0x24, 0x48, 0x90, 0x3d, 0x7a, 0xf4, 0xf5,
0xf7, 0xf3, 0xfb, 0xeb, 0xcb, 0x8b, 0x0b, 0x16,
0x2c, 0x58, 0xb0, 0x7d, 0xfa, 0xe9, 0xcf, 0x83,
0x1b, 0x36, 0x6c, 0xd8, 0xad, 0x47, 0x8e, 0x01
};
static const uint8_t gf256_log[256] = {
0x00, 0xff, 0x01, 0x19, 0x02, 0x32, 0x1a, 0xc6,
0x03, 0xdf, 0x33, 0xee, 0x1b, 0x68, 0xc7, 0x4b,
0x04, 0x64, 0xe0, 0x0e, 0x34, 0x8d, 0xef, 0x81,
0x1c, 0xc1, 0x69, 0xf8, 0xc8, 0x08, 0x4c, 0x71,
0x05, 0x8a, 0x65, 0x2f, 0xe1, 0x24, 0x0f, 0x21,
0x35, 0x93, 0x8e, 0xda, 0xf0, 0x12, 0x82, 0x45,
0x1d, 0xb5, 0xc2, 0x7d, 0x6a, 0x27, 0xf9, 0xb9,
0xc9, 0x9a, 0x09, 0x78, 0x4d, 0xe4, 0x72, 0xa6,
0x06, 0xbf, 0x8b, 0x62, 0x66, 0xdd, 0x30, 0xfd,
0xe2, 0x98, 0x25, 0xb3, 0x10, 0x91, 0x22, 0x88,
0x36, 0xd0, 0x94, 0xce, 0x8f, 0x96, 0xdb, 0xbd,
0xf1, 0xd2, 0x13, 0x5c, 0x83, 0x38, 0x46, 0x40,
0x1e, 0x42, 0xb6, 0xa3, 0xc3, 0x48, 0x7e, 0x6e,
0x6b, 0x3a, 0x28, 0x54, 0xfa, 0x85, 0xba, 0x3d,
0xca, 0x5e, 0x9b, 0x9f, 0x0a, 0x15, 0x79, 0x2b,
0x4e, 0xd4, 0xe5, 0xac, 0x73, 0xf3, 0xa7, 0x57,
0x07, 0x70, 0xc0, 0xf7, 0x8c, 0x80, 0x63, 0x0d,
0x67, 0x4a, 0xde, 0xed, 0x31, 0xc5, 0xfe, 0x18,
0xe3, 0xa5, 0x99, 0x77, 0x26, 0xb8, 0xb4, 0x7c,
0x11, 0x44, 0x92, 0xd9, 0x23, 0x20, 0x89, 0x2e,
0x37, 0x3f, 0xd1, 0x5b, 0x95, 0xbc, 0xcf, 0xcd,
0x90, 0x87, 0x97, 0xb2, 0xdc, 0xfc, 0xbe, 0x61,
0xf2, 0x56, 0xd3, 0xab, 0x14, 0x2a, 0x5d, 0x9e,
0x84, 0x3c, 0x39, 0x53, 0x47, 0x6d, 0x41, 0xa2,
0x1f, 0x2d, 0x43, 0xd8, 0xb7, 0x7b, 0xa4, 0x76,
0xc4, 0x17, 0x49, 0xec, 0x7f, 0x0c, 0x6f, 0xf6,
0x6c, 0xa1, 0x3b, 0x52, 0x29, 0x9d, 0x55, 0xaa,
0xfb, 0x60, 0x86, 0xb1, 0xbb, 0xcc, 0x3e, 0x5a,
0xcb, 0x59, 0x5f, 0xb0, 0x9c, 0xa9, 0xa0, 0x51,
0x0b, 0xf5, 0x16, 0xeb, 0x7a, 0x75, 0x2c, 0xd7,
0x4f, 0xae, 0xd5, 0xe9, 0xe6, 0xe7, 0xad, 0xe8,
0x74, 0xd6, 0xf4, 0xea, 0xa8, 0x50, 0x58, 0xaf
};
static const struct galois_field gf256 = {
.p = 255,
.log = gf256_log,
.exp = gf256_exp
};
/************************************************************************
* Polynomial operations
*/
static void poly_add(uint8_t *dst, const uint8_t *src, uint8_t c,
int shift, const struct galois_field *gf)
{
int i;
int log_c = gf->log[c];
if (!c)
return;
for (i = 0; i < MAX_POLY; i++) {
int p = i + shift;
uint8_t v = src[i];
if (p < 0 || p >= MAX_POLY)
continue;
if (!v)
continue;
dst[p] ^= gf->exp[(gf->log[v] + log_c) % gf->p];
}
}
static uint8_t poly_eval(const uint8_t *s, uint8_t x,
const struct galois_field *gf)
{
int i;
uint8_t sum = 0;
uint8_t log_x = gf->log[x];
if (!x)
return s[0];
for (i = 0; i < MAX_POLY; i++) {
uint8_t c = s[i];
if (!c)
continue;
sum ^= gf->exp[(gf->log[c] + log_x * i) % gf->p];
}
return sum;
}
/************************************************************************
* Berlekamp-Massey algorithm for finding error locator polynomials.
*/
static void berlekamp_massey(const uint8_t *s, int N,
const struct galois_field *gf,
uint8_t *sigma)
{
uint8_t C[MAX_POLY];
uint8_t B[MAX_POLY];
int L = 0;
int m = 1;
uint8_t b = 1;
int n;
memset(B, 0, sizeof(B));
memset(C, 0, sizeof(C));
B[0] = 1;
C[0] = 1;
for (n = 0; n < N; n++) {
uint8_t d = s[n];
uint8_t mult;
int i;
for (i = 1; i <= L; i++) {
if (!(C[i] && s[n - i]))
continue;
d ^= gf->exp[(gf->log[C[i]] +
gf->log[s[n - i]]) %
gf->p];
}
mult = gf->exp[(gf->p - gf->log[b] + gf->log[d]) % gf->p];
if (!d) {
m++;
} else if (L * 2 <= n) {
uint8_t T[MAX_POLY];
memcpy(T, C, sizeof(T));
poly_add(C, B, mult, m, gf);
memcpy(B, T, sizeof(B));
L = n + 1 - L;
b = d;
m = 1;
} else {
poly_add(C, B, mult, m, gf);
m++;
}
}
memcpy(sigma, C, MAX_POLY);
}
/************************************************************************
* Code stream error correction
*
* Generator polynomial for GF(2^8) is x^8 + x^4 + x^3 + x^2 + 1
*/
static int block_syndromes(const uint8_t *data, int bs, int npar, uint8_t *s)
{
int nonzero = 0;
int i;
memset(s, 0, MAX_POLY);
for (i = 0; i < npar; i++) {
int j;
for (j = 0; j < bs; j++) {
uint8_t c = data[bs - j - 1];
if (!c)
continue;
s[i] ^= gf256_exp[((int)gf256_log[c] +
i * j) % 255];
}
if (s[i])
nonzero = 1;
}
return nonzero;
}
static void eloc_poly(uint8_t *omega,
const uint8_t *s, const uint8_t *sigma,
int npar)
{
int i;
memset(omega, 0, MAX_POLY);
for (i = 0; i < npar; i++) {
const uint8_t a = sigma[i];
const uint8_t log_a = gf256_log[a];
int j;
if (!a)
continue;
for (j = 0; j + 1 < MAX_POLY; j++) {
const uint8_t b = s[j + 1];
if (i + j >= npar)
break;
if (!b)
continue;
omega[i + j] ^=
gf256_exp[(log_a + gf256_log[b]) % 255];
}
}
}
static quirc_decode_error_t correct_block(uint8_t *data,
const struct quirc_rs_params *ecc)
{
int npar = ecc->bs - ecc->dw;
uint8_t s[MAX_POLY];
uint8_t sigma[MAX_POLY];
uint8_t sigma_deriv[MAX_POLY];
uint8_t omega[MAX_POLY];
int i;
/* Compute syndrome vector */
if (!block_syndromes(data, ecc->bs, npar, s))
return QUIRC_SUCCESS;
berlekamp_massey(s, npar, &gf256, sigma);
/* Compute derivative of sigma */
memset(sigma_deriv, 0, MAX_POLY);
for (i = 0; i + 1 < MAX_POLY; i += 2)
sigma_deriv[i] = sigma[i + 1];
/* Compute error evaluator polynomial */
eloc_poly(omega, s, sigma, npar - 1);
/* Find error locations and magnitudes */
for (i = 0; i < ecc->bs; i++) {
uint8_t xinv = gf256_exp[255 - i];
if (!poly_eval(sigma, xinv, &gf256)) {
uint8_t sd_x = poly_eval(sigma_deriv, xinv, &gf256);
uint8_t omega_x = poly_eval(omega, xinv, &gf256);
uint8_t error = gf256_exp[(255 - gf256_log[sd_x] +
gf256_log[omega_x]) % 255];
data[ecc->bs - i - 1] ^= error;
}
}
if (block_syndromes(data, ecc->bs, npar, s))
return QUIRC_ERROR_DATA_ECC;
return QUIRC_SUCCESS;
}
/************************************************************************
* Format value error correction
*
* Generator polynomial for GF(2^4) is x^4 + x + 1
*/
#define FORMAT_MAX_ERROR 3
#define FORMAT_SYNDROMES (FORMAT_MAX_ERROR * 2)
#define FORMAT_BITS 15
static int format_syndromes(uint16_t u, uint8_t *s)
{
int i;
int nonzero = 0;
memset(s, 0, MAX_POLY);
for (i = 0; i < FORMAT_SYNDROMES; i++) {
int j;
s[i] = 0;
for (j = 0; j < FORMAT_BITS; j++)
if (u & (1 << j))
s[i] ^= gf16_exp[((i + 1) * j) % 15];
if (s[i])
nonzero = 1;
}
return nonzero;
}
static quirc_decode_error_t correct_format(uint16_t *f_ret)
{
uint16_t u = *f_ret;
int i;
uint8_t s[MAX_POLY];
uint8_t sigma[MAX_POLY];
/* Evaluate U (received codeword) at each of alpha_1 .. alpha_6
* to get S_1 .. S_6 (but we index them from 0).
*/
if (!format_syndromes(u, s))
return QUIRC_SUCCESS;
berlekamp_massey(s, FORMAT_SYNDROMES, &gf16, sigma);
/* Now, find the roots of the polynomial */
for (i = 0; i < 15; i++)
if (!poly_eval(sigma, gf16_exp[15 - i], &gf16))
u ^= (1 << i);
if (format_syndromes(u, s))
return QUIRC_ERROR_FORMAT_ECC;
*f_ret = u;
return QUIRC_SUCCESS;
}
/************************************************************************
* Decoder algorithm
*/
struct datastream {
uint8_t raw[QUIRC_MAX_PAYLOAD];
int data_bits;
int ptr;
uint8_t data[QUIRC_MAX_PAYLOAD];
};
static inline int grid_bit(const struct quirc_code *code, int x, int y)
{
int p = y * code->size + x;
return (code->cell_bitmap[p >> 3] >> (p & 7)) & 1;
}
static quirc_decode_error_t read_format(const struct quirc_code *code,
struct quirc_data *data, int which)
{
int i;
uint16_t format = 0;
uint16_t fdata;
quirc_decode_error_t err;
if (which) {
for (i = 0; i < 7; i++)
format = (format << 1) |
grid_bit(code, 8, code->size - 1 - i);
for (i = 0; i < 8; i++)
format = (format << 1) |
grid_bit(code, code->size - 8 + i, 8);
} else {
static const int xs[15] = {
8, 8, 8, 8, 8, 8, 8, 8, 7, 5, 4, 3, 2, 1, 0
};
static const int ys[15] = {
0, 1, 2, 3, 4, 5, 7, 8, 8, 8, 8, 8, 8, 8, 8
};
for (i = 14; i >= 0; i--)
format = (format << 1) | grid_bit(code, xs[i], ys[i]);
}
format ^= 0x5412;
err = correct_format(&format);
if (err)
return err;
fdata = format >> 10;
data->ecc_level = fdata >> 3;
data->mask = fdata & 7;
return QUIRC_SUCCESS;
}
static int mask_bit(int mask, int i, int j)
{
switch (mask) {
case 0: return !((i + j) % 2);
case 1: return !(i % 2);
case 2: return !(j % 3);
case 3: return !((i + j) % 3);
case 4: return !(((i / 2) + (j / 3)) % 2);
case 5: return !((i * j) % 2 + (i * j) % 3);
case 6: return !(((i * j) % 2 + (i * j) % 3) % 2);
case 7: return !(((i * j) % 3 + (i + j) % 2) % 2);
}
return 0;
}
static int reserved_cell(int version, int i, int j)
{
const struct quirc_version_info *ver = &quirc_version_db[version];
int size = version * 4 + 17;
int ai = -1, aj = -1, a;
/* Finder + format: top left */
if (i < 9 && j < 9)
return 1;
/* Finder + format: bottom left */
if (i + 8 >= size && j < 9)
return 1;
/* Finder + format: top right */
if (i < 9 && j + 8 >= size)
return 1;
/* Exclude timing patterns */
if (i == 6 || j == 6)
return 1;
/* Exclude version info, if it exists. Version info sits adjacent to
* the top-right and bottom-left finders in three rows, bounded by
* the timing pattern.
*/
if (version >= 7) {
if (i < 6 && j + 11 >= size)
return 1;
if (i + 11 >= size && j < 6)
return 1;
}
/* Exclude alignment patterns */
for (a = 0; a < QUIRC_MAX_ALIGNMENT && ver->apat[a]; a++) {
int p = ver->apat[a];
if (abs(p - i) < 3)
ai = a;
if (abs(p - j) < 3)
aj = a;
}
if (ai >= 0 && aj >= 0) {
a--;
if (ai > 0 && ai < a)
return 1;
if (aj > 0 && aj < a)
return 1;
if (aj == a && ai == a)
return 1;
}
return 0;
}
static void read_bit(const struct quirc_code *code,
struct quirc_data *data,
struct datastream *ds, int i, int j)
{
int bitpos = ds->data_bits & 7;
int bytepos = ds->data_bits >> 3;
int v = grid_bit(code, j, i);
if (mask_bit(data->mask, i, j))
v ^= 1;
if (v)
ds->raw[bytepos] |= (0x80 >> bitpos);
ds->data_bits++;
}
static void read_data(const struct quirc_code *code,
struct quirc_data *data,
struct datastream *ds)
{
int y = code->size - 1;
int x = code->size - 1;
int dir = -1;
while (x > 0) {
if (x == 6)
x--;
if (!reserved_cell(data->version, y, x))
read_bit(code, data, ds, y, x);
if (!reserved_cell(data->version, y, x - 1))
read_bit(code, data, ds, y, x - 1);
y += dir;
if (y < 0 || y >= code->size) {
dir = -dir;
x -= 2;
y += dir;
}
}
}
static quirc_decode_error_t codestream_ecc(struct quirc_data *data,
struct datastream *ds)
{
const struct quirc_version_info *ver =
&quirc_version_db[data->version];
const struct quirc_rs_params *sb_ecc = &ver->ecc[data->ecc_level];
struct quirc_rs_params lb_ecc;
int bc = ver->data_bytes / sb_ecc->bs;
int dst_offset = 0;
int lb_count = ver->data_bytes - bc * sb_ecc->bs;
int small_dw_total = bc * sb_ecc->dw;
int i;
memcpy(&lb_ecc, sb_ecc, sizeof(lb_ecc));
lb_ecc.dw++;
lb_ecc.bs++;
for (i = 0; i < bc; i++) {
uint8_t *dst = ds->data + dst_offset;
const struct quirc_rs_params *ecc = sb_ecc;
quirc_decode_error_t err;
int j = 0;
int k;
for (k = 0; k < sb_ecc->dw; k++)
dst[j++] = ds->raw[k * bc + i];
if (i + lb_count >= bc) {
dst[j++] = ds->raw[small_dw_total + i - lb_count];
ecc = &lb_ecc;
}
for (k = 0; k < sb_ecc->bs - sb_ecc->dw; k++)
dst[j++] = ds->raw[small_dw_total + lb_count + i +
k * bc];
err = correct_block(dst, ecc);
if (err)
return err;
dst_offset += ecc->dw;
}
ds->data_bits = dst_offset * 8;
return QUIRC_SUCCESS;
}
static inline int bits_remaining(const struct datastream *ds)
{
return ds->data_bits - ds->ptr;
}
static int take_bits(struct datastream *ds, int len)
{
int ret = 0;
while (len && (ds->ptr < ds->data_bits)) {
uint8_t b = ds->data[ds->ptr >> 3];
int bitpos = ds->ptr & 7;
ret <<= 1;
if ((b << bitpos) & 0x80)
ret |= 1;
ds->ptr++;
len--;
}
return ret;
}
static int numeric_tuple(struct quirc_data *data,
struct datastream *ds,
int bits, int digits)
{
int tuple;
int i;
if (bits_remaining(ds) < bits)
return -1;
tuple = take_bits(ds, bits);
for (i = digits - 1; i >= 0; i--) {
data->payload[data->payload_len + i] = tuple % 10 + '0';
tuple /= 10;
}
data->payload_len += digits;
return 0;
}
static quirc_decode_error_t decode_numeric(struct quirc_data *data,
struct datastream *ds)
{
int bits = 14;
int count;
if (data->version < 10)
bits = 10;
else if (data->version < 27)
bits = 12;
count = take_bits(ds, bits);
if (data->payload_len + count + 1 > QUIRC_MAX_PAYLOAD)
return QUIRC_ERROR_DATA_OVERFLOW;
while (count >= 3) {
if (numeric_tuple(data, ds, 10, 3) < 0)
return QUIRC_ERROR_DATA_UNDERFLOW;
count -= 3;
}
if (count >= 2) {
if (numeric_tuple(data, ds, 7, 2) < 0)
return QUIRC_ERROR_DATA_UNDERFLOW;
count -= 2;
}
if (count) {
if (numeric_tuple(data, ds, 4, 1) < 0)
return QUIRC_ERROR_DATA_UNDERFLOW;
count--;
}
return QUIRC_SUCCESS;
}
static int alpha_tuple(struct quirc_data *data,
struct datastream *ds,
int bits, int digits)
{
int tuple;
int i;
if (bits_remaining(ds) < bits)
return -1;
tuple = take_bits(ds, bits);
for (i = 0; i < digits; i++) {
static const char *alpha_map =
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:";
data->payload[data->payload_len + digits - i - 1] =
alpha_map[tuple % 45];
tuple /= 45;
}
data->payload_len += digits;
return 0;
}
static quirc_decode_error_t decode_alpha(struct quirc_data *data,
struct datastream *ds)
{
int bits = 13;
int count;
if (data->version < 7)
bits = 9;
else if (data->version < 11)
bits = 10;
count = take_bits(ds, bits);
if (data->payload_len + count + 1 > QUIRC_MAX_PAYLOAD)
return QUIRC_ERROR_DATA_OVERFLOW;
while (count >= 2) {
if (alpha_tuple(data, ds, 11, 2) < 0)
return QUIRC_ERROR_DATA_UNDERFLOW;
count -= 2;
}
if (count) {
if (alpha_tuple(data, ds, 6, 1) < 0)
return QUIRC_ERROR_DATA_UNDERFLOW;
count--;
}
return QUIRC_SUCCESS;
}
static quirc_decode_error_t decode_byte(struct quirc_data *data,
struct datastream *ds)
{
int bits = 16;
int count;
int i;
if (data->version < 10)
bits = 8;
count = take_bits(ds, bits);
if (data->payload_len + count + 1 > QUIRC_MAX_PAYLOAD)
return QUIRC_ERROR_DATA_OVERFLOW;
if (bits_remaining(ds) < count * 8)
return QUIRC_ERROR_DATA_UNDERFLOW;
for (i = 0; i < count; i++)
data->payload[data->payload_len++] = take_bits(ds, 8);
return QUIRC_SUCCESS;
}
static quirc_decode_error_t decode_kanji(struct quirc_data *data,
struct datastream *ds)
{
int bits = 12;
int count;
int i;
if (data->version < 10)
bits = 8;
else if (data->version < 27)
bits = 10;
count = take_bits(ds, bits);
if (data->payload_len + count * 2 + 1 > QUIRC_MAX_PAYLOAD)
return QUIRC_ERROR_DATA_OVERFLOW;
if (bits_remaining(ds) < count * 13)
return QUIRC_ERROR_DATA_UNDERFLOW;
for (i = 0; i < count; i++) {
int d = take_bits(ds, 13);
uint16_t sjw;
if (d + 0x8140 >= 0x9ffc)
sjw = d + 0x8140;
else
sjw = d + 0xc140;
data->payload[data->payload_len++] = sjw >> 8;
data->payload[data->payload_len++] = sjw & 0xff;
}
return QUIRC_SUCCESS;
}
static quirc_decode_error_t decode_eci(struct quirc_data *data,
struct datastream *ds)
{
if (bits_remaining(ds) < 8)
return QUIRC_ERROR_DATA_UNDERFLOW;
data->eci = take_bits(ds, 8);
if ((data->eci & 0xc0) == 0x80) {
if (bits_remaining(ds) < 8)
return QUIRC_ERROR_DATA_UNDERFLOW;
data->eci = (data->eci << 8) | take_bits(ds, 8);
} else if ((data->eci & 0xe0) == 0xc0) {
if (bits_remaining(ds) < 16)
return QUIRC_ERROR_DATA_UNDERFLOW;
data->eci = (data->eci << 16) | take_bits(ds, 16);
}
return QUIRC_SUCCESS;
}
static quirc_decode_error_t decode_payload(struct quirc_data *data,
struct datastream *ds)
{
while (bits_remaining(ds) >= 4) {
quirc_decode_error_t err = QUIRC_SUCCESS;
int type = take_bits(ds, 4);
switch (type) {
case QUIRC_DATA_TYPE_NUMERIC:
err = decode_numeric(data, ds);
break;
case QUIRC_DATA_TYPE_ALPHA:
err = decode_alpha(data, ds);
break;
case QUIRC_DATA_TYPE_BYTE:
err = decode_byte(data, ds);
break;
case QUIRC_DATA_TYPE_KANJI:
err = decode_kanji(data, ds);
break;
case 7:
err = decode_eci(data, ds);
break;
default:
goto done;
}
if (err)
return err;
if (!(type & (type - 1)) && (type > data->data_type))
data->data_type = type;
}
done:
/* Add nul terminator to all payloads */
if ((size_t)data->payload_len >= sizeof(data->payload))
data->payload_len--;
data->payload[data->payload_len] = 0;
return QUIRC_SUCCESS;
}
quirc_decode_error_t quirc_decode(const struct quirc_code *code,
struct quirc_data *data)
{
quirc_decode_error_t err;
struct datastream ds;
if ((code->size - 17) % 4)
return QUIRC_ERROR_INVALID_GRID_SIZE;
memset(data, 0, sizeof(*data));
memset(&ds, 0, sizeof(ds));
data->version = (code->size - 17) / 4;
if (data->version < 1 ||
data->version > QUIRC_MAX_VERSION)
return QUIRC_ERROR_INVALID_VERSION;
/* Read format information -- try both locations */
err = read_format(code, data, 0);
if (err)
err = read_format(code, data, 1);
if (err)
return err;
read_data(code, data, &ds);
err = codestream_ecc(data, &ds);
if (err)
return err;
err = decode_payload(data, &ds);
if (err)
return err;
return QUIRC_SUCCESS;
}
File diff suppressed because it is too large Load Diff
+315
View File
@@ -0,0 +1,315 @@
/*
* This file is part of Universal-Updater
* Copyright (C) 2019-2020 Universal-Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
/*
* This file is part of PKSM
* Copyright (C) 2016-2020 Bernardo Giordano, Admiral Fish, piepie62
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "qrcode.hpp"
#include <cstring>
/*
Initialize everything needed for the camera.
*/
QRCode::QRCode() {
this->image.tex = new C3D_Tex;
this->image.subtex = &this->subtex;
this->qrData = quirc_new();
std::fill(this->cameraBuffer.begin(), this->cameraBuffer.end(), 0);
C3D_TexInit(this->image.tex, 512, 256, GPU_RGB565);
C3D_TexSetFilter(this->image.tex, GPU_LINEAR, GPU_LINEAR);
this->image.tex->border = 0xFFFFFFFF;
C3D_TexSetWrap(this->image.tex, GPU_CLAMP_TO_BORDER, GPU_CLAMP_TO_BORDER);
LightLock_Init(&this->bufferLock);
LightLock_Init(&this->imageLock);
svcCreateEvent(&this->exitEvent, RESET_STICKY);
quirc_resize(this->qrData, 400, 240);
}
/*
Destroy everything.
*/
QRCode::~QRCode() {
C3D_TexDelete(this->image.tex);
delete this->image.tex;
quirc_destroy(this->qrData);
svcCloseHandle(this->exitEvent);
}
/*
mem copy the captured Image to the buffer, used for drawing.
*/
void QRCode::buffToImage() {
LightLock_Lock(&this->bufferLock);
for (u32 x = 0; x < 400; x++) {
for (u32 y = 0; y < 240; y++) {
const u32 dstPos = ((((y >> 3) * (512 >> 3) + (x >> 3)) << 6) +
((x & 1) | ((y & 1) << 1) | ((x & 2) << 1) | ((y & 2) << 2) | ((x & 4) << 2) | ((y & 4) << 3))) * 2;
const u32 srcPos = (y * 400 + x) * 2;
memcpy(((u8 *)this->image.tex->data) + dstPos, ((u8 *)this->cameraBuffer.data()) + srcPos, 2);
}
}
LightLock_Unlock(&this->bufferLock);
}
/*
Finish and unlock everything.
*/
void QRCode::finish() {
svcSignalEvent(this->exitEvent);
while (!this->done()) svcSleepThread(1000000);
LightLock_Lock(&this->bufferLock);
LightLock_Unlock(&this->bufferLock);
LightLock_Lock(&this->imageLock);
LightLock_Unlock(&this->imageLock);
}
/*
The Draw Thread of the Camera.
*/
void QRCode::drawThread() {
LightLock_Lock(&this->imageLock);
/* If we aren't done.. do the draw to scan. */
while (!this->done()) {
Gui::clearTextBufs();
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
C2D_TargetClear(Top, TRANSPARENT);
C2D_TargetClear(Bottom, TRANSPARENT);
this->buffToImage(); // Fetch image.
Gui::ScreenDraw(Top);
C2D_DrawImageAt(this->image, 0, 0, 0.5, nullptr, 1.0f, 1.0f);
GFX::DrawBottom();
C3D_FrameEnd(0);
}
LightLock_Unlock(&this->imageLock);
}
/*
The Capture Thread of the camera.
*/
void QRCode::captureThread() {
Handle events[3] = { 0 };
events[0] = exitEvent;
u32 transferUnit;
u16 *buffer = new u16[400 * 240];
camInit();
CAMU_SetSize(SELECT_OUT1, SIZE_CTR_TOP_LCD, CONTEXT_A);
CAMU_SetOutputFormat(SELECT_OUT1, OUTPUT_RGB_565, CONTEXT_A);
CAMU_SetFrameRate(SELECT_OUT1, FRAME_RATE_30);
CAMU_SetNoiseFilter(SELECT_OUT1, true);
CAMU_SetAutoExposure(SELECT_OUT1, true);
CAMU_SetAutoWhiteBalance(SELECT_OUT1, true);
CAMU_SetPhotoMode(SELECT_OUT1, PHOTO_MODE_LETTER);
/* No clue if this is actually effective or if it's just a placebo effect, but it seems to help? */
CAMU_SetSharpness(SELECT_OUT1, 127);
CAMU_Activate(SELECT_OUT1);
CAMU_GetBufferErrorInterruptEvent(&events[2], PORT_CAM1);
CAMU_SetTrimming(PORT_CAM1, false);
CAMU_GetMaxBytes(&transferUnit, 400, 240);
CAMU_SetTransferBytes(PORT_CAM1, transferUnit, 400, 240);
CAMU_ClearBuffer(PORT_CAM1);
CAMU_SetReceiving(&events[1], buffer, PORT_CAM1, 400 * 240 * sizeof(u16), (s16)transferUnit);
CAMU_StartCapture(PORT_CAM1);
bool cancel = false;
while (!cancel) {
s32 index = 0;
svcWaitSynchronizationN(&index, events, 3, false, U64_MAX);
switch (index) {
case 0:
cancel = true;
break;
case 1:
svcCloseHandle(events[1]);
events[1] = 0;
LightLock_Lock(&this->bufferLock);
memcpy(this->cameraBuffer.data(), buffer, 400 * 240 * sizeof(u16));
GSPGPU_FlushDataCache(this->cameraBuffer.data(), 400 * 240 * sizeof(u16));
LightLock_Unlock(&this->bufferLock);
CAMU_SetReceiving(&events[1], buffer, PORT_CAM1, 400 * 240 * sizeof(u16), transferUnit);
break;
case 2:
svcCloseHandle(events[1]);
events[1] = 0;
CAMU_ClearBuffer(PORT_CAM1);
CAMU_SetReceiving(&events[1], buffer, PORT_CAM1, 400 * 240 * sizeof(u16), transferUnit);
CAMU_StartCapture(PORT_CAM1);
break;
default:
break;
}
}
CAMU_StopCapture(PORT_CAM1);
bool busy = false;
while (R_SUCCEEDED(CAMU_IsBusy(&busy, PORT_CAM1)) && busy) svcSleepThread(1000000);
CAMU_ClearBuffer(PORT_CAM1);
CAMU_Activate(SELECT_NONE);
camExit();
delete[] buffer;
for (int i = 1; i < 3; i++) {
if (events[i] != 0) {
svcCloseHandle(events[i]);
events[i] = 0;
}
}
this->finished = true;
}
/*
These are just Helpers.. because Threads.
*/
void drawHelper(void *arg) {
QRCode *qrData = (QRCode *)arg;
qrData->drawThread();
}
void captureHelper(void *arg) {
QRCode *qrData = (QRCode *)arg;
qrData->captureThread();
}
/*
Handle the capture.
std::vector<u8> &out: The Reference, where to output the decoded result.
*/
void QRCode::handler(std::vector<u8> &out) {
hidScanInput();
if (hidKeysDown() & KEY_B) { // Cancel with B.
this->cancel = true;
this->finish();
return;
}
if (!this->capturing) {
/* create camera draw thread. */
if (threadCreate((ThreadFunc)&captureHelper, this, 0x10000, 0x1A, 1, true) != NULL) capturing = true;
else {
this->finish();
return;
}
}
if (this->done()) return;
int w, h;
u8 *image = (u8 *)quirc_begin(this->qrData, &w, &h);
LightLock_Lock(&bufferLock);
for (ssize_t x = 0; x < w; x++) {
for (ssize_t y = 0; y < h; y++) {
u16 px = this->cameraBuffer[y * 400 + x];
image[y * w + x] = (u8)(((((px >> 11) & 0x1F) << 3) + (((px >> 5) & 0x3F) << 2) + ((px & 0x1F) << 3)) / 3);
}
}
LightLock_Unlock(&this->bufferLock);
quirc_end(this->qrData);
if (quirc_count(this->qrData) > 0) {
struct quirc_code code;
struct quirc_data scan_data;
quirc_extract(this->qrData, 0, &code);
if (!quirc_decode(&code, &scan_data)) {
this->finish();
out.resize(scan_data.payload_len);
std::copy(scan_data.payload, scan_data.payload + scan_data.payload_len, out.begin());
}
}
}
/*
Return a vector of u8's from the QR Code.
*/
std::vector<u8> QR_Scanner::scan() {
std::vector<u8> out = { };
std::unique_ptr<QRCode> qrData = std::make_unique<QRCode>();
aptSetHomeAllowed(false); // Block the Home key.
threadCreate((ThreadFunc)&drawHelper, qrData.get(), 0x10000, 0x1A, 1, true);
while (!qrData->done()) qrData->handler(out); // Handle.
aptSetHomeAllowed(true); // Re-Allow it.
return out;
}
/*
Return the URL from the QR Code.
*/
std::string QR_Scanner::GetQRURL() {
std::vector<u8> qrData = QR_Scanner::scan();
if (qrData.empty()) return ""; // Because it is empty, return "".
if (qrData.back() == '\0') { // If Terminator, do -1.
return std::string((char *)qrData.data(), qrData.size() - 1);
} else {
return std::string((char *)qrData.data(), qrData.size());
}
return "";
}
+75
View File
@@ -0,0 +1,75 @@
/* quirc -- QR-code recognition library
* Copyright (C) 2010-2012 Daniel Beer <dlbeer@gmail.com>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <stdlib.h>
#include <string.h>
#include "quirc_internal.hpp"
const char *quirc_version(void) { return "1.0"; }
struct quirc *quirc_new(void) {
struct quirc *q = (quirc *)malloc(sizeof(*q));
if (!q) return NULL;
memset(q, 0, sizeof(*q));
return q;
}
void quirc_destroy(struct quirc *q) {
if (q->image) free(q->image);
if (sizeof(*q->image) != sizeof(*q->pixels)) free(q->pixels);
free(q);
}
int quirc_resize(struct quirc *q, int w, int h) {
uint8_t *new_image = (uint8_t *)realloc(q->image, w * h);
if (!new_image) return -1;
if (sizeof(*q->image) != sizeof(*q->pixels)) {
size_t new_size = w * h * sizeof(quirc_pixel_t);
quirc_pixel_t *new_pixels = (quirc_pixel_t *)realloc(q->pixels, new_size);
if (!new_pixels) return -1;
q->pixels = new_pixels;
}
q->image = new_image;
q->w = w;
q->h = h;
return 0;
}
int quirc_count(const struct quirc *q) { return q->num_grids; }
static const char *const error_table[] = {
[QUIRC_SUCCESS] = "Success",
[QUIRC_ERROR_INVALID_GRID_SIZE] = "Invalid grid size",
[QUIRC_ERROR_INVALID_VERSION] = "Invalid version",
[QUIRC_ERROR_FORMAT_ECC] = "Format data ECC failure",
[QUIRC_ERROR_DATA_ECC] = "ECC failure",
[QUIRC_ERROR_UNKNOWN_DATA_TYPE] = "Unknown data type",
[QUIRC_ERROR_DATA_OVERFLOW] = "Data overflow",
[QUIRC_ERROR_DATA_UNDERFLOW] = "Data underflow"
};
const char *quirc_strerror(quirc_decode_error_t err) {
if (err < sizeof(error_table) / sizeof(error_table[0])) return error_table[err];
return "Unknown error";
}
+421
View File
@@ -0,0 +1,421 @@
/* quirc -- QR-code recognition library
* Copyright (C) 2010-2012 Daniel Beer <dlbeer@gmail.com>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "quirc_internal.hpp"
const struct quirc_version_info quirc_version_db[QUIRC_MAX_VERSION + 1] = {
{0},
{ /* Version 1 */
.data_bytes = 26,
.apat = {0},
.ecc = {
{.bs = 26, .dw = 16, .ce = 4},
{.bs = 26, .dw = 19, .ce = 2},
{.bs = 26, .dw = 9, .ce = 8},
{.bs = 26, .dw = 13, .ce = 6}
}
},
{ /* Version 2 */
.data_bytes = 44,
.apat = {6, 18, 0},
.ecc = {
{.bs = 44, .dw = 28, .ce = 8},
{.bs = 44, .dw = 34, .ce = 4},
{.bs = 44, .dw = 16, .ce = 14},
{.bs = 44, .dw = 22, .ce = 11}
}
},
{ /* Version 3 */
.data_bytes = 70,
.apat = {6, 22, 0},
.ecc = {
{.bs = 70, .dw = 44, .ce = 13},
{.bs = 70, .dw = 55, .ce = 7},
{.bs = 35, .dw = 13, .ce = 11},
{.bs = 35, .dw = 17, .ce = 9}
}
},
{ /* Version 4 */
.data_bytes = 100,
.apat = {6, 26, 0},
.ecc = {
{.bs = 50, .dw = 32, .ce = 9},
{.bs = 100, .dw = 80, .ce = 10},
{.bs = 25, .dw = 9, .ce = 8},
{.bs = 50, .dw = 24, .ce = 13}
}
},
{ /* Version 5 */
.data_bytes = 134,
.apat = {6, 30, 0},
.ecc = {
{.bs = 67, .dw = 43, .ce = 12},
{.bs = 134, .dw = 108, .ce = 13},
{.bs = 33, .dw = 11, .ce = 11},
{.bs = 33, .dw = 15, .ce = 9}
}
},
{ /* Version 6 */
.data_bytes = 172,
.apat = {6, 34, 0},
.ecc = {
{.bs = 43, .dw = 27, .ce = 8},
{.bs = 86, .dw = 68, .ce = 9},
{.bs = 43, .dw = 15, .ce = 14},
{.bs = 43, .dw = 19, .ce = 12}
}
},
{ /* Version 7 */
.data_bytes = 196,
.apat = {6, 22, 38, 0},
.ecc = {
{.bs = 49, .dw = 31, .ce = 9},
{.bs = 98, .dw = 78, .ce = 10},
{.bs = 39, .dw = 13, .ce = 13},
{.bs = 32, .dw = 14, .ce = 9}
}
},
{ /* Version 8 */
.data_bytes = 242,
.apat = {6, 24, 42, 0},
.ecc = {
{.bs = 60, .dw = 38, .ce = 11},
{.bs = 121, .dw = 97, .ce = 12},
{.bs = 40, .dw = 14, .ce = 13},
{.bs = 40, .dw = 18, .ce = 11}
}
},
{ /* Version 9 */
.data_bytes = 292,
.apat = {6, 26, 46, 0},
.ecc = {
{.bs = 58, .dw = 36, .ce = 11},
{.bs = 146, .dw = 116, .ce = 15},
{.bs = 36, .dw = 12, .ce = 12},
{.bs = 36, .dw = 16, .ce = 10}
}
},
{ /* Version 10 */
.data_bytes = 346,
.apat = {6, 28, 50, 0},
.ecc = {
{.bs = 69, .dw = 43, .ce = 13},
{.bs = 86, .dw = 68, .ce = 9},
{.bs = 43, .dw = 15, .ce = 14},
{.bs = 43, .dw = 19, .ce = 12}
}
},
{ /* Version 11 */
.data_bytes = 404,
.apat = {6, 30, 54, 0},
.ecc = {
{.bs = 80, .dw = 50, .ce = 15},
{.bs = 101, .dw = 81, .ce = 10},
{.bs = 36, .dw = 12, .ce = 12},
{.bs = 50, .dw = 22, .ce = 14}
}
},
{ /* Version 12 */
.data_bytes = 466,
.apat = {6, 32, 58, 0},
.ecc = {
{.bs = 58, .dw = 36, .ce = 11},
{.bs = 116, .dw = 92, .ce = 12},
{.bs = 42, .dw = 14, .ce = 14},
{.bs = 46, .dw = 20, .ce = 14}
}
},
{ /* Version 13 */
.data_bytes = 532,
.apat = {6, 34, 62, 0},
.ecc = {
{.bs = 59, .dw = 37, .ce = 11},
{.bs = 133, .dw = 107, .ce = 13},
{.bs = 33, .dw = 11, .ce = 11},
{.bs = 44, .dw = 20, .ce = 12}
}
},
{ /* Version 14 */
.data_bytes = 581,
.apat = {6, 26, 46, 66, 0},
.ecc = {
{.bs = 65, .dw = 41, .ce = 12},
{.bs = 109, .dw = 87, .ce = 11},
{.bs = 36, .dw = 12, .ce = 12},
{.bs = 54, .dw = 24, .ce = 15}
}
},
{ /* Version 15 */
.data_bytes = 655,
.apat = {6, 26, 48, 70, 0},
.ecc = {
{.bs = 65, .dw = 41, .ce = 12},
{.bs = 109, .dw = 87, .ce = 11},
{.bs = 36, .dw = 12, .ce = 12},
{.bs = 54, .dw = 24, .ce = 15}
}
},
{ /* Version 16 */
.data_bytes = 733,
.apat = {6, 26, 50, 74, 0},
.ecc = {
{.bs = 73, .dw = 45, .ce = 14},
{.bs = 122, .dw = 98, .ce = 12},
{.bs = 45, .dw = 15, .ce = 15},
{.bs = 43, .dw = 19, .ce = 12}
}
},
{ /* Version 17 */
.data_bytes = 815,
.apat = {6, 30, 54, 78, 0},
.ecc = {
{.bs = 74, .dw = 46, .ce = 14},
{.bs = 135, .dw = 107, .ce = 14},
{.bs = 42, .dw = 14, .ce = 14},
{.bs = 50, .dw = 22, .ce = 14}
}
},
{ /* Version 18 */
.data_bytes = 901,
.apat = {6, 30, 56, 82, 0},
.ecc = {
{.bs = 69, .dw = 43, .ce = 13},
{.bs = 150, .dw = 120, .ce = 15},
{.bs = 42, .dw = 14, .ce = 14},
{.bs = 50, .dw = 22, .ce = 14}
}
},
{ /* Version 19 */
.data_bytes = 991,
.apat = {6, 30, 58, 86, 0},
.ecc = {
{.bs = 70, .dw = 44, .ce = 13},
{.bs = 141, .dw = 113, .ce = 14},
{.bs = 39, .dw = 13, .ce = 13},
{.bs = 47, .dw = 21, .ce = 13}
}
},
{ /* Version 20 */
.data_bytes = 1085,
.apat = {6, 34, 62, 90, 0},
.ecc = {
{.bs = 67, .dw = 41, .ce = 13},
{.bs = 135, .dw = 107, .ce = 14},
{.bs = 43, .dw = 15, .ce = 14},
{.bs = 54, .dw = 24, .ce = 15}
}
},
{ /* Version 21 */
.data_bytes = 1156,
.apat = {6, 28, 50, 72, 92, 0},
.ecc = {
{.bs = 68, .dw = 42, .ce = 13},
{.bs = 144, .dw = 116, .ce = 14},
{.bs = 46, .dw = 16, .ce = 15},
{.bs = 50, .dw = 22, .ce = 14}
}
},
{ /* Version 22 */
.data_bytes = 1258,
.apat = {6, 26, 50, 74, 98, 0},
.ecc = {
{.bs = 74, .dw = 46, .ce = 14},
{.bs = 139, .dw = 111, .ce = 14},
{.bs = 37, .dw = 13, .ce = 12},
{.bs = 54, .dw = 24, .ce = 15}
}
},
{ /* Version 23 */
.data_bytes = 1364,
.apat = {6, 30, 54, 78, 102, 0},
.ecc = {
{.bs = 75, .dw = 47, .ce = 14},
{.bs = 151, .dw = 121, .ce = 15},
{.bs = 45, .dw = 15, .ce = 15},
{.bs = 54, .dw = 24, .ce = 15}
}
},
{ /* Version 24 */
.data_bytes = 1474,
.apat = {6, 28, 54, 80, 106, 0},
.ecc = {
{.bs = 73, .dw = 45, .ce = 14},
{.bs = 147, .dw = 117, .ce = 15},
{.bs = 46, .dw = 16, .ce = 15},
{.bs = 54, .dw = 24, .ce = 15}
}
},
{ /* Version 25 */
.data_bytes = 1588,
.apat = {6, 32, 58, 84, 110, 0},
.ecc = {
{.bs = 75, .dw = 47, .ce = 14},
{.bs = 132, .dw = 106, .ce = 13},
{.bs = 45, .dw = 15, .ce = 15},
{.bs = 54, .dw = 24, .ce = 15}
}
},
{ /* Version 26 */
.data_bytes = 1706,
.apat = {6, 30, 58, 86, 114, 0},
.ecc = {
{.bs = 74, .dw = 46, .ce = 14},
{.bs = 142, .dw = 114, .ce = 14},
{.bs = 46, .dw = 16, .ce = 15},
{.bs = 50, .dw = 22, .ce = 14}
}
},
{ /* Version 27 */
.data_bytes = 1828,
.apat = {6, 34, 62, 90, 118, 0},
.ecc = {
{.bs = 73, .dw = 45, .ce = 14},
{.bs = 152, .dw = 122, .ce = 15},
{.bs = 45, .dw = 15, .ce = 15},
{.bs = 53, .dw = 23, .ce = 15}
}
},
{ /* Version 28 */
.data_bytes = 1921,
.apat = {6, 26, 50, 74, 98, 122, 0},
.ecc = {
{.bs = 73, .dw = 45, .ce = 14},
{.bs = 147, .dw = 117, .ce = 15},
{.bs = 45, .dw = 15, .ce = 15},
{.bs = 54, .dw = 24, .ce = 15}
}
},
{ /* Version 29 */
.data_bytes = 2051,
.apat = {6, 30, 54, 78, 102, 126, 0},
.ecc = {
{.bs = 73, .dw = 45, .ce = 14},
{.bs = 146, .dw = 116, .ce = 15},
{.bs = 45, .dw = 15, .ce = 15},
{.bs = 73, .dw = 45, .ce = 14}
}
},
{ /* Version 30 */
.data_bytes = 2185,
.apat = {6, 26, 52, 78, 104, 130, 0},
.ecc = {
{.bs = 75, .dw = 47, .ce = 14},
{.bs = 145, .dw = 115, .ce = 15},
{.bs = 45, .dw = 15, .ce = 15},
{.bs = 54, .dw = 24, .ce = 15}
}
},
{ /* Version 31 */
.data_bytes = 2323,
.apat = {6, 30, 56, 82, 108, 134, 0},
.ecc = {
{.bs = 74, .dw = 46, .ce = 14},
{.bs = 145, .dw = 115, .ce = 15},
{.bs = 45, .dw = 15, .ce = 15},
{.bs = 54, .dw = 24, .ce = 15}
}
},
{ /* Version 32 */
.data_bytes = 2465,
.apat = {6, 34, 60, 86, 112, 138, 0},
.ecc = {
{.bs = 74, .dw = 46, .ce = 14},
{.bs = 145, .dw = 115, .ce = 15},
{.bs = 45, .dw = 15, .ce = 15},
{.bs = 54, .dw = 24, .ce = 15}
}
},
{ /* Version 33 */
.data_bytes = 2611,
.apat = {6, 30, 58, 96, 114, 142, 0},
.ecc = {
{.bs = 74, .dw = 46, .ce = 14},
{.bs = 145, .dw = 115, .ce = 15},
{.bs = 45, .dw = 15, .ce = 15},
{.bs = 54, .dw = 24, .ce = 15}
}
},
{ /* Version 34 */
.data_bytes = 2761,
.apat = {6, 34, 62, 90, 118, 146, 0},
.ecc = {
{.bs = 74, .dw = 46, .ce = 14},
{.bs = 145, .dw = 115, .ce = 15},
{.bs = 46, .dw = 16, .ce = 15},
{.bs = 54, .dw = 24, .ce = 15}
}
},
{ /* Version 35 */
.data_bytes = 2876,
.apat = {6, 30, 54, 78, 102, 126, 150},
.ecc = {
{.bs = 75, .dw = 47, .ce = 14},
{.bs = 151, .dw = 121, .ce = 15},
{.bs = 45, .dw = 15, .ce = 15},
{.bs = 54, .dw = 24, .ce = 15}
}
},
{ /* Version 36 */
.data_bytes = 3034,
.apat = {6, 24, 50, 76, 102, 128, 154},
.ecc = {
{.bs = 75, .dw = 47, .ce = 14},
{.bs = 151, .dw = 121, .ce = 15},
{.bs = 45, .dw = 15, .ce = 15},
{.bs = 54, .dw = 24, .ce = 15}
}
},
{ /* Version 37 */
.data_bytes = 3196,
.apat = {6, 28, 54, 80, 106, 132, 158},
.ecc = {
{.bs = 74, .dw = 46, .ce = 14},
{.bs = 152, .dw = 122, .ce = 15},
{.bs = 45, .dw = 15, .ce = 15},
{.bs = 54, .dw = 24, .ce = 15}
}
},
{ /* Version 38 */
.data_bytes = 3362,
.apat = {6, 32, 58, 84, 110, 136, 162},
.ecc = {
{.bs = 74, .dw = 46, .ce = 14},
{.bs = 152, .dw = 122, .ce = 15},
{.bs = 45, .dw = 15, .ce = 15},
{.bs = 54, .dw = 24, .ce = 15}
}
},
{ /* Version 39 */
.data_bytes = 3532,
.apat = {6, 26, 54, 82, 110, 138, 166},
.ecc = {
{.bs = 75, .dw = 47, .ce = 14},
{.bs = 147, .dw = 117, .ce = 15},
{.bs = 45, .dw = 15, .ce = 15},
{.bs = 54, .dw = 24, .ce = 15}
}
},
{ /* Version 40 */
.data_bytes = 3706,
.apat = {6, 30, 58, 86, 114, 142, 170},
.ecc = {
{.bs = 75, .dw = 47, .ce = 14},
{.bs = 148, .dw = 118, .ce = 15},
{.bs = 45, .dw = 15, .ce = 15},
{.bs = 54, .dw = 24, .ce = 15}
}
}
};
-263
View File
@@ -1,263 +0,0 @@
/*
* This file is part of Universal-Updater
* Copyright (C) 2019-2020 Universal-Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "credits.hpp"
extern std::unique_ptr<Config> config;
extern bool touching(touchPosition touch, Structs::ButtonPos button);
// Language Page 1.
const std::vector<std::string> Translators = {
"_mapple²",
"AlbertCoolGuy",
"antoine62",
"Chips",
"cooolgamer",
"David Pires",
"FlameKat53",
"lemonnade0",
"LinuxCat",
"Pavel",
"Pk11",
"Roby Spia",
"SuperSaiyajinStackZ",
"XDgierman",
"YoSoy",
"XxPhoenix1996xX"
};
const std::vector<std::string> Languages = {
"Русский",
"Dansk",
"Français",
"Português",
"Français",
"Português",
"Bruh",
"Lietuvių",
"Français",
"Русский",
"日本語",
"Italiano",
"Deutsch, English",
"Polski",
"Español",
"Español, Italian, Portuguese"
};
// Universal-Team Page 2.
const std::vector<std::string> UniversalTeam = {
"DeadPhoenix",
"FlameKat53",
"NightScript",
"Pk11",
"RocketRobz",
"SuperSaiyajinStackZ",
"TotallyNotGuy"
};
// Script Page 3.
const std::vector<std::string> ScriptCreators = {
"cooolgamer", "DualBladedKirito", "Glazed_Belmont", "Pk11", "SuperSaiyajinStackZ", "The Conceptionist", "YoSoy"
};
const std::vector<std::string> ScriptAmount = {"1", "1", "1", "1", "5", "10", "1 | 2"};
const std::vector<std::string> specialNames = {
"devkitPro", "NightScript"
};
const std::vector<std::string> specialDescriptions = {
"For devkitARM, Libctru, Citro2D, Citro3D and the portlibs.",
"For posting updates on Reddit."
};
void Credits::Draw(void) const {
std::string title = "Universal-Updater - ";
title += Lang::get("CREDITS");
GFX::DrawTop();
if (creditsPage != 4) {
Gui::DrawStringCentered(0, config->useBars() ? 0 : 2, 0.7f, config->textColor(), title, 400);
Gui::DrawStringCentered(0, 30, 0.7f, config->textColor(), Lang::get("DEVELOPED_BY"), 390);
Gui::DrawStringCentered(0, 60, 0.7f, config->textColor(), Lang::get("MAIN_DEV"), 390);
GFX::DrawSprite(sprites_stackZ_idx, 5, 85);
GFX::DrawSprite(sprites_universal_core_idx, 200, 110);
std::string currentVersion = Lang::get("CURRENT_VERSION");
currentVersion += V_STRING;
Gui::DrawString(395-Gui::GetStringWidth(0.70f, currentVersion), 219, 0.70f, config->textColor(), currentVersion, 400);
} else {
Gui::Draw_Rect(0, 0, 400, 240, C2D_Color32(0, 0, 0, 190));
GFX::DrawSprite(sprites_discord_idx, 115, 35);
}
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 400, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
DrawBottom();
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 320, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
}
void Credits::DrawBottom(void) const {
std::string line1;
std::string line2;
GFX::DrawBottom();
if (creditsPage == 0) {
Gui::DrawStringCentered(0, -2, 0.7f, config->textColor(), Lang::get("TRANSLATORS"), 320);
for(int i = 0; i < ENTRIES_PER_SCREEN && i < (int)Translators.size(); i++) {
Gui::Draw_Rect(0, 40+(i*57), 320, 45, config->unselectedColor());
line1 = Translators[screenPos + i];
line2 = Languages[screenPos + i];
if (screenPos + i == Selection) {
Gui::drawAnimatedSelector(0, 40+(i*57), 320, 45, .060, TRANSPARENT, config->selectedColor());
}
Gui::DrawStringCentered(0, 38+(i*57), 0.7f, config->textColor(), line1, 320);
Gui::DrawStringCentered(0, 62+(i*57), 0.7f, config->textColor(), line2, 320);
}
} else if (creditsPage == 1) {
Gui::DrawStringCentered(0, -2, 0.7f, config->textColor(), "Universal-Team", 320);
for(int i = 0; i < ENTRIES_PER_SCREEN && i < (int)UniversalTeam.size(); i++) {
Gui::Draw_Rect(0, 40+(i*57), 320, 45, config->unselectedColor());
line1 = UniversalTeam[screenPos + i];
if (screenPos + i == Selection) {
Gui::drawAnimatedSelector(0, 40+(i*57), 320, 45, .060, TRANSPARENT, config->selectedColor());
}
Gui::DrawStringCentered(0, 50+(i*57), 0.7f, config->textColor(), line1, 320);
}
} else if (creditsPage == 2) {
Gui::DrawStringCentered(0, -2, 0.7f, config->textColor(), Lang::get("SCRIPTCREATORS"), 320);
for(int i = 0; i < ENTRIES_PER_SCREEN && i < (int)ScriptCreators.size(); i++) {
Gui::Draw_Rect(0, 40+(i*57), 320, 45, config->unselectedColor());
line1 = ScriptCreators[screenPos + i];
line2 = ScriptAmount[screenPos + i];
if (screenPos + i == Selection) {
Gui::drawAnimatedSelector(0, 40+(i*57), 320, 45, .060, TRANSPARENT, config->selectedColor());
}
Gui::DrawStringCentered(0, 38+(i*57), 0.7f, config->textColor(), line1, 320);
Gui::DrawStringCentered(0, 62+(i*57), 0.7f, config->textColor(), line2, 320);
}
} else if (creditsPage == 3) {
Gui::DrawStringCentered(0, -2, 0.7f, config->textColor(), "Special Thanks", 320);
for(int i = 0; i < ENTRIES_PER_SCREEN && i < (int)specialNames.size(); i++) {
Gui::Draw_Rect(0, 40+(i*57), 320, 45, config->unselectedColor());
line1 = specialNames[screenPos + i];
line2 = specialDescriptions[screenPos + i];
if (screenPos + i == Selection) {
Gui::drawAnimatedSelector(0, 40+(i*57), 320, 45, .060, TRANSPARENT, config->selectedColor());
}
Gui::DrawStringCentered(0, 38+(i*57), 0.7f, config->textColor(), line1, 320);
Gui::DrawStringCentered(0, 62+(i*57), 0.7f, config->textColor(), line2, 320);
}
} else {
Gui::DrawStringCentered(0, -2, 0.55f, config->textColor(), Lang::get("LINK"), 320);
}
}
void Credits::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
if (keyRepeatDelay) keyRepeatDelay--;
// KEY_DOWN Logic. (SIZE)
if (creditsPage == 0) {
if ((hHeld & KEY_DOWN && !keyRepeatDelay)) {
if (Selection < (int)Translators.size()-1) {
Selection++;
} else {
Selection = 0;
}
keyRepeatDelay = config->keyDelay();
}
} else if (creditsPage == 1) {
if ((hHeld & KEY_DOWN && !keyRepeatDelay)) {
if (Selection < (int)UniversalTeam.size()-1) {
Selection++;
} else {
Selection = 0;
}
keyRepeatDelay = config->keyDelay();
}
} else if (creditsPage == 2) {
if ((hHeld & KEY_DOWN && !keyRepeatDelay)) {
if (Selection < (int)ScriptCreators.size()-1) {
Selection++;
} else {
Selection = 0;
}
keyRepeatDelay = config->keyDelay();
}
} else if (creditsPage == 3) {
if ((hHeld & KEY_DOWN && !keyRepeatDelay)) {
if (Selection < (int)specialNames.size()-1) {
Selection++;
} else {
Selection = 0;
}
keyRepeatDelay = config->keyDelay();
}
}
if ((hHeld & KEY_UP && !keyRepeatDelay)) {
if (Selection > 0) {
Selection--;
} else {
if (creditsPage == 0) {
Selection = (int)Translators.size()-1;
} else if (creditsPage == 1) {
Selection = (int)UniversalTeam.size()-1;
} else if (creditsPage == 2) {
Selection = (int)ScriptCreators.size()-1;
} else if (creditsPage == 3) {
Selection = (int)specialNames.size()-1;
}
}
keyRepeatDelay = config->keyDelay();
}
if ((hDown & KEY_L || hDown & KEY_LEFT)) {
if (creditsPage > 0) {
Selection = 0;
creditsPage--;
}
}
if ((hDown & KEY_R || hDown & KEY_RIGHT)) {
if (creditsPage < 4) {
Selection = 0;
creditsPage++;
}
}
if (hDown & KEY_B) {
Gui::screenBack(config->screenFade());
return;
}
if (Selection < screenPos) {
screenPos = Selection;
} else if (Selection > screenPos + ENTRIES_PER_SCREEN - 1) {
screenPos = Selection - ENTRIES_PER_SCREEN + 1;
}
}
-109
View File
@@ -1,109 +0,0 @@
/*
* This file is part of Universal-Updater
* Copyright (C) 2019-2020 Universal-Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "config.hpp"
#include "credits.hpp"
#include "mainMenu.hpp"
#include "scriptHelper.hpp"
#include "scriptlist.hpp"
#include "settings.hpp"
#include "unistore.hpp"
extern std::unique_ptr<Config> config;
extern bool exiting;
extern bool touching(touchPosition touch, Structs::ButtonPos button);
extern int fadealpha;
extern bool fadein;
extern u32 TextColor;
void MainMenu::Draw(void) const {
GFX::DrawTop();
Gui::DrawStringCentered(0, config->useBars() ? 0 : 2, 0.7f, config->textColor(), "Universal-Updater", 400);
Gui::DrawString(397-Gui::GetStringWidth(0.5f, V_STRING), (config->useBars() ? 239 : 237)-Gui::GetStringHeight(0.5f, V_STRING), 0.5f, config->textColor(), V_STRING);
GFX::DrawSprite(sprites_universal_updater_idx, 110, 30);
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 400, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
GFX::DrawBottom();
GFX::DrawArrow(0, 218, 0, 1);
GFX::DrawButton(mainButtons[0].x, mainButtons[0].y, "UniStore");
GFX::DrawButton(mainButtons[1].x, mainButtons[1].y, Lang::get("SCRIPTS"));
GFX::DrawButton(mainButtons[2].x, mainButtons[2].y, Lang::get("SETTINGS"));
GFX::DrawButton(mainButtons[3].x, mainButtons[3].y, Lang::get("CREDITS"));
// Selector.
Animation::Button(mainButtons[Selection].x, mainButtons[Selection].y, .060);
// Draw UniStore Icon. ;P
//GFX::DrawSprite(sprites_uniStore_idx, 10, 65);
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 320, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
}
void MainMenu::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
if ((hDown & KEY_START) || (hDown & KEY_TOUCH && touching(touch, mainButtons[4]))) {
fadeout = true;
fadecolor = 0;
exiting = true;
}
// Navigation.
if (hDown & KEY_UP) {
if (Selection > 1) Selection -= 2;
} else if (hDown & KEY_DOWN) {
if (Selection < 3 && Selection != 2 && Selection != 3) Selection += 2;
} else if (hDown & KEY_LEFT) {
if (Selection%2) Selection--;
} else if (hDown & KEY_RIGHT) {
if (!(Selection%2)) Selection++;
}
if (hDown & KEY_A) {
switch(Selection) {
case 0:
Gui::setScreen(std::make_unique<UniStore>(false, "NOT_USED"), config->screenFade(), true);
break;
case 1:
Gui::setScreen(std::make_unique<ScriptList>(), config->screenFade(), true);
break;
case 2:
Gui::setScreen(std::make_unique<Settings>(), config->screenFade(), true);
break;
case 3:
Gui::setScreen(std::make_unique<Credits>(), config->screenFade(), true);
break;
}
}
if (hDown & KEY_TOUCH) {
if (touching(touch, mainButtons[0])) {
Gui::setScreen(std::make_unique<UniStore>(false, "NOT_USED"), config->screenFade(), true);
} else if (touching(touch, mainButtons[1])) {
Gui::setScreen(std::make_unique<ScriptList>(), config->screenFade(), true);
} else if (touching(touch, mainButtons[2])) {
Gui::setScreen(std::make_unique<Settings>(), config->screenFade(), true);
} else if (touching(touch, mainButtons[3])) {
Gui::setScreen(std::make_unique<Credits>(), config->screenFade(), true);
}
}
}
+161
View File
@@ -0,0 +1,161 @@
/*
* This file is part of Universal-Updater
* Copyright (C) 2019-2020 Universal-Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "download.hpp"
#include "mainScreen.hpp"
#include "storeUtils.hpp"
#include <unistd.h>
extern int fadeAlpha;
extern u32 hRepeat;
/*
MainScreen Constructor.
Initialized Meta, Store and StoreEntry class and:
- Downloads Universal-DB.. in case nothing exist.
*/
MainScreen::MainScreen() {
this->meta = std::make_unique<Meta>();
/* Check if lastStore is accessible. */
if (config->lastStore() != "universal-db-beta.unistore" || config->lastStore() != "") {
if (access((std::string(_STORE_PATH) + config->lastStore()).c_str(), F_OK) != 0) {
config->lastStore("universal-db-beta.unistore");
}
}
/* If Universal DB --> Get! */
if (config->lastStore() == "universal-db-beta.unistore" || config->lastStore() == "") {
if (access("sdmc:/3ds/Universal-Updater/stores/universal-db-beta.unistore", F_OK) != 0) {
std::string tmp = "";
DownloadUniStore("https://db.universal-team.net/unistore/universal-db-beta.unistore", -1, tmp, true, true);
DownloadSpriteSheet("https://db.universal-team.net/unistore/universal-db.t3x", "universal-db.t3x");
}
}
this->store = std::make_unique<Store>(_STORE_PATH + config->lastStore());
StoreUtils::ResetAll(this->store, this->meta, this->entries);
StoreUtils::SortEntries(false, SortType::LAST_UPDATED, this->entries);
};
/*
MainScreen Main Draw.
*/
void MainScreen::Draw(void) const {
GFX::DrawTop();
if (this->store && this->store->GetValid()) Gui::DrawStringCentered(0, 1, 0.7, TEXT_COLOR, this->store->GetUniStoreTitle());
else Gui::DrawStringCentered(0, 1, 0.7f, TEXT_COLOR, Lang::get("INVALID_UNISTORE"), 370);
config->list() ? StoreUtils::DrawList(this->store, this->entries) : StoreUtils::DrawGrid(this->store, this->entries);
if (fadeAlpha > 0) Gui::Draw_Rect(0, 0, 400, 240, C2D_Color32(0, 0, 0, fadeAlpha));
GFX::DrawBottom();
switch(this->storeMode) {
case 0:
/* Entry Info. */
if (this->store && this->store->GetValid() && this->entries.size() > 0) StoreUtils::DrawEntryInfo(this->store, this->entries[this->store->GetEntry()]);
break;
case 1:
/* Download List. */
StoreUtils::DrawDownList(this->store, this->dwnldList, this->fetchDown);
break;
case 2:
/* Search + Favorites. */
StoreUtils::DrawSearchMenu(this->searchIncludes, this->searchResult, this->marks, this->updateFilter);
break;
case 3:
/* Sorting. */
StoreUtils::DrawSorting(this->ascending, this->sorttype);
break;
case 4:
/* Settings. */
StoreUtils::DrawSettings(this->sPage, this->sSelection);
break;
}
StoreUtils::DrawSideMenu(this->storeMode);
if (this->showMarks && this->store && this->store->GetValid()) StoreUtils::DisplayMarkBox(this->entries[this->store->GetEntry()]->GetMarks());
if (fadeAlpha > 0) Gui::Draw_Rect(0, 0, 320, 240, C2D_Color32(0, 0, 0, fadeAlpha));
}
/*
MainScreen Logic.
*/
void MainScreen::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
if (this->showMarks) StoreUtils::MarkHandle(hDown, hHeld, touch, this->entries[this->store->GetEntry()], this->store, this->showMarks, this->meta);
if (!this->showMarks) {
if (this->storeMode == 0 || this->storeMode == 2 || this->storeMode == 3) {
config->list() ? StoreUtils::ListLogic(hDown, hHeld, touch, this->store, this->entries, this->storeMode, this->lastMode, this->fetchDown, this->smallDelay) : StoreUtils::GridLogic(hDown, hHeld, touch, this->store, this->entries, this->storeMode, this->lastMode, this->fetchDown, this->smallDelay);
}
StoreUtils::SideMenuHandle(hDown, touch, this->storeMode, this->fetchDown);
/* Fetch Download list. */
if (this->fetchDown) {
this->dwnldList.clear();
if (this->store && this->store->GetValid()) {
this->store->SetDownloadIndex(0); // Reset to 0.
this->store->SetDownloadSIndex(0);
if ((int)this->entries.size() > this->store->GetEntry()) {
this->dwnldList = this->store->GetDownloadList(this->entries[this->store->GetEntry()]->GetEntryIndex());
}
}
this->fetchDown = false;
}
switch(this->storeMode) {
case 0:
if (this->store && this->store->GetValid()) StoreUtils::EntryHandle(hDown, hHeld, touch, this->showMarks, this->fetchDown);
break;
case 1:
if (this->store && this->store->GetValid()) StoreUtils::DownloadHandle(hDown, hHeld, touch, this->store, this->entries[this->store->GetEntry()], this->dwnldList, this->storeMode, this->meta, this->lastMode, this->smallDelay);
break;
case 2:
StoreUtils::SearchHandle(hDown, hHeld, touch, this->store, this->entries, this->searchIncludes, this->meta, this->searchResult, this->marks, this->updateFilter, this->ascending, this->sorttype);
break;
case 3:
StoreUtils::SortHandle(hDown, hHeld, touch, this->store, this->entries, this->ascending, this->sorttype);
break;
case 4:
StoreUtils::SettingsHandle(hDown, hHeld, touch, this->sPage, this->showSettings, this->storeMode, this->sSelection, this->store, this->entries, this->meta);
break;
}
}
}
-527
View File
@@ -1,527 +0,0 @@
/*
* This file is part of Universal-Updater
* Copyright (C) 2019-2020 Universal-Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "download.hpp"
#include "fileBrowse.hpp"
#include "json.hpp"
#include "scriptBrowse.hpp"
#include <unistd.h>
extern std::unique_ptr<Config> config;
extern bool touching(touchPosition touch, Structs::ButtonPos button);
extern void downloadFailed();
void fixInfo(nlohmann::json &json) {
for(uint i = 0; i < json.size(); i++) {
if (!json[i].contains("title")) json[i]["title"] = "TITLE";
if (!json[i].contains("author")) json[i]["author"] = "AUTHOR";
if (!json[i].contains("shortDesc")) json[i]["shortDesc"] = "SHORTDESC";
if (!json[i].contains("revision")) json[i]["revision"] = 0;
if (!json[i].contains("curRevision")) json[i]["curRevision"] = -1;
if (!json[i].contains("version")) json[i]["revision"] = -1;
}
}
nlohmann::json infoFromScript(const std::string &path) {
nlohmann::json in, out;
FILE* file = fopen(path.c_str(), "r");
if (!file) return out;
in = nlohmann::json::parse(file, nullptr, false);
fclose(file);
if (in.contains("info")) {
if (in["info"].contains("title") && in["info"]["title"].is_string()) out["title"] = in["info"]["title"];
if (in["info"].contains("author") && in["info"]["author"].is_string()) out["author"] = in["info"]["author"];
if (in["info"].contains("shortDesc") && in["info"]["shortDesc"].is_string()) out["shortDesc"] = in["info"]["shortDesc"];
if (in["info"].contains("version") && in["info"]["version"].is_number()) out["version"] = in["info"]["version"];
if (in["info"].contains("revision") && in["info"]["revision"].is_number()) out["revision"] = in["info"]["revision"];
}
return out;
}
void findExistingFiles(nlohmann::json &json) {
nlohmann::json current;
chdir(config->scriptPath().c_str());
std::vector<DirEntry> dirContents;
getDirectoryContents(dirContents);
for(uint i = 0; i < dirContents.size(); i++) {
current[i] = infoFromScript(dirContents[i].name);
}
fixInfo(current);
for(uint i = 0; i < json.size(); i++) {
for(uint j = 0; j < current.size(); j++) {
if (current[j]["title"] == json[i]["title"]) {
json[i]["curRevision"] = current[j]["revision"];
}
}
}
}
ScriptBrowse::ScriptBrowse() {
Msg::DisplayMsg(Lang::get("GETTING_SCRIPT_LIST"));
// Get repo info
if (downloadToFile("https://github.com/Universal-Team/Universal-Updater-Scripts/raw/master/info/scriptInfo.json", metaFile) != 0) {
downloadFailed();
loaded = false;
return;
}
FILE* file = fopen(metaFile, "r");
if (file) {
infoJson = nlohmann::json::parse(file, nullptr, false);
fclose(file);
fixInfo(infoJson);
findExistingFiles(infoJson);
maxScripts = infoJson.size();
loaded = true;
// File is not able to be parsed, go screen back.
} else {
loaded = false;
}
}
void ScriptBrowse::refresh() {
if (checkWifiStatus() == true) {
if (Msg::promptMsg(Lang::get("REFRESH_SCRIPTBROWSE_PROMPT"))) {
Msg::DisplayMsg(Lang::get("GETTING_SCRIPT_LIST"));
if (downloadToFile("https://github.com/Universal-Team/Universal-Updater-Scripts/raw/master/info/scriptInfo.json", metaFile) != 0) {
downloadFailed();
loaded = false;
return;
}
FILE* file = fopen(metaFile, "r");
if (file) {
infoJson = nlohmann::json::parse(file, nullptr, false);
fclose(file);
fixInfo(infoJson);
findExistingFiles(infoJson);
maxScripts = infoJson.size();
Selection = 0;
loaded = true;
} else {
loaded = false;
}
}
} else {
notConnectedMsg();
}
}
void ScriptBrowse::Draw(void) const {
if (mode == 0) {
DrawBrowse();
} else {
DrawGlossary();
}
}
void ScriptBrowse::DrawBrowse(void) const {
GFX::DrawTop();
if (loaded) {
std::string revision = std::to_string(int64_t(infoJson[Selection]["curRevision"]));
revision += " | ";
revision += std::to_string(int64_t(infoJson[Selection]["revision"]));
Gui::DrawStringCentered(0, config->useBars() ? 0 : 2, 0.7f, config->textColor(), std::string(infoJson[Selection]["title"]), 400);
Gui::DrawString(397-Gui::GetStringWidth(0.6f, revision), (config->useBars() ? 239 : 237)-Gui::GetStringHeight(0.6f, revision), 0.6f, config->textColor(), revision);
Gui::DrawStringCentered(0, 120, 0.6f, config->textColor(), std::string(infoJson[Selection]["shortDesc"]), 400);
if (infoJson[Selection]["curRevision"] == -1) {
Gui::DrawStringCentered(0, 219, 0.7f, config->textColor(), Lang::get("SCRIPT_NOT_FOUND"), 370);
} else if(infoJson[Selection]["curRevision"] < infoJson[Selection]["revision"]) {
Gui::DrawStringCentered(0, 219, 0.7f, config->textColor(), Lang::get("OUTDATED_SCRIPT"), 370);
} else if(infoJson[Selection]["curRevision"] == infoJson[Selection]["revision"]) {
Gui::DrawStringCentered(0, 219, 0.7f, config->textColor(), Lang::get("UP-TO-DATE"), 370);
} else if(infoJson[Selection]["curRevision"] > infoJson[Selection]["revision"]) {
Gui::DrawStringCentered(0, 219, 0.7f, config->textColor(), Lang::get("FUTURE_SCRIPT"), 370);
}
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 400, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
GFX::DrawBottom();
GFX::DrawArrow(295, -1);
GFX::DrawArrow(315, 240, 180.0);
GFX::DrawArrow(0, 218, 0, 1);
GFX::DrawSpriteBlend(sprites_dropdown_idx, arrowPos[3].x, arrowPos[3].y);
Gui::DrawStringCentered(0, 1, 0.6f, config->textColor(), std::to_string(Selection + 1) + " | " + std::to_string(maxScripts));
if (config->viewMode() == 0) {
for(int i = 0; i < ENTRIES_PER_SCREEN && i < (int)infoJson.size(); i++) {
Gui::Draw_Rect(0, 40+(i*57), 320, 45, config->unselectedColor());
if (screenPos + i == Selection) {
if (!dropDownMenu) {
Gui::drawAnimatedSelector(0, 40+(i*57), 320, 45, .060, TRANSPARENT, config->selectedColor());
}
}
if (infoJson[screenPos+i]["curRevision"] == -1) {
Gui::Draw_Rect(295, 45+(i*59), 20, 20, config->notfoundColor());
} else if (infoJson[screenPos+i]["curRevision"] < infoJson[screenPos+i]["revision"]) {
Gui::Draw_Rect(295, 45+(i*59), 20, 20, config->outdatedColor());
} else if (infoJson[screenPos+i]["curRevision"] == infoJson[screenPos+i]["revision"]) {
Gui::Draw_Rect(295, 45+(i*59), 20, 20, config->uptodateColor());
} else if (infoJson[screenPos+i]["curRevision"] > infoJson[screenPos+i]["revision"]) {
Gui::Draw_Rect(295, 45+(i*59), 20, 20, config->futureColor());
}
Gui::DrawStringCentered(0, 38+(i*57), 0.7f, config->textColor(), infoJson[screenPos+i]["title"], 317);
Gui::DrawStringCentered(0, 62+(i*57), 0.7f, config->textColor(), infoJson[screenPos+i]["author"], 317);
}
} else if (config->viewMode() == 1) {
for(int i = 0; i < ENTRIES_PER_LIST && i < (int)infoJson.size(); i++) {
Gui::Draw_Rect(0, (i+1)*27, 320, 25, config->unselectedColor());
if (screenPosList + i == Selection) {
if (!dropDownMenu) {
Gui::drawAnimatedSelector(0, (i+1)*27, 320, 25, .060, TRANSPARENT, config->selectedColor());
}
}
// Script not found.
if (infoJson[screenPosList+i]["curRevision"] == -1) {
Gui::Draw_Rect(302, ((i+1)*27)+7, 11, 11, config->notfoundColor());
// Script outdaed.
} else if (infoJson[screenPosList+i]["curRevision"] < infoJson[screenPosList+i]["revision"]) {
Gui::Draw_Rect(302, ((i+1)*27)+7, 11, 11, config->outdatedColor());
// Script up-to-date.
} else if (infoJson[screenPosList+i]["curRevision"] == infoJson[screenPosList+i]["revision"]) {
Gui::Draw_Rect(302, ((i+1)*27)+7, 11, 11, config->uptodateColor());
// Future script.
} else if (infoJson[screenPosList+i]["curRevision"] > infoJson[screenPosList+i]["revision"]) {
Gui::Draw_Rect(302, ((i+1)*27)+7, 11, 11, config->futureColor());
}
Gui::DrawStringCentered(0, ((i+1)*27)+1, 0.7f, config->textColor(), infoJson[screenPosList+i]["title"], 317);
}
}
// DropDown Menu.
if (dropDownMenu) {
// Draw Operation Box.
Gui::Draw_Rect(0, 25, 140, 130, config->barColor());
for (int i = 0; i < 3; i++) {
if (dropSelection == i) {
Gui::drawAnimatedSelector(dropPos2[i].x, dropPos2[i].y, dropPos2[i].w, dropPos2[i].h, .090, TRANSPARENT, config->selectedColor());
} else {
Gui::Draw_Rect(dropPos2[i].x, dropPos2[i].y, dropPos2[i].w, dropPos2[i].h, config->unselectedColor());
}
}
// Draw Dropdown Icons.
GFX::DrawSpriteBlend(sprites_download_all_idx, dropPos[0].x, dropPos[0].y);
GFX::DrawSpriteBlend(sprites_update_idx, dropPos[1].x, dropPos[1].y);
GFX::DrawSpriteBlend(sprites_view_idx, dropPos[2].x, dropPos[2].y);
// Dropdown Text.
Gui::DrawString(dropPos[0].x+30, dropPos[0].y+5, 0.4f, config->textColor(), Lang::get("DOWNLOAD_ALL_DDM"), 100);
Gui::DrawString(dropPos[1].x+30, dropPos[1].y+5, 0.4f, config->textColor(), Lang::get("REFRESH_BROWSE_DDM"), 100);
Gui::DrawString(dropPos[2].x+30, dropPos[2].y+5, 0.4f, config->textColor(), Lang::get("VIEW_DDM"), 100);
}
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 320, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
} else {
GFX::DrawBottom();
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 320, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
}
}
void ScriptBrowse::DrawGlossary(void) const {
GFX::DrawTop();
if (loaded) {
Gui::DrawStringCentered(0, config->useBars() ? 0 : 2, 0.7f, config->textColor(), Lang::get("GLOSSARY"), 400);
Gui::Draw_Rect(20, 30, 30, 30, config->notfoundColor());
Gui::DrawString(65, 35, 0.7f, config->textColor(), Lang::get("SCRIPT_NOT_FOUND"), 300);
Gui::Draw_Rect(20, 70, 30, 30, config->outdatedColor());
Gui::DrawString(65, 75, 0.7f, config->textColor(), Lang::get("OUTDATED_SCRIPT"), 300);
Gui::Draw_Rect(20, 110, 30, 30, config->uptodateColor());
Gui::DrawString(65, 115, 0.7f, config->textColor(), Lang::get("UP-TO-DATE"), 300);
Gui::Draw_Rect(20, 150, 30, 30, config->futureColor());
Gui::DrawString(65, 155, 0.7f, config->textColor(), Lang::get("FUTURE_SCRIPT"), 300);
Gui::DrawString(15, 185, 0.7f, config->textColor(), std::to_string(int64_t(infoJson[Selection]["curRevision"])) + " | " + std::to_string(int64_t(infoJson[Selection]["revision"])), 40);
Gui::DrawString(65, 185, 0.7f, config->textColor(), Lang::get("REVISION"), 300);
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 400, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
GFX::DrawBottom();
GFX::DrawSpriteBlend(sprites_download_all_idx, 20, 25);
Gui::DrawString(50, 27, 0.6f, config->textColor(), Lang::get("DOWNLOAD_ALL"), 260);
GFX::DrawSpriteBlend(sprites_view_idx, 20, 55);
Gui::DrawString(50, 57, 0.6f, config->textColor(), Lang::get("CHANGE_VIEW_MODE"), 260);
GFX::DrawArrow(20, 85);
Gui::DrawString(50, 87, 0.6f, config->textColor(), Lang::get("ENTRY_UP"), 260);
GFX::DrawArrow(42, 140, 180.0);
Gui::DrawString(50, 117, 0.6f, config->textColor(), Lang::get("ENTRY_DOWN"), 260);
GFX::DrawArrow(20, 145, 0, 1);
Gui::DrawString(50, 147, 0.6f, config->textColor(), Lang::get("GO_BACK"), 260);
Gui::DrawString(10, 177, 0.6f, config->textColor(), std::to_string(Selection + 1) + " | " + std::to_string(maxScripts), 35);
Gui::DrawString(50, 177, 0.6f, config->textColor(), Lang::get("ENTRY"), 260);
GFX::DrawSpriteBlend(sprites_update_idx, 20, 195);
Gui::DrawString(50, 197, 0.6f, config->textColor(), Lang::get("REFRESH_SCRIPTBROWSE"), 260);
GFX::DrawArrow(0, 218, 0, 1);
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 320, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
} else {
GFX::DrawBottom();
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 320, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
}
}
void ScriptBrowse::DropDownLogic(u32 hDown, u32 hHeld, touchPosition touch) {
if (loaded) {
if ((hDown & KEY_SELECT) || (hDown & KEY_TOUCH && touching(touch, arrowPos[3]))) {
dropDownMenu = false;
}
if (hDown & KEY_DOWN) {
if (dropSelection < 2) dropSelection++;
}
if (hDown & KEY_UP) {
if (dropSelection > 0) dropSelection--;
}
if (hDown & KEY_A) {
switch(dropSelection) {
case 0:
downloadAll();
break;
case 1:
refresh();
break;
case 2:
if (config->viewMode() == 0) {
config->viewMode(1);
} else {
config->viewMode(0);
}
break;
}
dropDownMenu = false;
}
if (hDown & KEY_TOUCH) {
if (touching(touch, dropPos2[0])) {
downloadAll();
dropDownMenu = false;
} else if (touching(touch, dropPos2[1])) {
refresh();
dropDownMenu = false;
} else if (touching(touch, dropPos2[2])) {
if (config->viewMode() == 0) {
config->viewMode(1);
} else {
config->viewMode(0);
}
dropDownMenu = false;
}
}
}
}
void ScriptBrowse::downloadAll() {
if (infoJson.size() > 0) {
for (int i = 0; i < (int)infoJson.size(); i++) {
int current = i+1;
int total = infoJson.size();
std::string fileName = Lang::get("DOWNLOADING") + std::string(infoJson[i]["title"]);
std::string titleFix = infoJson[i]["title"];
for (int l = 0; l < (int)titleFix.size(); l++) {
if (titleFix[l] == '/') {
titleFix[l] = '-';
}
}
Msg::DisplayMsg(fileName + " " + std::to_string(current) + " / " + std::to_string(total));
downloadToFile(infoJson[i]["url"], config->scriptPath() + titleFix + ".json");
infoJson[i]["curRevision"] = infoJson[i]["revision"];
}
}
}
void ScriptBrowse::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
if (loaded) {
if (keyRepeatDelay) keyRepeatDelay--;
if (dropDownMenu) {
DropDownLogic(hDown, hHeld, touch);
} else {
if ((hDown & KEY_B) || (hDown & KEY_TOUCH && touching(touch, arrowPos[2]))) {
Gui::screenBack(config->screenFade());
return;
}
if (mode == 0) {
if ((hHeld & KEY_DOWN && !keyRepeatDelay) || (hDown & KEY_TOUCH && touching(touch, arrowPos[1]))) {
if (Selection < (int)infoJson.size()-1) {
Selection++;
} else {
Selection = 0;
}
keyRepeatDelay = config->keyDelay();
}
if ((hHeld & KEY_RIGHT && !keyRepeatDelay)) {
if (config->viewMode() == 0) {
if (Selection < (int)infoJson.size()-1-3) {
Selection += 3;
} else {
Selection = (int)infoJson.size()-1;
}
} else {
if (Selection < (int)infoJson.size()-1-6) {
Selection += 7;
} else {
Selection = (int)infoJson.size()-1;
}
}
keyRepeatDelay = config->keyDelay();
}
if ((hHeld & KEY_LEFT && !keyRepeatDelay)) {
if (config->viewMode() == 0) {
if (Selection > 2) {
Selection -= 3;
} else {
Selection = 0;
}
} else {
if (Selection > 6) {
Selection -= 7;
} else {
Selection = 0;
}
}
keyRepeatDelay = config->keyDelay();
}
if ((hDown & KEY_SELECT) || (hDown & KEY_TOUCH && touching(touch, arrowPos[3]))) {
dropDownMenu = true;
}
if ((hHeld & KEY_UP && !keyRepeatDelay) || (hDown & KEY_TOUCH && touching(touch, arrowPos[0]))) {
if (Selection > 0) {
Selection--;
} else {
Selection = (int)infoJson.size()-1;
}
keyRepeatDelay = config->keyDelay();
}
if (hDown & KEY_TOUCH) {
if (config->viewMode() == 0) {
for(int i = 0; i < ENTRIES_PER_SCREEN && i < (int)infoJson.size(); i++) {
if (touch.py > 40+(i*57) && touch.py < 40+(i*57)+45) {
if (infoJson.size() != 0) {
std::string fileName = Lang::get("DOWNLOADING") + std::string(infoJson[screenPos + i]["title"]);
std::string titleFix = infoJson[screenPos + i]["title"];
for (int l = 0; l < (int)titleFix.size(); l++) {
if (titleFix[l] == '/') {
titleFix[l] = '-';
}
}
Msg::DisplayMsg(fileName);
downloadToFile(infoJson[screenPos + i]["url"], config->scriptPath() + titleFix + ".json");
infoJson[screenPos + i]["curRevision"] = infoJson[screenPos + i]["revision"];
}
}
}
} else if (config->viewMode() == 1) {
for(int i = 0; i < ENTRIES_PER_LIST && i < (int)infoJson.size(); i++) {
if (touch.py > (i+1)*27 && touch.py < (i+2)*27) {
if (infoJson.size() != 0) {
std::string fileName = Lang::get("DOWNLOADING") + std::string(infoJson[screenPosList + i]["title"]);
std::string titleFix = infoJson[screenPosList + i]["title"];
for (int l = 0; l < (int)titleFix.size(); l++) {
if (titleFix[l] == '/') {
titleFix[l] = '-';
}
}
Msg::DisplayMsg(fileName);
downloadToFile(infoJson[screenPosList + i]["url"], config->scriptPath() + titleFix + ".json");
infoJson[screenPosList + i]["curRevision"] = infoJson[screenPosList + i]["revision"];
}
}
}
}
}
if (hDown & KEY_A) {
if (infoJson.size() != 0) {
std::string fileName = Lang::get("DOWNLOADING") + std::string(infoJson[Selection]["title"]);
std::string titleFix = infoJson[Selection]["title"];
for (int i = 0; i < (int)titleFix.size(); i++) {
if (titleFix[i] == '/') {
titleFix[i] = '-';
}
}
Msg::DisplayMsg(fileName);
downloadToFile(infoJson[Selection]["url"], config->scriptPath() + titleFix + ".json");
infoJson[Selection]["curRevision"] = infoJson[Selection]["revision"];
}
}
if (config->viewMode() == 0) {
if(Selection < screenPos) {
screenPos = Selection;
} else if (Selection > screenPos + ENTRIES_PER_SCREEN - 1) {
screenPos = Selection - ENTRIES_PER_SCREEN + 1;
}
} else if (config->viewMode() == 1) {
if(Selection < screenPosList) {
screenPosList = Selection;
} else if (Selection > screenPosList + ENTRIES_PER_LIST - 1) {
screenPosList = Selection - ENTRIES_PER_LIST + 1;
}
}
}
// Switch to Glossary and back.
if (hDown & KEY_R || hDown & KEY_L) {
if (mode == 0) mode = 1;
else mode = 0;
}
}
} else {
if (hDown & KEY_B) {
Gui::screenBack(config->screenFade());
return;
}
}
}
-592
View File
@@ -1,592 +0,0 @@
/*
* This file is part of Universal-Updater
* Copyright (C) 2019-2020 Universal-Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "fileBrowse.hpp"
#include "keyboard.hpp"
#include "logging.hpp"
#include "scriptCreator.hpp"
#include <fstream>
#include <unistd.h>
extern bool touching(touchPosition touch, Structs::ButtonPos button);
extern std::unique_ptr<Config> config;
void ScriptCreator::openJson(std::string fileName) {
std::string scriptFile = fileName;
FILE* file = fopen(scriptFile.c_str(), "r");
fseek(file, 0, SEEK_END);
size_t size = ftell(file);
fseek (file, 0, SEEK_SET);
char data[size + 1];
fread(data, 1, size, file);
data[size] = '\0';
fclose(file);
this->editScript = nlohmann::json::parse((char*)data, nullptr, false);
}
// BOOL.
void ScriptCreator::setBool(const std::string &object, const std::string &key, bool v) {
this->editScript[object][key] = v;
}
void ScriptCreator::setBool2(const std::string &object, const std::string &key, const std::string &key2, bool v) {
this->editScript[object][key][key2] = v;
}
// INT.
void ScriptCreator::setInt(const std::string &object, const std::string &key, int v) {
this->editScript[object][key] = v;
}
void ScriptCreator::setInt2(const std::string &object, const std::string &key, const std::string &key2, int v) {
this->editScript[object][key][key2] = v;
}
// STRING
void ScriptCreator::setString(const std::string &object, const std::string &key, const std::string &v) {
this->editScript[object][key] = v;
}
void ScriptCreator::setString2(const std::string &object, const std::string &key, const std::string &key2, const std::string &v) {
this->editScript[object][key][key2] = v;
}
void ScriptCreator::Draw(void) const {
if (this->mode == 0) {
this->DrawSubMenu();
} else if (this->mode == 1) {
this->DrawScriptScreen();
}
}
void ScriptCreator::DrawSubMenu(void) const {
GFX::DrawTop();
Gui::DrawStringCentered(0, config->useBars() ? 0 : 2, 0.7f, config->textColor(), Lang::get("SCRIPTCREATOR"), 400);
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 400, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
GFX::DrawBottom();
for (int i = 0; i < 2; i++) {
if (this->Selection == i) {
Gui::Draw_Rect(mainButtons[i].x, mainButtons[i].y, mainButtons[i].w, mainButtons[i].h, config->selectedColor());
} else {
Gui::Draw_Rect(mainButtons[i].x, mainButtons[i].y, mainButtons[i].w, mainButtons[i].h, config->unselectedColor());
}
}
Gui::DrawString((320-Gui::GetStringWidth(0.6f, "New script"))/2, mainButtons[0].y+10, 0.6f, config->textColor(), "New script", 140);
Gui::DrawString((320-Gui::GetStringWidth(0.6f, "Existing script"))/2, mainButtons[1].y+10, 0.6f, config->textColor(), "Existing script", 140);
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 320, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
}
void ScriptCreator::DrawScriptScreen(void) const {
GFX::DrawTop();
Gui::DrawStringCentered(0, config->useBars() ? 0 : 2, 0.7f, config->textColor(), "Selected Entry: " + entryName, 400);
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 400, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
GFX::DrawBottom();
// Draw Page.
for (int i = 0; i < 3; i++) {
if (i == this->page) {
Gui::DrawStringCentered(0, 3, 0.6f, config->textColor(), std::to_string(i+1) + " | 3", 140);
}
}
if (this->page == 0) {
for (int i = 0; i < 6; i++) {
if (this->Selection == i) {
Gui::Draw_Rect(creatorButtons[i].x, creatorButtons[i].y, creatorButtons[i].w, creatorButtons[i].h, config->selectedColor());
} else {
Gui::Draw_Rect(creatorButtons[i].x, creatorButtons[i].y, creatorButtons[i].w, creatorButtons[i].h, config->unselectedColor());
}
}
Gui::DrawString((320-Gui::GetStringWidth(0.6f, "downloadRelease"))/2-150+70, creatorButtons[0].y+10, 0.6f, config->textColor(), "downloadRelease", 140);
Gui::DrawString((320-Gui::GetStringWidth(0.6f, "downloadFile"))/2+150-70, creatorButtons[1].y+10, 0.6f, config->textColor(), "downloadFile", 140);
Gui::DrawString((320-Gui::GetStringWidth(0.6f, "deleteFile"))/2-150+70, creatorButtons[2].y+10, 0.6f, config->textColor(), "deleteFile", 140);
Gui::DrawString((320-Gui::GetStringWidth(0.6f, "extractFile"))/2+150-70, creatorButtons[3].y+10, 0.6f, config->textColor(), "extractFile", 140);
Gui::DrawString((320-Gui::GetStringWidth(0.6f, "installCia"))/2-150+70, creatorButtons[4].y+10, 0.6f, config->textColor(), "installCia", 140);
Gui::DrawString((320-Gui::GetStringWidth(0.6f, "mkdir"))/2+150-70, creatorButtons[5].y+10, 0.6f, config->textColor(), "mkdir", 140);
} else if (this->page == 1) {
for (int i = 0; i < 6; i++) {
if (this->Selection == i) {
Gui::Draw_Rect(creatorButtons[i].x, creatorButtons[i].y, creatorButtons[i].w, creatorButtons[i].h, config->selectedColor());
} else {
Gui::Draw_Rect(creatorButtons[i].x, creatorButtons[i].y, creatorButtons[i].w, creatorButtons[i].h, config->unselectedColor());
}
}
Gui::DrawString((320-Gui::GetStringWidth(0.6f, "rmdir"))/2-150+70, creatorButtons[0].y+10, 0.6f, config->textColor(), "rmdir", 140);
Gui::DrawString((320-Gui::GetStringWidth(0.6f, "mkfile"))/2+150-70, creatorButtons[1].y+10, 0.6f, config->textColor(), "mkfile", 140);
Gui::DrawString((320-Gui::GetStringWidth(0.6f, "TimeMsg"))/2-150+70, creatorButtons[2].y+10, 0.6f, config->textColor(), "TimeMsg", 140);
Gui::DrawString((320-Gui::GetStringWidth(0.6f, "saveConfig"))/2+150-70, creatorButtons[3].y+10, 0.6f, config->textColor(), "saveConfig", 140);
Gui::DrawString((320-Gui::GetStringWidth(0.6f, "bootTitle"))/2-150+70, creatorButtons[4].y+10, 0.6f, config->textColor(), "bootTitle", 140);
Gui::DrawString((320-Gui::GetStringWidth(0.6f, "promptMsg"))/2+150-70, creatorButtons[5].y+10, 0.6f, config->textColor(), "promptMsg", 140);
} else if (this->page == 2) {
for (int i = 0; i < 3; i++) {
if (this->Selection == i) {
Gui::Draw_Rect(creatorButtons[i].x, creatorButtons[i].y, creatorButtons[i].w, creatorButtons[i].h, config->selectedColor());
} else {
Gui::Draw_Rect(creatorButtons[i].x, creatorButtons[i].y, creatorButtons[i].w, creatorButtons[i].h, config->unselectedColor());
}
}
Gui::DrawString((320-Gui::GetStringWidth(0.6f, "copy"))/2-150+70, creatorButtons[0].y+10, 0.6f, config->textColor(), "copy", 140);
Gui::DrawString((320-Gui::GetStringWidth(0.6f, "move"))/2+150-70, creatorButtons[1].y+10, 0.6f, config->textColor(), "move", 140);
Gui::DrawString((320-Gui::GetStringWidth(0.6f, "change Entry"))/2-150+70, creatorButtons[2].y+10, 0.6f, config->textColor(), "change Entry", 140);
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 320, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
}
}
void ScriptCreator::createNewJson(std::string fileName) {
std::ofstream ofstream;
ofstream.open(fileName.c_str(), std::ofstream::out | std::ofstream::app);
ofstream << "{ }";
ofstream.close();
}
// Test.
void ScriptCreator::createDownloadRelease() {
// Repo.
std::string repo = Input::setkbdString(50, "Enter the name of the Owner.");
repo += "/";
repo += Input::setkbdString(50, "Enter the name of the repo.");
// File.
std::string file = Input::setkbdString(50, "Enter the name of the file.");
// Output.
std::string output = Input::setkbdString(50, "Enter the name of the Output path.");
// Prerelease.
bool prerelease = true;
// Message.
std::string message = Input::setkbdString(50, "Enter the Message.");
this->editScript[this->entryName].push_back({{"type", "downloadRelease"}, {"repo", repo}, {"file", file}, {"output", output}, {"includePrerelease", prerelease}, {"message", message}});
Logging::writeToLog("Execute 'ScriptCreator::createDownloadRelease();'.");
}
// To-Do.
void ScriptCreator::createDownloadFile() {
// URL of the file.
std::string file = Input::setkbdString(50, "Enter the URL of the file.");
// Output.
std::string output = Input::setkbdString(50, "Enter the name of the Output path.");
// Message.
std::string message = Input::setkbdString(50, "Enter the Message.");
this->editScript[this->entryName].push_back({{"type", "downloadFile"}, {"file", file}, {"output", output}, {"message", message}});
Logging::writeToLog("Execute 'ScriptCreator::createDownloadFile();'.");
}
void ScriptCreator::createDeleteFile() {
// URL of the file.
std::string file = Input::setkbdString(50, "Enter the path to the file.");
// Message.
std::string message = Input::setkbdString(50, "Enter the Message.");
this->editScript[this->entryName].push_back({{"type", "deleteFile"}, {"file", file}, {"message", message}});
Logging::writeToLog("Execute 'ScriptCreator::createDeleteFile();'.");
}
void ScriptCreator::createExtractFile() {
// File path.
std::string file = Input::setkbdString(50, "Enter the path to the file.");
// Input of the archive.
std::string input = Input::setkbdString(50, "Enter the Input of what should be extracted.");
// Output path.
std::string output = Input::setkbdString(50, "Enter the output path.");
// Message.
std::string message = Input::setkbdString(50, "Enter the Message.");
this->editScript[this->entryName].push_back({{"type", "extractFile"}, {"file", file}, {"input", input}, {"output", output}, {"message", message}});
Logging::writeToLog("Execute 'ScriptCreator::createExtractFile();'.");
}
void ScriptCreator::createInstallCia() {
// File path.
std::string file = Input::setkbdString(50, "Enter the path to the CIA File.");
// Message.
std::string message = Input::setkbdString(50, "Enter the Message.");
this->editScript[this->entryName].push_back({{"type", "installCia"}, {"file", file}, {"message", message}});
Logging::writeToLog("Execute 'ScriptCreator::createInstallCia();'.");
}
void ScriptCreator::createMkDir() {
// Directory path.
std::string directory = Input::setkbdString(50, "Enter the directory path.");
this->editScript[this->entryName].push_back({{"type", "mkdir"}, {"directory", directory}});
Logging::writeToLog("Execute 'ScriptCreator::createMkDir();'.");
}
void ScriptCreator::createRmDir() {
// Directory path.
std::string directory = Input::setkbdString(50, "Enter the directory path.");
this->editScript[this->entryName].push_back({{"type", "rmdir"}, {"directory", directory}});
Logging::writeToLog("Execute 'ScriptCreator::createRmDir();'.");
}
void ScriptCreator::createMkFile() {
// File path.
std::string file = Input::setkbdString(50, "Enter the path to the new File.");
this->editScript[this->entryName].push_back({{"type", "mkfile"}, {"file", file}});
Logging::writeToLog("Execute 'ScriptCreator::createMkFile();'.");
}
void ScriptCreator::createTimeMsg() {
int seconds = 0;
// Message.
std::string message = Input::setkbdString(50, "Enter the Message.");
// Seconds.
int temp = Input::setInt(999, "Enter the Seconds for the Message to display.");
if (temp != -1) seconds = temp;
this->editScript[this->entryName].push_back({{"type", "timeMsg"}, {"message", message}, {"seconds", seconds}});
Logging::writeToLog("Execute 'ScriptCreator::createTimeMsg();'.");
}
void ScriptCreator::createSaveConfig() {
this->editScript[this->entryName].push_back({{"type", "saveConfig"}});
Logging::writeToLog("Execute 'ScriptCreator::createSaveConfig();'.");
}
void ScriptCreator::createBootTitle() {
std::string titleID = Input::setkbdString(50, "Enter the TitleID.");
bool isNAND = Msg::promptMsg("Is the current title a NAND title?");
std::string message = Input::setkbdString(50, "Enter the Message.");
this->editScript[this->entryName].push_back({{"type", "bootTitle"}, {"TitleID", titleID}, {"NAND", isNAND}, {"message", message}});
Logging::writeToLog("Execute 'ScriptCreator::createBootTitle();'.");
}
void ScriptCreator::createPromptMessage() {
std::string message = Input::setkbdString(50, "Enter the Message.");
this->editScript[this->entryName].push_back({{"type", "promptMessage"}, {"message", message}});
Logging::writeToLog("Execute 'ScriptCreator::createPromptMessage();'.");
}
void ScriptCreator::createCopy() {
std::string source = Input::setkbdString(50, "Enter the source location.");
std::string destination = Input::setkbdString(50, "Enter the destination location.");
std::string message = Input::setkbdString(50, "Enter the Message.");
this->editScript[this->entryName].push_back({{"type", "copy"}, {"source", source}, {"destination", destination}, {"message", message}});
Logging::writeToLog("Execute 'ScriptCreator::createCopy();'.");
}
void ScriptCreator::createMove() {
std::string oldLocation = Input::setkbdString(50, "Enter the old location.");
std::string newLocation = Input::setkbdString(50, "Enter the new location.");
std::string message = Input::setkbdString(50, "Enter the Message.");
this->editScript[this->entryName].push_back({{"type", "move"}, {"old", oldLocation}, {"new", newLocation}, {"message", message}});
Logging::writeToLog("Execute 'ScriptCreator::createMove();'.");
}
void ScriptCreator::save() {
FILE* file = fopen(this->jsonFileName.c_str(), "w");
std::string result = this->editScript.dump(1, '\t');
if (file) fwrite(result.c_str(), 1, this->editScript.dump(1, '\t').size(), file);
fclose(file);
Logging::writeToLog("Execute 'ScriptCreator::save();'.");
}
// Important to make Scripts valid.
void ScriptCreator::setInfoStuff(void) {
// Get needed things.
const std::string test = Input::setkbdString(50, "Enter the Title of the script.");
const std::string test2 = Input::setkbdString(50, "Enter the Author name of the script.");
const std::string test3 = Input::setkbdString(80, "Enter the short description of the script.");
const std::string test4 = Input::setkbdString(300, "Enter the long description of the script.");
int scriptRevision = Input::setInt(99, "Enter the script revision.");
// Set the real JSON stuff.
this->setString("info", "title", test);
this->setString("info", "author", test2);
this->setString("info", "shortDesc", test3);
this->setString("info", "description", test4);
this->setInt("info", "version", SCRIPT_VERSION);
if (scriptRevision != -1) {
this->setInt("info", "revision", scriptRevision);
} else {
this->setInt("info", "revision", 1);
}
}
void ScriptCreator::SubMenuLogic(u32 hDown, u32 hHeld, touchPosition touch) {
if (hDown & KEY_B) {
Gui::screenBack(config->screenFade());
return;
}
if (hDown & KEY_A) {
switch(Selection) {
case 0:
this->jsonFileName = config->scriptPath();
this->jsonFileName += Input::setkbdString(20, "Enter the name of the JSON file.");
if (this->jsonFileName != "") {
this->jsonFileName += ".json";
this->createNewJson(this->jsonFileName);
this->openJson(this->jsonFileName);
// If not included, create.
if (!this->editScript.contains("info")) {
this->setInfoStuff();
}
this->entryName = Input::setkbdString(50, "Enter the EntryName.");
this->Selection = 0;
this->mode = 1;
}
break;
case 1:
std::string tempScript = selectFilePath("Select the Script file.", config->scriptPath(), {"json"}, 2);
if (tempScript != "") {
this->jsonFileName = tempScript;
if (access(this->jsonFileName.c_str(), F_OK) == 0) {
this->openJson(this->jsonFileName);
this->entryName = Input::setkbdString(50, "Enter the EntryName.");
this->Selection = 0;
this->mode = 1;
}
}
break;
}
}
if (hDown & KEY_UP) {
if (this->Selection == 1) this->Selection = 0;
}
if (hDown & KEY_DOWN) {
if (this->Selection == 0) this->Selection = 1;
}
if (hDown & KEY_TOUCH) {
if (touching(touch, mainButtons[0])) {
this->jsonFileName = config->scriptPath();
this->jsonFileName += Input::setkbdString(20, "Enter the name of the JSON file.");
if (this->jsonFileName != "") {
this->jsonFileName += ".json";
this->createNewJson(this->jsonFileName);
this->openJson(this->jsonFileName);
// If not included, create.
if (!this->editScript.contains("info")) {
this->setInfoStuff();
}
this->entryName = Input::setkbdString(50, "Enter the EntryName.");
this->Selection = 0;
this->mode = 1;
}
} else if (touching(touch, mainButtons[1])) {
std::string tempScript = selectFilePath("Select the Script file.", config->scriptPath(), {"json"}, 2);
if (tempScript != "") {
this->jsonFileName = tempScript;
if (access(this->jsonFileName.c_str(), F_OK) == 0) {
this->openJson(this->jsonFileName);
this->entryName = Input::setkbdString(50, "Enter the EntryName.");
this->Selection = 0;
this->mode = 1;
}
}
}
}
}
void ScriptCreator::scriptLogic(u32 hDown, u32 hHeld, touchPosition touch) {
if (hDown & KEY_B) {
this->save();
this->Selection = 0;
this->mode = 0;
}
// Page 1.
if (this->page == 0 || this->page == 1) {
if (hDown & KEY_UP) {
if (this->Selection > 1) this->Selection -= 2;
}
if (hDown & KEY_DOWN) {
if (this->Selection < 4) this->Selection += 2;
}
if (hDown & KEY_LEFT) {
if (this->Selection%2) this->Selection--;
}
if (hDown & KEY_RIGHT) {
if (!(this->Selection%2)) this->Selection++;
}
} else if (this->page == 2) {
if (hDown & KEY_RIGHT) {
if (this->Selection == 0) this->Selection = 1;
}
if (hDown & KEY_DOWN) {
if (this->Selection == 0) this->Selection = 2;
}
if (hDown & KEY_UP) {
if (this->Selection == 2) this->Selection = 0;
}
if (hDown & KEY_LEFT) {
if (this->Selection == 1) this->Selection = 0;
}
}
if (hDown & KEY_R) {
if (this->page < 2) {
this->page++;
this->Selection = 0;
}
}
if (hDown & KEY_L) {
if (this->page > 0) {
this->page--;
this->Selection = 0;
}
}
if (hDown & KEY_A) {
if (this->page == 0) {
switch(this->Selection) {
case 0:
this->createDownloadRelease();
break;
case 1:
this->createDownloadFile();
break;
case 2:
this->createDeleteFile();
break;
case 3:
this->createExtractFile();
break;
case 4:
this->createInstallCia();
break;
case 5:
this->createMkDir();
break;
}
} else if (this->page == 1) {
switch(this->Selection) {
case 0:
this->createRmDir();
break;
case 1:
this->createMkFile();
break;
case 2:
this->createTimeMsg();
break;
case 3:
this->createSaveConfig();
break;
case 4:
this->createBootTitle();
break;
case 5:
this->createPromptMessage();
break;
}
} else if (this->page == 2) {
switch(this->Selection) {
case 0:
this->createCopy();
break;
case 1:
this->createMove();
break;
case 2:
this->entryName = Input::setkbdString(50, "Enter the new entry.");
break;
}
}
}
if (hDown & KEY_TOUCH) {
if (this->page == 0) {
if (touching(touch, creatorButtons[0])) {
this->createDownloadRelease();
} else if (touching(touch, creatorButtons[1])) {
this->createDownloadFile();
} else if (touching(touch, creatorButtons[2])) {
this->createDeleteFile();
} else if (touching(touch, creatorButtons[3])) {
this->createExtractFile();
} else if (touching(touch, creatorButtons[4])) {
this->createInstallCia();
} else if (touching(touch, creatorButtons[5])) {
this->createMkDir();
}
} else if (this->page == 1) {
if (touching(touch, creatorButtons[0])) {
this->createRmDir();
} else if (touching(touch, creatorButtons[1])) {
this->createMkFile();
} else if (touching(touch, creatorButtons[2])) {
this->createTimeMsg();
} else if (touching(touch, creatorButtons[3])) {
this->createSaveConfig();
} else if (touching(touch, creatorButtons[4])) {
this->createBootTitle();
} else if (touching(touch, creatorButtons[5])) {
this->createPromptMessage();
}
} else if (this->page == 2) {
if (touching(touch, creatorButtons[0])) {
this->createCopy();
} else if (touching(touch, creatorButtons[1])) {
this->createMove();
} else if (touching(touch, creatorButtons[2])) {
this->entryName = Input::setkbdString(50, "Enter the new entry.");
}
}
}
if (hDown & KEY_X) {
this->setInfoStuff(); // Probably not needed at all.
}
}
void ScriptCreator::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
if (this->mode == 0) {
this->SubMenuLogic(hDown, hHeld, touch);
} else if (this->mode == 1) {
this->scriptLogic(hDown, hHeld, touch);
}
}
File diff suppressed because it is too large Load Diff
-668
View File
@@ -1,668 +0,0 @@
/*
* This file is part of Universal-Updater
* Copyright (C) 2019-2020 Universal-Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "keyboard.hpp"
#include "overlay.hpp"
#include "settings.hpp"
extern bool touching(touchPosition touch, Structs::ButtonPos button);
extern std::unique_ptr<Config> config;
int selectedLang;
extern bool changesMade;
Settings::Settings() { selectedLang = 0; }
void Settings::Draw(void) const {
if (mode == 0) {
DrawSubMenu();
} else if (mode == 1) {
DrawLanguageSelection();
} else if (mode == 2) {
DrawColorChanging();
}
}
void Settings::DrawSubMenu(void) const {
GFX::DrawTop();
Gui::DrawStringCentered(0, config->useBars() ? 0 : 2, 0.7f, config->textColor(), "Universal-Updater", 400);
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 400, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
GFX::DrawBottom();
GFX::DrawArrow(0, 218, 0, 1);
GFX::DrawArrow(318, 240, 180.0, 1);
if (this->settingPage == 0) {
GFX::DrawButton(mainButtons[0].x, mainButtons[0].y, Lang::get("LANGUAGE"));
GFX::DrawButton(mainButtons[1].x, mainButtons[1].y, Lang::get("COLORS"));
GFX::DrawButton(mainButtons[2].x, mainButtons[2].y, Lang::get("CHANGE_BAR_STYLE"));
} else if (this->settingPage == 1) {
GFX::DrawButton(mainButtons2[0].x, mainButtons2[0].y, Lang::get("CHANGE_MUSICFILE"));
GFX::DrawButton(mainButtons2[1].x, mainButtons2[1].y, Lang::get("CHANGE_KEY_DELAY"));
GFX::DrawButton(mainButtons2[2].x, mainButtons2[2].y, Lang::get("TOGGLE_FADE"));
GFX::DrawButton(mainButtons2[3].x, mainButtons2[3].y, Lang::get("TOGGLE_PROGRESSBAR"));
} else if (this->settingPage == 2) {
GFX::DrawButton(mainButtons[0].x, mainButtons[0].y, Lang::get("CHANGE_3DSX_PATH"));
GFX::DrawButton(mainButtons[1].x, mainButtons[1].y, Lang::get("CHANGE_NDS_PATH"));
GFX::DrawButton(mainButtons[2].x, mainButtons[2].y, Lang::get("CHANGE_ARCHIVE_PATH"));
}
// Selector.
if (this->settingPage == 0 || this->settingPage == 2) {
Animation::Button(mainButtons[Selection].x, mainButtons[Selection].y, .060);
} else {
Animation::Button(mainButtons2[Selection].x, mainButtons2[Selection].y, .060);
}
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 320, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
}
const std::vector<std::string> languages = {
"Bruh",
"Dansk",
"Deutsch",
"English",
"Español",
"Français",
"Italiano",
"Lietuvių",
"Polski",
"Português",
"Русский",
"日本語"
};
void Settings::DrawLanguageSelection(void) const {
std::string line1;
GFX::DrawTop();
Gui::DrawStringCentered(0, config->useBars() ? 0 : 2, 0.7f, config->textColor(), Lang::get("SELECT_LANG"), 400);
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 400, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
GFX::DrawBottom();
for(int i = 0; i < ENTRIES_PER_SCREEN && i < (int)languages.size(); i++) {
Gui::Draw_Rect(0, 40+(i*57), 320, 45, config->unselectedColor());
line1 = languages[screenPos + i];
if (screenPos + i == selectedLang) {
Gui::drawAnimatedSelector(0, 40+(i*57), 320, 45, .060, TRANSPARENT, config->selectedColor());
}
Gui::DrawStringCentered(0, 50+(i*57), 0.7f, config->textColor(), line1, 320);
}
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 320, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
}
const std::vector<std::string> colorList = {
"BAR_COLOR",
"TOP_BG_COLOR",
"BOTTOM_BG_COLOR",
"TEXT_COLOR",
"SELECTED_COLOR",
"UNSELECTED_COLOR",
"PROGRESSBAR_COLOR",
"NOT_FOUND_COLOR",
"OUTDATED_COLOR",
"UPTODATE_COLOR",
"FUTURE_COLOR",
"BUTTON_COLOR"
};
void Settings::DrawColorChanging(void) const {
std::string line1;
GFX::DrawTop();
Gui::DrawStringCentered(0, config->useBars() ? 0 : 2, 0.7f, config->textColor(), "Universal-Updater", 400);
if (!dropDownMenu) {
if (colorMode == 3) {
Gui::Draw_Rect(0, 40, 400, 45, config->selectedColor());
Gui::DrawStringCentered(0, 45, 0.7f, config->textColor(), Lang::get("TEXT_COLOR"), 320);
} else if (colorMode == 4) {
Gui::Draw_Rect(0, 40, 400, 45, config->selectedColor());
Gui::DrawStringCentered(0, 45, 0.7f, config->textColor(), Lang::get("SELECTED_COLOR"), 320);
} else if (colorMode == 5) {
Gui::Draw_Rect(0, 40, 400, 45, config->unselectedColor());
Gui::DrawStringCentered(0, 45, 0.7f, config->textColor(), Lang::get("UNSELECTED_COLOR"), 320);
} else if (colorMode == 6) {
Gui::Draw_Rect(31, 121, (int)(((float)100/(float)100) * 338.0f), 28, config->progressbarColor());
} else if (colorMode == 7) {
Gui::Draw_Rect(31, 121, (int)(((float)100/(float)100) * 338.0f), 28, config->notfoundColor());
} else if (colorMode == 8) {
Gui::Draw_Rect(31, 121, (int)(((float)100/(float)100) * 338.0f), 28, config->outdatedColor());
} else if (colorMode == 9) {
Gui::Draw_Rect(31, 121, (int)(((float)100/(float)100) * 338.0f), 28, config->uptodateColor());
} else if (colorMode == 10) {
Gui::Draw_Rect(31, 121, (int)(((float)100/(float)100) * 338.0f), 28, config->futureColor());
} else if (colorMode == 11) {
GFX::DrawButton(100, 100, "");
}
Gui::DrawStringCentered(0, 215, 0.7f, WHITE, Lang::get(colorList[colorMode]), 320);
}
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 400, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
GFX::DrawBottom();
if (!dropDownMenu) {
GFX::DrawArrow(0, 218, 0, 1);
GFX::DrawSpriteBlend(sprites_dropdown_idx, arrowPos[5].x, arrowPos[5].y);
}
if (dropDownMenu) {
for(int i = 0; i < ENTRIES_PER_SCREEN && i < (int)colorList.size(); i++) {
Gui::Draw_Rect(0, 40+(i*57), 320, 45, config->unselectedColor());
line1 = Lang::get(colorList[screenPos + i]);
if (screenPos + i == colorSelection) {
Gui::drawAnimatedSelector(0, 40+(i*57), 320, 45, .060, TRANSPARENT, config->selectedColor());
}
Gui::DrawStringCentered(0, 50+(i*57), 0.7f, config->textColor(), line1, 320);
}
} else {
if (colorMode == 0) {
GFX::DrawButton(mainButtons[0].x, mainButtons[0].y, ColorHelper::getColorName(config->barColor(), 2).c_str(), C2D_Color32(255, 0, 0, 255));
GFX::DrawButton(mainButtons[1].x, mainButtons[1].y, ColorHelper::getColorName(config->barColor(), 1).c_str(), C2D_Color32(0, 255, 0, 255));
GFX::DrawButton(mainButtons[2].x, mainButtons[2].y, ColorHelper::getColorName(config->barColor(), 0).c_str(), C2D_Color32(0, 0, 255, 255));
} else if (colorMode == 1) {
GFX::DrawButton(mainButtons[0].x, mainButtons[0].y, ColorHelper::getColorName(config->topBG(), 2).c_str(), C2D_Color32(255, 0, 0, 255));
GFX::DrawButton(mainButtons[1].x, mainButtons[1].y, ColorHelper::getColorName(config->topBG(), 1).c_str(), C2D_Color32(0, 255, 0, 255));
GFX::DrawButton(mainButtons[2].x, mainButtons[2].y, ColorHelper::getColorName(config->topBG(), 0).c_str(), C2D_Color32(0, 0, 255, 255));
} else if (colorMode == 2) {
GFX::DrawButton(mainButtons[0].x, mainButtons[0].y, ColorHelper::getColorName(config->bottomBG(), 2).c_str(), C2D_Color32(255, 0, 0, 255));
GFX::DrawButton(mainButtons[1].x, mainButtons[1].y, ColorHelper::getColorName(config->bottomBG(), 1).c_str(), C2D_Color32(0, 255, 0, 255));
GFX::DrawButton(mainButtons[2].x, mainButtons[2].y, ColorHelper::getColorName(config->bottomBG(), 0).c_str(), C2D_Color32(0, 0, 255, 255));
} else if (colorMode == 3) {
GFX::DrawButton(mainButtons[0].x, mainButtons[0].y, ColorHelper::getColorName(config->textColor(), 2).c_str(), C2D_Color32(255, 0, 0, 255));
GFX::DrawButton(mainButtons[1].x, mainButtons[1].y, ColorHelper::getColorName(config->textColor(), 1).c_str(), C2D_Color32(0, 255, 0, 255));
GFX::DrawButton(mainButtons[2].x, mainButtons[2].y, ColorHelper::getColorName(config->textColor(), 0).c_str(), C2D_Color32(0, 0, 255, 255));
} else if (colorMode == 4) {
GFX::DrawButton(mainButtons[0].x, mainButtons[0].y, ColorHelper::getColorName(config->selectedColor(), 2).c_str(), C2D_Color32(255, 0, 0, 255));
GFX::DrawButton(mainButtons[1].x, mainButtons[1].y, ColorHelper::getColorName(config->selectedColor(), 1).c_str(), C2D_Color32(0, 255, 0, 255));
GFX::DrawButton(mainButtons[2].x, mainButtons[2].y, ColorHelper::getColorName(config->selectedColor(), 0).c_str(), C2D_Color32(0, 0, 255, 255));
} else if (colorMode == 5) {
GFX::DrawButton(mainButtons[0].x, mainButtons[0].y, ColorHelper::getColorName(config->unselectedColor(), 2).c_str(), C2D_Color32(255, 0, 0, 255));
GFX::DrawButton(mainButtons[1].x, mainButtons[1].y, ColorHelper::getColorName(config->unselectedColor(), 1).c_str(), C2D_Color32(0, 255, 0, 255));
GFX::DrawButton(mainButtons[2].x, mainButtons[2].y, ColorHelper::getColorName(config->unselectedColor(), 0).c_str(), C2D_Color32(0, 0, 255, 255));
} else if (colorMode == 6) {
GFX::DrawButton(mainButtons[0].x, mainButtons[0].y, ColorHelper::getColorName(config->progressbarColor(), 2).c_str(), C2D_Color32(255, 0, 0, 255));
GFX::DrawButton(mainButtons[1].x, mainButtons[1].y, ColorHelper::getColorName(config->progressbarColor(), 1).c_str(), C2D_Color32(0, 255, 0, 255));
GFX::DrawButton(mainButtons[2].x, mainButtons[2].y, ColorHelper::getColorName(config->progressbarColor(), 0).c_str(), C2D_Color32(0, 0, 255, 255));
} else if (colorMode == 7) {
GFX::DrawButton(mainButtons[0].x, mainButtons[0].y, ColorHelper::getColorName(config->notfoundColor(), 2).c_str(), C2D_Color32(255, 0, 0, 255));
GFX::DrawButton(mainButtons[1].x, mainButtons[1].y, ColorHelper::getColorName(config->notfoundColor(), 1).c_str(), C2D_Color32(0, 255, 0, 255));
GFX::DrawButton(mainButtons[2].x, mainButtons[2].y, ColorHelper::getColorName(config->notfoundColor(), 0).c_str(), C2D_Color32(0, 0, 255, 255));
} else if (colorMode == 8) {
GFX::DrawButton(mainButtons[0].x, mainButtons[0].y, ColorHelper::getColorName(config->outdatedColor(), 2).c_str(), C2D_Color32(255, 0, 0, 255));
GFX::DrawButton(mainButtons[1].x, mainButtons[1].y, ColorHelper::getColorName(config->outdatedColor(), 1).c_str(), C2D_Color32(0, 255, 0, 255));
GFX::DrawButton(mainButtons[2].x, mainButtons[2].y, ColorHelper::getColorName(config->outdatedColor(), 0).c_str(), C2D_Color32(0, 0, 255, 255));
} else if (colorMode == 9) {
GFX::DrawButton(mainButtons[0].x, mainButtons[0].y, ColorHelper::getColorName(config->uptodateColor(), 2).c_str(), C2D_Color32(255, 0, 0, 255));
GFX::DrawButton(mainButtons[1].x, mainButtons[1].y, ColorHelper::getColorName(config->uptodateColor(), 1).c_str(), C2D_Color32(0, 255, 0, 255));
GFX::DrawButton(mainButtons[2].x, mainButtons[2].y, ColorHelper::getColorName(config->uptodateColor(), 0).c_str(), C2D_Color32(0, 0, 255, 255));
} else if (colorMode == 10) {
GFX::DrawButton(mainButtons[0].x, mainButtons[0].y, ColorHelper::getColorName(config->futureColor(), 2).c_str(), C2D_Color32(255, 0, 0, 255));
GFX::DrawButton(mainButtons[1].x, mainButtons[1].y, ColorHelper::getColorName(config->futureColor(), 1).c_str(), C2D_Color32(0, 255, 0, 255));
GFX::DrawButton(mainButtons[2].x, mainButtons[2].y, ColorHelper::getColorName(config->futureColor(), 0).c_str(), C2D_Color32(0, 0, 255, 255));
} else if (colorMode == 11) {
GFX::DrawButton(mainButtons[0].x, mainButtons[0].y, ColorHelper::getColorName(config->buttonColor(), 2).c_str(), C2D_Color32(255, 0, 0, 255));
GFX::DrawButton(mainButtons[1].x, mainButtons[1].y, ColorHelper::getColorName(config->buttonColor(), 1).c_str(), C2D_Color32(0, 255, 0, 255));
GFX::DrawButton(mainButtons[2].x, mainButtons[2].y, ColorHelper::getColorName(config->buttonColor(), 0).c_str(), C2D_Color32(0, 0, 255, 255));
}
}
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 320, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
}
void Settings::SubMenuLogic(u32 hDown, u32 hHeld, touchPosition touch) {
if ((hDown & KEY_B)) {
Gui::screenBack(config->screenFade());
return;
}
if ((hDown & KEY_R) || (hDown & KEY_TOUCH && touching(touch, arrowPos[4]))) {
if (this->settingPage < 2) {
this->settingPage++;
Selection = 0;
}
}
if ((hDown & KEY_L) || (hDown & KEY_TOUCH && touching(touch, arrowPos[2]))) {
if (this->settingPage > 0) {
this->settingPage--;
Selection = 0;
}
}
if (this->settingPage == 0) {
if (hDown & KEY_UP) {
if (Selection > 0) Selection--;
}
if (hDown & KEY_DOWN) {
if (Selection < 2) Selection++;
}
if (hDown & KEY_A) {
switch (Selection) {
case 0:
screenPos = 0;
selectedLang = 0;
mode = 1;
break;
case 1:
screenPos = 0;
mode = 2;
break;
case 2:
if (config->useBars()) config->useBars(false);
else config->useBars(true);
break;
}
}
if (hDown & KEY_TOUCH) {
if (touching(touch, mainButtons[0])) {
screenPos = 0;
selectedLang = 0;
mode = 1;
} else if (touching(touch, mainButtons[1])) {
screenPos = 0;
mode = 2;
} else if (touching(touch, mainButtons[2])) {
if (config->useBars()) config->useBars(false);
else config->useBars(true);
}
}
} else if (this->settingPage == 1) {
if (hDown & KEY_A) {
if (Selection == 0) {
std::string tempMusic = selectFilePath(Lang::get("SELECT_MUSIC_FILE"), "sdmc:/", {"wav"}, 2);
if (tempMusic != "") {
config->musicPath(tempMusic);
}
} else if (Selection == 1) {
int temp = Input::setInt(255, Lang::get("ENTER_KEY_DELAY"));
if (temp != -1) config->keyDelay(temp);
} else if (Selection == 2) {
if (config->screenFade()) {
if (Msg::promptMsg(Lang::get("TOGGLE_FADE_DISABLE"))) {
config->screenFade(false);
Msg::DisplayWarnMsg(Lang::get("DISABLED"));
}
} else {
if (Msg::promptMsg(Lang::get("TOGGLE_FADE_ENABLE"))) {
config->screenFade(true);
Msg::DisplayWarnMsg(Lang::get("ENABLED"));
}
}
} else if (Selection == 3) {
if (config->progressDisplay()) {
if (Msg::promptMsg(Lang::get("PROGRESS_BAR_DISABLE"))) {
config->progressDisplay(false);
Msg::DisplayWarnMsg(Lang::get("DISABLED"));
}
} else {
if (Msg::promptMsg(Lang::get("PROGRESS_BAR_ENABLE"))) {
config->progressDisplay(true);
Msg::DisplayWarnMsg(Lang::get("ENABLED"));
}
}
}
}
if (hDown & KEY_TOUCH) {
if (touching(touch, mainButtons2[0])) {
std::string tempMusic = selectFilePath(Lang::get("SELECT_MUSIC_FILE"), "sdmc:/", {"wav"}, 2);
if (tempMusic != "") {
config->musicPath(tempMusic);
}
} else if (touching(touch, mainButtons2[1])) {
int temp = Input::setInt(255, Lang::get("ENTER_KEY_DELAY"));
if (temp != -1) config->keyDelay(temp);
} else if (touching(touch, mainButtons2[2])) {
if (config->screenFade()) {
if (Msg::promptMsg(Lang::get("TOGGLE_FADE_DISABLE"))) {
config->screenFade(false);
Msg::DisplayWarnMsg(Lang::get("DISABLED"));
}
} else {
if (Msg::promptMsg(Lang::get("TOGGLE_FADE_ENABLE"))) {
config->screenFade(true);
Msg::DisplayWarnMsg(Lang::get("ENABLED"));
}
}
} else if (touching(touch, mainButtons2[3])) {
if (config->progressDisplay()) {
if (Msg::promptMsg(Lang::get("PROGRESS_BAR_DISABLE"))) {
config->progressDisplay(false);
Msg::DisplayWarnMsg(Lang::get("DISABLED"));
}
} else {
if (Msg::promptMsg(Lang::get("PROGRESS_BAR_ENABLE"))) {
config->progressDisplay(true);
Msg::DisplayWarnMsg(Lang::get("ENABLED"));
}
}
}
}
// Navigation.
if (hDown & KEY_UP) {
if (Selection > 1) Selection -= 2;
} else if (hDown & KEY_DOWN) {
if (Selection < 2) Selection += 2;
} else if (hDown & KEY_LEFT) {
if (Selection%2) Selection--;
} else if (hDown & KEY_RIGHT) {
if (!(Selection%2)) Selection++;
}
} else if (this->settingPage == 2) {
if (hDown & KEY_UP) {
if (Selection > 0) Selection--;
}
if (hDown & KEY_DOWN) {
if (Selection < 2) Selection++;
}
if (hDown & KEY_A) {
std::string tempPath;
switch (Selection) {
case 0:
tempPath = selectFilePath(Lang::get("SELECT_3DSX_PATH"), config->_3dsxpath(), {});
if (tempPath != "") config->_3dsxpath(tempPath);
break;
case 1:
tempPath = selectFilePath(Lang::get("SELECT_NDS_PATH"), config->ndspath(), {});
if (tempPath != "") config->ndspath(tempPath);
break;
case 2:
tempPath = selectFilePath(Lang::get("SELECT_ARCHIVE_PATH"), config->archivepath(), {});
if (tempPath != "") config->archivepath(tempPath);
break;
}
}
if (hDown & KEY_TOUCH) {
if (touching(touch, mainButtons[0])) {
std::string tempPath = selectFilePath(Lang::get("SELECT_3DSX_PATH"), config->_3dsxpath(), {});
if (tempPath != "") config->_3dsxpath(tempPath);
} else if (touching(touch, mainButtons[1])) {
std::string tempPath = selectFilePath(Lang::get("SELECT_NDS_PATH"), config->ndspath(), {});
if (tempPath != "") config->ndspath(tempPath);
} else if (touching(touch, mainButtons[2])) {
std::string tempPath = selectFilePath(Lang::get("SELECT_ARCHIVE_PATH"), config->archivepath(), {});
if (tempPath != "") config->archivepath(tempPath);
}
}
}
}
std::string langsTemp[] = {"br", "da", "de", "en", "es", "fr", "it", "lt", "pl", "pt", "ru", "jp"};
void Settings::LanguageSelection(u32 hDown, u32 hHeld, touchPosition touch) {
if (keyRepeatDelay) keyRepeatDelay--;
if ((hHeld & KEY_DOWN && !keyRepeatDelay)) {
if (selectedLang < (int)languages.size()-1) {
selectedLang++;
} else {
selectedLang = 0;
}
keyRepeatDelay = config->keyDelay();
}
if ((hHeld & KEY_UP && !keyRepeatDelay)) {
if (selectedLang > 0) {
selectedLang--;
} else {
selectedLang = (int)languages.size()-1;
}
keyRepeatDelay = config->keyDelay();
}
if (hDown & KEY_A) {
config->language(langsTemp[selectedLang]);
Lang::load(config->language());
mode = 0;
}
if ((hDown & KEY_B)) {
mode = 0;
}
if (selectedLang < screenPos) {
screenPos = selectedLang;
} else if (selectedLang > screenPos + ENTRIES_PER_SCREEN - 1) {
screenPos = selectedLang - ENTRIES_PER_SCREEN + 1;
}
}
void Settings::colorChanging(u32 hDown, u32 hHeld, touchPosition touch) {
if (keyRepeatDelay) keyRepeatDelay--;
int red;
int green;
int blue;
if (dropDownMenu) {
if (hDown & KEY_A) {
colorMode = colorSelection;
dropDownMenu = false;
}
if ((hHeld & KEY_DOWN && !keyRepeatDelay)) {
if (colorSelection < (int)colorList.size()-1) {
colorSelection++;
} else {
colorSelection = 0;
}
keyRepeatDelay = config->keyDelay();
}
if ((hHeld & KEY_UP && !keyRepeatDelay)) {
if (colorSelection > 0) {
colorSelection--;
} else {
colorSelection = (int)colorList.size()-1;
}
keyRepeatDelay = config->keyDelay();
}
} else {
if (hDown & KEY_A) {
switch(this->colorMode) {
case 0:
config->barColor(Overlays::SelectRGB(config->barColor()));
break;
case 1:
config->topBG(Overlays::SelectRGB(config->topBG()));
break;
case 2:
config->bottomBG(Overlays::SelectRGB(config->bottomBG()));
break;
case 3:
config->textColor(Overlays::SelectRGB(config->textColor()));
break;
case 4:
config->selectedColor(Overlays::SelectRGB(config->selectedColor()));
break;
case 5:
config->unselectedColor(Overlays::SelectRGB(config->unselectedColor()));
break;
case 6:
config->progressbarColor(Overlays::SelectRGB(config->progressbarColor()));
break;
case 7:
config->notfoundColor(Overlays::SelectRGB(config->notfoundColor()));
break;
case 8:
config->outdatedColor(Overlays::SelectRGB(config->outdatedColor()));
break;
case 9:
config->uptodateColor(Overlays::SelectRGB(config->uptodateColor()));
break;
case 10:
config->futureColor(Overlays::SelectRGB(config->futureColor()));
break;
case 11:
config->buttonColor(Overlays::SelectRGB(config->buttonColor()));
break;
}
}
if ((hDown & KEY_SELECT) || (hDown & KEY_TOUCH && touching(touch, arrowPos[3]))) {
colorSelection = colorMode;
dropDownMenu = true;
}
if ((hDown & KEY_B) || (hDown & KEY_TOUCH && touching(touch, arrowPos[2]))) {
mode = 0;
}
if ((hDown & KEY_L || hDown & KEY_LEFT)) {
if (colorMode > 0) colorMode--;
}
if ((hDown & KEY_R || hDown & KEY_RIGHT)) {
if (colorMode < 11) colorMode++;
}
if (hDown & KEY_TOUCH) {
if (touching(touch, mainButtons[0])) {
int temp = Input::setu8(Lang::get("ENTER_RED_RGB"));
if (temp != -1) {
red = temp;
if (colorMode == 0) {
config->barColor(RGBA8(red, ColorHelper::getColorValue(config->barColor(), 1), ColorHelper::getColorValue(config->barColor(), 0), 255));
} else if (colorMode == 1) {
config->topBG(RGBA8(red, ColorHelper::getColorValue(config->topBG(), 1), ColorHelper::getColorValue(config->topBG(), 0), 255));
} else if (colorMode == 2) {
config->bottomBG(RGBA8(red, ColorHelper::getColorValue(config->bottomBG(), 1), ColorHelper::getColorValue(config->bottomBG(), 0), 255));
} else if (colorMode == 3) {
config->textColor(RGBA8(red, ColorHelper::getColorValue(config->textColor(), 1), ColorHelper::getColorValue(config->textColor(), 0), 255));
} else if (colorMode == 4) {
config->selectedColor(RGBA8(red, ColorHelper::getColorValue(config->selectedColor(), 1), ColorHelper::getColorValue(config->selectedColor(), 0), 255));
} else if (colorMode == 5) {
config->unselectedColor(RGBA8(red, ColorHelper::getColorValue(config->unselectedColor(), 1), ColorHelper::getColorValue(config->unselectedColor(), 0), 255));
} else if (colorMode == 6) {
config->progressbarColor(RGBA8(red, ColorHelper::getColorValue(config->progressbarColor(), 1), ColorHelper::getColorValue(config->progressbarColor(), 0), 255));
} else if (colorMode == 7) {
config->notfoundColor(RGBA8(red, ColorHelper::getColorValue(config->notfoundColor(), 1), ColorHelper::getColorValue(config->notfoundColor(), 0), 255));
} else if (colorMode == 8) {
config->outdatedColor(RGBA8(red, ColorHelper::getColorValue(config->outdatedColor(), 1), ColorHelper::getColorValue(config->outdatedColor(), 0), 255));
} else if (colorMode == 9) {
config->uptodateColor(RGBA8(red, ColorHelper::getColorValue(config->uptodateColor(), 1), ColorHelper::getColorValue(config->uptodateColor(), 0), 255));
} else if (colorMode == 10) {
config->futureColor(RGBA8(red, ColorHelper::getColorValue(config->futureColor(), 1), ColorHelper::getColorValue(config->futureColor(), 0), 255));
} else if (colorMode == 11) {
config->buttonColor(RGBA8(red, ColorHelper::getColorValue(config->buttonColor(), 1), ColorHelper::getColorValue(config->buttonColor(), 0), 255));
}
}
} else if (touching(touch, mainButtons[1])) {
int temp = Input::setu8(Lang::get("ENTER_GREEN_RGB"));
if (temp != -1) {
green = temp;
if (colorMode == 0) {
config->barColor(RGBA8(ColorHelper::getColorValue(config->barColor(), 2), green, ColorHelper::getColorValue(config->barColor(), 0), 255));
} else if (colorMode == 1) {
config->topBG(RGBA8(ColorHelper::getColorValue(config->topBG(), 2), green, ColorHelper::getColorValue(config->topBG(), 0), 255));
} else if (colorMode == 2) {
config->bottomBG(RGBA8(ColorHelper::getColorValue(config->bottomBG(), 2), green, ColorHelper::getColorValue(config->bottomBG(), 0), 255));
} else if (colorMode == 3) {
config->textColor(RGBA8(ColorHelper::getColorValue(config->textColor(), 2), green, ColorHelper::getColorValue(config->textColor(), 0), 255));
} else if (colorMode == 4) {
config->selectedColor(RGBA8(ColorHelper::getColorValue(config->selectedColor(), 2), green, ColorHelper::getColorValue(config->selectedColor(), 0), 255));
} else if (colorMode == 5) {
config->unselectedColor(RGBA8(ColorHelper::getColorValue(config->unselectedColor(), 2), green, ColorHelper::getColorValue(config->unselectedColor(), 0), 255));
} else if (colorMode == 6) {
config->progressbarColor(RGBA8(ColorHelper::getColorValue(config->progressbarColor(), 2), green, ColorHelper::getColorValue(config->progressbarColor(), 0), 255));
} else if (colorMode == 7) {
config->notfoundColor(RGBA8(ColorHelper::getColorValue(config->notfoundColor(), 2), green, ColorHelper::getColorValue(config->notfoundColor(), 0), 255));
} else if (colorMode == 8) {
config->outdatedColor(RGBA8(ColorHelper::getColorValue(config->outdatedColor(), 2), green, ColorHelper::getColorValue(config->outdatedColor(), 0), 255));
} else if (colorMode == 9) {
config->uptodateColor(RGBA8(ColorHelper::getColorValue(config->uptodateColor(), 2), green, ColorHelper::getColorValue(config->uptodateColor(), 0), 255));
} else if (colorMode == 10) {
config->futureColor(RGBA8(ColorHelper::getColorValue(config->futureColor(), 2), green, ColorHelper::getColorValue(config->futureColor(), 0), 255));
} else if (colorMode == 11) {
config->buttonColor(RGBA8(ColorHelper::getColorValue(config->buttonColor(), 2), green, ColorHelper::getColorValue(config->buttonColor(), 0), 255));
}
}
} else if (touching(touch, mainButtons[2])) {
int temp = Input::setu8(Lang::get("ENTER_BLUE_RGB"));
if (temp != -1) {
blue = temp;
if (colorMode == 0) {
config->barColor(RGBA8(ColorHelper::getColorValue(config->barColor(), 2), ColorHelper::getColorValue(config->barColor(), 1), blue, 255));
} else if (colorMode == 1) {
config->topBG(RGBA8(ColorHelper::getColorValue(config->topBG(), 2), ColorHelper::getColorValue(config->topBG(), 1), blue, 255));
} else if (colorMode == 2) {
config->bottomBG(RGBA8(ColorHelper::getColorValue(config->bottomBG(), 2), ColorHelper::getColorValue(config->bottomBG(), 1), blue, 255));
} else if (colorMode == 3) {
config->textColor(RGBA8(ColorHelper::getColorValue(config->textColor(), 2), ColorHelper::getColorValue(config->textColor(), 1), blue, 255));
} else if (colorMode == 4) {
config->selectedColor(RGBA8(ColorHelper::getColorValue(config->selectedColor(), 2), ColorHelper::getColorValue(config->selectedColor(), 1), blue, 255));
} else if (colorMode == 5) {
config->unselectedColor(RGBA8(ColorHelper::getColorValue(config->unselectedColor(), 2), ColorHelper::getColorValue(config->unselectedColor(), 1), blue, 255));
} else if (colorMode == 6) {
config->progressbarColor(RGBA8(ColorHelper::getColorValue(config->progressbarColor(), 2), ColorHelper::getColorValue(config->progressbarColor(), 1), blue, 255));
} else if (colorMode == 7) {
config->notfoundColor(RGBA8(ColorHelper::getColorValue(config->notfoundColor(), 2), ColorHelper::getColorValue(config->notfoundColor(), 1), blue, 255));
} else if (colorMode == 8) {
config->outdatedColor(RGBA8(ColorHelper::getColorValue(config->outdatedColor(), 2), ColorHelper::getColorValue(config->outdatedColor(), 1), blue, 255));
} else if (colorMode == 9) {
config->uptodateColor(RGBA8(ColorHelper::getColorValue(config->uptodateColor(), 2), ColorHelper::getColorValue(config->uptodateColor(), 1), blue, 255));
} else if (colorMode == 10) {
config->futureColor(RGBA8(ColorHelper::getColorValue(config->futureColor(), 2), ColorHelper::getColorValue(config->futureColor(), 1), blue, 255));
} else if (colorMode == 11) {
config->buttonColor(RGBA8(ColorHelper::getColorValue(config->buttonColor(), 2), ColorHelper::getColorValue(config->buttonColor(), 1), blue, 255));
}
}
}
}
}
if (colorSelection < screenPos) {
screenPos = colorSelection;
} else if (colorSelection > screenPos + ENTRIES_PER_SCREEN - 1) {
screenPos = colorSelection - ENTRIES_PER_SCREEN + 1;
}
}
void Settings::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
if (mode == 0) {
SubMenuLogic(hDown, hHeld, touch);
} else if (mode == 1) {
LanguageSelection(hDown, hHeld, touch);
} else if (mode == 2) {
colorChanging(hDown, hHeld, touch);
}
}
-74
View File
@@ -1,74 +0,0 @@
/*
* This file is part of Universal-Updater
* Copyright (C) 2019-2020 Universal-Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "mainMenu.hpp"
#include "scriptlist.hpp"
#include "startup.hpp"
#include "unistore.hpp"
#include <unistd.h>
extern bool touching(touchPosition touch, Structs::ButtonPos button);
extern int fadealpha;
extern bool fadein;
extern std::unique_ptr<Config> config;
Startup::Startup(int mode, std::string file) {
this->mode = mode; this->file = file;
}
void Startup::Draw(void) const {
GFX::DrawTop();
GFX::DrawSprite(sprites_dev_by_idx, 0, 25);
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 400, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
GFX::DrawBottom();
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 320, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
}
void Startup::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
if (this->delay > 0) {
this->delay -= 2;
if (this->delay <= 0) {
if (this->mode == 0) {
config->firstStartup(false);
Gui::setScreen(std::make_unique<MainMenu>(), true, true);
} else if (this->mode == 1) {
config->firstStartup(false);
if (access(this->file.c_str(), F_OK) == 0) {
Gui::setScreen(std::make_unique<UniStore>(true, this->file), true, true);
} else {
Gui::setScreen(std::make_unique<MainMenu>(), true, true);
}
} else if (this->mode == 2) {
config->firstStartup(false);
if (access(this->file.c_str(), F_OK) == 0) {
Gui::setScreen(std::make_unique<ScriptList>(), true, true);
} else {
Gui::setScreen(std::make_unique<MainMenu>(), true, true);
}
}
}
}
}
-874
View File
@@ -1,874 +0,0 @@
/*
* This file is part of Universal-Updater
* Copyright (C) 2019-2020 Universal-Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "download.hpp"
#include "fileBrowse.hpp"
#include "formatting.hpp"
#include "keyboard.hpp"
#include "mainMenu.hpp"
#include "unistore.hpp"
#include "unistore_v1.hpp"
#include "unistore_v2.hpp"
#include <unistd.h>
extern void notImplemented(void);
extern bool touching(touchPosition touch, Structs::ButtonPos button);
extern bool changesMade;
bool specialHandling = false;
bool didAutoboot = false;
extern std::unique_ptr<Config> config;
UniStore::UniStore(bool doAutoboot, std::string file) {
this->doAutoboot = doAutoboot;
this->autobootFile = file;
}
// Autoboot stuff.
void UniStore::autobootLogic() {
if (this->doAutoboot) {
if (!didAutoboot) {
specialHandling = true; // Special back handling.
if (ScriptHelper::checkIfValid(this->autobootFile, 1) == true) {
storeInfo.push_back(parseStoreInfo(this->autobootFile));
// Update if WiFi found and wanted.
if (checkWifiStatus()) {
if (Msg::promptMsg(Lang::get("WOULD_YOU_LIKE_UPDATE"))) {
if (storeInfo[0].url != "" && storeInfo[0].url != "MISSING: storeInfo.url" &&
storeInfo[0].file != "" && storeInfo[0].file != "MISSING: storeInfo.file") {
ScriptHelper::downloadFile(storeInfo[0].url, storeInfo[0].file, Lang::get("UPDATING"));
}
if (storeInfo[0].sheetURL != "" && storeInfo[0].sheetURL != "MISSING: storeInfo.sheetURL" &&
storeInfo[0].storeSheet != "" && storeInfo[0].storeSheet != "MISSING: storeInfo.sheet") {
ScriptHelper::downloadFile(storeInfo[0].sheetURL, storeInfo[0].storeSheet, Lang::get("UPDATING"));
}
}
}
currentStoreFile = this->autobootFile;
Msg::DisplayMsg(Lang::get("PREPARE_STORE"));
JSON = openStoreFile();
displayInformations = handleIfDisplayText();
const std::string sheetURL = storeInfo[0].storeSheet;
if (storeInfo[0].version == 0 || storeInfo[0].version == 1) {
Gui::setScreen(std::make_unique<UniStoreV1>(JSON, sheetURL, displayInformations), config->screenFade(), true);
} else if (storeInfo[0].version == 2) {
Gui::setScreen(std::make_unique<UniStoreV2>(JSON, sheetURL, currentStoreFile), config->screenFade(), true);
} else {
Msg::DisplayWarnMsg(Lang::get("UNISTORE_NOT_SUPPORTED"));
}
} else {
specialHandling = true; // Special back handling.
// Display Warn or so?
}
}
}
}
// Parse informations like URL, Title, Author, Description.
StoreInfo UniStore::parseStoreInfo(std::string fileName) {
FILE* file = fopen(fileName.c_str(), "rt");
if (!file) {
printf("File not found.\n");
return {"", ""};
}
nlohmann::json json = nlohmann::json::parse(file, nullptr, false);
fclose(file);
StoreInfo info;
info.title = ScriptHelper::getString(json, "storeInfo", "title");
info.author = ScriptHelper::getString(json, "storeInfo", "author");
info.description = ScriptHelper::getString(json, "storeInfo", "description");
info.url = ScriptHelper::getString(json, "storeInfo", "url");
info.file = ScriptHelper::getString(json, "storeInfo", "file");
info.storeSheet = ScriptHelper::getString(json, "storeInfo", "sheet");
info.sheetURL = ScriptHelper::getString(json, "storeInfo", "sheetURL");
info.version = ScriptHelper::getNum(json, "storeInfo", "version");
return info;
}
// Return a parsed UniStore file.
nlohmann::json UniStore::openStoreFile() {
FILE* file = fopen(currentStoreFile.c_str(), "rt");
nlohmann::json jsonFile;
if (file) jsonFile = nlohmann::json::parse(file, nullptr, false);
fclose(file);
return jsonFile;
}
// Do the description, if found.
void UniStore::descript() {
if (storeInfo[Selection].description != "" || storeInfo[Selection].description != "MISSING: storeInfo.description") {
storeDesc = storeInfo[Selection].description;
} else storeDesc = "";
}
// Load the store description.
void UniStore::loadStoreDesc(void) {
descLines.clear();
while(storeDesc.find('\n') != storeDesc.npos) {
descLines.push_back(storeDesc.substr(0, storeDesc.find('\n')));
storeDesc = storeDesc.substr(storeDesc.find('\n')+1);
}
descLines.push_back(storeDesc.substr(0, storeDesc.find('\n')));
}
void UniStore::DrawSubMenu(void) const {
GFX::DrawTop();
Gui::DrawStringCentered(0, config->useBars() ? 0 : 2, 0.7f, config->textColor(), Lang::get("UNISTORE_SUBMENU"), 400);
GFX::DrawSprite(sprites_uniStore_HD_idx, 140, 50, 0.2, 0.2);
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 400, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
GFX::DrawBottom();
GFX::DrawArrow(0, 218, 0, 1);
GFX::DrawButton(subPos[0].x, subPos[0].y,Lang::get("STORE_LIST"));
GFX::DrawButton(subPos[1].x, subPos[1].y, Lang::get("STORE_SEARCH"));
GFX::DrawButton(subPos[2].x, subPos[2].y, Lang::get("CHANGE_STOREPATH"));
// Selector.
Animation::Button(subPos[Selection].x, subPos[Selection].y, .060);
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 320, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
}
// First Screen -> Storelist.
void UniStore::DrawStoreList(void) const {
std::string line1;
std::string line2;
std::string storeAmount = std::to_string(Selection +1) + " | " + std::to_string(storeInfo.size());
GFX::DrawTop();
Gui::DrawStringCentered(0, config->useBars() ? 0 : 2, 0.7f, config->textColor(), storeInfo[Selection].title, 400);
Gui::DrawString(5, config->useBars() ? 220 : 218, 0.6f, config->textColor(), Lang::get("UNISTORE_VERSION") + std::to_string(storeInfo[Selection].version), 400);
Gui::DrawString(397-Gui::GetStringWidth(0.6f, storeAmount), (config->useBars() ? 239 : 237)-Gui::GetStringHeight(0.6f, storeAmount), 0.6f, config->textColor(), storeAmount);
for(uint i = 0; i < descLines.size(); i++) {
Gui::DrawStringCentered(0, 120-((descLines.size()*20)/2)+i*20, 0.6f, config->textColor(), descLines[i], 400);
}
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 400, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
GFX::DrawBottom();
GFX::DrawArrow(295, -1);
GFX::DrawArrow(315, 240, 180.0);
GFX::DrawArrow(0, 218, 0, 1);
GFX::DrawSpriteBlend(sprites_dropdown_idx, arrowPos[3].x, arrowPos[3].y);
if (config->viewMode() == 0) {
for(int i = 0; i < ENTRIES_PER_SCREEN && i < (int)storeInfo.size(); i++) {
Gui::Draw_Rect(0, 40+(i*57), 320, 45, config->unselectedColor());
line1 = storeInfo[screenPos + i].title;
line2 = storeInfo[screenPos + i].author;
if (screenPos + i == Selection) {
if (!dropDownMenu) {
Gui::drawAnimatedSelector(0, 40+(i*57), 320, 45, .060, TRANSPARENT, config->selectedColor());
}
}
Gui::DrawStringCentered(0, 38+(i*57), 0.7f, config->textColor(), line1, 320);
Gui::DrawStringCentered(0, 62+(i*57), 0.7f, config->textColor(), line2, 320);
}
} else if (config->viewMode() == 1) {
for(int i = 0; i < ENTRIES_PER_LIST && i < (int)storeInfo.size(); i++) {
Gui::Draw_Rect(0, (i+1)*27, 320, 25, config->unselectedColor());
line1 = storeInfo[screenPosList + i].title;
if (screenPosList + i == Selection) {
if (!dropDownMenu) {
Gui::drawAnimatedSelector(0, (i+1)*27, 320, 25, .060, TRANSPARENT, config->selectedColor());
}
}
Gui::DrawStringCentered(0, ((i+1)*27)+1, 0.7f, config->textColor(), line1, 320);
}
}
// DropDown Menu.
if (dropDownMenu) {
// Draw Operation Box.
Gui::Draw_Rect(0, 25, 140, 130, config->barColor());
for (int i = 0; i < 3; i++) {
if (dropSelection == i) {
Gui::drawAnimatedSelector(dropPos2[i].x, dropPos2[i].y, dropPos2[i].w, dropPos2[i].h, .090, TRANSPARENT, config->selectedColor());
} else {
Gui::Draw_Rect(dropPos2[i].x, dropPos2[i].y, dropPos2[i].w, dropPos2[i].h, config->unselectedColor());
}
}
// Draw Dropdown Icons.
GFX::DrawSpriteBlend(sprites_delete_idx, dropPos[0].x, dropPos[0].y);
GFX::DrawSpriteBlend(sprites_update_idx, dropPos[1].x, dropPos[1].y);
GFX::DrawSpriteBlend(sprites_view_idx, dropPos[2].x, dropPos[2].y);
// Dropdown Text.
Gui::DrawString(dropPos[0].x+30, dropPos[0].y+5, 0.4f, config->textColor(), Lang::get("DELETE_DDM"), 100);
Gui::DrawString(dropPos[1].x+30, dropPos[1].y+5, 0.4f, config->textColor(), Lang::get("UPDATE_DDM"), 100);
Gui::DrawString(dropPos[2].x+30, dropPos[2].y+5, 0.4f, config->textColor(), Lang::get("VIEW_DDM"), 100);
}
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 320, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
}
void UniStore::Draw(void) const {
if (mode == 0) {
DrawSubMenu();
} else if (mode == 1) {
DrawStoreList();
} else if (mode == 2) {
DrawSearch();
} else if (mode == 3) {
DrawFullURLScreen();
} else if (mode == 4) {
DrawGitHubScreen();
}
}
void UniStore::updateStore(int selectedStore) {
if (checkWifiStatus()) {
if (Msg::promptMsg(Lang::get("WOULD_YOU_LIKE_UPDATE"))) {
if (storeInfo[selectedStore].url != "" && storeInfo[selectedStore].url != "MISSING: storeInfo.url" &&
storeInfo[selectedStore].file != "" && storeInfo[selectedStore].file != "MISSING: storeInfo.file") {
ScriptHelper::downloadFile(storeInfo[selectedStore].url, storeInfo[selectedStore].file, Lang::get("UPDATING"));
}
if (storeInfo[selectedStore].sheetURL != "" && storeInfo[selectedStore].sheetURL != "MISSING: storeInfo.sheetURL" &&
storeInfo[selectedStore].storeSheet != "" && storeInfo[selectedStore].storeSheet != "MISSING: storeInfo.sheet") {
ScriptHelper::downloadFile(storeInfo[selectedStore].sheetURL, storeInfo[selectedStore].storeSheet, Lang::get("UPDATING"));
}
// Refresh the list.
Msg::DisplayMsg(Lang::get("REFRESHING_LIST"));
dirContents.clear();
storeInfo.clear();
chdir(config->storePath().c_str());
getDirectoryContents(dirContents, {"unistore"});
for(uint i = 0; i < dirContents.size(); i++) {
storeInfo.push_back(parseStoreInfo(dirContents[i].name));
descript();
loadStoreDesc();
}
}
}
}
void UniStore::refreshList() {
if (returnIfExist(config->storePath(), {"unistore"}) == true) {
Msg::DisplayMsg(Lang::get("REFRESHING_LIST"));
dirContents.clear();
storeInfo.clear();
chdir(config->storePath().c_str());
getDirectoryContents(dirContents, {"unistore"});
for(uint i = 0; i < dirContents.size(); i++) {
storeInfo.push_back(parseStoreInfo(dirContents[i].name));
descript();
loadStoreDesc();
}
Selection = 0;
mode = 1;
} else {
Msg::DisplayWarnMsg(Lang::get("GET_STORES_FIRST"));
Selection = 0;
mode = 0;
}
}
void UniStore::SubMenuLogic(u32 hDown, u32 hHeld, touchPosition touch) {
if ((hDown & KEY_B) || (hDown & KEY_TOUCH && touching(touch, arrowPos[2]))) {
if (specialHandling) {
Gui::setScreen(std::make_unique<MainMenu>(), config->screenFade(), true);
} else {
Gui::screenBack(config->screenFade());
return;
}
}
if (hDown & KEY_UP) {
if(Selection > 0) Selection--;
}
if (hDown & KEY_DOWN) {
if(Selection < 2) Selection++;
}
if (hDown & KEY_A) {
switch(Selection) {
case 0:
if (returnIfExist(config->storePath(), {"unistore"}) == true) {
Msg::DisplayMsg(Lang::get("REFRESHING_LIST"));
dirContents.clear();
storeInfo.clear();
chdir(config->storePath().c_str());
getDirectoryContents(dirContents, {"unistore"});
for(uint i = 0; i < dirContents.size(); i++) {
storeInfo.push_back(parseStoreInfo(dirContents[i].name));
descript();
loadStoreDesc();
}
Selection = 0;
mode = 1;
} else {
Msg::DisplayWarnMsg(Lang::get("GET_STORES_FIRST"));
}
break;
case 1:
if (checkWifiStatus()) {
Selection = 0;
mode = 2;
} else {
notConnectedMsg();
}
break;
case 2:
std::string tempStore = selectFilePath(Lang::get("SELECT_STORE_PATH"), config->storePath(), {});
if (tempStore != "") {
config->storePath(tempStore);
changesMade = true;
}
break;
}
}
if (hDown & KEY_TOUCH) {
if (touching(touch, subPos[0])) {
if (returnIfExist(config->storePath(), {"unistore"}) == true) {
Msg::DisplayMsg(Lang::get("REFRESHING_LIST"));
dirContents.clear();
storeInfo.clear();
chdir(config->storePath().c_str());
getDirectoryContents(dirContents, {"unistore"});
for(uint i = 0; i < dirContents.size(); i++) {
storeInfo.push_back(parseStoreInfo(dirContents[i].name));
descript();
loadStoreDesc();
}
Selection = 0;
mode = 1;
} else {
Msg::DisplayWarnMsg(Lang::get("GET_STORES_FIRST"));
}
} else if (touching(touch, subPos[1])) {
if (checkWifiStatus() == true) {
Selection = 0;
mode = 2;
} else {
notConnectedMsg();
}
} else if (touching(touch, subPos[2])) {
std::string tempStore = selectFilePath(Lang::get("SELECT_STORE_PATH"), config->storePath(), {});
if (tempStore != "") {
config->storePath(tempStore);
changesMade = true;
}
}
}
}
void UniStore::deleteStore(int selectedStore) {
std::string path = config->storePath();
path += dirContents[selectedStore].name;
deleteFile(path.c_str());
// Refresh the list.
Msg::DisplayMsg(Lang::get("REFRESHING_LIST"));
Selection = 0;
dirContents.clear();
storeInfo.clear();
chdir(config->storePath().c_str());
getDirectoryContents(dirContents, {"unistore"});
for(uint i = 0; i < dirContents.size(); i++) {
storeInfo.push_back(parseStoreInfo(dirContents[i].name));
descript();
loadStoreDesc();
}
if (dirContents.size() == 0) {
dirContents.clear();
storeInfo.clear();
Selection = 0;
mode = 0;
}
}
bool UniStore::handleIfDisplayText() {
if (JSON.at("storeInfo").contains("displayInformation")) {
if (JSON["storeInfo"]["displayInformation"] != true) {
return false;
} else {
return true;
}
} else {
return true;
}
}
void UniStore::StoreSelectionLogic(u32 hDown, u32 hHeld, touchPosition touch) {
if (keyRepeatDelay) keyRepeatDelay--;
if (dropDownMenu) {
if ((hDown & KEY_SELECT) || (hDown & KEY_TOUCH && touching(touch, arrowPos[3]))) {
dropDownMenu = false;
}
if (hDown & KEY_DOWN) {
if (dropSelection < 2) dropSelection++;
}
if (hDown & KEY_UP) {
if (dropSelection > 0) dropSelection--;
}
if (hDown & KEY_A) {
switch(dropSelection) {
case 0:
if (Msg::promptMsg(Lang::get("DELETE_STORE"))) {
deleteStore(Selection);
}
break;
case 1:
updateStore(Selection);
break;
case 2:
if (config->viewMode() == 0) {
config->viewMode(1);
} else {
config->viewMode(0);
}
break;
}
dropDownMenu = false;
}
if (hDown & KEY_TOUCH) {
if (touching(touch, dropPos2[0])) {
if (Msg::promptMsg(Lang::get("DELETE_STORE"))) {
deleteStore(Selection);
}
dropDownMenu = false;
} else if (touching(touch, dropPos2[1])) {
updateStore(Selection);
dropDownMenu = false;
} else if (touching(touch, dropPos2[2])) {
if (config->viewMode() == 0) {
config->viewMode(1);
} else {
config->viewMode(0);
}
dropDownMenu = false;
}
}
} else {
if ((hDown & KEY_SELECT) || (hDown & KEY_TOUCH && touching(touch, arrowPos[3]))) {
dropSelection = 0;
dropDownMenu = true;
}
if ((hDown & KEY_B) || (hDown & KEY_TOUCH && touching(touch, arrowPos[2]))) {
storeInfo.clear();
Selection = 0;
mode = 0;
}
if ((hHeld & KEY_DOWN && !keyRepeatDelay) || (hDown & KEY_TOUCH && touching(touch, arrowPos[1]))) {
if (Selection < (int)storeInfo.size()-1) {
Selection++;
descript();
loadStoreDesc();
} else {
Selection = 0;
descript();
loadStoreDesc();
}
keyRepeatDelay = config->keyDelay();
}
if ((hHeld & KEY_UP && !keyRepeatDelay) || (hDown & KEY_TOUCH && touching(touch, arrowPos[0]))) {
if (Selection > 0) {
Selection--;
descript();
loadStoreDesc();
} else {
Selection = (int)storeInfo.size()-1;
descript();
loadStoreDesc();
}
keyRepeatDelay = config->keyDelay();
}
if ((hHeld & KEY_RIGHT && !keyRepeatDelay)) {
if (config->viewMode() == 0) {
if (Selection < (int)storeInfo.size()-1-3) {
Selection += 3;
descript();
loadStoreDesc();
} else {
Selection = (int)storeInfo.size()-1;
descript();
loadStoreDesc();
}
} else {
if (Selection < (int)storeInfo.size()-1-6) {
Selection += 7;
descript();
loadStoreDesc();
} else {
Selection = (int)storeInfo.size()-1;
descript();
loadStoreDesc();
}
}
keyRepeatDelay = config->keyDelay();
}
if ((hHeld & KEY_LEFT && !keyRepeatDelay)) {
if (config->viewMode() == 0) {
if (Selection > 2) {
Selection -= 3;
descript();
loadStoreDesc();
} else {
Selection = 0;
descript();
loadStoreDesc();
}
} else {
if (Selection > 6) {
Selection -= 7;
descript();
loadStoreDesc();
} else {
Selection = 0;
descript();
loadStoreDesc();
}
}
keyRepeatDelay = config->keyDelay();
}
if (hDown & KEY_A) {
if (!dirContents[Selection].isDirectory && storeInfo.size() != 0) {
if (ScriptHelper::checkIfValid(dirContents[Selection].name, 1) == true) {
updateStore(Selection);
currentStoreFile = dirContents[Selection].name;
Msg::DisplayMsg(Lang::get("PREPARE_STORE"));
JSON = openStoreFile();
displayInformations = handleIfDisplayText();
const std::string sheetURL = storeInfo[Selection].storeSheet;
if (storeInfo[Selection].version == 0 || storeInfo[Selection].version == 1) {
Gui::setScreen(std::make_unique<UniStoreV1>(JSON, sheetURL, displayInformations), config->screenFade(), true);
} else if (storeInfo[Selection].version == 2) {
Gui::setScreen(std::make_unique<UniStoreV2>(JSON, sheetURL, currentStoreFile), config->screenFade(), true);
} else {
Msg::DisplayWarnMsg(Lang::get("UNISTORE_NOT_SUPPORTED"));
}
}
}
}
if (config->viewMode() == 0) {
if(Selection < screenPos) {
screenPos = Selection;
} else if (Selection > screenPos + ENTRIES_PER_SCREEN - 1) {
screenPos = Selection - ENTRIES_PER_SCREEN + 1;
}
} else if (config->viewMode() == 1) {
if(Selection < screenPosList) {
screenPosList = Selection;
} else if (Selection > screenPosList + ENTRIES_PER_LIST - 1) {
screenPosList = Selection - ENTRIES_PER_LIST + 1;
}
}
if (hDown & KEY_TOUCH) {
if (config->viewMode() == 0) {
for(int i = 0; i < ENTRIES_PER_SCREEN && i < (int)storeInfo.size(); i++) {
if (touch.py > 40+(i*57) && touch.py < 40+(i*57)+45) {
if (ScriptHelper::checkIfValid(dirContents[screenPos + i].name, 1) == true) {
updateStore(screenPos + i);
currentStoreFile = dirContents[screenPos + i].name;
Msg::DisplayMsg(Lang::get("PREPARE_STORE"));
JSON = openStoreFile();
displayInformations = handleIfDisplayText();
const std::string sheetURL = storeInfo[screenPos + i].storeSheet;
if (storeInfo[screenPos + i].version == 0 || storeInfo[screenPos + i].version == 1) {
Gui::setScreen(std::make_unique<UniStoreV1>(JSON, sheetURL, displayInformations), config->screenFade(), true);
} else if (storeInfo[screenPos + i].version == 2) {
Gui::setScreen(std::make_unique<UniStoreV2>(JSON, sheetURL, currentStoreFile), config->screenFade(), true);
} else {
Msg::DisplayWarnMsg(Lang::get("UNISTORE_NOT_SUPPORTED"));
}
}
}
}
} else if (config->viewMode() == 1) {
for(int i = 0; i < ENTRIES_PER_LIST && i < (int)storeInfo.size(); i++) {
if (touch.py > (i+1)*27 && touch.py < (i+2)*27) {
if (ScriptHelper::checkIfValid(dirContents[screenPosList + i].name, 1) == true) {
updateStore(screenPosList + i);
currentStoreFile = dirContents[screenPosList + i].name;
Msg::DisplayMsg(Lang::get("PREPARE_STORE"));
JSON = openStoreFile();
displayInformations = handleIfDisplayText();
const std::string sheetURL = storeInfo[screenPosList + i].storeSheet;
if (storeInfo[screenPosList + i].version == 0 || storeInfo[screenPosList + i].version == 1) {
Gui::setScreen(std::make_unique<UniStoreV1>(JSON, sheetURL, displayInformations), config->screenFade(), true);
} else if (storeInfo[screenPosList + i].version == 2) {
Gui::setScreen(std::make_unique<UniStoreV2>(JSON, sheetURL, currentStoreFile), config->screenFade(), true);
} else {
Msg::DisplayWarnMsg(Lang::get("UNISTORE_NOT_SUPPORTED"));
}
}
}
}
}
}
if (hDown & KEY_START) {
if (config->autoboot() == 1) {
if (Msg::promptMsg(Lang::get("DISABLE_AUTOBOOT"))) {
config->autoboot(0);
config->autobootFile("");
changesMade = true;
}
} else {
if (!dirContents[Selection].isDirectory && storeInfo.size() != 0) {
if (ScriptHelper::checkIfValid(dirContents[Selection].name, 1) == true) {
if (Msg::promptMsg(Lang::get("AUTOBOOT_STORE"))) {
config->autoboot(1);
config->autobootFile(config->storePath() + dirContents[Selection].name);
changesMade = true;
}
}
}
}
}
}
}
void UniStore::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
this->autobootLogic();
if (mode == 0) {
SubMenuLogic(hDown, hHeld, touch);
} else if (mode == 1) {
StoreSelectionLogic(hDown, hHeld, touch);
} else if (mode == 2) {
SearchLogic(hDown, hHeld, touch);
} else if (mode == 3) {
FullURLLogic(hDown, hHeld, touch);
} else if (mode == 4) {
GitHubLogic(hDown, hHeld, touch);
}
}
void UniStore::DrawSearch(void) const {
GFX::DrawTop();
if (config->useBars() == true) {
Gui::DrawStringCentered(0, 0, 0.7f, config->textColor(), Lang::get("UNISTORE_SEARCH"), 400);
} else {
Gui::DrawStringCentered(0, 2, 0.7f, config->textColor(), Lang::get("UNISTORE_SEARCH"), 400);
}
GFX::DrawSprite(sprites_uniStore_HD_idx, 140, 50, 0.2, 0.2);
GFX::DrawBottom();
GFX::DrawArrow(0, 218, 0, 1);
GFX::DrawButton(URLBtn[0].x, URLBtn[0].y,Lang::get("FULL_URL"));
GFX::DrawButton(URLBtn[1].x, URLBtn[1].y, Lang::get("GITHUB"));
GFX::DrawButton(URLBtn[2].x, URLBtn[2].y, "TinyDB");
GFX::DrawButton(URLBtn[3].x, URLBtn[3].y, "Universal DB");
// Selector.
Animation::Button(URLBtn[Selection].x, URLBtn[Selection].y, .060);
}
void UniStore::SearchLogic(u32 hDown, u32 hHeld, touchPosition touch) {
if ((hDown & KEY_B) || (hDown & KEY_TOUCH && touching(touch, arrowPos[2]))) {
Selection = 0;
mode = 0;
}
if (hDown & KEY_RIGHT || hDown & KEY_R) {
if (Selection == 0) Selection = 1;
else if (Selection == 2) Selection = 3;
}
if (hDown & KEY_LEFT || hDown & KEY_L) {
if (Selection == 1) Selection = 0;
else if (Selection == 3) Selection = 2;
}
if (hDown & KEY_DOWN) {
if (Selection == 0) Selection = 2;
else if (Selection == 1) Selection = 3;
}
if (hDown & KEY_UP) {
if (Selection == 2) Selection = 0;
else if (Selection == 3) Selection = 1;
}
if (hDown & KEY_A) {
if (Selection == 0) {
Selection = 0;
mode = 3;
} else if (Selection == 1) {
Selection = 0;
mode = 4;
} else if (Selection == 2) {
if (Msg::promptMsg("TinyDB might be down. This would lead to Download Failed!\nDo you still like to continue?")) {
ScriptHelper::downloadFile("https://tinydb.eiphax.tech/api/tinydb.unistore", config->storePath() + "TinyDB.unistore", Lang::get("DOWNLOADING") + "TinyDB");
}
} else if (Selection == 3) {
ScriptHelper::downloadFile("https://db.universal-team.net/unistore/universal-db.unistore", config->storePath() + "Universal-DB.unistore", Lang::get("DOWNLOADING") + "Universal DB");
}
}
if (hDown & KEY_TOUCH && touching(touch, URLBtn[0])) {
Selection = 0;
mode = 3;
} else if (hDown & KEY_TOUCH && touching(touch, URLBtn[1])) {
Selection = 0;
mode = 4;
} else if (hDown & KEY_TOUCH && touching(touch, URLBtn[2])) {
if (Msg::promptMsg("TinyDB might be down. This would lead to Download Failed!\nDo you still like to continue?")) {
ScriptHelper::downloadFile("https://tinydb.eiphax.tech/api/tinydb.unistore", config->storePath() + "TinyDB.unistore", Lang::get("DOWNLOADING") + "TinyDB");
}
} else if (hDown & KEY_TOUCH && touching(touch, URLBtn[3])) {
ScriptHelper::downloadFile("https://db.universal-team.net/unistore/universal-db.unistore", config->storePath() + "Universal-DB.unistore", Lang::get("DOWNLOADING") + "Universal DB");
}
}
void UniStore::DrawGitHubScreen(void) const {
GFX::DrawTop();
if (config->useBars() == true) {
Gui::DrawStringCentered(0, 0, 0.7f, config->textColor(), Lang::get("GITHUB"), 400);
} else {
Gui::DrawStringCentered(0, 2, 0.7f, config->textColor(), Lang::get("GITHUB"), 400);
}
GFX::DrawSprite(sprites_uniStore_HD_idx, 140, 50, 0.2, 0.2);
GFX::DrawBottom();
GFX::DrawArrow(0, 218, 0, 1);
Gui::DrawStringCentered(0, 28, 0.7f, config->textColor(), Lang::get("OWNER_AND_REPO"), 300);
Gui::DrawStringCentered(0, 108, 0.7f, config->textColor(), Lang::get("FILENAME"), 300);
Gui::Draw_Rect(GitHubPos[0].x, GitHubPos[0].y, GitHubPos[0].w, GitHubPos[0].h, config->barColor());
Gui::Draw_Rect(GitHubPos[1].x, GitHubPos[1].y, GitHubPos[1].w, GitHubPos[1].h, config->barColor());
Gui::Draw_Rect(GitHubPos[2].x, GitHubPos[2].y, GitHubPos[2].w, GitHubPos[2].h, config->barColor());
Gui::DrawStringCentered(0, 185, 0.7f, config->textColor(), Lang::get("OK"), 40);
Gui::DrawStringCentered(0, 57, 0.5f, config->textColor(), OwnerAndRepo, 250);
Gui::DrawStringCentered(0, 137, 0.5f, config->textColor(), fileName, 250);
}
void UniStore::GitHubLogic(u32 hDown, u32 hHeld, touchPosition touch) {
if (hDown & KEY_TOUCH && touching(touch, GitHubPos[0])) {
OwnerAndRepo = Input::setkbdString(150, Lang::get("ENTER_OWNER_AND_REPO"));
}
if (hDown & KEY_TOUCH && touching(touch, GitHubPos[1])) {
fileName = Input::setkbdString(150, Lang::get("ENTER_FILENAME"));
}
if (hDown & KEY_TOUCH && touching(touch, GitHubPos[2])) {
if (checkWifiStatus() == true) {
std::string URL = "https://github.com/";
URL += OwnerAndRepo;
URL += "/raw/master/unistore/";
URL += fileName;
ScriptHelper::downloadFile(URL, config->storePath() + fileName, Lang::get("DOWNLOADING") + fileName);
} else {
notConnectedMsg();
}
}
if ((hDown & KEY_B) || (hDown & KEY_TOUCH && touching(touch, arrowPos[2]))) {
// Reset everything.
OwnerAndRepo = "";
fileName = "";
Selection = 0;
mode = 2;
}
}
void UniStore::DrawFullURLScreen(void) const {
GFX::DrawTop();
if (config->useBars() == true) {
Gui::DrawStringCentered(0, 0, 0.7f, config->textColor(), Lang::get("FULL_URL"), 400);
} else {
Gui::DrawStringCentered(0, 2, 0.7f, config->textColor(), Lang::get("FULL_URL"), 400);
}
GFX::DrawSprite(sprites_uniStore_HD_idx, 140, 50, 0.2, 0.2);
GFX::DrawBottom();
GFX::DrawArrow(0, 218, 0, 1);
Gui::DrawStringCentered(0, 28, 0.7f, config->textColor(), Lang::get("FULL_URL"), 320);
Gui::DrawStringCentered(0, 108, 0.7f, config->textColor(), Lang::get("FILENAME"), 320);
Gui::Draw_Rect(GitHubPos[0].x, GitHubPos[0].y, GitHubPos[0].w, GitHubPos[0].h, config->barColor());
Gui::Draw_Rect(GitHubPos[1].x, GitHubPos[1].y, GitHubPos[1].w, GitHubPos[1].h, config->barColor());
Gui::Draw_Rect(GitHubPos[2].x, GitHubPos[2].y, GitHubPos[2].w, GitHubPos[2].h, config->barColor());
Gui::DrawStringCentered(0, 185, 0.7f, config->textColor(), Lang::get("OK"), 40);
Gui::DrawStringCentered(0, 57, 0.45f, config->textColor(), FullURL, 250);
Gui::DrawStringCentered(0, 137, 0.45f, config->textColor(), fileName, 250);
}
void UniStore::FullURLLogic(u32 hDown, u32 hHeld, touchPosition touch) {
if (hDown & KEY_TOUCH && touching(touch, GitHubPos[0])) {
FullURL = Input::setkbdString(150, Lang::get("ENTER_FULL_URL"));
}
if (hDown & KEY_TOUCH && touching(touch, GitHubPos[1])) {
fileName = Input::setkbdString(150, Lang::get("ENTER_FILENAME"));
}
if (hDown & KEY_TOUCH && touching(touch, GitHubPos[2])) {
if (checkWifiStatus() == true) {
ScriptHelper::downloadFile(FullURL, config->storePath() + fileName, Lang::get("DOWNLOADING") + fileName);
} else {
notConnectedMsg();
}
}
if ((hDown & KEY_B) || (hDown & KEY_TOUCH && touching(touch, arrowPos[2]))) {
// Reset everything.
FullURL = "";
fileName = "";
Selection = 0;
mode = 2;
}
}
-540
View File
@@ -1,540 +0,0 @@
/*
* This file is part of Universal-Updater
* Copyright (C) 2019-2020 Universal-Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "download.hpp"
#include "formatting.hpp"
#include "json.hpp"
#include "scriptHelper.hpp"
#include "unistore_v1.hpp"
#include <unistd.h>
extern std::unique_ptr<Config> config;
extern bool touching(touchPosition touch, Structs::ButtonPos button);
extern u32 getColor(std::string colorString);
extern u32 barColor, bgTopColor, bgBottomColor, TextColor, progressBar, selected, unselected;
extern bool didAutoboot, isScriptSelected;
UniStoreV1::UniStoreV1(nlohmann::json &JSON, const std::string sheetPath, bool displayInf) {
this->storeJson = JSON;
this->displayInformations = displayInf;
if (access(sheetPath.c_str(), F_OK) != 0) {
this->sheetHasLoaded = false;
} else {
Gui::loadSheet(sheetPath.c_str(), this->sheet);
this->sheetHasLoaded = true;
}
u32 colorTemp;
if (config->useScriptColor()) {
colorTemp = getColor(ScriptHelper::getString(this->storeJson, "storeInfo", "barColor"));
barColor = colorTemp == 0 ? config->barColor() : colorTemp;
colorTemp = getColor(ScriptHelper::getString(this->storeJson, "storeInfo", "bgTopColor"));
bgTopColor = colorTemp == 0 ? config->topBG() : colorTemp;
colorTemp = getColor(ScriptHelper::getString(this->storeJson, "storeInfo", "bgBottomColor"));
bgBottomColor = colorTemp == 0 ? config->bottomBG() : colorTemp;
colorTemp = getColor(ScriptHelper::getString(this->storeJson, "storeInfo", "textColor"));
TextColor = colorTemp == 0 ? config->textColor() : colorTemp;
colorTemp = getColor(ScriptHelper::getString(this->storeJson, "storeInfo", "selectedColor"));
selected = colorTemp == 0 ? config->selectedColor() : colorTemp;
colorTemp = getColor(ScriptHelper::getString(this->storeJson, "storeInfo", "unselectedColor"));
unselected = colorTemp == 0 ? config->unselectedColor() : colorTemp;
colorTemp = getColor(ScriptHelper::getString(this->storeJson, "storeInfo", "progressbarColor"));
progressBar = colorTemp == 0 ? config->progressbarColor() : colorTemp;
} else {
barColor = config->barColor();
bgTopColor = config->topBG();
bgBottomColor = config->bottomBG();
TextColor = config->textColor();
selected = config->selectedColor();
unselected = config->unselectedColor();
progressBar = config->progressbarColor();
}
}
void UniStoreV1::drawBlend(int key, int x, int y) const {
C2D_ImageTint tint;
C2D_SetImageTint(&tint, C2D_TopLeft, C2D_Color32(0, 0, 0, 180), 0.5);
C2D_SetImageTint(&tint, C2D_TopRight, C2D_Color32(0, 0, 0, 180), 0.5);
C2D_SetImageTint(&tint, C2D_BotLeft, C2D_Color32(0, 0, 0, 180), 0.5);
C2D_SetImageTint(&tint, C2D_BotRight, C2D_Color32(0, 0, 0, 180), 0.5);
C2D_DrawImageAt(C2D_SpriteSheetGetImage(this->sheet, key), x, y, 0.5f, &tint);
}
void UniStoreV1::parseObjects() {
this->objects.clear();
for(auto it = this->storeJson.begin();it != this->storeJson.end(); it++) {
if (it.key() != "storeInfo") {
this->objects.push_back(it.key());
}
}
}
UniStoreV1::~UniStoreV1() {
// Only unload if sheet has loaded.
if (this->sheetHasLoaded) {
Gui::unloadSheet(this->sheet);
}
}
void UniStoreV1::Draw(void) const {
std::string entryAmount = std::to_string(this->Selection+1) + " | " + std::to_string((int)this->storeJson.at("storeContent").size());
std::string info;
GFX::DrawTop();
// Top Background.
if (this->storeJson.at("storeInfo").contains("iconIndexTop") && sheetHasLoaded == true) {
Gui::DrawSprite(this->sheet, this->storeJson["storeInfo"]["iconIndexTop"], 0, 0);
}
// Icon.
if (this->storeJson.at("storeContent").at(Selection).at("info").contains("iconIndex") && sheetHasLoaded == true) {
if (this->storeJson.at("storeContent").at(Selection).at("info").contains("posX") && this->storeJson.at("storeContent").at(Selection).at("info").contains("posY")) {
Gui::DrawSprite(this->sheet, this->storeJson["storeContent"][Selection]["info"]["iconIndex"], this->storeJson["storeContent"][Selection]["info"]["posX"], this->storeJson["storeContent"][Selection]["info"]["posY"]);
} else {
Gui::DrawSprite(this->sheet, this->storeJson["storeContent"][Selection]["info"]["iconIndex"], 175, 155);
}
}
if (displayInformations != false) {
Gui::DrawStringCentered(0, config->useBars() ? 0 : 2, 0.7f, TextColor, std::string(this->storeJson["storeInfo"]["title"]), 400);
Gui::DrawString(397-Gui::GetStringWidth(0.6f, entryAmount), (config->useBars() ? 239 : 237)-Gui::GetStringHeight(0.6f, entryAmount), 0.6f, TextColor, entryAmount);
Gui::DrawStringCentered(0, 32, 0.6f, TextColor, Lang::get("TITLE") + std::string(this->storeJson["storeContent"][Selection]["info"]["title"]), 400);
Gui::DrawStringCentered(0, 57, 0.6f, TextColor, Lang::get("AUTHOR") + std::string(this->storeJson["storeContent"][Selection]["info"]["author"]), 400);
Gui::DrawStringCentered(0, 82, 0.6f, TextColor, Lang::get("DESC") + std::string(this->storeJson["storeContent"][Selection]["info"]["description"]), 400);
if (this->storeJson["storeContent"][Selection]["info"]["version"] != "") {
Gui::DrawStringCentered(0, 107, 0.6f, TextColor, Lang::get("VERSION") + std::string(this->storeJson["storeContent"][Selection]["info"]["version"]), 400);
} else {
Gui::DrawStringCentered(0, 107, 0.6f, TextColor, Lang::get("VERSION") + Lang::get("UNKNOWN"), 400);
}
if (this->storeJson["storeContent"][Selection]["info"]["fileSize"] != 0) {
Gui::DrawStringCentered(0, 132, 0.6f, TextColor, Lang::get("FILE_SIZE") + formatBytes(int64_t(this->storeJson["storeContent"][Selection]["info"]["fileSize"])), 400);
} else {
Gui::DrawStringCentered(0, 132, 0.6f, TextColor, Lang::get("FILE_SIZE") + Lang::get("UNKNOWN"), 400);
}
}
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 400, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
GFX::DrawBottom();
// Bottom Background.
if (this->storeJson.at("storeInfo").contains("iconIndexBottom") && sheetHasLoaded == true) {
Gui::DrawSprite(this->sheet, this->storeJson["storeInfo"]["iconIndexBottom"], 0, 0);
}
GFX::DrawArrow(295, -1);
GFX::DrawArrow(315, 240, 180.0);
GFX::DrawArrow(0, 218, 0, 1);
GFX::DrawSpriteBlend(sprites_dropdown_idx, arrowPos[3].x, arrowPos[3].y);
if (config->viewMode() == 0) {
for(int i = 0; i < ENTRIES_PER_SCREEN && i < (int)this->storeJson.at("storeContent").size(); i++) {
info = this->storeJson["storeContent"][screenPos + i]["info"]["title"];
if (screenPos + i == Selection) {
if (this->storeJson.at("storeInfo").contains("buttonLarge") && sheetHasLoaded == true) {
Gui::DrawSprite(this->sheet, this->storeJson["storeInfo"]["buttonLarge"], 0, 40+(i*57));
} else {
if (!dropDownMenu) {
Gui::drawAnimatedSelector(0, 40+(i*57), 320, 45, .060, TRANSPARENT, selected);
}
}
} else {
if (this->storeJson.at("storeInfo").contains("buttonLarge") && sheetHasLoaded == true) {
this->drawBlend(this->storeJson["storeInfo"]["buttonLarge"], 0, 40+(i*57));
} else {
Gui::Draw_Rect(0, 40+(i*57), 320, 45, unselected);
}
}
Gui::DrawStringCentered(0, 50+(i*57), 0.7f, TextColor, info, 320);
}
} else if (config->viewMode() == 1) {
for(int i = 0; i < ENTRIES_PER_LIST && i < (int)this->storeJson.at("storeContent").size(); i++) {
info = this->storeJson["storeContent"][screenPosList + i]["info"]["title"];
if (screenPosList + i == Selection) {
if (this->storeJson.at("storeInfo").contains("buttonSmall") && sheetHasLoaded == true) {
Gui::DrawSprite(this->sheet, this->storeJson["storeInfo"]["buttonSmall"], 0, (i+1)*27);
} else {
if (!dropDownMenu) {
Gui::drawAnimatedSelector(0, (i+1)*27, 320, 25, .060, TRANSPARENT, selected);
}
}
} else {
if (this->storeJson.at("storeInfo").contains("buttonSmall") && sheetHasLoaded == true) {
this->drawBlend(this->storeJson["storeInfo"]["buttonSmall"], 0, (i+1)*27);
} else {
Gui::Draw_Rect(0, (i+1)*27, 320, 25, unselected);
}
}
Gui::DrawStringCentered(0, ((i+1)*27)+1, 0.7f, TextColor, info, 320);
}
}
// DropDown Menu.
if (dropDownMenu) {
// Draw Operation Box.
Gui::Draw_Rect(0, 25, 140, 44, barColor);
Gui::drawAnimatedSelector(dropPos[0].x, dropPos[0].y, dropPos[0].w, dropPos[0].h, .090, TRANSPARENT, selected);
// Draw Dropdown Icons.
GFX::DrawSpriteBlend(sprites_view_idx, dropPos[0].x, dropPos[0].y);
// Dropdown Text.
Gui::DrawString(dropPos[0].x+30, dropPos[0].y+5, 0.4f, TextColor, Lang::get("VIEW_DDM"), 100);
}
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 320, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); // Fade in/out effect
}
void UniStoreV1::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
if (keyRepeatDelay) keyRepeatDelay--;
//DropDown Logic.
if (dropDownMenu) {
if ((hDown & KEY_SELECT) || (hDown & KEY_TOUCH && touching(touch, arrowPos[3]))) {
dropDownMenu = false;
}
if (hDown & KEY_DOWN) {
if (dropSelection < 1) dropSelection++;
}
if (hDown & KEY_UP) {
if (dropSelection > 0) dropSelection--;
}
if (hDown & KEY_A) {
if (config->viewMode() == 0) {
config->viewMode(1);
} else {
config->viewMode(0);
}
dropDownMenu = false;
}
if (hDown & KEY_TOUCH) {
if (touching(touch, dropPos[0])) {
if (config->viewMode() == 0) {
config->viewMode(1);
} else {
config->viewMode(0);
}
dropDownMenu = false;
}
}
} else {
if ((hDown & KEY_SELECT) || (hDown & KEY_TOUCH && touching(touch, arrowPos[3]))) {
dropSelection = 0;
dropDownMenu = true;
}
if ((hDown & KEY_B) || (hDown & KEY_TOUCH && touching(touch, arrowPos[2]))) {
if (!didAutoboot) didAutoboot = true;
Gui::screenBack(config->screenFade());
return;
}
// Go one entry up.
if ((hHeld & KEY_UP && !keyRepeatDelay) || (hDown & KEY_TOUCH && touching(touch, arrowPos[0]))) {
if (Selection > 0) {
Selection--;
} else {
Selection = (int)this->storeJson.at("storeContent").size()-1;
}
keyRepeatDelay = config->keyDelay();
}
// Go one entry down.
if ((hHeld & KEY_DOWN && !keyRepeatDelay) || (hDown & KEY_TOUCH && touching(touch, arrowPos[1]))) {
if (Selection < (int)this->storeJson.at("storeContent").size()-1) {
Selection++;
} else {
Selection = 0;
}
keyRepeatDelay = config->keyDelay();
}
if ((hHeld & KEY_RIGHT && !keyRepeatDelay)) {
if (config->viewMode() == 0) {
if (Selection < (int)this->storeJson.at("storeContent").size()-1-3) {
Selection += 3;
} else {
Selection = (int)this->storeJson.at("storeContent").size()-1;
}
} else {
if (Selection < (int)this->storeJson.at("storeContent").size()-1-6) {
Selection += 7;
} else {
Selection = (int)this->storeJson.at("storeContent").size()-1;
}
}
keyRepeatDelay = config->keyDelay();
}
if ((hHeld & KEY_LEFT && !keyRepeatDelay)) {
if (config->viewMode() == 0) {
if (Selection > 2) {
Selection -= 3;
} else {
Selection = 0;
}
} else {
if (Selection > 6) {
Selection -= 7;
} else {
Selection = 0;
}
}
keyRepeatDelay = config->keyDelay();
}
// Execute touched Entry.
if (hDown & KEY_TOUCH) {
if (config->viewMode() == 0) {
for(int i = 0; i < ENTRIES_PER_SCREEN && i < (int)this->storeJson.at("storeContent").size(); i++) {
if (touch.py > 40+(i*57) && touch.py < 40+(i*57)+45) {
Selection = screenPos + i;
std::string info = this->storeJson["storeContent"][Selection]["info"]["title"];
if (Msg::promptMsg(Lang::get("EXECUTE_STORE") + "\n\n" + info)) {
execute();
}
}
}
} else if (config->viewMode() == 1) {
for(int i = 0; i < ENTRIES_PER_LIST && i < (int)this->storeJson.at("storeContent").size(); i++) {
if (touch.py > (i+1)*27 && touch.py < (i+2)*27) {
Selection = screenPosList + i;
std::string info = this->storeJson["storeContent"][Selection]["info"]["title"];
if (Msg::promptMsg(Lang::get("EXECUTE_STORE") + "\n\n" + info)) {
execute();
}
}
}
}
}
// Execute that Entry.
if (hDown & KEY_A) {
std::string info = this->storeJson["storeContent"][Selection]["info"]["title"];
if (Msg::promptMsg(Lang::get("EXECUTE_STORE") + "\n\n" + info)) {
execute();
}
}
if (config->viewMode() == 0) {
if (Selection < screenPos) {
screenPos = Selection;
} else if (Selection > screenPos + ENTRIES_PER_SCREEN - 1) {
screenPos = Selection - ENTRIES_PER_SCREEN + 1;
}
} else if (config->viewMode() == 1) {
if (Selection < screenPosList) {
screenPosList = Selection;
} else if (Selection > screenPosList + ENTRIES_PER_LIST - 1) {
screenPosList = Selection - ENTRIES_PER_LIST + 1;
}
}
}
}
// Execute Entry.
Result UniStoreV1::execute() {
Result ret = NONE; // No Error has been occured now.
for(int i = 0; i < (int)this->storeJson.at("storeContent").at(Selection).at("script").size(); i++) {
if (ret == NONE) {
std::string type = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("type");
if (type == "deleteFile") {
bool missing = false;
std::string file, message;
if (this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("file")) file = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("file");
else missing = true;
if (this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("message")) message = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("message");
if (!missing) ret = ScriptHelper::removeFile(file, message);
else ret = SYNTAX_ERROR;
} else if (type == "downloadFile") {
bool missing = false;
std::string file, output, message;
if (this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("file")) file = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("file");
else missing = true;
if (this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("output")) output = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("output");
else missing = true;
if (this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("message")) message = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("message");
if (!missing) ret = ScriptHelper::downloadFile(file, output, message);
else ret = SYNTAX_ERROR;
} else if (type == "downloadRelease") {
bool missing = false, includePrereleases = false, showVersions = false;
std::string repo, file, output, message;
if (this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("repo")) repo = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("repo");
else missing = true;
if (this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("file")) file = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("file");
else missing = true;
if (this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("output")) output = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("output");
else missing = true;
if (this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("includePrereleases") && this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("includePrereleases").is_boolean())
includePrereleases = this->storeJson.at(Selection).at("script").at(i).at("includePrereleases");
if (this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("showVersions") && this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("showVersions").is_boolean())
showVersions = this->storeJson.at(Selection).at("script").at(i).at("showVersions");
if (this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("message")) message = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("message");
if (!missing) ret = ScriptHelper::downloadRelease(repo, file, output, includePrereleases, showVersions, message);
else ret = SYNTAX_ERROR;
} else if (type == "extractFile") {
bool missing = false;
std::string file, input, output, message;
if (this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("file")) file = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("file");
else missing = true;
if (this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("input")) input = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("input");
else missing = true;
if (this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("output")) output = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("output");
else missing = true;
if (this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("message")) message = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("message");
if (!missing) ScriptHelper::extractFile(file, input, output, message);
else ret = SYNTAX_ERROR;
} else if (type == "installCia") {
bool missing = false, updateSelf = false;
std::string file, message;
if (this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("file")) file = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("file");
else missing = true;
if (this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("updateSelf") && this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("updateSelf").is_boolean()) {
updateSelf = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("updateSelf");
}
if (this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("message")) message = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("message");
if (!missing) ScriptHelper::installFile(file, updateSelf, message);
else ret = SYNTAX_ERROR;
} else if (type == "mkdir") {
bool missing = false;
std::string directory, message;
if (this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("directory")) directory = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("directory");
else missing = true;
if (!missing) makeDirs(directory.c_str());
else ret = SYNTAX_ERROR;
} else if (type == "rmdir") {
bool missing = false;
std::string directory, message, promptmsg;
if (this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("directory")) directory = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("directory");
else missing = true;
promptmsg = Lang::get("DELETE_PROMPT") + "\n" + directory;
if (!missing) {
if (access(directory.c_str(), F_OK) != 0 ) {
ret = DELETE_ERROR;
} else {
if (Msg::promptMsg(promptmsg)) {
removeDirRecursive(directory.c_str());
}
}
}
else ret = SYNTAX_ERROR;
} else if (type == "mkfile") {
bool missing = false;
std::string file;
if (this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("file")) file = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("file");
else missing = true;
if (!missing) ScriptHelper::createFile(file.c_str());
else ret = SYNTAX_ERROR;
} else if (type == "timeMsg") {
bool missing = false;
std::string message;
int seconds;
if (this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("message")) message = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("message");
else missing = true;
if (this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("seconds") && this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("seconds").is_number())
seconds = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("seconds");
else missing = true;
if (!missing) ScriptHelper::displayTimeMsg(message, seconds);
else ret = SYNTAX_ERROR;
} else if (type == "saveConfig") {
config->save();
} else if (type == "notImplemented") {
notImplemented();
} else if (type == "bootTitle") {
std::string TitleID = "";
std::string message = "";
bool isNAND = false, missing = false;
if (this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("TitleID")) TitleID = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("TitleID");
else missing = true;
if (this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("NAND") && this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("NAND").is_boolean()) isNAND = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("NAND");
else missing = true;
if (this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("message")) message = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("message");
else missing = true;
if (!missing) ScriptHelper::bootTitle(TitleID, isNAND, message);
else ret = SYNTAX_ERROR;
} else if (type == "promptMessage") {
std::string Message = "";
if (this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("message")) Message = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("message");
ret = ScriptHelper::prompt(Message);
} else if (type == "copy") {
std::string Message = "", source = "", destination = "";
bool missing = false;
if (this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("source")) source = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("source");
else missing = true;
if (this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("destination")) destination = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("destination");
else missing = true;
if (this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("message")) Message = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("message");
if (!missing) ret = ScriptHelper::copyFile(source, destination, Message);
else ret = SYNTAX_ERROR;
} else if (type == "move") {
std::string Message = "", oldFile = "", newFile = "";
bool missing = false;
if (this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("old")) oldFile = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("old");
else missing = true;
if (this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("new")) newFile = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("new");
else missing = true;
if (this->storeJson.at("storeContent").at(Selection).at("script").at(i).contains("message")) Message = this->storeJson.at("storeContent").at(Selection).at("script").at(i).at("message");
if (!missing) ret = ScriptHelper::renameFile(oldFile, newFile, Message);
else ret = SYNTAX_ERROR;
}
}
}
if (ret == NONE) doneMsg();
else if (ret == FAILED_DOWNLOAD) Msg::DisplayWarnMsg(Lang::get("DOWNLOAD_ERROR"));
else if (ret == SCRIPT_CANCELED) Msg::DisplayWarnMsg(Lang::get("SCRIPT_CANCELED"));
else if (ret == SYNTAX_ERROR) Msg::DisplayWarnMsg(Lang::get("SYNTAX_ERROR"));
else if (ret == COPY_ERROR) Msg::DisplayWarnMsg(Lang::get("COPY_ERROR"));
else if (ret == MOVE_ERROR) Msg::DisplayWarnMsg(Lang::get("MOVE_ERROR"));
else if (ret == DELETE_ERROR) Msg::DisplayWarnMsg(Lang::get("DELETE_ERROR"));
return ret;
}
File diff suppressed because it is too large Load Diff
+154
View File
@@ -0,0 +1,154 @@
/*
* This file is part of Universal-Updater
* Copyright (C) 2019-2020 Universal-Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "scriptUtils.hpp"
#include "storeUtils.hpp"
#include "structs.hpp"
#define DOWNLOAD_ENTRIES 8
extern bool touching(touchPosition touch, Structs::ButtonPos button);
static const std::vector<Structs::ButtonPos> downloadBoxes = {
{ 54, 4, 262, 22 },
{ 54, 34, 262, 22 },
{ 54, 64, 262, 22 },
{ 54, 94, 262, 22 },
{ 54, 124, 262, 22 },
{ 54, 154, 262, 22 },
{ 54, 184, 262, 22 },
{ 54, 214, 262, 22 }
};
/*
Draw the Download Entries part.
const std::unique_ptr<Store> &store: Const Reference to the Store class.
const std::vector<std::string> &entries: Const Reference to the download list as a vector of strings.
const bool &fetch: Const Reference to Fetch.
*/
void StoreUtils::DrawDownList(const std::unique_ptr<Store> &store, const std::vector<std::string> &entries, const bool &fetch) {
if (store && !fetch) {
if (entries.size() > 0) {
for (int i = 0; i < DOWNLOAD_ENTRIES && i < (int)entries.size(); i++) {
GFX::drawBox(downloadBoxes[i].x, downloadBoxes[i].y, downloadBoxes[i].w, downloadBoxes[i].h, store->GetDownloadIndex() == i + store->GetDownloadSIndex());
Gui::DrawStringCentered(54 - 160 + (262 / 2), downloadBoxes[i].y + 4, 0.45f, TEXT_COLOR, entries[(i + store->GetDownloadSIndex())], 260);
}
} else { // If no downloads available..
Gui::DrawStringCentered(25, downloadBoxes[0].y + 4, 0.5f, TEXT_COLOR, Lang::get("NO_DOWNLOADS_AVAILABLE"), 260);
}
}
}
/*
This is the Download List handle.
Here you can..
- Scroll through the download list, if any available.
- Execute an Entry of the download list.
- Return back to EntryInfo through `B`.
u32 hDown: The hidKeysDown() variable.
u32 hHeld: The hidKeysHeld() variable.
touchPosition touch: The TouchPosition variable.
const std::unique_ptr<Store> &store: Const Reference to the Store class, since we do not modify anything in it.
const std::unique_ptr<StoreEntry> &entry: Const Reference to the current StoreEntry, since we do not modify anything in it.
const std::vector<std::string> &entries: Const Reference to the download list, since we do not modify anything in it.
int &currentMenu: Reference to the StoreMode / Menu, so we can switch back to EntryInfo with `B`.
std::unique_ptr<Meta> &meta: Reference to the Meta, to apply the updates stuff.
const int &lastMode: Const Reference to the last mode.
int &smallDelay: Reference to the small delay. This helps to not directly press A.
*/
void StoreUtils::DownloadHandle(u32 hDown, u32 hHeld, touchPosition touch, const std::unique_ptr<Store> &store, const std::unique_ptr<StoreEntry> &entry, const std::vector<std::string> &entries, int &currentMenu, std::unique_ptr<Meta> &meta, const int &lastMode, int &smallDelay) {
if (store && entry) { // Ensure, store & entry is not a nullptr.
if (smallDelay > 0) {
smallDelay--;
}
if (hRepeat & KEY_DOWN) {
if (entries.size() <= 0) return; // Smaller *than* 0 -> Invalid.
if (store->GetDownloadIndex() < (int)entries.size() - 1) store->SetDownloadIndex(store->GetDownloadIndex() + 1);
else store->SetDownloadIndex(0);
}
if (hRepeat & KEY_UP) {
if (entries.size() <= 0) return; // Smaller *than* 0 -> Invalid.
if (store->GetDownloadIndex() > 0) store->SetDownloadIndex(store->GetDownloadIndex() - 1);
else store->SetDownloadIndex(entries.size() - 1);
}
if (hRepeat & KEY_RIGHT) {
if (entries.size() <= 0) return; // Smaller *than* 0 -> Invalid.
if (store->GetDownloadIndex() + DOWNLOAD_ENTRIES < (int)entries.size()-1) store->SetDownloadIndex(store->GetDownloadIndex() + DOWNLOAD_ENTRIES);
else store->SetDownloadIndex(entries.size()-1);
}
if (hRepeat & KEY_LEFT) {
if (entries.size() <= 0) return; // Smaller *than* 0 -> Invalid.
if (store->GetDownloadIndex() - DOWNLOAD_ENTRIES > 0) store->SetDownloadIndex(store->GetDownloadIndex() - DOWNLOAD_ENTRIES);
else store->SetDownloadIndex(0);
}
if (smallDelay == 0 && hDown & KEY_TOUCH) {
if (entries.size() <= 0) return; // Smaller *than* 0 -> Invalid.
for (int i = 0; i < DOWNLOAD_ENTRIES; i++) {
if (touching(touch, downloadBoxes[i])) {
if (i + store->GetDownloadSIndex() < (int)entries.size()) {
const std::string tmp = Lang::get("EXECUTE_ENTRY") + "\n\n" + entries[i + store->GetDownloadSIndex()];
if (Msg::promptMsg(tmp)) {
ScriptUtils::runFunctions(store->GetJson(), entry->GetEntryIndex(), entries[i + store->GetDownloadSIndex()]);
if (meta) meta->SetUpdated(store->GetUniStoreTitle(), entry->GetTitle(), entry->GetLastUpdated());
entry->SetUpdateAvl(false);
}
}
}
}
}
if (smallDelay == 0 && hDown & KEY_A) {
if (entries.size() <= 0) return; // Smaller *than* 0 -> Invalid.
const std::string tmp = Lang::get("EXECUTE_ENTRY") + "\n\n" + entries[store->GetDownloadIndex()];
if (Msg::promptMsg(tmp)) {
ScriptUtils::runFunctions(store->GetJson(), entry->GetEntryIndex(), entries[store->GetDownloadIndex()]);
if (meta) meta->SetUpdated(store->GetUniStoreTitle(), entry->GetTitle(), entry->GetLastUpdated());
entry->SetUpdateAvl(false);
}
}
if (hDown & KEY_B) currentMenu = lastMode; // Go back to EntryInfo.
/* Scroll Handle. */
if (store->GetDownloadIndex() < store->GetDownloadSIndex()) store->SetDownloadSIndex(store->GetDownloadIndex());
else if (store->GetDownloadIndex() > store->GetDownloadSIndex() + DOWNLOAD_ENTRIES - 1) store->SetDownloadSIndex(store->GetDownloadIndex() - DOWNLOAD_ENTRIES + 1);
}
}
+83
View File
@@ -0,0 +1,83 @@
/*
* This file is part of Universal-Updater
* Copyright (C) 2019-2020 Universal-Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "storeUtils.hpp"
#include "structs.hpp"
extern bool touching(touchPosition touch, Structs::ButtonPos button);
static const Structs::ButtonPos btn = { 53, 215, 20, 20 };
/*
Draw the Entry Info part.
const std::unique_ptr<Store> &store: Const Reference to the Store class.
const std::unique_ptr<StoreEntry> &entry: Const Reference to the current StoreEntry.
*/
void StoreUtils::DrawEntryInfo(const std::unique_ptr<Store> &store, const std::unique_ptr<StoreEntry> &entry) {
if (store && entry) { // Ensure, store & entry is not a nullptr.
Gui::Draw_Rect(48, 0, 272, 36, ENTRY_BAR_COLOR);
Gui::Draw_Rect(48, 36, 272, 1, ENTRY_BAR_OUTL_COLOR);
Gui::DrawStringCentered(25, 0, 0.6, TEXT_COLOR, entry->GetTitle(), 265);
Gui::DrawStringCentered(25, 20, 0.4, TEXT_COLOR, entry->GetAuthor(), 265);
if (entry->GetDescription() != "") {
/* "\n\n" breaks C2D_WordWrap, so check here. */
if (!(entry->GetDescription().find("\n\n") != std::string::npos)) {
Gui::DrawStringCentered(25, 50, 0.4, TEXT_COLOR, entry->GetDescription(), 220, 0, nullptr, C2D_WordWrap);
} else {
Gui::DrawStringCentered(25, 50, 0.4, TEXT_COLOR, entry->GetDescription(), 220, 0);
}
}
Gui::DrawString(61, 130, 0.45, TEXT_COLOR, Lang::get("VERSION") + ": " + entry->GetVersion(), 240);
Gui::DrawString(61, 145, 0.45, TEXT_COLOR, Lang::get("CATEGORY") + ": " + entry->GetCategory(), 240);
Gui::DrawString(61, 160, 0.45, TEXT_COLOR, Lang::get("CONSOLE") + ": " + entry->GetConsole(), 240);
Gui::DrawString(61, 175, 0.45, TEXT_COLOR, Lang::get("LAST_UPDATED") + ": " + entry->GetLastUpdated(), 240);
Gui::DrawString(61, 190, 0.45, TEXT_COLOR, Lang::get("LICENSE") + ": " + entry->GetLicense(), 240);
GFX::drawBox(btn.x, btn.y, btn.w, btn.h, false);
Gui::DrawString(btn.x + 3, btn.y, 0.6f, TEXT_COLOR, "");
}
}
/*
The EntryInfo handle.
Here you can..
- Go to the download list, by pressing `A`.
- Show the MarkMenu with START.
u32 hDown: The hidKeysDown() variable.
u32 hHeld: The hidKeysHeld() variable.
touchPosition touch: The TouchPosition variable.
bool &showMark: Reference to showMark.. to show the mark menu.
bool &fetch: Reference to fetch, so we know, if we need to fetch, when accessing download list.
*/
void StoreUtils::EntryHandle(u32 hDown, u32 hHeld, touchPosition touch, bool &showMark, bool &fetch) {
if ((hDown & KEY_START) || (hDown & KEY_TOUCH && touching(touch, btn))) showMark = true;
}
+175
View File
@@ -0,0 +1,175 @@
/*
* This file is part of Universal-Updater
* Copyright (C) 2019-2020 Universal-Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "storeUtils.hpp"
#include "structs.hpp"
static const std::vector<Structs::ButtonPos> GridBoxes = {
{25, 45, 50, 50},
{100, 45, 50, 50},
{175, 45, 50, 50},
{250, 45, 50, 50},
{325, 45, 50, 50},
{25, 105, 50, 50},
{100, 105, 50, 50},
{175, 105, 50, 50},
{250, 105, 50, 50},
{325, 105, 50, 50},
{25, 165, 50, 50},
{100, 165, 50, 50},
{175, 165, 50, 50},
{250, 165, 50, 50},
{325, 165, 50, 50}
};
/*
Draw the Top Grid.
const std::unique_ptr<Store> &store: Const Reference to the Store class.
const std::vector<std::unique_ptr<StoreEntry>> &entries: Const Reference to the StoreEntries.
*/
void StoreUtils::DrawGrid(const std::unique_ptr<Store> &store, const std::vector<std::unique_ptr<StoreEntry>> &entries) {
if (store) { // Ensure, store is not a nullptr.
for (int i = 0, i2 = 0 + (store->GetScreenIndx() * 5); i2 < 15 + (store->GetScreenIndx() * 5) && i2 < (int)entries.size(); i2++, i++) {
/* Boxes. */
if (i == store->GetBox()) {
GFX::drawBox(GridBoxes[i].x, GridBoxes[i].y, 50, 50, true);
} else {
GFX::drawBox(GridBoxes[i].x, GridBoxes[i].y, 50, 50, false);
}
/* Ensure, entries is larger than the index. */
if ((int)entries.size() > i2) {
if (entries[i2]) { // Ensure, the Entry is not nullptr.
const C2D_Image tempImg = entries[i2]->GetIcon();
const uint8_t offsetW = (48 - tempImg.subtex->width) / 2; // Center W.
const uint8_t offsetH = (48 - tempImg.subtex->height) / 2; // Center H.
C2D_DrawImageAt(tempImg, GridBoxes[i].x + 1 + offsetW, GridBoxes[i].y + 1 + offsetH, 0.5);
/* Update Available mark. */
if (entries[i2]->GetUpdateAvl()) GFX::DrawSprite(sprites_update_app_idx, GridBoxes[i].x + 32, GridBoxes[i].y + 32);
}
}
}
}
}
/*
Top Grid Logic Handle.
Here you can..
- Scroll through the Grid with the D-Pad.
u32 hDown: The hidKeysDown() variable.
u32 hHeld: The hidKeysHeld() variable.
touchPosition touch: The TouchPosition variable.
std::unique_ptr<Store> &store: Reference to the Store class.
std::vector<std::unique_ptr<StoreEntry>> &entries: Reference to the StoreEntries.
const int &currentMode: Reference to the current Mode.
int &lastMode: Reference to the last mode.
bool &fetch: Reference to fetch.
int &smallDelay: Reference to the small delay.
*/
void StoreUtils::GridLogic(u32 hDown, u32 hHeld, touchPosition touch, std::unique_ptr<Store> &store, std::vector<std::unique_ptr<StoreEntry>> &entries, int &currentMode, int &lastMode, bool &fetch, int &smallDelay) {
if (store) { // Ensure, store is not a nullptr.
bool needUpdate = false;
if (hRepeat & KEY_DOWN) {
if (store->GetBox() > 9) {
if (store->GetEntry() + 5 < (int)entries.size()) {
store->SetEntry(store->GetEntry() + 5);
needUpdate = true;
}
} else {
if (store->GetEntry() + 5 < (int)entries.size()) {
store->SetBox(store->GetBox() + 5);
store->SetEntry(store->GetEntry() + 5);
}
}
}
if (hRepeat & KEY_RIGHT) {
if (store->GetEntry() < (int)entries.size() - 1) {
if (store->GetBox() < 14) {
store->SetBox(store->GetBox() + 1);
store->SetEntry(store->GetEntry() + 1);
}
}
}
if (hRepeat & KEY_LEFT) {
if (store->GetEntry() > 0) {
if (store->GetBox() > 0) {
store->SetBox(store->GetBox() - 1);
store->SetEntry(store->GetEntry() - 1);
}
}
}
if (hRepeat & KEY_UP) {
if (store->GetBox() < 5) {
if (store->GetEntry() > 4) {
store->SetEntry(store->GetEntry() - 5);
needUpdate = true;
}
} else {
store->SetBox(store->GetBox() - 5);
store->SetEntry(store->GetEntry() - 5);
}
}
if (hDown & KEY_A) {
fetch = true;
smallDelay = 5;
lastMode = currentMode;
currentMode = 1;
}
if (needUpdate) {
needUpdate = false;
/* Scroll Logic. */
if (store->GetBox() > 9) {
if (store->GetEntry() < (int)entries.size()) {
store->SetScreenIndx(store->GetScreenIndx() + 1);
}
} else if (store->GetBox() < 5) {
if (store->GetScreenIndx() > 0) {
store->SetScreenIndx(store->GetScreenIndx() - 1);
}
}
}
}
}
+118
View File
@@ -0,0 +1,118 @@
/*
* This file is part of Universal-Updater
* Copyright (C) 2019-2020 Universal-Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "storeUtils.hpp"
#include "structs.hpp"
static const std::vector<Structs::ButtonPos> StoreBoxesList = {
{ 20, 45, 360, 50 },
{ 20, 105, 360, 50 },
{ 20, 165, 360, 50 }
};
/*
Draw the top List.
const std::unique_ptr<Store> &store: Const Reference to the Store class.
const std::vector<std::unique_ptr<StoreEntry>> &entries: Const Reference to the StoreEntries.
*/
void StoreUtils::DrawList(const std::unique_ptr<Store> &store, const std::vector<std::unique_ptr<StoreEntry>> &entries) {
if (store) { // Ensure, store is not a nullptr.
if (entries.size() > 0) {
for (int i = 0; i < 3 && i < (int)entries.size(); i++) {
/* Boxes. */
GFX::drawBox(StoreBoxesList[i].x, StoreBoxesList[i].y, StoreBoxesList[i].w, StoreBoxesList[i].h, i + store->GetScreenIndx() == store->GetEntry());
/* Ensure, entries is larger than the index. */
if ((int)entries.size() > i + store->GetScreenIndx()) {
if (entries[i + store->GetScreenIndx()]) { // Ensure, the Entry is not nullptr.
const C2D_Image tempImg = entries[i + store->GetScreenIndx()]->GetIcon();
const uint8_t offsetW = (48 - tempImg.subtex->width) / 2; // Center W.
const uint8_t offsetH = (48 - tempImg.subtex->height) / 2; // Center H.
C2D_DrawImageAt(tempImg, StoreBoxesList[i].x + 1 + offsetW, StoreBoxesList[i].y + 1 + offsetH, 0.5);
}
if (entries[i + store->GetScreenIndx()]->GetUpdateAvl()) GFX::DrawSprite(sprites_update_app_idx, StoreBoxesList[i].x + 32, StoreBoxesList[i].y + 32);
Gui::DrawStringCentered(29, StoreBoxesList[i].y + 5, 0.6f, TEXT_COLOR, entries[i + store->GetScreenIndx()]->GetTitle(), 300);
Gui::DrawStringCentered(29, StoreBoxesList[i].y + 24, 0.6f, TEXT_COLOR, entries[i + store->GetScreenIndx()]->GetAuthor(), 300);
}
}
}
}
}
/*
Top List Logic Handle.
Here you can..
- Scroll through the Grid with the D-Pad Up / Down and skip 3 Entries with Left / Right.
u32 hDown: The hidKeysDown() variable.
u32 hHeld: The hidKeysHeld() variable.
touchPosition touch: The TouchPosition variable.
std::unique_ptr<Store> &store: Reference to the Store class.
std::vector<std::unique_ptr<StoreEntry>> &entries: Reference to the StoreEntries.
int &currentMode: Const Reference to the current Mode.
int &lastMode: Reference to the last mode.
bool &fetch: Reference to fetch.
int &smallDelay: Reference to the small delay.
*/
void StoreUtils::ListLogic(u32 hDown, u32 hHeld, touchPosition touch, std::unique_ptr<Store> &store, std::vector<std::unique_ptr<StoreEntry>> &entries, int &currentMode, int &lastMode, bool &fetch, int &smallDelay) {
if (store) { // Ensure, store is not a nullptr.
if (hRepeat & KEY_DOWN) {
if (store->GetEntry() < (int)entries.size() - 1) store->SetEntry(store->GetEntry() + 1);
else store->SetEntry(0);
}
if (hRepeat & KEY_RIGHT) {
if (store->GetEntry() < (int)entries.size() - 3) store->SetEntry(store->GetEntry() + 3);
else store->SetEntry(entries.size() - 1);
}
if (hRepeat & KEY_LEFT) {
if (store->GetEntry() - 2 > 0) store->SetEntry(store->GetEntry() - 3);
}
if (hRepeat & KEY_UP) {
if (store->GetEntry() > 0) store->SetEntry(store->GetEntry() - 1);
else store->SetEntry(entries.size() - 1);
}
if (hDown & KEY_A) {
fetch = true;
smallDelay = 5;
lastMode = currentMode;
currentMode = 1;
}
/* Scroll Logic. */
if (store->GetEntry() < store->GetScreenIndx()) store->SetScreenIndx(store->GetEntry());
else if (store->GetEntry() > store->GetScreenIndx() + 3 - 1) store->SetScreenIndx(store->GetEntry() - 3 + 1);
}
}
+123
View File
@@ -0,0 +1,123 @@
/*
* This file is part of Universal-Updater
* Copyright (C) 2019-2020 Universal-Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "storeUtils.hpp"
#include "structs.hpp"
extern bool touching(touchPosition touch, Structs::ButtonPos button);
static const std::vector<Structs::ButtonPos> markBox = {
{10, 94, 52, 52},
{72, 94, 52, 52},
{134, 94, 52, 52},
{196, 94, 52, 52},
{258, 94, 52, 52},
{ 53, 215, 20, 20 }
};
/*
Draw the Marking part.
const int &marks: A Reference to the active mark flags.
*/
void StoreUtils::DisplayMarkBox(const int &marks) {
Gui::Draw_Rect(0, 0, 320, 240, DIM_COLOR); // Darken.
GFX::drawBox(markBox[0].x, markBox[0].y, markBox[0].w, markBox[0].h, marks & favoriteMarks::STAR);
GFX::drawBox(markBox[1].x, markBox[1].y, markBox[1].w, markBox[1].h, marks & favoriteMarks::HEART);
GFX::drawBox(markBox[2].x, markBox[2].y, markBox[2].w, markBox[2].h, marks & favoriteMarks::DIAMOND);
GFX::drawBox(markBox[3].x, markBox[3].y, markBox[3].w, markBox[3].h, marks & favoriteMarks::CLUBS);
GFX::drawBox(markBox[4].x, markBox[4].y, markBox[4].w, markBox[4].h, marks & favoriteMarks::SPADE);
Gui::DrawString(markBox[0].x + 15, markBox[0].y + 12, 0.9, TEXT_COLOR, "");
Gui::DrawString(markBox[1].x + 15, markBox[1].y + 12, 0.9, TEXT_COLOR, "");
Gui::DrawString(markBox[2].x + 15, markBox[2].y + 12, 0.9, TEXT_COLOR, "");
Gui::DrawString(markBox[3].x + 15, markBox[3].y + 12, 0.9, TEXT_COLOR, "");
Gui::DrawString(markBox[4].x + 15, markBox[4].y + 12, 0.9, TEXT_COLOR, "");
GFX::drawBox(markBox[5].x, markBox[5].y, markBox[5].w, markBox[5].h, false);
Gui::DrawString(markBox[5].x + 3, markBox[5].y, 0.6f, TEXT_COLOR, "");
}
/*
Mark Menu handle.
Here you can..
- Mark the selected app.
- Return to EntryInfo with `B`.
u32 hDown: The hidKeysDown() variable.
u32 hHeld: The hidKeysHeld() variable.
touchPosition touch: The TouchPosition variable.
std::unique_ptr<StoreEntry> &entry: Reference to the current StoreEntry.
const std::unique_ptr<Store> &store: Const Reference to the Store, since we do not modify anything there.
bool &showMark: Reference to showMark, so we know, if we should stay here or not.
std::unique_ptr<Meta> &meta: Reference to the Meta class.
*/
void StoreUtils::MarkHandle(u32 hDown, u32 hHeld, touchPosition touch, std::unique_ptr<StoreEntry> &entry, const std::unique_ptr<Store> &store, bool &showMark, std::unique_ptr<Meta> &meta) {
hidScanInput();
touchPosition t;
hidTouchRead(&t);
if (meta && entry) {
if (hidKeysDown() & KEY_TOUCH) {
/* Star. */
if (touching(t, markBox[0])) {
meta->SetMarks(store->GetUniStoreTitle(), entry->GetTitle(),
meta->GetMarks(store->GetUniStoreTitle(), entry->GetTitle()) ^ favoriteMarks::STAR);
entry->SetMark(meta->GetMarks(store->GetUniStoreTitle(), entry->GetTitle()));
/* Heart. */
} else if (touching(t, markBox[1])) {
meta->SetMarks(store->GetUniStoreTitle(), entry->GetTitle(),
meta->GetMarks(store->GetUniStoreTitle(), entry->GetTitle()) ^ favoriteMarks::HEART);
entry->SetMark(meta->GetMarks(store->GetUniStoreTitle(), entry->GetTitle()));
/* Diamond. */
} else if (touching(t, markBox[2])) {
meta->SetMarks(store->GetUniStoreTitle(), entry->GetTitle(),
meta->GetMarks(store->GetUniStoreTitle(), entry->GetTitle()) ^ favoriteMarks::DIAMOND);
entry->SetMark(meta->GetMarks(store->GetUniStoreTitle(), entry->GetTitle()));
/* Clubs. */
} else if (touching(t, markBox[3])) {
meta->SetMarks(store->GetUniStoreTitle(), entry->GetTitle(),
meta->GetMarks(store->GetUniStoreTitle(), entry->GetTitle()) ^ favoriteMarks::CLUBS);
entry->SetMark(meta->GetMarks(store->GetUniStoreTitle(), entry->GetTitle()));
/* Spade. */
} else if (touching(t, markBox[4])) {
meta->SetMarks(store->GetUniStoreTitle(), entry->GetTitle(),
meta->GetMarks(store->GetUniStoreTitle(), entry->GetTitle()) ^ favoriteMarks::SPADE);
entry->SetMark(meta->GetMarks(store->GetUniStoreTitle(), entry->GetTitle()));
}
}
}
if ((hidKeysDown() & KEY_B || hidKeysDown() & KEY_START) || (hidKeysDown() & KEY_TOUCH && touching(t, markBox[5]))) showMark = false; // Return back to screen.
}
+140
View File
@@ -0,0 +1,140 @@
/*
* This file is part of Universal-Updater
* Copyright (C) 2019-2020 Universal-Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "common.hpp"
#include "fileBrowse.hpp"
#include "meta.hpp"
#include <unistd.h>
/*
The Constructor of the Meta.
Includes MetaData file creation, if non existent.
*/
Meta::Meta() {
if (access(_META_PATH, F_OK) != 0) {
FILE *temp = fopen(_META_PATH, "w");
char tmp[2] = { '{', '}' };
fwrite(tmp, sizeof(tmp), 1, temp);
fclose(temp);
}
FILE *temp = fopen(_META_PATH, "rt");
this->metadataJson = nlohmann::json::parse(temp, nullptr, false);
fclose(temp);
if (config->metadata()) this->ImportMetadata();
}
/*
Import the old Metadata of the 'updates.json' file.
*/
void Meta::ImportMetadata() {
if (access("sdmc:/3ds/Universal-Updater/updates.json", F_OK) != 0) {
config->metadata(false);
return; // Not found.
}
Msg::DisplayMsg(Lang::get("FETCHING_METADATA"));
FILE *old = fopen("sdmc:/3ds/Universal-Updater/updates.json", "r");
nlohmann::json oldJson = nlohmann::json::parse(old, nullptr, false);
fclose(old);
std::vector<UniStoreInfo> info = GetUniStoreInfo(_STORE_PATH); // Fetch UniStores.
for (int i = 0; i < (int)info.size(); i++) {
if (info[i].Title != "" && oldJson.contains(info[i].FileName)) {
for(auto it = oldJson[info[i].FileName].begin(); it != oldJson[info[i].FileName].end(); ++it) {
this->SetUpdated(info[i].Title, it.key().c_str(), it.value().get<std::string>());
}
}
}
config->metadata(false);
}
/*
Get Last Updated.
std::string unistoreName: The UniStore name.
std::string entry: The Entry name.
*/
std::string Meta::GetUpdated(std::string unistoreName, std::string entry) const {
if (!this->metadataJson.contains(unistoreName)) return ""; // UniStore Name does not exist.
if (!this->metadataJson[unistoreName].contains(entry)) return ""; // Entry does not exist.
if (!this->metadataJson[unistoreName][entry].contains("updated")) return ""; // updated does not exist.
if (this->metadataJson[unistoreName][entry]["updated"].is_string()) return this->metadataJson[unistoreName][entry]["updated"];
return "";
}
/*
Get the marks.
std::string unistoreName: The UniStore name.
std::string entry: The Entry name.
*/
int Meta::GetMarks(std::string unistoreName, std::string entry) const {
int temp = 0;
if (!this->metadataJson.contains(unistoreName)) return temp; // UniStore Name does not exist.
if (!this->metadataJson[unistoreName].contains(entry)) return temp; // Entry does not exist.
if (!this->metadataJson[unistoreName][entry].contains("marks")) return temp; // marks does not exist.
if (this->metadataJson[unistoreName][entry]["marks"].is_number()) return this->metadataJson[unistoreName][entry]["marks"];
return temp;
}
/*
Return, if update available.
std::string unistoreName: The UniStore name.
std::string entry: The Entry name.
std::string updated: Compare for the update.
*/
bool Meta::UpdateAvailable(std::string unistoreName, std::string entry, std::string updated) const {
if (this->GetUpdated(unistoreName, entry) != "" && updated != "") {
return strcasecmp(updated.c_str(), this->GetUpdated(unistoreName, entry).c_str()) > 0;
}
return false;
}
/*
The save call.
Write to file.. called on destructor.
*/
void Meta::SaveCall() {
FILE *file = fopen(_META_PATH, "wb");
const std::string dump = this->metadataJson.dump(1, '\t');
fwrite(dump.c_str(), 1, dump.size(), file);
fclose(file);
}
+185
View File
@@ -0,0 +1,185 @@
/*
* This file is part of Universal-Updater
* Copyright (C) 2019-2020 Universal-Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "keyboard.hpp"
#include "storeUtils.hpp"
#include "structs.hpp"
extern bool touching(touchPosition touch, Structs::ButtonPos button);
static const std::vector<Structs::ButtonPos> SearchMenu = {
{ 55, 5, 258, 30 }, // Search bar.
/* Includes. */
{ 85, 84, 10, 10 },
{ 85, 100, 10, 10 },
{ 167, 84, 10, 10 },
{ 167, 100, 10, 10 },
/* Filters. */
{ 82, 170, 30, 30 },
{ 117, 170, 30, 30 },
{ 152, 170, 30, 30 },
{ 187, 170, 30, 30 },
{ 222, 170, 30, 30 },
{ 257, 170, 30, 30 }
};
/*
Draw the Search + Filter Menu.
const std::vector<bool> &searchIncludes: Const Reference to the searchIncludes.
const std::string &searchResult: Const Reference to the searchResult.
const int &marks: Const Reference to the filter mark flags.
const bool &updateFilter: Const Reference to the update filter.
*/
void StoreUtils::DrawSearchMenu(const std::vector<bool> &searchIncludes, const std::string &searchResult, const int &marks, const bool &updateFilter) {
Gui::Draw_Rect(54, 4, 260, SearchMenu[0].h + 2, SEARCH_BAR_OUTL_COLOR);
Gui::Draw_Rect(SearchMenu[0].x, SearchMenu[0].y, SearchMenu[0].w, SearchMenu[0].h, SEARCH_BAR_COLOR);
Gui::DrawStringCentered(28, 10, 0.6, TEXT_COLOR, searchResult, 265);
/* Checkboxes. */
for (int i = 0; i < 4; i++) {
GFX::DrawCheckbox(SearchMenu[i + 1].x, SearchMenu[i + 1].y, searchIncludes[i]);
}
Gui::DrawString(84, 60, 0.5, TEXT_COLOR, Lang::get("INCLUDE_IN_RESULTS"));
Gui::DrawString(SearchMenu[1].x + 18, SearchMenu[1].y + 1, 0.4, TEXT_COLOR, Lang::get("TITLE"));
Gui::DrawString(SearchMenu[2].x + 18, SearchMenu[2].y + 1, 0.4, TEXT_COLOR, Lang::get("AUTHOR"));
Gui::DrawString(SearchMenu[3].x + 18, SearchMenu[3].y + 1, 0.4, TEXT_COLOR, Lang::get("CATEGORY"));
Gui::DrawString(SearchMenu[4].x + 18, SearchMenu[4].y + 1, 0.4, TEXT_COLOR, Lang::get("CONSOLE"));
/* Filters. */
Gui::DrawString(84, 150, 0.5, TEXT_COLOR, Lang::get("FILTER_TO"));
GFX::drawBox(SearchMenu[5].x, SearchMenu[5].y, SearchMenu[5].w, SearchMenu[5].h, marks & favoriteMarks::STAR);
GFX::drawBox(SearchMenu[6].x, SearchMenu[6].y, SearchMenu[6].w, SearchMenu[6].h, marks & favoriteMarks::HEART);
GFX::drawBox(SearchMenu[7].x, SearchMenu[7].y, SearchMenu[7].w, SearchMenu[7].h, marks & favoriteMarks::DIAMOND);
GFX::drawBox(SearchMenu[8].x, SearchMenu[8].y, SearchMenu[8].w, SearchMenu[8].h, marks & favoriteMarks::CLUBS);
GFX::drawBox(SearchMenu[9].x, SearchMenu[9].y, SearchMenu[9].w, SearchMenu[9].h, marks & favoriteMarks::SPADE);
GFX::drawBox(SearchMenu[10].x, SearchMenu[10].y, SearchMenu[10].w, SearchMenu[10].h, updateFilter);
GFX::DrawSprite(sprites_update_filter_idx, SearchMenu[10].x + 8, SearchMenu[10].y + 8);
Gui::DrawString(SearchMenu[5].x + 8, SearchMenu[5].y + 8, 0.5, TEXT_COLOR, "");
Gui::DrawString(SearchMenu[6].x + 8, SearchMenu[6].y + 8, 0.5, TEXT_COLOR, "");
Gui::DrawString(SearchMenu[7].x + 8, SearchMenu[7].y + 8, 0.5, TEXT_COLOR, "");
Gui::DrawString(SearchMenu[8].x + 8, SearchMenu[8].y + 8, 0.5, TEXT_COLOR, "");
Gui::DrawString(SearchMenu[9].x + 8, SearchMenu[9].y + 8, 0.5, TEXT_COLOR, "");
}
/*
Search + Filter Handle.
Here you can..
- Filter your apps for the marks.
- Search the UniStore.
- Include stuff into the search.
u32 hDown: The hidKeysDown() variable.
u32 hHeld: The hidKeysHeld() variable.
touchPosition touch: The TouchPosition variable.
std::unique_ptr<Store> &store: Reference to the Store class.
std::vector<std::unique_ptr<StoreEntry>> &entries: Reference to the Store Entries.
std::vector<bool> &searchIncludes: Reference to the searchIncludes.
std::unique_ptr<Meta> &meta: Reference to the Meta class.
std::string &searchResult: Reference to the searchResult.
int &marks: Reference to the mark flags.
bool &updateFilter: Reference to the update filter.
*/
void StoreUtils::SearchHandle(u32 hDown, u32 hHeld, touchPosition touch, std::unique_ptr<Store> &store, std::vector<std::unique_ptr<StoreEntry>> &entries, std::vector<bool> &searchIncludes, std::unique_ptr<Meta> &meta, std::string &searchResult, int &marks, bool &updateFilter, bool ascending, SortType sorttype) {
/* Checkboxes. */
if (hDown & KEY_TOUCH) {
bool didTouch = false;
/* Includes. */
for (int i = 0; i < 4; i++) {
if (touching(touch, SearchMenu[i + 1])) {
searchIncludes[i] = !searchIncludes[i];
didTouch = true;
break;
}
}
/* Search bar. */
if (!didTouch) {
if (touching(touch, SearchMenu[0])) {
searchResult = Input::setkbdString(20, Lang::get("ENTER_SEARCH"));
didTouch = true;
}
}
/* Filters. */
if (!didTouch) {
if (touching(touch, SearchMenu[5])) {
marks = marks ^ favoriteMarks::STAR;
didTouch = true;
} else if (touching(touch, SearchMenu[6])) {
marks = marks ^ favoriteMarks::HEART;
didTouch = true;
} else if (touching(touch, SearchMenu[7])) {
marks = marks ^ favoriteMarks::DIAMOND;
didTouch = true;
} else if (touching(touch, SearchMenu[8])) {
marks = marks ^ favoriteMarks::CLUBS;
didTouch = true;
} else if (touching(touch, SearchMenu[9])) {
marks = marks ^ favoriteMarks::SPADE;
didTouch = true;
} else if (touching(touch, SearchMenu[10])) {
updateFilter = !updateFilter;
didTouch = true;
}
}
if (didTouch) {
if (store && store->GetValid()) { // Only search, when valid.
StoreUtils::ResetAll(store, meta, entries);
StoreUtils::search(entries, searchResult, searchIncludes[0], searchIncludes[1], searchIncludes[2], searchIncludes[3], marks, updateFilter);
store->SetScreenIndx(0);
store->SetEntry(0);
store->SetBox(0);
StoreUtils::SortEntries(ascending, sorttype, entries);
}
}
}
/* Reset all. */
if (hDown & KEY_X) {
marks = 0;
updateFilter = false;
for(uint i = 0; i < searchIncludes.size(); i++)
searchIncludes[i] = false;
searchResult = "";
if (store && store->GetValid()) {
StoreUtils::ResetAll(store, meta, entries);
StoreUtils::SortEntries(ascending, sorttype, entries);
}
}
}
+303
View File
@@ -0,0 +1,303 @@
/*
* This file is part of Universal-Updater
* Copyright (C) 2019-2020 Universal-Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "overlay.hpp"
#include "storeUtils.hpp"
extern bool exiting;
extern bool touching(touchPosition touch, Structs::ButtonPos button);
static const std::vector<Structs::ButtonPos> mainButtons = {
{ 54, 4, 262, 22 },
{ 54, 34, 262, 22 },
{ 54, 64, 262, 22 },
{ 54, 94, 262, 22 },
{ 54, 124, 262, 22 },
{ 54, 154, 262, 22 },
{ 54, 184, 262, 22 }
};
static const std::string autoupdate() { return (config->autoupdate() ? "DISABLE_AUTOUPDATE_UNISTORE" : "ENABLE_AUTOUPDATE_UNISTORE"); };
static const std::string updateCheck() { return (config->updatecheck() ? "DISABLE_UPDATE_CHECK" : "ENABLE_UPDATE_CHECK"); };
static const std::vector<std::string> mainStrings = { "LANGUAGE", "SELECT_UNISTORE", "CHANGE_DIRECTORIES", "CREDITS", "EXIT_APP" };
static const std::vector<std::string> dirStrings = { "CHANGE_3DSX_PATH", "CHANGE_NDS_PATH", "CHANGE_ARCHIVE_PATH" };
/*
Main Settings.
const int &selection: Const Reference to the Settings Selection.
*/
static void DrawSettingsMain(const int &selection) {
for (int i = 0; i < 7; i++) {
GFX::drawBox(mainButtons[i].x, mainButtons[i].y, mainButtons[i].w, mainButtons[i].h, i == selection);
}
Gui::DrawStringCentered(54 - 160 + (262 / 2), mainButtons[0].y + 4, 0.45f, TEXT_COLOR, Lang::get(mainStrings[0]), 260);
Gui::DrawStringCentered(54 - 160 + (262 / 2), mainButtons[1].y + 4, 0.45f, TEXT_COLOR, Lang::get(mainStrings[1]), 260);
Gui::DrawStringCentered(54 - 160 + (262 / 2), mainButtons[2].y + 4, 0.45f, TEXT_COLOR, Lang::get(autoupdate()), 260);
Gui::DrawStringCentered(54 - 160 + (262 / 2), mainButtons[3].y + 4, 0.45f, TEXT_COLOR, Lang::get(updateCheck()), 260);
Gui::DrawStringCentered(54 - 160 + (262 / 2), mainButtons[4].y + 4, 0.45f, TEXT_COLOR, Lang::get(mainStrings[2]), 260);
Gui::DrawStringCentered(54 - 160 + (262 / 2), mainButtons[5].y + 4, 0.45f, TEXT_COLOR, Lang::get(mainStrings[3]), 260);
Gui::DrawStringCentered(54 - 160 + (262 / 2), mainButtons[6].y + 4, 0.45f, TEXT_COLOR, Lang::get(mainStrings[4]), 260);
}
/*
Directory Change Draw.
const int &selection: Const Reference to the Settings Selection.
*/
static void DrawSettingsDir(const int &selection) {
for (int i = 0; i < 3; i++) {
GFX::DrawButton(mainButtons[i].x, mainButtons[i].y, mainButtons[i].w, mainButtons[i].h, i == selection, Lang::get(dirStrings[i]));
}
}
/*
Settings Main Handle.
Here you can..
- Change the Language.
- Access the UniStore Manage Handle.
- Enable UniStore auto update on boot.
- Show the Credits.
- Exit Universal-Updater.
u32 hDown: The hidKeysDown() variable.
u32 hHeld: The hidKeysHeld() variable.
touchPosition touch: The TouchPosition variable.
int &page: Reference to the page.
bool &dspSettings: Reference to the display Settings.
int &storeMode: Reference to the Store Mode.
int &selection: Reference to the Selection.
std::unique_ptr<Store> &store: Reference to the Store class.
std::vector<std::unique_ptr<StoreEntry>> &entries: Reference to the StoreEntries.
std::unique_ptr<Meta> &meta: Reference to the Meta class.
*/
static void SettingsHandleMain(u32 hDown, u32 hHeld, touchPosition touch, int &page, bool &dspSettings, int &storeMode, int &selection, std::unique_ptr<Store> &store, std::vector<std::unique_ptr<StoreEntry>> &entries, std::unique_ptr<Meta> &meta) {
if (hDown & KEY_B) {
selection = 0;
storeMode = 0;
}
if (hRepeat & KEY_DOWN) {
if (selection < 6) selection++;
else selection = 0;
}
if (hRepeat & KEY_UP) {
if (selection > 0) selection--;
else selection = mainStrings.size() + 1;
}
if (hRepeat & KEY_RIGHT) {
if (selection + 8 < (int)mainStrings.size() + 1) selection += 8;
else selection = mainStrings.size() + 1;
}
if (hRepeat & KEY_LEFT) {
if (selection - 8 > 0) selection -= 8;
else selection = 0;
}
if (hDown & KEY_TOUCH) {
if (touching(touch, mainButtons[0])) {
Overlays::SelectLanguage();
} else if (touching(touch, mainButtons[1])) {
Overlays::SelectStore(store, entries, meta);
} else if (touching(touch, mainButtons[2])) {
config->autoupdate(!config->autoupdate());
} else if (touching(touch, mainButtons[3])) {
config->updatecheck(!config->updatecheck());
} else if (touching(touch, mainButtons[4])) {
selection = 0;
page = 1;
} else if (touching(touch, mainButtons[5])) {
Overlays::ShowCredits();
} else if (touching(touch, mainButtons[6])) {
exiting = true;
}
}
if (hDown & KEY_A) {
switch(selection) {
case 0:
Overlays::SelectLanguage();
break;
case 1:
Overlays::SelectStore(store, entries, meta);
break;
case 2:
config->autoupdate(!config->autoupdate());
break;
case 3:
config->updatecheck(!config->updatecheck());
break;
case 4:
selection = 0;
page = 1;
break;
case 5:
Overlays::ShowCredits();
break;
case 6:
exiting = true;
break;
}
}
}
/*
Directory Handle.
Here you can..
- Change the Directory of...
- 3DSX, NDS & Archives.
u32 hDown: The hidKeysDown() variable.
u32 hHeld: The hidKeysHeld() variable.
touchPosition touch: The TouchPosition variable.
int &page: Reference to the page.
int &selection: Reference to the Selection.
*/
static void SettingsHandleDir(u32 hDown, u32 hHeld, touchPosition touch, int &page, int &selection) {
if (hDown & KEY_B) {
page = 0;
selection = 4;
}
if (hRepeat & KEY_DOWN) {
if (selection < 2) selection++;
else selection = 0;
}
if (hRepeat & KEY_UP) {
if (selection > 0) selection--;
else selection = dirStrings.size()-1;
}
if (hRepeat & KEY_RIGHT) {
if (selection + 8 < (int)dirStrings.size()-1) selection += 8;
else selection = dirStrings.size()-1;
}
if (hRepeat & KEY_LEFT) {
if (selection - 8 > 0) selection -= 8;
else selection = 0;
}
if (hDown & KEY_TOUCH) {
if (touching(touch, mainButtons[0])) {
const std::string path = Overlays::SelectDir(config->_3dsxPath(), Lang::get("SELECT_DIR"));
if (path != "") config->_3dsxPath(path);
} else if (touching(touch, mainButtons[1])) {
const std::string path = Overlays::SelectDir(config->ndsPath(), Lang::get("SELECT_DIR"));
if (path != "") config->ndsPath(path);
} else if (touching(touch, mainButtons[2])) {
const std::string path = Overlays::SelectDir(config->archPath(), Lang::get("SELECT_DIR"));
if (path != "") config->archPath(path);
}
}
if (hDown & KEY_A) {
std::string path = "";
switch(selection) {
case 0:
path = Overlays::SelectDir(config->_3dsxPath(), Lang::get("SELECT_DIR"));
if (path != "") config->_3dsxPath(path);
break;
case 1:
path = Overlays::SelectDir(config->ndsPath(), Lang::get("SELECT_DIR"));
if (path != "") config->ndsPath(path);
break;
case 2:
path = Overlays::SelectDir(config->archPath(), Lang::get("SELECT_DIR"));
if (path != "") config->archPath(path);
break;
}
}
}
/*
Draw the Settings.
const int &page: Const Reference to the page.
const int &selection: Const Reference to the selection.
*/
void StoreUtils::DrawSettings(const int &page, const int &selection) {
switch(page) {
case 0:
DrawSettingsMain(selection);
break;
case 1:
DrawSettingsDir(selection);
break;
}
}
/*
Settings Handle.
u32 hDown: The hidKeysDown() variable.
u32 hHeld: The hidKeysHeld() variable.
touchPosition touch: The TouchPosition variable.
int &page: Reference to the page.
bool &dspSettings: Reference to the display Settings.
int &storeMode: Reference to the Store Mode.
int &selection: Reference to the Selection.
std::unique_ptr<Store> &store: Reference to the Store class.
std::vector<std::unique_ptr<StoreEntry>> &entries: Reference to the StoreEntries.
std::unique_ptr<Meta> &meta: Reference to the Meta class.
*/
void StoreUtils::SettingsHandle(u32 hDown, u32 hHeld, touchPosition touch, int &page, bool &dspSettings, int &storeMode, int &selection, std::unique_ptr<Store> &store, std::vector<std::unique_ptr<StoreEntry>> &entries, std::unique_ptr<Meta> &meta) {
switch(page) {
case 0:
SettingsHandleMain(hDown, hHeld, touch, page, dspSettings, storeMode, selection, store, entries, meta);
break;
case 1:
SettingsHandleDir(hDown, hHeld, touch, page, selection);
break;
}
}
+98
View File
@@ -0,0 +1,98 @@
/*
* This file is part of Universal-Updater
* Copyright (C) 2019-2020 Universal-Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "storeUtils.hpp"
#include "structs.hpp"
extern bool touching(touchPosition touch, Structs::ButtonPos button);
static const std::vector<Structs::ButtonPos> sidePos = {
{ 0, 0, 48, 48 },
{ 0, 48, 48, 48 },
{ 0, 96, 48, 48 },
{ 0, 144, 48, 48 },
{ 0, 192, 48, 48 }
};
/*
Draw the Side Menu part.
const int &currentMenu: Const Reference to the current Store Mode / Menu.
*/
void StoreUtils::DrawSideMenu(const int &currentMenu) {
for (int i = 0; i < 5; i++) {
if (i == currentMenu) {
Gui::Draw_Rect(sidePos[i].x, sidePos[i].y, sidePos[i].w, sidePos[i].h, SIDEBAR_SELECTED_COLOR);
} else {
Gui::Draw_Rect(sidePos[i].x, sidePos[i].y, sidePos[i].w, sidePos[i].h, SIDEBAR_UNSELECTED_COLOR);
}
}
GFX::DrawSprite(sprites_info_idx, sidePos[0].x + 4, sidePos[0].y + 4);
GFX::DrawSprite(sprites_download_idx, sidePos[1].x + 4, sidePos[1].y + 4);
GFX::DrawSprite(sprites_search_idx, sidePos[2].x + 4, sidePos[2].y + 4);
GFX::DrawSprite(sprites_sort_idx, sidePos[3].x + 4, sidePos[3].y + 4);
GFX::DrawSprite(sprites_settings_idx, sidePos[4].x + 4, sidePos[4].y + 4);
Gui::Draw_Rect(48, 0, 1, 240, BAR_OUTL_COLOR);
}
/*
Side Menu Handle.
Here you can..
- Switch between the Menus through the sidebar.
u32 hDown: The hidKeysDown() variable.
touchPosition touch: The TouchPosition variable.
int &currentMenu: Reference to the Store Mode / Menu.
bool &fetch: Reference of the download fetch variable.. so we know, if we need to fetch the download entries.
*/
void StoreUtils::SideMenuHandle(u32 hDown, touchPosition touch, int &currentMenu, bool &fetch) {
if (hDown & KEY_TOUCH) {
for (int i = 0; i < 5; i++) {
if (touching(touch, sidePos[i])) {
if (i == 1) fetch = true; // Fetch download list, if 1.
currentMenu = i;
break;
}
}
}
if (hRepeat & KEY_R) {
if (currentMenu < 4) {
if (currentMenu + 1 == 1) fetch = true; // Fetch download list, if 1.
currentMenu++;
}
}
if (hRepeat & KEY_L) {
if (currentMenu > 0) {
if (currentMenu - 1 == 1) fetch = true; // Fetch download list, if 1.
currentMenu--;
}
}
}
+161
View File
@@ -0,0 +1,161 @@
/*
* This file is part of Universal-Updater
* Copyright (C) 2019-2020 Universal-Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "keyboard.hpp"
#include "storeUtils.hpp"
#include "structs.hpp"
extern bool touching(touchPosition touch, Structs::ButtonPos button);
static const std::vector<Structs::ButtonPos> buttons = {
{ 75, 50, 100, 16 },
{ 75, 70, 100, 16 },
{ 75, 90, 100, 16 },
{ 205, 50, 100, 16 },
{ 205, 70, 100, 16 },
{ 75, 160, 100, 16 },
{ 75, 180, 100, 16 }
};
static void DrawCheck(int pos, bool v) {
GFX::DrawSprite((v ? sprites_sort_checked_idx : sprites_sort_unchecked_idx), buttons[pos].x + 5, buttons[pos].y);
}
/*
Return SortType as an uint8_t.
const SortType &st: Const Reference to the SortType variable.
*/
static const uint8_t GetType(const SortType &st) {
switch(st) {
case SortType::TITLE:
return 0;
case SortType::AUTHOR:
return 1;
case SortType::LAST_UPDATED:
return 2;
}
return 1;
}
/*
Draw the Sort Menu.
const bool &asc: Const Reference to the Ascending variable.
const SortType &st: Const Reference to the SortType variable.
*/
void StoreUtils::DrawSorting(const bool &asc, const SortType &st) {
/* Sort By. */
Gui::DrawString(buttons[0].x + 5, buttons[0].y - 20, 0.6f, TEXT_COLOR, Lang::get("SORT_BY"));
for (int i = 0; i < 3; i++) {
DrawCheck(i, i == GetType(st));
}
Gui::DrawString(buttons[0].x + 25, buttons[0].y + 2, 0.4f, TEXT_COLOR, Lang::get("TITLE"));
Gui::DrawString(buttons[1].x + 25, buttons[1].y + 2, 0.4f, TEXT_COLOR, Lang::get("AUTHOR"));
Gui::DrawString(buttons[2].x + 25, buttons[2].y + 2, 0.4f, TEXT_COLOR, Lang::get("LAST_UPDATED"));
/* Direction. */
Gui::DrawString(buttons[3].x + 5, buttons[3].y - 20, 0.6f, TEXT_COLOR, Lang::get("DIRECTION"));
DrawCheck(3, asc);
DrawCheck(4, !asc);
Gui::DrawString(buttons[3].x + 25, buttons[3].y + 2, 0.4f, TEXT_COLOR, Lang::get("ASCENDING"));
Gui::DrawString(buttons[4].x + 25, buttons[4].y + 2, 0.4f, TEXT_COLOR, Lang::get("DESCENDING"));
/* Top Style. */
Gui::DrawString(buttons[5].x + 5, buttons[5].y - 20, 0.6f, TEXT_COLOR, Lang::get("TOP_STYLE"));
DrawCheck(5, config->list());
DrawCheck(6, !config->list());
Gui::DrawString(buttons[5].x + 25, buttons[5].y + 2, 0.4f, TEXT_COLOR, Lang::get("LIST"));
Gui::DrawString(buttons[6].x + 25, buttons[6].y + 2, 0.4f, TEXT_COLOR, Lang::get("GRID"));
}
/*
Sort Handle.
Here you can..
- Sort your Entries to..
- Title (Ascending / Descending).
- Author (Ascending / Descending).
- Last Updated Date (Ascending / Descending).
- Change the Top Style.
u32 hDown: The hidKeysDown() variable.
u32 hHeld: The hidKeysHeld() variable.
touchPosition touch: The TouchPosition variable.
std::unique_ptr<Store> &store: Reference to the Store class.
std::vector<std::unique_ptr<StoreEntry>> &entries: Reference to the StoreEntries.
bool &asc: Reference to the Ascending variable.
SortType &st: Reference to the SortType.
*/
void StoreUtils::SortHandle(u32 hDown, u32 hHeld, touchPosition touch, std::unique_ptr<Store> &store, std::vector<std::unique_ptr<StoreEntry>> &entries, bool &asc, SortType &st) {
if (store && store->GetValid() && entries.size() > 0) { // Ensure, this is valid and more than 0 entries exist.
if (hDown & KEY_TOUCH) {
/* SortType Part. */
if (touching(touch, buttons[0])) {
st = SortType::TITLE;
StoreUtils::SortEntries(asc, st, entries);
} else if (touching(touch, buttons[1])) {
st = SortType::AUTHOR;
StoreUtils::SortEntries(asc, st, entries);
} else if (touching(touch, buttons[2])) {
st = SortType::LAST_UPDATED;
StoreUtils::SortEntries(asc, st, entries);
/* Ascending | Descending Part. */
} else if (touching(touch, buttons[3])) {
asc = true;
StoreUtils::SortEntries(asc, st, entries);
} else if (touching(touch, buttons[4])) {
asc = false;
StoreUtils::SortEntries(asc, st, entries);
} else if (touching(touch, buttons[5])) {
if (config->list()) return;
config->list(true);
store->SetEntry(0);
store->SetScreenIndx(0);
store->SetBox(0);
} else if (touching(touch, buttons[6])) {
if (!config->list()) return;
config->list(false);
store->SetEntry(0);
store->SetScreenIndx(0);
store->SetBox(0);
}
}
}
}
+427
View File
@@ -0,0 +1,427 @@
/*
* This file is part of Universal-Updater
* Copyright (C) 2019-2020 Universal-Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "common.hpp"
#include "download.hpp"
#include "gui.hpp"
#include "scriptUtils.hpp"
#include "store.hpp"
#include <unistd.h>
extern C2D_SpriteSheet sprites;
extern bool checkWifiStatus();
static bool firstStart = true;
/*
Initialize a store.
const std::string &file: The UniStore file.
*/
Store::Store(const std::string &file) { this->update(file); };
/*
Update an UniStore,, including SpriteSheet, if revision increased.
const std::string &file: Const Reference to the fileName.
*/
void Store::update(const std::string &file) {
bool doSheet = false;
this->LoadFromFile(file);
int rev = -1;
/* Only do this, if valid. */
if (this->valid) {
if (this->storeJson["storeInfo"].contains("revision") && this->storeJson["storeInfo"]["revision"].is_number()) {
rev = this->storeJson["storeInfo"]["revision"];
}
/* First start exceptions. */
if (firstStart) {
firstStart = false;
if (!config->autoupdate()) {
this->loadSheets();
return;
}
}
if (this->storeJson.contains("storeInfo")) {
/* Checking... */
if (checkWifiStatus()) { // Only do, if WiFi available.
if (this->storeJson["storeInfo"].contains("url") && this->storeJson["storeInfo"]["url"].is_string()) {
if (this->storeJson["storeInfo"].contains("file") && this->storeJson["storeInfo"]["file"].is_string()) {
const std::string fl = this->storeJson["storeInfo"]["file"];
if (!(fl.find("/") != std::string::npos)) {
const std::string URL = this->storeJson["storeInfo"]["url"];
if (URL != "") {
std::string tmp = "";
doSheet = DownloadUniStore(URL, rev, tmp);
}
} else {
Msg::waitMsg(Lang::get("FILE_SLASH"));
}
}
}
if (doSheet) {
/* SpriteSheet Array. */
if (this->storeJson["storeInfo"].contains("sheetURL") && this->storeJson["storeInfo"]["sheetURL"].is_array()) {
if (this->storeJson["storeInfo"].contains("sheet") && this->storeJson["storeInfo"]["sheet"].is_array()) {
const std::vector<std::string> locs = this->storeJson["storeInfo"]["sheetURL"].get<std::vector<std::string>>();
const std::vector<std::string> sht = this->storeJson["storeInfo"]["sheet"].get<std::vector<std::string>>();
if (locs.size() == sht.size()) {
for (int i = 0; i < (int)sht.size(); i++) {
if (!(sht[i].find("/") != std::string::npos)) {
char msg[150];
snprintf(msg, sizeof(msg), Lang::get("UPDATING_SPRITE_SHEET2").c_str(), i + 1, sht.size());
Msg::DisplayMsg(msg);
DownloadSpriteSheet(locs[i], sht[i]);
} else {
Msg::waitMsg(Lang::get("SHEET_SLASH"));
i++;
}
}
}
}
/* Single SpriteSheet (No array). */
} else if (this->storeJson["storeInfo"].contains("sheetURL") && this->storeJson["storeInfo"]["sheetURL"].is_string()) {
if (this->storeJson["storeInfo"].contains("sheet") && this->storeJson["storeInfo"]["sheet"].is_string()) {
const std::string fl = this->storeJson["storeInfo"]["sheetURL"];
const std::string fl2 = this->storeJson["storeInfo"]["sheet"];
if (!(fl2.find("/") != std::string::npos)) {
Msg::DisplayMsg(Lang::get("UPDATING_SPRITE_SHEET"));
DownloadSpriteSheet(fl, fl2);
} else {
Msg::waitMsg(Lang::get("SHEET_SLASH"));
}
}
}
}
}
this->LoadFromFile(file);
this->loadSheets();
}
}
}
/*
Unload all SpriteSheets on Destructor.
*/
Store::~Store() { this->unloadSheets(); };
/*
Unload all SpriteSheets.
*/
void Store::unloadSheets() {
if (this->valid) {
if (this->sheets.size() > 0) {
for (int i = 0; i < (int)this->sheets.size(); i++) {
if (this->sheets[i]) C2D_SpriteSheetFree(this->sheets[i]);
}
}
this->sheets.clear();
}
}
/*
Load all SpriteSheets.
*/
void Store::loadSheets() {
if (this->valid) {
if (this->storeJson["storeInfo"].contains("sheet")) {
this->unloadSheets();
std::vector<std::string> sheetLocs = { "" };
if (this->storeJson["storeInfo"]["sheet"].is_array()) {
sheetLocs = this->storeJson["storeInfo"]["sheet"].get<std::vector<std::string>>();
} else if (this->storeJson["storeInfo"]["sheet"].is_string()) {
sheetLocs[0] = this->storeJson["storeInfo"]["sheet"];
} else {
return;
}
for (int i = 0; i < (int)sheetLocs.size(); i++) {
this->sheets.push_back({ });
if (sheetLocs[i] != "") {
if (!(sheetLocs[i].find("/") != std::string::npos)) {
if (access((std::string(_STORE_PATH) + sheetLocs[i]).c_str(), F_OK) == 0) {
char msg[150];
snprintf(msg, sizeof(msg), Lang::get("LOADING_SPRITESHEET").c_str(), i + 1, sheetLocs.size());
Msg::DisplayMsg(msg);
this->sheets[i] = C2D_SpriteSheetLoad((std::string(_STORE_PATH) + sheetLocs[i]).c_str());
}
}
}
}
}
}
}
/*
Load a UniStore from a file.
const std::string &file: The file of the UniStore.
*/
void Store::LoadFromFile(const std::string &file) {
FILE *in = fopen(file.c_str(), "rt");
this->storeJson = nlohmann::json::parse(in, nullptr, false);
fclose(in);
/* Check, if valid. */
if (this->storeJson.contains("storeInfo") && this->storeJson.contains("storeContent")) {
if (this->storeJson["storeInfo"].contains("version") && this->storeJson["storeInfo"]["version"].is_number()) {
if (this->storeJson["storeInfo"]["version"] < 3) Msg::waitMsg(Lang::get("UNISTORE_TOO_OLD"));
else if (this->storeJson["storeInfo"]["version"] > 3) Msg::waitMsg(Lang::get("UNISTORE_TOO_NEW"));
this->valid = this->storeJson["storeInfo"]["version"] == 3;
}
} else {
Msg::waitMsg(Lang::get("UNISTORE_INVALID_ERROR"));
}
}
/*
Return the Title of the UniStore.
*/
std::string Store::GetUniStoreTitle() const {
if (this->valid) {
if (this->storeJson["storeInfo"].contains("title")) return this->storeJson["storeInfo"]["title"];
}
return "";
}
/*
Return the Title of an index.
const int &index: Const Reference to the index.
*/
std::string Store::GetTitleEntry(const int &index) const {
if (!this->valid) return "";
if (index > (int)this->storeJson["storeContent"].size() - 1) return ""; // Empty.
if (this->storeJson["storeContent"][index]["info"].contains("title") && this->storeJson["storeContent"][index]["info"]["title"].is_string()) {
return this->storeJson["storeContent"][index]["info"]["title"];
}
return "";
}
/*
Return the Author name of an index.
const int &index: Const Reference to the index.
*/
std::string Store::GetAuthorEntry(const int &index) const {
if (!this->valid) return "";
if (index > (int)this->storeJson["storeContent"].size() - 1) return ""; // Empty.
if (this->storeJson["storeContent"][index]["info"].contains("author") && this->storeJson["storeContent"][index]["info"]["author"].is_string()) {
return this->storeJson["storeContent"][index]["info"]["author"];
}
return "";
}
/*
Return the Description of an index.
const int &index: Const Reference to the index.
*/
std::string Store::GetDescriptionEntry(const int &index) const {
if (!this->valid) return "";
if (index > (int)this->storeJson["storeContent"].size() - 1) return ""; // Empty.
if (this->storeJson["storeContent"][index]["info"].contains("description") && this->storeJson["storeContent"][index]["info"]["description"].is_string()) {
return this->storeJson["storeContent"][index]["info"]["description"];
}
return "";
}
/*
Return the Category of an index.
const int &index: Const Reference to the index.
*/
std::vector<std::string> Store::GetCategoryIndex(const int &index) const {
if (!this->valid) return { "" };
if (index > (int)this->storeJson["storeContent"].size() - 1) return { "" }; // Empty.
if (this->storeJson["storeContent"][index]["info"].contains("category")) {
if (this->storeJson["storeContent"][index]["info"]["category"].is_array()) {
return this->storeJson["storeContent"][index]["info"]["category"].get<std::vector<std::string>>();
} else if (this->storeJson["storeContent"][index]["info"]["category"].is_string()) {
std::vector<std::string> temp;
temp.push_back( this->storeJson["storeContent"][index]["info"]["category"] );
return temp;
}
}
return { "" };
}
/*
Return the Version of an index.
const int &index: Const Reference to the index.
*/
std::string Store::GetVersionEntry(const int &index) const {
if (!this->valid) return "";
if (index > (int)this->storeJson["storeContent"].size() - 1) return ""; // Empty.
if (this->storeJson["storeContent"][index]["info"].contains("version") && this->storeJson["storeContent"][index]["info"]["version"].is_string()) {
return this->storeJson["storeContent"][index]["info"]["version"];
}
return "";
}
/*
Return the Console of an index.
const int &index: Const Reference to the index.
*/
std::vector<std::string> Store::GetConsoleEntry(const int &index) const {
if (!this->valid) return { "" };
if (index > (int)this->storeJson["storeContent"].size() - 1) return { "" }; // Empty.
if (this->storeJson["storeContent"][index]["info"].contains("console")) {
if (this->storeJson["storeContent"][index]["info"]["console"].is_array()) {
return this->storeJson["storeContent"][index]["info"]["console"].get<std::vector<std::string>>();
} else if (this->storeJson["storeContent"][index]["info"]["console"].is_string()) {
std::vector<std::string> temp;
temp.push_back( this->storeJson["storeContent"][index]["info"]["console"] );
return temp;
}
}
return { "" };
}
/*
Return the Last updated date of an index.
const int &index: Const Reference to the index.
*/
std::string Store::GetLastUpdatedEntry(const int &index) const {
if (!this->valid) return "";
if (index > (int)this->storeJson["storeContent"].size() - 1) return ""; // Empty.
if (this->storeJson["storeContent"][index]["info"].contains("last_updated") && this->storeJson["storeContent"][index]["info"]["last_updated"].is_string()) {
return this->storeJson["storeContent"][index]["info"]["last_updated"];
}
return "";
}
/*
Return the License of an index.
const int &index: Const Reference to the index.
*/
std::string Store::GetLicenseEntry(const int &index) const {
if (!this->valid) return Lang::get("NO_LICENSE");
if (index > (int)this->storeJson["storeContent"].size() - 1) return Lang::get("NO_LICENSE"); // Empty.
if (this->storeJson["storeContent"][index]["info"].contains("license") && this->storeJson["storeContent"][index]["info"]["license"].is_string()) {
if (this->storeJson["storeContent"][index]["info"]["license"] == "") return Lang::get("NO_LICENSE");
return this->storeJson["storeContent"][index]["info"]["license"];
}
return Lang::get("NO_LICENSE");
}
/*
Return a C2D_Image of an index.
const int &index: Const Reference to the index.
*/
C2D_Image Store::GetIconEntry(const int &index) const {
if (!this->valid) return C2D_SpriteSheetGetImage(sprites, sprites_noIcon_idx);
int iconIndex = -1, sheetIndex = 0;
if (index > (int)this->storeJson["storeContent"].size() - 1) return C2D_SpriteSheetGetImage(sprites, sprites_noIcon_idx);
if (this->storeJson["storeContent"][index]["info"].contains("icon_index") && this->storeJson["storeContent"][index]["info"]["icon_index"].is_number()) {
iconIndex = this->storeJson["storeContent"][index]["info"]["icon_index"];
}
if (this->storeJson["storeContent"][index]["info"].contains("sheet_index") && this->storeJson["storeContent"][index]["info"]["sheet_index"].is_number()) {
sheetIndex = this->storeJson["storeContent"][index]["info"]["sheet_index"];
}
if (iconIndex == -1) return C2D_SpriteSheetGetImage(sprites, sprites_noIcon_idx);
if (sheetIndex > (int)this->sheets.size()) return C2D_SpriteSheetGetImage(sprites, sprites_noIcon_idx);
if (!this->sheets[sheetIndex]) return C2D_SpriteSheetGetImage(sprites, sprites_noIcon_idx);
if (iconIndex > (int)C2D_SpriteSheetCount(this->sheets[sheetIndex])-1) return C2D_SpriteSheetGetImage(sprites, sprites_noIcon_idx);
C2D_Image temp = C2D_SpriteSheetGetImage(this->sheets[sheetIndex], iconIndex);
if (temp.subtex->width < 49 && temp.subtex->height < 49) return temp; // up to 48x48 is valid.
return C2D_SpriteSheetGetImage(sprites, sprites_noIcon_idx);
}
/*
Return the download list of an entry.
const int &index: Const Reference to the index.
*/
std::vector<std::string> Store::GetDownloadList(const int &index) const {
if (!this->valid) return { "" };
std::vector<std::string> temp;
if (index > (int)this->storeJson["storeContent"].size() - 1) return temp;
for(auto it = this->storeJson.at("storeContent").at(index).begin(); it != this->storeJson.at("storeContent").at(index).end(); it++) {
if (it.key() != "info") temp.push_back(it.key());
}
return temp;
}
+58
View File
@@ -0,0 +1,58 @@
/*
* This file is part of Universal-Updater
* Copyright (C) 2019-2020 Universal-Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "storeEntry.hpp"
/*
Fetch informations on constructor.
const std::unique_ptr<Store> &store: Const Reference to the Store class.
const std::unique_ptr<Meta> &meta: Const Reference to the Meta class.
const int &index: Const Reference Index of the entry.
*/
StoreEntry::StoreEntry(const std::unique_ptr<Store> &store, const std::unique_ptr<Meta> &meta, const int &index) {
this->Title = store->GetTitleEntry(index);
this->Author = store->GetAuthorEntry(index);
this->Description = store->GetDescriptionEntry(index);
this->Category = StringUtils::FetchStringsFromVector(store->GetCategoryIndex(index));
this->Version = store->GetVersionEntry(index);
this->Console = StringUtils::FetchStringsFromVector(store->GetConsoleEntry(index));
this->LastUpdated = store->GetLastUpdatedEntry(index);
this->License = store->GetLicenseEntry(index);
this->MarkString = StringUtils::GetMarkString(meta->GetMarks(store->GetUniStoreTitle(), this->Title));
this->Icon = store->GetIconEntry(index);
this->SheetIndex = 0;
this->EntryIndex = index;
this->FullCategory = store->GetCategoryIndex(index);
this->FullConsole = store->GetConsoleEntry(index);
this->UpdateAvailable = meta->UpdateAvailable(store->GetUniStoreTitle(), this->Title, store->GetLastUpdatedEntry(index));
this->Marks = meta->GetMarks(store->GetUniStoreTitle(), this->Title);
}
+178
View File
@@ -0,0 +1,178 @@
/*
* This file is part of Universal-Updater
* Copyright (C) 2019-2020 Universal-Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "storeUtils.hpp"
/*
Compare Title.
const std::unique_ptr<StoreEntry> &a: Const Reference to Entry A.
const std::unique_ptr<StoreEntry> &b: Const Reference to Entry B.
*/
bool StoreUtils::compareTitleDescending(const std::unique_ptr<StoreEntry> &a, const std::unique_ptr<StoreEntry> &b) {
if (a && b) return strcasecmp(StringUtils::lower_case(a->GetTitle()).c_str(), StringUtils::lower_case(b->GetTitle()).c_str()) > 0;
return true;
}
bool StoreUtils::compareTitleAscending(const std::unique_ptr<StoreEntry> &a, const std::unique_ptr<StoreEntry> &b) {
if (a && b) return strcasecmp(StringUtils::lower_case(b->GetTitle()).c_str(), StringUtils::lower_case(a->GetTitle()).c_str()) > 0;
return true;
}
/*
Compare Author.
const std::unique_ptr<StoreEntry> &a: Const Reference to Entry A.
const std::unique_ptr<StoreEntry> &b: Const Reference to Entry B.
*/
bool StoreUtils::compareAuthorDescending(const std::unique_ptr<StoreEntry> &a, const std::unique_ptr<StoreEntry> &b) {
if (a && b) return strcasecmp(StringUtils::lower_case(a->GetAuthor()).c_str(), StringUtils::lower_case(b->GetAuthor()).c_str()) > 0;
return true;
}
bool StoreUtils::compareAuthorAscending(const std::unique_ptr<StoreEntry> &a, const std::unique_ptr<StoreEntry> &b) {
if (a && b) return strcasecmp(StringUtils::lower_case(b->GetAuthor()).c_str(), StringUtils::lower_case(a->GetAuthor()).c_str()) > 0;
return true;
}
/*
Compare Last Updated.
const std::unique_ptr<StoreEntry> &a: Const Reference to Entry A.
const std::unique_ptr<StoreEntry> &b: Const Reference to Entry B.
*/
bool StoreUtils::compareUpdateDescending(const std::unique_ptr<StoreEntry> &a, const std::unique_ptr<StoreEntry> &b) {
if (a && b) return strcasecmp(StringUtils::lower_case(a->GetLastUpdated()).c_str(), StringUtils::lower_case(b->GetLastUpdated()).c_str()) > 0;
return true;
}
bool StoreUtils::compareUpdateAscending(const std::unique_ptr<StoreEntry> &a, const std::unique_ptr<StoreEntry> &b) {
if (a && b) return strcasecmp(StringUtils::lower_case(b->GetLastUpdated()).c_str(), StringUtils::lower_case(a->GetLastUpdated()).c_str()) > 0;
return true;
}
/*
Sort the entries.
const bool &Ascending: Const Reference to Ascending.
const SortType &sorttype: Const Reference to the sort type.
std::vector<std::unique_ptr<StoreEntry>> &entries: Reference to the Entries, which should be sorted.
*/
void StoreUtils::SortEntries(const bool &Ascending, const SortType &sorttype, std::vector<std::unique_ptr<StoreEntry>> &entries) {
switch(sorttype) {
case SortType::TITLE:
Ascending ? std::sort(entries.begin(), entries.end(), StoreUtils::compareTitleAscending) : std::sort(entries.begin(), entries.end(), StoreUtils::compareTitleDescending);
break;
case SortType::AUTHOR:
Ascending ? std::sort(entries.begin(), entries.end(), StoreUtils::compareAuthorAscending) : std::sort(entries.begin(), entries.end(), StoreUtils::compareAuthorDescending);
break;
case SortType::LAST_UPDATED:
Ascending ? std::sort(entries.begin(), entries.end(), StoreUtils::compareUpdateAscending) : std::sort(entries.begin(), entries.end(), StoreUtils::compareUpdateDescending);
break;
}
}
/*
Find a query from a vector.
const std::vector<std::string> &items: Const Reference to the vector strings / items.
const std::string &query: Const Reference to the query.
*/
static bool findInVector(const std::vector<std::string> &items, const std::string &query) {
for(const std::string &item : items) {
if (StringUtils::lower_case(item).find(query) != std::string::npos) return true;
}
return false;
}
/*
Search for stuff of the store.
std::vector<std::unique_ptr<StoreEntry>> &entries: Reference to the entries.
const std::string &query: Const Reference to the query.
bool title: if titles should be included.
bool author: if authors should be included.
bool category: if categories should be included.
bool console: if consoles should be included.
int selectedMarks: The selected mark flags.
bool updateAvl: if available updates should be an included flag
*/
void StoreUtils::search(std::vector<std::unique_ptr<StoreEntry>> &entries, const std::string &query, bool title, bool author, bool category, bool console, int selectedMarks, bool updateAvl) {
for (auto it = entries.begin(); it != entries.end(); ++it) {
if (!(((title && StringUtils::lower_case((*it)->GetTitle()).find(StringUtils::lower_case(query)) != std::string::npos)
|| (author && StringUtils::lower_case((*it)->GetAuthor()).find(StringUtils::lower_case(query)) != std::string::npos)
|| (category && findInVector((*it)->GetCategoryFull(), StringUtils::lower_case(query)))
|| (console && findInVector((*it)->GetConsoleFull(), StringUtils::lower_case(query)))
|| (!title && !author && !category && !console))
&& ((selectedMarks == 0 && !updateAvl) || (*it)->GetMarks() & selectedMarks || (updateAvl && (*it)->GetUpdateAvl())))) {
entries.erase(it);
--it;
}
}
}
/*
Filter for available updates.
std::vector<std::unique_ptr<StoreEntry>> &entries: Reference to the entries.
*/
void StoreUtils::FilterUpdateAvailable(std::vector<std::unique_ptr<StoreEntry>> &entries) {
for (auto it = entries.begin(); it != entries.end(); ++it) {
if (!((*it)->GetUpdateAvl())) {
entries.erase(it);
--it;
}
}
}
/*
Reset everything of the store and clear + fetch the Entries again.
const std::unique_ptr<Store> &store: Const Reference to the Store class.
const std::unique_ptr<Meta> &meta: Const Reference to the Meta class.
std::vector<std::unique_ptr<StoreEntry>> &entries: Reference to the entries.
*/
void StoreUtils::ResetAll(const std::unique_ptr<Store> &store, const std::unique_ptr<Meta> &meta, std::vector<std::unique_ptr<StoreEntry>> &entries) {
if (store) {
entries.clear();
if (store->GetValid()) {
for (int i = 0; i < store->GetStoreSize(); i++) {
entries.push_back( std::make_unique<StoreEntry>(store, meta, i) );
}
store->SetBox(0);
store->SetEntry(0);
store->SetScreenIndx(0);
}
}
}
@@ -24,24 +24,16 @@
* reasonable ways as different from the original version.
*/
#include "colorHelper.hpp"
#include "animation.hpp"
#include "common.hpp"
int ColorHelper::getColorValue(int color, int bgr) {
char colorName[10];
int i;
std::stringstream ss;
/*
Draw the progressbar.
itoa(color, colorName, 16);
std::string colorNamePart(colorName, 2*bgr+2, 2);
ss << std::hex << colorNamePart.c_str();
ss >> i;
return i;
}
std::string ColorHelper::getColorName(int color, int bgr) {
char colorName[10];
int i = getColorValue(color, bgr);
itoa(i, colorName, 10);
return colorName;
const u64 &currentProgress: Const Reference to the current progress.
const u64 &totalProgress: Const Reference to the total progress.
*/
void Animation::DrawProgressBar(const u64 &currentProgress, const u64 &totalProgress) {
Gui::Draw_Rect(30, 120, 340, 30, PROGRESSBAR_OUT_COLOR);
Gui::Draw_Rect(31, 121, (int)(((float)currentProgress / (float)totalProgress) * 338.0f), 28, PROGRESSBAR_IN_COLOR);
}
+42 -14
View File
@@ -1,6 +1,33 @@
#include "cia.hpp"
/*
* This file is part of Universal-Updater
* Copyright (C) 2019-2020 Universal-Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
Result CIA_LaunchTitle(u64 titleId, FS_MediaType mediaType) {
#include "cia.hpp"
#include "files.hpp"
Result CIA_LaunchTitle(const u64 &titleId, const FS_MediaType &mediaType) {
Result ret = 0;
u8 param[0x300];
u8 hmac[0x20];
@@ -9,6 +36,7 @@ Result CIA_LaunchTitle(u64 titleId, FS_MediaType mediaType) {
printf("Error In:\nAPT_PrepareToDoApplicationJump");
return ret;
}
if (R_FAILED(ret = APT_DoApplicationJump(param, sizeof(param), hmac))) {
printf("Error In:\nAPT_DoApplicationJump");
return ret;
@@ -17,10 +45,10 @@ Result CIA_LaunchTitle(u64 titleId, FS_MediaType mediaType) {
return 0;
}
Result deletePrevious(u64 titleid, FS_MediaType media) {
Result deletePrevious(const u64 &titleid, const FS_MediaType &media) {
Result ret = 0;
u32 titles_amount = 0;
ret = AM_GetTitleCount(media, &titles_amount);
if (R_FAILED(ret)) {
printf("Error in:\nAM_GetTitleCount\n");
@@ -28,7 +56,8 @@ Result deletePrevious(u64 titleid, FS_MediaType media) {
}
u32 read_titles = 0;
u64 * titleIDs = (u64*)malloc(titles_amount * sizeof(u64));
u64 *titleIDs = (u64 *)malloc(titles_amount * sizeof(u64));
ret = AM_GetTitleList(&read_titles, media, titles_amount, titleIDs);
if (R_FAILED(ret)) {
free(titleIDs);
@@ -44,6 +73,7 @@ Result deletePrevious(u64 titleid, FS_MediaType media) {
}
free(titleIDs);
if (R_FAILED(ret)) {
printf("Error in:\nAM_DeleteAppTitle\n");
return ret;
@@ -52,7 +82,7 @@ Result deletePrevious(u64 titleid, FS_MediaType media) {
return 0;
}
FS_MediaType getTitleDestination(u64 titleId) {
FS_MediaType getTitleDestination(const u64 &titleId) {
u16 platform = (u16) ((titleId >> 48) & 0xFFFF);
u16 category = (u16) ((titleId >> 32) & 0xFFFF);
u8 variation = (u8) (titleId & 0xFF);
@@ -61,10 +91,9 @@ FS_MediaType getTitleDestination(u64 titleId) {
return platform == 0x0003 || (platform == 0x0004 && ((category & 0x8011) != 0 || (category == 0x0000 && variation == 0x02))) ? MEDIATYPE_NAND : MEDIATYPE_SD;
}
// Variables.
u64 installSize = 0, installOffset = 0;
Result installCia(const char * ciaPath, bool updatingSelf) {
Result installCia(const char *ciaPath, const bool &updatingSelf) {
u32 bytes_read = 0, bytes_written;
installSize = 0, installOffset = 0; u64 size = 0;
Handle ciaHandle, fileHandle;
@@ -88,8 +117,7 @@ Result installCia(const char * ciaPath, bool updatingSelf) {
if (!updatingSelf) {
ret = deletePrevious(info.titleID, media);
if (R_FAILED(ret))
return ret;
if (R_FAILED(ret)) return ret;
}
ret = FSFILE_GetSize(fileHandle, &size);
@@ -97,6 +125,7 @@ Result installCia(const char * ciaPath, bool updatingSelf) {
printf("Error in:\nFSFILE_GetSize\n");
return ret;
}
ret = AM_StartCiaInstall(media, &ciaHandle);
if (R_FAILED(ret)) {
printf("Error in:\nAM_StartCiaInstall\n");
@@ -105,9 +134,8 @@ Result installCia(const char * ciaPath, bool updatingSelf) {
u32 toRead = 0x200000;
u8 *buf = new u8[toRead];
if(buf == nullptr) {
return -1;
}
if (!buf) return -1;
installSize = size;
do {
@@ -130,7 +158,7 @@ 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;
+173 -427
View File
@@ -1,427 +1,173 @@
/*
* This file is part of Universal-Updater
* Copyright (C) 2019-2020 Universal-Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "colorHelper.hpp"
#include "common.hpp"
#include "config.hpp"
#include <citro2d.h>
#include <unistd.h>
// Used to add missing stuff for the JSON.
void Config::addMissingThings() {
if (this->json["VERSION"] < 2) {
this->setString("3DSX_PATH", _3DSX_PATH);
this->setString("NDS_PATH", _NDS_PATH);
this->setString("ARCHIVE_PATH", ARCHIVES_DEFAULT);
this->setBool("CITRA", false);
}
}
//Detects system language and is used later to set app language to system language
void Config::sysLang() {
u8 language = 0;
CFGU_GetSystemLanguage(&language);
switch(language) {
case 0:
this->language("jp");
break;
case 1:
this->language("en");
break;
case 2:
this->language("fr");
break;
case 3:
this->language("de");
break;
case 4:
this->language("it");
break;
case 5:
this->language("es");
break;
case 6:
this->language("en"); //Simplified chinese, not translated
break;
case 7:
this->language("en"); //Korean, not translated
break;
case 8:
this->language("nl");
break;
case 9:
this->language("pt");
break;
case 10:
this->language("ru");
break;
case 11:
this->language("en"); //traditional chinese, not translated
break;
}
}
// In case it doesn't exist.
void Config::initialize() {
// Create through fopen "Write".
FILE *file = fopen("sdmc:/3ds/Universal-Updater/Settings.json", "w");
// Set default values.
this->setInt("BARCOLOR", BarColor);
this->setInt("TOPBGCOLOR", TopBGColor);
this->setInt("BOTTOMBGCOLOR", BottomBGColor);
this->setInt("TEXTCOLOR", WHITE);
this->setInt("BUTTON", C2D_Color32(0, 0, 50, 255));
this->setInt("SELECTEDCOLOR", SelectedColordefault);
this->setInt("UNSELECTEDCOLOR", UnselectedColordefault);
this->setString("SCRIPTPATH", SCRIPTS_PATH);
this->setInt("LANGPATH", 0);
this->setInt("VIEWMODE", 0);
this->setInt("PROGRESSBARCOLOR", WHITE);
this->setString("MUSICPATH", MUSIC_PATH);
this->setBool("LOGGING", false);
this->setBool("BARS", true);
this->setInt("AUTOBOOT", 0);
this->setString("STOREPATH", STORE_PATH);
this->setString("AUTOBOOT_FILE", "");
this->setInt("OUTDATED", C2D_Color32(0xfb, 0x5b, 0x5b, 255));
this->setInt("UPTODATE", C2D_Color32(0xa5, 0xdd, 0x81, 255));
this->setInt("NOTFOUND", C2D_Color32(255, 128, 0, 255));
this->setInt("FUTURE", C2D_Color32(255, 255, 0, 255));
this->setInt("KEY_DELAY", 5);
this->setBool("SCREEN_FADE", false);
this->setBool("PROGRESS_DISPLAY", true);
this->sysLang();
this->setBool("FIRST_STARTUP", true);
this->setBool("USE_SCRIPT_COLORS", true);
this->setBool("SHOW_SPEED", false);
this->setString("3DSX_PATH", _3DSX_PATH);
this->setString("NDS_PATH", _NDS_PATH);
this->setString("ARCHIVE_PATH", ARCHIVES_DEFAULT);
this->setBool("CITRA", false);
this->setInt("VERSION", this->configVersion);
// Write to file.
const std::string dump = this->json.dump(1, '\t');
fwrite(dump.c_str(), 1, this->json.dump(1, '\t').size(), file);
fclose(file); // Now we have the file and can properly access it.
}
Config::Config() {
if (access("sdmc:/3ds/Universal-Updater/Settings.json", F_OK) != 0 ) {
this->initialize();
}
FILE* file = fopen("sdmc:/3ds/Universal-Updater/Settings.json", "r");
this->json = nlohmann::json::parse(file, nullptr, false);
fclose(file);
if (!this->json.contains("VERSION")) {
// Let us create a new one.
this->initialize();
}
// Here we add the missing things.
if (this->json["VERSION"] < this->configVersion) {
this->addMissingThings();
}
if (!this->json.contains("BARCOLOR")) {
this->barColor(BarColor);
} else {
this->barColor(this->getInt("BARCOLOR"));
}
if (!this->json.contains("TOPBGCOLOR")) {
this->topBG(TopBGColor);
} else {
this->topBG(this->getInt("TOPBGCOLOR"));
}
if (!this->json.contains("BOTTOMBGCOLOR")) {
this->bottomBG(BottomBGColor);
} else {
this->bottomBG(this->getInt("BOTTOMBGCOLOR"));
}
if (!this->json.contains("TEXTCOLOR")) {
this->textColor(WHITE);
} else {
this->textColor(this->getInt("TEXTCOLOR"));
}
if (!this->json.contains("BUTTON")) {
this->buttonColor(C2D_Color32(0, 0, 50, 255));
} else {
this->buttonColor(this->getInt("BUTTON"));
}
if (!this->json.contains("SELECTEDCOLOR")) {
this->selectedColor(SelectedColordefault);
} else {
this->selectedColor(this->getInt("SELECTEDCOLOR"));
}
if (!this->json.contains("UNSELECTEDCOLOR")) {
this->unselectedColor(UnselectedColordefault);
} else {
this->unselectedColor(this->getInt("UNSELECTEDCOLOR"));
}
if (!this->json.contains("SCRIPTPATH")) {
this->scriptPath(SCRIPTS_PATH);
} else {
this->scriptPath(this->getString("SCRIPTPATH"));
}
if (!this->json.contains("LANGPATH")) {
this->langPath(0);
} else {
this->langPath(this->getInt("LANGPATH"));
}
if (!this->json.contains("VIEWMODE")) {
this->viewMode(0);
} else {
this->viewMode(this->getInt("VIEWMODE"));
}
if (!this->json.contains("PROGRESSBARCOLOR")) {
this->progressbarColor(WHITE);
} else {
this->progressbarColor(this->getInt("PROGRESSBARCOLOR"));
}
if (!this->json.contains("MUSICPATH")) {
this->musicPath(MUSIC_PATH);
} else {
this->musicPath(this->getString("MUSICPATH"));
}
if (!this->json.contains("LOGGING")) {
this->logging(false);
} else {
this->logging(this->getBool("LOGGING"));
}
if (!this->json.contains("BARS")) {
this->useBars(true);
} else {
this->useBars(this->getBool("BARS"));
}
if (!this->json.contains("AUTOBOOT")) {
this->autoboot(0);
} else {
this->autoboot(this->getInt("AUTOBOOT"));
}
if (!this->json.contains("STOREPATH")) {
this->storePath(STORE_PATH);
} else {
this->storePath(this->getString("STOREPATH"));
}
if (!this->json.contains("AUTOBOOT_FILE")) {
this->autobootFile("");
} else {
this->autobootFile(this->getString("AUTOBOOT_FILE"));
}
if (!this->json.contains("OUTDATED")) {
this->outdatedColor(C2D_Color32(0xfb, 0x5b, 0x5b, 255));
} else {
this->outdatedColor(this->getInt("OUTDATED"));
}
if (!this->json.contains("UPTODATE")) {
this->uptodateColor(C2D_Color32(0xa5, 0xdd, 0x81, 255));
} else {
this->uptodateColor(this->getInt("UPTODATE"));
}
if (!this->json.contains("NOTFOUND")) {
this->notfoundColor(C2D_Color32(255, 128, 0, 255));
} else {
this->notfoundColor(this->getInt("NOTFOUND"));
}
if (!this->json.contains("FUTURE")) {
this->futureColor(C2D_Color32(255, 255, 0, 255));
} else {
this->futureColor(this->getInt("FUTURE"));
}
if (!this->json.contains("KEY_DELAY")) {
this->keyDelay(5);
} else {
this->keyDelay(this->getInt("KEY_DELAY"));
}
if (!this->json.contains("SCREEN_FADE")) {
this->screenFade(false);
} else {
this->screenFade(this->getBool("SCREEN_FADE"));
}
if (!this->json.contains("PROGRESS_DISPLAY")) {
this->progressDisplay(true);
} else {
this->progressDisplay(this->getBool("PROGRESS_DISPLAY"));
}
if (!this->json.contains("LANGUAGE") || this->json.at("LANGUAGE").is_number()) {
this->sysLang();
this->initialChanges = true;
} else {
this->language(this->getString("LANGUAGE"));
}
if (!this->json.contains("FIRST_STARTUP")) {
this->firstStartup(true);
} else {
this->firstStartup(this->getBool("FIRST_STARTUP"));
}
if (!this->json.contains("USE_SCRIPT_COLORS")) {
this->useScriptColor(true);
} else {
this->useScriptColor(this->getBool("USE_SCRIPT_COLORS"));
}
if (!this->json.contains("SHOW_SPEED")) {
this->showSpeed(false);
} else {
this->showSpeed(this->getBool("SHOW_SPEED"));
}
if (!this->json.contains("3DSX_PATH")) {
this->_3dsxpath(_3DSX_PATH);
} else {
this->_3dsxpath(this->getString("3DSX_PATH"));
}
if (!this->json.contains("NDS_PATH")) {
this->ndspath(_NDS_PATH);
} else {
this->ndspath(this->getString("NDS_PATH"));
}
if (!this->json.contains("ARCHIVE_PATH")) {
this->archivepath(ARCHIVES_DEFAULT);
} else {
this->archivepath(this->getString("ARCHIVE_PATH"));
}
if (!this->json.contains("CITRA")) {
this->citra(false);
} else {
this->citra(this->getBool("CITRA"));
}
this->changesMade = false; // No changes made yet.
}
// Write to config if changesMade.
void Config::save() {
if (this->changesMade) {
this->changesMade = false;
FILE *file = fopen("sdmc:/3ds/Universal-Updater/Settings.json", "w");
// Set values.
this->setInt("BARCOLOR", this->barColor());
this->setInt("TOPBGCOLOR", this->topBG());
this->setInt("BOTTOMBGCOLOR", this->bottomBG());
this->setInt("TEXTCOLOR", this->textColor());
this->setInt("BUTTON", this->buttonColor());
this->setInt("SELECTEDCOLOR", this->selectedColor());
this->setInt("UNSELECTEDCOLOR", this->unselectedColor());
this->setString("SCRIPTPATH", this->scriptPath());
this->setInt("LANGPATH", this->langPath());
this->setInt("VIEWMODE", this->viewMode());
this->setInt("PROGRESSBARCOLOR", this->progressbarColor());
this->setString("MUSICPATH", this->musicPath());
this->setBool("LOGGING", this->logging());
this->setBool("BARS", this->useBars());
this->setInt("AUTOBOOT", this->autoboot());
this->setString("STOREPATH", this->storePath());
this->setString("AUTOBOOT_FILE", this->autobootFile());
this->setInt("OUTDATED", this->outdatedColor());
this->setInt("UPTODATE", this->uptodateColor());
this->setInt("NOTFOUND", this->notfoundColor());
this->setInt("FUTURE", this->futureColor());
this->setInt("KEY_DELAY", this->keyDelay());
this->setBool("SCREEN_FADE", this->screenFade());
this->setBool("PROGRESS_DISPLAY", this->progressDisplay());
this->setString("LANGUAGE", this->language());
this->setBool("FIRST_STARTUP", this->firstStartup());
this->setBool("USE_SCRIPT_COLORS", this->useScriptColor());
this->setBool("SHOW_SPEED", this->showSpeed());
this->setString("3DSX_PATH", this->_3dsxpath());
this->setString("NDS_PATH", this->ndspath());
this->setString("ARCHIVE_PATH", this->archivepath());
this->setBool("CITRA", this->citra());
// Write changes to file.
const std::string dump = this->json.dump(1, '\t');
fwrite(dump.c_str(), 1, this->json.dump(1, '\t').size(), file);
fclose(file);
}
}
// Helper functions.
bool Config::getBool(const std::string &key) {
if (!this->json.contains(key)) {
return false;
}
return this->json.at(key).get_ref<const bool&>();
}
void Config::setBool(const std::string &key, bool v) {
this->json[key] = v;
}
int Config::getInt(const std::string &key) {
if (!this->json.contains(key)) {
return 0;
}
return this->json.at(key).get_ref<const int64_t&>();
}
void Config::setInt(const std::string &key, int v) {
this->json[key] = v;
}
std::string Config::getString(const std::string &key) {
if (!this->json.contains(key)) {
return "";
}
return this->json.at(key).get_ref<const std::string&>();
}
void Config::setString(const std::string &key, const std::string &v) {
this->json[key] = v;
}
/*
* This file is part of Universal-Updater
* Copyright (C) 2019-2020 Universal-Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "common.hpp"
#include "config.hpp"
#include "json.hpp"
#include <string>
#include <unistd.h>
/*
Detects system language and is used later to set app language to system language.
*/
void Config::sysLang() {
u8 language = 0;
CFGU_GetSystemLanguage(&language);
switch(language) {
case 0:
this->language("jp");
break;
case 1:
this->language("en");
break;
case 2:
this->language("fr");
break;
case 3:
this->language("de");
break;
case 4:
this->language("it");
break;
case 5:
this->language("es");
break;
case 6:
this->language("en"); // Simplified chinese, not translated.
break;
case 7:
this->language("en"); // Korean, not translated.
break;
case 8:
this->language("nl");
break;
case 9:
this->language("pt");
break;
case 10:
this->language("ru");
break;
case 11:
this->language("en"); // traditional chinese, not translated.
break;
}
}
/*
In case it doesn't exist.
*/
void Config::initialize() {
FILE *temp = fopen("sdmc:/3ds/Universal-Updater/Config.json", "w");
char tmp[2] = { '{', '}' };
fwrite(tmp, sizeof(tmp), 1, temp);
fclose(temp);
}
/*
Constructor of the config.
*/
Config::Config() {
if (access("sdmc:/3ds/Universal-Updater/Config.json", F_OK) != 0) {
this->initialize();
}
FILE *file = fopen("sdmc:/3ds/Universal-Updater/Config.json", "r");
this->json = nlohmann::json::parse(file, nullptr, false);
fclose(file);
/* Let us create a new one. */
if (!this->json.contains("Version")) this->initialize();
if (!this->json.contains("Language")) this->sysLang();
else this->language(this->getString("Language"));
if (this->json.contains("LastStore")) this->lastStore(this->getString("LastStore"));
if (this->json.contains("List")) this->list(this->getBool("List"));
if (this->json.contains("AutoUpdate")) this->autoupdate(this->getBool("AutoUpdate"));
if (this->json.contains("_3DSX_Path")) this->_3dsxPath(this->getString("_3DSX_Path"));
if (this->json.contains("NDS_Path")) this->ndsPath(this->getString("NDS_Path"));
if (this->json.contains("Archive_Path")) this->archPath(this->getString("Archive_Path"));
if (this->json.contains("MetaData")) this->metadata(this->getBool("MetaData"));
if (this->json.contains("UpdateCheck")) this->updatecheck(this->getBool("UpdateCheck"));
this->changesMade = false; // No changes made yet.
}
/* Write to config if changesMade. */
void Config::save() {
if (this->changesMade) {
FILE *file = fopen("sdmc:/3ds/Universal-Updater/Config.json", "w");
/* Set values. */
this->setString("Language", this->language());
this->setInt("Version", 1);
this->setString("LastStore", this->lastStore());
this->setBool("List", this->list());
this->setBool("AutoUpdate", this->autoupdate());
this->setString("_3DSX_Path", this->_3dsxPath());
this->setString("NDS_Path", this->ndsPath());
this->setString("Archive_Path", this->archPath());
this->setBool("MetaData", this->metadata());
this->setBool("UpdateCheck", this->updatecheck());
/* Write changes to file. */
const std::string dump = this->json.dump(1, '\t');
fwrite(dump.c_str(), 1, this->json.dump(1, '\t').size(), file);
fclose(file);
}
}
/* Helper functions. */
bool Config::getBool(const std::string &key) {
if (!this->json.contains(key)) return false;
return this->json.at(key).get_ref<const bool&>();
}
void Config::setBool(const std::string &key, bool v) { this->json[key] = v; };
int Config::getInt(const std::string &key) {
if (!this->json.contains(key)) return 0;
return this->json.at(key).get_ref<const int64_t&>();
}
void Config::setInt(const std::string &key, int v) { this->json[key] = v; };
std::string Config::getString(const std::string &key) {
if (!this->json.contains(key)) return "";
return this->json.at(key).get_ref<const std::string&>();
}
void Config::setString(const std::string &key, const std::string &v) { this->json[key] = v; };
+899
View File
@@ -0,0 +1,899 @@
/*
* This file is part of Universal-Updater
* Copyright (C) 2019-2020 Universal-Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "animation.hpp"
#include "download.hpp"
#include "files.hpp"
#include "json.hpp"
#include "lang.hpp"
#include "scriptUtils.hpp"
#include "stringutils.hpp"
#include <3ds.h>
#include <curl/curl.h>
#include <dirent.h>
#include <malloc.h>
#include <regex>
#include <string>
#include <vector>
#define USER_AGENT APP_TITLE "-" VERSION_STRING
static char *result_buf = nullptr;
static size_t result_sz = 0;
static size_t result_written = 0;
std::vector<std::string> _topText;
std::string jsonName;
#define TIME_IN_US 1
#define TIMETYPE curl_off_t
#define TIMEOPT CURLINFO_TOTAL_TIME_T
#define MINIMAL_PROGRESS_FUNCTIONALITY_INTERVAL 3000000
curl_off_t downloadTotal = 1; // Dont initialize with 0 to avoid division by zero later.
curl_off_t downloadNow = 0;
static FILE *downfile = nullptr;
static size_t file_buffer_pos = 0;
static size_t file_toCommit_size = 0;
static char *g_buffers[2] = { nullptr };
static u8 g_index = 0;
static Thread fsCommitThread;
static LightEvent readyToCommit;
static LightEvent waitCommit;
static bool killThread = false;
static bool writeError = false;
#define FILE_ALLOC_SIZE 0x60000
extern int filesExtracted;
extern std::string extractingFile;
char progressBarMsg[128] = "";
bool showProgressBar = false;
ProgressBar progressbarType = ProgressBar::Downloading;
extern u64 extractSize, writeOffset;
extern u64 installSize, installOffset;
static int curlProgress(CURL *hnd,
curl_off_t dltotal, curl_off_t dlnow,
curl_off_t ultotal, curl_off_t ulnow)
{
downloadTotal = dltotal;
downloadNow = dlnow;
return 0;
}
bool filecommit() {
if (!downfile) return false;
fseek(downfile, 0, SEEK_END);
u32 byteswritten = fwrite(g_buffers[!g_index], 1, file_toCommit_size, downfile);
if (byteswritten != file_toCommit_size) return false;
file_toCommit_size = 0;
return true;
}
static void commitToFileThreadFunc(void *args) {
LightEvent_Signal(&waitCommit);
while (true) {
LightEvent_Wait(&readyToCommit);
LightEvent_Clear(&readyToCommit);
if (killThread) threadExit(0);
writeError = !filecommit();
LightEvent_Signal(&waitCommit);
}
}
static size_t file_handle_data(char *ptr, size_t size, size_t nmemb, void *userdata) {
(void)userdata;
const size_t bsz = size * nmemb;
size_t tofill = 0;
if (writeError) return 0;
if (!g_buffers[g_index]) {
LightEvent_Init(&waitCommit, RESET_STICKY);
LightEvent_Init(&readyToCommit, RESET_STICKY);
s32 prio = 0;
svcGetThreadPriority(&prio, CUR_THREAD_HANDLE);
fsCommitThread = threadCreate(commitToFileThreadFunc, NULL, 0x1000, prio - 1, -2, true);
g_buffers[0] = (char*)memalign(0x1000, FILE_ALLOC_SIZE);
g_buffers[1] = (char*)memalign(0x1000, FILE_ALLOC_SIZE);
if (!fsCommitThread || !g_buffers[0] || !g_buffers[1]) return 0;
}
if (file_buffer_pos + bsz >= FILE_ALLOC_SIZE) {
tofill = FILE_ALLOC_SIZE - file_buffer_pos;
memcpy(g_buffers[g_index] + file_buffer_pos, ptr, tofill);
LightEvent_Wait(&waitCommit);
LightEvent_Clear(&waitCommit);
file_toCommit_size = file_buffer_pos + tofill;
file_buffer_pos = 0;
svcFlushProcessDataCache(CUR_PROCESS_HANDLE, (u32)g_buffers[g_index], file_toCommit_size);
g_index = !g_index;
LightEvent_Signal(&readyToCommit);
}
memcpy(g_buffers[g_index] + file_buffer_pos, ptr + tofill, bsz - tofill);
file_buffer_pos += bsz - tofill;
return bsz;
}
Result downloadToFile(const std::string &url, const std::string &path) {
downloadTotal = 1;
downloadNow = 0;
CURLcode curlResult;
CURL *hnd;
Result retcode = 0;
downloadTotal = 1;
int res;
printf("Downloading from:\n%s\nto:\n%s\n", url.c_str(), path.c_str());
const char *filepath = path.c_str();
void *socubuf = memalign(0x1000, 0x100000);
if (!socubuf) {
retcode = -1;
goto exit;
}
res = socInit((u32 *)socubuf, 0x100000);
if (R_FAILED(res)) {
retcode = res;
goto exit;
}
makeDirs(strdup(filepath));
downfile = fopen(filepath, "wb");
if (!downfile) {
retcode = -2;
goto exit;
}
hnd = curl_easy_init();
curl_easy_setopt(hnd, CURLOPT_BUFFERSIZE, FILE_ALLOC_SIZE);
curl_easy_setopt(hnd, CURLOPT_URL, url.c_str());
curl_easy_setopt(hnd, CURLOPT_NOPROGRESS, 0L);
curl_easy_setopt(hnd, CURLOPT_USERAGENT, USER_AGENT);
curl_easy_setopt(hnd, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(hnd, CURLOPT_FAILONERROR, 1L);
curl_easy_setopt(hnd, CURLOPT_ACCEPT_ENCODING, "gzip");
curl_easy_setopt(hnd, CURLOPT_MAXREDIRS, 50L);
curl_easy_setopt(hnd, CURLOPT_XFERINFOFUNCTION, curlProgress);
curl_easy_setopt(hnd, CURLOPT_HTTP_VERSION, (long)CURL_HTTP_VERSION_2TLS);
curl_easy_setopt(hnd, CURLOPT_WRITEFUNCTION, file_handle_data);
curl_easy_setopt(hnd, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(hnd, CURLOPT_VERBOSE, 1L);
curl_easy_setopt(hnd, CURLOPT_STDERR, stdout);
curlResult = curl_easy_perform(hnd);
curl_easy_cleanup(hnd);
if (curlResult != CURLE_OK) {
retcode = -curlResult;
goto exit;
}
LightEvent_Wait(&waitCommit);
LightEvent_Clear(&waitCommit);
file_toCommit_size = file_buffer_pos;
svcFlushProcessDataCache(CUR_PROCESS_HANDLE, (u32)g_buffers[g_index], file_toCommit_size);
g_index = !g_index;
if (!filecommit()) {
retcode = -3;
goto exit;
}
fflush(downfile);
exit:
if (fsCommitThread) {
killThread = true;
LightEvent_Signal(&readyToCommit);
threadJoin(fsCommitThread, U64_MAX);
killThread = false;
fsCommitThread = nullptr;
}
socExit();
if (socubuf) free(socubuf);
if (downfile) {
fclose(downfile);
downfile = nullptr;
}
if (g_buffers[0]) {
free(g_buffers[0]);
g_buffers[0] = nullptr;
}
if (g_buffers[1]) {
free(g_buffers[1]);
g_buffers[1] = nullptr;
}
g_index = 0;
file_buffer_pos = 0;
file_toCommit_size = 0;
writeError = false;
return retcode;
}
/*
following function is from
https://github.com/angelsl/libctrfgh/blob/master/curl_test/src/main.c
*/
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) {
result_sz = 0x1000;
result_buf = (char *)malloc(result_sz);
}
bool need_realloc = false;
while (result_written + bsz > result_sz) {
result_sz <<= 1;
need_realloc = true;
}
if (need_realloc) {
char *new_buf = (char *)realloc(result_buf, result_sz);
if (!new_buf) return 0;
result_buf = new_buf;
}
if (!result_buf) return 0;
memcpy(result_buf + result_written, ptr, bsz);
result_written += bsz;
return bsz;
}
/*
This + Above is Used for No File Write and instead into RAM.
*/
static Result setupContext(CURL *hnd, const char *url) {
curl_easy_setopt(hnd, CURLOPT_BUFFERSIZE, 102400L);
curl_easy_setopt(hnd, CURLOPT_URL, url);
curl_easy_setopt(hnd, CURLOPT_NOPROGRESS, 0L);
curl_easy_setopt(hnd, CURLOPT_USERAGENT, USER_AGENT);
curl_easy_setopt(hnd, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(hnd, CURLOPT_MAXREDIRS, 50L);
curl_easy_setopt(hnd, CURLOPT_HTTP_VERSION, (long)CURL_HTTP_VERSION_2TLS);
curl_easy_setopt(hnd, CURLOPT_WRITEFUNCTION, handle_data);
curl_easy_setopt(hnd, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(hnd, CURLOPT_VERBOSE, 1L);
curl_easy_setopt(hnd, CURLOPT_STDERR, stdout);
return 0;
}
/*
Download a file of a GitHub Release.
const std::string &url: Const Reference to the URL. (https://github.com/Owner/Repo)
const std::string &asset: Const Reference to the Asset. (File.filetype)
const std::string &path: Const Reference, where to store. (sdmc:/File.filetype)
const bool &includePrereleases: Const Reference, if including Pre-Releases.
*/
Result downloadFromRelease(const std::string &url, const std::string &asset, const std::string &path, const bool &includePrereleases) {
Result ret = 0;
CURL *hnd;
void *socubuf = memalign(0x1000, 0x100000);
if (!socubuf) {
return -1;
}
ret = socInit((u32*)socubuf, 0x100000);
if (R_FAILED(ret)) {
free(socubuf);
return ret;
}
std::regex parseUrl("github\\.com\\/(.+)\\/(.+)");
std::smatch result;
regex_search(url, result, parseUrl);
std::string repoOwner = result[1].str(), repoName = result[2].str();
std::stringstream apiurlStream;
apiurlStream << "https://api.github.com/repos/" << repoOwner << "/" << repoName << (includePrereleases ? "/releases" : "/releases/latest");
std::string apiurl = apiurlStream.str();
printf("Downloading latest release from repo:\n%s\nby:\n%s\n", repoName.c_str(), repoOwner.c_str());
printf("Crafted API url:\n%s\n", apiurl.c_str());
hnd = curl_easy_init();
ret = setupContext(hnd, apiurl.c_str());
if (ret != 0) {
socExit();
free(result_buf);
free(socubuf);
result_buf = NULL;
result_sz = 0;
result_written = 0;
return ret;
}
CURLcode cres = curl_easy_perform(hnd);
curl_easy_cleanup(hnd);
char *newbuf = (char *)realloc(result_buf, result_written + 1);
result_buf = newbuf;
result_buf[result_written] = 0; // nullbyte to end it as a proper C style string.
if (cres != CURLE_OK) {
printf("Error in:\ncurl\n");
socExit();
free(result_buf);
free(socubuf);
result_buf = nullptr;
result_sz = 0;
result_written = 0;
return -1;
}
printf("Looking for asset with matching name:\n%s\n", asset.c_str());
std::string assetUrl;
nlohmann::json parsedAPI = nlohmann::json::parse(result_buf);
if (parsedAPI.size() == 0) return -2; // All were prereleases and those are being ignored.
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()) {
std::string assetName = jsonAsset["name"];
if (ScriptUtils::matchPattern(asset, assetName)) {
assetUrl = jsonAsset["browser_download_url"];
break;
}
}
}
}
socExit();
free(result_buf);
free(socubuf);
result_buf = nullptr;
result_sz = 0;
result_written = 0;
if (assetUrl.empty()) {
ret = DL_ERROR_GIT;
} else {
ret = downloadToFile(assetUrl, path);
}
return ret;
}
/*
Check Wi-Fi status.
@return True if Wi-Fi is connected; false if not.
*/
bool checkWifiStatus(void) {
//return true; // For citra.
u32 wifiStatus;
bool res = false;
if (R_SUCCEEDED(ACU_GetWifiStatus(&wifiStatus)) && wifiStatus) res = true;
return res;
}
void downloadFailed(void) { Msg::waitMsg(Lang::get("DOWNLOAD_FAILED")); }
void notImplemented(void) { Msg::waitMsg(Lang::get("NOT_IMPLEMENTED")); }
void doneMsg(void) { Msg::waitMsg(Lang::get("DONE")); }
void notConnectedMsg(void) { Msg::waitMsg(Lang::get("CONNECT_WIFI")); }
/*
Display the progressbar.
*/
void displayProgressBar() {
char str[256];
while(showProgressBar) {
switch(progressbarType) {
case ProgressBar::Downloading:
if (downloadTotal < 1.0f) downloadTotal = 1.0f;
if (downloadTotal < downloadNow) downloadTotal = downloadNow;
snprintf(str, sizeof(str), "%s / %s (%.2f%%)",
StringUtils::formatBytes(downloadNow).c_str(),
StringUtils::formatBytes(downloadTotal).c_str(),
((float)downloadNow/(float)downloadTotal) * 100.0f);
break;
case ProgressBar::Extracting:
snprintf(str, sizeof(str), "%s / %s (%.2f%%)",
StringUtils::formatBytes(writeOffset).c_str(),
StringUtils::formatBytes(extractSize).c_str(),
((float)writeOffset/(float)extractSize) * 100.0f);
break;
case ProgressBar::Installing:
snprintf(str, sizeof(str), "%s / %s (%.2f%%)",
StringUtils::formatBytes(installOffset).c_str(),
StringUtils::formatBytes(installSize).c_str(),
((float)installOffset/(float)installSize) * 100.0f);
break;
}
Gui::clearTextBufs();
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
C2D_TargetClear(Top, TRANSPARENT);
C2D_TargetClear(Bottom, TRANSPARENT);
GFX::DrawTop();
Gui::DrawStringCentered(0, 1, 0.7f, TEXT_COLOR, progressBarMsg, 400);
switch(progressbarType) {
case ProgressBar::Downloading:
Gui::DrawStringCentered(0, 80, 0.6f, TEXT_COLOR, str, 400);
Animation::DrawProgressBar(downloadNow, downloadTotal);
break;
case ProgressBar::Extracting:
Gui::DrawStringCentered(0, 180, 0.6f, TEXT_COLOR, str, 400);
Gui::DrawStringCentered(0, 100, 0.6f, TEXT_COLOR, std::to_string(filesExtracted) + " " + (filesExtracted == 1 ? (Lang::get("FILE_EXTRACTED")).c_str() :(Lang::get("FILES_EXTRACTED"))), 400);
Gui::DrawStringCentered(0, 40, 0.6f, TEXT_COLOR, Lang::get("CURRENTLY_EXTRACTING") + "\n" + extractingFile, 400);
Animation::DrawProgressBar(writeOffset, extractSize);
break;
case ProgressBar::Installing:
Gui::DrawStringCentered(0, 80, 0.6f, TEXT_COLOR, str, 400);
Animation::DrawProgressBar(installOffset, installSize);
break;
}
GFX::DrawBottom();
C3D_FrameEnd(0);
}
}
/*
Return, if an update is available.
const std::string &URL: Const Reference to the URL of the UniStore.
const int &revCurrent: Const Reference to the current Revision. (-1 if unused)
*/
bool IsUpdateAvailable(const std::string &URL, const int &revCurrent) {
Msg::DisplayMsg(Lang::get("CHECK_UNISTORE_UPDATES"));
Result ret = 0;
void *socubuf = memalign(0x1000, 0x100000);
if (!socubuf) return false;
ret = socInit((u32 *)socubuf, 0x100000);
if (R_FAILED(ret)) {
free(socubuf);
return false;
}
CURL *hnd = curl_easy_init();
ret = setupContext(hnd, URL.c_str());
if (ret != 0) {
socExit();
free(result_buf);
free(socubuf);
result_buf = nullptr;
result_sz = 0;
result_written = 0;
return false;
}
CURLcode cres = curl_easy_perform(hnd);
curl_easy_cleanup(hnd);
char *newbuf = (char *)realloc(result_buf, result_written + 1);
result_buf = newbuf;
result_buf[result_written] = 0; // nullbyte to end it as a proper C style string.
if (cres != CURLE_OK) {
printf("Error in:\ncurl\n");
socExit();
free(result_buf);
free(socubuf);
result_buf = nullptr;
result_sz = 0;
result_written = 0;
return false;
}
if (nlohmann::json::accept(result_buf)) {
nlohmann::json parsedAPI = nlohmann::json::parse(result_buf);
if (parsedAPI.contains("storeInfo") && parsedAPI.contains("storeContent")) {
if (parsedAPI["storeInfo"].contains("revision") && parsedAPI["storeInfo"]["revision"].is_number()) {
const int rev = parsedAPI["storeInfo"]["revision"];
socExit();
free(result_buf);
free(socubuf);
result_buf = nullptr;
result_sz = 0;
result_written = 0;
return rev > revCurrent;
}
}
}
socExit();
free(result_buf);
free(socubuf);
result_buf = nullptr;
result_sz = 0;
result_written = 0;
return false;
}
/*
Download a UniStore and return, if revision is higher than current.
const std::string &URL: Const Reference to the URL of the UniStore.
const int &currentRev: Const Reference to the current Revision. (-1 if unused)
const bool &isDownload: Const Reference, if download or updating.
const bool &isUDB: Const Reference, if Universal-DB download or not.
*/
bool DownloadUniStore(const std::string &URL, const int &currentRev, std::string &fl, const bool &isDownload, const bool &isUDB) {
if (isUDB) Msg::DisplayMsg(Lang::get("DOWNLOADING_UNIVERSAL_DB"));
else {
if (currentRev > -1) Msg::DisplayMsg(Lang::get("CHECK_UNISTORE_UPDATES"));
else Msg::DisplayMsg((isDownload ? Lang::get("DOWNLOADING_UNISTORE") : Lang::get("UPDATING_UNISTORE")));
}
Result ret = 0;
void *socubuf = memalign(0x1000, 0x100000);
if (!socubuf) return false;
ret = socInit((u32 *)socubuf, 0x100000);
if (R_FAILED(ret)) {
free(socubuf);
return false;
}
CURL *hnd = curl_easy_init();
ret = setupContext(hnd, URL.c_str());
if (ret != 0) {
socExit();
free(result_buf);
free(socubuf);
result_buf = nullptr;
result_sz = 0;
result_written = 0;
return false;
}
CURLcode cres = curl_easy_perform(hnd);
curl_easy_cleanup(hnd);
char *newbuf = (char *)realloc(result_buf, result_written + 1);
result_buf = newbuf;
result_buf[result_written] = 0; // nullbyte to end it as a proper C style string.
if (cres != CURLE_OK) {
printf("Error in:\ncurl\n");
socExit();
free(result_buf);
free(socubuf);
result_buf = nullptr;
result_sz = 0;
result_written = 0;
return false;
}
if (nlohmann::json::accept(result_buf)) {
nlohmann::json parsedAPI = nlohmann::json::parse(result_buf);
if (parsedAPI.contains("storeInfo") && parsedAPI.contains("storeContent")) {
/* Ensure, version == 3. */
if (parsedAPI["storeInfo"].contains("version") && parsedAPI["storeInfo"]["version"].is_number()) {
if (parsedAPI["storeInfo"]["version"] == 3) {
if (currentRev > -1) {
if (parsedAPI["storeInfo"].contains("revision") && parsedAPI["storeInfo"]["revision"].is_number()) {
const int rev = parsedAPI["storeInfo"]["revision"];
if (rev > currentRev) {
Msg::DisplayMsg(Lang::get("UPDATING_UNISTORE"));
if (parsedAPI["storeInfo"].contains("file") && parsedAPI["storeInfo"]["file"].is_string()) {
fl = parsedAPI["storeInfo"]["file"];
/* Make sure it's not "/", otherwise it breaks. */
if (!(fl.find("/") != std::string::npos)) {
FILE *out = fopen((std::string(_STORE_PATH) + fl).c_str(), "w");
fwrite(result_buf, sizeof(char), result_written, out);
fclose(out);
socExit();
free(result_buf);
free(socubuf);
result_buf = nullptr;
result_sz = 0;
result_written = 0;
return true;
} else {
Msg::waitMsg(Lang::get("FILE_SLASH"));
}
}
}
}
} else {
if (parsedAPI["storeInfo"].contains("file") && parsedAPI["storeInfo"]["file"].is_string()) {
fl = parsedAPI["storeInfo"]["file"];
/* Make sure it's not "/", otherwise it breaks. */
if (!(fl.find("/") != std::string::npos)) {
FILE *out = fopen((std::string(_STORE_PATH) + fl).c_str(), "w");
fwrite(result_buf, sizeof(char), result_written, out);
fclose(out);
socExit();
free(result_buf);
free(socubuf);
result_buf = nullptr;
result_sz = 0;
result_written = 0;
return true;
} else {
Msg::waitMsg(Lang::get("FILE_SLASH"));
}
}
}
} else if (parsedAPI["storeInfo"]["version"] < 3) {
Msg::waitMsg(Lang::get("UNISTORE_TOO_OLD"));
} else if (parsedAPI["storeInfo"]["version"] > 3) {
Msg::waitMsg(Lang::get("UNISTORE_TOO_NEW"));
}
}
} else {
Msg::waitMsg(Lang::get("UNISTORE_INVALID_ERROR"));
}
}
socExit();
free(result_buf);
free(socubuf);
result_buf = nullptr;
result_sz = 0;
result_written = 0;
return false;
}
/*
Download a SpriteSheet.
const std::string &URL: Const Reference to the SpriteSheet URL.
const std::string &file: Const Reference to the filepath.
*/
bool DownloadSpriteSheet(const std::string &URL, const std::string &file) {
if (file.find("/") != std::string::npos) return false;
Result ret = 0;
void *socubuf = memalign(0x1000, 0x100000);
if (!socubuf) return false;
ret = socInit((u32 *)socubuf, 0x100000);
if (R_FAILED(ret)) {
free(socubuf);
return false;
}
CURL *hnd = curl_easy_init();
ret = setupContext(hnd, URL.c_str());
if (ret != 0) {
socExit();
free(result_buf);
free(socubuf);
result_buf = nullptr;
result_sz = 0;
result_written = 0;
return false;
}
CURLcode cres = curl_easy_perform(hnd);
curl_easy_cleanup(hnd);
char *newbuf = (char *)realloc(result_buf, result_written + 1);
result_buf = newbuf;
result_buf[result_written] = 0; // nullbyte to end it as a proper C style string.
if (cres != CURLE_OK) {
printf("Error in:\ncurl\n");
socExit();
free(result_buf);
free(socubuf);
result_buf = nullptr;
result_sz = 0;
result_written = 0;
return false;
}
C2D_SpriteSheet sheet = C2D_SpriteSheetLoadFromMem(result_buf, result_written);
if (sheet) {
if (C2D_SpriteSheetCount(sheet) > 0) {
FILE *out = fopen((std::string(_STORE_PATH) + file).c_str(), "w");
fwrite(result_buf, sizeof(char), result_written, out);
fclose(out);
socExit();
free(result_buf);
free(socubuf);
result_buf = nullptr;
result_sz = 0;
result_written = 0;
C2D_SpriteSheetFree(sheet);
return true;
}
}
socExit();
free(result_buf);
free(socubuf);
result_buf = nullptr;
result_sz = 0;
result_written = 0;
return false;
}
/*
Checks for U-U updates.
*/
bool IsUUUpdateAvailable() {
if (!checkWifiStatus()) return false;
Msg::DisplayMsg(Lang::get("CHECK_UU_UPDATES"));
Result ret = 0;
void *socubuf = memalign(0x1000, 0x100000);
if (!socubuf) return false;
ret = socInit((u32 *)socubuf, 0x100000);
if (R_FAILED(ret)) {
free(socubuf);
return false;
}
CURL *hnd = curl_easy_init();
ret = setupContext(hnd, "https://api.github.com/repos/Universal-Team/Universal-Updater/releases/latest");
if (ret != 0) {
socExit();
free(result_buf);
free(socubuf);
result_buf = nullptr;
result_sz = 0;
result_written = 0;
return false;
}
CURLcode cres = curl_easy_perform(hnd);
curl_easy_cleanup(hnd);
char *newbuf = (char *)realloc(result_buf, result_written + 1);
result_buf = newbuf;
result_buf[result_written] = 0; // nullbyte to end it as a proper C style string.
if (cres != CURLE_OK) {
printf("Error in:\ncurl\n");
socExit();
free(result_buf);
free(socubuf);
result_buf = nullptr;
result_sz = 0;
result_written = 0;
return false;
}
if (nlohmann::json::accept(result_buf)) {
nlohmann::json parsedAPI = nlohmann::json::parse(result_buf);
if (parsedAPI.contains("tag_name") && parsedAPI["tag_name"].is_string()) {
const std::string tag = parsedAPI["tag_name"];
socExit();
free(result_buf);
free(socubuf);
result_buf = nullptr;
result_sz = 0;
result_written = 0;
return strcasecmp(StringUtils::lower_case(tag).c_str(), StringUtils::lower_case(C_V).c_str()) > 0;
}
}
socExit();
free(result_buf);
free(socubuf);
result_buf = nullptr;
result_sz = 0;
result_written = 0;
return false;
}
extern bool is3DSX, exiting;
extern std::string _3dsxPath;
/*
Execute U-U update action.
*/
void UpdateAction() {
if (ScriptUtils::downloadRelease("Universal-Team/Universal-Updater", (is3DSX ? "Universal-Updater.3dsx" : "Universal-Updater.cia"),
(is3DSX ? _3dsxPath : "sdmc:/Universal-Updater.cia"),
false, Lang::get("DONLOADING_UNIVERSAL_UPDATER")) == 0) {
if (is3DSX) {
Msg::waitMsg(Lang::get("UPDATE_DONE"));
exiting = true;
return;
}
ScriptUtils::installFile("sdmc:/Universal-Updater.cia", false, Lang::get("INSTALL_UNIVERSAL_UPDATER"));
ScriptUtils::removeFile("sdmc:/Universal-Updater.cia", Lang::get("DELETE_UNNEEDED_FILE"));
Msg::waitMsg(Lang::get("UPDATE_DONE"));
exiting = true;
}
}
+98 -104
View File
@@ -1,105 +1,99 @@
/*
* This file is part of Universal-Updater
* Copyright (C) 2019-2020 Universal-Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "extract.hpp"
#include "logging.hpp"
#include <archive.h>
#include <archive_entry.h>
#include <regex>
int filesExtracted = 0;
std::string extractingFile = "";
// That are our File Progressbar variable.
u64 extractSize = 0, writeOffset = 0;
Result extractArchive(std::string archivePath, std::string wantedFile, std::string outputPath) {
extractSize = 0, writeOffset = 0, filesExtracted = 0;
archive *a = archive_read_new();
archive_entry *entry;
int flags;
/* Select which attributes we want to restore. */
flags = ARCHIVE_EXTRACT_TIME;
flags |= ARCHIVE_EXTRACT_PERM;
flags |= ARCHIVE_EXTRACT_ACL;
flags |= ARCHIVE_EXTRACT_FFLAGS;
a = archive_read_new();
archive_read_support_format_all(a);
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
std::smatch match;
std::string entryName(archive_entry_pathname(entry));
if (std::regex_search(entryName, match, std::regex(wantedFile))) {
extractingFile = outputPath + match.suffix().str();
// make directories
int substrPos = 1;
while(extractingFile.find("/", substrPos)) {
mkdir(extractingFile.substr(0, substrPos).c_str(), 0777);
substrPos = extractingFile.find("/", substrPos) + 1;
}
uint sizeLeft = archive_entry_size(entry);
extractSize = sizeLeft;
writeOffset = 0;
FILE *file = fopen(extractingFile.c_str(), "wb");
if (!file) {
return EXTRACT_ERROR_WRITEFILE;
}
u8 *buf = new u8[0x30000];
if (buf == nullptr) {
return EXTRACT_ERROR_ALLOC;
}
while(sizeLeft > 0) {
u64 toRead = std::min(0x30000u, sizeLeft);
ssize_t size = archive_read_data(a, buf, toRead);
fwrite(buf, 1, size, file);
sizeLeft -= size;
writeOffset += size;
}
filesExtracted++;
fclose(file);
delete[] buf;
}
}
}
archive_read_close(a);
archive_read_free(a);
return EXTRACT_ERROR_NONE;
/*
* This file is part of Universal-Updater
* Copyright (C) 2019-2020 Universal-Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "extract.hpp"
#include "scriptUtils.hpp"
#include <archive.h>
#include <archive_entry.h>
#include <regex>
int filesExtracted = 0;
std::string extractingFile = "";
/* That are our File Progressbar variable. */
u64 extractSize = 0, writeOffset = 0;
Result extractArchive(const std::string &archivePath, const std::string &wantedFile, const std::string &outputPath) {
extractSize = 0, writeOffset = 0, filesExtracted = 0;
archive *a = archive_read_new();
archive_entry *entry;
int flags;
/* Select which attributes we want to restore. */
flags = ARCHIVE_EXTRACT_TIME;
flags |= ARCHIVE_EXTRACT_PERM;
flags |= ARCHIVE_EXTRACT_ACL;
flags |= ARCHIVE_EXTRACT_FFLAGS;
a = archive_read_new();
archive_read_support_format_all(a);
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. */
std::smatch match;
std::string entryName(archive_entry_pathname(entry));
if (std::regex_search(entryName, match, std::regex(wantedFile))) {
extractingFile = outputPath + match.suffix().str();
/* make directories. */
int substrPos = 1;
while(extractingFile.find("/", substrPos)) {
mkdir(extractingFile.substr(0, substrPos).c_str(), 0777);
substrPos = extractingFile.find("/", substrPos) + 1;
}
uint sizeLeft = archive_entry_size(entry);
extractSize = sizeLeft;
writeOffset = 0;
FILE *file = fopen(extractingFile.c_str(), "wb");
if (!file) return EXTRACT_ERROR_WRITEFILE;
u8 *buf = new u8[0x30000];
if (!buf) return EXTRACT_ERROR_ALLOC;
while(sizeLeft > 0) {
u64 toRead = std::min(0x30000u, sizeLeft);
ssize_t size = archive_read_data(a, buf, toRead);
fwrite(buf, 1, size, file);
sizeLeft -= size;
writeOffset += size;
}
filesExtracted++;
fclose(file);
delete[] buf;
}
}
}
archive_read_close(a);
archive_read_free(a);
return EXTRACT_ERROR_NONE;
}
+281 -453
View File
@@ -1,454 +1,282 @@
/*
* This file is part of Universal-Updater
* Copyright (C) 2019-2020 Universal-Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "common.hpp"
#include "config.hpp"
#include "fileBrowse.hpp"
#include "gfx.hpp"
#include "gui.hpp"
#include "screenCommon.hpp"
#include "structs.hpp"
#include <3ds.h>
#include <cstring>
#include <dirent.h>
#include <sys/stat.h>
#include <unistd.h>
#include <vector>
#include <algorithm>
#include <functional>
#include <array>
#include <iostream>
int file_count = 0;
extern std::unique_ptr<Config> config;
extern uint selectedFile;
extern int keyRepeatDelay;
extern bool dirChanged;
std::vector<DirEntry> dirContents;
extern bool touching(touchPosition touch, Structs::ButtonPos button);
extern touchPosition touch;
const std::vector<Structs::ButtonPos> buttonPositions = {
{295, 0, 25, 25}, // Arrow Up.
{295, 215, 25, 25}, // Arrow Down.
{15, 220, 50, 15}, // Open.
{80, 220, 50, 15}, // Select.
{145, 220, 50, 15}, // Refresh.
{210, 220, 50, 15}, // Back.
{0, 0, 25, 25} // ViewMode Change.
};
off_t getFileSize(const char *fileName) {
FILE* fp = fopen(fileName, "rb");
off_t fsize = 0;
if (fp) {
fseek(fp, 0, SEEK_END);
fsize = ftell(fp); // Get source file's size
fseek(fp, 0, SEEK_SET);
}
fclose(fp);
return fsize;
}
bool nameEndsWith(const std::string& name, const std::vector<std::string> extensionList) {
if (name.substr(0, 2) == "._") return false;
if (name.size() == 0) return false;
if (extensionList.size() == 0) return true;
for(int i = 0; i < (int)extensionList.size(); i++) {
const std::string ext = extensionList.at(i);
if (strcasecmp(name.c_str() + name.size() - ext.size(), ext.c_str()) == 0) return true;
}
return false;
}
bool dirEntryPredicate(const DirEntry& lhs, const DirEntry& rhs) {
if (!lhs.isDirectory && rhs.isDirectory) {
return false;
}
if (lhs.isDirectory && !rhs.isDirectory) {
return true;
}
return strcasecmp(lhs.name.c_str(), rhs.name.c_str()) < 0;
}
void getDirectoryContents(std::vector<DirEntry>& dirContents, const std::vector<std::string> extensionList) {
struct stat st;
dirContents.clear();
DIR *pdir = opendir(".");
if (pdir == NULL) {
Msg::DisplayMsg("Unable to open the directory.");
for(int i = 0; i < 120; i++) gspWaitForVBlank();
} else {
while(true) {
DirEntry dirEntry;
struct dirent* pent = readdir(pdir);
if (pent == NULL) break;
stat(pent->d_name, &st);
dirEntry.name = pent->d_name;
dirEntry.isDirectory = (st.st_mode & S_IFDIR) ? true : false;
if (dirEntry.name.compare(".") != 0 && (dirEntry.isDirectory || nameEndsWith(dirEntry.name, extensionList))) {
dirContents.push_back(dirEntry);
}
}
closedir(pdir);
}
sort(dirContents.begin(), dirContents.end(), dirEntryPredicate);
}
void getDirectoryContents(std::vector<DirEntry>& dirContents) {
getDirectoryContents(dirContents, {});
}
std::vector<std::string> getContents(const std::string &name, const std::vector<std::string> &extensionList) {
std::vector<std::string> dirContents;
DIR* pdir = opendir(name.c_str());
struct dirent *pent;
while ((pent = readdir(pdir)) != NULL) {
if (nameEndsWith(pent->d_name, extensionList))
dirContents.push_back(pent->d_name);
}
closedir(pdir);
return dirContents;
}
// Directory exist?
bool returnIfExist(const std::string &path, const std::vector<std::string> &extensionList) {
dirContents.clear();
chdir(path.c_str());
std::vector<DirEntry> dirContentsTemp;
getDirectoryContents(dirContentsTemp, extensionList);
for(uint i = 0; i < dirContentsTemp.size(); i++) {
dirContents.push_back(dirContentsTemp[i]);
}
if (dirContents.size() == 0) {
return false;
}
return true;
}
// returns a Path or file to 'std::string'.
// selectText is the Text which is displayed on the bottom bar of the top screen.
// selectionMode is how you select it. 1 -> Path, 2 -> File.
std::string selectFilePath(std::string selectText, std::string initialPath, const std::vector<std::string> &extensionList, int selectionMode) {
uint selectedFile = 0;
std::string selectedPath = "";
int keyRepeatDelay = 4;
bool dirChanged = true;
bool fastMode = false;
uint screenPos = 0;
uint screenPosList = 0;
std::vector<DirEntry> dirContents;
std::string dirs;
// Initial dir change.
dirContents.clear();
chdir(initialPath.c_str());
std::vector<DirEntry> dirContentsTemp;
getDirectoryContents(dirContentsTemp, extensionList);
for(uint i = 0; i < dirContentsTemp.size(); i++) {
dirContents.push_back(dirContentsTemp[i]);
}
selectedFile = 0;
while (1) {
Gui::clearTextBufs();
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
C2D_TargetClear(Top, BLACK);
C2D_TargetClear(Bottom, BLACK);
GFX::DrawTop();
char path[PATH_MAX];
getcwd(path, PATH_MAX);
Gui::DrawString((400-(Gui::GetStringWidth(0.60f, path)))/2, config->useBars() ? 0 : 2, 0.60f, config->textColor(), path, 390);
Gui::DrawStringCentered(0, config->useBars() ? 220 : 218, 0.60f, config->textColor(), selectText, 390);
GFX::DrawBottom();
if (config->viewMode() == 0) {
for(int i = 0; i < ENTRIES_PER_SCREEN && i < (int)dirContents.size(); i++) {
Gui::Draw_Rect(0, 40+(i*57), 320, 45, config->unselectedColor());
dirs = dirContents[screenPos + i].name;
if (screenPos + i == selectedFile) {
Gui::drawAnimatedSelector(0, 40+(i*57), 320, 45, .060, TRANSPARENT, config->selectedColor());
}
Gui::DrawStringCentered(0, 50+(i*57), 0.7f, config->textColor(), dirs, 320);
}
} else if (config->viewMode() == 1) {
for(int i = 0; i < ENTRIES_PER_LIST && i < (int)dirContents.size(); i++) {
Gui::Draw_Rect(0, (i+1)*27, 320, 25, config->unselectedColor());
dirs = dirContents[screenPosList + i].name;
if (screenPosList + i == selectedFile) {
Gui::drawAnimatedSelector(0, (i+1)*27, 320, 25, .060, TRANSPARENT, config->selectedColor());
}
Gui::DrawStringCentered(0, ((i+1)*27)+1, 0.7f, config->textColor(), dirs, 320);
}
}
Gui::DrawStringCentered(0, config->useBars() ? 0 : 2, 0.45f, config->textColor(), Lang::get("FILEBROWSE_MSG"), 260);
GFX::DrawArrow(295, -1);
GFX::DrawArrow(315, 240, 180.0);
GFX::DrawSpriteBlend(sprites_view_idx, buttonPositions[6].x, buttonPositions[6].y);
Gui::Draw_Rect(buttonPositions[2].x, buttonPositions[2].y, buttonPositions[2].w, buttonPositions[2].h, C2D_Color32(0, 0, 0, 190));
Gui::Draw_Rect(buttonPositions[3].x, buttonPositions[3].y, buttonPositions[3].w, buttonPositions[3].h, C2D_Color32(0, 0, 0, 190));
Gui::Draw_Rect(buttonPositions[4].x, buttonPositions[4].y, buttonPositions[4].w, buttonPositions[4].h, C2D_Color32(0, 0, 0, 190));
Gui::Draw_Rect(buttonPositions[5].x, buttonPositions[5].y, buttonPositions[5].w, buttonPositions[5].h, C2D_Color32(0, 0, 0, 190));
Gui::DrawStringCentered(-120, 222, 0.4, config->textColor(), Lang::get("OPEN"), 40);
Gui::DrawStringCentered(-55, 222, 0.4, config->textColor(), Lang::get("SELECT"), 40);
Gui::DrawStringCentered(10, 222, 0.4, config->textColor(), Lang::get("REFRESH"), 40);
Gui::DrawStringCentered(75, 222, 0.4, config->textColor(), Lang::get("BACK"), 40);
C3D_FrameEnd(0);
// The input part.
hidScanInput();
hidTouchRead(&touch);
if (keyRepeatDelay) keyRepeatDelay--;
if (dirChanged) {
dirContents.clear();
std::vector<DirEntry> dirContentsTemp;
getDirectoryContents(dirContentsTemp, extensionList);
for(uint i = 0; i < dirContentsTemp.size(); i++) {
dirContents.push_back(dirContentsTemp[i]);
}
dirChanged = false;
}
if ((hidKeysDown() & KEY_SELECT) || (hidKeysDown() & KEY_TOUCH && touching(touch, buttonPositions[4]))) {
dirChanged = true;
}
if ((hidKeysDown() & KEY_A) || (hidKeysDown() & KEY_TOUCH && touching(touch, buttonPositions[2]))) {
if (dirContents.size() != 0) {
if (dirContents[selectedFile].isDirectory) {
chdir(dirContents[selectedFile].name.c_str());
selectedFile = 0;
dirChanged = true;
}
}
}
if (hidKeysDown() & KEY_TOUCH && touching(touch, buttonPositions[0])) {
if (selectedFile > 0) selectedFile--;
}
if (hidKeysDown() & KEY_TOUCH && touching(touch, buttonPositions[1])) {
if (selectedFile < dirContents.size()-1) selectedFile++;
}
if (hidKeysHeld() & KEY_UP) {
if (selectedFile > 0 && !keyRepeatDelay) {
selectedFile--;
if (fastMode == true) {
keyRepeatDelay = 3;
} else if (fastMode == false){
keyRepeatDelay = 6;
}
}
}
if (hidKeysHeld() & KEY_DOWN && !keyRepeatDelay) {
if (selectedFile < dirContents.size()-1) {
selectedFile++;
if (fastMode == true) {
keyRepeatDelay = 3;
} else if (fastMode == false){
keyRepeatDelay = 6;
}
}
}
if ((hidKeysDown() & KEY_B) || (hidKeysDown() & KEY_TOUCH && touching(touch, buttonPositions[5]))) {
char path[PATH_MAX];
getcwd(path, PATH_MAX);
if (strcmp(path, "sdmc:/") == 0 || strcmp(path, "/") == 0) {
return "";
} else {
chdir("..");
selectedFile = 0;
dirChanged = true;
}
}
if ((hidKeysDown() & KEY_X) || (hidKeysDown() & KEY_TOUCH && touching(touch, buttonPositions[3]))) {
char path[PATH_MAX];
getcwd(path, PATH_MAX);
selectedPath = path;
if (selectionMode == 2) {
selectedPath += dirContents[selectedFile].name;
}
return selectedPath;
}
if (hidKeysDown() & KEY_R) {
fastMode = true;
}
if (hidKeysDown() & KEY_L) {
fastMode = false;
}
// Switch ViewMode.
if ((hidKeysDown() & KEY_Y) || (hidKeysDown() & KEY_TOUCH && touching(touch, buttonPositions[6]))) {
if (config->viewMode() == 0) {
config->viewMode(1);
} else {
config->viewMode(0);
}
}
if (config->viewMode() == 0) {
if (selectedFile < screenPos) {
screenPos = selectedFile;
} else if (selectedFile > screenPos + ENTRIES_PER_SCREEN - 1) {
screenPos = selectedFile - ENTRIES_PER_SCREEN + 1;
}
} else if (config->viewMode() == 1) {
if (selectedFile < screenPosList) {
screenPosList = selectedFile;
} else if (selectedFile > screenPosList + ENTRIES_PER_LIST - 1) {
screenPosList = selectedFile - ENTRIES_PER_LIST + 1;
}
}
}
}
#define copyBufSize 0x8000
u32 copyBuf[copyBufSize];
void dirCopy(DirEntry* entry, int i, const char *destinationPath, const char *sourcePath) {
std::vector<DirEntry> dirContents;
dirContents.clear();
if (entry->isDirectory) chdir((sourcePath + ("/" + entry->name)).c_str());
getDirectoryContents(dirContents);
if (((int)dirContents.size()) == 1) mkdir((destinationPath + ("/" + entry->name)).c_str(), 0777);
if (((int)dirContents.size()) != 1) fcopy((sourcePath + ("/" + entry->name)).c_str(), (destinationPath + ("/" + entry->name)).c_str());
}
int fcopy(const char *sourcePath, const char *destinationPath) {
DIR *isDir = opendir(sourcePath);
if (isDir != NULL) {
closedir(isDir);
// Source path is a directory
chdir(sourcePath);
std::vector<DirEntry> dirContents;
getDirectoryContents(dirContents);
DirEntry* entry = &dirContents.at(1);
mkdir(destinationPath, 0777);
for(int i = 1; i < ((int)dirContents.size()); i++) {
chdir(sourcePath);
entry = &dirContents.at(i);
dirCopy(entry, i, destinationPath, sourcePath);
}
chdir(destinationPath);
chdir("..");
return 1;
} else {
closedir(isDir);
// Source path is a file
FILE* sourceFile = fopen(sourcePath, "rb");
off_t fsize = 0;
if (sourceFile) {
fseek(sourceFile, 0, SEEK_END);
fsize = ftell(sourceFile); // Get source file's size
fseek(sourceFile, 0, SEEK_SET);
} else {
fclose(sourceFile);
return -1;
}
FILE* destinationFile = fopen(destinationPath, "wb");
//if (destinationFile) {
fseek(destinationFile, 0, SEEK_SET);
/*} else {
fclose(sourceFile);
fclose(destinationFile);
return -1;
}*/
off_t offset = 0;
int numr;
while(1) {
scanKeys();
if (keysHeld() & KEY_B) {
// Cancel copying
fclose(sourceFile);
fclose(destinationFile);
return -1;
break;
}
printf("\x1b[16;0H");
printf("Progress:\n");
printf("%i/%i Bytes ", (int)offset, (int)fsize);
// Copy file to destination path
numr = fread(copyBuf, 2, copyBufSize, sourceFile);
fwrite(copyBuf, 2, numr, destinationFile);
offset += copyBufSize;
if (offset > fsize) {
fclose(sourceFile);
fclose(destinationFile);
printf("\x1b[17;0H");
printf("%i/%i Bytes ", (int)fsize, (int)fsize);
for(int i = 0; i < 30; i++) gspWaitForVBlank();
return 1;
break;
}
}
return -1;
}
/*
* This file is part of Universal-Updater
* Copyright (C) 2019-2020 Universal-Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "fileBrowse.hpp"
#include "json.hpp"
#include "structs.hpp"
#include <3ds.h>
#include <cstring>
#include <functional>
#include <unistd.h>
extern bool touching(touchPosition touch, Structs::ButtonPos button);
extern touchPosition touch;
bool nameEndsWith(const std::string &name, const std::vector<std::string> &extensionList) {
if (name.substr(0, 2) == "._") return false;
if (name.size() == 0) return false;
if (extensionList.size() == 0) return true;
for(int i = 0; i < (int)extensionList.size(); i++) {
const std::string ext = extensionList.at(i);
if (strcasecmp(name.c_str() + name.size() - ext.size(), ext.c_str()) == 0) return true;
}
return false;
}
bool dirEntryPredicate(const DirEntry &lhs, const DirEntry &rhs) {
if (!lhs.isDirectory && rhs.isDirectory) return false;
if (lhs.isDirectory && !rhs.isDirectory) return true;
return strcasecmp(lhs.name.c_str(), rhs.name.c_str()) < 0;
}
void getDirectoryContents(std::vector<DirEntry> &dirContents, const std::vector<std::string> &extensionList) {
struct stat st;
dirContents.clear();
DIR *pdir = opendir(".");
if (pdir != nullptr) {
while(true) {
DirEntry dirEntry;
struct dirent *pent = readdir(pdir);
if (pent == NULL) break;
stat(pent->d_name, &st);
dirEntry.name = pent->d_name;
dirEntry.isDirectory = (st.st_mode & S_IFDIR) ? true : false;
if (dirEntry.name.compare(".") != 0 && (dirEntry.isDirectory || nameEndsWith(dirEntry.name, extensionList))) {
dirContents.push_back(dirEntry);
}
}
closedir(pdir);
}
sort(dirContents.begin(), dirContents.end(), dirEntryPredicate);
}
void getDirectoryContents(std::vector<DirEntry> &dirContents) {
getDirectoryContents(dirContents, {});
}
std::vector<std::string> getContents(const std::string &name, const std::vector<std::string> &extensionList) {
std::vector<std::string> dirContents;
DIR* pdir = opendir(name.c_str());
struct dirent *pent;
while ((pent = readdir(pdir)) != NULL) {
if (nameEndsWith(pent->d_name, extensionList)) dirContents.push_back(pent->d_name);
}
closedir(pdir);
return dirContents;
}
/*
Return UniStore info.
const std::string &file: Const Reference to the path of the file.
const std::string &fieName: Const Reference to the filename, without path.
*/
UniStoreInfo GetInfo(const std::string &file, const std::string &fileName) {
UniStoreInfo Temp = { "", "", "", fileName, "", -1, -1, -1 }; // Title, Author, URL, FileName, Desc, Version, Revision, Entries.
nlohmann::json JSON = nullptr;
FILE *temp = fopen(file.c_str(), "r");
JSON = nlohmann::json::parse(temp, nullptr, false);
fclose(temp);
if (!JSON.contains("storeInfo")) return Temp; // storeInfo does not exist.
if (JSON["storeInfo"].contains("title") && JSON["storeInfo"]["title"].is_string()) {
Temp.Title = JSON["storeInfo"]["title"];
}
if (JSON["storeInfo"].contains("author") && JSON["storeInfo"]["author"].is_string()) {
Temp.Author = JSON["storeInfo"]["author"];
}
if (JSON["storeInfo"].contains("url") && JSON["storeInfo"]["url"].is_string()) {
Temp.URL = JSON["storeInfo"]["url"];
}
if (JSON["storeInfo"].contains("description") && JSON["storeInfo"]["description"].is_string()) {
Temp.Description = JSON["storeInfo"]["description"];
}
if (JSON["storeInfo"].contains("version") && JSON["storeInfo"]["version"].is_number()) {
Temp.Version = JSON["storeInfo"]["version"];
}
if (JSON["storeInfo"].contains("revision") && JSON["storeInfo"]["revision"].is_number()) {
Temp.Revision = JSON["storeInfo"]["revision"];
}
if (JSON.contains("storeContent")) Temp.StoreSize = JSON["storeContent"].size();
return Temp;
}
/*
Return UniStore info vector.
const std::string &path: Const Reference to the path, where to check.
*/
std::vector<UniStoreInfo> GetUniStoreInfo(const std::string &path) {
std::vector<UniStoreInfo> info;
std::vector<DirEntry> dirContents;
chdir(path.c_str());
getDirectoryContents(dirContents, { "unistore" });
for(uint i = 0; i < dirContents.size(); i++) {
/* Make sure to ONLY push .unistores, and no folders. Avoids crashes in that case too. */
if ((path + dirContents[i].name).find(".unistore") != std::string::npos) {
info.push_back( GetInfo(path + dirContents[i].name, dirContents[i].name) );
}
}
return info;
}
#define copyBufSize 0x8000
u32 copyBuf[copyBufSize];
/*
Copy a directory.
DirEntry *entry: Pointer to a DirEntry.
const char *destinationPath: Pointer to the destination path.
const char *sourcePath: Pointer to the source path.
*/
void dirCopy(DirEntry *entry, const char *destinationPath, const char *sourcePath) {
std::vector<DirEntry> dirContents;
dirContents.clear();
if (entry->isDirectory) chdir((sourcePath + ("/" + entry->name)).c_str());
getDirectoryContents(dirContents);
if (((int)dirContents.size()) == 1) mkdir((destinationPath + ("/" + entry->name)).c_str(), 0777);
if (((int)dirContents.size()) != 1) fcopy((sourcePath + ("/" + entry->name)).c_str(), (destinationPath + ("/" + entry->name)).c_str());
}
/*
The copy operation.
const char *destinationPath: Pointer to the destination path.
const char *sourcePath: Pointer to the source path.
*/
int fcopy(const char *sourcePath, const char *destinationPath) {
DIR *isDir = opendir(sourcePath);
if (isDir != NULL) {
closedir(isDir);
/* Source path is a directory. */
chdir(sourcePath);
std::vector<DirEntry> dirContents;
getDirectoryContents(dirContents);
DirEntry *entry = &dirContents.at(1);
mkdir(destinationPath, 0777);
for(int i = 1; i < ((int)dirContents.size()); i++) {
chdir(sourcePath);
entry = &dirContents.at(i);
dirCopy(entry, destinationPath, sourcePath);
}
chdir(destinationPath);
chdir("..");
return 1;
} else {
closedir(isDir);
/* Source path is a file. */
FILE *sourceFile = fopen(sourcePath, "rb");
off_t fsize = 0;
if (sourceFile) {
fseek(sourceFile, 0, SEEK_END);
fsize = ftell(sourceFile); // Get source file's size.
fseek(sourceFile, 0, SEEK_SET);
} else {
fclose(sourceFile);
return -1;
}
FILE* destinationFile = fopen(destinationPath, "wb");
//if (destinationFile) {
fseek(destinationFile, 0, SEEK_SET);
/*} else {
fclose(sourceFile);
fclose(destinationFile);
return -1;
}*/
off_t offset = 0;
int numr;
while(1) {
scanKeys();
if (keysHeld() & KEY_B) {
/* Cancel copying. */
fclose(sourceFile);
fclose(destinationFile);
return -1;
break;
}
printf("\x1b[16;0H");
printf("Progress:\n");
printf("%i/%i Bytes ", (int)offset, (int)fsize);
/* Copy file to destination path. */
numr = fread(copyBuf, 2, copyBufSize, sourceFile);
fwrite(copyBuf, 2, numr, destinationFile);
offset += copyBufSize;
if (offset > fsize) {
fclose(sourceFile);
fclose(destinationFile);
printf("\x1b[17;0H");
printf("%i/%i Bytes ", (int)fsize, (int)fsize);
for(int i = 0; i < 30; i++) gspWaitForVBlank();
return 1;
break;
}
}
return -1;
}
}
-101
View File
@@ -1,101 +0,0 @@
#include "files.h"
FS_Path getPathInfo(const char * path, FS_ArchiveID * archive) {
*archive = ARCHIVE_SDMC;
FS_Path filePath = {0};
unsigned int prefixlen = 0;
if (!strncmp(path, "sdmc:/", 6)) {
prefixlen = 5;
} else if (*path != '/') {
//if the path is local (doesnt start with a slash), it needs to be appended to the working dir to be valid
char * actualPath = NULL;
asprintf(&actualPath, "%s%s", WORKING_DIR, path);
filePath = fsMakePath(PATH_ASCII, actualPath);
free(actualPath);
}
//if the filePath wasnt set above, set it
if (filePath.size == 0) {
filePath = fsMakePath(PATH_ASCII, path+prefixlen);
}
return filePath;
}
Result makeDirs(const char * path) {
Result ret = 0;
FS_ArchiveID archiveID;
FS_Path filePath = getPathInfo(path, &archiveID);
FS_Archive archive;
ret = FSUSER_OpenArchive(&archive, archiveID, fsMakePath(PATH_EMPTY, ""));
for (char * slashpos = strchr(path+1, '/'); slashpos != NULL; slashpos = strchr(slashpos+1, '/')) {
char bak = *(slashpos);
*(slashpos) = '\0';
Handle dirHandle;
ret = FSUSER_OpenDirectory(&dirHandle, archive, filePath);
if (R_SUCCEEDED(ret)) FSDIR_Close(dirHandle);
else ret = FSUSER_CreateDirectory(archive, filePath, FS_ATTRIBUTE_DIRECTORY);
*(slashpos) = bak;
}
FSUSER_CloseArchive(archive);
return ret;
}
Result openFile(Handle* fileHandle, const char * path, bool write) {
FS_ArchiveID archive;
FS_Path filePath = getPathInfo(path, &archive);
u32 flags = (write ? (FS_OPEN_CREATE | FS_OPEN_WRITE) : FS_OPEN_READ);
Result ret = 0;
ret = makeDirs(strdup(path));
ret = FSUSER_OpenFileDirectly(fileHandle, archive, fsMakePath(PATH_EMPTY, ""), filePath, flags, 0);
if (write) ret = FSFILE_SetSize(*fileHandle, 0); //truncate the file to remove previous contents before writing
return ret;
}
Result deleteFile(const char * path) {
FS_ArchiveID archiveID;
FS_Path filePath = getPathInfo(path, &archiveID);
FS_Archive archive;
Result ret = FSUSER_OpenArchive(&archive, archiveID, fsMakePath(PATH_EMPTY, ""));
if (R_FAILED(ret)) return ret;
ret = FSUSER_DeleteFile(archive, filePath);
FSUSER_CloseArchive(archive);
return ret;
}
Result removeDir(const char *path) {
FS_ArchiveID archiveID;
FS_Path filePath = getPathInfo(path, &archiveID);
FS_Archive archive;
Result ret = FSUSER_OpenArchive(&archive, archiveID, fsMakePath(PATH_EMPTY, ""));
if (R_FAILED(ret)) return ret;
ret = FSUSER_DeleteDirectory(archive, filePath);
FSUSER_CloseArchive(archive);
return ret;
}
Result removeDirRecursive(const char *path) {
FS_ArchiveID archiveID;
FS_Path filePath = getPathInfo(path, &archiveID);
FS_Archive archive;
Result ret = FSUSER_OpenArchive(&archive, archiveID, fsMakePath(PATH_EMPTY, ""));
if (R_FAILED(ret)) return ret;
ret = FSUSER_DeleteDirectoryRecursively(archive, filePath);
FSUSER_CloseArchive(archive);
return ret;
}
+130
View File
@@ -0,0 +1,130 @@
/*
* This file is part of Universal-Updater
* Copyright (C) 2019-2020 Universal-Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "files.hpp"
FS_Path getPathInfo(const char *path, FS_ArchiveID *archive) {
*archive = ARCHIVE_SDMC;
FS_Path filePath = { PATH_INVALID, 0, nullptr };
unsigned int prefixlen = 0;
if (!strncmp(path, "sdmc:/", 6)) {
prefixlen = 5;
} else if (*path != '/') {
/*
if the path is local (doesnt start with a slash),
it needs to be appended to the working dir to be valid.
*/
char *actualPath = NULL;
asprintf(&actualPath, "%s%s", "/", path);
filePath = fsMakePath(PATH_ASCII, actualPath);
free(actualPath);
}
/* if the filePath wasnt set above, set it. */
if (filePath.size == 0) filePath = fsMakePath(PATH_ASCII, path + prefixlen);
return filePath;
}
Result makeDirs(const char *path) {
Result ret = 0;
FS_ArchiveID archiveID;
FS_Path filePath = getPathInfo(path, &archiveID);
FS_Archive archive;
ret = FSUSER_OpenArchive(&archive, archiveID, fsMakePath(PATH_EMPTY, ""));
for (char *slashpos = strchr(path + 1, '/'); slashpos != NULL; slashpos = strchr(slashpos + 1, '/')) {
char bak = *(slashpos);
*(slashpos) = '\0';
Handle dirHandle;
ret = FSUSER_OpenDirectory(&dirHandle, archive, filePath);
if (R_SUCCEEDED(ret)) FSDIR_Close(dirHandle);
else ret = FSUSER_CreateDirectory(archive, filePath, FS_ATTRIBUTE_DIRECTORY);
*(slashpos) = bak;
}
FSUSER_CloseArchive(archive);
return ret;
}
Result openFile(Handle *fileHandle, const char *path, const bool &write) {
FS_ArchiveID archive;
FS_Path filePath = getPathInfo(path, &archive);
u32 flags = (write ? (FS_OPEN_CREATE | FS_OPEN_WRITE) : FS_OPEN_READ);
Result ret = 0;
ret = makeDirs(strdup(path));
ret = FSUSER_OpenFileDirectly(fileHandle, archive, fsMakePath(PATH_EMPTY, ""), filePath, flags, 0);
if (write) ret = FSFILE_SetSize(*fileHandle, 0); // truncate the file to remove previous contents before writing.
return ret;
}
Result deleteFile(const char *path) {
FS_ArchiveID archiveID;
FS_Path filePath = getPathInfo(path, &archiveID);
FS_Archive archive;
Result ret = FSUSER_OpenArchive(&archive, archiveID, fsMakePath(PATH_EMPTY, ""));
if (R_FAILED(ret)) return ret;
ret = FSUSER_DeleteFile(archive, filePath);
FSUSER_CloseArchive(archive);
return ret;
}
Result removeDir(const char *path) {
FS_ArchiveID archiveID;
FS_Path filePath = getPathInfo(path, &archiveID);
FS_Archive archive;
Result ret = FSUSER_OpenArchive(&archive, archiveID, fsMakePath(PATH_EMPTY, ""));
if (R_FAILED(ret)) return ret;
ret = FSUSER_DeleteDirectory(archive, filePath);
FSUSER_CloseArchive(archive);
return ret;
}
Result removeDirRecursive(const char *path) {
FS_ArchiveID archiveID;
FS_Path filePath = getPathInfo(path, &archiveID);
FS_Archive archive;
Result ret = FSUSER_OpenArchive(&archive, archiveID, fsMakePath(PATH_EMPTY, ""));
if (R_FAILED(ret)) return ret;
ret = FSUSER_DeleteDirectoryRecursively(archive, filePath);
FSUSER_CloseArchive(archive);
return ret;
}
@@ -1,45 +1,55 @@
/*
* This file is part of Universal-Updater
* Copyright (C) 2019-2020 Universal-Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "formatting.hpp"
// adapted from GM9i's byte parsing.
std::string formatBytes(int bytes) {
char out[32];
if (bytes == 1) {
snprintf(out, sizeof(out), "%d Byte", bytes);
} else if (bytes < 1024) {
snprintf(out, sizeof(out), "%d Bytes", bytes);
} else if (bytes < 1024 * 1024) {
snprintf(out, sizeof(out), "%.1f KB", (float)bytes / 1024);
} else if (bytes < 1024 * 1024 * 1024) {
snprintf(out, sizeof(out), "%.1f MB", (float)bytes / 1024 / 1024);
} else {
snprintf(out, sizeof(out), "%.1f GB", (float)bytes / 1024 / 1024 / 1024);
}
return out;
/*
* This file is part of Universal-Updater
* Copyright (C) 2019-2020 Universal-Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "lang.hpp"
#include <stdio.h>
#include <unistd.h>
static nlohmann::json appJson;
std::string Lang::get(const std::string &key) {
if (!appJson.contains(key)) return "";
return appJson.at(key).get_ref<const std::string&>();
}
void Lang::load(const std::string &lang) {
FILE *values;
/* Check if exist. */
if (access(("romfs:/lang/" + lang + "/app.json").c_str(), F_OK) == 0) {
values = fopen(std::string(("romfs:/lang/" + lang + "/app.json")).c_str(), "rt");
appJson = nlohmann::json::parse(values, nullptr, false);
fclose(values);
return;
} else {
values = fopen(("romfs:/lang/en/app.json"), "rt");
appJson = nlohmann::json::parse(values, nullptr, false);
fclose(values);
return;
}
}
-233
View File
@@ -1,233 +0,0 @@
/*
* This file is part of Universal-Updater
* Copyright (C) 2019-2020 Universal-Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "cia.hpp"
#include "download.hpp"
#include "extract.hpp"
#include "fileBrowse.hpp"
#include "gui.hpp"
#include "msg.hpp"
#include "scriptHelper.hpp"
#include "thread.hpp"
#include <fstream>
#include <regex>
#include <unistd.h>
extern bool showProgressBar;
extern ProgressBar progressbarType;
extern char progressBarMsg[128];
extern int filesExtracted;
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.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.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&>();
}
// Download from a Github Release.
Result ScriptHelper::downloadRelease(std::string repo, std::string file, std::string output, bool includePrereleases, bool showVersions, std::string message) {
std::string out;
out = std::regex_replace(output, std::regex("%3DSX%"), config->_3dsxpath().c_str());
out = std::regex_replace(out, std::regex("%NDS%"), config->ndspath().c_str());
out = std::regex_replace(out, std::regex("%ARCHIVE_DEFAULT%"), config->archivepath().c_str());
Result ret = NONE;
if (downloadFromRelease("https://github.com/" + repo, file, out, message, includePrereleases, showVersions) != 0) {
showProgressBar = false;
downloadFailed();
ret = FAILED_DOWNLOAD;
return ret;
}
showProgressBar = false;
return ret;
}
// Download a File from everywhere.
Result ScriptHelper::downloadFile(std::string file, std::string output, std::string message) {
std::string out;
out = std::regex_replace(output, std::regex("%3DSX%"), config->_3dsxpath().c_str());
out = std::regex_replace(out, std::regex("%NDS%"), config->ndspath().c_str());
out = std::regex_replace(out, std::regex("%ARCHIVE_DEFAULT%"), config->archivepath().c_str());
Result ret = NONE;
snprintf(progressBarMsg, sizeof(progressBarMsg), message.c_str());
showProgressBar = true;
progressbarType = ProgressBar::Downloading;
Threads::create((ThreadFunc)displayProgressBar);
if (downloadToFile(file, out) != 0) {
showProgressBar = false;
downloadFailed();
ret = FAILED_DOWNLOAD;
return ret;
}
showProgressBar = false;
return ret;
}
// Remove a File.
Result ScriptHelper::removeFile(std::string file, std::string message) {
std::string out;
out = std::regex_replace(file, std::regex("%ARCHIVE_DEFAULT%"), config->archivepath().c_str());
Result ret = NONE;
if (access(out.c_str(), F_OK) != 0 ) {
return DELETE_ERROR;
}
Msg::DisplayMsg(message);
deleteFile(out.c_str());
return ret;
}
// Install a file.
void ScriptHelper::installFile(std::string file, bool updatingSelf, std::string message) {
snprintf(progressBarMsg, sizeof(progressBarMsg), message.c_str());
showProgressBar = true;
progressbarType = ProgressBar::Installing;
Threads::create((ThreadFunc)displayProgressBar);
installCia(file.c_str(), updatingSelf);
showProgressBar = false;
}
// Extract Files.
void ScriptHelper::extractFile(std::string file, std::string input, std::string output, std::string message) {
std::string out, in;
in = std::regex_replace(file, std::regex("%ARCHIVE_DEFAULT%"), config->archivepath().c_str());
out = std::regex_replace(output, std::regex("%ARCHIVE_DEFAULT%"), config->archivepath().c_str());
snprintf(progressBarMsg, sizeof(progressBarMsg), message.c_str());
showProgressBar = true;
filesExtracted = 0;
progressbarType = ProgressBar::Extracting;
Threads::create((ThreadFunc)displayProgressBar);
extractArchive(in, input, out);
showProgressBar = false;
}
// Create an empty file.
Result ScriptHelper::createFile(const char * path) {
std::ofstream ofstream;
ofstream.open(path, std::ofstream::out | std::ofstream::app);
ofstream.close();
return 0;
}
// Display a Message for a specific amount of time.
void ScriptHelper::displayTimeMsg(std::string message, int seconds) {
Msg::DisplayMsg(message);
for (int i = 0; i < 60*seconds; i++) {
gspWaitForVBlank();
}
}
bool ScriptHelper::checkIfValid(std::string scriptFile, int mode) {
FILE* file = fopen(scriptFile.c_str(), "rt");
if (!file) {
printf("File not found\n");
return false;
}
nlohmann::json json = nlohmann::json::parse(file, nullptr, false);
fclose(file);
if (mode == 0) {
if (!json.contains("info")) return false;
} else if (mode == 1) {
if (!json.contains("storeInfo")) return false;
}
return true;
}
void ScriptHelper::bootTitle(const std::string TitleID, bool isNAND, std::string message) {
std::string MSG = Lang::get("BOOT_TITLE") + "\n\n";
if (isNAND) MSG += Lang::get("MEDIATYPE_NAND") + "\n" + TitleID;
else MSG += Lang::get("MEDIATYPE_SD") + "\n" + TitleID;
u64 ID = std::stoull(TitleID, 0, 16);
if (Msg::promptMsg(MSG)) {
Msg::DisplayMsg(message);
CIA_LaunchTitle(ID, isNAND ? MEDIATYPE_NAND : MEDIATYPE_SD);
}
}
Result ScriptHelper::prompt(std::string message) {
Result ret = NONE;
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) {
return COPY_ERROR;
}
Msg::DisplayMsg(message);
// If destination does not exist, create dirs.
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) {
return MOVE_ERROR;
}
Msg::DisplayMsg(message);
// TODO: Kinda avoid that?
makeDirs(newName.c_str());
rename(oldName.c_str(), newName.c_str());
return ret;
}
+458
View File
@@ -0,0 +1,458 @@
/*
* This file is part of Universal-Updater
* Copyright (C) 2019-2020 Universal-Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "animation.hpp"
#include "cia.hpp"
#include "download.hpp"
#include "extract.hpp"
#include "fileBrowse.hpp"
#include "files.hpp"
#include "scriptUtils.hpp"
#include <regex>
#include <unistd.h>
extern bool showProgressBar;
extern ProgressBar progressbarType;
extern char progressBarMsg[128];
extern int filesExtracted;
extern void downloadFailed();
static Thread thread;
bool ScriptUtils::matchPattern(const std::string &pattern, const std::string &tested) {
std::regex patternRegex(pattern);
return regex_match(tested, patternRegex);
}
/*
Remove a File.
*/
Result ScriptUtils::removeFile(const std::string &file, const std::string &message) {
std::string out;
out = std::regex_replace(file, std::regex("%ARCHIVE_DEFAULT%"), config->archPath());
Result ret = NONE;
if (access(out.c_str(), F_OK) != 0) return DELETE_ERROR;
Msg::DisplayMsg(message);
deleteFile(out.c_str());
return ret;
}
/*
Boot a title.
*/
void ScriptUtils::bootTitle(const std::string &TitleID, const bool &isNAND, const std::string &message) {
std::string MSG = Lang::get("BOOT_TITLE") + "\n\n";
if (isNAND) MSG += Lang::get("MEDIATYPE_NAND") + "\n" + TitleID;
else MSG += Lang::get("MEDIATYPE_SD") + "\n" + TitleID;
const u64 ID = std::stoull(TitleID, 0, 16);
if (Msg::promptMsg(MSG)) {
Msg::DisplayMsg(message);
CIA_LaunchTitle(ID, isNAND ? MEDIATYPE_NAND : MEDIATYPE_SD);
}
}
/*
Prompt message.
*/
Result ScriptUtils::prompt(const std::string &message) {
Result ret = NONE;
if (!Msg::promptMsg(message)) ret = SCRIPT_CANCELED;
return ret;
}
/*
Copy.
*/
Result ScriptUtils::copyFile(const std::string &source, const std::string &destination, const std::string &message) {
Result ret = NONE;
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) makeDirs(destination.c_str());
fcopy(source.c_str(), destination.c_str());
return ret;
}
/*
Rename / Move a file.
*/
Result ScriptUtils::renameFile(const std::string &oldName, const std::string &newName, const std::string &message) {
Result ret = NONE;
if (access(oldName.c_str(), F_OK) != 0) return MOVE_ERROR;
Msg::DisplayMsg(message);
/* TODO: Kinda avoid that? */
makeDirs(newName.c_str());
rename(oldName.c_str(), newName.c_str());
return ret;
}
/*
Download from GitHub Release.
*/
Result ScriptUtils::downloadRelease(const std::string &repo, const std::string &file, const std::string &output, const bool &includePrereleases, const std::string &message) {
std::string out;
out = std::regex_replace(output, std::regex("%3DSX%"), config->_3dsxPath());
out = std::regex_replace(out, std::regex("%NDS%"), config->ndsPath());
out = std::regex_replace(out, std::regex("%ARCHIVE_DEFAULT%"), config->archPath());
Result ret = NONE;
snprintf(progressBarMsg, sizeof(progressBarMsg), message.c_str());
showProgressBar = true;
progressbarType = ProgressBar::Downloading;
s32 prio = 0;
svcGetThreadPriority(&prio, CUR_THREAD_HANDLE);
thread = threadCreate((ThreadFunc)displayProgressBar, NULL, 64 * 1024, prio - 1, -2, false);
if (downloadFromRelease("https://github.com/" + repo, file, out, includePrereleases) != 0) {
showProgressBar = false;
downloadFailed();
ret = FAILED_DOWNLOAD;
threadJoin(thread, U64_MAX);
threadFree(thread);
return ret;
}
showProgressBar = false;
threadJoin(thread, U64_MAX);
threadFree(thread);
return ret;
}
/*
Download a file.
*/
Result ScriptUtils::downloadFile(const std::string &file, const std::string &output, const std::string &message) {
std::string out;
out = std::regex_replace(output, std::regex("%3DSX%"), config->_3dsxPath());
out = std::regex_replace(out, std::regex("%NDS%"), config->ndsPath());
out = std::regex_replace(out, std::regex("%ARCHIVE_DEFAULT%"), config->archPath());
Result ret = NONE;
snprintf(progressBarMsg, sizeof(progressBarMsg), message.c_str());
showProgressBar = true;
progressbarType = ProgressBar::Downloading;
s32 prio = 0;
svcGetThreadPriority(&prio, CUR_THREAD_HANDLE);
thread = threadCreate((ThreadFunc)displayProgressBar, NULL, 64 * 1024, prio - 1, -2, false);
if (downloadToFile(file, out) != 0) {
showProgressBar = false;
downloadFailed();
ret = FAILED_DOWNLOAD;
threadJoin(thread, U64_MAX);
threadFree(thread);
return ret;
}
showProgressBar = false;
threadJoin(thread, U64_MAX);
threadFree(thread);
return ret;
}
/*
Install CIA files.
*/
void ScriptUtils::installFile(const std::string &file, const bool &updatingSelf, const std::string &message) {
snprintf(progressBarMsg, sizeof(progressBarMsg), message.c_str());
showProgressBar = true;
progressbarType = ProgressBar::Installing;
s32 prio = 0;
svcGetThreadPriority(&prio, CUR_THREAD_HANDLE);
thread = threadCreate((ThreadFunc)displayProgressBar, NULL, 64 * 1024, prio - 1, -2, false);
installCia(file.c_str(), updatingSelf);
showProgressBar = false;
threadJoin(thread, U64_MAX);
threadFree(thread);
}
/*
Extract files.
*/
void ScriptUtils::extractFile(const std::string &file, const std::string &input, const std::string &output, const std::string &message) {
std::string out, in;
in = std::regex_replace(file, std::regex("%ARCHIVE_DEFAULT%"), config->archPath());
out = std::regex_replace(output, std::regex("%ARCHIVE_DEFAULT%"), config->archPath());
snprintf(progressBarMsg, sizeof(progressBarMsg), message.c_str());
showProgressBar = true;
filesExtracted = 0;
progressbarType = ProgressBar::Extracting;
s32 prio = 0;
svcGetThreadPriority(&prio, CUR_THREAD_HANDLE);
thread = threadCreate((ThreadFunc)displayProgressBar, NULL, 64 * 1024, prio - 1, -2, false);
extractArchive(in, input, out);
showProgressBar = false;
threadJoin(thread, U64_MAX);
threadFree(thread);
}
/*
Execute | run the script.
*/
Result ScriptUtils::runFunctions(const nlohmann::json &storeJson, const int &selection, const std::string &entry) {
Result ret = NONE; // No Error as of yet.
if (!storeJson.contains("storeContent")) { Msg::waitMsg(Lang::get("SYNTAX_ERROR")); return SYNTAX_ERROR; };
if ((int)storeJson["storeContent"].size() < selection) { Msg::waitMsg(Lang::get("SYNTAX_ERROR")); return SYNTAX_ERROR; };
if (!storeJson["storeContent"][selection].contains(entry)) { Msg::waitMsg(Lang::get("SYNTAX_ERROR")); return SYNTAX_ERROR; };
for(int i = 0; i < (int)storeJson["storeContent"][selection][entry].size(); i++) {
if (ret == NONE) {
std::string type = "";
if (storeJson["storeContent"][selection][entry][i].contains("type") && storeJson["storeContent"][selection][entry][i]["type"].is_string()) {
type = storeJson["storeContent"][selection][entry][i]["type"];
} else {
ret = SYNTAX_ERROR;
}
if (type == "deleteFile") {
bool missing = false;
std::string file = "", message = "";
if (storeJson["storeContent"][selection][entry][i].contains("file") && storeJson["storeContent"][selection][entry][i]["file"].is_string()) {
file = storeJson["storeContent"][selection][entry][i]["file"];
}
else missing = true;
if (storeJson["storeContent"][selection][entry][i].contains("message") && storeJson["storeContent"][selection][entry][i]["message"].is_string()) {
message = storeJson["storeContent"][selection][entry][i]["message"];
}
if (!missing) ret = ScriptUtils::removeFile(file, message);
else ret = SYNTAX_ERROR;
} else if (type == "downloadFile") {
bool missing = false;
std::string file = "", output = "", message = "";
if (storeJson["storeContent"][selection][entry][i].contains("file") && storeJson["storeContent"][selection][entry][i]["file"].is_string()) {
file = storeJson["storeContent"][selection][entry][i]["file"];
}
else missing = true;
if (storeJson["storeContent"][selection][entry][i].contains("output") && storeJson["storeContent"][selection][entry][i]["output"].is_string()) {
output = storeJson["storeContent"][selection][entry][i]["output"];
}
else missing = true;
if (storeJson["storeContent"][selection][entry][i].contains("message") && storeJson["storeContent"][selection][entry][i]["message"].is_string()) {
message = storeJson["storeContent"][selection][entry][i]["message"];
}
if (!missing) ret = ScriptUtils::downloadFile(file, output, message);
else ret = SYNTAX_ERROR;
} else if (type == "downloadRelease") {
bool missing = false, includePrereleases = false;
std::string repo = "", file = "", output = "", message = "";
if (storeJson["storeContent"][selection][entry][i].contains("repo") && storeJson["storeContent"][selection][entry][i]["repo"].is_string()) {
repo = storeJson["storeContent"][selection][entry][i]["repo"];
}
else missing = true;
if (storeJson["storeContent"][selection][entry][i].contains("file") && storeJson["storeContent"][selection][entry][i]["file"].is_string()) {
file = storeJson["storeContent"][selection][entry][i]["file"];
}
else missing = true;
if (storeJson["storeContent"][selection][entry][i].contains("output") && storeJson["storeContent"][selection][entry][i]["output"].is_string()) {
output = storeJson["storeContent"][selection][entry][i]["output"];
}
else missing = true;
if (storeJson["storeContent"][selection][entry][i].contains("includePrereleases") && storeJson["storeContent"][selection][entry][i]["includePrereleases"].is_boolean())
includePrereleases = storeJson["storeContent"][selection][entry][i]["includePrereleases"];
if (storeJson["storeContent"][selection][entry][i].contains("message") && storeJson["storeContent"][selection][entry][i]["message"].is_string()) {
message = storeJson["storeContent"][selection][entry][i]["message"];
}
if (!missing) ret = ScriptUtils::downloadRelease(repo, file, output, includePrereleases, message);
else ret = SYNTAX_ERROR;
} else if (type == "extractFile") {
bool missing = false;
std::string file = "", input = "", output = "", message = "";
if (storeJson["storeContent"][selection][entry][i].contains("file") && storeJson["storeContent"][selection][entry][i]["file"].is_string()) {
file = storeJson["storeContent"][selection][entry][i]["file"];
}
else missing = true;
if (storeJson["storeContent"][selection][entry][i].contains("input") && storeJson["storeContent"][selection][entry][i]["input"].is_string()) {
input = storeJson["storeContent"][selection][entry][i]["input"];
}
else missing = true;
if (storeJson["storeContent"][selection][entry][i].contains("output") && storeJson["storeContent"][selection][entry][i]["output"].is_string()) {
output = storeJson["storeContent"][selection][entry][i]["output"];
}
else missing = true;
if (storeJson["storeContent"][selection][entry][i].contains("message") && storeJson["storeContent"][selection][entry][i]["message"].is_string()) {
message = storeJson["storeContent"][selection][entry][i]["message"];
}
if (!missing) ScriptUtils::extractFile(file, input, output, message);
else ret = SYNTAX_ERROR;
} else if (type == "installCia") {
bool missing = false, updateSelf = false;
std::string file = "", message = "";
if (storeJson["storeContent"][selection][entry][i].contains("file") && storeJson["storeContent"][selection][entry][i]["file"].is_string()) {
file = storeJson["storeContent"][selection][entry][i]["file"];
}
else missing = true;
if (storeJson["storeContent"][selection][entry][i].contains("updateSelf") && storeJson["storeContent"][selection][entry][i]["updateSelf"].is_boolean()) {
updateSelf = storeJson["storeContent"][selection][entry][i]["updateSelf"];
}
if (storeJson["storeContent"][selection][entry][i].contains("message") && storeJson["storeContent"][selection][entry][i]["message"].is_string()) {
message = storeJson["storeContent"][selection][entry][i]["message"];
}
if (!missing) ScriptUtils::installFile(file, updateSelf, message);
else ret = SYNTAX_ERROR;
} else if (type == "mkdir") {
bool missing = false;
std::string directory = "", message = "";
if (storeJson["storeContent"][selection][entry][i].contains("directory") && storeJson["storeContent"][selection][entry][i]["directory"].is_string()) {
directory = storeJson["storeContent"][selection][entry][i]["directory"];
}
else missing = true;
if (!missing) makeDirs(directory.c_str());
else ret = SYNTAX_ERROR;
} else if (type == "rmdir") {
bool missing = false;
std::string directory = "", message = "", promptmsg = "";
if (storeJson["storeContent"][selection][entry][i].contains("directory") && storeJson["storeContent"][selection][entry][i]["directory"].is_string()) {
directory = storeJson["storeContent"][selection][entry][i]["directory"];
}
else missing = true;
promptmsg = Lang::get("DELETE_PROMPT") + "\n" + directory;
if (!missing && directory != "") {
if (access(directory.c_str(), F_OK) != 0) ret = DELETE_ERROR;
else {
if (Msg::promptMsg(promptmsg)) removeDirRecursive(directory.c_str());
}
}
else ret = SYNTAX_ERROR;
} else if (type == "promptMessage") {
std::string Message = "";
if (storeJson["storeContent"][selection][entry][i].contains("message") && storeJson["storeContent"][selection][entry][i]["message"].is_string()) {
Message = storeJson["storeContent"][selection][entry][i]["message"];
}
ret = ScriptUtils::prompt(Message);
if (ret == SCRIPT_CANCELED) {
ret = NONE;
i++; // Skip.
}
} else if (type == "copy") {
std::string Message = "", source = "", destination = "";
bool missing = false;
if (storeJson["storeContent"][selection][entry][i].contains("source") && storeJson["storeContent"][selection][entry][i]["source"].is_string()) {
source = storeJson["storeContent"][selection][entry][i]["source"];
}
else missing = true;
if (storeJson["storeContent"][selection][entry][i].contains("destination") && storeJson["storeContent"][selection][entry][i]["destination"].is_string()) {
destination = storeJson["storeContent"][selection][entry][i]["destination"];
}
else missing = true;
if (storeJson["storeContent"][selection][entry][i].contains("message") && storeJson["storeContent"][selection][entry][i]["message"].is_string()) {
Message = storeJson["storeContent"][selection][entry][i]["message"];
}
if (!missing) ret = ScriptUtils::copyFile(source, destination, Message);
else ret = SYNTAX_ERROR;
} else if (type == "move") {
std::string Message = "", oldFile = "", newFile = "";
bool missing = false;
if (storeJson["storeContent"][selection][entry][i].contains("old") && storeJson["storeContent"][selection][entry][i]["old"].is_string()) {
oldFile = storeJson["storeContent"][selection][entry][i]["old"];
}
else missing = true;
if (storeJson["storeContent"][selection][entry][i].contains("new") && storeJson["storeContent"][selection][entry][i]["new"].is_string()) {
newFile = storeJson["storeContent"][selection][entry][i]["new"];
}
else missing = true;
if (storeJson["storeContent"][selection][entry][i].contains("message") && storeJson["storeContent"][selection][entry][i]["message"].is_string()) {
Message = storeJson["storeContent"][selection][entry][i]["message"];
}
if (!missing) ret = ScriptUtils::renameFile(oldFile, newFile, Message);
else ret = SYNTAX_ERROR;
}
}
}
if (ret == NONE) doneMsg();
else if (ret == FAILED_DOWNLOAD) Msg::waitMsg(Lang::get("DOWNLOAD_ERROR"));
else if (ret == SYNTAX_ERROR) Msg::waitMsg(Lang::get("SYNTAX_ERROR"));
else if (ret == COPY_ERROR) Msg::waitMsg(Lang::get("COPY_ERROR"));
else if (ret == MOVE_ERROR) Msg::waitMsg(Lang::get("MOVE_ERROR"));
else if (ret == DELETE_ERROR) Msg::waitMsg(Lang::get("DELETE_ERROR"));
return ret;
}
-125
View File
@@ -1,125 +0,0 @@
#include "sound.h"
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
using std::string;
// Reference: http://yannesposito.com/Scratch/en/blog/2010-10-14-Fun-with-wav/
typedef struct _WavHeader {
char magic[4]; // "RIFF"
u32 totallength; // Total file length, minus 8.
char wavefmt[8]; // Should be "WAVEfmt "
u32 format; // 16 for PCM format
u16 pcm; // 1 for PCM format
u16 channels; // Channels
u32 frequency; // Sampling frequency
u32 bytes_per_second;
u16 bytes_by_capture;
u16 bits_per_sample;
char data[4]; // "data"
u32 bytes_in_data;
} WavHeader;
static_assert(sizeof(WavHeader) == 44, "WavHeader size is not 44 bytes.");
sound::sound(const string& path, int channel, bool toloop) {
ndspSetOutputMode(NDSP_OUTPUT_STEREO);
ndspSetOutputCount(2); // Num of buffers
// Reading wav file
FILE* fp = fopen(path.c_str(), "rb");
if (!fp) {
printf("Could not open the WAV file: %s\n", path.c_str());
return;
}
WavHeader wavHeader;
size_t read = fread(&wavHeader, 1, sizeof(wavHeader), fp);
if (read != sizeof(wavHeader)) {
// Short read.
printf("WAV file header is too short: %s\n", path.c_str());
fclose(fp);
return;
}
// Verify the header.
static const char RIFF_magic[4] = {'R','I','F','F'};
if (memcmp(wavHeader.magic, RIFF_magic, sizeof(wavHeader.magic)) != 0) {
// Incorrect magic number.
printf("Wrong file format.\n");
fclose(fp);
return;
}
if (wavHeader.totallength == 0 ||
(wavHeader.channels != 1 && wavHeader.channels != 2) ||
(wavHeader.bits_per_sample != 8 && wavHeader.bits_per_sample != 16)) {
// Unsupported WAV file.
printf("Corrupted wav file.\n");
fclose(fp);
return;
}
// Get the file size.
fseek(fp, 0, SEEK_END);
dataSize = ftell(fp) - sizeof(wavHeader);
// Allocating and reading samples
data = static_cast<u8*>(linearAlloc(dataSize));
fseek(fp, 44, SEEK_SET);
fread(data, 1, dataSize, fp);
fclose(fp);
dataSize /= 2; // FIXME: 16-bit or stereo?
// Find the right format
u16 ndspFormat;
if (wavHeader.bits_per_sample == 8) {
ndspFormat = (wavHeader.channels == 1) ?
NDSP_FORMAT_MONO_PCM8 :
NDSP_FORMAT_STEREO_PCM8;
} else {
ndspFormat = (wavHeader.channels == 1) ?
NDSP_FORMAT_MONO_PCM16 :
NDSP_FORMAT_STEREO_PCM16;
}
ndspChnReset(channel);
ndspChnSetInterp(channel, NDSP_INTERP_NONE);
ndspChnSetRate(channel, float(wavHeader.frequency));
ndspChnSetFormat(channel, ndspFormat);
// Create and play a wav buffer
memset(&waveBuf, 0, sizeof(waveBuf));
waveBuf.data_vaddr = reinterpret_cast<u32*>(data);
waveBuf.nsamples = dataSize / (wavHeader.bits_per_sample >> 3);
waveBuf.looping = toloop;
waveBuf.status = NDSP_WBUF_FREE;
chnl = channel;
}
sound::~sound() {
waveBuf.data_vaddr = 0;
waveBuf.nsamples = 0;
waveBuf.looping = false;
waveBuf.status = 0;
ndspChnWaveBufClear(chnl);
if (data) {
linearFree(data);
}
}
void sound::play() {
if (!data) return;
DSP_FlushDataCache(data, dataSize);
ndspChnWaveBufAdd(chnl, &waveBuf);
}
void sound::stop() {
if (!data) return;
ndspChnWaveBufClear(chnl);
}
-292
View File
@@ -1,292 +0,0 @@
/*
* This file is part of Universal-Updater
* Copyright (C) 2019-2020 Universal-Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "store.hpp"
#include <unistd.h>
Store::Store(nlohmann::json &JS, std::string JSONName) {
this->storeJson = JS;
this->updateFile = JSONName;
if (access("sdmc:/3ds/Universal-Updater/updates.json", F_OK) != 0) {
// We'd create the file here.
FILE *file = fopen("sdmc:/3ds/Universal-Updater/updates.json", "w");
this->updateJSON = nlohmann::json::parse("{}"); // So we have a valid JSON at the end.
fwrite(this->updateJSON.dump(1, '\t').c_str(), 1, this->updateJSON.dump(1, '\t').size(), file);
fclose(file);
FILE *file2 = fopen("sdmc:/3ds/Universal-Updater/updates.json", "r");
this->updateJSON = nlohmann::json::parse(file2, nullptr, false);
fclose(file2);
} else {
FILE *file = fopen("sdmc:/3ds/Universal-Updater/updates.json", "r");
this->updateJSON = nlohmann::json::parse(file, nullptr, false);
fclose(file);
}
for (int i = 0; i < (int)this->storeJson.at("storeContent").size(); i++) {
this->unsortedStore.push_back(this->getData(i));
}
this->sortedStore = this->unsortedStore; // Put that to sorted store as well.
// If Categories available, push them to our vector.
if (this->storeJson["storeInfo"].contains("categories")) {
this->availableCategories = this->storeJson["storeInfo"]["categories"].get<std::vector<std::string>>();
}
// If Authors available, push them to our vector.
if (this->storeJson["storeInfo"].contains("authors")) {
this->availableAuthors = this->storeJson["storeInfo"]["authors"].get<std::vector<std::string>>();
}
// If Systems available, push them to our vector.
if (this->storeJson["storeInfo"].contains("consoles")) {
this->availableSystems = this->storeJson["storeInfo"]["consoles"].get<std::vector<std::string>>();
}
}
bool Store::updateAvailable(int index) {
if (index > (int)this->storeJson.at("storeContent").size()) return false; // out of scope.
if (this->storeJson["storeContent"][index]["info"].contains("last_updated")) {
const std::string updateEntry = this->storeJson["storeContent"][index]["info"]["last_updated"];
const std::string entry = this->storeJson["storeContent"][index]["info"]["title"];
if (this->updateJSON.contains(this->updateFile)) {
if (this->updateJSON[this->updateFile].contains(entry)) {
const std::string updateEntry2 = (std::string)this->updateJSON[this->updateFile][entry];
return strcasecmp(updateEntry.c_str(), updateEntry2.c_str()) > 0;
} else {
return false; // Since we do not have this entry there yet.
}
} else { // Our update json don't have that yet.. so display available.
return false;
}
} else { // Since the Store doesn't have that feature.
return false;
}
return false;
}
// Here we write that to our file.
void Store::writeToFile(int index) {
FILE *file = fopen("sdmc:/3ds/Universal-Updater/updates.json", "w");
this->updateJSON[this->updateFile][this->sortedStore[index].title] = this->sortedStore[index].last_updated;
const std::string dump = this->updateJSON.dump(1, '\t');
fwrite(dump.c_str(), 1, this->updateJSON.dump(1, '\t').size(), file);
fclose(file);
this->sortedStore[index].updateAvailable = false;
}
// Here we get the data of the UniStore!
UniStoreV2Struct Store::getData(const int index) {
UniStoreV2Struct temp = {"", "", "", "", "", "" ,"", -1, 0, false};
if (index > (int)this->storeJson["storeContent"].size()) return temp; // Empty.
// Here we check.
// Title.
if (this->storeJson["storeContent"][index]["info"].contains("title")) {
temp.title = this->storeJson["storeContent"][index]["info"]["title"];
}
// Author.
if (this->storeJson["storeContent"][index]["info"].contains("author")) {
temp.author = this->storeJson["storeContent"][index]["info"]["author"];
}
// Description.
if (this->storeJson["storeContent"][index]["info"].contains("description")) {
temp.description = this->storeJson["storeContent"][index]["info"]["description"];
}
// Version.
if (this->storeJson["storeContent"][index]["info"].contains("version")) {
temp.version = this->storeJson["storeContent"][index]["info"]["version"];
}
if (this->storeJson["storeContent"][index]["info"].contains("category")) {
temp.category = this->storeJson["storeContent"][index]["info"]["category"];
}
// Console.
if (this->storeJson["storeContent"][index]["info"].contains("console")) {
temp.console = this->storeJson["storeContent"][index]["info"]["console"];
}
// Last updated.
if (this->storeJson["storeContent"][index]["info"].contains("last_updated")) {
temp.last_updated = this->storeJson["storeContent"][index]["info"]["last_updated"];
}
// Icon index.
if (this->storeJson["storeContent"][index]["info"].contains("icon_index")) {
temp.icon_index = this->storeJson["storeContent"][index]["info"]["icon_index"];
}
// Update available(?).
temp.updateAvailable = this->updateAvailable(index);
// JSON index.
temp.JSONIndex = index;
return temp;
}
int Store::searchForCategory(const std::string searchResult) {
std::vector<UniStoreV2Struct> temp;
for (int i = 0; i < (int)this->sortedStore.size(); i++) {
if (this->sortedStore[i].category == searchResult) {
temp.push_back({this->sortedStore[i]});
}
}
if (temp.size() != 0) {
this->sortedStore = temp;
}
return (int)temp.size();
}
int Store::searchForConsole(const std::string searchResult) {
std::vector<UniStoreV2Struct> temp;
for (int i = 0; i < (int)this->sortedStore.size(); i++) {
if (this->sortedStore[i].console == searchResult) {
temp.push_back({this->sortedStore[i]});
}
}
if (temp.size() != 0) {
this->sortedStore = temp;
}
return (int)temp.size();
}
int Store::searchForAuthor(const std::string searchResult) {
std::vector<UniStoreV2Struct> temp;
for (int i = 0; i < (int)this->sortedStore.size(); i++) {
if (this->sortedStore[i].author == searchResult) {
temp.push_back({this->sortedStore[i]});
}
}
if (temp.size() != 0) {
this->sortedStore = temp;
}
return (int)temp.size();
}
int Store::searchForEntries(const std::string searchResult) {
std::vector<UniStoreV2Struct> temp;
for (int i = 0; i < (int)this->sortedStore.size(); i++) {
if (this->sortedStore[i].title.find(searchResult) != std::string::npos) {
temp.push_back({this->sortedStore[i]});
}
}
if (temp.size() != 0) {
this->sortedStore = temp;
}
return (int)temp.size();
}
// Title.
bool compareTitleDescending(const UniStoreV2Struct& a, const UniStoreV2Struct& b) {
return strcasecmp(a.title.c_str(), b.title.c_str()) > 0;
}
bool compareTitleAscending(const UniStoreV2Struct& a, const UniStoreV2Struct& b) {
return strcasecmp(b.title.c_str(), a.title.c_str()) > 0;
}
// Author.
bool compareAuthorDescending(const UniStoreV2Struct& a, const UniStoreV2Struct& b) {
return strcasecmp(a.author.c_str(), b.author.c_str()) > 0;
}
bool compareAuthorAscending(const UniStoreV2Struct& a, const UniStoreV2Struct& b) {
return strcasecmp(b.author.c_str(), a.author.c_str()) > 0;
}
// Last updated.
bool compareUpdateDescending(const UniStoreV2Struct& a, const UniStoreV2Struct& b) {
return strcasecmp(a.last_updated.c_str(), b.last_updated.c_str()) > 0;
}
bool compareUpdateAscending(const UniStoreV2Struct& a, const UniStoreV2Struct& b) {
return strcasecmp(b.last_updated.c_str(), a.last_updated.c_str()) > 0;
}
void Store::sorting(bool Ascending, SortType sorttype) {
this->ascending = Ascending;
this->sorttype = sorttype;
switch(this->sorttype) {
case SortType::TITLE:
Ascending ? std::sort(this->sortedStore.begin(), this->sortedStore.end(), compareTitleAscending) : std::sort(this->sortedStore.begin(), this->sortedStore.end(), compareAuthorAscending);
break;
case SortType::AUTHOR:
Ascending ? std::sort(this->sortedStore.begin(), this->sortedStore.end(), compareTitleAscending) : std::sort(this->sortedStore.begin(), this->sortedStore.end(), compareAuthorDescending);
break;
case SortType::LAST_UPDATED:
Ascending ? std::sort(this->sortedStore.begin(), this->sortedStore.end(), compareUpdateAscending) : std::sort(this->sortedStore.begin(), this->sortedStore.end(), compareUpdateDescending);
break;
}
}
// Some return stuff with checks!
std::string Store::returnTitle(const int index) {
if (index > (int)this->sortedStore.size()) return "?"; // Out of scope.
return this->sortedStore[index].title;
}
std::string Store::returnAuthor(const int index) {
if (index > (int)this->sortedStore.size()) return "?"; // Out of scope.
return this->sortedStore[index].author;
}
std::string Store::returnDescription(const int index) {
if (index > (int)this->sortedStore.size()) return "?"; // Out of scope.
return this->sortedStore[index].description;
}
int Store::returnIconIndex(const int index) {
if (index > (int)this->sortedStore.size()) return -1; // Out of scope.
return this->sortedStore[index].icon_index;
}
int Store::returnJSONIndex(const int index) {
if (index > (int)this->sortedStore.size()) return -1; // Out of scope.
return this->sortedStore[index].JSONIndex;
}
int Store::getSize() { return (int)this->sortedStore.size(); }
+102 -11
View File
@@ -1,16 +1,107 @@
/*
* This file is part of Universal-Updater
* Copyright (C) 2019-2020 Universal-Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "common.hpp"
#include "stringutils.hpp"
bool matchPattern(std::string pattern, std::string tested) {
std::regex patternRegex(pattern);
return regex_match(tested, patternRegex);
/*
To lowercase conversion.
const std::string &str: The string which should be converted.
*/
std::string StringUtils::lower_case(const std::string &str) {
std::string lower;
transform(str.begin(), str.end(), std::back_inserter(lower), tolower); // Transform the string to lowercase.
return lower;
}
std::string StringUtils::format(const std::string& fmt_str, ...) {
va_list ap;
char* fp = NULL;
va_start(ap, fmt_str);
vasprintf(&fp, fmt_str.c_str(), ap);
va_end(ap);
std::unique_ptr<char, decltype(free)*> formatted(fp, free);
return std::string(formatted.get());
/*
Fetch strings from a vector and return it as a single string.
std::vector<std::string> fetch: The vector.
*/
std::string StringUtils::FetchStringsFromVector(const std::vector<std::string> &fetch) {
std::string temp;
if (fetch.size() < 1) return ""; // Smaller than 1 --> Return empty.
for (int i = 0; i < (int)fetch.size(); i++) {
if (i != (int)fetch.size() - 1) {
temp += fetch[i] + ", ";
} else {
temp += fetch[i];
}
}
return temp;
}
/*
adapted from GM9i's byte parsing.
*/
std::string StringUtils::formatBytes(const int bytes) {
char out[32];
if (bytes == 1) snprintf(out, sizeof(out), "%d Byte", bytes);
else if (bytes < 1024) snprintf(out, sizeof(out), "%d Bytes", bytes);
else if (bytes < 1024 * 1024) snprintf(out, sizeof(out), "%.1f KB", (float)bytes / 1024);
else if (bytes < 1024 * 1024 * 1024) snprintf(out, sizeof(out), "%.1f MB", (float)bytes / 1024 / 1024);
else snprintf(out, sizeof(out), "%.1f GB", (float)bytes / 1024 / 1024 / 1024);
return out;
}
/*
Return a vector of all marks.
*/
std::vector<std::string> StringUtils::GetMarks(int marks) {
std::vector<std::string> out;
if (marks & favoriteMarks::STAR) out.push_back( "" );
if (marks & favoriteMarks::HEART) out.push_back( "" );
if (marks & favoriteMarks::DIAMOND) out.push_back( "" );
if (marks & favoriteMarks::CLUBS) out.push_back( "" );
if (marks & favoriteMarks::SPADE) out.push_back( "" );
return out;
}
/*
Return a string of all marks.
*/
std::string StringUtils::GetMarkString(int marks) {
std::string out;
if (marks & favoriteMarks::STAR) out += "";
if (marks & favoriteMarks::HEART) out += "";
if (marks & favoriteMarks::DIAMOND) out += "";
if (marks & favoriteMarks::CLUBS) out += "";
if (marks & favoriteMarks::SPADE) out += "";
return out;
}
-21
View File
@@ -1,21 +0,0 @@
#include "thread.hpp"
#include <3ds.h>
#include <stdio.h>
#include <string.h>
static std::vector<Thread> threads;
void Threads::create(ThreadFunc entrypoint) {
s32 prio = 0;
svcGetThreadPriority(&prio, CUR_THREAD_HANDLE);
Thread thread = threadCreate((ThreadFunc)entrypoint, NULL, 64 * 1024, prio - 1, -2, false);
threads.push_back(thread);
}
void Threads::destroy(void) {
for (u32 i = 0; i < threads.size(); i++) {
threadJoin(threads.at(i), U64_MAX);
threadFree(threads.at(i));
}
}