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
commit 913475eabf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
142 changed files with 14746 additions and 15397 deletions

View file

@ -2,7 +2,7 @@ name: Build Universal-Updater
on:
push:
branches-ignore: [translation]
branches-ignore: [translation, full-rewrite]
paths-ignore:
- 'README.md'
pull_request:

3
.gitignore vendored
View file

@ -11,7 +11,7 @@
*.lst
.vscode/ipch
*.DS_Store
3ds/romfs/gfx/*.t3x
romfs/gfx/*.t3x
bannertool*
makerom*
@ -19,4 +19,3 @@ makerom*
*.nso
*.nacp
build/sprites.h
*.t3x

59
.vscode/settings.json vendored Normal file
View file

@ -0,0 +1,59 @@
{
"files.associations": {
"*.tcc": "cpp",
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"exception": "cpp",
"fstream": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"memory": "cpp",
"new": "cpp",
"ostream": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"typeinfo": "cpp",
"valarray": "cpp",
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"cstdint": "cpp",
"deque": "cpp",
"forward_list": "cpp",
"map": "cpp",
"unordered_map": "cpp",
"vector": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"optional": "cpp",
"random": "cpp",
"string": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"initializer_list": "cpp",
"bitset": "cpp",
"chrono": "cpp",
"condition_variable": "cpp",
"ratio": "cpp",
"regex": "cpp",
"shared_mutex": "cpp"
}
}

View file

@ -44,11 +44,13 @@ BANNERTOOL ?= bannertool
endif
CURRENT_VERSION := $(shell git describe --abbrev=0 --tags)
# If on a tagged commit, use the tag instead of the commit
ifneq ($(shell echo $(shell git tag -l --points-at HEAD) | head -c 1),)
GIT_VER := $(shell git tag -l --points-at HEAD)
else
GIT_VER := $(shell git rev-parse --short HEAD)
GIT_VER := $(shell git describe --abbrev=0 --tags)-$(shell git rev-parse --short HEAD)
endif
#---------------------------------------------------------------------------------
@ -76,15 +78,16 @@ endif
TARGET := Universal-Updater
BUILD := build
UNIVCORE := Universal-Core
SOURCES := $(UNIVCORE) source source/download source/gui source/lang source/overlays source/screens source/utils
SOURCES := $(UNIVCORE) source source/download source/gui source/lang source/overlays source/qr source/screens \
source/store source/utils
DATA := data
INCLUDES := $(UNIVCORE) include include/download include/gui include/lang include/overlays include/screens include/utils
INCLUDES := $(UNIVCORE) include include/download include/gui include/lang include/overlays include/qr include/screens \
include/store include/utils
GRAPHICS := assets/gfx
#GFXBUILD := $(BUILD)
ROMFS := romfs
GFXBUILD := $(ROMFS)/gfx
APP_AUTHOR := Universal-Team
APP_DESCRIPTION := A multiapp, JSON script-based updater for Nintendo 3DS
APP_DESCRIPTION := A multiapp, JSON script-based updater for Nintendo 3DS
ICON := app/icon.png
BNR_IMAGE := app/banner.png
BNR_AUDIO := app/BannerAudio.wav
@ -97,6 +100,7 @@ ARCH := -march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft
CFLAGS := -g -Wall -Wno-psabi -O2 -mword-relocations \
-DV_STRING=\"$(GIT_VER)\" \
-DC_V=\"$(CURRENT_VERSION)\" \
-fomit-frame-pointer -ffunction-sections \
$(ARCH)
@ -252,7 +256,7 @@ $(OUTPUT).cia : $(OUTPUT).elf $(OUTPUT).smdh
$(BANNERTOOL) makesmdh -i "../app/icon.png" -s "$(TARGET)" -l "$(APP_DESCRIPTION)" -p "$(APP_AUTHOR)" -o "../app/icon.bin"
$(MAKEROM) -f cia -target t -exefslogo -o "../Universal-Updater.cia" -elf "../Universal-Updater.elf" -rsf "../app/build-cia.rsf" -banner "../app/banner.bin" -icon "../app/icon.bin" -logo "../app/logo.bcma.lz" -DAPP_ROMFS="$(TOPDIR)/$(ROMFS)" -major $(VERSION_MAJOR) -minor $(VERSION_MINOR) -micro $(VERSION_MICRO) -DAPP_VERSION_MAJOR="$(VERSION_MAJOR)"
$(MAKEROM) -f cia -target t -exefslogo -o "../$(TARGET).cia" -elf "../$(TARGET).elf" -rsf "../app/build-cia.rsf" -banner "../app/banner.bin" -icon "../app/icon.bin" -logo "../app/logo.bcma.lz" -DAPP_ROMFS="$(TOPDIR)/$(ROMFS)" -major $(VERSION_MAJOR) -minor $(VERSION_MINOR) -micro $(VERSION_MICRO) -DAPP_VERSION_MAJOR="$(VERSION_MAJOR)"
#---------------------------------------------------------------------------------
# you need a rule like this for each extension you use as binary data
#---------------------------------------------------------------------------------

View file

@ -33,7 +33,7 @@ To download the source you will need to clone it with submodules, this can be do
```
git clone --recursive https://github.com/Universal-Team/Universal-Updater.git
```
or if you've already cloned it running
or if you've already cloned it running
```
git submodule update --init --recursive
```
@ -52,12 +52,9 @@ Simply run `make` in the Universal-Updater source directory.
Want to help to translate Universal-Updater? Then feel free to join us on Crowdin [here](https://crwd.in/universal-updater).
Is it a new Language which isn't available in Universal-Updater? Then join our [Discord Server](https://discord.gg/KDJCfGF) and ask Evie to add the language to crowdin.
## Contributions
## Credits
[PabloMK7](https://github.com/mariohackandglitch): For improving the Download code.
## Icon Credits
<a target="_blank" href="https://icons8.com/icons/set/trash">Trash icon</a> icon by <a target="_blank" href="https://icons8.com">Icons8</a>
<a target="_blank" href="https://icons8.com/icons/set/menu">Menu icon</a> icon by <a target="_blank" href="https://icons8.com">Icons8</a>
- [dlbeer](https://github.com/dlbeer) for [quirc](https://github.com/dlbeer/quirc) which i changed to C++.
- [FlagBrew](https://github.com/FlagBrew): For the QR Code Scanner code, which i reworked some bit.
- [Icons8](https://icons8.com/): For the icons.
- [PabloMK7](https://github.com/mariohackandglitch): For improving the Download code.

@ -1 +1 @@
Subproject commit d0d78f2bfbda1e37d1edd93fa9e3644860ed56d5
Subproject commit 155058f9a14dd376fde8f49e9d5b8666bffc6dec

View file

@ -1,26 +1,20 @@
--atlas -f rgba -z auto
sprites/arrow.png
sprites/bottom_screen_bot.png
sprites/bottom_screen_top.png
sprites/button.png
sprites/add.png
sprites/checked.png
sprites/delete.png
sprites/dev_by.png
sprites/download_all.png
sprites/dropdown.png
sprites/download.png
sprites/info.png
sprites/noIcon.png
sprites/top_screen_bot.png
sprites/top_screen_top.png
sprites/qr_code.png
sprites/search.png
sprites/selector.png
sprites/side_arrow.png
sprites/uniStore.png
sprites/uniStore_HD.png
sprites/settings.png
sprites/sort.png
sprites/sort_checked.png
sprites/sort_unchecked.png
sprites/unchecked.png
sprites/universal-updater.png
sprites/universal-core.png
sprites/update.png
sprites/updateStore.png
sprites/view.png
sprites/credits/discord.png
sprites/credits/stackZ.png
sprites/credits/universal-core.png
sprites/update_app.png
sprites/update_filter.png

BIN
assets/gfx/sprites/add.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 310 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 736 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 250 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 429 B

After

Width:  |  Height:  |  Size: 395 B

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 951 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 723 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 107 B

BIN
assets/gfx/sprites/info.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 894 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 532 B

After

Width:  |  Height:  |  Size: 426 B

Before After
Before After

Binary file not shown.

After

Width:  |  Height:  |  Size: 387 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 1 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 767 B

BIN
assets/gfx/sprites/sort.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 978 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 245 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 224 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 223 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 336 B

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 964 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 427 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 260 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 514 B

View file

@ -24,19 +24,19 @@
* reasonable ways as different from the original version.
*/
#ifndef _UNIVERSAL_UPDATER_STARTUP_HPP
#define _UNIVERSAL_UPDATER_STARTUP_HPP
#ifndef _UNIVERSAL_UPDATER_COMMON_HPP
#define _UNIVERSAL_UPDATER_COMMON_HPP
#include "common.hpp"
#include "config.hpp"
#include "gfx.hpp"
#include "lang.hpp"
#include "msg.hpp"
#include "screenCommon.hpp"
class Startup : public Screen {
public:
void Draw(void) const override;
void Logic(u32 hDown, u32 hHeld, touchPosition touch) override;
Startup(int mode = 0, std::string file = "NOT_USED");
private:
int mode = 0, delay = 150;
std::string file = "NOT_USED";
};
inline std::unique_ptr<Config> config;
#define _STORE_PATH "sdmc:/3ds/Universal-Updater/stores/"
#define _META_PATH "sdmc:/3ds/Universal-Updater/MetaData.json"
inline uint32_t hRepeat;
#endif

View file

@ -1,103 +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.
*/
#ifndef _UNIVERSAL_UPDATER_DOWNLOAD_HPP
#define _UNIVERSAL_UPDATER_DOWNLOAD_HPP
#include "common.hpp"
#define APP_TITLE "Universal-Updater"
#define VERSION_STRING "2.5.1"
// The Release Fetch struct.
struct ReleaseFetch {
std::string Target;
std::string TagName;
std::string ReleaseName;
std::string Created;
std::string Published;
bool PreRelease;
};
enum DownloadError {
DL_ERROR_NONE = 0,
DL_ERROR_WRITEFILE,
DL_ERROR_ALLOC,
DL_ERROR_STATUSCODE,
DL_ERROR_GIT,
DL_CANCEL, // No clue if that's needed tho.
};
Result downloadToFile(std::string url, std::string path);
Result downloadFromRelease(std::string url, std::string asset, std::string path, std::string Message, bool includePrereleases, bool showVersions);
void displayProgressBar();
/**
* Check Wi-Fi status.
* @return True if Wi-Fi is connected; false if not.
*/
bool checkWifiStatus(void);
/**
* Display "Please connect to Wi-Fi" for 2s.
*/
void notConnectedMsg(void);
/**
* Display "Not Implemented Yet" for 2s.
*/
void notImplemented(void);
// Display the done msg.
void doneMsg(void);
/**
* Get info from the GitHub API about a Release.
* repo is where to get from. (Ex. "RocketRobz/TWiLightMenu")
* item is that to get from the API. (Ex. "tag_name")
* @return the string from the API.
*/
std::string getLatestRelease(std::string repo, std::string item);
/**
* Get info from the GitHub API about a Commit.
* repo is where to get from. (Ex. "RocketRobz/TWiLightMenu")
* item is that to get from the API. (Ex. "sha")
* @return the string from the API.
*/
std::string getLatestCommit(std::string repo, std::string item);
/**
* Get info from the GitHub API about a Commit.
* repo is where to get from. (Ex. "RocketRobz/TWiLightMenu")
* array is the array the item is in. (Ex. "commit")
* item is that to get from the API. (Ex. "message")
* @return the string from the API.
*/
std::string getLatestCommit(std::string repo, std::string array, std::string item);
#endif

View file

@ -27,24 +27,55 @@
#ifndef _UNIVERSAL_UPDATER_GFX_HPP
#define _UNIVERSAL_UPDATER_GFX_HPP
#include "colorHelper.hpp"
#include "gui.hpp"
#include "common.hpp"
#include "sprites.h"
#include <citro2d.h>
#include <string>
extern std::unique_ptr<Config> config;
/*
Define all used Colors, for easier changes.
*/
/* Standard Colors. */
#define WHITE C2D_Color32(255, 255, 255, 255)
#define BLACK C2D_Color32(0, 0, 0, 255)
#define TRANSPARENT C2D_Color32(0, 0, 0, 0)
#define DIM_COLOR C2D_Color32(0, 0, 0, 190)
/* Bar, Text, BG Colors. */
#define TEXT_COLOR WHITE
#define BAR_COLOR C2D_Color32(50, 73, 98, 255)
#define BAR_OUTL_COLOR C2D_Color32(25, 30, 53, 255)
#define BG_COLOR C2D_Color32(38, 44, 77, 255)
/* Progressbar Colors. */
#define PROGRESSBAR_OUT_COLOR BLACK
#define PROGRESSBAR_IN_COLOR WHITE
/* Entry Colors. */
#define ENTRY_BAR_COLOR BAR_COLOR
#define ENTRY_BAR_OUTL_COLOR BAR_OUTL_COLOR
/* Entry Box Colors. */
#define BOX_INSIDE_COLOR C2D_Color32(49, 49, 49, 255)
#define BOX_SELECTED_COLOR C2D_Color32(240, 0, 0, 255)
#define BOX_UNSELECTED_COLOR BLACK
/* Search Menu Colors. */
#define SEARCH_BAR_COLOR C2D_Color32(51, 75, 102, 255)
#define SEARCH_BAR_OUTL_COLOR BAR_OUTL_COLOR
/* Sidebar Colors. */
#define SIDEBAR_SELECTED_COLOR C2D_Color32(108, 130, 155, 255)
#define SIDEBAR_UNSELECTED_COLOR C2D_Color32(77, 101, 128, 255)
namespace GFX {
// Basic GUI.
void DrawTop(void);
void DrawBottom(void);
// Draw arrow.
void DrawArrow(int x, int y, float rotation = 0, int arrowSprite = 0);
// Draw Sprites.
void DrawSprite(int img, int x, int y, float ScaleX = 1, float ScaleY = 1);
void DrawSpriteBlend(int img, int x, int y, float ScaleX = 1, float ScaleY = 1);
void DrawButton(int x, int y, std::string ButtonText = "", u32 color = config->buttonColor());
void TextFormatted(float x, float y, float size, const char *format, ...);
}
void DrawBottom();
void DrawSprite(const int &img, const int &x, const int &y, const float &ScaleX = 1, const float &ScaleY = 1);
void drawBox(const float &xPos, const float &yPos, const float &width = 50, const float &height = 50, const bool &selected = false, const uint32_t &clr = BOX_INSIDE_COLOR);
void DrawButton(const float &xPos, const float &yPos, const float &width, const float &height, const bool &selected, const std::string &Text = "");
void DrawCheckbox(const float &xPos, const float &yPos, const bool &selected);
};
#endif

View file

@ -25,15 +25,15 @@
*/
#ifndef _UNIVERSAL_UPDATER_MSG_HPP
#define UNIVERSAL_UPDATER_MSG_HPP
#define _UNIVERSAL_UPDATER_MSG_HPP
#include <string>
namespace Msg {
void DisplayMsg(std::string text);
void DisplayWarnMsg(std::string Text);
bool promptMsg(std::string promptMsg);
void DisplayStartMSG();
}
void DisplayMsg(const std::string &Text);
void DisplayWarnMsg(const std::string &Text);
bool promptMsg(const std::string &promptMsg);
void waitMsg(const std::string &msg);
};
#endif

View file

@ -30,15 +30,9 @@
#include <3ds.h>
namespace Init {
// Init, Mainloop & Exit.
Result Initialize();
Result MainLoop();
Result Exit();
// Sound / Music stuff.
void loadSoundEffects(void);
void playMusic(void);
void stopMusic(void);
}
};
#endif

View file

@ -30,9 +30,7 @@
#include <string>
namespace Input {
std::string setkbdString(uint maxLength, std::string Text);
std::uint8_t setu8(std::string Text);
int setInt(int maxValue, std::string Text);
}
std::string setkbdString(const uint &maxLength, const std::string &Text);
};
#endif

View file

@ -28,9 +28,15 @@
#define _UNIVERSAL_UPDATER_OVERLAY_HPP
#include "common.hpp"
#include "store.hpp"
#include "storeEntry.hpp"
#include <3ds.h>
namespace Overlays {
u32 SelectRGB(u32 oldColor);
}
void SelectStore(std::unique_ptr<Store> &store, std::vector<std::unique_ptr<StoreEntry>> &entries, std::unique_ptr<Meta> &meta);
void SelectLanguage();
void ShowCredits();
std::string SelectDir(const std::string &oldDir, const std::string &msg);
};
#endif

97
include/qr/qrcode.hpp Normal file
View file

@ -0,0 +1,97 @@
/*
* 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.
*/
#ifndef _UNIVERSAL_UPDATER_QR_CODE_HPP
#define _UNIVERSAL_UPDATER_QR_CODE_HPP
#include "common.hpp"
#include "quirc.hpp"
#include <atomic>
#include <3ds.h>
#include <array>
#include <vector>
class QRCode {
public:
QRCode();
~QRCode();
void drawThread();
void captureThread();
void handler(std::vector<u8>& out);
bool done() const { return finished; };
bool cancelled() const { return cancel; };
private:
void buffToImage();
void finish();
std::array<u16, 400 * 240> cameraBuffer;
LightLock bufferLock;
C2D_Image image;
LightLock imageLock;
quirc *qrData;
Handle exitEvent;
static constexpr Tex3DS_SubTexture subtex = { 512, 256, 0.0f, 1.0f, 1.0f, 0.0f };
std::atomic<bool> finished = false;
bool capturing = false;
bool cancel = false;
};
/*
This is, what should get called.
*/
namespace QR_Scanner {
/* Empty == cancelled. */
std::vector<u8> scan();
std::string GetQRURL();
};
#endif

165
include/qr/quirc.hpp Normal file
View file

@ -0,0 +1,165 @@
/* 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.
*/
#ifndef QUIRC_HPP
#define QUIRC_HPP
#include <stdint.h>
struct quirc;
/* Obtain the library version string. */
const char *quirc_version(void);
/* Construct a new QR-code recognizer. This function will return NULL
* if sufficient memory could not be allocated.
*/
struct quirc *quirc_new(void);
/* Destroy a QR-code recognizer. */
void quirc_destroy(struct quirc *q);
/* Resize the QR-code recognizer. The size of an image must be
* specified before codes can be analyzed.
*
* This function returns 0 on success, or -1 if sufficient memory could
* not be allocated.
*/
int quirc_resize(struct quirc *q, int w, int h);
/* These functions are used to process images for QR-code recognition.
* quirc_begin() must first be called to obtain access to a buffer into
* which the input image should be placed. Optionally, the current
* width and height may be returned.
*
* After filling the buffer, quirc_end() should be called to process
* the image for QR-code recognition. The locations and content of each
* code may be obtained using accessor functions described below.
*/
uint8_t *quirc_begin(struct quirc *q, int *w, int *h);
void quirc_end(struct quirc *q);
/* This structure describes a location in the input image buffer. */
struct quirc_point {
int x;
int y;
};
/* This enum describes the various decoder errors which may occur. */
typedef enum {
QUIRC_SUCCESS = 0,
QUIRC_ERROR_INVALID_GRID_SIZE,
QUIRC_ERROR_INVALID_VERSION,
QUIRC_ERROR_FORMAT_ECC,
QUIRC_ERROR_DATA_ECC,
QUIRC_ERROR_UNKNOWN_DATA_TYPE,
QUIRC_ERROR_DATA_OVERFLOW,
QUIRC_ERROR_DATA_UNDERFLOW
} quirc_decode_error_t;
/* Return a string error message for an error code. */
const char *quirc_strerror(quirc_decode_error_t err);
/* Limits on the maximum size of QR-codes and their content. */
#define QUIRC_MAX_BITMAP 3917
#define QUIRC_MAX_PAYLOAD 8896
/* QR-code ECC types. */
#define QUIRC_ECC_LEVEL_M 0
#define QUIRC_ECC_LEVEL_L 1
#define QUIRC_ECC_LEVEL_H 2
#define QUIRC_ECC_LEVEL_Q 3
/* QR-code data types. */
#define QUIRC_DATA_TYPE_NUMERIC 1
#define QUIRC_DATA_TYPE_ALPHA 2
#define QUIRC_DATA_TYPE_BYTE 4
#define QUIRC_DATA_TYPE_KANJI 8
/* Common character encodings */
#define QUIRC_ECI_ISO_8859_1 1
#define QUIRC_ECI_IBM437 2
#define QUIRC_ECI_ISO_8859_2 4
#define QUIRC_ECI_ISO_8859_3 5
#define QUIRC_ECI_ISO_8859_4 6
#define QUIRC_ECI_ISO_8859_5 7
#define QUIRC_ECI_ISO_8859_6 8
#define QUIRC_ECI_ISO_8859_7 9
#define QUIRC_ECI_ISO_8859_8 10
#define QUIRC_ECI_ISO_8859_9 11
#define QUIRC_ECI_WINDOWS_874 13
#define QUIRC_ECI_ISO_8859_13 15
#define QUIRC_ECI_ISO_8859_15 17
#define QUIRC_ECI_SHIFT_JIS 20
#define QUIRC_ECI_UTF_8 26
/* This structure is used to return information about detected QR codes
* in the input image.
*/
struct quirc_code {
/* The four corners of the QR-code, from top left, clockwise */
struct quirc_point corners[4];
/* The number of cells across in the QR-code. The cell bitmap
* is a bitmask giving the actual values of cells. If the cell
* at (x, y) is black, then the following bit is set:
*
* cell_bitmap[i << 3] & (1 << (i & 7))
*
* where i = (y * size) + x.
*/
int size;
uint8_t cell_bitmap[QUIRC_MAX_BITMAP];
};
/* This structure holds the decoded QR-code data */
struct quirc_data {
/* Various parameters of the QR-code. These can mostly be
* ignored if you only care about the data.
*/
int version;
int ecc_level;
int mask;
/* This field is the highest-valued data type found in the QR
* code.
*/
int data_type;
/* Data payload. For the Kanji datatype, payload is encoded as
* Shift-JIS. For all other datatypes, payload is ASCII text.
*/
uint8_t payload[QUIRC_MAX_PAYLOAD];
int payload_len;
/* ECI assignment number */
uint32_t eci;
};
/* Return the number of QR-codes identified in the last processed
* image.
*/
int quirc_count(const struct quirc *q);
/* Extract the QR-code specified by the given index. */
void quirc_extract(const struct quirc *q, int index,
struct quirc_code *code);
/* Decode a QR-code, returning the payload data. */
quirc_decode_error_t quirc_decode(const struct quirc_code *code,
struct quirc_data *data);
#endif

View file

@ -0,0 +1,114 @@
/* 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.
*/
#ifndef QUIRC_INTERNAL_HPP
#define QUIRC_INTERNAL_HPP
#include "quirc.hpp"
#define QUIRC_PIXEL_WHITE 0
#define QUIRC_PIXEL_BLACK 1
#define QUIRC_PIXEL_REGION 2
#ifndef QUIRC_MAX_REGIONS
#define QUIRC_MAX_REGIONS 254
#endif
#define QUIRC_MAX_CAPSTONES 32
#define QUIRC_MAX_GRIDS 8
#define QUIRC_PERSPECTIVE_PARAMS 8
#if QUIRC_MAX_REGIONS < UINT8_MAX
typedef uint8_t quirc_pixel_t;
#elif QUIRC_MAX_REGIONS < UINT16_MAX
typedef uint16_t quirc_pixel_t;
#else
#error "QUIRC_MAX_REGIONS > 65534 is not supported"
#endif
struct quirc_region {
struct quirc_point seed;
int count;
int capstone;
};
struct quirc_capstone {
int ring;
int stone;
struct quirc_point corners[4];
struct quirc_point center;
double c[QUIRC_PERSPECTIVE_PARAMS];
int qr_grid;
};
struct quirc_grid {
/* Capstone indices */
int caps[3];
/* Alignment pattern region and corner */
int align_region;
struct quirc_point align;
/* Timing pattern endpoints */
struct quirc_point tpep[3];
int hscan;
int vscan;
/* Grid size and perspective transform */
int grid_size;
double c[QUIRC_PERSPECTIVE_PARAMS];
};
struct quirc {
uint8_t *image;
quirc_pixel_t *pixels;
int w;
int h;
int num_regions;
struct quirc_region regions[QUIRC_MAX_REGIONS];
int num_capstones;
struct quirc_capstone capstones[QUIRC_MAX_CAPSTONES];
int num_grids;
struct quirc_grid grids[QUIRC_MAX_GRIDS];
};
/************************************************************************
* QR-code version information database
*/
#define QUIRC_MAX_VERSION 40
#define QUIRC_MAX_ALIGNMENT 7
struct quirc_rs_params {
int bs; /* Block size */
int dw; /* Data words */
int ce; /* Correctable errors */
};
struct quirc_version_info {
int data_bytes;
int apat[QUIRC_MAX_ALIGNMENT];
struct quirc_rs_params ecc[4];
};
extern const struct quirc_version_info quirc_version_db[QUIRC_MAX_VERSION + 1];
#endif

View file

@ -24,29 +24,41 @@
* reasonable ways as different from the original version.
*/
#ifndef _UNIVERSAL_UPDATER_CREDITS_HPP
#define _UNIVERSAL_UPDATER_CREDITS_HPP
#ifndef _UNIVERSAL_UPDATER_MAIN_SCREEN_HPP
#define _UNIVERSAL_UPDATER_MAIN_SCREEN_HPP
#include "common.hpp"
#include "structs.hpp"
#include "store.hpp"
#include "storeEntry.hpp"
#include "storeUtils.hpp"
#include <vector>
/*
Modes:
class Credits : public Screen {
0: Entry Info.
1: Download List.
2: Search + Favorites.
3: Sorting.
4: Settings / Credits(?).
*/
class MainScreen : public Screen {
public:
MainScreen();
void Draw(void) const override;
void Logic(u32 hDown, u32 hHeld, touchPosition touch) override;
private:
void DrawBottom(void) const;
int creditsPage = 0;
int screenPos = 0;
int Selection = 0;
int keyRepeatDelay = 0;
std::unique_ptr<Store> store = nullptr;
std::unique_ptr<Meta> meta = nullptr;
std::vector<std::unique_ptr<StoreEntry>> entries;
std::vector<std::string> dwnldList;
bool initialized = false, fetchDown = false, showMarks = false, showSettings = false, ascending = false, updateFilter = false;
int storeMode = 0, marks = 0, markIndex = 0, sPage = 0, lMode = 0, sSelection = 0, lastMode = 0, smallDelay = 0;
SortType sorttype = SortType::LAST_UPDATED;
const std::vector<Structs::ButtonPos> arrowPos = {
{0, 215, 25, 25}, // Back Arrow.
{295, 215, 25, 25} // Next Page.
};
/* Title, Author, Category, Console. */
std::vector<bool> searchIncludes = { false, false, false, false };
std::string searchResult = "";
};
#endif

View file

@ -1,87 +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.
*/
#ifndef _UNIVERSAL_UPDATER_SCRIPT_BROWSE_HPP
#define _UNIVERSAL_UPDATER_SCRIPT_BROWSE_HPP
#include "common.hpp"
#include "fileBrowse.hpp"
#include "structs.hpp"
#include <vector>
class ScriptBrowse : public Screen {
public:
void Draw(void) const override;
void Logic(u32 hDown, u32 hHeld, touchPosition touch) override;
ScriptBrowse();
private:
// Selection.
mutable int screenPos = 0;
mutable int screenPosList = 0;
mutable int Selection = 0;
int dropSelection = 0;
int mode = 0;
bool dropDownMenu = false;
bool loaded = false;
// Draws.
void DrawBrowse(void) const;
void DrawGlossary(void) const;
void DropDownLogic(u32 hDown, u32 hHeld, touchPosition touch);
nlohmann::json infoJson;
int maxScripts;
// Browse stuff.
int keyRepeatDelay = 0;
std::vector<DirEntry> dirContents;
void refresh();
void downloadAll();
// Button | Icon struct.
const std::vector<Structs::ButtonPos> arrowPos = {
{295, 0, 25, 25}, // Arrow Up.
{295, 215, 25, 25}, // Arrow Down.
{0, 215, 25, 25}, // Back Arrow.
{5, 0, 25, 25} // Dropdown Menu.
};
// DropDownMenu.
const std::vector<Structs::ButtonPos> dropPos = {
{5, 30, 25, 25}, // Download All.
{5, 70, 25, 25}, // Refresh.
{5, 110, 25, 25} // ViewMode.
};
const std::vector<Structs::ButtonPos> dropPos2 = {
{0, 28, 140, 30}, // Download All.
{0, 68, 140, 30}, // Refresh.
{0, 108, 140, 30} // ViewMode.
};
};
#endif

View file

@ -1,113 +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.
*/
#ifndef _UNIVERSAL_UPDATER_SCRIPT_CREATOR_HPP
#define _UNIVERSAL_UPDATER_SCRIPT_CREATOR_HPP
#include "common.hpp"
#include "json.hpp"
#include "structs.hpp"
#include <vector>
class ScriptCreator : public Screen {
public:
void Draw(void) const override;
void Logic(u32 hDown, u32 hHeld, touchPosition touch) override;
private:
std::string entryName = "";
// Screen draws.
void DrawSubMenu(void) const;
void DrawScriptScreen(void) const;
void SubMenuLogic(u32 hDown, u32 hHeld, touchPosition touch);
void scriptLogic(u32 hDown, u32 hHeld, touchPosition touch);
// Selection + Mode.
int Selection = 0;
int mode = 0;
int page = 0;
// Functions.
void openJson(std::string fileName);
void createNewJson(std::string fileName);
void save();
void setInfoStuff(void);
// Creating Functions. -> Page 1.
void createDownloadRelease();
void createDownloadFile();
void createDeleteFile();
void createExtractFile();
void createInstallCia();
void createMkDir();
// Creating Functions. -> Page 2.
void createRmDir();
void createMkFile();
void createTimeMsg();
void createSaveConfig();
void createBootTitle();
void createPromptMessage();
// Creating Functions. -> Page 3.
void createCopy();
void createMove();
//
void setBool(const std::string &object, const std::string &key, bool v);
void setBool2(const std::string &object, const std::string &key, const std::string &key2, bool v);
void setInt(const std::string &object, const std::string &key, int v);
void setInt2(const std::string &object, const std::string &key, const std::string &key2, int v);
void setString(const std::string &object, const std::string &key, const std::string &v);
void setString2(const std::string &object, const std::string &key, const std::string &key2, const std::string &v);
void createEntry(const std::string &Entryname);
std::string jsonFileName;
nlohmann::json editScript;
// Main Pos.
const std::vector<Structs::ButtonPos> mainButtons = {
{90, 40, 140, 35}, // New Script.
{90, 100, 140, 35} // Existing Script.
};
// Creator Button Pos.
const std::vector<Structs::ButtonPos> creatorButtons = {
{10, 40, 140, 35},
{170, 40, 140, 35},
{10, 100, 140, 35},
{170, 100, 140, 35},
{10, 160, 140, 35},
{170, 160, 140, 35}
};
};
#endif

View file

@ -1,115 +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.
*/
#ifndef _UNIVERSAL_UPDATER_SCRIPT_LIST_HPP
#define _UNIVERSAL_UPDATER_SCRIPT_LIST_HPP
#include "common.hpp"
#include "fileBrowse.hpp"
#include "scriptHelper.hpp"
#include "structs.hpp"
#include <vector>
class ScriptList : public Screen {
public:
void Draw(void) const override;
void Logic(u32 hDown, u32 hHeld, touchPosition touch) override;
ScriptList(); // In case of "Autoboot", have a Constructor which handles stuff.
private:
// Screen Mode.
int mode = 0;
int lastMode = 1;
// Helper functions.
void deleteScript(int selectedScript);
void refreshList();
nlohmann::json openScriptFile();
bool checkForValidate(void);
void loadDesc(void);
Result runFunctions(nlohmann::json &json);
// Draw Functions.
void DrawSubMenu(void) const;
void DrawList(void) const;
void DrawSingleObject(void) const;
void DrawGlossary(void) const;
// Logic Functions.
void SubMenuLogic(u32 hDown, u32 hHeld, touchPosition touch);
void ListSelection(u32 hDown, u32 hHeld, touchPosition touch);
void SelectFunction(u32 hDown, u32 hHeld, touchPosition touch);
// This is for the Script Creator, so no one can access it for now, until it is stable or so.
bool isTesting = true;
// Other includes which get destructed automatically.
std::string choice;
std::string currentFile;
std::string selectedTitle;
std::string Desc = "";
nlohmann::json jsonFile;
std::vector<ScriptInfo> fileInfo;
std::vector<std::string> fileInfo2;
std::vector<std::string> lines;
mutable int screenPos = 0;
mutable int screenPosList = 0;
mutable int Selection = 0;
int dropSelection = 0;
bool dropDownMenu = false;
// Browse stuff.
int keyRepeatDelay = 0;
std::vector<DirEntry> dirContents;
// Button | Icon structs.
const std::vector<Structs::ButtonPos> arrowPos = {
{295, 0, 25, 25}, // Arrow Up.
{295, 215, 25, 25}, // Arrow Down.
{0, 215, 25, 25}, // Back Arrow.
{5, 0, 25, 25} // Dropdown Menu.
};
const std::vector<Structs::ButtonPos> subPos = {
{0, 60, 149, 52}, // Script list.
{162, 60, 149, 52}, // Get Scripts.
{0, 130, 149, 52}, // Script Creator.
{162, 130, 149, 52} // Script path change.
};
// DropDownMenu.
const std::vector<Structs::ButtonPos> dropPos = {
{5, 30, 25, 25}, // Delete.
{5, 70, 25, 25} // ViewMode.
};
const std::vector<Structs::ButtonPos> dropPos2 = {
{0, 28, 140, 30}, // Delete.
{0, 68, 140, 30} // ViewMode.
};
};
#endif

View file

@ -1,83 +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.
*/
#ifndef _UNIVERSAL_UPDATER_SETTINGS_HPP
#define _UNIVERSAL_UPDATER_SETTINGS_HPP
#include "common.hpp"
#include "fileBrowse.hpp"
#include "structs.hpp"
#include <vector>
class Settings : public Screen {
public:
void Draw(void) const override;
void Logic(u32 hDown, u32 hHeld, touchPosition touch) override;
Settings();
private:
int colorMode = 0;
int mode = 0;
int Selection = 0;
bool dropDownMenu = false;
mutable int screenPos = 0;
int colorSelection = 0;
int keyRepeatDelay = 0;
int settingPage = 0;
// Draws.
void DrawSubMenu(void) const;
void DrawLanguageSelection(void) const;
void DrawColorChanging(void) const;
// Logic's.
void SubMenuLogic(u32 hDown, u32 hHeld, touchPosition touch);
void LanguageSelection(u32 hDown, u32 hHeld, touchPosition touch);
void colorChanging(u32 hDown, u32 hHeld, touchPosition touch);
const std::vector<Structs::ButtonPos> mainButtons = {
{80, 30, 149, 52}, // Language.
{80, 90, 149, 52}, // Colors.
{80, 150, 149, 52} // Credits.
};
const std::vector<Structs::ButtonPos> mainButtons2 = {
{0, 60, 149, 52}, // Change Music File.
{162, 60, 149, 52}, // Change bar style.
{0, 130, 149, 52}, // Change Key Delay.
{162, 130, 149, 52} // Toggle animation.
};
const std::vector<Structs::ButtonPos> arrowPos = {
{0, 0, 25, 25}, // Previous Arrow.
{295, 0, 25, 25}, // Next Arrow.
{0, 215, 25, 25}, // Back Arrow.
{0, 0, 25, 25}, // Back Arrow top left.
{295, 215, 25, 25}, // Next Page / Misc Arrow.
{5, 0, 25, 25} // Dropdown Menu.
};
};
#endif

View file

@ -1,134 +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.
*/
#ifndef _UNIVERSAL_UPDATER_UNISTORE_HPP
#define _UNIVERSAL_UPDATER_UNISTORE_HPP
#include "common.hpp"
#include "fileBrowse.hpp"
#include "scriptHelper.hpp"
#include "structs.hpp"
#include <vector>
class UniStore : public Screen {
public:
void Draw(void) const override;
void Logic(u32 hDown, u32 hHeld, touchPosition touch) override;
UniStore(bool doAutoboot, std::string file);
private:
bool doAutoboot = false;
std::string autobootFile = "";
void refreshList();
nlohmann::json openStoreFile();
void loadStoreDesc(void);
StoreInfo parseStoreInfo(std::string fileName);
void autobootLogic();
void DrawSubMenu(void) const;
void DrawStoreList(void) const;
void DrawSearch(void) const;
void DrawFullURLScreen(void) const;
void DrawGitHubScreen(void) const;
void SubMenuLogic(u32 hDown, u32 hHeld, touchPosition touch);
void StoreSelectionLogic(u32 hDown, u32 hHeld, touchPosition touch);
void SearchLogic(u32 hDown, u32 hHeld, touchPosition touch);
void FullURLLogic(u32 hDown, u32 hHeld, touchPosition touch);
void GitHubLogic(u32 hDown, u32 hHeld, touchPosition touch);
void descript();
void updateStore(int selectedStore);
void deleteStore(int selectedStore);
bool handleIfDisplayText();
int mode = 0;
bool displayInformations = true;
// Stuff for the GitHub Store Search function and Full URL.
std::string OwnerAndRepo = "";
std::string fileName = "";
std::string FullURL = "";
// Selections.
mutable int Selection = 0;
int screenPos = 0;
mutable int screenPosList = 0;
bool dropDownMenu = false;
int dropSelection = 0;
// Browse stuff.
int keyRepeatDelay = 0;
std::vector<DirEntry> dirContents;
// Other stuff.
std::vector<StoreInfo> storeInfo; // Store Selection.
std::vector<std::string> descLines;
std::string storeDesc = "";
nlohmann::json JSON;
std::string currentStoreFile;
// Icon | Button Structs.
const std::vector<Structs::ButtonPos> arrowPos = {
{295, 0, 25, 25}, // Arrow Up.
{295, 215, 25, 25}, // Arrow Down.
{0, 215, 25, 25}, // Back Arrow.
{5, 0, 25, 25} // Dropdown Menu.
};
const std::vector<Structs::ButtonPos> URLBtn = {
{0, 60, 149, 52}, // FULL URL.
{162, 60, 149, 52}, // GitHub.
{0, 130, 149, 52}, // TinyDB.
{162, 130, 149, 52} // Universal-DB.
};
const std::vector<Structs::ButtonPos> GitHubPos = {
{30, 50, 260, 30}, // Owner & Repo.
{30, 130, 260, 30}, // Filename.
{135, 180, 50, 30} // OK.
};
const std::vector<Structs::ButtonPos> subPos = {
{80, 30, 149, 52}, // StoreList.
{80, 90, 149, 52}, // storeSearch.
{80, 150, 149, 52} // storePathChange.
};
// DropDownMenu.
const std::vector<Structs::ButtonPos> dropPos = {
{5, 30, 25, 25}, // Delete.
{5, 70, 25, 25}, // Update.
{5, 110, 25, 25} // ViewMode.
};
const std::vector<Structs::ButtonPos> dropPos2 = {
{0, 28, 140, 30}, // Delete.
{0, 68, 140, 30}, // Update.
{0, 108, 140, 30} // ViewMode.
};
};
#endif

View file

@ -1,75 +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.
*/
#ifndef _UNIVERSAL_UPDATER_UNIVERSAL_STORE_V1_HPP
#define _UNIVERSAL_UPDATER_UNIVERSAL_STORE_V1_HPP
#include "common.hpp"
#include "json.hpp"
#include "structs.hpp"
#include <citro2d.h>
#include <vector>
class UniStoreV1 : public Screen {
public:
void Draw(void) const override;
void Logic(u32 hDown, u32 hHeld, touchPosition touch) override;
UniStoreV1(nlohmann::json &JSON, const std::string sheetPath, bool displayInf);
~UniStoreV1();
private:
// Selections.
mutable int Selection = 0;
bool sheetHasLoaded = false;
int screenPos = 0;
mutable int screenPosList = 0;
bool dropDownMenu = false;
int dropSelection = 0;
int keyRepeatDelay = 0;
nlohmann::json storeJson;
C2D_SpriteSheet sheet;
std::vector<std::string> objects;
mutable bool displayInformations = true;
void drawBlend(int key, int x, int y) const;
void parseObjects();
Result execute();
// Icon | Button Structs.
const std::vector<Structs::ButtonPos> arrowPos = {
{295, 0, 25, 25}, // Arrow Up.
{295, 215, 25, 25}, // Arrow Down.
{0, 215, 25, 25}, // Back Arrow.
{5, 0, 25, 25} // Dropdown Menu.
};
// DropDownMenu.
const std::vector<Structs::ButtonPos> dropPos = {
{5, 30, 140, 30}, // Delete.
{5, 70, 140, 30}, // Update.
{5, 110, 140, 30} // ViewMode.
};
};
#endif

View file

@ -1,135 +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.
*/
#ifndef _UNIVERSAL_UPDATER_UNIVERSAL_STORE_V2_HPP
#define _UNIVERSAL_UPDATER_UNIVERSAL_STORE_V2_HPP
#include "common.hpp"
#include "json.hpp"
#include "store.hpp"
#include "structs.hpp"
#include <citro2d.h>
#include <vector>
class UniStoreV2 : public Screen {
public:
void Draw(void) const override;
void Logic(u32 hDown, u32 hHeld, touchPosition touch) override;
UniStoreV2(nlohmann::json &JSON, const std::string sheetPath, const std::string fileName);
~UniStoreV2();
private:
std::unique_ptr<Store> sortedStore;
bool darkMode = true, sheetLoaded = false, canDisplay = false, hasLoaded = false, isDropDown = false;
int selectMenu = 0, selectedObject = 0, selectedBox = 0, lastViewMode = 0, dropSelection = 0, searchSelection = 0, iconAmount = 0, categorySelection = 0, selectedBoxList = 0, selection = -1, storePage = 0, downloadPage = 0, storePageList = 0, mode = 0, subSelection = 0, categoryPage = 0;
nlohmann::json storeJson;
C2D_SpriteSheet sheet;
std::vector<std::string> objects;
void DrawSortingMenu(void) const;
void DrawSearchMenu(void) const;
void DrawSelectMenu(int option) const;
// Base stuff.
void DrawBaseTop(void) const;
void DrawBaseBottom(void) const;
void drawBox(float xPos, float yPos, float width, float height, bool selected) const;
void DrawGrid(void) const;
void DrawDescription(int selection) const;
u32 returnTextColor() const;
void parseObjects(int selection);
Result runFunctions(std::string entry);
void DrawList(void) const;
void displaySelectedEntry(int selection, int storeIndex) const;
void DropLogic(u32 hDown, u32 hHeld, touchPosition touch);
void DropDownMenu(void) const;
const std::vector<Structs::ButtonPos> StoreBoxesGrid = {
{25, 35, 50, 50},
{100, 35, 50, 50},
{175, 35, 50, 50},
{250, 35, 50, 50},
{325, 35, 50, 50},
{25, 95, 50, 50},
{100, 95, 50, 50},
{175, 95, 50, 50},
{250, 95, 50, 50},
{325, 95, 50, 50},
{25, 155, 50, 50},
{100, 155, 50, 50},
{175, 155, 50, 50},
{250, 155, 50, 50},
{325, 155, 50, 50}
};
const std::vector<Structs::ButtonPos> StoreBoxesList = {
{20, 35, 360, 50},
{20, 95, 360, 50},
{20, 155, 360, 50}
};
const std::vector<Structs::ButtonPos> downloadBoxes = {
{10, 40, 300, 25},
{10, 75, 300, 25},
{10, 110, 300, 25},
{10, 145, 300, 25},
{10, 180, 300, 25}
};
const std::vector<Structs::ButtonPos> iconPos = {
{5, 0, 25, 25} // Dropdown Menu.
};
const std::vector<Structs::ButtonPos> dropPos = {
{5, 30, 140, 25}, // Theme.
{5, 70, 140, 25}, // Style.
{5, 110, 140, 25},// Search.
{5, 150, 140, 25} // Reset.
};
const std::vector<Structs::ButtonPos> sortingPos = {
{40, 40, 100, 40}, // Descending.
{180, 40, 100, 40}, // Ascending.
// Now the actual options.
{115, 90, 100, 30}, // Title.
{115, 130, 100, 30}, // Author.
{115, 170, 100, 30} // Last Updated.
};
const std::vector<Structs::ButtonPos> searchPos = {
{0, 60, 149, 52}, // Title.
{162, 60, 149, 52}, // Author.
{0, 130, 149, 52}, // Category.
{162, 130, 149, 52} // Console.
};
u32 barColorLight, barColorDark, bgColorLight, bgColorDark, textColorLight, textColorDark, boxColorLight, boxColorDark, outlineColorLight, outlineColorDark;
};
#endif

View file

@ -24,28 +24,41 @@
* reasonable ways as different from the original version.
*/
#ifndef _UNIVERSAL_UPDATER_MAINMENU_HPP
#define _UNIVERSAL_UPDATER_MAINMENU_HPP
#ifndef _UNIVERSAL_UPDATER_META_HPP
#define _UNIVERSAL_UPDATER_META_HPP
#include "common.hpp"
#include "structs.hpp"
#include "json.hpp"
#include <string>
#include <vector>
enum favoriteMarks {
STAR = 1 << 0,
HEART = 1 << 1,
DIAMOND = 1 << 2,
CLUBS = 1 << 3,
SPADE = 1 << 4
};
class MainMenu : public Screen {
class Meta {
public:
void Draw(void) const override;
void Logic(u32 hDown, u32 hHeld, touchPosition touch) override;
private:
int Selection = 0;
Meta();
~Meta() { this->SaveCall(); };
const std::vector<Structs::ButtonPos> mainButtons = {
{0, 60, 149, 52}, // UniStore.
{162, 60, 149, 52}, // Scripts.
{0, 130, 149, 52}, // Settings.
{162, 130, 149, 52}, // FTP.
{0, 215, 25, 25} // Back Arrow.
std::string GetUpdated(std::string unistoreName, std::string entry) const;
int GetMarks(std::string unistoreName, std::string entry) const;
bool UpdateAvailable(std::string unistoreName, std::string entry, std::string updated) const;
void SetUpdated(std::string unistoreName, std::string entry, std::string updated) {
this->metadataJson[unistoreName][entry]["updated"] = updated;
};
void SetMarks(std::string unistoreName, std::string entry, int marks) {
this->metadataJson[unistoreName][entry]["marks"] = marks;
};
void ImportMetadata();
void SaveCall();
private:
nlohmann::json metadataJson = nullptr;
};
#endif

86
include/store/store.hpp Normal file
View file

@ -0,0 +1,86 @@
/*
* 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.
*/
#ifndef _UNIVERSAL_UPDATER_STORE_HPP
#define _UNIVERSAL_UPDATER_STORE_HPP
#include "json.hpp"
#include <citro2d.h>
#include <string>
class Store {
public:
Store(const std::string &file);
~Store();
void LoadFromFile(const std::string &file);
void loadSheets();
void unloadSheets();
void update(const std::string &file);
/* Get Information of the UniStore itself. */
std::string GetUniStoreTitle() const;
std::string GetUniStoreAuthor() const;
/* Get Information of the UniStore Entries. */
std::string GetTitleEntry(const int &index) const;
std::string GetAuthorEntry(const int &index) const;
std::string GetDescriptionEntry(const int &index) const;
std::vector<std::string> GetCategoryIndex(const int &index) const;
std::string GetVersionEntry(const int &index) const;
std::vector<std::string> GetConsoleEntry(const int &index) const;
std::string GetLastUpdatedEntry(const int &index) const;
std::string GetLicenseEntry(const int &index) const;
C2D_Image GetIconEntry(const int &index) const;
std::vector<std::string> GetDownloadList(const int &index) const;
int GetStoreSize() const { return (int)this->storeJson["storeContent"].size(); };
int GetScreenIndx() const { return this->screenIndex; };
void SetScreenIndx(int v) { this->screenIndex = v; };
int GetEntry() const { return this->entry; };
void SetEntry(int v) { this->entry = v; };
int GetBox() const { return this->box; };
void SetBox(int v) { this->box = v; };
int GetDownloadSIndex() const { return this->downIndex; };
void SetDownloadSIndex(int v) { this->downIndex = v; };
int GetDownloadIndex() const { return this->downEntry; };
void SetDownloadIndex(int v) { this->downEntry = v; };
nlohmann::json &GetJson() { return this->storeJson; };
bool GetValid() const { return this->valid; };
private:
nlohmann::json storeJson = nullptr;
std::vector<C2D_SpriteSheet> sheets;
bool valid = false;
int screenIndex = 0, entry = 0, box = 0, downEntry = 0, downIndex = 0;
};
#endif

View file

@ -0,0 +1,72 @@
/*
* 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.
*/
#ifndef _UNIVERSAL_UPDATER_STORE_ENTRY_HPP
#define _UNIVERSAL_UPDATER_STORE_ENTRY_HPP
#include "meta.hpp"
#include "store.hpp"
#include "stringutils.hpp"
class StoreEntry {
public:
StoreEntry(const std::unique_ptr<Store> &store, const std::unique_ptr<Meta> &meta, const int &index);
std::string GetTitle() const { return this->Title; };
std::string GetAuthor() const { return this->Author; };
std::string GetDescription() const { return this->Description; };
std::string GetCategory() const { return this->Category; };
std::string GetVersion() const { return this->Version; };
std::string GetConsole() const { return this->Console; };
std::string GetLastUpdated() const { return this->LastUpdated; };
std::string GetLicense() const { return this->License; };
int GetMarks() const { return this->Marks; };
C2D_Image GetIcon() const { return this->Icon; };
int GetSheetIndex() const { return this->SheetIndex; };
int GetEntryIndex() const { return this->EntryIndex; };
std::vector<std::string> GetCategoryFull() const { return this->FullCategory; };
std::vector<std::string> GetConsoleFull() const { return this->FullConsole; };
bool GetUpdateAvl() const { return this->UpdateAvailable; };
void SetUpdateAvl(const bool &v) { this->UpdateAvailable = v; };
void SetMark(const int &marks) {
this->Marks = marks;
this->MarkString = StringUtils::GetMarkString(this->Marks);
};
private:
std::string Title, Author, Description, Category, Version, Console, LastUpdated, License, MarkString;
C2D_Image Icon;
int SheetIndex, EntryIndex, Marks;
std::vector<std::string> FullCategory, FullConsole;
bool UpdateAvailable;
};
#endif

View file

@ -0,0 +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.
*/
#ifndef _UNIVERSAL_UPDATER_STORE_UTILS_HPP
#define _UNIVERSAL_UPDATER_STORE_UTILS_HPP
#include "common.hpp"
#include "store.hpp"
#include "storeEntry.hpp"
#include <vector>
enum class SortType : uint8_t {
TITLE,
AUTHOR,
LAST_UPDATED
};
namespace StoreUtils {
/* Grid. */
void DrawGrid(const std::unique_ptr<Store> &store, const std::vector<std::unique_ptr<StoreEntry>> &entries);
void 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);
/* Top List. */
void DrawList(const std::unique_ptr<Store> &store, const std::vector<std::unique_ptr<StoreEntry>> &entries);
void 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);
/* Entry Info. */
void DrawEntryInfo(const std::unique_ptr<Store> &store, const std::unique_ptr<StoreEntry> &entry);
void EntryHandle(u32 hDown, u32 hHeld, touchPosition touch, bool &showMark, bool &fetch);
/* Side Menu. */
void DrawSideMenu(const int &currentMenu);
void SideMenuHandle(u32 hDown, touchPosition touch, int &currentMenu, bool &fetch);
/* Download Entries. */
void DrawDownList(const std::unique_ptr<Store> &store, const std::vector<std::string> &entries, const bool &fetch);
void 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);
/* Search + Favorite Menu. */
void DrawSearchMenu(const std::vector<bool> &searchIncludes, const std::string &searchResult, const int &marks, const bool &updateFilter);
void 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);
/* Mark Menu. */
void DisplayMarkBox(const int &marks);
void 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);
/* Credits. */
void DrawCredits();
/* Settings. */
void DrawSettings(const int &page, const int &selection);
void 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);
/* Sorting. */
void DrawSorting(const bool &asc, const SortType &st);
void SortHandle(u32 hDown, u32 hHeld, touchPosition touch, std::unique_ptr<Store> &store, std::vector<std::unique_ptr<StoreEntry>> &entries, bool &asc, SortType &st);
bool compareTitleDescending(const std::unique_ptr<StoreEntry> &a, const std::unique_ptr<StoreEntry> &b);
bool compareTitleAscending(const std::unique_ptr<StoreEntry> &a, const std::unique_ptr<StoreEntry> &b);
bool compareAuthorDescending(const std::unique_ptr<StoreEntry> &a, const std::unique_ptr<StoreEntry> &b);
bool compareAuthorAscending(const std::unique_ptr<StoreEntry> &a, const std::unique_ptr<StoreEntry> &b);
bool compareUpdateDescending(const std::unique_ptr<StoreEntry> &a, const std::unique_ptr<StoreEntry> &b);
bool compareUpdateAscending(const std::unique_ptr<StoreEntry> &a, const std::unique_ptr<StoreEntry> &b);
void SortEntries(const bool &Ascending, const SortType &sorttype, std::vector<std::unique_ptr<StoreEntry>> &entries);
void search(std::vector<std::unique_ptr<StoreEntry>> &entries, const std::string &query, bool title, bool author, bool category, bool console, int selectedMarks, bool updateAvl);
void FilterUpdateAvailable(std::vector<std::unique_ptr<StoreEntry>> &entries);
void ResetAll(const std::unique_ptr<Store> &store, const std::unique_ptr<Meta> &meta, std::vector<std::unique_ptr<StoreEntry>> &entries);
};
#endif

View file

@ -37,10 +37,7 @@ enum class ProgressBar {
};
namespace Animation {
// Progressbar.
void DrawProgressBar(u64 currentProgress, u64 totalProgress);
// Draw Button.
void Button(int x, int y, float speed = .030);
}
void DrawProgressBar(const u64 &currentProgress, const u64 &totalProgress);
};
#endif

View file

@ -1,3 +1,29 @@
/*
* 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.
*/
#ifndef _UNIVERSAL_UPDATER_CIA_HPP
#define _UNIVERSAL_UPDATER_CIA_HPP
@ -5,8 +31,8 @@
#include <3ds.h>
Result CIA_LaunchTitle(u64 titleId, FS_MediaType mediaType);
Result deletePrevious(u64 titleid, FS_MediaType media);
Result installCia(const char * ciaPath, bool updateSelf);
Result CIA_LaunchTitle(const u64 &titleId, const FS_MediaType &mediaType);
Result deletePrevious(const u64 &titleid, const FS_MediaType &media);
Result installCia(const char *ciaPath, const bool &updateSelf);
#endif

View file

@ -1,60 +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.
*/
#ifndef _UNIVERSAL_UPDATER_COLOR_HELPER_HPP
#define _UNIVERSAL_UPDATER_COLOR_HELPER_HPP
#include <citro2d.h>
#include <citro3d.h>
#include <sstream>
#include <string>
/**
* @brief Creates a 8 byte RGBA color
* @param r red component of the color
* @param g green component of the color
* @param b blue component of the color
* @param a alpha component of the color
*/
#define RGBA8(r, g, b, a) ((((r)&0xFF)<<0) | (((g)&0xFF)<<8) | (((b)&0xFF)<<16) | (((a)&0xFF)<<24))
#define BarColor C2D_Color32(57, 84, 114, 255)
#define TopBGColor C2D_Color32(96, 168, 192, 255)
#define BottomBGColor C2D_Color32(38, 44, 77, 255)
#define SelectedColordefault C2D_Color32(120, 192, 216, 255)
#define UnselectedColordefault C2D_Color32(77, 118, 132, 255)
#define BLACK C2D_Color32(0, 0, 0, 255)
#define WHITE C2D_Color32(255, 255, 255, 255)
#define TRANSPARENT C2D_Color32(0, 0, 0, 0)
typedef u32 Color;
namespace ColorHelper {
int getColorValue(int color, int bgr);
std::string getColorName(int color, int bgr);
}
#endif

View file

@ -1,76 +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.
*/
#pragma once
#include <3ds.h>
#ifdef __cplusplus
extern "C" {
#endif
#include "files.h"
#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#ifdef __cplusplus
}
#include "animation.hpp"
#include "config.hpp"
#include "gfx.hpp"
#include "gui.hpp"
#include "json.hpp"
#include "lang.hpp"
#include "msg.hpp"
#include "screenCommon.hpp"
#include "stringutils.hpp"
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <regex>
#include <curl/curl.h>
using json = nlohmann::json;
#endif
#define WORKING_DIR "/"
#define SCRIPTS_PATH "sdmc:/3ds/Universal-Updater/scripts/" // The Scripts will be here.
#define MUSIC_PATH "sdmc:/3ds/Universal-Updater/Music.wav" // Default Music File / Path.
#define SCRIPT_VERSION 4
#define STORE_PATH "sdmc:/3ds/Universal-Updater/stores/" // Default Store path.
#define ENTRIES_PER_SCREEN 3
#define ENTRIES_PER_LIST 7
#define metaFile "sdmc:/3ds/Universal-Updater/ScriptInfo.json"
#define _3DSX_PATH "sdmc:/3ds"
#define _NDS_PATH "sdmc:"
#define ARCHIVES_DEFAULT "sdmc:"

View file

@ -1,161 +1,91 @@
/*
* 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.
*/
#ifndef _UNIVERSAL_UPDATER_CONFIG_HPP
#define _UNIVERSAL_UPDATER_CONFIG_HPP
#include "json.hpp"
#include <3ds.h>
#include <string>
class Config {
public:
Config();
void save();
void initialize();
void addMissingThings();
void sysLang();
// Bar Color.
u32 barColor() { return this->v_barColor; }
void barColor(u32 v) { this->v_barColor = v; if (!this->changesMade) this->changesMade = true; }
// Top BG Color.
u32 topBG() { return this->v_topBG; }
void topBG(u32 v) { this->v_topBG = v; if (!this->changesMade) this->changesMade = true; }
// Bottom BG Color.
u32 bottomBG() { return this->v_bottomBG; }
void bottomBG(u32 v) { this->v_bottomBG = v; if (!this->changesMade) this->changesMade = true; }
// Text Color.
u32 textColor() { return this->v_textColor; }
void textColor(u32 v) { this->v_textColor = v; if (!this->changesMade) this->changesMade = true; }
// Button Color.
u32 buttonColor() { return this->v_buttonColor; }
void buttonColor(u32 v) { this->v_buttonColor = v; if (!this->changesMade) this->changesMade = true; }
// Selected Color.
u32 selectedColor() { return this->v_selectedColor; }
void selectedColor(u32 v) { this->v_selectedColor = v; if (!this->changesMade) this->changesMade = true; }
// Unselected Color.
u32 unselectedColor() { return this->v_unselectedColor; }
void unselectedColor(u32 v) { this->v_unselectedColor = v; if (!this->changesMade) this->changesMade = true; }
// Script Path.
std::string scriptPath() { return this->v_scriptPath; }
void scriptPath(std::string v) { this->v_scriptPath = v; if (!this->changesMade) this->changesMade = true; }
// Lang Path.
int langPath() { return this->v_langPath; }
void langPath(int v) { this->v_langPath = v; if (!this->changesMade) this->changesMade = true; }
// View Mode.
int viewMode() { return this->v_viewMode; }
void viewMode(int v) { this->v_viewMode = v; if (!this->changesMade) this->changesMade = true; }
// Progressbar Color.
u32 progressbarColor() { return this->v_progressbarColor; }
void progressbarColor(u32 v) { this->v_progressbarColor = v; if (!this->changesMade) this->changesMade = true; }
// Music Path.
std::string musicPath() { return this->v_musicPath; }
void musicPath(std::string v) { this->v_musicPath = v; if (!this->changesMade) this->changesMade = true; }
// Logging.
bool logging() { return this->v_logging; }
void logging(bool v) { this->v_logging = v; if (!this->changesMade) this->changesMade = true; }
// Use bars.
bool useBars() { return this->v_useBars; }
void useBars(bool v) { this->v_useBars = v; if (!this->changesMade) this->changesMade = true; }
// Autoboot.
int autoboot() { return this->v_autoboot; }
void autoboot(int v) { this->v_autoboot = v; if (!this->changesMade) this->changesMade = true; }
// Store Path.
std::string storePath() { return this->v_storePath; }
void storePath(std::string v) { this->v_storePath = v; if (!this->changesMade) this->changesMade = true; }
// Autoboto file.
std::string autobootFile() { return this->v_autobootFile; }
void autobootFile(std::string v) { this->v_autobootFile = v; if (!this->changesMade) this->changesMade = true; }
// Outdated Script Color.
u32 outdatedColor() { return this->v_outdatedColor; }
void outdatedColor(u32 v) { this->v_outdatedColor = v; if (!this->changesMade) this->changesMade = true; }
// Uptodate Script Color.
u32 uptodateColor() { return this->v_uptodateColor; }
void uptodateColor(u32 v) { this->v_uptodateColor = v; if (!this->changesMade) this->changesMade = true; }
// Not found Script Color.
u32 notfoundColor() { return this->v_notfoundColor; }
void notfoundColor(u32 v) { this->v_notfoundColor = v; if (!this->changesMade) this->changesMade = true; }
// Future Script Color.
u32 futureColor() { return this->v_futureColor; }
void futureColor(u32 v) { this->v_futureColor = v; if (!this->changesMade) this->changesMade = true; }
// Keydelay.
int keyDelay() { return this->v_keyDelay; }
void keyDelay(int v) { this->v_keyDelay = v; if (!this->changesMade) this->changesMade = true; }
// Screen Fade.
bool screenFade() { return this->v_screenFade; }
void screenFade(bool v) { this->v_screenFade = v; if (!this->changesMade) this->changesMade = true; }
// Progressbar Display.
bool progressDisplay() { return this->v_progressDisplay; }
void progressDisplay(bool v) { this->v_progressDisplay = v; if (!this->changesMade) this->changesMade = true; }
// Language.
std::string language() { return this->v_language; }
void language(std::string v) { this->v_language = v; if (!this->changesMade) this->changesMade = true; }
// First startup.
bool firstStartup() { return this->v_firstStartup; }
void firstStartup(bool v) { this->v_firstStartup = v; if (!this->changesMade) this->changesMade = true; }
// Use ScriptColors.
bool useScriptColor() { return this->v_useScriptColor; }
void useScriptColor(bool v) { this->v_useScriptColor = v; if (!this->changesMade) this->changesMade = true; }
// Show Downloadspeed.
bool showSpeed() { return this->v_showSpeed; }
void showSpeed(bool v) { this->v_showSpeed = v; if (!this->changesMade) this->changesMade = true; }
// Citra stuff.
bool citra() { return this->v_citra; }
void citra(bool v) { this->v_citra = v; if (!this->changesMade) this->changesMade = true; }
// Variables.
std::string _3dsxpath() { return this->v_3dsx_install_path; }
void _3dsxpath(std::string v) { this->v_3dsx_install_path = v; if (!this->changesMade) this->changesMade = true; }
std::string ndspath() { return this->v_nds_install_path; }
void ndspath(std::string v) { this->v_nds_install_path = v; if (!this->changesMade) this->changesMade = true; }
std::string archivepath() { return this->v_archive_path; }
void archivepath(std::string v) { this->v_archive_path = v; if (!this->changesMade) this->changesMade = true; }
// Mainly helper.
bool getBool(const std::string &key);
void setBool(const std::string &key, bool v);
int getInt(const std::string &key);
void setInt(const std::string &key, int v);
std::string getString(const std::string &key);
void setString(const std::string &key, const std::string &v);
private:
nlohmann::json json; // Our private JSON file.
bool changesMade = false, initialChanges = false;
int configVersion = 2;
// Color variables and more.
u32 v_barColor, v_topBG, v_bottomBG, v_textColor, v_buttonColor, v_selectedColor, v_unselectedColor, v_progressbarColor,
v_outdatedColor, v_uptodateColor, v_notfoundColor, v_futureColor;
std::string v_scriptPath, v_musicPath, v_storePath, v_autobootFile, v_language;
int v_langPath, v_viewMode, v_autoboot, v_keyDelay;
bool v_logging, v_useBars, v_screenFade, v_progressDisplay, v_firstStartup, v_useScriptColor, v_showSpeed, v_citra;
// Some variables.
std::string v_3dsx_install_path, v_nds_install_path, v_archive_path;
};
#endif
/*
* 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.
*/
#ifndef _UNIVERSAL_UPDATER_CONFIG_HPP
#define _UNIVERSAL_UPDATER_CONFIG_HPP
#include "json.hpp"
#include <3ds.h>
#include <string>
class Config {
public:
Config();
void save();
void initialize();
void sysLang();
/* Language. */
std::string language() const { return this->v_language; };
void language(const std::string &v) { this->v_language = v; if (!this->changesMade) this->changesMade = true; };
/* Last Store. */
std::string lastStore() const { return this->v_lastStore; };
void lastStore(const std::string &v) { this->v_lastStore = v; if (!this->changesMade) this->changesMade = true; };
/* Using Top List. */
bool list() const { return this->v_list; };
void list(bool v) { this->v_list = v; if (!this->changesMade) this->changesMade = true; };
/* Auto update on boot. */
bool autoupdate() const { return this->v_autoUpdate; };
void autoupdate(bool v) { this->v_autoUpdate = v; if (!this->changesMade) this->changesMade = true; };
std::string _3dsxPath() const { return this->v_3dsxPath; };
void _3dsxPath(const std::string &v) { this->v_3dsxPath = v; if (!this->changesMade) this->changesMade = true; };
std::string ndsPath() const { return this->v_ndsPath; };
void ndsPath(const std::string &v) { this->v_ndsPath = v; if (!this->changesMade) this->changesMade = true; };
std::string archPath() const { return this->v_archivePath; };
void archPath(const std::string &v) { this->v_archivePath = v; if (!this->changesMade) this->changesMade = true; };
/* Fetching old metadata. */
bool metadata() const { return this->v_metadata; };
void metadata(bool v) { this->v_metadata = v; if (!this->changesMade) this->changesMade = true; };
/* U-U Update check on startup. */
bool updatecheck() const { return this->v_updateCheck; };
void updatecheck(bool v) { this->v_updateCheck = v; if (!this->changesMade) this->changesMade = true; };
private:
/* Mainly helper. */
bool getBool(const std::string &key);
void setBool(const std::string &key, bool v);
int getInt(const std::string &key);
void setInt(const std::string &key, int v);
std::string getString(const std::string &key);
void setString(const std::string &key, const std::string &v);
nlohmann::json json;
bool changesMade = false;
std::string v_language = "en", v_lastStore = "universal-db-beta.unistore",
v_3dsxPath = "sdmc:/3ds", v_ndsPath = "sdmc:", v_archivePath = "sdmc:";
bool v_list = false, v_autoUpdate = true, v_metadata = true, v_updateCheck = true;
};
#endif

View file

@ -0,0 +1,75 @@
/*
* 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.
*/
#ifndef _UNIVERSAL_UPDATER_DOWNLOAD_HPP
#define _UNIVERSAL_UPDATER_DOWNLOAD_HPP
#include "common.hpp"
#define APP_TITLE "Universal-Updater"
#define VERSION_STRING "3.0.0"
enum DownloadError {
DL_ERROR_NONE = 0,
DL_ERROR_WRITEFILE,
DL_ERROR_ALLOC,
DL_ERROR_STATUSCODE,
DL_ERROR_GIT,
DL_CANCEL, // No clue if that's needed tho.
};
Result downloadToFile(const std::string &url, const std::string &path);
Result downloadFromRelease(const std::string &url, const std::string &asset, const std::string &path, const bool &includePrereleases);
/*
Check Wi-Fi status.
@return True if Wi-Fi is connected; false if not.
*/
bool checkWifiStatus(void);
/*
Display "Please connect to Wi-Fi" for 2s.
*/
void notConnectedMsg(void);
/*
Display "Not Implemented Yet" for 2s.
*/
void notImplemented(void);
/*
Display the done msg.
*/
void doneMsg(void);
void displayProgressBar();
bool IsUpdateAvailable(const std::string &URL, const int &revCurrent);
bool DownloadUniStore(const std::string &URL, const int &currentRev, std::string &fl, const bool &isDownload = false, const bool &isUDB = false);
bool DownloadSpriteSheet(const std::string &URL, const std::string &file);
bool IsUUUpdateAvailable();
void UpdateAction();
#endif

View file

@ -1,44 +1,44 @@
/*
* 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.
*/
#ifndef _UNIVERSAL_UPDATER_EXTRACT_HPP
#define _UNIVERSAL_UPDATER_EXTRACT_HPP
#include "common.hpp"
enum ExtractError {
EXTRACT_ERROR_NONE = 0,
EXTRACT_ERROR_ARCHIVE,
EXTRACT_ERROR_ALLOC,
EXTRACT_ERROR_FIND,
EXTRACT_ERROR_READFILE,
EXTRACT_ERROR_OPENFILE,
EXTRACT_ERROR_WRITEFILE,
};
Result extractArchive(std::string archivePath, std::string wantedFile, std::string outputPath);
/*
* 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.
*/
#ifndef _UNIVERSAL_UPDATER_EXTRACT_HPP
#define _UNIVERSAL_UPDATER_EXTRACT_HPP
#include "common.hpp"
enum ExtractError {
EXTRACT_ERROR_NONE = 0,
EXTRACT_ERROR_ARCHIVE,
EXTRACT_ERROR_ALLOC,
EXTRACT_ERROR_FIND,
EXTRACT_ERROR_READFILE,
EXTRACT_ERROR_OPENFILE,
EXTRACT_ERROR_WRITEFILE,
};
Result extractArchive(const std::string &archivePath, const std::string &wantedFile, const std::string &outputPath);
#endif

View file

@ -32,25 +32,34 @@
#include <sys/stat.h>
#include <vector>
using namespace std;
struct DirEntry {
std::string name;
std::string path;
bool isDirectory;
off_t size;
};
bool nameEndsWith(const std::string& name, const std::vector<std::string> extensionList);
void getDirectoryContents(std::vector<DirEntry>& dirContents, const std::vector<std::string> extensionList);
void getDirectoryContents(std::vector<DirEntry>& dirContents);
/*
UniStore Info struct.
*/
struct UniStoreInfo {
std::string Title;
std::string Author;
std::string URL;
std::string FileName;
std::string Description;
int Version;
int Revision;
int StoreSize;
};
bool nameEndsWith(const std::string &name, const std::vector<std::string> &extensionList);
void getDirectoryContents(std::vector<DirEntry> &dirContents, const std::vector<std::string> &extensionList);
void getDirectoryContents(std::vector<DirEntry> &dirContents);
std::vector<std::string> getContents(const std::string &name, const std::vector<std::string> &extensionList);
bool returnIfExist(const std::string &path, const std::vector<std::string> &extensionList);
std::vector<UniStoreInfo> GetUniStoreInfo(const std::string &path);
std::string selectFilePath(std::string selectText, std::string initialPath, const std::vector<std::string> &extensionList, int selectionMode = 1);
void dirCopy(DirEntry* entry, int i, const char *destinationPath, const char *sourcePath);
void dirCopy(DirEntry *entry, const char *destinationPath, const char *sourcePath);
int fcopy(const char *sourcePath, const char *destinationPath);
#endif

View file

@ -1,34 +1,38 @@
/*
* 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.
*/
#ifndef _UNIVERSAL_UPDATER_FORMATTING_HPP
#define _UNIVERSAL_UPDATER_FORMATTING_HPP
#include <string>
std::string formatBytes(int bytes);
/*
* 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.
*/
#ifndef _UNIVERSAL_UPDATER_FILES_HPP
#define _UNIVERSAL_UPDATER_FILES_HPP
#include "common.hpp"
Result makeDirs(const char *path);
Result openFile(Handle *fileHandle, const char *path, const bool &write);
Result deleteFile(const char *path);
Result removeDir(const char *path);
Result removeDirRecursive(const char *path);
#endif

File diff suppressed because it is too large Load diff

View file

@ -1,39 +1,38 @@
/*
* 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.
*/
#ifndef _UNIVERSAL_UPDATER_LANG_HPP
#define _UNIVERSAL_UPDATER_LANG_HPP
#include "json.hpp"
#include <string>
namespace Lang {
std::string get(const std::string &key);
void load(const std::string lang);
}
/*
* 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.
*/
#ifndef _UNIVERSAL_UPDATER_LANG_HPP
#define _UNIVERSAL_UPDATER_LANG_HPP
#include "json.hpp"
#include <string>
namespace Lang {
std::string get(const std::string &key);
void load(const std::string &lang);
};
#endif

View file

@ -1,86 +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.
*/
#ifndef _UNIVERSAL_UPDATER_SCRIPT_HELPER_HPP
#define _UNIVERSAL_UPDATER_SCRIPT_HELPER_HPP
#include <string>
// Information like Title and Author.
struct ScriptInfo {
std::string title;
std::string author;
std::string shortDesc;
};
// Store Information.
struct StoreInfo {
std::string title;
std::string author;
std::string description;
std::string url;
std::string file;
std::string storeSheet;
std::string sheetURL;
int version;
};
enum ScriptState {
NONE = 0,
FAILED_DOWNLOAD,
SCRIPT_CANCELED,
SYNTAX_ERROR,
COPY_ERROR,
MOVE_ERROR,
DELETE_ERROR,
};
namespace ScriptHelper {
// Get stuff from a JSON.
std::string getString(nlohmann::json json, const std::string &key, const std::string &key2);
int getNum(nlohmann::json json, const std::string &key, const std::string &key2);
// Script Functions.
Result downloadRelease(std::string repo, std::string file, std::string output, bool includePrereleases, bool showVersions, std::string message);
Result downloadFile(std::string file, std::string output, std::string message);
Result removeFile(std::string file, std::string message);
void installFile(std::string file, bool updateSelf, std::string message);
void extractFile(std::string file, std::string input, std::string output, std::string message);
Result createFile(const char * path);
void displayTimeMsg(std::string message, int seconds);
bool checkIfValid(std::string scriptFile, int mode = 0);
void bootTitle(const std::string TitleID, bool isNAND, std::string message);
Result prompt(std::string message);
Result copyFile(std::string source, std::string destination, std::string message);
Result renameFile(std::string oldName, std::string newName, std::string message);
}
#endif

View file

@ -0,0 +1,60 @@
/*
* 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.
*/
#ifndef _UNIVERSAL_UPDATER_SCRIPT_UTILS_HPP
#define _UNIVERSAL_UPDATER_SCRIPT_UTILS_HPP
#include "json.hpp"
#include <3ds.h>
#include <string>
enum ScriptState {
NONE = 0,
FAILED_DOWNLOAD,
SCRIPT_CANCELED,
SYNTAX_ERROR,
COPY_ERROR,
MOVE_ERROR,
DELETE_ERROR
};
namespace ScriptUtils {
bool matchPattern(const std::string &pattern, const std::string &tested);
Result removeFile(const std::string &file, const std::string &message);
void bootTitle(const std::string &TitleID, const bool &isNAND, const std::string &message);
Result prompt(const std::string &message);
Result copyFile(const std::string &source, const std::string &destination, const std::string &message);
Result renameFile(const std::string &oldName, const std::string &newName, const std::string &message);
Result downloadRelease(const std::string &repo, const std::string &file, const std::string &output, const bool &includePrereleases, const std::string &message);
Result downloadFile(const std::string &file, const std::string &output, const std::string &message);
void installFile(const std::string &file, const bool &updatingSelf, const std::string &message);
void extractFile(const std::string &file, const std::string &input, const std::string &output, const std::string &message);
Result runFunctions(const nlohmann::json &storeJson, const int &selection, const std::string &entry);
};
#endif

View file

@ -1,21 +0,0 @@
#ifndef _UNIVERSAL_UPDATER_SOUND_H
#define _UNIVERSAL_UPDATER_SOUND_H
#include <3ds.h>
#include <string>
class sound {
public:
sound(const std::string& path, int channel = 1, bool toloop = true);
~sound();
void play();
void stop();
private:
u32 dataSize;
ndspWaveBuf waveBuf;
u8* data = NULL;
int chnl;
};
#endif

View file

@ -1,99 +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.
*/
#ifndef _UNIVERSAL_UPDATER_STORE_HPP
#define _UNIVERSAL_UPDATER_STORE_HPP
#include "json.hpp"
#include <3ds.h>
#include <string>
#include <vector>
struct UniStoreV2Struct {
std::string title;
std::string author;
std::string description;
std::string version;
std::string category;
std::string console;
std::string last_updated;
int icon_index;
int JSONIndex;
bool updateAvailable;
};
enum class SortType {
TITLE,
AUTHOR,
LAST_UPDATED
};
class Store {
public:
Store(nlohmann::json &JS, std::string updateJSON = "NOT_FOUND");
void writeToFile(int index);
void sorting(bool Ascending, SortType sorttype);
std::string returnTitle(const int index);
std::string returnAuthor(const int index);
std::string returnDescription(const int index);
int returnIconIndex(const int index);
int returnJSONIndex(const int index);
int getSize();
bool getAscending() { return this->ascending; }
bool isUpdateAvailable(int index) { return this->sortedStore[index].updateAvailable; }
// Searching stuff.
int searchForEntries(const std::string searchResult);
int searchForAuthor(const std::string searchResult);
int searchForCategory(const std::string searchResult);
int searchForConsole(const std::string searchResult);
bool updateAvailable(int index);
void reset() { this->sortedStore = this->unsortedStore; }
const int getSortType() {
if (this->sorttype == SortType::TITLE) return 0;
else if (this->sorttype == SortType::AUTHOR) return 1;
else if (this->sorttype == SortType::LAST_UPDATED) return 2;
else return -1; // Should not happen.
}
const std::vector<std::string> getCategories() { return this->availableCategories; }
const std::vector<std::string> getAuthors() { return this->availableAuthors; }
const std::vector<std::string> getSystems() { return this->availableSystems; }
private:
std::vector<UniStoreV2Struct> sortedStore, unsortedStore;
std::vector<std::string> availableCategories, availableAuthors, availableSystems;
std::string updateFile;
bool ascending = false;
nlohmann::json storeJson, updateJSON;
SortType sorttype = SortType::TITLE;
UniStoreV2Struct getData(const int index);
};
#endif

View file

@ -1,12 +1,42 @@
/*
* 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.
*/
#ifndef _UNIVERSAL_UPDATER_STRING_UTILS_HPP
#define _UNIVERSAL_UPDATER_STRING_UTILS_HPP
#include "common.hpp"
bool matchPattern(std::string pattern, std::string tested);
#include "meta.hpp"
#include <string>
#include <vector>
namespace StringUtils {
std::string format(const std::string& fmt_str, ...);
}
std::string lower_case(const std::string &str);
std::string FetchStringsFromVector(const std::vector<std::string> &fetch);
std::string formatBytes(const int bytes);
std::string GetMarkString(int marks);
std::vector<std::string> GetMarks(int marks);
};
#endif

View file

@ -1,12 +0,0 @@
#ifndef _UNIVERSAL_UPDATER_THREAD_HPP
#define _UNIVERSAL_UPDATER_THREAD_HPP
#include <3ds.h>
#include <vector>
namespace Threads {
void create(ThreadFunc entrypoint);
void destroy(void);
}
#endif

View file

@ -1,227 +1,88 @@
{
"DOWNLOAD_FAILED": "Download Failed!",
"NOT_IMPLEMENTED": "Not Implemented Yet.",
"DONE": "Done!",
"CONNECT_WIFI": "Please Connect to WiFi.",
"DOWNLOADING": "Downloading: ",
"CURRENTLY_EXTRACTING": "Currently extracting:\n",
"FILE_EXTRACTED": "file extracted.",
"FILES_EXTRACTED": "files extracted.",
"SCRIPTLIST": "Script list",
"SCRIPTS": "Scripts",
"SETTINGS": "Settings",
"LANGUAGE": "Language",
"COLORS": "Colors",
"SELECT_LANG": "Choose the current language.",
"BAR_COLOR": "Bar Color",
"TOP_BG_COLOR": "Top Background Color",
"BOTTOM_BG_COLOR": "Bottom Background Color",
"TEXT_COLOR": "Text Color",
"SELECTED_COLOR": "Selected Color",
"UNSELECTED_COLOR": "Unselected Color",
"PROGRESSBAR_COLOR": "Progressbar Color",
"ENTER_RED_RGB": "Enter the Red RGB.",
"ENTER_GREEN_RGB": "Enter the Green RGB.",
"ENTER_BLUE_RGB": "Enter the Blue RGB.",
"INCOMPATIBLE_SCRIPT": "You have an incompatible script.",
"DELETE_PROMPT": "Are you sure you want to delete this Directory?",
"CONFIRM_OR_CANCEL": "Press A to confirm, B to cancel.",
"GETTING_SCRIPT_LIST": "Getting Script List...",
"SCRIPTBROWSE": "Script browse",
"GET_SCRIPTS": "Get Scripts",
"INSTALLED_REV": "Installed revision: ",
"CURRENT_REV": "Current revision: ",
"AUTHOR": "Author: ",
"TITLE": "Title: ",
"FUTURE_SCRIPT": "This script is a future script.",
"OUTDATED_SCRIPT": "This script is outdated.",
"UP-TO-DATE": "This script is up-to-date.",
"FTP_MODE": "FTP Mode",
"FTP_INITIALIZED": "FTP Initialized.",
"FAILED_GET_IP": "Failed to get IP.",
"FAILED_INITIALIZE_FTP": "Failed to initialize FTP.",
"B_FTP_EXIT": "Press B to exit from FTP.",
"WIFI_NOT_ENABLED": "WiFi not enabled.",
"SCRIPTCREATOR": "Script Creator",
"CREDITS": "Credits",
"DEVELOPED_BY": "Developed by: Universal-Team.",
"MAIN_DEV": "Main Developer: StackZ",
"CURRENT_VERSION": "Current version: ",
"MANY_THANKS": "Many Thanks to:",
"TRANSLATORS": "All our Translators",
"HELP_TRANSLATE": "- For helping translate Universal-Updater's strings.",
"HELP_OUT": "- For helping out by Universal-Updater.",
"SCRIPTCREATORS": "All Script Creators",
"CREATING_SCRIPTS": "- For creating Scripts for Universal-Updater.",
"SHOW_QR": "Click here to show the QR Code.",
"LINK": "Join our Discord: https://discord.gg/KDJCfGF",
"RELEASE_TAG": "Release Tag: ",
"DESC": "Desc: ",
"RELEASE_ID": "Release ID: ",
"TITLE_ID": "Title ID: ",
"FILE_SIZE": "File size: ",
"GET_SCRIPTS_FIRST": "Get some Scripts first!",
"OPEN": "Open",
"SELECT": "Select",
"REFRESH": "Refresh",
"BACK": "Back",
"FILEBROWSE_MSG": "Press X to select, Select to refresh.",
"SELECT_SCRIPT_PATH": "Select the Script Path.",
"CHANGE_BAR_STYLE": "Change bar style",
"CHANGE_SCRIPTPATH": "Change Script path",
"CHANGE_MUSICFILE": "Change Music file",
"SELECT_MUSIC_FILE": "Select the Music file.",
"VERSION": "Version: ",
"UPDATING": "Updating...",
"WOULD_YOU_LIKE_UPDATE": "Would you like to update this store?",
"GET_STORES_FIRST": "Get some Stores first!",
"PREPARE_STORE": "Preparing store... please wait.",
"YES": "Yes",
"NO": "No",
"CHANGE_STOREPATH": "Change Store path",
"SELECT_STORE_PATH": "Select the Store Path.",
"UNKNOWN": "Unknown",
"ENTER_OWNER_AND_REPO": "Enter Owner and Repo.",
"ENTER_FILENAME": "Enter filename.",
"UNISTORE_SEARCH": "UniStore search",
"FULL_URL": "Full URL",
"GITHUB": "GitHub",
"ENTER_FULL_URL": "Enter the full URL.",
"SCRIPTS_SUBMENU": "Scripts Submenu",
"STORE_LIST": "Store list",
"STORE_SEARCH": "Store search",
"UNISTORE_SUBMENU": "UniStore SubMenu",
"OWNER_AND_REPO": "Owner & Repo",
"FILENAME": "Filename",
"OK": "OK",
"DELETE_STORE": "Would you like to delete this store?",
"DELETE_TITLE": "Would you like to delete this title?",
"MEDIATYPE_SD": "MediaType SD",
"MEDIATYPE_NAND": "MediaType NAND",
"BOOT_TITLE": "Would you like to boot this title?",
"DISABLE_AUTOBOOT": "Would you like to disable autoboot?",
"AUTOBOOT_STORE": "Would you like to autoboot this Store?\n\nThis will autoboot this store on startup!",
"SCRIPT_NOT_FOUND": "This script does not exist.",
"DELETE_SCRIPT": "Would you like to delete this script?",
"REFRESHING_LIST": "Refreshing List...",
"AUTOBOOT_SCRIPT": "Would you like to autoboot this Script?\n\nThis will autoboot this Script on startup!",
"STARTING_UNIVERSAL_UPDATER": "Starting Universal-Updater...",
"EXECUTE_SCRIPT": "Would you like to execute this script?",
"EXECUTE_STORE": "Would you like to execute this entry?",
"GLOSSARY": "Glossary",
"DOWNLOAD_ALL": "Download all Scripts at once.",
"CHANGE_VIEW_MODE": "Change the viewMode.",
"ENTRY_UP": "Go one Entry up.",
"ENTRY_DOWN": "Go one Entry down.",
"GO_BACK": "Go back.",
"ENTRY": "Current Entry | Last Entry",
"REVISION": "Current Revision | Latest Revision",
"UPDATE_STORE": "Update selected UniStore.",
"NOT_FOUND_COLOR": "Not Found Script Color",
"OUTDATED_COLOR": "Outdated Script Color",
"UPTODATE_COLOR": "Up-To-Date Script Color",
"FUTURE_COLOR": "Future Script Color",
"BUTTON_COLOR": "Button Color",
"DELETE_SCRIPT2": "Delete the selected Script.",
"DELETE_UNISTORE": "Delete the selected UniStore.",
"REFRESH_SCRIPTBROWSE_PROMPT": "Would you like to refresh the ScriptBrowse?",
"REFRESH_SCRIPTBROWSE": "Refresh the ScriptBrowse.",
"DOWNLOAD_ALL_DDM": "Download All",
"REFRESH_BROWSE_DDM": "Refresh",
"VIEW_DDM": "Change ViewMode",
"DELETE_DDM": "Delete",
"UPDATE_DDM": "Update",
"TAG_NAME": "Tag name: ",
"TARGET": "Target: ",
"RELEASE_NAME": "Release Name: ",
"CREATED_AT": "Created at: ",
"PUBLISHED_AT": "Published at: ",
"FETCHING_RELEASES": "Fetching Releases... please wait.",
"VERSION_SELECT": "Select the Release you want to download.",
"IS_PRERELEASE": "PreRelease: ",
"DOWNLOAD_ERROR": "Download Error!",
"SCRIPT_CANCELED": "Script Canceled!",
"SYNTAX_ERROR": "Syntax Error!",
"COPY_ERROR": "Copy Error!",
"MOVE_ERROR": "Move Error!",
"DELETE_ERROR": "Delete Error!",
"CHANGE_KEY_DELAY": "Change Key Delay",
"ENTER_KEY_DELAY": "Enter the Key Delay for Scrolling.",
"TOGGLE_FADE": "Toggle Fade Effect",
"TOGGLE_FADE_ENABLE": "Would you like to enable the Screen fade effect?",
"TOGGLE_FADE_DISABLE": "Would you like to disable the Screen fade effect?",
"ENABLED": "Enabled!",
"DISABLED": "Disabled!",
"DOWNLOAD_SPEED": "Download Speed: ",
"KB_PER_SECOND": " KB per second",
"PROGRESS_BAR_ENABLE": "Would you like to enable the progressbar?",
"PROGRESS_BAR_DISABLE": "Would you like to disable the progressbar?",
"CATEGORY": "Category: ",
"CONSOLE": "Console: ",
"LAST_UPDATED": "Last updated: ",
"CHANGE_THEME": "Change Theme",
"CHANGE_STYLE": "Change Style",
"NO_DOWNLOADS_AVAILABLE": "No downloads available.",
"UNISTORE_VERSION": "UniStore version: ",
"UNISTORE_NOT_SUPPORTED": "This UniStore version is not supported!",
"DESCENDING": "Descending",
"ASCENDING": "Ascending",
"TITLE_BTN": "Title",
"AUTHOR_BTN": "Author",
"LAST_UPDATED_BTN": "Last updated",
"ENTER_SEARCH": "Enter what you like to search.",
"NO_RESULTS_FOUND": "No results found!",
"SEARCH": "Search Entry",
"INVALID_INPUT": "Invalid input!",
"RESET": "Reset",
"SEARCH_MENU": "Search Menu",
"TITLE_SEARCH": "Title search",
"AUTHOR_SEARCH": "Author search",
"CATEGORY_SEARCH": "Category search",
"CONSOLE_SEARCH": "Console search",
"SEARCHING_FOR": "Searching for...",
"SELECT_CATEGORY": "Select a category you like to view.",
"NO_CATEGORIES_AVAILABLE": "No categories available.",
"UPDATE_AVAILABLE": "Update available!",
"UPDATE_NOT_AVAILABLE": "No updates available.",
"ENTRY_AMOUNT": "There are %i entries available.",
"SELECT_AUTHOR": "Select an author you like to view.",
"SELECT_CONSOLE": "Select a console you like to view.",
"NO_AUTHORS_AVAILABLE": "No authors available.",
"NO_CONSOLES_AVAILABLE": "No consoles available.",
"CHANGE_3DSX_PATH": "Change 3DSX path",
"CHANGE_NDS_PATH": "Change NDS path",
"CHANGE_ARCHIVE_PATH": "Change Archive path",
"SELECT_3DSX_PATH": "Select the 3DSX path.",
"SELECT_NDS_PATH": "Select the NDS path.",
"SELECT_ARCHIVE_PATH": "Select the Archive path.",
"TOGGLE_PROGRESSBAR": "Toggle Progressbar",
"SELECT_RGB_COLOR": "Select your RGB Color.",
"UI_COLOR_BEHAVIOUR": "Press START to Select.\n\uE001 to cancel.\nTouch to control the RGB.\nD-Pad to control the RGB."
}
"ASCENDING": "Ascending",
"AUTHOR": "Author",
"BOOT_TITLE": "Would you like to boot this title?",
"CATEGORY": "Category",
"CHANGE_3DSX_PATH": "Change 3DSX path",
"CHANGE_ARCHIVE_PATH": "Change archive path",
"CHANGE_DIRECTORIES": "Change directories...",
"CHANGE_NDS_PATH": "Change NDS path",
"CHECK_UNISTORE_UPDATES": "Checking for UniStore updates...",
"CHECK_UU_UPDATES": "Checking for Universal-Updater updates...",
"CONFIRM_OR_CANCEL": "Press \uE000 to confirm, \uE001 to cancel.",
"CONNECT_WIFI": "Please Connect to WiFi.",
"CONSOLE": "Console",
"CONTRIBUTOR_TRANSLATORS": "- All Translators & Contributors",
"COPY_ERROR": "Copy Error!",
"CREDITS": "Credits",
"CURRENT_VERSION": "Current version: ",
"CURRENTLY_EXTRACTING": "Currently extracting:\n",
"DELETE_ERROR": "Delete Error!",
"DELETE_PROMPT": "Are you sure you want to delete this Directory?",
"DELETE_UNNEEDED_FILE": "Deleting unneeded file...",
"DESCENDING": "Descending",
"DIRECTION": "Direction",
"DISABLE_AUTOUPDATE_UNISTORE": "Disable auto-update UniStore on boot",
"DISABLE_UPDATE_CHECK": "Disable self-updating",
"DONE": "Done!",
"DOWNLOAD_ERROR": "Download Error!",
"DOWNLOAD_FAILED": "Download Failed!",
"DOWNLOADING_SPRITE_SHEET": "Downloading Spritesheet...",
"DOWNLOADING_SPRITE_SHEET2": "Downloading Spritesheet %i of %i...",
"DOWNLOADING_UNIVERSAL_DB": "Downloading Universal-DB...",
"DONLOADING_UNIVERSAL_UPDATER": "Downloading Universal-Updater...",
"DOWNLOADING_UNISTORE": "Downloading UniStore...",
"ENABLE_AUTOUPDATE_UNISTORE": "Enable auto-update UniStore on boot",
"ENABLE_UPDATE_CHECK": "Enable self-updating",
"ENTER_SEARCH": "Enter what you like to search.",
"ENTER_URL": "Enter the URL of the UniStore.",
"ENTRIES": "Entries",
"EXECUTE_ENTRY": "Would you like to execute this entry?",
"EXIT_APP": "Exit Universal-Updater",
"FETCHING_METADATA": "Fetching old metadata...",
"FILE_EXTRACTED": "file extracted.",
"FILE_SLASH": "Seems like a '/' is included, which is not supported.\nPlease change 'file' to filename only.",
"FILES_EXTRACTED": "files extracted.",
"FILTER_TO": "Filter to:",
"GITHUB": "Full credits can be found on GitHub",
"GRID": "Grid",
"INCLUDE_IN_RESULTS": "Include in results:",
"INSTALL_UNIVERSAL_UPDATER": "Installing Universal-Updater...",
"INVALID_UNISTORE": "Invalid UniStore",
"KEY_CONTINUE": "Press any key to continue.",
"LANGUAGE": "Language",
"LAST_UPDATED": "Last updated",
"LICENSE": "License",
"LIST": "List",
"LOADING_SPRITESHEET": "Loading Spritesheet %i of %i...",
"MEDIATYPE_NAND": "MediaType NAND",
"MEDIATYPE_SD": "MediaType SD",
"MOVE_ERROR": "Move Error!",
"NO": "No",
"NO_DOWNLOADS_AVAILABLE": "No downloads available",
"NO_LICENSE": "No License",
"NOT_IMPLEMENTED": "Not Implemented Yet",
"REVISION": "Revision",
"SELECT_DIR": "Select a directory",
"SELECT_LANG": "Choose the language",
"SELECT_UNISTORE": "Select UniStore",
"SELECT_UNISTORE_2": "Select a UniStore",
"SHEET_SLASH": "Seems like a '/' is included, which is not supported.\nPlease change 'sheet' to filename only.",
"SORT_BY": "Sort By",
"START_SELECT": "Press START to select the current folder",
"SYNTAX_ERROR": "Syntax Error!",
"TITLE": "Title",
"TOP_STYLE": "Top Style",
"UNISTORE_INVALID_ERROR": "This UniStore is invalid and cannot be\nloaded with Universal-Updater.\nMaybe check if there are any Syntax errors?",
"UNISTORE_TOO_NEW": "Your version of Universal-Updater is \ntoo old to use this UniStore.\nPlease update to the latest version.",
"UNISTORE_TOO_OLD": "This UniStore is outdated and cannot be used\nwith this version of Universal-Updater.\nPlease ask the creator to update it.",
"UNSUPPORTED_UNISTORE_VERSION": "The version of this UniStore is unsupported.",
"UPDATE_AVAILABLE": "Update Available!",
"UPDATE_DONE": "Update done! Please re-open Universal-Updater.",
"UPDATE_NOT_AVAILABLE": "No Updates Available!",
"UPDATING_SPRITE_SHEET": "Updating Spritesheet...",
"UPDATING_SPRITE_SHEET2": "Updating Spritesheet %i of %i...",
"UPDATING_UNISTORE": "Updating UniStore...",
"VERSION": "Version",
"YES": "Yes"
}

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
}

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();
}
}

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);
}

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;
}

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;
}
}

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;
}

View file

@ -24,24 +24,26 @@
* reasonable ways as different from the original version.
*/
#include "colorHelper.hpp"
#include "gfx.hpp"
#include "keyboard.hpp"
#include "screenCommon.hpp"
int ColorHelper::getColorValue(int color, int bgr) {
char colorName[10];
int i;
std::stringstream ss;
/*
Return a string of the keyboard.
itoa(color, colorName, 16);
std::string colorNamePart(colorName, 2*bgr+2, 2);
ss << std::hex << colorNamePart.c_str();
ss >> i;
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.
return i;
}
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';
std::string ColorHelper::getColorName(int color, int bgr) {
char colorName[10];
int i = getColorValue(color, bgr);
itoa(i, colorName, 10);
return colorName;
return (ret == SWKBD_BUTTON_CONFIRM ? temp : "");
}

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;
}
}
}

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();
}
}

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();
}

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;
}
}
}
}
}

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;
}
}

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;
}
}
}
}

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;
}
}

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
source/qr/decode.cpp Normal file
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;
}

1266
source/qr/identify.cpp Normal file

File diff suppressed because it is too large Load diff

315
source/qr/qrcode.cpp Normal file
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 "";
}

Some files were not shown because too many files have changed in this diff Show more