Compare commits
88 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
47de3eb171 | ||
|
|
02c1aab3f3 | ||
|
|
cd69aa7ef7 | ||
|
|
a2b5788fe8 | ||
|
|
5090da114f | ||
|
|
f01e347b17 | ||
|
|
82f6e073ce | ||
|
|
ed94610d0f | ||
|
|
fbbb4f590d | ||
|
|
d2e65d1edc | ||
|
|
fd7e932df3 | ||
|
|
b2e81528af | ||
|
|
f5dd25369a | ||
|
|
fc9d0be42e | ||
|
|
c6f3af7350 | ||
| 642b9f9c13 | |||
| 10b130b416 | |||
|
|
f65b32c90c | ||
|
|
841773d9e4 | ||
|
|
a764ea9bed | ||
|
|
45349a4ba3 | ||
|
|
c85d9d978d | ||
|
|
db0804af3b | ||
|
|
310c92bee2 | ||
|
|
b59e5fc078 | ||
|
|
6eabfc84ab | ||
|
|
cb88c7e2dc | ||
|
|
b72f266e40 | ||
|
|
f261f152c9 | ||
|
|
2848cade74 | ||
|
|
05d3ac73c0 | ||
|
|
a92db32d67 | ||
|
|
78bdb0d738 | ||
|
|
23c98a4ed1 | ||
|
|
15be473684 | ||
|
|
fb18dce177 | ||
|
|
adf2a50143 | ||
|
|
0f27cb1259 | ||
|
|
c1ef601c2f | ||
|
|
7c3ca57e07 | ||
|
|
0818389752 | ||
|
|
6be1b5e217 | ||
|
|
d937ae1716 | ||
|
|
ab4ead03b5 | ||
|
|
026bb367bc | ||
|
|
5c52b475ce | ||
|
|
32116aa8ed | ||
|
|
f01793321e | ||
|
|
3cfbf3c35b | ||
|
|
36106b72f2 | ||
|
|
1d95f47840 | ||
|
|
204d5e8a85 | ||
|
|
6c3fdbaf31 | ||
|
|
b5c78cf68b | ||
| 24810a48ad | |||
|
|
5d2119344a | ||
|
|
492ea13ef6 | ||
|
|
f99f744000 | ||
| 4fb10029bb | |||
| 7644974705 | |||
|
|
b7379af2f3 | ||
| 26d8c283b3 | |||
| 4ceac06f0c | |||
| 337693ca13 | |||
| 8ba1fed5d7 | |||
|
|
d99f1c97a0 | ||
|
|
1a1b3e25b0 | ||
| c92c20d4e8 | |||
| ef456c7e9e | |||
| 1103885baf | |||
| 5564ffe31b | |||
| 97ab2307f8 | |||
|
|
47c64828a4 | ||
| d3aa231c3f | |||
|
|
3fb86c80be | ||
|
|
67566330a5 | ||
| 68805337bf | |||
|
|
416cca88d3 | ||
| 2be3bde64d | |||
| c46c5ff8cb | |||
|
|
6b5b391d7b | ||
|
|
dc1cbda232 | ||
|
|
e63a4066a1 | ||
| 2e71fc5954 | |||
| 778e1a8331 | |||
| 0871f4f30b | |||
| 62f4356a17 | |||
|
|
3e2c5994ca |
BIN
.flask/banner.t3x
Normal file
BIN
.flask/icon.t3x
Normal file
5
.flask/meta.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"user": "astronautlevel2",
|
||||
"name": "Anemone3DS",
|
||||
"description": "A theme and boot splash manager for the Nintendo 3DS console"
|
||||
}
|
||||
3
.gitmodules
vendored
@@ -1,3 +0,0 @@
|
||||
[submodule "source/pp2d"]
|
||||
path = source/pp2d
|
||||
url = https://github.com/BernardoGiordano/pp2d.git
|
||||
20
Makefile
@@ -11,14 +11,14 @@ include $(DEVKITARM)/3ds_rules
|
||||
|
||||
# Your values.
|
||||
APP_TITLE := Anemone3DS
|
||||
APP_DESCRIPTION := A complete themeing tool for the 3DS
|
||||
APP_DESCRIPTION := A complete theming tool for the 3DS
|
||||
APP_AUTHOR := astronautlevel and daedreth
|
||||
|
||||
|
||||
TARGET := $(subst $e ,_,$(notdir $(APP_TITLE)))
|
||||
OUTDIR := out
|
||||
BUILD := build
|
||||
SOURCES := source source/pp2d/pp2d source/minizip source/quirc
|
||||
SOURCES := source source/pp2d/pp2d source/quirc
|
||||
INCLUDES := include
|
||||
ROMFS := romfs
|
||||
|
||||
@@ -33,7 +33,7 @@ BANNER_IMAGE := meta/banner.png
|
||||
RSF_PATH := meta/app.rsf
|
||||
|
||||
# If left blank, makerom will use the default Homebrew logo
|
||||
LOGO :=
|
||||
LOGO := meta/logo.bin
|
||||
|
||||
|
||||
# If left blank, makerom will use default values (0xff3ff and CTR-P-CTAP, respectively)
|
||||
@@ -49,26 +49,29 @@ ICON_FLAGS := nosavebackups,visible
|
||||
#---------------------------------------------------------------------------------
|
||||
ARCH := -march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft
|
||||
|
||||
CFLAGS := -g -Wall -Wextra -mword-relocations \
|
||||
CFLAGS := -g -Wall -Wextra -O2 -mword-relocations \
|
||||
-ffunction-sections \
|
||||
$(ARCH)
|
||||
|
||||
revision := $(shell git describe --tags --match v[0-9]* --abbrev=8 | sed 's/-[0-9]*-g/-/')
|
||||
|
||||
CFLAGS += $(INCLUDE) -DARM11 -D_3DS -D_GNU_SOURCE -DVERSION="\"$(revision)\""
|
||||
CFLAGS += $(INCLUDE) -DARM11 -D_3DS -D_GNU_SOURCE -DVERSION="\"$(revision)\"" -DUSER_AGENT="\"$(APP_TITLE)/$(revision)\""
|
||||
ifneq ($(strip $(CITRA_MODE)),)
|
||||
CFLAGS += -DCITRA_MODE
|
||||
endif
|
||||
|
||||
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11
|
||||
|
||||
ASFLAGS := -g $(ARCH)
|
||||
LDFLAGS = -specs=3dsx.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
|
||||
|
||||
LIBS := -lcitro3d -lctrud -lm -lz
|
||||
LIBS := -larchive -ljansson -lcitro3d -lctrud -lm -lz
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# list of directories containing libraries, this must be the top level containing
|
||||
# include and lib
|
||||
#---------------------------------------------------------------------------------
|
||||
LIBDIRS := $(CTRULIB) $(DEVKITPRO)/portlibs/armv6k
|
||||
LIBDIRS := $(CTRULIB) $(PORTLIBS)
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
@@ -146,6 +149,9 @@ all: 3dsx cia
|
||||
3dsx: $(BUILD) $(OUTPUT).3dsx
|
||||
|
||||
cia : $(BUILD) $(OUTPUT).cia
|
||||
|
||||
citra: export CITRA_MODE = 1
|
||||
citra: 3dsx
|
||||
#---------------------------------------------------------------------------------
|
||||
$(BUILD):
|
||||
@mkdir -p $(OUTDIR)
|
||||
|
||||
16
README.md
@@ -1,28 +1,30 @@
|
||||

|
||||
|
||||
A Theme and Splashscreen Manager for the Nintendo3DS, written in C.
|
||||
A Theme and Splashscreen Manager for the Nintendo 3DS, written in C.\
|
||||
To-do list here: https://trello.com/b/F1YSa1VK
|
||||
|
||||
# Dependencies
|
||||
* zlib, which can be retrieved from the [3ds_portlibs](https://github.com/devkitPro/3ds_portlibs).
|
||||
* zlib, jansson, and libarchive, which can be retrieved from the [3ds_portlibs](https://github.com/devkitPro/3ds_portlibs).
|
||||
|
||||
* [makerom](https://github.com/profi200/Project_CTR) and [bannertool](https://github.com/Steveice10/buildtools), which can be retrieved from [SteveIce10's](https://github.com/Steveice10) buildtools repo. These must be added to your PATH.
|
||||
* [pp2d](https://github.com/BernardoGiordano/pp2d), which is included in the repo if you do a git clone --recursive.
|
||||
* ~~[pp2d](https://github.com/BernardoGiordano/pp2d), which is included in the repo if you do a git clone --recursive.~~ Due to circumstances surrounding the privacy settings on the pp2d repo, the source files are now included directly within the repo.
|
||||
* Git needs to be on your PATH, if building in a non-*nix environment.
|
||||
# Building
|
||||
First of all, make sure devkitPRO is properly installed and added to the PATH.
|
||||
After that, open the directory you want to clone the repo into, and type: `git clone https://github.com/astronautlevel2/Anemone3DS/ --recursive`.
|
||||
Instructions for installing zlib can be found on the [3ds_portlibs repo](https://github.com/devkitPro/3ds_portlibs) (its easy, just run `make` and `make install-zlib`). After also adding [makerom](https://github.com/profi200/Project_CTR) and [bannertool](https://github.com/Steveice10/buildtools) to your PATH, just enter your directory and run `make`. All built files will be in `/out/`.
|
||||
Instructions for installing zlib, jansson and libarchive can be found on the [3ds_portlibs repo](https://github.com/devkitPro/3ds_portlibs) (its easy, just run `make` and `make install-zlib`). After also adding [makerom](https://github.com/profi200/Project_CTR) and [bannertool](https://github.com/Steveice10/buildtools) to your PATH, just enter your directory and run `make`. All built files will be in `/out/`.
|
||||
# License
|
||||
This project is licensed under the GNU GPLv3. See LICENSE.md for details. Additional terms 7b and 7c apply to this project.
|
||||
|
||||
# Credits
|
||||
The following people contributed to Anemone3DS in some way. Without these people, Anemone3DS wouldn't exist, or wouldn't be as good as it is:
|
||||
* [Daedreth](https://github.com/daedreth), who wrote the initial implementation of theme application code and SMDH parsing.
|
||||
* [LiquidFenrir](https://github.com/LiquidFenrir), who refactored a lot of my messy GUI code and wrote the image preview from zip code, as well as the icon code.
|
||||
* [Sono](https://github.com/MarcuzD), who wrote the BCSTM playback code.
|
||||
* [Daedreth](https://github.com/daedreth), who wrote the initial implementation of theme installation code and SMDH parsing.
|
||||
* [LiquidFenrir](https://github.com/LiquidFenrir), who refactored a lot of my messy code and has been essential in development.
|
||||
* [Kenn (mattkenster)](https://github.com/mattkenster), for designing the GUI, a number of sprites used in the application, and drawing the banner and icon.
|
||||
|
||||
Special thanks go to these people who, while not directly contributing, helped immensely:
|
||||
* [Rinnegatamante](https://github.com/Rinnegatamante), whose code served as reference on theme installation.
|
||||
* [SteveIce10](https://github.com/SteveIce10), whose QR code in FBI was essential.
|
||||
* [BernardoGiordano](https://github.com/BernardoGiordano) for making pp2d, and being super responsive to feature requests and just general help.
|
||||
* [yellows8](https://github.com/yellows8) for his home menu extdump tool, which was invaluable in debugging.
|
||||
* the folks on #dev of Nintendo Homebrew, who helped with unicode shenanigans (especially [Stary2001](https://github.com/Stary2001), [Fenrir](https://github.com/FenrirWolf), and DanielKO).
|
||||
|
||||
@@ -29,13 +29,20 @@
|
||||
|
||||
#include "common.h"
|
||||
|
||||
struct quirc* context;
|
||||
u16 *buf;
|
||||
bool qr_mode;
|
||||
typedef struct {
|
||||
u16 *camera_buffer;
|
||||
u32 *texture_buffer;
|
||||
Handle mutex;
|
||||
volatile bool finished;
|
||||
volatile bool success;
|
||||
Handle cancel;
|
||||
|
||||
void init_qr(void);
|
||||
void exit_qr(void);
|
||||
bool capturing;
|
||||
struct quirc* context;
|
||||
} qr_data;
|
||||
|
||||
bool init_qr(void);
|
||||
void exit_qr(qr_data *data);
|
||||
void take_picture(void);
|
||||
Result http_get(char *url, char *path);
|
||||
|
||||
#endif
|
||||
43
include/colors.h
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* This file is part of Anemone3DS
|
||||
* Copyright (C) 2016-2017 Alex Taber ("astronautlevel"), Dawid Eckert ("daedreth")
|
||||
*
|
||||
* 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 COLORS_H
|
||||
#define COLORS_H
|
||||
|
||||
#define ABGR8(a, b, g, r) ((((a)&0xFF)<<0) | (((b)&0xFF)<<8) | (((g)&0xFF)<<16) | (((r)&0xFF)<<24))
|
||||
#define RGBA8(r, g, b, a) ((((r)&0xFF)<<0) | (((g)&0xFF)<<8) | (((b)&0xFF)<<16) | (((a)&0xFF)<<24))
|
||||
|
||||
typedef enum {
|
||||
COLOR_BACKGROUND = ABGR8(255, 32, 28, 35), //silver-y black
|
||||
COLOR_ACCENT = RGBA8(55, 122, 168, 255),
|
||||
COLOR_WHITE = RGBA8(255, 255, 255, 255),
|
||||
COLOR_CURSOR = RGBA8(200, 200, 200, 255),
|
||||
COLOR_BLACK = RGBA8(0, 0, 0, 255),
|
||||
COLOR_RED = RGBA8(200, 0, 0, 255),
|
||||
COLOR_YELLOW = RGBA8(239, 220, 11, 255),
|
||||
} Color;
|
||||
|
||||
#endif
|
||||
@@ -33,23 +33,40 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define THEMES_PATH "/Themes/"
|
||||
#define SPLASHES_PATH "/Splashes/"
|
||||
#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
|
||||
#define POS() DEBUG("%s (line %d)...\n", __func__, __LINE__)
|
||||
|
||||
#define SINGLE_INSTALL 0
|
||||
#define SHUFFLE_INSTALL 1
|
||||
#define BGM_INSTALL 2
|
||||
#define UNINSTALL 3
|
||||
#define DOWNLOADING 3
|
||||
#define DEBUGPOS(...) \
|
||||
POS(); \
|
||||
DEBUG(__VA_ARGS__)
|
||||
|
||||
#define ERROR 0
|
||||
#define WARNING 1
|
||||
static const int THEMES_PER_SCREEN = 4;
|
||||
#define FASTSCROLL_WAIT 1.5e8
|
||||
|
||||
typedef enum {
|
||||
MODE_THEMES = 0,
|
||||
MODE_SPLASHES,
|
||||
|
||||
MODE_AMOUNT,
|
||||
} EntryMode;
|
||||
|
||||
extern const char * main_paths[MODE_AMOUNT];
|
||||
extern const int entries_per_screen_v[MODE_AMOUNT];
|
||||
extern const int entries_per_screen_h[MODE_AMOUNT];
|
||||
extern const int entry_size[MODE_AMOUNT];
|
||||
extern bool quit;
|
||||
|
||||
enum TextureID {
|
||||
TEXTURE_FONT_RESERVED = 0, // used by pp2d for the font
|
||||
TEXTURE_ARROW,
|
||||
TEXTURE_ARROW_SIDE,
|
||||
TEXTURE_SHUFFLE,
|
||||
TEXTURE_INSTALLED,
|
||||
TEXTURE_PREVIEW_ICON,
|
||||
TEXTURE_DOWNLOAD,
|
||||
TEXTURE_BROWSE,
|
||||
TEXTURE_LIST,
|
||||
TEXTURE_EXIT,
|
||||
TEXTURE_BATTERY_0,
|
||||
TEXTURE_BATTERY_1,
|
||||
TEXTURE_BATTERY_2,
|
||||
TEXTURE_BATTERY_3,
|
||||
@@ -58,6 +75,13 @@ enum TextureID {
|
||||
TEXTURE_BATTERY_CHARGE,
|
||||
TEXTURE_QR,
|
||||
TEXTURE_PREVIEW,
|
||||
TEXTURE_REMOTE_PREVIEW,
|
||||
TEXTURE_SELECT_BUTTON,
|
||||
TEXTURE_START_BUTTON,
|
||||
|
||||
// always the last
|
||||
TEXTURE_REMOTE_ICONS,
|
||||
TEXTURE_ICON = TEXTURE_REMOTE_ICONS + 24,
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -27,18 +27,74 @@
|
||||
#ifndef DRAW_H
|
||||
#define DRAW_H
|
||||
|
||||
#include "themes.h"
|
||||
#include "splashes.h"
|
||||
#include "camera.h"
|
||||
#include "common.h"
|
||||
#include "loading.h"
|
||||
#include "colors.h"
|
||||
|
||||
typedef enum {
|
||||
INSTALL_LOADING_THEMES,
|
||||
INSTALL_LOADING_SPLASHES,
|
||||
INSTALL_LOADING_ICONS,
|
||||
|
||||
INSTALL_SPLASH,
|
||||
INSTALL_SPLASH_DELETE,
|
||||
|
||||
INSTALL_SINGLE,
|
||||
INSTALL_SHUFFLE,
|
||||
INSTALL_BGM,
|
||||
INSTALL_NO_BGM,
|
||||
|
||||
INSTALL_DOWNLOAD,
|
||||
INSTALL_CHECKING_DOWNLOAD,
|
||||
INSTALL_ENTRY_DELETE,
|
||||
|
||||
INSTALL_LOADING_REMOTE_THEMES,
|
||||
INSTALL_LOADING_REMOTE_SPLASHES,
|
||||
INSTALL_LOADING_REMOTE_PREVIEW,
|
||||
|
||||
INSTALL_NONE,
|
||||
} InstallType;
|
||||
|
||||
typedef enum {
|
||||
ERROR_LEVEL_ERROR,
|
||||
ERROR_LEVEL_WARNING,
|
||||
} ErrorLevel;
|
||||
|
||||
#define BUTTONS_START_Y 130
|
||||
#define BUTTONS_STEP 22
|
||||
#define BUTTONS_INFO_LINES 4
|
||||
#define BUTTONS_INFO_COLUNMNS 2
|
||||
|
||||
enum {
|
||||
BUTTONS_Y_INFO = BUTTONS_START_Y+5,
|
||||
|
||||
BUTTONS_Y_LINE_1 = BUTTONS_START_Y + BUTTONS_STEP*1,
|
||||
BUTTONS_Y_LINE_2 = BUTTONS_START_Y + BUTTONS_STEP*2,
|
||||
BUTTONS_Y_LINE_3 = BUTTONS_START_Y + BUTTONS_STEP*3,
|
||||
BUTTONS_Y_LINE_4 = BUTTONS_START_Y + BUTTONS_STEP*4,
|
||||
|
||||
BUTTONS_X_LEFT = 20,
|
||||
BUTTONS_X_RIGHT = 200,
|
||||
} ButtonPos;
|
||||
|
||||
typedef struct {
|
||||
const wchar_t * info_line;
|
||||
Color info_line_color;
|
||||
const wchar_t * instructions[BUTTONS_INFO_LINES][BUTTONS_INFO_COLUNMNS];
|
||||
} Instructions_s;
|
||||
|
||||
void init_screens(void);
|
||||
void exit_screens(void);
|
||||
|
||||
void throw_error(char* error, ErrorLevel level);
|
||||
bool draw_confirm(const char* conf_msg, Entry_List_s* list);
|
||||
|
||||
void draw_preview(ssize_t previewID, int preview_offset);
|
||||
|
||||
void draw_install(InstallType type);
|
||||
|
||||
void draw_base_interface(void);
|
||||
void draw_qr(void);
|
||||
void draw_theme_install(int install_type);
|
||||
void draw_theme_interface(Theme_s * themes_list, int theme_count, int selected_theme, bool preview_mode, int shuffle_theme_count);
|
||||
void draw_splash_install(int install_type);
|
||||
void draw_splash_interface(Splash_s *splashes_list, int splash_count, int selected_splash, bool preview_mode);
|
||||
void throw_error(char* error, int error_type);
|
||||
void draw_grid_interface(Entry_List_s* list, Instructions_s instructions);
|
||||
void draw_interface(Entry_List_s* list, Instructions_s instructions);
|
||||
|
||||
#endif
|
||||
@@ -36,7 +36,8 @@ FS_Archive ArchiveThemeExt;
|
||||
Result open_archives(void);
|
||||
Result close_archives(void);
|
||||
|
||||
u64 file_to_buf(FS_Path path, FS_Archive archive, char** buf);
|
||||
u32 file_to_buf(FS_Path path, FS_Archive archive, char** buf);
|
||||
u32 zip_memory_to_buf(char *file_name, void * zip_memory, size_t zip_size, char ** buf);
|
||||
u32 zip_file_to_buf(char *file_name, u16 *zip_path, char **buf);
|
||||
|
||||
Result buf_to_file(u32 size, char *path, FS_Archive archive, char *buf);
|
||||
|
||||
124
include/instructions.h
Normal file
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* This file is part of Anemone3DS
|
||||
* Copyright (C) 2016-2017 Alex Taber ("astronautlevel"), Dawid Eckert ("daedreth")
|
||||
*
|
||||
* 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 INSTRUCTIONS_H
|
||||
#define INSTRUCTIONS_H
|
||||
|
||||
#include "draw.h"
|
||||
#include "colors.h"
|
||||
|
||||
Instructions_s normal_instructions[MODE_AMOUNT] = {
|
||||
{
|
||||
.info_line = NULL,
|
||||
.instructions = {
|
||||
{
|
||||
L"\uE000 Hold to install",
|
||||
L"\uE001 Queue shuffle theme"
|
||||
},
|
||||
{
|
||||
L"\uE002 Hold for more",
|
||||
L"\uE003 Preview theme"
|
||||
},
|
||||
{
|
||||
L"\uE004 Switch to splashes",
|
||||
L"\uE005 Scan QR code"
|
||||
},
|
||||
{
|
||||
L"Exit",
|
||||
L"Delete from SD"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
.info_line = NULL,
|
||||
.instructions = {
|
||||
{
|
||||
L"\uE000 Install splash",
|
||||
L"\uE001 Delete installed splash"
|
||||
},
|
||||
{
|
||||
L"\uE002 Hold for more",
|
||||
L"\uE003 Preview splash"
|
||||
},
|
||||
{
|
||||
L"\uE004 Switch to themes",
|
||||
L"\uE005 Scan QR code"
|
||||
},
|
||||
{
|
||||
L"Exit",
|
||||
L"Delete from SD"
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Instructions_s install_instructions = {
|
||||
.info_line = L"Release \uE000 to cancel or hold \uE006 and release \uE000 to install",
|
||||
.info_line_color = COLOR_WHITE,
|
||||
.instructions = {
|
||||
{
|
||||
L"\uE079 Normal install",
|
||||
L"\uE07A Shuffle install"
|
||||
},
|
||||
{
|
||||
L"\uE07B BGM-only install",
|
||||
L"\uE07C No-BGM install"
|
||||
},
|
||||
{
|
||||
NULL,
|
||||
NULL
|
||||
},
|
||||
{
|
||||
L"Exit",
|
||||
NULL
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Instructions_s extra_instructions = {
|
||||
.info_line = L"Release \uE002 to cancel or hold \uE006 and release \uE002 to do stuff",
|
||||
.info_line_color = COLOR_WHITE,
|
||||
.instructions = {
|
||||
{
|
||||
L"\uE079 Jump in the list",
|
||||
L"\uE07A Reload broken icons"
|
||||
},
|
||||
{
|
||||
L"\uE07B Browse ThemePlaza",
|
||||
NULL
|
||||
},
|
||||
{
|
||||
NULL,
|
||||
NULL
|
||||
},
|
||||
{
|
||||
L"Exit",
|
||||
NULL
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
109
include/loading.h
Normal file
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* This file is part of Anemone3DS
|
||||
* Copyright (C) 2016-2017 Alex Taber ("astronautlevel"), Dawid Eckert ("daedreth")
|
||||
*
|
||||
* 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 LOADING_H
|
||||
#define LOADING_H
|
||||
|
||||
#include "common.h"
|
||||
#include <jansson.h>
|
||||
|
||||
enum ICON_IDS_OFFSET {
|
||||
ICONS_ABOVE = 0,
|
||||
ICONS_VISIBLE,
|
||||
ICONS_UNDER,
|
||||
|
||||
ICONS_OFFSET_AMOUNT,
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
u8 _padding1[4 + 2 + 2];
|
||||
|
||||
u16 name[0x40];
|
||||
u16 desc[0x80];
|
||||
u16 author[0x40];
|
||||
|
||||
u8 _padding2[0x2000 - 0x200 + 0x30 + 0x8];
|
||||
u16 small_icon[24*24];
|
||||
|
||||
u16 big_icon[48*48];
|
||||
} Icon_s;
|
||||
|
||||
typedef struct {
|
||||
u16 name[0x41];
|
||||
u16 desc[0x81];
|
||||
u16 author[0x41];
|
||||
|
||||
u32 placeholder_color;
|
||||
|
||||
u16 path[0x106];
|
||||
bool is_zip;
|
||||
|
||||
bool in_shuffle;
|
||||
bool installed;
|
||||
|
||||
json_int_t tp_download_id;
|
||||
} Entry_s;
|
||||
|
||||
typedef struct {
|
||||
Entry_s * entries;
|
||||
int entries_count;
|
||||
|
||||
ssize_t texture_id_offset;
|
||||
ssize_t * icons_ids;
|
||||
|
||||
int previous_scroll;
|
||||
int scroll;
|
||||
|
||||
int previous_selected;
|
||||
int selected_entry;
|
||||
|
||||
int shuffle_count;
|
||||
|
||||
EntryMode mode;
|
||||
int entries_per_screen_v;
|
||||
int entries_per_screen_h;
|
||||
int entries_loaded;
|
||||
int entry_size;
|
||||
|
||||
json_int_t tp_current_page;
|
||||
json_int_t tp_page_count;
|
||||
char * tp_search;
|
||||
} Entry_List_s;
|
||||
|
||||
typedef struct {
|
||||
void ** thread_arg;
|
||||
volatile bool run_thread;
|
||||
} Thread_Arg_s;
|
||||
|
||||
void delete_entry(Entry_s * entry, bool is_file);
|
||||
Result load_entries(const char * loading_path, Entry_List_s * list);
|
||||
bool load_preview(Entry_List_s list, int * preview_offset);
|
||||
void load_icons_first(Entry_List_s * current_list, bool silent);
|
||||
void handle_scrolling(Entry_List_s * list);
|
||||
void load_icons_thread(void * void_arg);
|
||||
u32 load_data(char * filename, Entry_s entry, char ** buf);
|
||||
|
||||
#endif
|
||||
57
include/remote.h
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* This file is part of Anemone3DS
|
||||
* Copyright (C) 2016-2017 Alex Taber ("astronautlevel"), Dawid Eckert ("daedreth")
|
||||
*
|
||||
* 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 REMOTE_H
|
||||
#define REMOTE_H
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#define THEMEPLAZA_BASE_URL "https://themeplaza.eu"
|
||||
#define THEMEPLAZA_API_URL "/api/anemone/v1"
|
||||
#define THEMEPLAZA_BASE_API_URL THEMEPLAZA_BASE_URL THEMEPLAZA_API_URL
|
||||
|
||||
#define THEMEPLAZA_PAGE_FORMAT THEMEPLAZA_BASE_API_URL "/list?page=%" JSON_INTEGER_FORMAT "&category=%i&query=%s"
|
||||
#define THEMEPLAZA_JSON_PAGE_COUNT "pages"
|
||||
#define THEMEPLAZA_JSON_PAGE_IDS "items"
|
||||
|
||||
#define THEMEPLAZA_JSON_ERROR_MESSAGE "message"
|
||||
#define THEMEPLAZA_JSON_ERROR_MESSAGE_NOT_FOUND "No items found"
|
||||
|
||||
|
||||
#define THEMEPLAZA_ENTRY_FORMAT THEMEPLAZA_BASE_API_URL "/query?item_id=%" JSON_INTEGER_FORMAT
|
||||
#define THEMEPLAZA_JSON_ENTRY_NAME "title"
|
||||
#define THEMEPLAZA_JSON_ENTRY_DESC "description"
|
||||
#define THEMEPLAZA_JSON_ENTRY_AUTH "author"
|
||||
|
||||
#define THEMEPLAZA_DOWNLOAD_FORMAT THEMEPLAZA_BASE_URL "/download/%" JSON_INTEGER_FORMAT
|
||||
#define THEMEPLAZA_PREVIEW_FORMAT THEMEPLAZA_DOWNLOAD_FORMAT "/preview"
|
||||
#define THEMEPLAZA_BGM_FORMAT THEMEPLAZA_DOWNLOAD_FORMAT "/bgm"
|
||||
#define THEMEPLAZA_ICON_FORMAT THEMEPLAZA_DOWNLOAD_FORMAT "/preview/icon"
|
||||
|
||||
bool themeplaza_browser(EntryMode mode);
|
||||
u32 http_get(const char *url, char ** filename, char ** buf);
|
||||
|
||||
#endif
|
||||
@@ -28,14 +28,11 @@
|
||||
#define SPLASHES_H
|
||||
|
||||
#include "common.h"
|
||||
#include "loading.h"
|
||||
|
||||
typedef struct{
|
||||
u16 name[0x106];
|
||||
u16 top_path[0x106];
|
||||
u16 bottom_path[0x106];
|
||||
} Splash_s;
|
||||
void splash_delete(void);
|
||||
void splash_install(Entry_s splash);
|
||||
|
||||
void splash_check_installed(void * void_arg);
|
||||
|
||||
Result get_splashes(Splash_s** splashes_list, int *splash_count);
|
||||
void splash_install(Splash_s splash_to_install);
|
||||
void splash_delete();
|
||||
#endif
|
||||
@@ -28,32 +28,53 @@
|
||||
#define THEMES_H
|
||||
|
||||
#include "common.h"
|
||||
#include "loading.h"
|
||||
|
||||
#define MAX_SHUFFLE_THEMES 10
|
||||
|
||||
enum ThemeInstall {
|
||||
THEME_INSTALL_SHUFFLE = BIT(0),
|
||||
THEME_INSTALL_BODY = BIT(1),
|
||||
THEME_INSTALL_BGM = BIT(2),
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
u16 name[0x40];
|
||||
u16 desc[0x80];
|
||||
u16 author[0x40];
|
||||
u32 index;
|
||||
u8 dlc_tid_low_bits;
|
||||
u8 type;
|
||||
u16 unk;
|
||||
} ThemeEntry_s;
|
||||
|
||||
u32 placeholder_color;
|
||||
ssize_t icon_id;
|
||||
typedef struct {
|
||||
u8 _padding1[0x13b8];
|
||||
ThemeEntry_s theme_entry;
|
||||
ThemeEntry_s shuffle_themes[MAX_SHUFFLE_THEMES];
|
||||
u8 _padding2[0xb];
|
||||
bool shuffle;
|
||||
} SaveData_dat_s;
|
||||
|
||||
bool has_preview;
|
||||
int preview_offset;
|
||||
typedef struct {
|
||||
u32 unk1;
|
||||
u32 unk2;
|
||||
u32 body_size;
|
||||
u32 music_size;
|
||||
u32 unk3;
|
||||
u32 unk4;
|
||||
u32 dlc_theme_content_index;
|
||||
u32 use_theme_cache;
|
||||
|
||||
u16 path[0x106];
|
||||
bool is_zip;
|
||||
u8 _padding1[0x338 - 8*sizeof(u32)];
|
||||
|
||||
bool in_shuffle;
|
||||
} Theme_s;
|
||||
u32 shuffle_body_sizes[MAX_SHUFFLE_THEMES];
|
||||
u32 shuffle_music_sizes[MAX_SHUFFLE_THEMES];
|
||||
} ThemeManage_bin_s;
|
||||
|
||||
Theme_s * themes_list;
|
||||
int theme_count;
|
||||
Result theme_install(Entry_s theme);
|
||||
Result no_bgm_install(Entry_s theme);
|
||||
Result bgm_install(Entry_s theme);
|
||||
|
||||
void load_theme_preview(Theme_s *theme);
|
||||
Result get_themes(Theme_s **themes_list, int *theme_count);
|
||||
void add_theme(Theme_s **themes_list, int *theme_count, char *path, char *filename);
|
||||
Result single_install(Theme_s theme);
|
||||
Result shuffle_install(Theme_s *themes_list, int theme_count);
|
||||
Result bgm_install(Theme_s bgm_to_install);
|
||||
Result shuffle_install(Entry_List_s themes);
|
||||
|
||||
void themes_check_installed(void * void_arg);
|
||||
|
||||
#endif
|
||||
BIN
meta/logo.bin
Normal file
BIN
romfs/arrow_side.png
Normal file
|
After Width: | Height: | Size: 2.9 KiB |
BIN
romfs/battery0.png
Normal file
|
After Width: | Height: | Size: 498 B |
|
Before Width: | Height: | Size: 443 B After Width: | Height: | Size: 303 B |
|
Before Width: | Height: | Size: 271 B After Width: | Height: | Size: 319 B |
|
Before Width: | Height: | Size: 272 B After Width: | Height: | Size: 323 B |
|
Before Width: | Height: | Size: 272 B After Width: | Height: | Size: 323 B |
|
Before Width: | Height: | Size: 272 B After Width: | Height: | Size: 323 B |
BIN
romfs/browse.png
Normal file
|
After Width: | Height: | Size: 654 B |
BIN
romfs/download.png
Normal file
|
After Width: | Height: | Size: 404 B |
BIN
romfs/exit.png
Normal file
|
After Width: | Height: | Size: 390 B |
BIN
romfs/installed.png
Normal file
|
After Width: | Height: | Size: 579 B |
BIN
romfs/list.png
Normal file
|
After Width: | Height: | Size: 179 B |
BIN
romfs/preview.png
Normal file
|
After Width: | Height: | Size: 307 B |
BIN
romfs/select.png
Normal file
|
After Width: | Height: | Size: 1.7 KiB |
|
Before Width: | Height: | Size: 466 B After Width: | Height: | Size: 658 B |
BIN
romfs/start.png
Normal file
|
After Width: | Height: | Size: 494 B |
402
source/camera.c
@@ -27,183 +27,273 @@
|
||||
#include "camera.h"
|
||||
|
||||
#include "quirc/quirc.h"
|
||||
#include "pp2d/pp2d/pp2d.h"
|
||||
|
||||
#include "draw.h"
|
||||
#include "fs.h"
|
||||
#include "themes.h"
|
||||
#include "loading.h"
|
||||
#include "remote.h"
|
||||
|
||||
void init_qr(void)
|
||||
{
|
||||
camInit();
|
||||
CAMU_SetSize(SELECT_OUT1_OUT2, SIZE_CTR_TOP_LCD, CONTEXT_A);
|
||||
CAMU_SetOutputFormat(SELECT_OUT1_OUT2, OUTPUT_RGB_565, CONTEXT_A);
|
||||
|
||||
CAMU_SetNoiseFilter(SELECT_OUT1_OUT2, true);
|
||||
CAMU_SetAutoExposure(SELECT_OUT1_OUT2, true);
|
||||
CAMU_SetAutoWhiteBalance(SELECT_OUT1_OUT2, true);
|
||||
|
||||
CAMU_SetTrimming(PORT_CAM1, false);
|
||||
|
||||
buf = malloc(sizeof(u16) * 400 * 240 * 2);
|
||||
|
||||
context = quirc_new();
|
||||
quirc_resize(context, 400, 240);
|
||||
}
|
||||
|
||||
void exit_qr(void)
|
||||
{
|
||||
CAMU_Activate(SELECT_NONE);
|
||||
camExit();
|
||||
quirc_destroy(context);
|
||||
free(buf);
|
||||
}
|
||||
|
||||
void take_picture(void)
|
||||
{
|
||||
u32 transfer_size;
|
||||
Handle cam_handle = 0;
|
||||
CAMU_GetMaxBytes(&transfer_size, 400, 240);
|
||||
CAMU_SetTransferBytes(PORT_BOTH, transfer_size, 400, 240);
|
||||
CAMU_Activate(SELECT_OUT1_OUT2);
|
||||
CAMU_ClearBuffer(PORT_BOTH);
|
||||
CAMU_SynchronizeVsyncTiming(SELECT_OUT1, SELECT_OUT2);
|
||||
CAMU_StartCapture(PORT_BOTH);
|
||||
CAMU_SetReceiving(&cam_handle, buf, PORT_CAM1, 400 * 240 * 2, transfer_size);
|
||||
svcWaitSynchronization(cam_handle, U64_MAX);
|
||||
CAMU_StopCapture(PORT_BOTH);
|
||||
svcCloseHandle(cam_handle);
|
||||
CAMU_Activate(PORT_NONE);
|
||||
}
|
||||
#include <archive.h>
|
||||
#include <archive_entry.h>
|
||||
|
||||
/*
|
||||
Putting this in camera because I'm too lazy to make a network.c
|
||||
This'll probably get refactored later
|
||||
static u32 transfer_size;
|
||||
static Handle event;
|
||||
static struct quirc* context;
|
||||
static u16 * camera_buf = NULL;
|
||||
*/
|
||||
Result http_get(char *url, char *path)
|
||||
{
|
||||
Result ret;
|
||||
httpcContext context;
|
||||
char *new_url = NULL;
|
||||
u32 status_code;
|
||||
u32 content_size = 0;
|
||||
u32 read_size = 0;
|
||||
u32 size = 0;
|
||||
u8 *buf;
|
||||
u8 *last_buf;
|
||||
|
||||
void exit_qr(qr_data *data)
|
||||
{
|
||||
svcSignalEvent(data->cancel);
|
||||
while(!data->finished)
|
||||
svcSleepThread(1000000);
|
||||
data->capturing = false;
|
||||
|
||||
free(data->camera_buffer);
|
||||
free(data->texture_buffer);
|
||||
quirc_destroy(data->context);
|
||||
free(data);
|
||||
}
|
||||
|
||||
void capture_cam_thread(void *arg)
|
||||
{
|
||||
qr_data *data = (qr_data *) arg;
|
||||
Handle events[3] = {0};
|
||||
events[0] = data->cancel;
|
||||
u32 transferUnit;
|
||||
|
||||
u16 *buffer = calloc(1, 400 * 240 * sizeof(u16));
|
||||
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_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;
|
||||
svcWaitSynchronization(data->mutex, U64_MAX);
|
||||
memcpy(data->camera_buffer, buffer, 400 * 240 * sizeof(u16));
|
||||
GSPGPU_FlushDataCache(data->camera_buffer, 400 * 240 * sizeof(u16));
|
||||
svcReleaseMutex(data->mutex);
|
||||
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();
|
||||
free(buffer);
|
||||
for(int i = 0; i < 3; i++) {
|
||||
if(events[i] != 0) {
|
||||
svcCloseHandle(events[i]);
|
||||
events[i] = 0;
|
||||
}
|
||||
}
|
||||
svcCloseHandle(data->mutex);
|
||||
data->finished = true;
|
||||
}
|
||||
|
||||
bool start_capture_cam(qr_data *data)
|
||||
{
|
||||
data->mutex = 0;
|
||||
data->cancel = 0;
|
||||
svcCreateEvent(&data->cancel, RESET_STICKY);
|
||||
svcCreateMutex(&data->mutex, false);
|
||||
if(threadCreate(capture_cam_thread, data, 0x10000, 0x1A, 1, true) == NULL)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
void update_qr(qr_data *data)
|
||||
{
|
||||
hidScanInput();
|
||||
if (hidKeysDown() & (KEY_R | KEY_B | KEY_TOUCH)) {
|
||||
exit_qr(data);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!data->capturing) {
|
||||
if(start_capture_cam(data))
|
||||
data->capturing = true;
|
||||
else {
|
||||
exit_qr(data);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (data->finished) {
|
||||
exit_qr(data);
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < 240 * 400; i++)
|
||||
{
|
||||
data->texture_buffer[i] = RGB565_TO_ABGR8(data->camera_buffer[i]);
|
||||
}
|
||||
draw_base_interface();
|
||||
pp2d_free_texture(TEXTURE_QR);
|
||||
pp2d_load_texture_memory(TEXTURE_QR, data->texture_buffer, 400, 240);
|
||||
|
||||
pp2d_draw_texture(TEXTURE_QR, 0, 0);
|
||||
|
||||
pp2d_draw_on(GFX_BOTTOM, GFX_LEFT);
|
||||
pp2d_draw_text_center(GFX_BOTTOM, 4, 0.5, 0.5, RGBA8(255, 255, 255, 255), "Press \uE005 To Quit");
|
||||
pp2d_end_draw();
|
||||
|
||||
int w;
|
||||
int h;
|
||||
u8 *image = (u8*) quirc_begin(data->context, &w, &h);
|
||||
svcWaitSynchronization(data->mutex, U64_MAX);
|
||||
for (ssize_t x = 0; x < w; x++) {
|
||||
for (ssize_t y = 0; y < h; y++) {
|
||||
u16 px = data->camera_buffer[y * 400 + x];
|
||||
image[y * w + x] = (u8)(((((px >> 11) & 0x1F) << 3) + (((px >> 5) & 0x3F) << 2) + ((px & 0x1F) << 3)) / 3);
|
||||
}
|
||||
}
|
||||
svcReleaseMutex(data->mutex);
|
||||
quirc_end(data->context);
|
||||
if(quirc_count(data->context) > 0)
|
||||
{
|
||||
struct quirc_code code;
|
||||
struct quirc_data scan_data;
|
||||
quirc_extract(data->context, 0, &code);
|
||||
if (!quirc_decode(&code, &scan_data))
|
||||
{
|
||||
exit_qr(data);
|
||||
|
||||
draw_install(INSTALL_DOWNLOAD);
|
||||
char * zip_buf = NULL;
|
||||
char * filename = NULL;
|
||||
u32 zip_size = http_get((char*)scan_data.payload, &filename, &zip_buf);
|
||||
|
||||
if(zip_size != 0)
|
||||
{
|
||||
draw_install(INSTALL_CHECKING_DOWNLOAD);
|
||||
|
||||
struct archive *a = archive_read_new();
|
||||
archive_read_support_format_zip(a);
|
||||
|
||||
int r = archive_read_open_memory(a, zip_buf, zip_size);
|
||||
archive_read_free(a);
|
||||
|
||||
if(r == ARCHIVE_OK)
|
||||
{
|
||||
EntryMode mode = MODE_AMOUNT;
|
||||
|
||||
char * buf = NULL;
|
||||
do {
|
||||
ret = httpcOpenContext(&context, HTTPC_METHOD_GET, url, 1);
|
||||
ret = httpcSetSSLOpt(&context, SSLCOPT_DisableVerify); // should let us do https
|
||||
ret = httpcSetKeepAlive(&context, HTTPC_KEEPALIVE_ENABLED);
|
||||
ret = httpcAddRequestHeaderField(&context, "User-Agent", "Anemone3DS/1.1.0");
|
||||
ret = httpcAddRequestHeaderField(&context, "Connection", "Keep-Alive");
|
||||
draw_theme_install(DOWNLOADING);
|
||||
ret = httpcBeginRequest(&context);
|
||||
if (ret != 0)
|
||||
if(zip_memory_to_buf("body_LZ.bin", zip_buf, zip_size, &buf) != 0)
|
||||
{
|
||||
httpcCloseContext(&context);
|
||||
if (new_url != NULL) free(new_url);
|
||||
return ret;
|
||||
mode = MODE_THEMES;
|
||||
break;
|
||||
}
|
||||
|
||||
ret = httpcGetResponseStatusCode(&context, &status_code);
|
||||
if(ret!=0){
|
||||
httpcCloseContext(&context);
|
||||
if(new_url!=NULL) free(new_url);
|
||||
return ret;
|
||||
}
|
||||
|
||||
if ((status_code >= 301 && status_code <= 303) || (status_code >= 307 && status_code <= 308))
|
||||
{
|
||||
if (new_url == NULL) new_url = malloc(0x1000);
|
||||
ret = httpcGetResponseHeader(&context, "Location", new_url, 0x1000);
|
||||
url = new_url;
|
||||
httpcCloseContext(&context);
|
||||
}
|
||||
} while ((status_code >= 301 && status_code <= 303) || (status_code >= 307 && status_code <= 308));
|
||||
|
||||
if (status_code != 200)
|
||||
{
|
||||
httpcCloseContext(&context);
|
||||
if (new_url != NULL) free(new_url);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = httpcGetDownloadSizeState(&context, NULL, &content_size);
|
||||
if (ret != 0)
|
||||
{
|
||||
httpcCloseContext(&context);
|
||||
if (new_url != NULL) free(new_url);
|
||||
return ret;
|
||||
}
|
||||
|
||||
buf = malloc(0x1000);
|
||||
if (buf == NULL)
|
||||
{
|
||||
httpcCloseContext(&context);
|
||||
free(new_url);
|
||||
return -2;
|
||||
}
|
||||
|
||||
char *content_disposition = malloc(1024);
|
||||
ret = httpcGetResponseHeader(&context, "Content-Disposition", content_disposition, 1024);
|
||||
if (ret != 0)
|
||||
{
|
||||
free(content_disposition);
|
||||
free(new_url);
|
||||
free(buf);
|
||||
}
|
||||
|
||||
char *filename;
|
||||
filename = strtok(content_disposition, "\"");
|
||||
filename = strtok(NULL, "\"");
|
||||
|
||||
char *illegal_characters = "\"?;:/\\+";
|
||||
for (size_t i = 0; i < strlen(filename); i++)
|
||||
buf = NULL;
|
||||
if(zip_memory_to_buf("splash.bin", zip_buf, zip_size, &buf) != 0)
|
||||
{
|
||||
for (size_t n = 0; n < strlen(illegal_characters); n++)
|
||||
mode = MODE_SPLASHES;
|
||||
break;
|
||||
}
|
||||
|
||||
free(buf);
|
||||
buf = NULL;
|
||||
if(zip_memory_to_buf("splashbottom.bin", zip_buf, zip_size, &buf) != 0)
|
||||
{
|
||||
if (filename[i] == illegal_characters[n])
|
||||
mode = MODE_SPLASHES;
|
||||
break;
|
||||
}
|
||||
}
|
||||
while(false);
|
||||
|
||||
free(buf);
|
||||
buf = NULL;
|
||||
|
||||
if(mode != MODE_AMOUNT)
|
||||
{
|
||||
filename[i] = '-';
|
||||
}
|
||||
}
|
||||
}
|
||||
char path_to_file[0x107] = {0};
|
||||
sprintf(path_to_file, "%s%s", main_paths[mode], filename);
|
||||
char * extension = strrchr(path_to_file, '.');
|
||||
if (extension == NULL || strcmp(extension, ".zip"))
|
||||
strcat(path_to_file, ".zip");
|
||||
|
||||
do {
|
||||
ret = httpcDownloadData(&context, buf + size, 0x1000, &read_size);
|
||||
size += read_size;
|
||||
|
||||
if (ret == (s32)HTTPC_RESULTCODE_DOWNLOADPENDING)
|
||||
remake_file(path_to_file, ArchiveSD, zip_size);
|
||||
buf_to_file(zip_size, path_to_file, ArchiveSD, zip_buf);
|
||||
data->success = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
last_buf = buf;
|
||||
buf = realloc(buf, size + 0x1000);
|
||||
if (buf == NULL)
|
||||
throw_error("Zip downloaded is neither\na splash nor a theme.", ERROR_LEVEL_WARNING);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
httpcCloseContext(&context);
|
||||
free(last_buf);
|
||||
return ret;
|
||||
throw_error("File downloaded isn't a zip.", ERROR_LEVEL_WARNING);
|
||||
}
|
||||
}
|
||||
} while (ret == (s32)HTTPC_RESULTCODE_DOWNLOADPENDING);
|
||||
|
||||
last_buf = buf;
|
||||
buf = realloc(buf, size);
|
||||
if (buf == NULL)
|
||||
else
|
||||
{
|
||||
httpcCloseContext(&context);
|
||||
free(last_buf);
|
||||
return -1;
|
||||
throw_error("Download failed.", ERROR_LEVEL_WARNING);
|
||||
}
|
||||
|
||||
char path_to_file[0x106] = {0};
|
||||
strcpy(path_to_file, path);
|
||||
strcat(path_to_file, filename);
|
||||
remake_file(path_to_file, ArchiveSD, size);
|
||||
buf_to_file(size, path_to_file, ArchiveSD, (char*)buf);
|
||||
|
||||
add_theme(&themes_list, &theme_count, path_to_file, filename);
|
||||
|
||||
exit_qr();
|
||||
|
||||
return 0;
|
||||
free(filename);
|
||||
free(zip_buf);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool init_qr(void)
|
||||
{
|
||||
qr_data *data = calloc(1, sizeof(qr_data));
|
||||
data->capturing = false;
|
||||
data->finished = false;
|
||||
data->context = quirc_new();
|
||||
quirc_resize(data->context, 400, 240);
|
||||
|
||||
data->camera_buffer = calloc(1, 400 * 240 * sizeof(u16));
|
||||
data->texture_buffer = calloc(1, 400 * 240 * sizeof(u32));
|
||||
|
||||
while (!data->finished) update_qr(data);
|
||||
|
||||
return (bool)data->success;
|
||||
}
|
||||
|
||||
|
||||
629
source/draw.c
@@ -25,22 +25,13 @@
|
||||
*/
|
||||
|
||||
#include "draw.h"
|
||||
#include "unicode.h"
|
||||
#include "colors.h"
|
||||
|
||||
#include "pp2d/pp2d/pp2d.h"
|
||||
#include "quirc/quirc.h"
|
||||
|
||||
#include <time.h>
|
||||
|
||||
enum Colors {
|
||||
COLOR_BACKGROUND = ABGR8(255, 32, 28, 35), //silver-y black
|
||||
COLOR_ACCENT = RGBA8(55, 122, 168, 255),
|
||||
COLOR_WHITE = RGBA8(255, 255, 255, 255),
|
||||
COLOR_CURSOR = RGBA8(200, 200, 200, 255),
|
||||
COLOR_BLACK = RGBA8(0, 0, 0, 255),
|
||||
COLOR_RED = RGBA8(200, 0, 0, 255),
|
||||
COLOR_YELLOW = RGBA8(239, 220, 11, 255),
|
||||
};
|
||||
|
||||
void init_screens(void)
|
||||
{
|
||||
pp2d_init();
|
||||
@@ -49,13 +40,23 @@ void init_screens(void)
|
||||
pp2d_set_screen_color(GFX_BOTTOM, COLOR_BACKGROUND);
|
||||
|
||||
pp2d_load_texture_png(TEXTURE_ARROW, "romfs:/arrow.png");
|
||||
pp2d_load_texture_png(TEXTURE_ARROW_SIDE, "romfs:/arrow_side.png");
|
||||
pp2d_load_texture_png(TEXTURE_SHUFFLE, "romfs:/shuffle.png");
|
||||
pp2d_load_texture_png(TEXTURE_INSTALLED, "romfs:/installed.png");
|
||||
pp2d_load_texture_png(TEXTURE_DOWNLOAD, "romfs:/download.png");
|
||||
pp2d_load_texture_png(TEXTURE_PREVIEW_ICON, "romfs:/preview.png");
|
||||
pp2d_load_texture_png(TEXTURE_BROWSE, "romfs:/browse.png");
|
||||
pp2d_load_texture_png(TEXTURE_LIST, "romfs:/list.png");
|
||||
pp2d_load_texture_png(TEXTURE_EXIT, "romfs:/exit.png");
|
||||
pp2d_load_texture_png(TEXTURE_BATTERY_0, "romfs:/battery0.png");
|
||||
pp2d_load_texture_png(TEXTURE_BATTERY_1, "romfs:/battery1.png");
|
||||
pp2d_load_texture_png(TEXTURE_BATTERY_2, "romfs:/battery2.png");
|
||||
pp2d_load_texture_png(TEXTURE_BATTERY_3, "romfs:/battery3.png");
|
||||
pp2d_load_texture_png(TEXTURE_BATTERY_4, "romfs:/battery4.png");
|
||||
pp2d_load_texture_png(TEXTURE_BATTERY_5, "romfs:/battery5.png");
|
||||
pp2d_load_texture_png(TEXTURE_BATTERY_CHARGE, "romfs:/charging.png");
|
||||
pp2d_load_texture_png(TEXTURE_SELECT_BUTTON, "romfs:/select.png");
|
||||
pp2d_load_texture_png(TEXTURE_START_BUTTON, "romfs:/start.png");
|
||||
}
|
||||
|
||||
void exit_screens(void)
|
||||
@@ -63,301 +64,441 @@ void exit_screens(void)
|
||||
pp2d_exit();
|
||||
}
|
||||
|
||||
static int theme_vertical_scroll = 0;
|
||||
static int splash_vertical_scroll = 0;
|
||||
|
||||
void draw_qr(void)
|
||||
{
|
||||
pp2d_begin_draw(GFX_TOP);
|
||||
pp2d_free_texture(TEXTURE_QR);
|
||||
take_picture();
|
||||
u32 *rgba8_buf = malloc(240 * 400 * sizeof(u32));
|
||||
for (int i = 0; i < 240 * 400; i++)
|
||||
{
|
||||
rgba8_buf[i] = RGB565_TO_RGBA8(buf[i]);
|
||||
u8 *byte_pointer = (u8*)&rgba8_buf[i];
|
||||
u8 r = *(byte_pointer+3);
|
||||
u8 g = *(byte_pointer+2);
|
||||
u8 b = *(byte_pointer+1);
|
||||
u8 a = *(byte_pointer);
|
||||
rgba8_buf[i] = RGBA8(r, g, b, a);
|
||||
}
|
||||
pp2d_load_texture_memory(TEXTURE_QR, rgba8_buf, 400, 240);
|
||||
pp2d_draw_texture(TEXTURE_QR, 0, 0);
|
||||
free(rgba8_buf);
|
||||
pp2d_end_draw();
|
||||
|
||||
int w;
|
||||
int h;
|
||||
|
||||
u8 *image = (u8*) quirc_begin(context, &w, &h);
|
||||
|
||||
for (ssize_t x = 0; x < w; x++)
|
||||
{
|
||||
for (ssize_t y = 0; y < h; y++)
|
||||
{
|
||||
u16 px = buf[y * 400 + x];
|
||||
image[y * w + x] = (u8)(((((px >> 11) & 0x1F) << 3) + (((px >> 5) & 0x3F) << 2) + ((px & 0x1F) << 3)) / 3);
|
||||
}
|
||||
}
|
||||
|
||||
quirc_end(context);
|
||||
|
||||
if (quirc_count(context) > 0)
|
||||
{
|
||||
struct quirc_code code;
|
||||
struct quirc_data data;
|
||||
quirc_extract(context, 0, &code);
|
||||
if (!quirc_decode(&code, &data))
|
||||
{
|
||||
qr_mode = false;
|
||||
|
||||
http_get((char*)data.payload, "/Themes/");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void draw_base_interface(void)
|
||||
{
|
||||
pp2d_begin_draw(GFX_TOP);
|
||||
pp2d_begin_draw(GFX_TOP, GFX_LEFT);
|
||||
pp2d_draw_rectangle(0, 0, 400, 23, COLOR_ACCENT);
|
||||
|
||||
time_t t = time(NULL);
|
||||
struct tm tm = *localtime(&t);
|
||||
|
||||
pp2d_draw_textf(7, 2, 0.6, 0.6, COLOR_WHITE, "%.2i", tm.tm_hour);
|
||||
pp2d_draw_text(28, 2, 0.6, 0.6, COLOR_WHITE, (tm.tm_sec % 2 == 1) ? ":" : " ");
|
||||
pp2d_draw_text(28, 1, 0.6, 0.6, COLOR_WHITE, (tm.tm_sec % 2 == 1) ? ":" : " ");
|
||||
pp2d_draw_textf(34, 2, 0.6, 0.6, COLOR_WHITE, "%.2i", tm.tm_min);
|
||||
|
||||
u8 battery_charging;
|
||||
#ifndef CITRA_MODE
|
||||
u8 battery_charging = 0;
|
||||
PTMU_GetBatteryChargeState(&battery_charging);
|
||||
u8 battery_status;
|
||||
u8 battery_status = 0;
|
||||
PTMU_GetBatteryLevel(&battery_status);
|
||||
pp2d_draw_texture(2 + battery_status, 357, 2);
|
||||
pp2d_draw_texture(TEXTURE_BATTERY_0 + battery_status, 357, 2);
|
||||
|
||||
if(battery_charging)
|
||||
pp2d_draw_texture(TEXTURE_BATTERY_CHARGE, 357, 2);
|
||||
#endif
|
||||
|
||||
pp2d_draw_on(GFX_BOTTOM);
|
||||
pp2d_draw_on(GFX_BOTTOM, GFX_LEFT);
|
||||
pp2d_draw_rectangle(0, 0, 320, 24, COLOR_ACCENT);
|
||||
pp2d_draw_rectangle(0, 216, 320, 24, COLOR_ACCENT);
|
||||
pp2d_draw_text(7, 219, 0.6, 0.6, COLOR_WHITE, VERSION);
|
||||
pp2d_draw_on(GFX_TOP);
|
||||
|
||||
pp2d_draw_on(GFX_TOP, GFX_LEFT);
|
||||
}
|
||||
void throw_error(char* error, int error_type) {
|
||||
|
||||
static void draw_text_center(gfxScreen_t target, float y, float scaleX, float scaleY, u32 color, const char* text)
|
||||
{
|
||||
char * _text = strdup(text);
|
||||
float prevY = y;
|
||||
int offset = 0;
|
||||
while(true)
|
||||
{
|
||||
char *nline = strchr(_text+offset, '\n');
|
||||
int nlinepos = 0;
|
||||
if(nline != NULL)
|
||||
{
|
||||
nlinepos = nline-_text;
|
||||
_text[nlinepos] = '\0';
|
||||
}
|
||||
pp2d_draw_text_center(target, prevY, scaleX, scaleY, color, _text+offset);
|
||||
if(nline == NULL) break;
|
||||
else
|
||||
{
|
||||
prevY += pp2d_get_text_height(_text+offset, scaleX, scaleY);
|
||||
_text[nlinepos] = '\n';
|
||||
offset = nlinepos+1;
|
||||
}
|
||||
}
|
||||
free(_text);
|
||||
}
|
||||
|
||||
void throw_error(char* error, ErrorLevel level)
|
||||
{
|
||||
switch(level)
|
||||
{
|
||||
case ERROR_LEVEL_ERROR:
|
||||
while(aptMainLoop())
|
||||
{
|
||||
hidScanInput();
|
||||
u32 kDown = hidKeysDown();
|
||||
draw_base_interface();
|
||||
switch (error_type) {
|
||||
case ERROR:
|
||||
pp2d_draw_text(70, 120, 0.8, 0.8, COLOR_RED, error);
|
||||
break;
|
||||
case WARNING:
|
||||
pp2d_draw_text(70, 120, 0.8, 0.8, COLOR_YELLOW, error);
|
||||
break;
|
||||
}
|
||||
draw_text_center(GFX_TOP, 100, 0.6, 0.6, COLOR_RED, error);
|
||||
pp2d_draw_wtext_center(GFX_TOP, 150, 0.6, 0.6, COLOR_WHITE, L"Press \uE000 to shut down.");
|
||||
pp2d_end_draw();
|
||||
if(kDown & KEY_A) break;
|
||||
}
|
||||
void draw_theme_install(int install_type)
|
||||
break;
|
||||
case ERROR_LEVEL_WARNING:
|
||||
while(aptMainLoop())
|
||||
{
|
||||
hidScanInput();
|
||||
u32 kDown = hidKeysDown();
|
||||
draw_base_interface();
|
||||
draw_text_center(GFX_TOP, 100, 0.6, 0.6, COLOR_YELLOW, error);
|
||||
pp2d_draw_wtext_center(GFX_TOP, 150, 0.6, 0.6, COLOR_WHITE, L"Press \uE000 to continue.");
|
||||
pp2d_end_draw();
|
||||
if(kDown & KEY_A) break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool draw_confirm(const char* conf_msg, Entry_List_s* list)
|
||||
{
|
||||
while(aptMainLoop())
|
||||
{
|
||||
Instructions_s instructions = {0};
|
||||
draw_interface(list, instructions);
|
||||
pp2d_draw_on(GFX_TOP, GFX_LEFT);
|
||||
draw_text_center(GFX_TOP, BUTTONS_Y_LINE_1, 0.7, 0.7, COLOR_YELLOW, conf_msg);
|
||||
pp2d_draw_wtext_center(GFX_TOP, BUTTONS_Y_LINE_3, 0.6, 0.6, COLOR_WHITE, L"\uE000 Yes \uE001 No");
|
||||
pp2d_end_draw();
|
||||
|
||||
hidScanInput();
|
||||
u32 kDown = hidKeysDown();
|
||||
if(kDown & KEY_A) return true;
|
||||
if(kDown & KEY_B) return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void draw_preview(ssize_t previewID, int preview_offset)
|
||||
{
|
||||
pp2d_begin_draw(GFX_TOP, GFX_LEFT);
|
||||
pp2d_draw_texture_part(previewID, 0, 0, preview_offset, 0, 400, 240);
|
||||
pp2d_draw_on(GFX_BOTTOM, GFX_LEFT);
|
||||
pp2d_draw_texture_part(previewID, 0, 0, 40 + preview_offset, 240, 320, 240);
|
||||
}
|
||||
|
||||
void draw_install(InstallType type)
|
||||
{
|
||||
draw_base_interface();
|
||||
switch(install_type)
|
||||
switch(type)
|
||||
{
|
||||
case 0:
|
||||
case INSTALL_LOADING_THEMES:
|
||||
pp2d_draw_text_center(GFX_TOP, 120, 0.8, 0.8, COLOR_WHITE, "Loading themes, please wait...");
|
||||
break;
|
||||
case INSTALL_LOADING_SPLASHES:
|
||||
pp2d_draw_text_center(GFX_TOP, 120, 0.8, 0.8, COLOR_WHITE, "Loading splashes, please wait...");
|
||||
break;
|
||||
case INSTALL_LOADING_ICONS:
|
||||
pp2d_draw_text_center(GFX_TOP, 120, 0.8, 0.8, COLOR_WHITE, "Loading icons, please wait...");
|
||||
break;
|
||||
case INSTALL_LOADING_REMOTE_THEMES:
|
||||
pp2d_draw_text_center(GFX_TOP, 120, 0.8, 0.8, COLOR_WHITE, "Downloading theme list, please wait...");
|
||||
break;
|
||||
case INSTALL_LOADING_REMOTE_SPLASHES:
|
||||
pp2d_draw_text_center(GFX_TOP, 120, 0.8, 0.8, COLOR_WHITE, "Downloading splash list, please wait...");
|
||||
break;
|
||||
case INSTALL_LOADING_REMOTE_PREVIEW:
|
||||
pp2d_draw_text_center(GFX_TOP, 120, 0.8, 0.8, COLOR_WHITE, "Downloading preview, please wait...");
|
||||
break;
|
||||
case INSTALL_SINGLE:
|
||||
pp2d_draw_text_center(GFX_TOP, 120, 0.8, 0.8, COLOR_WHITE, "Installing a single theme...");
|
||||
break;
|
||||
case 1:
|
||||
pp2d_draw_text_center(GFX_TOP, 120, 0.8, 0.8, COLOR_WHITE, "Installing a shuffle theme...");
|
||||
case INSTALL_SHUFFLE:
|
||||
pp2d_draw_text_center(GFX_TOP, 120, 0.8, 0.8, COLOR_WHITE, "Installing shuffle themes...");
|
||||
break;
|
||||
case 2:
|
||||
pp2d_draw_text_center(GFX_TOP, 120, 0.8, 0.8, COLOR_WHITE, "Installing BGM...");
|
||||
case INSTALL_BGM:
|
||||
pp2d_draw_text_center(GFX_TOP, 120, 0.8, 0.8, COLOR_WHITE, "Installing BGM-only theme...");
|
||||
break;
|
||||
case 3:
|
||||
case INSTALL_DOWNLOAD:
|
||||
pp2d_draw_text_center(GFX_TOP, 120, 0.8, 0.8, COLOR_WHITE, "Downloading...");
|
||||
break;
|
||||
case INSTALL_CHECKING_DOWNLOAD:
|
||||
pp2d_draw_text_center(GFX_TOP, 120, 0.8, 0.8, COLOR_WHITE, "Checking downloaded file...");
|
||||
break;
|
||||
case INSTALL_SPLASH:
|
||||
pp2d_draw_text_center(GFX_TOP, 120, 0.8, 0.8, COLOR_WHITE, "Installing a splash...");
|
||||
break;
|
||||
case INSTALL_SPLASH_DELETE:
|
||||
pp2d_draw_text_center(GFX_TOP, 120, 0.8, 0.8, COLOR_WHITE, "Deleting installed splash...");
|
||||
break;
|
||||
case INSTALL_ENTRY_DELETE:
|
||||
pp2d_draw_text_center(GFX_TOP, 120, 0.8, 0.8, COLOR_WHITE, "Deleting from SD...");
|
||||
break;
|
||||
case INSTALL_NO_BGM:
|
||||
pp2d_draw_text_center(GFX_TOP, 120, 0.8, 0.8, COLOR_WHITE, "Installing theme without BGM...");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
pp2d_end_draw();
|
||||
}
|
||||
|
||||
void draw_theme_interface(Theme_s * themes_list, int theme_count, int selected_theme, bool preview_mode, int shuffle_theme_count)
|
||||
static void draw_instructions(Instructions_s instructions)
|
||||
{
|
||||
pp2d_draw_on(GFX_TOP, GFX_LEFT);
|
||||
|
||||
if (themes_list == NULL)
|
||||
if(instructions.info_line != NULL)
|
||||
pp2d_draw_wtext_center(GFX_TOP, BUTTONS_Y_INFO, 0.55, 0.55, instructions.info_line_color, instructions.info_line);
|
||||
|
||||
const int y_lines[BUTTONS_INFO_LINES-1] = {
|
||||
BUTTONS_Y_LINE_1,
|
||||
BUTTONS_Y_LINE_2,
|
||||
BUTTONS_Y_LINE_3,
|
||||
};
|
||||
|
||||
for(int i = 0; i < BUTTONS_INFO_LINES-1; i++)
|
||||
{
|
||||
pp2d_begin_draw(GFX_TOP);
|
||||
pp2d_draw_text_center(GFX_TOP, 100, 1, 1, COLOR_WHITE, "NO THEMES FOUND");
|
||||
pp2d_end_draw();
|
||||
if(instructions.instructions[i][0] != NULL)
|
||||
pp2d_draw_wtext(BUTTONS_X_LEFT, y_lines[i], 0.6, 0.6, COLOR_WHITE, instructions.instructions[i][0]);
|
||||
if(instructions.instructions[i][1] != NULL)
|
||||
pp2d_draw_wtext(BUTTONS_X_RIGHT, y_lines[i], 0.6, 0.6, COLOR_WHITE, instructions.instructions[i][1]);
|
||||
}
|
||||
|
||||
const wchar_t * start_line = instructions.instructions[BUTTONS_INFO_LINES-1][0];
|
||||
if(start_line != NULL)
|
||||
{
|
||||
pp2d_draw_texture(TEXTURE_START_BUTTON, BUTTONS_X_LEFT-10, BUTTONS_Y_LINE_4 + 3);
|
||||
pp2d_draw_wtext(BUTTONS_X_LEFT+26, BUTTONS_Y_LINE_4, 0.6, 0.6, COLOR_WHITE, start_line);
|
||||
}
|
||||
|
||||
const wchar_t * select_line = instructions.instructions[BUTTONS_INFO_LINES-1][1];
|
||||
if(select_line != NULL)
|
||||
{
|
||||
pp2d_draw_texture(TEXTURE_SELECT_BUTTON, BUTTONS_X_RIGHT-10, BUTTONS_Y_LINE_4 + 3);
|
||||
pp2d_draw_wtext(BUTTONS_X_RIGHT+26, BUTTONS_Y_LINE_4, 0.6, 0.6, COLOR_WHITE, select_line);
|
||||
}
|
||||
}
|
||||
|
||||
static void draw_entry_info(Entry_s * entry)
|
||||
{
|
||||
float wrap = 363;
|
||||
|
||||
wchar_t author[0x41] = {0};
|
||||
utf16_to_utf32((u32*)author, entry->author, 0x40);
|
||||
pp2d_draw_text(20, 35, 0.5, 0.5, COLOR_WHITE, "By ");
|
||||
pp2d_draw_wtext_wrap(40, 35, 0.5, 0.5, COLOR_WHITE, wrap, author);
|
||||
|
||||
wchar_t title[0x41] = {0};
|
||||
utf16_to_utf32((u32*)title, entry->name, 0x40);
|
||||
pp2d_draw_wtext_wrap(20, 50, 0.7, 0.7, COLOR_WHITE, wrap, title);
|
||||
|
||||
int width = (int)pp2d_get_wtext_width(title, 0.7, 0.7);
|
||||
int height = (int)pp2d_get_wtext_height(title, 0.7, 0.7);
|
||||
int count = ((width - (width % (int)wrap))/wrap) + 1;
|
||||
|
||||
wchar_t description[0x81] = {0};
|
||||
utf16_to_utf32((u32*)description, entry->desc, 0x80);
|
||||
pp2d_draw_wtext_wrap(20, 50+count*height, 0.5, 0.5, COLOR_WHITE, wrap, description);
|
||||
}
|
||||
|
||||
void draw_grid_interface(Entry_List_s* list, Instructions_s instructions)
|
||||
{
|
||||
draw_base_interface();
|
||||
EntryMode current_mode = list->mode;
|
||||
|
||||
const char* mode_string[MODE_AMOUNT] = {
|
||||
"ThemePlaza Theme mode",
|
||||
"ThemePlaza Splash mode",
|
||||
};
|
||||
|
||||
pp2d_draw_text_center(GFX_TOP, 4, 0.5, 0.5, COLOR_WHITE, mode_string[current_mode]);
|
||||
|
||||
draw_instructions(instructions);
|
||||
|
||||
int selected_entry = list->selected_entry;
|
||||
Entry_s * current_entry = &list->entries[selected_entry];
|
||||
draw_entry_info(current_entry);
|
||||
|
||||
pp2d_draw_on(GFX_BOTTOM, GFX_LEFT);
|
||||
|
||||
pp2d_draw_text(7, 3, 0.6, 0.6, COLOR_WHITE, "Search...");
|
||||
|
||||
pp2d_draw_texture_blend(TEXTURE_LIST, 320-96, 0, COLOR_WHITE);
|
||||
pp2d_draw_texture_blend(TEXTURE_EXIT, 320-72, 0, COLOR_WHITE);
|
||||
pp2d_draw_texture_blend(TEXTURE_PREVIEW_ICON, 320-48, 0, COLOR_WHITE);
|
||||
pp2d_draw_textf(320-24+2.5, -3, 1, 1, COLOR_WHITE, "%c", mode_string[!list->mode][11]);
|
||||
|
||||
pp2d_draw_texture(TEXTURE_ARROW_SIDE, 3, 114);
|
||||
pp2d_draw_texture_flip(TEXTURE_ARROW_SIDE, 308, 114, HORIZONTAL);
|
||||
|
||||
for(int i = list->scroll; i < (list->entries_loaded + list->scroll); i++)
|
||||
{
|
||||
if(i >= list->entries_count) break;
|
||||
|
||||
current_entry = &list->entries[i];
|
||||
|
||||
wchar_t name[0x41] = {0};
|
||||
utf16_to_utf32((u32*)name, current_entry->name, 0x40);
|
||||
|
||||
int vertical_offset = 0;
|
||||
int horizontal_offset = i - list->scroll;
|
||||
vertical_offset = horizontal_offset/list->entries_per_screen_h;
|
||||
horizontal_offset %= list->entries_per_screen_h;
|
||||
|
||||
horizontal_offset *= list->entry_size;
|
||||
vertical_offset *= list->entry_size;
|
||||
vertical_offset += 24;
|
||||
horizontal_offset += 16;
|
||||
|
||||
if(!current_entry->placeholder_color)
|
||||
{
|
||||
ssize_t id = list->icons_ids[i];
|
||||
pp2d_draw_texture(id, horizontal_offset, vertical_offset);
|
||||
}
|
||||
else
|
||||
pp2d_draw_rectangle(horizontal_offset, vertical_offset, list->entry_size, list->entry_size, current_entry->placeholder_color);
|
||||
|
||||
if(i == selected_entry)
|
||||
{
|
||||
unsigned int border_width = 3;
|
||||
pp2d_draw_rectangle(horizontal_offset, vertical_offset, border_width, list->entry_size, COLOR_CURSOR);
|
||||
pp2d_draw_rectangle(horizontal_offset, vertical_offset, list->entry_size, border_width, COLOR_CURSOR);
|
||||
pp2d_draw_rectangle(horizontal_offset, vertical_offset+list->entry_size-border_width, list->entry_size, border_width, COLOR_CURSOR);
|
||||
pp2d_draw_rectangle(horizontal_offset+list->entry_size-border_width, vertical_offset, border_width, list->entry_size, COLOR_CURSOR);
|
||||
}
|
||||
}
|
||||
|
||||
char entries_count_str[0x20] = {0};
|
||||
sprintf(entries_count_str, "/%" JSON_INTEGER_FORMAT, list->tp_page_count);
|
||||
float x = 316;
|
||||
x -= pp2d_get_text_width(entries_count_str, 0.6, 0.6);
|
||||
pp2d_draw_text(x, 219, 0.6, 0.6, COLOR_WHITE, entries_count_str);
|
||||
|
||||
char selected_entry_str[0x20] = {0};
|
||||
sprintf(selected_entry_str, "%" JSON_INTEGER_FORMAT, list->tp_current_page);
|
||||
x -= pp2d_get_text_width(selected_entry_str, 0.6, 0.6);
|
||||
pp2d_draw_text(x, 219, 0.6, 0.6, COLOR_WHITE, selected_entry_str);
|
||||
|
||||
pp2d_draw_text(176, 219, 0.6, 0.6, COLOR_WHITE, "Page:");
|
||||
}
|
||||
|
||||
void draw_interface(Entry_List_s* list, Instructions_s instructions)
|
||||
{
|
||||
draw_base_interface();
|
||||
EntryMode current_mode = list->mode;
|
||||
|
||||
const char* mode_string[MODE_AMOUNT] = {
|
||||
"Theme mode",
|
||||
"Splash mode",
|
||||
};
|
||||
|
||||
pp2d_draw_text_center(GFX_TOP, 4, 0.5, 0.5, COLOR_WHITE, mode_string[current_mode]);
|
||||
|
||||
if(list->entries == NULL)
|
||||
{
|
||||
const char* mode_found_string[MODE_AMOUNT] = {
|
||||
"No themes found",
|
||||
"No splashes found",
|
||||
};
|
||||
pp2d_draw_text_center(GFX_TOP, 80, 0.7, 0.7, COLOR_YELLOW, mode_found_string[current_mode]);
|
||||
pp2d_draw_text_center(GFX_TOP, 110, 0.7, 0.7, COLOR_YELLOW, "Press \uE005 to download from QR");
|
||||
const char* mode_switch_string[MODE_AMOUNT] = {
|
||||
"Or \uE004 to switch to splashes",
|
||||
"Or \uE004 to switch to themes",
|
||||
};
|
||||
pp2d_draw_text_center(GFX_TOP, 140, 0.7, 0.7, COLOR_YELLOW, mode_switch_string[current_mode]);
|
||||
pp2d_draw_text_center(GFX_TOP, 170, 0.7, 0.7, COLOR_YELLOW, "Or to quit");
|
||||
pp2d_texture_select(TEXTURE_START_BUTTON, 162, 173);
|
||||
pp2d_texture_blend(COLOR_YELLOW);
|
||||
pp2d_texture_scale(1.25, 1.4);
|
||||
pp2d_texture_draw();
|
||||
|
||||
pp2d_draw_on(GFX_BOTTOM, GFX_LEFT);
|
||||
|
||||
pp2d_draw_texture_blend(TEXTURE_EXIT, 320-120, 0, COLOR_WHITE);
|
||||
pp2d_draw_texture_blend(TEXTURE_DOWNLOAD, 320-96, 0, COLOR_WHITE);
|
||||
for(int i = 0; i < MODE_AMOUNT; i++)
|
||||
pp2d_draw_textf(320-(24*(i+1))+2.5, -3, 1, 1, COLOR_WHITE, "%c", mode_string[i][0]);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Theme_s current_theme = themes_list[selected_theme];
|
||||
draw_instructions(instructions);
|
||||
|
||||
if (preview_mode)
|
||||
int selected_entry = list->selected_entry;
|
||||
Entry_s * current_entry = &list->entries[selected_entry];
|
||||
draw_entry_info(current_entry);
|
||||
|
||||
pp2d_draw_on(GFX_BOTTOM, GFX_LEFT);
|
||||
|
||||
switch(current_mode)
|
||||
{
|
||||
if (current_theme.has_preview)
|
||||
{
|
||||
pp2d_begin_draw(GFX_TOP);
|
||||
pp2d_draw_texture_part(TEXTURE_PREVIEW, 0, 0, current_theme.preview_offset, 0, 400, 240);
|
||||
pp2d_draw_on(GFX_BOTTOM);
|
||||
pp2d_draw_texture_part(TEXTURE_PREVIEW, 0, 0, 40+current_theme.preview_offset, 240, 320, 240);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
draw_base_interface();
|
||||
pp2d_draw_text_center(GFX_TOP, 4, 0.5, 0.5, COLOR_WHITE, "Theme mode");
|
||||
wchar_t title[0x40] = {0};
|
||||
utf16_to_utf32((u32*)title, current_theme.name, 0x40);
|
||||
pp2d_draw_wtext_wrap(20, 30, 0.7, 0.7, COLOR_WHITE, 380, title);
|
||||
wchar_t author[0x40] = {0};
|
||||
utf16_to_utf32((u32*)author, current_theme.author, 0x40);
|
||||
pp2d_draw_text(20, 50, 0.5, 0.5, COLOR_WHITE, "By: ");
|
||||
pp2d_draw_wtext_wrap(44, 50, 0.5, 0.5, COLOR_WHITE, 380, author);
|
||||
wchar_t description[0xa6] = {0};
|
||||
utf16_to_utf32((u32*)description, current_theme.desc, 0xb0);
|
||||
pp2d_draw_wtext_wrap(20, 65, 0.5, 0.5, COLOR_WHITE, 363, description);
|
||||
|
||||
pp2d_draw_wtext(20, 150, 0.6, 0.6, COLOR_WHITE, L"\uE046 Install Shuffle Theme");
|
||||
pp2d_draw_wtext(200, 150, 0.6, 0.6, COLOR_WHITE, L"\uE004 Switch to Splashes");
|
||||
pp2d_draw_wtext(20, 180, 0.6, 0.6, COLOR_WHITE, L"\uE000 Install Theme");
|
||||
pp2d_draw_wtext(200, 180, 0.6, 0.6, COLOR_WHITE, L"\uE001 Queue Shuffle");
|
||||
pp2d_draw_wtext(20, 210, 0.6, 0.6, COLOR_WHITE, L"\uE002 Install BGM");
|
||||
pp2d_draw_wtext(200, 210, 0.6, 0.6, COLOR_WHITE, L"\uE003 Preview Theme");
|
||||
pp2d_draw_wtext(130, 120, 0.6, 0.6, COLOR_WHITE, L"\uE005 Scan QRCode");
|
||||
pp2d_draw_on(GFX_BOTTOM);
|
||||
|
||||
pp2d_draw_textf(7, 3, 0.6, 0.6, COLOR_WHITE, "Selected: %i/10", shuffle_theme_count);
|
||||
|
||||
// Scroll the menu up or down if the selected theme is out of its bounds
|
||||
//----------------------------------------------------------------
|
||||
for (int i = 0; i < theme_count; i++) {
|
||||
if (theme_count <= THEMES_PER_SCREEN)
|
||||
case MODE_THEMES:
|
||||
pp2d_draw_textf(7, 3, 0.6, 0.6, list->shuffle_count <= 10 && list->shuffle_count >= 2 ? COLOR_WHITE : COLOR_RED, "Shuffle: %i/10", list->shuffle_count);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
if (theme_vertical_scroll > selected_theme)
|
||||
theme_vertical_scroll--;
|
||||
|
||||
if ((i < selected_theme) && \
|
||||
((selected_theme - theme_vertical_scroll) >= THEMES_PER_SCREEN) && \
|
||||
(theme_vertical_scroll != ( - THEMES_PER_SCREEN)))
|
||||
theme_vertical_scroll++;
|
||||
}
|
||||
//----------------------------------------------------------------
|
||||
|
||||
pp2d_draw_texture_blend(TEXTURE_DOWNLOAD, 320-120, 0, COLOR_WHITE);
|
||||
pp2d_draw_texture_blend(TEXTURE_BROWSE, 320-96, 0, COLOR_WHITE);
|
||||
pp2d_draw_texture_blend(TEXTURE_EXIT, 320-72, 0, COLOR_WHITE);
|
||||
pp2d_draw_texture_blend(TEXTURE_PREVIEW_ICON, 320-48, 0, COLOR_WHITE);
|
||||
pp2d_draw_textf(320-24+2.5, -3, 1, 1, COLOR_WHITE, "%c", mode_string[!list->mode][0]);
|
||||
|
||||
// Show arrows if there are themes out of bounds
|
||||
//----------------------------------------------------------------
|
||||
if (theme_vertical_scroll > 0)
|
||||
pp2d_draw_texture(TEXTURE_ARROW, 155, 6);
|
||||
if (theme_vertical_scroll + THEMES_PER_SCREEN < theme_count)
|
||||
pp2d_draw_texture_flip(TEXTURE_ARROW, 155, 224, VERTICAL);
|
||||
if(list->scroll > 0)
|
||||
pp2d_draw_texture(TEXTURE_ARROW, 152, 4);
|
||||
if(list->scroll + list->entries_loaded < list->entries_count)
|
||||
pp2d_draw_texture_flip(TEXTURE_ARROW, 152, 220, VERTICAL);
|
||||
|
||||
for (int i = theme_vertical_scroll; i < (THEMES_PER_SCREEN + theme_vertical_scroll); i++)
|
||||
for(int i = list->scroll; i < (list->entries_loaded + list->scroll); i++)
|
||||
{
|
||||
if (i >= theme_count)
|
||||
break;
|
||||
if(i >= list->entries_count) break;
|
||||
|
||||
current_theme = themes_list[i];
|
||||
wchar_t name[0x80] = {0};
|
||||
utf16_to_utf32((u32*)name, current_theme.name, 0x80);
|
||||
current_entry = &list->entries[i];
|
||||
|
||||
wchar_t name[0x41] = {0};
|
||||
utf16_to_utf32((u32*)name, current_entry->name, 0x40);
|
||||
|
||||
int vertical_offset = i - list->scroll;
|
||||
int horizontal_offset = 0;
|
||||
horizontal_offset *= list->entry_size;
|
||||
vertical_offset *= list->entry_size;
|
||||
vertical_offset += 24;
|
||||
|
||||
int vertical_offset = 48 * (i-theme_vertical_scroll);
|
||||
u32 font_color = COLOR_WHITE;
|
||||
|
||||
if (i == selected_theme)
|
||||
if(i == selected_entry)
|
||||
{
|
||||
font_color = COLOR_BLACK;
|
||||
pp2d_draw_rectangle(0, 24 + vertical_offset, 320, 48, COLOR_CURSOR);
|
||||
pp2d_draw_rectangle(0, vertical_offset, 320, list->entry_size, COLOR_CURSOR);
|
||||
}
|
||||
pp2d_draw_wtext(54, 40 + vertical_offset, 0.55, 0.55, font_color, name);
|
||||
if (!current_theme.placeholder_color)
|
||||
pp2d_draw_texture(current_theme.icon_id, 0, 24 + vertical_offset);
|
||||
|
||||
pp2d_draw_wtext(list->entry_size+6, vertical_offset + 16, 0.55, 0.55, font_color, name);
|
||||
|
||||
if(current_entry->in_shuffle)
|
||||
pp2d_draw_texture_blend(TEXTURE_SHUFFLE, 320-24-4, vertical_offset, font_color);
|
||||
if(current_entry->installed)
|
||||
pp2d_draw_texture_blend(TEXTURE_INSTALLED, 320-24-4, vertical_offset + 22, font_color);
|
||||
|
||||
if(!current_entry->placeholder_color)
|
||||
{
|
||||
ssize_t id = 0;
|
||||
if(list->entries_count > list->entries_loaded*ICONS_OFFSET_AMOUNT)
|
||||
id = list->icons_ids[ICONS_VISIBLE*list->entries_loaded + (i - list->scroll)];
|
||||
else
|
||||
pp2d_draw_rectangle(0, 24 + vertical_offset, 48, 48, current_theme.placeholder_color);
|
||||
|
||||
if (current_theme.in_shuffle)
|
||||
pp2d_draw_texture_blend(TEXTURE_SHUFFLE, 280, 32 + vertical_offset, font_color);
|
||||
id = list->icons_ids[i];
|
||||
pp2d_draw_texture(id, horizontal_offset, vertical_offset);
|
||||
}
|
||||
else
|
||||
pp2d_draw_rectangle(horizontal_offset, vertical_offset, list->entry_size, list->entry_size, current_entry->placeholder_color);
|
||||
}
|
||||
|
||||
pp2d_end_draw();
|
||||
}
|
||||
|
||||
void draw_splash_install(int install_type)
|
||||
{
|
||||
draw_base_interface();
|
||||
switch (install_type)
|
||||
{
|
||||
case SINGLE_INSTALL:
|
||||
pp2d_draw_text_center(GFX_TOP, 110, 0.7, 0.7, COLOR_WHITE, "Installing a splash...");
|
||||
break;
|
||||
case UNINSTALL:
|
||||
pp2d_draw_text_center(GFX_TOP, 110, 0.7, 0.7, COLOR_WHITE, "Uninstalling a splash...");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
pp2d_end_draw();
|
||||
}
|
||||
|
||||
void draw_splash_interface(Splash_s *splashes_list, int splash_count, int selected_splash, bool preview_mode)
|
||||
{
|
||||
if (splashes_list == NULL)
|
||||
{
|
||||
pp2d_begin_draw(GFX_TOP);
|
||||
pp2d_draw_text_center(GFX_TOP, 100, 1, 1, COLOR_WHITE, "NO SPLASHES FOUND");
|
||||
pp2d_end_draw();
|
||||
return;
|
||||
}
|
||||
|
||||
Splash_s current_splash = splashes_list[selected_splash];
|
||||
|
||||
if (preview_mode)
|
||||
{
|
||||
// TODO: Splash Previews
|
||||
} else {
|
||||
draw_base_interface();
|
||||
pp2d_draw_text_center(GFX_TOP, 4, 0.5, 0.5, COLOR_WHITE, "Splash mode");
|
||||
|
||||
pp2d_draw_wtext_center(GFX_TOP, 180, 0.7, 0.7, COLOR_WHITE, L"\uE000 Install Splash \uE004 Switch to Themes");
|
||||
pp2d_draw_wtext_center(GFX_TOP, 210, 0.7, 0.7, COLOR_WHITE, L"\uE002 Delete current Splash");
|
||||
pp2d_draw_on(GFX_BOTTOM);
|
||||
for (int i = 0; i < splash_count; i++) {
|
||||
if (splash_count <= THEMES_PER_SCREEN)
|
||||
break;
|
||||
|
||||
if (splash_vertical_scroll > selected_splash)
|
||||
splash_vertical_scroll--;
|
||||
|
||||
if ((i < selected_splash) && \
|
||||
((selected_splash - splash_vertical_scroll) >= THEMES_PER_SCREEN) && \
|
||||
(splash_vertical_scroll != ( - THEMES_PER_SCREEN)))
|
||||
splash_vertical_scroll++;
|
||||
}
|
||||
|
||||
if (splash_vertical_scroll > 0)
|
||||
pp2d_draw_texture(TEXTURE_ARROW, 155, 6);
|
||||
if (splash_vertical_scroll + THEMES_PER_SCREEN < splash_count)
|
||||
pp2d_draw_texture_flip(TEXTURE_ARROW, 155, 224, VERTICAL);
|
||||
|
||||
for (int i = splash_vertical_scroll; i < (THEMES_PER_SCREEN + splash_vertical_scroll); i++)
|
||||
{
|
||||
if (i >= splash_count)
|
||||
break;
|
||||
|
||||
current_splash = splashes_list[i];
|
||||
wchar_t name[0x106] = {0};
|
||||
utf16_to_utf32((u32*)name, current_splash.name, 0x106);
|
||||
|
||||
int vertical_offset = 48 * (i-splash_vertical_scroll);
|
||||
u32 font_color = COLOR_WHITE;
|
||||
|
||||
if (i == selected_splash)
|
||||
{
|
||||
font_color = COLOR_BLACK;
|
||||
pp2d_draw_rectangle(0, 24 + vertical_offset, 320, 48, COLOR_CURSOR);
|
||||
}
|
||||
pp2d_draw_wtext(15, 40 + vertical_offset, 0.55, 0.55, font_color, name);
|
||||
}
|
||||
}
|
||||
pp2d_end_draw();
|
||||
char entries_count_str[0x20] = {0};
|
||||
sprintf(entries_count_str, "/%i", list->entries_count);
|
||||
float x = 316;
|
||||
x -= pp2d_get_text_width(entries_count_str, 0.6, 0.6);
|
||||
pp2d_draw_text(x, 219, 0.6, 0.6, COLOR_WHITE, entries_count_str);
|
||||
|
||||
char selected_entry_str[0x20] = {0};
|
||||
sprintf(selected_entry_str, "%i", selected_entry + 1);
|
||||
x -= pp2d_get_text_width(selected_entry_str, 0.6, 0.6);
|
||||
pp2d_draw_text(x, 219, 0.6, 0.6, COLOR_WHITE, selected_entry_str);
|
||||
|
||||
pp2d_draw_text(176, 219, 0.6, 0.6, COLOR_WHITE, list->entries_count < 1000 ? "Selected:" : "Sel.:");
|
||||
}
|
||||
|
||||
139
source/fs.c
@@ -29,21 +29,17 @@
|
||||
#include "fs.h"
|
||||
#include "unicode.h"
|
||||
|
||||
#include "minizip/unzip.h"
|
||||
|
||||
int filename_compare(__attribute__((unused)) unzFile file, const char *current_filename, const char *filename)
|
||||
{
|
||||
return strcasecmp(current_filename, filename);
|
||||
}
|
||||
#include <archive.h>
|
||||
#include <archive_entry.h>
|
||||
|
||||
Result open_archives(void)
|
||||
{
|
||||
|
||||
romfsInit();
|
||||
u8 regionCode;
|
||||
u32 archive1;
|
||||
u32 archive2;
|
||||
|
||||
Result retValue;
|
||||
Result res = 0;
|
||||
|
||||
FS_Path home;
|
||||
FS_Path theme;
|
||||
@@ -68,98 +64,127 @@ Result open_archives(void)
|
||||
archive2 = 0x00;
|
||||
}
|
||||
|
||||
retValue = FSUSER_OpenArchive(&ArchiveSD, ARCHIVE_SDMC, fsMakePath(PATH_EMPTY, ""));
|
||||
if(R_FAILED(retValue)) return retValue;
|
||||
if(R_FAILED(res = FSUSER_OpenArchive(&ArchiveSD, ARCHIVE_SDMC, fsMakePath(PATH_EMPTY, "")))) return res;
|
||||
|
||||
FSUSER_CreateDirectory(ArchiveSD, fsMakePath(PATH_ASCII, "/Themes"), FS_ATTRIBUTE_DIRECTORY);
|
||||
FSUSER_CreateDirectory(ArchiveSD, fsMakePath(PATH_ASCII, "/Splashes"), FS_ATTRIBUTE_DIRECTORY);
|
||||
|
||||
u32 homeMenuPath[3] = {MEDIATYPE_SD, archive2, 0};
|
||||
home.type = PATH_BINARY;
|
||||
home.size = 0xC;
|
||||
home.data = homeMenuPath;
|
||||
retValue = FSUSER_OpenArchive(&ArchiveHomeExt, ARCHIVE_EXTDATA, home);
|
||||
if(R_FAILED(retValue)) return retValue;
|
||||
if(R_FAILED(res = FSUSER_OpenArchive(&ArchiveHomeExt, ARCHIVE_EXTDATA, home))) return res;
|
||||
|
||||
u32 themePath[3] = {MEDIATYPE_SD, archive1, 0};
|
||||
theme.type = PATH_BINARY;
|
||||
theme.size = 0xC;
|
||||
theme.data = themePath;
|
||||
retValue = FSUSER_OpenArchive(&ArchiveThemeExt, ARCHIVE_EXTDATA, theme);
|
||||
if(R_FAILED(retValue)) return retValue;
|
||||
if(R_FAILED(res = FSUSER_OpenArchive(&ArchiveThemeExt, ARCHIVE_EXTDATA, theme))) return res;
|
||||
|
||||
Handle test_handle;
|
||||
if(R_FAILED(res = FSUSER_OpenFile(&test_handle, ArchiveThemeExt, fsMakePath(PATH_ASCII, "/ThemeManage.bin"), FS_OPEN_READ, 0))) return res;
|
||||
FSFILE_Close(test_handle);
|
||||
|
||||
romfsInit();
|
||||
return 0;
|
||||
}
|
||||
|
||||
Result close_archives(void)
|
||||
{
|
||||
Result retValue;
|
||||
Result res;
|
||||
|
||||
retValue = FSUSER_CloseArchive(ArchiveSD);
|
||||
if(R_FAILED(retValue)) return retValue;
|
||||
retValue = FSUSER_CloseArchive(ArchiveHomeExt);
|
||||
if(R_FAILED(retValue)) return retValue;
|
||||
retValue = FSUSER_CloseArchive(ArchiveThemeExt);
|
||||
if(R_FAILED(retValue)) return retValue;
|
||||
if(R_FAILED(res = FSUSER_CloseArchive(ArchiveSD))) return res;
|
||||
if(R_FAILED(res = FSUSER_CloseArchive(ArchiveHomeExt))) return res;
|
||||
if(R_FAILED(res = FSUSER_CloseArchive(ArchiveThemeExt))) return res;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
u64 file_to_buf(FS_Path path, FS_Archive archive, char** buf)
|
||||
u32 file_to_buf(FS_Path path, FS_Archive archive, char** buf)
|
||||
{
|
||||
Handle file;
|
||||
Result res = FSUSER_OpenFile(&file, archive, path, FS_OPEN_READ, 0);
|
||||
if (R_FAILED(res)) return 0;
|
||||
Result res = 0;
|
||||
if (R_FAILED(res = FSUSER_OpenFile(&file, archive, path, FS_OPEN_READ, 0))) return 0;
|
||||
|
||||
u64 size;
|
||||
FSFILE_GetSize(file, &size);
|
||||
*buf = malloc(size);
|
||||
if(size != 0)
|
||||
{
|
||||
*buf = calloc(1, size);
|
||||
FSFILE_Read(file, NULL, 0, *buf, size);
|
||||
}
|
||||
FSFILE_Close(file);
|
||||
return size;
|
||||
return (u32)size;
|
||||
}
|
||||
|
||||
static u32 zip_to_buf(struct archive *a, char *file_name, char ** buf)
|
||||
{
|
||||
struct archive_entry *entry;
|
||||
|
||||
bool found = false;
|
||||
u64 file_size = 0;
|
||||
|
||||
while(!found && archive_read_next_header(a, &entry) == ARCHIVE_OK)
|
||||
{
|
||||
found = !strcasecmp(archive_entry_pathname(entry), file_name);
|
||||
}
|
||||
|
||||
if(found)
|
||||
{
|
||||
file_size = archive_entry_size(entry);
|
||||
*buf = calloc(file_size, sizeof(char));
|
||||
archive_read_data(a, *buf, file_size);
|
||||
}
|
||||
else
|
||||
{
|
||||
DEBUG("Couldn't find file in zip\n");
|
||||
}
|
||||
|
||||
archive_read_free(a);
|
||||
|
||||
return (u32)file_size;
|
||||
}
|
||||
|
||||
u32 zip_memory_to_buf(char *file_name, void * zip_memory, size_t zip_size, char ** buf)
|
||||
{
|
||||
struct archive *a = archive_read_new();
|
||||
archive_read_support_format_zip(a);
|
||||
|
||||
int r = archive_read_open_memory(a, zip_memory, zip_size);
|
||||
if(r != ARCHIVE_OK)
|
||||
{
|
||||
DEBUG("Invalid zip being opened from memory\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return zip_to_buf(a, file_name, buf);
|
||||
}
|
||||
|
||||
u32 zip_file_to_buf(char *file_name, u16 *zip_path, char **buf)
|
||||
{
|
||||
ssize_t len = strulen(zip_path, 0x106);
|
||||
char *path = calloc(sizeof(char), len*sizeof(u16));
|
||||
utf16_to_utf8((u8*)path, zip_path, len*sizeof(u16));
|
||||
|
||||
u8 *path = calloc(sizeof(u8), len * 4);
|
||||
utf16_to_utf8(path, zip_path, len * 4);
|
||||
struct archive *a = archive_read_new();
|
||||
archive_read_support_format_zip(a);
|
||||
|
||||
unzFile zip_handle = unzOpen((char*)path);
|
||||
|
||||
if (zip_handle == NULL) return 0;
|
||||
u32 file_size = 0;
|
||||
|
||||
int status = unzLocateFile(zip_handle, file_name, filename_compare);
|
||||
if (status == UNZ_OK)
|
||||
int r = archive_read_open_filename(a, path, 0x4000);
|
||||
if(r != ARCHIVE_OK)
|
||||
{
|
||||
unz_file_info *file_info = malloc(sizeof(unz_file_info));
|
||||
unzGetCurrentFileInfo(zip_handle, file_info, NULL, 0, NULL, 0, NULL, 0);
|
||||
file_size = file_info->uncompressed_size;
|
||||
*buf = malloc(file_size);
|
||||
unzOpenCurrentFile(zip_handle);
|
||||
unzReadCurrentFile(zip_handle, *buf, file_size);
|
||||
unzCloseCurrentFile(zip_handle);
|
||||
unzClose(zip_handle);
|
||||
|
||||
free(path);
|
||||
free(file_info);
|
||||
return file_size;
|
||||
} else {
|
||||
free(path);
|
||||
puts("fileziprip");
|
||||
DEBUG("Invalid zip being opened\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return zip_to_buf(a, file_name, buf);
|
||||
}
|
||||
|
||||
Result buf_to_file(u32 size, char *path, FS_Archive archive, char *buf)
|
||||
{
|
||||
Handle handle;
|
||||
Result res = FSUSER_OpenFile(&handle, archive, fsMakePath(PATH_ASCII, path), FS_OPEN_WRITE, 0);
|
||||
if (R_FAILED(res)) return res;
|
||||
res = FSFILE_Write(handle, NULL, 0, buf, size, FS_WRITE_FLUSH);
|
||||
if (R_FAILED(res)) return res;
|
||||
res = FSFILE_Close(handle);
|
||||
if (R_FAILED(res)) return res;
|
||||
Result res = 0;
|
||||
if (R_FAILED(res = FSUSER_OpenFile(&handle, archive, fsMakePath(PATH_ASCII, path), FS_OPEN_WRITE, 0))) return res;
|
||||
if (R_FAILED(res = FSFILE_Write(handle, NULL, 0, buf, size, FS_WRITE_FLUSH))) return res;
|
||||
if (R_FAILED(res = FSFILE_Close(handle))) return res;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
431
source/loading.c
Normal file
@@ -0,0 +1,431 @@
|
||||
/*
|
||||
* This file is part of Anemone3DS
|
||||
* Copyright (C) 2016-2017 Alex Taber ("astronautlevel"), Dawid Eckert ("daedreth")
|
||||
*
|
||||
* 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 "loading.h"
|
||||
#include "pp2d/pp2d/pp2d.h"
|
||||
#include "fs.h"
|
||||
#include "unicode.h"
|
||||
#include "draw.h"
|
||||
|
||||
void delete_entry(Entry_s * entry, bool is_file)
|
||||
{
|
||||
if(is_file)
|
||||
FSUSER_DeleteFile(ArchiveSD, fsMakePath(PATH_UTF16, entry->path));
|
||||
else
|
||||
FSUSER_DeleteDirectoryRecursively(ArchiveSD, fsMakePath(PATH_UTF16, entry->path));
|
||||
}
|
||||
|
||||
u32 load_data(char * filename, Entry_s entry, char ** buf)
|
||||
{
|
||||
if(entry.is_zip)
|
||||
{
|
||||
return zip_file_to_buf(filename+1, entry.path, buf); //the first character will always be '/' because of the other case
|
||||
}
|
||||
else
|
||||
{
|
||||
u16 path[0x106] = {0};
|
||||
strucat(path, entry.path);
|
||||
struacat(path, filename);
|
||||
|
||||
return file_to_buf(fsMakePath(PATH_UTF16, path), ArchiveSD, buf);
|
||||
}
|
||||
}
|
||||
|
||||
static void parse_smdh(Entry_s * entry, const u16 * fallback_name)
|
||||
{
|
||||
char *info_buffer = NULL;
|
||||
u64 size = load_data("/info.smdh", *entry, &info_buffer);
|
||||
Icon_s * smdh = (Icon_s *)info_buffer;
|
||||
|
||||
if(!size)
|
||||
{
|
||||
free(info_buffer);
|
||||
memcpy(entry->name, fallback_name, 0x80);
|
||||
utf8_to_utf16(entry->desc, (u8*)"No description", 0x100);
|
||||
utf8_to_utf16(entry->author, (u8*)"Unknown author", 0x80);
|
||||
entry->placeholder_color = RGBA8(rand() % 255, rand() % 255, rand() % 255, 255);
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(entry->name, smdh->name, 0x40*sizeof(u16));
|
||||
memcpy(entry->desc, smdh->desc, 0x80*sizeof(u16));
|
||||
memcpy(entry->author, smdh->author, 0x40*sizeof(u16));
|
||||
}
|
||||
|
||||
static void load_smdh_icon(Entry_s entry, const ssize_t textureID)
|
||||
{
|
||||
pp2d_free_texture(textureID);
|
||||
|
||||
char *info_buffer = NULL;
|
||||
u64 size = load_data("/info.smdh", entry, &info_buffer);
|
||||
if(!size) return;
|
||||
|
||||
Icon_s * smdh = (Icon_s *)info_buffer;
|
||||
|
||||
const u32 width = 48, height = 48;
|
||||
u32 *image = malloc(width*height*sizeof(u32));
|
||||
|
||||
for(u32 x = 0; x < width; x++)
|
||||
{
|
||||
for(u32 y = 0; y < height; y++)
|
||||
{
|
||||
unsigned int dest_pixel = (x + y*width);
|
||||
unsigned int source_pixel = (((y >> 3) * (width >> 3) + (x >> 3)) << 6) + ((x & 1) | ((y & 1) << 1) | ((x & 2) << 1) | ((y & 2) << 2) | ((x & 4) << 2) | ((y & 4) << 3));
|
||||
|
||||
image[dest_pixel] = RGB565_TO_ABGR8(smdh->big_icon[source_pixel]);
|
||||
}
|
||||
}
|
||||
|
||||
free(info_buffer);
|
||||
pp2d_load_texture_memory(textureID, (u8*)image, (u32)width, (u32)height);
|
||||
free(image);
|
||||
}
|
||||
|
||||
static int compare_entries(const void * a, const void * b)
|
||||
{
|
||||
Entry_s *entry_a = (Entry_s *)a;
|
||||
Entry_s *entry_b = (Entry_s *)b;
|
||||
|
||||
return memcmp(entry_a->name, entry_b->name, 0x40*sizeof(u16));
|
||||
}
|
||||
|
||||
static void sort_list(Entry_List_s * list)
|
||||
{
|
||||
if(list->entries != NULL)
|
||||
qsort(list->entries, list->entries_count, sizeof(Entry_s), compare_entries); //alphabet sort
|
||||
}
|
||||
|
||||
Result load_entries(const char * loading_path, Entry_List_s * list)
|
||||
{
|
||||
Handle dir_handle;
|
||||
Result res = FSUSER_OpenDirectory(&dir_handle, ArchiveSD, fsMakePath(PATH_ASCII, loading_path));
|
||||
if(R_FAILED(res))
|
||||
{
|
||||
DEBUG("Failed to open folder: %s\n", loading_path);
|
||||
return res;
|
||||
}
|
||||
|
||||
u32 entries_read = 1;
|
||||
|
||||
while(entries_read)
|
||||
{
|
||||
FS_DirectoryEntry dir_entry = {0};
|
||||
res = FSDIR_Read(dir_handle, &entries_read, 1, &dir_entry);
|
||||
if(R_FAILED(res) || entries_read == 0)
|
||||
break;
|
||||
|
||||
if(!(dir_entry.attributes & FS_ATTRIBUTE_DIRECTORY) && strcmp(dir_entry.shortExt, "ZIP"))
|
||||
continue;
|
||||
|
||||
list->entries_count++;
|
||||
Entry_s * new_list = realloc(list->entries, list->entries_count * sizeof(Entry_s));
|
||||
if(new_list == NULL)
|
||||
{
|
||||
free(list->entries);
|
||||
list->entries = NULL;
|
||||
res = -1;
|
||||
DEBUG("break\n");
|
||||
break;
|
||||
}
|
||||
else
|
||||
list->entries = new_list;
|
||||
|
||||
Entry_s * current_entry = &(list->entries[list->entries_count-1]);
|
||||
memset(current_entry, 0, sizeof(Entry_s));
|
||||
|
||||
struacat(current_entry->path, loading_path);
|
||||
strucat(current_entry->path, dir_entry.name);
|
||||
|
||||
current_entry->is_zip = !strcmp(dir_entry.shortExt, "ZIP");
|
||||
parse_smdh(current_entry, dir_entry.name);
|
||||
}
|
||||
|
||||
FSDIR_Close(dir_handle);
|
||||
|
||||
sort_list(list);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void load_icons_first(Entry_List_s * list, bool silent)
|
||||
{
|
||||
if(list == NULL || list->entries == NULL) return;
|
||||
|
||||
if(!silent)
|
||||
draw_install(INSTALL_LOADING_ICONS);
|
||||
|
||||
int starti = 0, endi = 0;
|
||||
|
||||
if(list->entries_count <= list->entries_loaded*ICONS_OFFSET_AMOUNT)
|
||||
{
|
||||
DEBUG("small load\n");
|
||||
// if the list is one that doesnt need swapping, load everything at once
|
||||
endi = list->entries_count;
|
||||
}
|
||||
else
|
||||
{
|
||||
DEBUG("extended load\n");
|
||||
// otherwise, load around to prepare for swapping
|
||||
starti = list->scroll - list->entries_loaded*ICONS_VISIBLE;
|
||||
endi = starti + list->entries_loaded*ICONS_OFFSET_AMOUNT;
|
||||
}
|
||||
|
||||
list->icons_ids = calloc(endi-starti, sizeof(ssize_t));
|
||||
|
||||
ssize_t * icons_ids = list->icons_ids;
|
||||
ssize_t id = list->texture_id_offset;
|
||||
|
||||
for(int i = starti; i < endi; i++, id++)
|
||||
{
|
||||
int offset = i;
|
||||
if(offset < 0)
|
||||
offset += list->entries_count;
|
||||
if(offset >= list->entries_count)
|
||||
offset -= list->entries_count;
|
||||
|
||||
Entry_s current_entry = list->entries[offset];
|
||||
load_smdh_icon(current_entry, id);
|
||||
|
||||
icons_ids[i-starti] = id;
|
||||
}
|
||||
}
|
||||
|
||||
static void reverse(ssize_t a[], int sz) {
|
||||
int i, j;
|
||||
for (i = 0, j = sz; i < j; i++, j--) {
|
||||
ssize_t tmp = a[i];
|
||||
a[i] = a[j];
|
||||
a[j] = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
static void rotate(ssize_t array[], int size, int amt) {
|
||||
if (amt < 0)
|
||||
amt = size + amt;
|
||||
reverse(array, size-amt-1);
|
||||
reverse(array+size-amt, amt-1);
|
||||
reverse(array, size-1);
|
||||
}
|
||||
|
||||
void handle_scrolling(Entry_List_s * list)
|
||||
{
|
||||
// Scroll the menu up or down if the selected theme is out of its bounds
|
||||
//----------------------------------------------------------------
|
||||
if(list->entries_count > list->entries_loaded)
|
||||
{
|
||||
for(int i = 0; i < list->entries_count; i++)
|
||||
{
|
||||
int change = 0;
|
||||
|
||||
if(list->entries_count > list->entries_loaded*2 && list->previous_scroll < list->entries_loaded && list->selected_entry >= list->entries_count - list->entries_loaded)
|
||||
{
|
||||
list->scroll = list->entries_count - list->entries_loaded;
|
||||
}
|
||||
else if(list->entries_count > list->entries_loaded*2 && list->selected_entry < list->entries_loaded && list->previous_selected >= list->entries_count - list->entries_loaded)
|
||||
{
|
||||
list->scroll = 0;
|
||||
}
|
||||
else if(list->selected_entry == list->previous_selected+1 && list->selected_entry == list->scroll+list->entries_loaded)
|
||||
{
|
||||
change = 1;
|
||||
}
|
||||
else if(list->selected_entry == list->previous_selected-1 && list->selected_entry == list->scroll-1)
|
||||
{
|
||||
change = -1;
|
||||
}
|
||||
else if(list->selected_entry == list->previous_selected+list->entries_loaded || list->selected_entry >= list->scroll + list->entries_loaded)
|
||||
{
|
||||
change = list->entries_loaded;
|
||||
}
|
||||
else if(list->selected_entry == list->previous_selected-list->entries_loaded || list->selected_entry < list->scroll)
|
||||
{
|
||||
change = -list->entries_loaded;
|
||||
}
|
||||
|
||||
list->scroll += change;
|
||||
|
||||
if(list->scroll < 0)
|
||||
list->scroll = 0;
|
||||
else if(list->scroll > list->entries_count - list->entries_loaded)
|
||||
list->scroll = list->entries_count - list->entries_loaded;
|
||||
|
||||
if(!change)
|
||||
list->previous_selected = list->selected_entry;
|
||||
else
|
||||
list->previous_selected += change;
|
||||
}
|
||||
}
|
||||
//----------------------------------------------------------------
|
||||
}
|
||||
|
||||
static void load_icons(Entry_List_s * current_list)
|
||||
{
|
||||
if(current_list == NULL || current_list->entries == NULL)
|
||||
return;
|
||||
|
||||
handle_scrolling(current_list);
|
||||
|
||||
if(current_list->entries_count <= current_list->entries_loaded*ICONS_OFFSET_AMOUNT || current_list->previous_scroll == current_list->scroll)
|
||||
return; // return if the list is one that doesnt need swapping, or if nothing changed
|
||||
|
||||
#define SIGN(x) (x > 0 ? 1 : ((x < 0) ? -1 : 0))
|
||||
|
||||
int delta = current_list->scroll - current_list->previous_scroll;
|
||||
if(abs(delta) >= current_list->entries_count - current_list->entries_loaded*(ICONS_OFFSET_AMOUNT-1))
|
||||
delta = -SIGN(delta) * (current_list->entries_count - abs(delta));
|
||||
|
||||
int starti = current_list->scroll;
|
||||
int endi = starti + abs(delta);
|
||||
|
||||
if(delta < 0)
|
||||
{
|
||||
endi -= abs(delta) + 1;
|
||||
starti += abs(delta) - 1;
|
||||
}
|
||||
|
||||
int ctr = 0;
|
||||
Entry_s ** entries = calloc(abs(delta), sizeof(Entry_s *));
|
||||
ssize_t * ids = calloc(abs(delta), sizeof(ssize_t));
|
||||
|
||||
#define FIRST(arr) arr[0]
|
||||
#define LAST(arr) arr[current_list->entries_loaded*ICONS_OFFSET_AMOUNT - 1]
|
||||
|
||||
ssize_t * icons_ids = current_list->icons_ids;
|
||||
|
||||
for(int i = starti; i != endi; i++, ctr++)
|
||||
{
|
||||
ssize_t id = 0;
|
||||
int offset = i;
|
||||
|
||||
rotate(icons_ids, ICONS_OFFSET_AMOUNT*current_list->entries_loaded, -1*SIGN(delta));
|
||||
|
||||
if(delta > 0)
|
||||
{
|
||||
id = LAST(icons_ids);
|
||||
offset += current_list->entries_loaded*ICONS_UNDER - delta;
|
||||
}
|
||||
else
|
||||
{
|
||||
id = FIRST(icons_ids);
|
||||
offset -= current_list->entries_loaded*ICONS_VISIBLE;
|
||||
i -= 2; //i-- twice to counter the i++, needed only for this case
|
||||
}
|
||||
|
||||
if(offset < 0)
|
||||
offset += current_list->entries_count;
|
||||
if(offset >= current_list->entries_count)
|
||||
offset -= current_list->entries_count;
|
||||
|
||||
entries[ctr] = ¤t_list->entries[offset];
|
||||
ids[ctr] = id;
|
||||
}
|
||||
|
||||
#undef FIRST
|
||||
#undef LAST
|
||||
#undef SIGN
|
||||
|
||||
svcSleepThread(1e6);
|
||||
for(int i = 0; i < abs(delta); i++)
|
||||
{
|
||||
Entry_s current_entry = *entries[i];
|
||||
ssize_t id = ids[i];
|
||||
load_smdh_icon(current_entry, id);
|
||||
}
|
||||
|
||||
free(entries);
|
||||
free(ids);
|
||||
|
||||
current_list->previous_scroll = current_list->scroll;
|
||||
}
|
||||
|
||||
void load_icons_thread(void * void_arg)
|
||||
{
|
||||
Thread_Arg_s * arg = (Thread_Arg_s *)void_arg;
|
||||
Handle update_request = *(Handle *)arg->thread_arg[1];
|
||||
do
|
||||
{
|
||||
svcWaitSynchronization(update_request, U64_MAX);
|
||||
svcClearEvent(update_request);
|
||||
volatile Entry_List_s * current_list = *(volatile Entry_List_s **)arg->thread_arg[0];
|
||||
load_icons((Entry_List_s *)current_list);
|
||||
}
|
||||
while(arg->run_thread);
|
||||
}
|
||||
|
||||
static u16 previous_path_preview[0x106] = {0};
|
||||
bool load_preview(Entry_List_s list, int * preview_offset)
|
||||
{
|
||||
if(list.entries == NULL) return false;
|
||||
|
||||
Entry_s entry = list.entries[list.selected_entry];
|
||||
|
||||
if(!memcmp(&previous_path_preview, &entry.path, 0x106*sizeof(u16))) return true;
|
||||
|
||||
char *preview_buffer = NULL;
|
||||
u64 size = load_data("/preview.png", entry, &preview_buffer);
|
||||
|
||||
if(!size)
|
||||
{
|
||||
free(preview_buffer);
|
||||
throw_error("No preview found.", ERROR_LEVEL_WARNING);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ret = false;
|
||||
u8 * image = NULL;
|
||||
unsigned int width = 0, height = 0;
|
||||
|
||||
if((lodepng_decode32(&image, &width, &height, (u8*)preview_buffer, size)) == 0) // no error
|
||||
{
|
||||
for(u32 i = 0; i < width; i++)
|
||||
{
|
||||
for(u32 j = 0; j < height; j++)
|
||||
{
|
||||
u32* pixel = (u32*)(image + (i + j*width) * 4);
|
||||
*pixel = __builtin_bswap32(*pixel); //swap from RGBA to ABGR, needed for pp2d
|
||||
}
|
||||
}
|
||||
|
||||
// mark the new preview as loaded for optimisation
|
||||
memcpy(&previous_path_preview, &entry.path, 0x106*sizeof(u16));
|
||||
// free the previously loaded preview. wont do anything if there wasnt one
|
||||
pp2d_free_texture(TEXTURE_PREVIEW);
|
||||
|
||||
pp2d_load_texture_memory(TEXTURE_PREVIEW, image, (u32)width, (u32)height);
|
||||
|
||||
*preview_offset = (width-400)/2;
|
||||
ret = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw_error("Corrupted/invalid preview.png", ERROR_LEVEL_WARNING);
|
||||
}
|
||||
|
||||
free(image);
|
||||
free(preview_buffer);
|
||||
|
||||
return ret;
|
||||
}
|
||||
831
source/main.c
@@ -25,319 +25,698 @@
|
||||
*/
|
||||
|
||||
#include "fs.h"
|
||||
#include "loading.h"
|
||||
#include "themes.h"
|
||||
#include "splashes.h"
|
||||
#include "draw.h"
|
||||
#include "common.h"
|
||||
#include "camera.h"
|
||||
#include "remote.h"
|
||||
#include "instructions.h"
|
||||
#include "pp2d/pp2d/pp2d.h"
|
||||
#include <time.h>
|
||||
|
||||
int __stacksize__ = 64 * 1024;
|
||||
bool quit = false;
|
||||
static bool homebrew = false;
|
||||
static bool installed_themes = false;
|
||||
|
||||
int init_services(void)
|
||||
static Thread iconLoadingThread = {0};
|
||||
static Thread_Arg_s iconLoadingThread_arg = {0};
|
||||
static Handle update_icons_handle;
|
||||
|
||||
static Thread installCheckThreads[MODE_AMOUNT] = {0};
|
||||
static Thread_Arg_s installCheckThreads_arg[MODE_AMOUNT] = {0};
|
||||
|
||||
static Entry_List_s lists[MODE_AMOUNT] = {0};
|
||||
|
||||
int __stacksize__ = 64 * 1024;
|
||||
Result archive_result;
|
||||
u32 old_time_limit;
|
||||
|
||||
const char * main_paths[MODE_AMOUNT] = {
|
||||
"/Themes/",
|
||||
"/Splashes/",
|
||||
};
|
||||
const int entries_per_screen_v[MODE_AMOUNT] = {
|
||||
4,
|
||||
4,
|
||||
};
|
||||
const int entries_per_screen_h[MODE_AMOUNT] = { //for themeplaza browser
|
||||
6,
|
||||
6,
|
||||
};
|
||||
const int entry_size[MODE_AMOUNT] = {
|
||||
48,
|
||||
48,
|
||||
};
|
||||
|
||||
static void init_services(void)
|
||||
{
|
||||
consoleDebugInit(debugDevice_SVC);
|
||||
cfguInit();
|
||||
ptmuInit();
|
||||
acInit();
|
||||
APT_GetAppCpuTimeLimit(&old_time_limit);
|
||||
APT_SetAppCpuTimeLimit(30);
|
||||
httpcInit(0);
|
||||
open_archives();
|
||||
bool homebrew = true;
|
||||
if (!envIsHomebrew())
|
||||
archive_result = open_archives();
|
||||
if(envIsHomebrew())
|
||||
{
|
||||
homebrew = false;
|
||||
} else {
|
||||
s64 out;
|
||||
svcGetSystemInfo(&out, 0x10000, 0);
|
||||
if (out)
|
||||
{
|
||||
homebrew = false;
|
||||
homebrew = !out;
|
||||
}
|
||||
}
|
||||
return homebrew;
|
||||
}
|
||||
|
||||
int exit_services(void)
|
||||
static void exit_services(void)
|
||||
{
|
||||
close_archives();
|
||||
cfguExit();
|
||||
ptmuExit();
|
||||
if (old_time_limit != UINT32_MAX) APT_SetAppCpuTimeLimit(old_time_limit);
|
||||
httpcExit();
|
||||
return 0;
|
||||
acExit();
|
||||
}
|
||||
|
||||
static void stop_install_check(void)
|
||||
{
|
||||
for(int i = 0; i < MODE_AMOUNT; i++)
|
||||
{
|
||||
installCheckThreads_arg[i].run_thread = false;
|
||||
}
|
||||
}
|
||||
|
||||
static void exit_thread(void)
|
||||
{
|
||||
if(iconLoadingThread_arg.run_thread)
|
||||
{
|
||||
DEBUG("exiting thread\n");
|
||||
iconLoadingThread_arg.run_thread = false;
|
||||
svcSignalEvent(update_icons_handle);
|
||||
threadJoin(iconLoadingThread, U64_MAX);
|
||||
threadFree(iconLoadingThread);
|
||||
}
|
||||
}
|
||||
|
||||
void free_lists(void)
|
||||
{
|
||||
stop_install_check();
|
||||
for(int i = 0; i < MODE_AMOUNT; i++)
|
||||
{
|
||||
Entry_List_s * current_list = &lists[i];
|
||||
free(current_list->entries);
|
||||
free(current_list->icons_ids);
|
||||
memset(current_list, 0, sizeof(Entry_List_s));
|
||||
}
|
||||
exit_thread();
|
||||
}
|
||||
|
||||
void exit_function(bool power_pressed)
|
||||
{
|
||||
free_lists();
|
||||
svcCloseHandle(update_icons_handle);
|
||||
exit_screens();
|
||||
exit_services();
|
||||
|
||||
if(!power_pressed && installed_themes)
|
||||
{
|
||||
if(homebrew)
|
||||
{
|
||||
APT_HardwareResetAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
srvPublishToSubscriber(0x202, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void start_thread(void)
|
||||
{
|
||||
if(iconLoadingThread_arg.run_thread)
|
||||
{
|
||||
DEBUG("starting thread\n");
|
||||
iconLoadingThread = threadCreate(load_icons_thread, &iconLoadingThread_arg, __stacksize__, 0x38, -2, false);
|
||||
}
|
||||
}
|
||||
|
||||
static void load_lists(Entry_List_s * lists)
|
||||
{
|
||||
ssize_t texture_id_offset = TEXTURE_ICON;
|
||||
|
||||
free_lists();
|
||||
for(int i = 0; i < MODE_AMOUNT; i++)
|
||||
{
|
||||
InstallType loading_screen = INSTALL_NONE;
|
||||
if(i == MODE_THEMES)
|
||||
loading_screen = INSTALL_LOADING_THEMES;
|
||||
else if(i == MODE_SPLASHES)
|
||||
loading_screen = INSTALL_LOADING_SPLASHES;
|
||||
|
||||
draw_install(loading_screen);
|
||||
draw_install(loading_screen);
|
||||
|
||||
Entry_List_s * current_list = &lists[i];
|
||||
current_list->mode = i;
|
||||
current_list->entries_per_screen_v = entries_per_screen_v[i];
|
||||
current_list->entries_per_screen_h = 1;
|
||||
current_list->entries_loaded = current_list->entries_per_screen_v * current_list->entries_per_screen_h;
|
||||
current_list->entry_size = entry_size[i];
|
||||
Result res = load_entries(main_paths[i], current_list);
|
||||
if(R_SUCCEEDED(res))
|
||||
{
|
||||
if(current_list->entries_count > current_list->entries_loaded*ICONS_OFFSET_AMOUNT)
|
||||
iconLoadingThread_arg.run_thread = true;
|
||||
|
||||
DEBUG("total: %i\n", current_list->entries_count);
|
||||
|
||||
current_list->texture_id_offset = texture_id_offset;
|
||||
load_icons_first(current_list, false);
|
||||
|
||||
texture_id_offset += current_list->entries_loaded*ICONS_OFFSET_AMOUNT;
|
||||
|
||||
void (*install_check_function)(void*) = NULL;
|
||||
if(i == MODE_THEMES)
|
||||
install_check_function = themes_check_installed;
|
||||
else if(i == MODE_SPLASHES)
|
||||
install_check_function = splash_check_installed;
|
||||
|
||||
Thread_Arg_s * current_arg = &installCheckThreads_arg[i];
|
||||
current_arg->run_thread = true;
|
||||
current_arg->thread_arg = (void**)current_list;
|
||||
|
||||
if(install_check_function != NULL)
|
||||
{
|
||||
installCheckThreads[i] = threadCreate(install_check_function, current_arg, __stacksize__, 0x3f, -2, true);
|
||||
svcSleepThread(1e8);
|
||||
}
|
||||
}
|
||||
}
|
||||
start_thread();
|
||||
}
|
||||
|
||||
static SwkbdCallbackResult jump_menu_callback(void* entries_count, const char** ppMessage, const char* text, size_t textlen)
|
||||
{
|
||||
int typed_value = atoi(text);
|
||||
if(typed_value > *(int*)entries_count)
|
||||
{
|
||||
*ppMessage = "The new position has to be\nsmaller or equal to the\nnumber of entries!";
|
||||
return SWKBD_CALLBACK_CONTINUE;
|
||||
}
|
||||
else if(typed_value == 0)
|
||||
{
|
||||
*ppMessage = "The new position has to\nbe positive!";
|
||||
return SWKBD_CALLBACK_CONTINUE;
|
||||
}
|
||||
return SWKBD_CALLBACK_OK;
|
||||
}
|
||||
|
||||
static void jump_menu(Entry_List_s * list)
|
||||
{
|
||||
if(list == NULL) return;
|
||||
|
||||
char numbuf[64] = {0};
|
||||
|
||||
SwkbdState swkbd;
|
||||
|
||||
sprintf(numbuf, "%i", list->entries_count);
|
||||
int max_chars = strlen(numbuf);
|
||||
swkbdInit(&swkbd, SWKBD_TYPE_NUMPAD, 2, max_chars);
|
||||
|
||||
sprintf(numbuf, "%i", list->selected_entry);
|
||||
swkbdSetInitialText(&swkbd, numbuf);
|
||||
|
||||
sprintf(numbuf, "Where do you want to jump to?\nMay cause icons to reload.");
|
||||
swkbdSetHintText(&swkbd, numbuf);
|
||||
|
||||
swkbdSetButton(&swkbd, SWKBD_BUTTON_LEFT, "Cancel", false);
|
||||
swkbdSetButton(&swkbd, SWKBD_BUTTON_RIGHT, "Jump", true);
|
||||
swkbdSetValidation(&swkbd, SWKBD_NOTEMPTY_NOTBLANK, 0, max_chars);
|
||||
swkbdSetFilterCallback(&swkbd, jump_menu_callback, &list->entries_count);
|
||||
|
||||
memset(numbuf, 0, sizeof(numbuf));
|
||||
SwkbdButton button = swkbdInputText(&swkbd, numbuf, sizeof(numbuf));
|
||||
if(button == SWKBD_BUTTON_CONFIRM)
|
||||
{
|
||||
list->selected_entry = atoi(numbuf) - 1;
|
||||
list->scroll = list->selected_entry;
|
||||
if(list->scroll >= list->entries_count - list->entries_loaded)
|
||||
list->scroll = list->entries_count - list->entries_loaded - 1;
|
||||
}
|
||||
}
|
||||
|
||||
static void change_selected(Entry_List_s * list, int change_value)
|
||||
{
|
||||
if(abs(change_value) >= list->entries_count) return;
|
||||
|
||||
int newval = list->selected_entry + change_value;
|
||||
|
||||
if(newval < 0)
|
||||
newval += list->entries_count;
|
||||
newval %= list->entries_count;
|
||||
|
||||
list->selected_entry = newval;
|
||||
}
|
||||
|
||||
static void toggle_shuffle(Entry_List_s * list)
|
||||
{
|
||||
Entry_s * current_entry = &list->entries[list->selected_entry];
|
||||
if(current_entry->in_shuffle) list->shuffle_count--;
|
||||
else list->shuffle_count++;
|
||||
current_entry->in_shuffle = !current_entry->in_shuffle;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
srand(time(NULL));
|
||||
bool homebrew = init_services();
|
||||
init_services();
|
||||
init_screens();
|
||||
|
||||
themes_list = NULL;
|
||||
theme_count = 0;
|
||||
Result res = get_themes(&themes_list, &theme_count);
|
||||
if (R_FAILED(res))
|
||||
{
|
||||
//don't need to worry about possible textures (icons, previews), that's freed by pp2d itself
|
||||
free(themes_list);
|
||||
themes_list = NULL;
|
||||
}
|
||||
int splash_count = 0;
|
||||
Splash_s *splashes_list = NULL;
|
||||
res = get_splashes(&splashes_list, &splash_count);
|
||||
if (R_FAILED(res))
|
||||
{
|
||||
//don't need to worry about possible textures (icons, previews), that's freed by pp2d itself
|
||||
free(splashes_list);
|
||||
splashes_list = NULL;
|
||||
}
|
||||
svcCreateEvent(&update_icons_handle, RESET_ONESHOT);
|
||||
|
||||
static Entry_List_s * current_list = NULL;
|
||||
void * iconLoadingThread_args_void[] = {
|
||||
¤t_list,
|
||||
&update_icons_handle,
|
||||
};
|
||||
iconLoadingThread_arg.thread_arg = iconLoadingThread_args_void;
|
||||
iconLoadingThread_arg.run_thread = false;
|
||||
|
||||
#ifndef CITRA_MODE
|
||||
if(R_SUCCEEDED(archive_result))
|
||||
load_lists(lists);
|
||||
#else
|
||||
load_lists(lists);
|
||||
#endif
|
||||
|
||||
EntryMode current_mode = MODE_THEMES;
|
||||
|
||||
bool splash_mode = false;
|
||||
int selected_splash = 0;
|
||||
int selected_theme = 0;
|
||||
int previously_selected = 0;
|
||||
int shuffle_theme_count = 0;
|
||||
bool preview_mode = false;
|
||||
int preview_offset = 0;
|
||||
|
||||
bool qr_mode = false;
|
||||
bool install_mode = false;
|
||||
bool extra_mode = false;
|
||||
|
||||
while(aptMainLoop())
|
||||
{
|
||||
if(quit)
|
||||
{
|
||||
exit_function(false);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifndef CITRA_MODE
|
||||
if(R_FAILED(archive_result) && current_mode == MODE_THEMES)
|
||||
{
|
||||
throw_error("Theme extdata does not exist!\nSet a default theme from the home menu.", ERROR_LEVEL_ERROR);
|
||||
quit = true;
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
|
||||
hidScanInput();
|
||||
u32 kDown = hidKeysDown();
|
||||
u32 kHeld = hidKeysHeld();
|
||||
u32 kUp = hidKeysUp();
|
||||
|
||||
if (qr_mode)
|
||||
{
|
||||
draw_qr();
|
||||
} else if (!splash_mode)
|
||||
{
|
||||
draw_theme_interface(themes_list, theme_count, selected_theme, preview_mode, shuffle_theme_count);
|
||||
} else {
|
||||
draw_splash_interface(splashes_list, splash_count, selected_splash, preview_mode);
|
||||
}
|
||||
current_list = &lists[current_mode];
|
||||
|
||||
if (kDown & KEY_START)
|
||||
{
|
||||
if (homebrew)
|
||||
APT_HardwareResetAsync();
|
||||
Instructions_s instructions = normal_instructions[current_mode];
|
||||
if(install_mode)
|
||||
instructions = install_instructions;
|
||||
if(extra_mode)
|
||||
instructions = extra_instructions;
|
||||
|
||||
if(qr_mode) take_picture();
|
||||
else if(preview_mode) draw_preview(TEXTURE_PREVIEW, preview_offset);
|
||||
else {
|
||||
srvPublishToSubscriber(0x202, 0);
|
||||
}
|
||||
}
|
||||
else if (kDown & KEY_L)
|
||||
if(!iconLoadingThread_arg.run_thread)
|
||||
{
|
||||
splash_mode = !splash_mode;
|
||||
} else if (kDown & KEY_R)
|
||||
{
|
||||
if (splash_mode || preview_mode) {
|
||||
continue;
|
||||
} else {
|
||||
qr_mode = !qr_mode;
|
||||
if (qr_mode) init_qr();
|
||||
else exit_qr();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (qr_mode) continue;
|
||||
|
||||
if (themes_list == NULL && !splash_mode)
|
||||
continue;
|
||||
|
||||
if (splashes_list == NULL && splash_mode)
|
||||
continue;
|
||||
|
||||
Theme_s * current_theme = &themes_list[selected_theme];
|
||||
Splash_s *current_splash = &splashes_list[selected_splash];
|
||||
|
||||
if (kDown & KEY_Y)
|
||||
{
|
||||
if (!preview_mode)
|
||||
{
|
||||
if (!current_theme->has_preview)
|
||||
load_theme_preview(current_theme);
|
||||
|
||||
preview_mode = current_theme->has_preview;
|
||||
handle_scrolling(current_list);
|
||||
current_list->previous_scroll = current_list->scroll;
|
||||
}
|
||||
else
|
||||
preview_mode = false;
|
||||
{
|
||||
svcSignalEvent(update_icons_handle);
|
||||
svcSleepThread(5e6);
|
||||
}
|
||||
|
||||
//don't allow anything while the preview is up
|
||||
if (preview_mode)
|
||||
draw_interface(current_list, instructions);
|
||||
svcSleepThread(1e7);
|
||||
}
|
||||
|
||||
pp2d_end_draw();
|
||||
|
||||
if(kDown & KEY_START) quit = true;
|
||||
|
||||
if(!install_mode && !extra_mode)
|
||||
{
|
||||
if(!preview_mode && !qr_mode && kDown & KEY_L) //toggle between splashes and themes
|
||||
{
|
||||
switch_mode:
|
||||
current_mode++;
|
||||
current_mode %= MODE_AMOUNT;
|
||||
continue;
|
||||
}
|
||||
else if(!qr_mode && !preview_mode && kDown & KEY_R) //toggle QR mode
|
||||
{
|
||||
enable_qr:
|
||||
if(R_SUCCEEDED(camInit()))
|
||||
{
|
||||
camExit();
|
||||
u32 out;
|
||||
ACU_GetWifiStatus(&out);
|
||||
if(out)
|
||||
{
|
||||
if(init_qr())
|
||||
{
|
||||
load_lists(lists);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw_error("Please connect to Wi-Fi before scanning QR codes", ERROR_LEVEL_WARNING);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(homebrew)
|
||||
throw_error("QR scanning doesnt work from the Homebrew\nLauncher, use the ThemePlaza browser instead.", ERROR_LEVEL_WARNING);
|
||||
else
|
||||
throw_error("Your camera seems to have a problem,\nunable to scan QR codes.", ERROR_LEVEL_WARNING);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
else if(!qr_mode && kDown & KEY_Y) //toggle preview mode
|
||||
{
|
||||
toggle_preview:
|
||||
if(!preview_mode)
|
||||
preview_mode = load_preview(*current_list, &preview_offset);
|
||||
else
|
||||
preview_mode = false;
|
||||
continue;
|
||||
}
|
||||
else if(preview_mode && kDown & (KEY_B | KEY_TOUCH))
|
||||
{
|
||||
preview_mode = false;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if(qr_mode || preview_mode || current_list->entries == NULL)
|
||||
goto touch;
|
||||
|
||||
int selected_entry = current_list->selected_entry;
|
||||
Entry_s * current_entry = ¤t_list->entries[selected_entry];
|
||||
|
||||
if(install_mode)
|
||||
{
|
||||
if(kUp & KEY_A)
|
||||
install_mode = false;
|
||||
if(!install_mode)
|
||||
{
|
||||
if((kDown | kHeld) & KEY_DLEFT)
|
||||
{
|
||||
draw_install(INSTALL_BGM);
|
||||
if(R_SUCCEEDED(bgm_install(*current_entry)))
|
||||
{
|
||||
for(int i = 0; i < current_list->entries_count; i++)
|
||||
{
|
||||
Entry_s * theme = ¤t_list->entries[i];
|
||||
if(theme == current_entry)
|
||||
theme->installed = true;
|
||||
else
|
||||
theme->installed = false;
|
||||
}
|
||||
installed_themes = true;
|
||||
}
|
||||
}
|
||||
else if((kDown | kHeld) & KEY_DUP)
|
||||
{
|
||||
draw_install(INSTALL_SINGLE);
|
||||
if(R_SUCCEEDED(theme_install(*current_entry)))
|
||||
{
|
||||
for(int i = 0; i < current_list->entries_count; i++)
|
||||
{
|
||||
Entry_s * theme = ¤t_list->entries[i];
|
||||
if(theme == current_entry)
|
||||
theme->installed = true;
|
||||
else
|
||||
theme->installed = false;
|
||||
}
|
||||
installed_themes = true;
|
||||
}
|
||||
}
|
||||
else if((kDown | kHeld) & KEY_DRIGHT)
|
||||
{
|
||||
draw_install(INSTALL_NO_BGM);
|
||||
if(R_SUCCEEDED(no_bgm_install(*current_entry)))
|
||||
{
|
||||
for(int i = 0; i < current_list->entries_count; i++)
|
||||
{
|
||||
Entry_s * theme = ¤t_list->entries[i];
|
||||
if(theme == current_entry)
|
||||
theme->installed = true;
|
||||
else
|
||||
theme->installed = false;
|
||||
}
|
||||
installed_themes = true;
|
||||
}
|
||||
}
|
||||
else if((kDown | kHeld) & KEY_DDOWN)
|
||||
{
|
||||
if(current_list->shuffle_count > MAX_SHUFFLE_THEMES)
|
||||
{
|
||||
throw_error("You have too many themes selected.", ERROR_LEVEL_WARNING);
|
||||
}
|
||||
else if(current_list->shuffle_count < 2)
|
||||
{
|
||||
throw_error("You don't have enough themes selected.", ERROR_LEVEL_WARNING);
|
||||
}
|
||||
else
|
||||
{
|
||||
draw_install(INSTALL_SHUFFLE);
|
||||
Result res = shuffle_install(*current_list);
|
||||
if(R_FAILED(res)) DEBUG("shuffle install result: %lx\n", res);
|
||||
else
|
||||
{
|
||||
for(int i = 0; i < current_list->entries_count; i++)
|
||||
{
|
||||
Entry_s * theme = ¤t_list->entries[i];
|
||||
if(theme->in_shuffle)
|
||||
{
|
||||
theme->in_shuffle = false;
|
||||
theme->installed = true;
|
||||
}
|
||||
else theme->installed = false;
|
||||
}
|
||||
current_list->shuffle_count = 0;
|
||||
installed_themes = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
else if(extra_mode)
|
||||
{
|
||||
if(kUp & KEY_X)
|
||||
extra_mode = false;
|
||||
if(!extra_mode)
|
||||
{
|
||||
if((kDown | kHeld) & KEY_DLEFT)
|
||||
{
|
||||
browse_themeplaza:
|
||||
if(themeplaza_browser(current_mode))
|
||||
{
|
||||
current_mode = MODE_THEMES;
|
||||
load_lists(lists);
|
||||
}
|
||||
}
|
||||
else if((kDown | kHeld) & KEY_DUP)
|
||||
{
|
||||
jump:
|
||||
jump_menu(current_list);
|
||||
|
||||
}
|
||||
else if((kDown | kHeld) & KEY_DRIGHT)
|
||||
{
|
||||
|
||||
}
|
||||
else if((kDown | kHeld) & KEY_DDOWN)
|
||||
{
|
||||
load_icons_first(current_list, false);
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// Actions
|
||||
else if (kDown & KEY_X)
|
||||
{
|
||||
if (splash_mode) {
|
||||
draw_splash_install(UNINSTALL);
|
||||
splash_delete();
|
||||
} else {
|
||||
draw_theme_install(BGM_INSTALL);
|
||||
bgm_install(*current_theme);
|
||||
}
|
||||
}
|
||||
else if (kDown & KEY_A)
|
||||
{
|
||||
if (splash_mode)
|
||||
{
|
||||
draw_splash_install(SINGLE_INSTALL);
|
||||
splash_install(*current_splash);
|
||||
svcSleepThread(5e8);
|
||||
} else {
|
||||
draw_theme_install(SINGLE_INSTALL);
|
||||
single_install(*current_theme);
|
||||
}
|
||||
}
|
||||
|
||||
if(kDown & KEY_A)
|
||||
{
|
||||
switch(current_mode)
|
||||
{
|
||||
case MODE_THEMES:
|
||||
install_mode = true;
|
||||
break;
|
||||
case MODE_SPLASHES:
|
||||
draw_install(INSTALL_SPLASH);
|
||||
splash_install(*current_entry);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if(kDown & KEY_B)
|
||||
{
|
||||
if (splash_mode)
|
||||
switch(current_mode)
|
||||
{
|
||||
|
||||
} else {
|
||||
if (shuffle_theme_count < 10)
|
||||
case MODE_THEMES:
|
||||
toggle_shuffle(current_list);
|
||||
break;
|
||||
case MODE_SPLASHES:
|
||||
if(draw_confirm("Are you sure you would like to delete\nthe installed splash?", current_list))
|
||||
{
|
||||
if (current_theme->in_shuffle) shuffle_theme_count--;
|
||||
else shuffle_theme_count++;
|
||||
current_theme->in_shuffle = !(current_theme->in_shuffle);
|
||||
} else {
|
||||
if (current_theme->in_shuffle) {
|
||||
shuffle_theme_count--;
|
||||
current_theme->in_shuffle = false;
|
||||
draw_install(INSTALL_SPLASH_DELETE);
|
||||
splash_delete();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if(kDown & KEY_X)
|
||||
{
|
||||
extra_mode = true;
|
||||
}
|
||||
}
|
||||
|
||||
else if(kDown & KEY_SELECT)
|
||||
{
|
||||
if (splash_mode)
|
||||
if(draw_confirm("Are you sure you would like to delete this?", current_list))
|
||||
{
|
||||
|
||||
} else {
|
||||
if (shuffle_theme_count > 0)
|
||||
{
|
||||
draw_theme_install(SHUFFLE_INSTALL);
|
||||
shuffle_install(themes_list, theme_count);
|
||||
shuffle_theme_count = 0;
|
||||
}
|
||||
draw_install(INSTALL_ENTRY_DELETE);
|
||||
delete_entry(current_entry, current_entry->is_zip);
|
||||
load_lists(lists);
|
||||
}
|
||||
}
|
||||
|
||||
// Movement in the UI
|
||||
else if (kDown & KEY_DOWN)
|
||||
{
|
||||
if (splash_mode)
|
||||
{
|
||||
selected_splash++;
|
||||
if (selected_splash >= splash_count)
|
||||
selected_splash = 0;
|
||||
} else {
|
||||
selected_theme++;
|
||||
if (selected_theme >= theme_count)
|
||||
selected_theme = 0;
|
||||
}
|
||||
}
|
||||
else if(kDown & KEY_UP)
|
||||
{
|
||||
if (splash_mode)
|
||||
{
|
||||
selected_splash--;
|
||||
if (selected_splash < 0)
|
||||
selected_splash = splash_count - 1;
|
||||
} else {
|
||||
selected_theme--;
|
||||
if (selected_theme < 0)
|
||||
selected_theme = theme_count - 1;
|
||||
change_selected(current_list, -1);
|
||||
}
|
||||
else if(kDown & KEY_DOWN)
|
||||
{
|
||||
change_selected(current_list, 1);
|
||||
}
|
||||
// Quick moving
|
||||
else if(kDown & KEY_LEFT)
|
||||
{
|
||||
if (splash_mode)
|
||||
{
|
||||
selected_splash -= 4;
|
||||
if (selected_splash < 0) selected_splash = 0;
|
||||
} else {
|
||||
selected_theme -= 4;
|
||||
if (selected_theme < 0) selected_theme = 0;
|
||||
}
|
||||
change_selected(current_list, -current_list->entries_per_screen_v);
|
||||
}
|
||||
else if(kDown & KEY_RIGHT)
|
||||
{
|
||||
if (splash_mode)
|
||||
{
|
||||
selected_splash += 4;
|
||||
if (selected_splash >= splash_count) selected_splash = splash_count-1;
|
||||
} else {
|
||||
selected_theme += 4;
|
||||
if (selected_theme >= theme_count) selected_theme = theme_count-1;
|
||||
}
|
||||
change_selected(current_list, current_list->entries_per_screen_v);
|
||||
}
|
||||
|
||||
// Fast scroll using circle pad
|
||||
else if(kHeld & KEY_CPAD_UP)
|
||||
{
|
||||
svcSleepThread(100000000);
|
||||
|
||||
if (splash_mode)
|
||||
{
|
||||
selected_splash--;
|
||||
if (selected_splash < 0)
|
||||
selected_splash = splash_count - 1;
|
||||
} else {
|
||||
selected_theme--;
|
||||
if (selected_theme < 0)
|
||||
selected_theme = theme_count - 1;
|
||||
}
|
||||
change_selected(current_list, -1);
|
||||
svcSleepThread(FASTSCROLL_WAIT);
|
||||
}
|
||||
else if(kHeld & KEY_CPAD_DOWN)
|
||||
{
|
||||
svcSleepThread(100000000);
|
||||
change_selected(current_list, 1);
|
||||
svcSleepThread(FASTSCROLL_WAIT);
|
||||
}
|
||||
else if(kHeld & KEY_CPAD_LEFT)
|
||||
{
|
||||
change_selected(current_list, -current_list->entries_per_screen_v);
|
||||
svcSleepThread(FASTSCROLL_WAIT);
|
||||
}
|
||||
else if(kHeld & KEY_CPAD_RIGHT)
|
||||
{
|
||||
change_selected(current_list, current_list->entries_per_screen_v);
|
||||
svcSleepThread(FASTSCROLL_WAIT);
|
||||
}
|
||||
|
||||
if (splash_mode)
|
||||
// Movement using the touchscreen
|
||||
touch:
|
||||
if((kDown | kHeld) & KEY_TOUCH)
|
||||
{
|
||||
selected_splash++;
|
||||
if (selected_splash >= splash_count)
|
||||
selected_splash = 0;
|
||||
} else {
|
||||
selected_theme++;
|
||||
if (selected_theme >= theme_count)
|
||||
selected_theme = 0;
|
||||
}
|
||||
}
|
||||
else if (kDown & KEY_CPAD_LEFT)
|
||||
{
|
||||
svcSleepThread(100000000);
|
||||
touchPosition touch = {0};
|
||||
hidTouchRead(&touch);
|
||||
|
||||
if (splash_mode)
|
||||
{
|
||||
selected_splash -= 4;
|
||||
if (selected_splash < 0) selected_splash = 0;
|
||||
} else {
|
||||
selected_theme -= 4;
|
||||
if (selected_theme < 0) selected_theme = 0;
|
||||
}
|
||||
}
|
||||
else if (kDown & KEY_CPAD_RIGHT)
|
||||
{
|
||||
svcSleepThread(100000000);
|
||||
u16 x = touch.px;
|
||||
u16 y = touch.py;
|
||||
|
||||
if (splash_mode)
|
||||
u16 arrowStartX = 152;
|
||||
u16 arrowEndX = arrowStartX+16;
|
||||
|
||||
#define BETWEEN(min, x, max) (min < x && x < max)
|
||||
|
||||
if(kDown & KEY_TOUCH)
|
||||
{
|
||||
selected_splash += 4;
|
||||
if (selected_splash >= splash_count) selected_splash = splash_count-1;
|
||||
} else {
|
||||
selected_theme += 4;
|
||||
if (selected_theme >= theme_count) selected_theme = theme_count-1;
|
||||
if(y < 24)
|
||||
{
|
||||
if(current_list->entries != NULL && BETWEEN(arrowStartX, x, arrowEndX) && current_list->scroll > 0)
|
||||
{
|
||||
change_selected(current_list, -current_list->entries_per_screen_v);
|
||||
}
|
||||
else if(BETWEEN(320-120, x, 320-96))
|
||||
{
|
||||
goto enable_qr;
|
||||
}
|
||||
else if(BETWEEN(320-96, x, 320-72))
|
||||
{
|
||||
goto browse_themeplaza;
|
||||
}
|
||||
else if(BETWEEN(320-72, x, 320-48))
|
||||
{
|
||||
quit = true;
|
||||
}
|
||||
else if(BETWEEN(320-48, x, 320-24))
|
||||
{
|
||||
goto toggle_preview;
|
||||
}
|
||||
else if(BETWEEN(320-24, x, 320))
|
||||
{
|
||||
goto switch_mode;
|
||||
}
|
||||
}
|
||||
else if(y >= 216)
|
||||
{
|
||||
if(current_list->entries != NULL && BETWEEN(arrowStartX, x, arrowEndX) && current_list->scroll < current_list->entries_count - current_list->entries_per_screen_v)
|
||||
{
|
||||
change_selected(current_list, current_list->entries_per_screen_v);
|
||||
}
|
||||
else if(current_list->entries != NULL && BETWEEN(176, x, 320))
|
||||
{
|
||||
goto jump;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(current_list->entries != NULL && BETWEEN(24, y, 216))
|
||||
{
|
||||
for(int i = 0; i < current_list->entries_loaded; i++)
|
||||
{
|
||||
u16 miny = 24 + current_list->entry_size*i;
|
||||
u16 maxy = miny + current_list->entry_size;
|
||||
if(BETWEEN(miny, y, maxy) && current_list->scroll + i < current_list->entries_count)
|
||||
{
|
||||
current_list->selected_entry = current_list->scroll + i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!splash_mode && selected_theme != previously_selected)
|
||||
{
|
||||
current_theme->has_preview = false;
|
||||
previously_selected = selected_theme;
|
||||
}
|
||||
}
|
||||
exit_screens();
|
||||
exit_services();
|
||||
|
||||
exit_function(true);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,137 +0,0 @@
|
||||
/* crypt.h -- base code for traditional PKWARE encryption
|
||||
Version 1.01e, February 12th, 2005
|
||||
|
||||
Copyright (C) 1998-2005 Gilles Vollant
|
||||
Modifications for Info-ZIP crypting
|
||||
Copyright (C) 2003 Terry Thorsen
|
||||
|
||||
This code is a modified version of crypting code in Info-ZIP distribution
|
||||
|
||||
Copyright (C) 1990-2000 Info-ZIP. All rights reserved.
|
||||
|
||||
See the Info-ZIP LICENSE file version 2000-Apr-09 or later for terms of use
|
||||
which also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html
|
||||
|
||||
The encryption/decryption parts of this source code (as opposed to the
|
||||
non-echoing password parts) were originally written in Europe. The
|
||||
whole source package can be freely distributed, including from the USA.
|
||||
(Prior to January 2000, re-export from the US was a violation of US law.)
|
||||
|
||||
This encryption code is a direct transcription of the algorithm from
|
||||
Roger Schlafly, described by Phil Katz in the file appnote.txt. This
|
||||
file (appnote.txt) is distributed with the PKZIP program (even in the
|
||||
version without encryption capabilities).
|
||||
|
||||
If you don't need crypting in your application, just define symbols
|
||||
NOCRYPT and NOUNCRYPT.
|
||||
|
||||
Mar 8th, 2016 - Lucio Cosmo
|
||||
Fixed support for 64bit builds for archives with "PKWARE" password.
|
||||
Changed long, unsigned long, unsigned to unsigned int in
|
||||
access functions to crctables and pkeys
|
||||
|
||||
*/
|
||||
|
||||
#define CRC32(c, b) ((*(pcrc_32_tab+(((unsigned int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8))
|
||||
|
||||
/***********************************************************************
|
||||
* Return the next byte in the pseudo-random sequence
|
||||
*/
|
||||
static int decrypt_byte(unsigned int* pkeys)
|
||||
{
|
||||
unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an
|
||||
* unpredictable manner on 16-bit systems; not a problem
|
||||
* with any known compiler so far, though */
|
||||
|
||||
temp = ((unsigned int)(*(pkeys+2)) & 0xffff) | 2;
|
||||
return (unsigned int)(((temp * (temp ^ 1)) >> 8) & 0xff);
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* Update the encryption keys with the next byte of plain text
|
||||
*/
|
||||
static int update_keys(unsigned int* pkeys,const unsigned int* pcrc_32_tab,int c)
|
||||
{
|
||||
(*(pkeys+0)) = CRC32((*(pkeys+0)), c);
|
||||
(*(pkeys+1)) += (*(pkeys+0)) & 0xff;
|
||||
(*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1;
|
||||
{
|
||||
register int keyshift = (int)((*(pkeys+1)) >> 24);
|
||||
(*(pkeys+2)) = CRC32((*(pkeys+2)), keyshift);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
* Initialize the encryption keys and the random header according to
|
||||
* the given password.
|
||||
*/
|
||||
static void init_keys(const char* passwd,unsigned int* pkeys,const unsigned int* pcrc_32_tab)
|
||||
{
|
||||
*(pkeys+0) = 305419896L;
|
||||
*(pkeys+1) = 591751049L;
|
||||
*(pkeys+2) = 878082192L;
|
||||
while (*passwd != 0)
|
||||
{
|
||||
update_keys(pkeys,pcrc_32_tab,(int)*passwd);
|
||||
passwd++;
|
||||
}
|
||||
}
|
||||
|
||||
#define zdecode(pkeys,pcrc_32_tab,c) \
|
||||
(update_keys(pkeys,pcrc_32_tab,c ^= decrypt_byte(pkeys)))
|
||||
|
||||
#define zencode(pkeys,pcrc_32_tab,c,t) \
|
||||
(t=decrypt_byte(pkeys), update_keys(pkeys,pcrc_32_tab,c), t^(c))
|
||||
|
||||
#ifdef INCLUDECRYPTINGCODE_IFCRYPTALLOWED
|
||||
|
||||
#define RAND_HEAD_LEN 12
|
||||
/* "last resort" source for second part of crypt seed pattern */
|
||||
# ifndef ZCR_SEED2
|
||||
# define ZCR_SEED2 3141592654UL /* use PI as default pattern */
|
||||
# endif
|
||||
|
||||
static int crypthead(const char* passwd, /* password string */
|
||||
unsigned char* buf, /* where to write header */
|
||||
int bufSize,
|
||||
unsigned int* pkeys,
|
||||
const unsigned int* pcrc_32_tab,
|
||||
unsigned int crcForCrypting)
|
||||
{
|
||||
int n; /* index in random header */
|
||||
int t; /* temporary */
|
||||
int c; /* random byte */
|
||||
unsigned char header[RAND_HEAD_LEN-2]; /* random header */
|
||||
static unsigned calls = 0; /* ensure different random header each time */
|
||||
|
||||
if (bufSize < RAND_HEAD_LEN)
|
||||
return 0;
|
||||
|
||||
/* First generate RAND_HEAD_LEN-2 random bytes. We encrypt the
|
||||
* output of rand() to get less predictability, since rand() is
|
||||
* often poorly implemented.
|
||||
*/
|
||||
if (++calls == 1)
|
||||
{
|
||||
srand((unsigned)(time(NULL) ^ ZCR_SEED2));
|
||||
}
|
||||
init_keys(passwd, pkeys, pcrc_32_tab);
|
||||
for (n = 0; n < RAND_HEAD_LEN-2; n++)
|
||||
{
|
||||
c = (rand() >> 7) & 0xff;
|
||||
header[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, c, t);
|
||||
}
|
||||
/* Encrypt random header (last two bytes is high word of crc) */
|
||||
init_keys(passwd, pkeys, pcrc_32_tab);
|
||||
for (n = 0; n < RAND_HEAD_LEN-2; n++)
|
||||
{
|
||||
buf[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, header[n], t);
|
||||
}
|
||||
buf[n++] = (unsigned char)zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 16) & 0xff, t);
|
||||
buf[n++] = (unsigned char)zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 24) & 0xff, t);
|
||||
return n;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,380 +0,0 @@
|
||||
/* ioapi.h -- IO base function header for compress/uncompress .zip
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 1998-2010 Gilles Vollant
|
||||
http://www.winimage.com/zLibDll/minizip.html
|
||||
Modifications for Zip64 support
|
||||
Copyright (C) 2009-2010 Mathias Svensson
|
||||
http://result42.com
|
||||
|
||||
This program is distributed under the terms of the same license as zlib.
|
||||
See the accompanying LICENSE file for the full text of the license.
|
||||
*/
|
||||
|
||||
//taken and adapted from https://stackoverflow.com/a/13492589
|
||||
|
||||
// save diagnostic state
|
||||
#pragma GCC diagnostic push
|
||||
|
||||
// turn off the specific warning. Can also use "-Wall"
|
||||
#pragma GCC diagnostic ignored "-Wunused-parameter"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "ioapi.h"
|
||||
|
||||
#if defined(_WIN32)
|
||||
# define snprintf _snprintf
|
||||
#endif
|
||||
|
||||
#ifdef __APPLE__
|
||||
/* In darwin and perhaps other BSD variants off_t is a 64 bit value, hence no need for specific 64 bit functions */
|
||||
# define FOPEN_FUNC(filename, mode) fopen(filename, mode)
|
||||
# define FTELLO_FUNC(stream) ftello(stream)
|
||||
# define FSEEKO_FUNC(stream, offset, origin) fseeko(stream, offset, origin)
|
||||
#else
|
||||
# define FOPEN_FUNC(filename, mode) fopen64(filename, mode)
|
||||
# define FTELLO_FUNC(stream) ftello64(stream)
|
||||
# define FSEEKO_FUNC(stream, offset, origin) fseeko64(stream, offset, origin)
|
||||
#endif
|
||||
|
||||
/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */
|
||||
#ifndef SEEK_CUR
|
||||
# define SEEK_CUR 1
|
||||
#endif
|
||||
#ifndef SEEK_END
|
||||
# define SEEK_END 2
|
||||
#endif
|
||||
#ifndef SEEK_SET
|
||||
# define SEEK_SET 0
|
||||
#endif
|
||||
|
||||
voidpf call_zopen64 (const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode)
|
||||
{
|
||||
if (pfilefunc->zfile_func64.zopen64_file != NULL)
|
||||
return (*(pfilefunc->zfile_func64.zopen64_file)) (pfilefunc->zfile_func64.opaque,filename,mode);
|
||||
return (*(pfilefunc->zopen32_file))(pfilefunc->zfile_func64.opaque,(const char*)filename,mode);
|
||||
}
|
||||
|
||||
voidpf call_zopendisk64 OF((const zlib_filefunc64_32_def* pfilefunc, voidpf filestream, int number_disk, int mode))
|
||||
{
|
||||
if (pfilefunc->zfile_func64.zopendisk64_file != NULL)
|
||||
return (*(pfilefunc->zfile_func64.zopendisk64_file)) (pfilefunc->zfile_func64.opaque,filestream,number_disk,mode);
|
||||
return (*(pfilefunc->zopendisk32_file))(pfilefunc->zfile_func64.opaque,filestream,number_disk,mode);
|
||||
}
|
||||
|
||||
long call_zseek64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin)
|
||||
{
|
||||
uLong offsetTruncated;
|
||||
if (pfilefunc->zfile_func64.zseek64_file != NULL)
|
||||
return (*(pfilefunc->zfile_func64.zseek64_file)) (pfilefunc->zfile_func64.opaque,filestream,offset,origin);
|
||||
offsetTruncated = (uLong)offset;
|
||||
if (offsetTruncated != offset)
|
||||
return -1;
|
||||
return (*(pfilefunc->zseek32_file))(pfilefunc->zfile_func64.opaque,filestream,offsetTruncated,origin);
|
||||
}
|
||||
|
||||
ZPOS64_T call_ztell64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream)
|
||||
{
|
||||
uLong tell_uLong;
|
||||
if (pfilefunc->zfile_func64.zseek64_file != NULL)
|
||||
return (*(pfilefunc->zfile_func64.ztell64_file)) (pfilefunc->zfile_func64.opaque,filestream);
|
||||
tell_uLong = (*(pfilefunc->ztell32_file))(pfilefunc->zfile_func64.opaque,filestream);
|
||||
if ((tell_uLong) == 0xffffffff)
|
||||
return (ZPOS64_T)-1;
|
||||
return tell_uLong;
|
||||
}
|
||||
|
||||
void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32)
|
||||
{
|
||||
p_filefunc64_32->zfile_func64.zopen64_file = NULL;
|
||||
p_filefunc64_32->zfile_func64.zopendisk64_file = NULL;
|
||||
p_filefunc64_32->zopen32_file = p_filefunc32->zopen_file;
|
||||
p_filefunc64_32->zopendisk32_file = p_filefunc32->zopendisk_file;
|
||||
p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file;
|
||||
p_filefunc64_32->zfile_func64.zread_file = p_filefunc32->zread_file;
|
||||
p_filefunc64_32->zfile_func64.zwrite_file = p_filefunc32->zwrite_file;
|
||||
p_filefunc64_32->zfile_func64.ztell64_file = NULL;
|
||||
p_filefunc64_32->zfile_func64.zseek64_file = NULL;
|
||||
p_filefunc64_32->zfile_func64.zclose_file = p_filefunc32->zclose_file;
|
||||
p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file;
|
||||
p_filefunc64_32->zfile_func64.opaque = p_filefunc32->opaque;
|
||||
p_filefunc64_32->zseek32_file = p_filefunc32->zseek_file;
|
||||
p_filefunc64_32->ztell32_file = p_filefunc32->ztell_file;
|
||||
}
|
||||
|
||||
static voidpf ZCALLBACK fopen_file_func OF((voidpf opaque, const char* filename, int mode));
|
||||
static uLong ZCALLBACK fread_file_func OF((voidpf opaque, voidpf stream, void* buf, uLong size));
|
||||
static uLong ZCALLBACK fwrite_file_func OF((voidpf opaque, voidpf stream, const void* buf,uLong size));
|
||||
static ZPOS64_T ZCALLBACK ftell64_file_func OF((voidpf opaque, voidpf stream));
|
||||
static long ZCALLBACK fseek64_file_func OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin));
|
||||
static int ZCALLBACK fclose_file_func OF((voidpf opaque, voidpf stream));
|
||||
static int ZCALLBACK ferror_file_func OF((voidpf opaque, voidpf stream));
|
||||
|
||||
typedef struct
|
||||
{
|
||||
FILE *file;
|
||||
int filenameLength;
|
||||
void *filename;
|
||||
} FILE_IOPOSIX;
|
||||
|
||||
static voidpf file_build_ioposix(FILE *file, const char *filename)
|
||||
{
|
||||
FILE_IOPOSIX *ioposix = NULL;
|
||||
if (file == NULL)
|
||||
return NULL;
|
||||
ioposix = (FILE_IOPOSIX*)malloc(sizeof(FILE_IOPOSIX));
|
||||
ioposix->file = file;
|
||||
ioposix->filenameLength = strlen(filename) + 1;
|
||||
ioposix->filename = (char*)malloc(ioposix->filenameLength * sizeof(char));
|
||||
strncpy(ioposix->filename, filename, ioposix->filenameLength);
|
||||
return (voidpf)ioposix;
|
||||
}
|
||||
|
||||
static voidpf ZCALLBACK fopen_file_func (voidpf opaque, const char* filename, int mode)
|
||||
{
|
||||
FILE* file = NULL;
|
||||
const char* mode_fopen = NULL;
|
||||
if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER) == ZLIB_FILEFUNC_MODE_READ)
|
||||
mode_fopen = "rb";
|
||||
else if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
|
||||
mode_fopen = "r+b";
|
||||
else if (mode & ZLIB_FILEFUNC_MODE_CREATE)
|
||||
mode_fopen = "wb";
|
||||
|
||||
if ((filename != NULL) && (mode_fopen != NULL))
|
||||
{
|
||||
file = fopen(filename, mode_fopen);
|
||||
return file_build_ioposix(file, filename);
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
static voidpf ZCALLBACK fopen64_file_func (voidpf opaque, const void* filename, int mode)
|
||||
{
|
||||
FILE* file = NULL;
|
||||
const char* mode_fopen = NULL;
|
||||
if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER) == ZLIB_FILEFUNC_MODE_READ)
|
||||
mode_fopen = "rb";
|
||||
else if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
|
||||
mode_fopen = "r+b";
|
||||
else if (mode & ZLIB_FILEFUNC_MODE_CREATE)
|
||||
mode_fopen = "wb";
|
||||
|
||||
if ((filename != NULL) && (mode_fopen != NULL))
|
||||
{
|
||||
file = FOPEN_FUNC((const char*)filename, mode_fopen);
|
||||
return file_build_ioposix(file, (const char*)filename);
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
static voidpf ZCALLBACK fopendisk64_file_func (voidpf opaque, voidpf stream, int number_disk, int mode)
|
||||
{
|
||||
FILE_IOPOSIX *ioposix = NULL;
|
||||
char *diskFilename = NULL;
|
||||
voidpf ret = NULL;
|
||||
int i = 0;
|
||||
|
||||
if (stream == NULL)
|
||||
return NULL;
|
||||
ioposix = (FILE_IOPOSIX*)stream;
|
||||
diskFilename = (char*)malloc(ioposix->filenameLength * sizeof(char));
|
||||
strncpy(diskFilename, ioposix->filename, ioposix->filenameLength);
|
||||
for (i = ioposix->filenameLength - 1; i >= 0; i -= 1)
|
||||
{
|
||||
if (diskFilename[i] != '.')
|
||||
continue;
|
||||
snprintf(&diskFilename[i], ioposix->filenameLength - i, ".z%02d", number_disk + 1);
|
||||
break;
|
||||
}
|
||||
if (i >= 0)
|
||||
ret = fopen64_file_func(opaque, diskFilename, mode);
|
||||
free(diskFilename);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static voidpf ZCALLBACK fopendisk_file_func (voidpf opaque, voidpf stream, int number_disk, int mode)
|
||||
{
|
||||
FILE_IOPOSIX *ioposix = NULL;
|
||||
char *diskFilename = NULL;
|
||||
voidpf ret = NULL;
|
||||
int i = 0;
|
||||
|
||||
if (stream == NULL)
|
||||
return NULL;
|
||||
ioposix = (FILE_IOPOSIX*)stream;
|
||||
diskFilename = (char*)malloc(ioposix->filenameLength * sizeof(char));
|
||||
strncpy(diskFilename, ioposix->filename, ioposix->filenameLength);
|
||||
for (i = ioposix->filenameLength - 1; i >= 0; i -= 1)
|
||||
{
|
||||
if (diskFilename[i] != '.')
|
||||
continue;
|
||||
snprintf(&diskFilename[i], ioposix->filenameLength - i, ".z%02d", number_disk + 1);
|
||||
break;
|
||||
}
|
||||
if (i >= 0)
|
||||
ret = fopen_file_func(opaque, diskFilename, mode);
|
||||
free(diskFilename);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static uLong ZCALLBACK fread_file_func (voidpf opaque, voidpf stream, void* buf, uLong size)
|
||||
{
|
||||
FILE_IOPOSIX *ioposix = NULL;
|
||||
uLong ret;
|
||||
if (stream == NULL)
|
||||
return -1;
|
||||
ioposix = (FILE_IOPOSIX*)stream;
|
||||
ret = (uLong)fread(buf, 1, (size_t)size, ioposix->file);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static uLong ZCALLBACK fwrite_file_func (voidpf opaque, voidpf stream, const void* buf, uLong size)
|
||||
{
|
||||
FILE_IOPOSIX *ioposix = NULL;
|
||||
uLong ret;
|
||||
if (stream == NULL)
|
||||
return -1;
|
||||
ioposix = (FILE_IOPOSIX*)stream;
|
||||
ret = (uLong)fwrite(buf, 1, (size_t)size, ioposix->file);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static long ZCALLBACK ftell_file_func (voidpf opaque, voidpf stream)
|
||||
{
|
||||
FILE_IOPOSIX *ioposix = NULL;
|
||||
long ret = -1;
|
||||
if (stream == NULL)
|
||||
return ret;
|
||||
ioposix = (FILE_IOPOSIX*)stream;
|
||||
ret = ftell(ioposix->file);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static ZPOS64_T ZCALLBACK ftell64_file_func (voidpf opaque, voidpf stream)
|
||||
{
|
||||
FILE_IOPOSIX *ioposix = NULL;
|
||||
ZPOS64_T ret = -1;
|
||||
if (stream == NULL)
|
||||
return ret;
|
||||
ioposix = (FILE_IOPOSIX*)stream;
|
||||
ret = FTELLO_FUNC(ioposix->file);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static long ZCALLBACK fseek_file_func (voidpf opaque, voidpf stream, uLong offset, int origin)
|
||||
{
|
||||
FILE_IOPOSIX *ioposix = NULL;
|
||||
int fseek_origin = 0;
|
||||
long ret = 0;
|
||||
|
||||
if (stream == NULL)
|
||||
return -1;
|
||||
ioposix = (FILE_IOPOSIX*)stream;
|
||||
|
||||
switch (origin)
|
||||
{
|
||||
case ZLIB_FILEFUNC_SEEK_CUR:
|
||||
fseek_origin = SEEK_CUR;
|
||||
break;
|
||||
case ZLIB_FILEFUNC_SEEK_END:
|
||||
fseek_origin = SEEK_END;
|
||||
break;
|
||||
case ZLIB_FILEFUNC_SEEK_SET:
|
||||
fseek_origin = SEEK_SET;
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
if (fseek(ioposix->file, offset, fseek_origin) != 0)
|
||||
ret = -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static long ZCALLBACK fseek64_file_func (voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)
|
||||
{
|
||||
FILE_IOPOSIX *ioposix = NULL;
|
||||
int fseek_origin = 0;
|
||||
long ret = 0;
|
||||
|
||||
if (stream == NULL)
|
||||
return -1;
|
||||
ioposix = (FILE_IOPOSIX*)stream;
|
||||
|
||||
switch (origin)
|
||||
{
|
||||
case ZLIB_FILEFUNC_SEEK_CUR:
|
||||
fseek_origin = SEEK_CUR;
|
||||
break;
|
||||
case ZLIB_FILEFUNC_SEEK_END:
|
||||
fseek_origin = SEEK_END;
|
||||
break;
|
||||
case ZLIB_FILEFUNC_SEEK_SET:
|
||||
fseek_origin = SEEK_SET;
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(FSEEKO_FUNC(ioposix->file, offset, fseek_origin) != 0)
|
||||
ret = -1;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static int ZCALLBACK fclose_file_func (voidpf opaque, voidpf stream)
|
||||
{
|
||||
FILE_IOPOSIX *ioposix = NULL;
|
||||
int ret = -1;
|
||||
if (stream == NULL)
|
||||
return ret;
|
||||
ioposix = (FILE_IOPOSIX*)stream;
|
||||
if (ioposix->filename != NULL)
|
||||
free(ioposix->filename);
|
||||
ret = fclose(ioposix->file);
|
||||
free(ioposix);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int ZCALLBACK ferror_file_func (voidpf opaque, voidpf stream)
|
||||
{
|
||||
FILE_IOPOSIX *ioposix = NULL;
|
||||
int ret = -1;
|
||||
if (stream == NULL)
|
||||
return ret;
|
||||
ioposix = (FILE_IOPOSIX*)stream;
|
||||
ret = ferror(ioposix->file);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void fill_fopen_filefunc (zlib_filefunc_def* pzlib_filefunc_def)
|
||||
{
|
||||
pzlib_filefunc_def->zopen_file = fopen_file_func;
|
||||
pzlib_filefunc_def->zopendisk_file = fopendisk_file_func;
|
||||
pzlib_filefunc_def->zread_file = fread_file_func;
|
||||
pzlib_filefunc_def->zwrite_file = fwrite_file_func;
|
||||
pzlib_filefunc_def->ztell_file = ftell_file_func;
|
||||
pzlib_filefunc_def->zseek_file = fseek_file_func;
|
||||
pzlib_filefunc_def->zclose_file = fclose_file_func;
|
||||
pzlib_filefunc_def->zerror_file = ferror_file_func;
|
||||
pzlib_filefunc_def->opaque = NULL;
|
||||
}
|
||||
|
||||
void fill_fopen64_filefunc (zlib_filefunc64_def* pzlib_filefunc_def)
|
||||
{
|
||||
pzlib_filefunc_def->zopen64_file = fopen64_file_func;
|
||||
pzlib_filefunc_def->zopendisk64_file = fopendisk64_file_func;
|
||||
pzlib_filefunc_def->zread_file = fread_file_func;
|
||||
pzlib_filefunc_def->zwrite_file = fwrite_file_func;
|
||||
pzlib_filefunc_def->ztell64_file = ftell64_file_func;
|
||||
pzlib_filefunc_def->zseek64_file = fseek64_file_func;
|
||||
pzlib_filefunc_def->zclose_file = fclose_file_func;
|
||||
pzlib_filefunc_def->zerror_file = ferror_file_func;
|
||||
pzlib_filefunc_def->opaque = NULL;
|
||||
}
|
||||
|
||||
// turn the warnings back on
|
||||
#pragma GCC diagnostic pop
|
||||
@@ -1,158 +0,0 @@
|
||||
/* ioapi.h -- IO base function header for compress/uncompress .zip
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 1998-2010 Gilles Vollant
|
||||
http://www.winimage.com/zLibDll/minizip.html
|
||||
Modifications for Zip64 support
|
||||
Copyright (C) 2009-2010 Mathias Svensson
|
||||
http://result42.com
|
||||
|
||||
This program is distributed under the terms of the same license as zlib.
|
||||
See the accompanying LICENSE file for the full text of the license.
|
||||
*/
|
||||
|
||||
#ifndef _ZLIBIOAPI64_H
|
||||
#define _ZLIBIOAPI64_H
|
||||
|
||||
#if (!defined(_WIN32)) && (!defined(WIN32)) && (!defined(__APPLE__))
|
||||
# ifndef __USE_FILE_OFFSET64
|
||||
# define __USE_FILE_OFFSET64
|
||||
# endif
|
||||
# ifndef __USE_LARGEFILE64
|
||||
# define __USE_LARGEFILE64
|
||||
# endif
|
||||
# ifndef _LARGEFILE64_SOURCE
|
||||
# define _LARGEFILE64_SOURCE
|
||||
# endif
|
||||
# ifndef _FILE_OFFSET_BIT
|
||||
# define _FILE_OFFSET_BIT 64
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <zlib.h>
|
||||
|
||||
|
||||
#define fopen64 fopen
|
||||
#define ftello64 ftell
|
||||
#define fseeko64 fseek
|
||||
|
||||
/* a type choosen by DEFINE */
|
||||
#ifdef HAVE_64BIT_INT_CUSTOM
|
||||
typedef 64BIT_INT_CUSTOM_TYPE ZPOS64_T;
|
||||
#else
|
||||
# ifdef HAVE_STDINT_H
|
||||
# include "stdint.h"
|
||||
typedef uint64_t ZPOS64_T;
|
||||
# else
|
||||
# if defined(_MSC_VER) || defined(__BORLANDC__)
|
||||
typedef unsigned __int64 ZPOS64_T;
|
||||
# else
|
||||
typedef unsigned long long int ZPOS64_T;
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define ZLIB_FILEFUNC_SEEK_CUR (1)
|
||||
#define ZLIB_FILEFUNC_SEEK_END (2)
|
||||
#define ZLIB_FILEFUNC_SEEK_SET (0)
|
||||
|
||||
#define ZLIB_FILEFUNC_MODE_READ (1)
|
||||
#define ZLIB_FILEFUNC_MODE_WRITE (2)
|
||||
#define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3)
|
||||
#define ZLIB_FILEFUNC_MODE_EXISTING (4)
|
||||
#define ZLIB_FILEFUNC_MODE_CREATE (8)
|
||||
|
||||
#ifndef ZCALLBACK
|
||||
# if (defined(WIN32) || defined(_WIN32) || defined (WINDOWS) || \
|
||||
defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK)
|
||||
# define ZCALLBACK CALLBACK
|
||||
# else
|
||||
# define ZCALLBACK
|
||||
# endif
|
||||
#endif
|
||||
|
||||
typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode));
|
||||
typedef voidpf (ZCALLBACK *opendisk_file_func) OF((voidpf opaque, voidpf stream, int number_disk, int mode));
|
||||
typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size));
|
||||
typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size));
|
||||
typedef int (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream));
|
||||
typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream));
|
||||
|
||||
typedef long (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream));
|
||||
typedef long (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin));
|
||||
|
||||
/* here is the "old" 32 bits structure structure */
|
||||
typedef struct zlib_filefunc_def_s
|
||||
{
|
||||
open_file_func zopen_file;
|
||||
opendisk_file_func zopendisk_file;
|
||||
read_file_func zread_file;
|
||||
write_file_func zwrite_file;
|
||||
tell_file_func ztell_file;
|
||||
seek_file_func zseek_file;
|
||||
close_file_func zclose_file;
|
||||
testerror_file_func zerror_file;
|
||||
voidpf opaque;
|
||||
} zlib_filefunc_def;
|
||||
|
||||
typedef ZPOS64_T (ZCALLBACK *tell64_file_func) OF((voidpf opaque, voidpf stream));
|
||||
typedef long (ZCALLBACK *seek64_file_func) OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin));
|
||||
typedef voidpf (ZCALLBACK *open64_file_func) OF((voidpf opaque, const void* filename, int mode));
|
||||
typedef voidpf (ZCALLBACK *opendisk64_file_func)OF((voidpf opaque, voidpf stream, int number_disk, int mode));
|
||||
|
||||
typedef struct zlib_filefunc64_def_s
|
||||
{
|
||||
open64_file_func zopen64_file;
|
||||
opendisk64_file_func zopendisk64_file;
|
||||
read_file_func zread_file;
|
||||
write_file_func zwrite_file;
|
||||
tell64_file_func ztell64_file;
|
||||
seek64_file_func zseek64_file;
|
||||
close_file_func zclose_file;
|
||||
testerror_file_func zerror_file;
|
||||
voidpf opaque;
|
||||
} zlib_filefunc64_def;
|
||||
|
||||
void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def));
|
||||
void fill_fopen64_filefunc OF((zlib_filefunc64_def* pzlib_filefunc_def));
|
||||
|
||||
/* now internal definition, only for zip.c and unzip.h */
|
||||
typedef struct zlib_filefunc64_32_def_s
|
||||
{
|
||||
zlib_filefunc64_def zfile_func64;
|
||||
open_file_func zopen32_file;
|
||||
opendisk_file_func zopendisk32_file;
|
||||
tell_file_func ztell32_file;
|
||||
seek_file_func zseek32_file;
|
||||
} zlib_filefunc64_32_def;
|
||||
|
||||
#define ZREAD64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zread_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size))
|
||||
#define ZWRITE64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zwrite_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size))
|
||||
/*#define ZTELL64(filefunc,filestream) ((*((filefunc).ztell64_file)) ((filefunc).opaque,filestream))*/
|
||||
/*#define ZSEEK64(filefunc,filestream,pos,mode) ((*((filefunc).zseek64_file)) ((filefunc).opaque,filestream,pos,mode))*/
|
||||
#define ZCLOSE64(filefunc,filestream) ((*((filefunc).zfile_func64.zclose_file)) ((filefunc).zfile_func64.opaque,filestream))
|
||||
#define ZERROR64(filefunc,filestream) ((*((filefunc).zfile_func64.zerror_file)) ((filefunc).zfile_func64.opaque,filestream))
|
||||
|
||||
voidpf call_zopen64 OF((const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode));
|
||||
voidpf call_zopendisk64 OF((const zlib_filefunc64_32_def* pfilefunc, voidpf filestream, int number_disk, int mode));
|
||||
long call_zseek64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin));
|
||||
ZPOS64_T call_ztell64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream));
|
||||
|
||||
void fill_zlib_filefunc64_32_def_from_filefunc32 OF((zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32));
|
||||
|
||||
#define ZOPEN64(filefunc,filename,mode) (call_zopen64((&(filefunc)),(filename),(mode)))
|
||||
#define ZOPENDISK64(filefunc,filestream,diskn,mode) (call_zopendisk64((&(filefunc)),(filestream),(diskn),(mode)))
|
||||
#define ZTELL64(filefunc,filestream) (call_ztell64((&(filefunc)),(filestream)))
|
||||
#define ZSEEK64(filefunc,filestream,pos,mode) (call_zseek64((&(filefunc)),(filestream),(pos),(mode)))
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,202 +0,0 @@
|
||||
/* ioapi_mem.h -- IO base function header for compress/uncompress .zip
|
||||
files using zlib + zip or unzip API
|
||||
|
||||
This version of ioapi is designed to access memory rather than files.
|
||||
We do use a region of memory to put data in to and take it out of. We do
|
||||
not have auto-extending buffers and do not inform anyone else that the
|
||||
data has been written. It is really intended for accessing a zip archive
|
||||
embedded in an application such that I can write an installer with no
|
||||
external files. Creation of archives has not been attempted, although
|
||||
parts of the framework are present.
|
||||
|
||||
Based on Unzip ioapi.c version 0.22, May 19th, 2003
|
||||
|
||||
Copyright (C) 1998-2003 Gilles Vollant
|
||||
(C) 2003 Justin Fletcher
|
||||
|
||||
This file is under the same license as the Unzip tool it is distributed
|
||||
with.
|
||||
*/
|
||||
|
||||
//taken and adapted from https://stackoverflow.com/a/13492589
|
||||
|
||||
// save diagnostic state
|
||||
#pragma GCC diagnostic push
|
||||
|
||||
// turn off the specific warning. Can also use "-Wall"
|
||||
#pragma GCC diagnostic ignored "-Wunused-parameter"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "zlib.h"
|
||||
#include "ioapi.h"
|
||||
|
||||
#include "ioapi_mem.h"
|
||||
|
||||
#ifndef IOMEM_BUFFERSIZE
|
||||
# define IOMEM_BUFFERSIZE (64 * 1024)
|
||||
#endif
|
||||
|
||||
voidpf ZCALLBACK fopen_mem_func (opaque, filename, mode)
|
||||
voidpf opaque;
|
||||
const char* filename;
|
||||
int mode;
|
||||
{
|
||||
ourmemory_t *mem = (ourmemory_t *)opaque;
|
||||
if (mem == NULL)
|
||||
return NULL; /* Mem structure passed in was null */
|
||||
|
||||
if (mode & ZLIB_FILEFUNC_MODE_CREATE)
|
||||
{
|
||||
if (mem->grow)
|
||||
{
|
||||
mem->size = IOMEM_BUFFERSIZE;
|
||||
mem->base = (char *)malloc(mem->size);
|
||||
}
|
||||
|
||||
mem->limit = 0; /* When writing we start with 0 bytes written */
|
||||
}
|
||||
else
|
||||
mem->limit = mem->size;
|
||||
|
||||
mem->cur_offset = 0;
|
||||
|
||||
return mem;
|
||||
}
|
||||
|
||||
voidpf ZCALLBACK fopendisk_mem_func (opaque, stream, number_disk, mode)
|
||||
voidpf opaque;
|
||||
voidpf stream;
|
||||
int number_disk;
|
||||
int mode;
|
||||
{
|
||||
/* Not used */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
uLong ZCALLBACK fread_mem_func (opaque, stream, buf, size)
|
||||
voidpf opaque;
|
||||
voidpf stream;
|
||||
void* buf;
|
||||
uLong size;
|
||||
{
|
||||
ourmemory_t *mem = (ourmemory_t *)stream;
|
||||
|
||||
if (size > mem->size - mem->cur_offset)
|
||||
size = mem->size - mem->cur_offset;
|
||||
|
||||
memcpy(buf, mem->base + mem->cur_offset, size);
|
||||
mem->cur_offset += size;
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
|
||||
uLong ZCALLBACK fwrite_mem_func (opaque, stream, buf, size)
|
||||
voidpf opaque;
|
||||
voidpf stream;
|
||||
const void* buf;
|
||||
uLong size;
|
||||
{
|
||||
ourmemory_t *mem = (ourmemory_t *)stream;
|
||||
char *newbase = NULL;
|
||||
uLong newmemsize = 0;
|
||||
|
||||
if (size > mem->size - mem->cur_offset)
|
||||
{
|
||||
if (mem->grow)
|
||||
{
|
||||
newmemsize = mem->size;
|
||||
if (size < IOMEM_BUFFERSIZE)
|
||||
newmemsize += IOMEM_BUFFERSIZE;
|
||||
else
|
||||
newmemsize += size;
|
||||
newbase = (char *)malloc(newmemsize);
|
||||
memcpy(newbase, mem->base, mem->size);
|
||||
free(mem->base);
|
||||
mem->base = newbase;
|
||||
mem->size = newmemsize;
|
||||
}
|
||||
else
|
||||
size = mem->size - mem->cur_offset;
|
||||
}
|
||||
memcpy(mem->base + mem->cur_offset, buf, size);
|
||||
mem->cur_offset += size;
|
||||
if (mem->cur_offset > mem->limit)
|
||||
mem->limit = mem->cur_offset;
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
long ZCALLBACK ftell_mem_func (opaque, stream)
|
||||
voidpf opaque;
|
||||
voidpf stream;
|
||||
{
|
||||
ourmemory_t *mem = (ourmemory_t *)stream;
|
||||
return mem->cur_offset;
|
||||
}
|
||||
|
||||
long ZCALLBACK fseek_mem_func (opaque, stream, offset, origin)
|
||||
voidpf opaque;
|
||||
voidpf stream;
|
||||
uLong offset;
|
||||
int origin;
|
||||
{
|
||||
ourmemory_t *mem = (ourmemory_t *)stream;
|
||||
uLong new_pos;
|
||||
switch (origin)
|
||||
{
|
||||
case ZLIB_FILEFUNC_SEEK_CUR:
|
||||
new_pos = mem->cur_offset + offset;
|
||||
break;
|
||||
case ZLIB_FILEFUNC_SEEK_END:
|
||||
new_pos = mem->limit + offset;
|
||||
break;
|
||||
case ZLIB_FILEFUNC_SEEK_SET:
|
||||
new_pos = offset;
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (new_pos > mem->size)
|
||||
return 1; /* Failed to seek that far */
|
||||
mem->cur_offset = new_pos;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ZCALLBACK fclose_mem_func (opaque, stream)
|
||||
voidpf opaque;
|
||||
voidpf stream;
|
||||
{
|
||||
/* Even with grow = 1, caller must always free() memory */
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ZCALLBACK ferror_mem_func (opaque, stream)
|
||||
voidpf opaque;
|
||||
voidpf stream;
|
||||
{
|
||||
/* We never return errors */
|
||||
return 0;
|
||||
}
|
||||
|
||||
void fill_memory_filefunc (pzlib_filefunc_def, ourmem)
|
||||
zlib_filefunc_def* pzlib_filefunc_def;
|
||||
ourmemory_t *ourmem;
|
||||
{
|
||||
pzlib_filefunc_def->zopen_file = fopen_mem_func;
|
||||
pzlib_filefunc_def->zopendisk_file = fopendisk_mem_func;
|
||||
pzlib_filefunc_def->zread_file = fread_mem_func;
|
||||
pzlib_filefunc_def->zwrite_file = fwrite_mem_func;
|
||||
pzlib_filefunc_def->ztell_file = ftell_mem_func;
|
||||
pzlib_filefunc_def->zseek_file = fseek_mem_func;
|
||||
pzlib_filefunc_def->zclose_file = fclose_mem_func;
|
||||
pzlib_filefunc_def->zerror_file = ferror_mem_func;
|
||||
pzlib_filefunc_def->opaque = ourmem;
|
||||
}
|
||||
|
||||
// turn the warnings back on
|
||||
#pragma GCC diagnostic pop
|
||||
@@ -1,51 +0,0 @@
|
||||
/* ioapi_mem.h -- IO base function header for compress/uncompress .zip
|
||||
files using zlib + zip or unzip API
|
||||
|
||||
This version of ioapi is designed to access memory rather than files.
|
||||
We do use a region of memory to put data in to and take it out of.
|
||||
|
||||
Copyright (C) 1998-2003 Gilles Vollant
|
||||
(C) 2003 Justin Fletcher
|
||||
|
||||
This program is distributed under the terms of the same license as zlib.
|
||||
See the accompanying LICENSE file for the full text of the license.
|
||||
*/
|
||||
|
||||
#ifndef _IOAPI_MEM_H
|
||||
#define _IOAPI_MEM_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "zlib.h"
|
||||
#include "ioapi.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
voidpf ZCALLBACK fopen_mem_func OF((voidpf opaque,const char* filename,int mode));
|
||||
voidpf ZCALLBACK fopendisk_mem_func OF((voidpf opaque, voidpf stream, int number_disk, int mode));
|
||||
uLong ZCALLBACK fread_mem_func OF((voidpf opaque,voidpf stream,void* buf,uLong size));
|
||||
uLong ZCALLBACK fwrite_mem_func OF((voidpf opaque,voidpf stream,const void* buf,uLong size));
|
||||
long ZCALLBACK ftell_mem_func OF((voidpf opaque,voidpf stream));
|
||||
long ZCALLBACK fseek_mem_func OF((voidpf opaque,voidpf stream,uLong offset,int origin));
|
||||
int ZCALLBACK fclose_mem_func OF((voidpf opaque,voidpf stream));
|
||||
int ZCALLBACK ferror_mem_func OF((voidpf opaque,voidpf stream));
|
||||
|
||||
typedef struct ourmemory_s {
|
||||
char *base; /* Base of the region of memory we're using */
|
||||
uLong size; /* Size of the region of memory we're using */
|
||||
uLong limit; /* Furthest we've written */
|
||||
uLong cur_offset; /* Current offset in the area */
|
||||
int grow; /* Growable memory buffer */
|
||||
} ourmemory_t;
|
||||
|
||||
void fill_memory_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def, ourmemory_t *ourmem));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,320 +0,0 @@
|
||||
/* unzip.h -- IO for uncompress .zip files using zlib
|
||||
Version 1.1, February 14h, 2010
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 1998-2010 Gilles Vollant
|
||||
http://www.winimage.com/zLibDll/minizip.html
|
||||
Modifications of Unzip for Zip64
|
||||
Copyright (C) 2007-2008 Even Rouault
|
||||
Modifications for Zip64 support on both zip and unzip
|
||||
Copyright (C) 2009-2010 Mathias Svensson
|
||||
http://result42.com
|
||||
|
||||
This program is distributed under the terms of the same license as zlib.
|
||||
See the accompanying LICENSE file for the full text of the license.
|
||||
*/
|
||||
|
||||
#ifndef _UNZ_H
|
||||
#define _UNZ_H
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef _ZLIB_H
|
||||
#include <zlib.h>
|
||||
#endif
|
||||
|
||||
#ifndef _ZLIBIOAPI_H
|
||||
#include "ioapi.h"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_BZIP2
|
||||
#include "bzlib.h"
|
||||
#endif
|
||||
|
||||
#define Z_BZIP2ED 12
|
||||
|
||||
#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
|
||||
/* like the STRICT of WIN32, we define a pointer that cannot be converted
|
||||
from (void*) without cast */
|
||||
typedef struct TagunzFile__ { int unused; } unzFile__;
|
||||
typedef unzFile__ *unzFile;
|
||||
#else
|
||||
typedef voidp unzFile;
|
||||
#endif
|
||||
|
||||
#define UNZ_OK (0)
|
||||
#define UNZ_END_OF_LIST_OF_FILE (-100)
|
||||
#define UNZ_ERRNO (Z_ERRNO)
|
||||
#define UNZ_EOF (0)
|
||||
#define UNZ_PARAMERROR (-102)
|
||||
#define UNZ_BADZIPFILE (-103)
|
||||
#define UNZ_INTERNALERROR (-104)
|
||||
#define UNZ_CRCERROR (-105)
|
||||
|
||||
/* tm_unz contain date/time info */
|
||||
typedef struct tm_unz_s
|
||||
{
|
||||
uInt tm_sec; /* seconds after the minute - [0,59] */
|
||||
uInt tm_min; /* minutes after the hour - [0,59] */
|
||||
uInt tm_hour; /* hours since midnight - [0,23] */
|
||||
uInt tm_mday; /* day of the month - [1,31] */
|
||||
uInt tm_mon; /* months since January - [0,11] */
|
||||
uInt tm_year; /* years - [1980..2044] */
|
||||
} tm_unz;
|
||||
|
||||
/* unz_global_info structure contain global data about the ZIPfile
|
||||
These data comes from the end of central dir */
|
||||
typedef struct unz_global_info64_s
|
||||
{
|
||||
ZPOS64_T number_entry; /* total number of entries in the central dir on this disk */
|
||||
uLong number_disk_with_CD; /* number the the disk with central dir, used for spanning ZIP*/
|
||||
uLong size_comment; /* size of the global comment of the zipfile */
|
||||
} unz_global_info64;
|
||||
|
||||
typedef struct unz_global_info_s
|
||||
{
|
||||
uLong number_entry; /* total number of entries in the central dir on this disk */
|
||||
uLong number_disk_with_CD; /* number the the disk with central dir, used for spanning ZIP*/
|
||||
uLong size_comment; /* size of the global comment of the zipfile */
|
||||
} unz_global_info;
|
||||
|
||||
/* unz_file_info contain information about a file in the zipfile */
|
||||
typedef struct unz_file_info64_s
|
||||
{
|
||||
uLong version; /* version made by 2 bytes */
|
||||
uLong version_needed; /* version needed to extract 2 bytes */
|
||||
uLong flag; /* general purpose bit flag 2 bytes */
|
||||
uLong compression_method; /* compression method 2 bytes */
|
||||
uLong dosDate; /* last mod file date in Dos fmt 4 bytes */
|
||||
uLong crc; /* crc-32 4 bytes */
|
||||
ZPOS64_T compressed_size; /* compressed size 8 bytes */
|
||||
ZPOS64_T uncompressed_size; /* uncompressed size 8 bytes */
|
||||
uLong size_filename; /* filename length 2 bytes */
|
||||
uLong size_file_extra; /* extra field length 2 bytes */
|
||||
uLong size_file_comment; /* file comment length 2 bytes */
|
||||
|
||||
uLong disk_num_start; /* disk number start 2 bytes */
|
||||
uLong internal_fa; /* internal file attributes 2 bytes */
|
||||
uLong external_fa; /* external file attributes 4 bytes */
|
||||
|
||||
tm_unz tmu_date;
|
||||
ZPOS64_T disk_offset;
|
||||
uLong size_file_extra_internal;
|
||||
} unz_file_info64;
|
||||
|
||||
typedef struct unz_file_info_s
|
||||
{
|
||||
uLong version; /* version made by 2 bytes */
|
||||
uLong version_needed; /* version needed to extract 2 bytes */
|
||||
uLong flag; /* general purpose bit flag 2 bytes */
|
||||
uLong compression_method; /* compression method 2 bytes */
|
||||
uLong dosDate; /* last mod file date in Dos fmt 4 bytes */
|
||||
uLong crc; /* crc-32 4 bytes */
|
||||
uLong compressed_size; /* compressed size 4 bytes */
|
||||
uLong uncompressed_size; /* uncompressed size 4 bytes */
|
||||
uLong size_filename; /* filename length 2 bytes */
|
||||
uLong size_file_extra; /* extra field length 2 bytes */
|
||||
uLong size_file_comment; /* file comment length 2 bytes */
|
||||
|
||||
uLong disk_num_start; /* disk number start 2 bytes */
|
||||
uLong internal_fa; /* internal file attributes 2 bytes */
|
||||
uLong external_fa; /* external file attributes 4 bytes */
|
||||
|
||||
tm_unz tmu_date;
|
||||
uLong disk_offset;
|
||||
} unz_file_info;
|
||||
|
||||
/***************************************************************************/
|
||||
/* Opening and close a zip file */
|
||||
|
||||
extern unzFile ZEXPORT unzOpen OF((const char *path));
|
||||
extern unzFile ZEXPORT unzOpen64 OF((const void *path));
|
||||
/* Open a Zip file.
|
||||
|
||||
path should contain the full pathname (by example, on a Windows XP computer
|
||||
"c:\\zlib\\zlib113.zip" or on an Unix computer "zlib/zlib113.zip".
|
||||
return NULL if zipfile cannot be opened or doesn't exist
|
||||
return unzFile handle if no error
|
||||
|
||||
NOTE: The "64" function take a const void* pointer, because the path is just the value passed to the
|
||||
open64_file_func callback. Under Windows, if UNICODE is defined, using fill_fopen64_filefunc, the path
|
||||
is a pointer to a wide unicode string (LPCTSTR is LPCWSTR), so const char* does not describe the reality */
|
||||
|
||||
extern unzFile ZEXPORT unzOpen2 OF((const char *path, zlib_filefunc_def* pzlib_filefunc_def));
|
||||
/* Open a Zip file, like unzOpen, but provide a set of file low level API for read/write operations */
|
||||
extern unzFile ZEXPORT unzOpen2_64 OF((const void *path, zlib_filefunc64_def* pzlib_filefunc_def));
|
||||
/* Open a Zip file, like unz64Open, but provide a set of file low level API for read/write 64-bit operations */
|
||||
|
||||
extern int ZEXPORT unzClose OF((unzFile file));
|
||||
/* Close a ZipFile opened with unzOpen. If there is files inside the .Zip opened with unzOpenCurrentFile,
|
||||
these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
|
||||
|
||||
return UNZ_OK if there is no error */
|
||||
|
||||
extern int ZEXPORT unzGetGlobalInfo OF((unzFile file, unz_global_info *pglobal_info));
|
||||
extern int ZEXPORT unzGetGlobalInfo64 OF((unzFile file, unz_global_info64 *pglobal_info));
|
||||
/* Write info about the ZipFile in the *pglobal_info structure.
|
||||
|
||||
return UNZ_OK if no error */
|
||||
|
||||
extern int ZEXPORT unzGetGlobalComment OF((unzFile file, char *comment, uLong comment_size));
|
||||
/* Get the global comment string of the ZipFile, in the comment buffer.
|
||||
|
||||
uSizeBuf is the size of the szComment buffer.
|
||||
return the number of byte copied or an error code <0 */
|
||||
|
||||
/***************************************************************************/
|
||||
/* Reading the content of the current zipfile, you can open it, read data from it, and close it
|
||||
(you can close it before reading all the file) */
|
||||
|
||||
extern int ZEXPORT unzOpenCurrentFile OF((unzFile file));
|
||||
/* Open for reading data the current file in the zipfile.
|
||||
|
||||
return UNZ_OK if no error */
|
||||
|
||||
extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file, const char* password));
|
||||
/* Open for reading data the current file in the zipfile.
|
||||
password is a crypting password
|
||||
|
||||
return UNZ_OK if no error */
|
||||
|
||||
extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file, int* method, int* level, int raw));
|
||||
/* Same as unzOpenCurrentFile, but open for read raw the file (not uncompress)
|
||||
if raw==1 *method will receive method of compression, *level will receive level of compression
|
||||
|
||||
NOTE: you can set level parameter as NULL (if you did not want known level,
|
||||
but you CANNOT set method parameter as NULL */
|
||||
|
||||
extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file, int* method, int* level, int raw, const char* password));
|
||||
/* Same as unzOpenCurrentFile, but takes extra parameter password for encrypted files */
|
||||
|
||||
extern int ZEXPORT unzReadCurrentFile OF((unzFile file, voidp buf, unsigned len));
|
||||
/* Read bytes from the current file (opened by unzOpenCurrentFile)
|
||||
buf contain buffer where data must be copied
|
||||
len the size of buf.
|
||||
|
||||
return the number of byte copied if somes bytes are copied
|
||||
return 0 if the end of file was reached
|
||||
return <0 with error code if there is an error (UNZ_ERRNO for IO error, or zLib error for uncompress error) */
|
||||
|
||||
extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file, unz_file_info *pfile_info, char *filename,
|
||||
uLong filename_size, void *extrafield, uLong extrafield_size, char *comment, uLong comment_size));
|
||||
extern int ZEXPORT unzGetCurrentFileInfo64 OF((unzFile file, unz_file_info64 *pfile_info, char *filename,
|
||||
uLong filename_size, void *extrafield, uLong extrafield_size, char *comment, uLong comment_size));
|
||||
/* Get Info about the current file
|
||||
|
||||
pfile_info if != NULL, the *pfile_info structure will contain somes info about the current file
|
||||
filename if != NULL, the file name string will be copied in filename
|
||||
filename_size is the size of the filename buffer
|
||||
extrafield if != NULL, the extra field information from the central header will be copied in to
|
||||
extrafield_size is the size of the extraField buffer
|
||||
comment if != NULL, the comment string of the file will be copied in to
|
||||
comment_size is the size of the comment buffer */
|
||||
|
||||
extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64 OF((unzFile file));
|
||||
|
||||
extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file, voidp buf, unsigned len));
|
||||
/* Read extra field from the current file (opened by unzOpenCurrentFile)
|
||||
This is the local-header version of the extra field (sometimes, there is
|
||||
more info in the local-header version than in the central-header)
|
||||
|
||||
if buf == NULL, it return the size of the local extra field
|
||||
if buf != NULL, len is the size of the buffer, the extra header is copied in buf.
|
||||
|
||||
return number of bytes copied in buf, or (if <0) the error code */
|
||||
|
||||
extern int ZEXPORT unzCloseCurrentFile OF((unzFile file));
|
||||
/* Close the file in zip opened with unzOpenCurrentFile
|
||||
|
||||
return UNZ_CRCERROR if all the file was read but the CRC is not good */
|
||||
|
||||
/***************************************************************************/
|
||||
/* Browse the directory of the zipfile */
|
||||
|
||||
typedef int (*unzFileNameComparer)(unzFile file, const char *filename1, const char *filename2);
|
||||
typedef int (*unzIteratorFunction)(unzFile file);
|
||||
typedef int (*unzIteratorFunction2)(unzFile file, unz_file_info64 *pfile_info, char *filename,
|
||||
uLong filename_size, void *extrafield, uLong extrafield_size, char *comment, uLong comment_size);
|
||||
|
||||
extern int ZEXPORT unzGoToFirstFile OF((unzFile file));
|
||||
/* Set the current file of the zipfile to the first file.
|
||||
|
||||
return UNZ_OK if no error */
|
||||
|
||||
extern int ZEXPORT unzGoToFirstFile2 OF((unzFile file, unz_file_info64 *pfile_info, char *filename,
|
||||
uLong filename_size, void *extrafield, uLong extrafield_size, char *comment, uLong comment_size));
|
||||
/* Set the current file of the zipfile to the first file and retrieves the current info on success.
|
||||
Not as seek intensive as unzGoToFirstFile + unzGetCurrentFileInfo.
|
||||
|
||||
return UNZ_OK if no error */
|
||||
|
||||
extern int ZEXPORT unzGoToNextFile OF((unzFile file));
|
||||
/* Set the current file of the zipfile to the next file.
|
||||
|
||||
return UNZ_OK if no error
|
||||
return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest */
|
||||
|
||||
extern int ZEXPORT unzGoToNextFile2 OF((unzFile file, unz_file_info64 *pfile_info, char *filename,
|
||||
uLong filename_size, void *extrafield, uLong extrafield_size, char *comment, uLong comment_size));
|
||||
/* Set the current file of the zipfile to the next file and retrieves the current
|
||||
info on success. Does less seeking around than unzGotoNextFile + unzGetCurrentFileInfo.
|
||||
|
||||
return UNZ_OK if no error
|
||||
return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest */
|
||||
|
||||
extern int ZEXPORT unzLocateFile OF((unzFile file, const char *filename, unzFileNameComparer filename_compare_func));
|
||||
/* Try locate the file szFileName in the zipfile. For custom filename comparison pass in comparison function.
|
||||
|
||||
return UNZ_OK if the file is found (it becomes the current file)
|
||||
return UNZ_END_OF_LIST_OF_FILE if the file is not found */
|
||||
|
||||
/***************************************************************************/
|
||||
/* Raw access to zip file */
|
||||
|
||||
typedef struct unz_file_pos_s
|
||||
{
|
||||
uLong pos_in_zip_directory; /* offset in zip file directory */
|
||||
uLong num_of_file; /* # of file */
|
||||
} unz_file_pos;
|
||||
|
||||
extern int ZEXPORT unzGetFilePos OF((unzFile file, unz_file_pos* file_pos));
|
||||
extern int ZEXPORT unzGoToFilePos OF((unzFile file, unz_file_pos* file_pos));
|
||||
|
||||
typedef struct unz64_file_pos_s
|
||||
{
|
||||
ZPOS64_T pos_in_zip_directory; /* offset in zip file directory */
|
||||
ZPOS64_T num_of_file; /* # of file */
|
||||
} unz64_file_pos;
|
||||
|
||||
extern int ZEXPORT unzGetFilePos64 OF((unzFile file, unz64_file_pos* file_pos));
|
||||
extern int ZEXPORT unzGoToFilePos64 OF((unzFile file, const unz64_file_pos* file_pos));
|
||||
|
||||
extern uLong ZEXPORT unzGetOffset OF((unzFile file));
|
||||
extern ZPOS64_T ZEXPORT unzGetOffset64 OF((unzFile file));
|
||||
/* Get the current file offset */
|
||||
|
||||
extern int ZEXPORT unzSetOffset OF((unzFile file, uLong pos));
|
||||
extern int ZEXPORT unzSetOffset64 OF((unzFile file, ZPOS64_T pos));
|
||||
/* Set the current file offset */
|
||||
|
||||
extern z_off_t ZEXPORT unztell OF((unzFile file));
|
||||
extern ZPOS64_T ZEXPORT unztell64 OF((unzFile file));
|
||||
/* return current position in uncompressed data */
|
||||
|
||||
extern int ZEXPORT unzseek OF((unzFile file, z_off_t offset, int origin));
|
||||
extern int ZEXPORT unzseek64 OF((unzFile file, ZPOS64_T offset, int origin));
|
||||
/* Seek within the uncompressed data if compression method is storage */
|
||||
|
||||
extern int ZEXPORT unzeof OF((unzFile file));
|
||||
/* return 1 if the end of file was reached, 0 elsewhere */
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _UNZ_H */
|
||||
14
source/pp2d/README.md
Normal file
@@ -0,0 +1,14 @@
|
||||
# [pp2d](https://discord.gg/zqXWgsH)
|
||||
|
||||
Plug & Play 2D (unofficial) wrapper for Citro3D.
|
||||
|
||||
## License
|
||||
|
||||
pp2d is licensed under the MIT License.
|
||||
|
||||
## Changes
|
||||
|
||||
* depth parameter (Ryuzaki-MrL)
|
||||
* standalone pp2d_free_texture (LiquidFenrir)
|
||||
* 3d support (Robz8)
|
||||
* load png from memory (ErmanSayin)
|
||||
6167
source/pp2d/pp2d/lodepng.c
Normal file
1713
source/pp2d/pp2d/lodepng.h
Normal file
789
source/pp2d/pp2d/pp2d.c
Normal file
@@ -0,0 +1,789 @@
|
||||
/* MIT License
|
||||
*
|
||||
* Copyright (c) 2017 Bernardo Giordano
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* https://discord.gg/zqXWgsH
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plug & Play 2D
|
||||
* @file pp2d.c
|
||||
* @author Bernardo Giordano
|
||||
* @date 26 October 2017
|
||||
* @brief pp2d implementation
|
||||
*/
|
||||
|
||||
#include "pp2d.h"
|
||||
|
||||
static DVLB_s* vshader_dvlb;
|
||||
static shaderProgram_s program;
|
||||
static int uLoc_projection;
|
||||
static C3D_Mtx projectionTopLeft;
|
||||
static C3D_Mtx projectionTopRight;
|
||||
static C3D_Mtx projectionBot;
|
||||
static C3D_Tex* glyphSheets;
|
||||
static textVertex_s* textVtxArray;
|
||||
static int textVtxArrayPos;
|
||||
static C3D_RenderTarget* topLeft;
|
||||
static C3D_RenderTarget* topRight;
|
||||
static C3D_RenderTarget* bot;
|
||||
|
||||
static struct {
|
||||
GPU_TEXTURE_FILTER_PARAM magFilter;
|
||||
GPU_TEXTURE_FILTER_PARAM minFilter;
|
||||
} textureFilters;
|
||||
|
||||
static struct {
|
||||
size_t id;
|
||||
int x;
|
||||
int y;
|
||||
int xbegin;
|
||||
int ybegin;
|
||||
int width;
|
||||
int height;
|
||||
u32 color;
|
||||
flipType fliptype;
|
||||
float scaleX;
|
||||
float scaleY;
|
||||
float angle;
|
||||
float depth;
|
||||
bool initialized;
|
||||
} textureData;
|
||||
|
||||
static struct {
|
||||
C3D_Tex tex;
|
||||
u32 width;
|
||||
u32 height;
|
||||
bool allocated;
|
||||
} textures[MAX_TEXTURES];
|
||||
|
||||
static void pp2d_add_text_vertex(float vx, float vy, float vz, float tx, float ty);
|
||||
static bool pp2d_fast_draw_vbo(int x, int y, int height, int width, float left, float right, float top, float bottom, float depth);
|
||||
static u32 pp2d_get_next_pow2(u32 n);
|
||||
static void pp2d_get_text_size_internal(float* width, float* height, float scaleX, float scaleY, int wrapX, const char* text);
|
||||
static void pp2d_set_text_color(u32 color);
|
||||
|
||||
static void pp2d_add_text_vertex(float vx, float vy, float vz, float tx, float ty)
|
||||
{
|
||||
textVertex_s* vtx = &textVtxArray[textVtxArrayPos++];
|
||||
vtx->position[0] = vx;
|
||||
vtx->position[1] = vy;
|
||||
vtx->position[2] = vz;
|
||||
vtx->texcoord[0] = tx;
|
||||
vtx->texcoord[1] = ty;
|
||||
}
|
||||
|
||||
void pp2d_begin_draw(gfxScreen_t target, gfx3dSide_t side)
|
||||
{
|
||||
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
|
||||
textVtxArrayPos = 0;
|
||||
pp2d_draw_on(target, side);
|
||||
}
|
||||
|
||||
void pp2d_draw_on(gfxScreen_t target, gfx3dSide_t side)
|
||||
{
|
||||
if(target == GFX_TOP) {
|
||||
C3D_FrameDrawOn(side == GFX_LEFT ? topLeft : topRight);
|
||||
C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, uLoc_projection, side == GFX_LEFT ? &projectionTopLeft : &projectionTopRight);
|
||||
} else {
|
||||
C3D_FrameDrawOn(bot);
|
||||
C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, uLoc_projection, &projectionBot);
|
||||
}
|
||||
}
|
||||
|
||||
void pp2d_draw_rectangle(int x, int y, int width, int height, u32 color)
|
||||
{
|
||||
C3D_TexEnv* env = C3D_GetTexEnv(0);
|
||||
C3D_TexEnvSrc(env, C3D_Both, GPU_CONSTANT, GPU_CONSTANT, 0);
|
||||
C3D_TexEnvOp(env, C3D_Both, 0, 0, 0);
|
||||
C3D_TexEnvFunc(env, C3D_Both, GPU_MODULATE);
|
||||
C3D_TexEnvColor(env, color);
|
||||
|
||||
if (pp2d_fast_draw_vbo(x, y, height, width, 0, 0, 0, 0, DEFAULT_DEPTH))
|
||||
{
|
||||
C3D_DrawArrays(GPU_TRIANGLE_STRIP, textVtxArrayPos - 4, 4);
|
||||
}
|
||||
}
|
||||
|
||||
void pp2d_draw_text(float x, float y, float scaleX, float scaleY, u32 color, const char* text)
|
||||
{
|
||||
pp2d_draw_text_wrap(x, y, scaleX, scaleY, color, -1, text);
|
||||
}
|
||||
|
||||
void pp2d_draw_text_center(gfxScreen_t target, float y, float scaleX, float scaleY, u32 color, const char* text)
|
||||
{
|
||||
float width = pp2d_get_text_width(text, scaleX, scaleY);
|
||||
float x = ((target == GFX_TOP ? TOP_WIDTH : BOTTOM_WIDTH) - width) / 2;
|
||||
pp2d_draw_text(x, y, scaleX, scaleY, color, text);
|
||||
}
|
||||
|
||||
void pp2d_draw_textf(float x, float y, float scaleX, float scaleY, u32 color, const char* text, ...)
|
||||
{
|
||||
char buffer[256];
|
||||
va_list args;
|
||||
va_start(args, text);
|
||||
vsnprintf(buffer, 256, text, args);
|
||||
pp2d_draw_text(x, y, scaleX, scaleY, color, buffer);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void pp2d_draw_text_wrap(float x, float y, float scaleX, float scaleY, u32 color, float wrapX, const char* text)
|
||||
{
|
||||
if (text == NULL)
|
||||
return;
|
||||
|
||||
pp2d_set_text_color(color);
|
||||
|
||||
ssize_t units;
|
||||
uint32_t code;
|
||||
const uint8_t* p = (const uint8_t*)text;
|
||||
float firstX = x;
|
||||
int lastSheet = -1;
|
||||
|
||||
do
|
||||
{
|
||||
if (!*p) break;
|
||||
units = decode_utf8(&code, p);
|
||||
if (units == -1)
|
||||
break;
|
||||
p += units;
|
||||
if (code == '\n' || (wrapX != -1 && x + scaleX * fontGetCharWidthInfo(fontGlyphIndexFromCodePoint(code))->charWidth >= firstX + wrapX))
|
||||
{
|
||||
x = firstX;
|
||||
y += scaleY*fontGetInfo()->lineFeed;
|
||||
p -= code == '\n' ? 0 : 1;
|
||||
}
|
||||
else if (code > 0)
|
||||
{
|
||||
int glyphIdx = fontGlyphIndexFromCodePoint(code);
|
||||
fontGlyphPos_s data;
|
||||
fontCalcGlyphPos(&data, glyphIdx, GLYPH_POS_CALC_VTXCOORD, scaleX, scaleY);
|
||||
|
||||
if (data.sheetIndex != lastSheet)
|
||||
{
|
||||
lastSheet = data.sheetIndex;
|
||||
C3D_TexBind(0, &glyphSheets[lastSheet]);
|
||||
}
|
||||
|
||||
if ((textVtxArrayPos+4) >= TEXT_VTX_ARRAY_COUNT)
|
||||
break;
|
||||
|
||||
pp2d_add_text_vertex(x+data.vtxcoord.left, y+data.vtxcoord.bottom, DEFAULT_DEPTH, data.texcoord.left, data.texcoord.bottom);
|
||||
pp2d_add_text_vertex(x+data.vtxcoord.right, y+data.vtxcoord.bottom, DEFAULT_DEPTH, data.texcoord.right, data.texcoord.bottom);
|
||||
pp2d_add_text_vertex(x+data.vtxcoord.left, y+data.vtxcoord.top, DEFAULT_DEPTH, data.texcoord.left, data.texcoord.top);
|
||||
pp2d_add_text_vertex(x+data.vtxcoord.right, y+data.vtxcoord.top, DEFAULT_DEPTH, data.texcoord.right, data.texcoord.top);
|
||||
|
||||
C3D_DrawArrays(GPU_TRIANGLE_STRIP, textVtxArrayPos - 4, 4);
|
||||
|
||||
x += data.xAdvance;
|
||||
}
|
||||
} while (code > 0);
|
||||
}
|
||||
|
||||
void pp2d_draw_texture(size_t id, int x, int y)
|
||||
{
|
||||
pp2d_texture_select(id, x, y);
|
||||
pp2d_texture_draw();
|
||||
}
|
||||
|
||||
void pp2d_draw_texture_blend(size_t id, int x, int y, u32 color)
|
||||
{
|
||||
pp2d_texture_select(id, x, y);
|
||||
pp2d_texture_blend(color);
|
||||
pp2d_texture_draw();
|
||||
}
|
||||
|
||||
void pp2d_draw_texture_flip(size_t id, int x, int y, flipType fliptype)
|
||||
{
|
||||
pp2d_texture_select(id, x, y);
|
||||
pp2d_texture_flip(fliptype);
|
||||
pp2d_texture_draw();
|
||||
}
|
||||
|
||||
void pp2d_draw_texture_rotate(size_t id, int x, int y, float angle)
|
||||
{
|
||||
pp2d_texture_select(id, x, y);
|
||||
pp2d_texture_rotate(angle);
|
||||
pp2d_texture_draw();
|
||||
}
|
||||
|
||||
void pp2d_draw_texture_scale(size_t id, int x, int y, float scaleX, float scaleY)
|
||||
{
|
||||
pp2d_texture_select(id, x, y);
|
||||
pp2d_texture_scale(scaleX, scaleY);
|
||||
pp2d_texture_draw();
|
||||
}
|
||||
|
||||
void pp2d_draw_texture_part(size_t id, int x, int y, int xbegin, int ybegin, int width, int height)
|
||||
{
|
||||
pp2d_texture_select_part(id, x, y, xbegin, ybegin, width, height);
|
||||
pp2d_texture_draw();
|
||||
}
|
||||
|
||||
void pp2d_draw_wtext(float x, float y, float scaleX, float scaleY, u32 color, const wchar_t* text)
|
||||
{
|
||||
pp2d_draw_wtext_wrap(x, y, scaleX, scaleY, color, -1, text);
|
||||
}
|
||||
|
||||
void pp2d_draw_wtext_center(gfxScreen_t target, float y, float scaleX, float scaleY, u32 color, const wchar_t* text)
|
||||
{
|
||||
float width = pp2d_get_wtext_width(text, scaleX, scaleY);
|
||||
float x = ((target == GFX_TOP ? TOP_WIDTH : BOTTOM_WIDTH) - width) / 2;
|
||||
pp2d_draw_wtext(x, y, scaleX, scaleY, color, text);
|
||||
}
|
||||
|
||||
void pp2d_draw_wtext_wrap(float x, float y, float scaleX, float scaleY, u32 color, float wrapX, const wchar_t* text)
|
||||
{
|
||||
if (text == NULL)
|
||||
return;
|
||||
|
||||
u32 size = wcslen(text) * sizeof(wchar_t);
|
||||
char buf[size];
|
||||
memset(buf, 0, size);
|
||||
utf32_to_utf8((uint8_t*)buf, (uint32_t*)text, size);
|
||||
buf[size - 1] = '\0';
|
||||
|
||||
pp2d_draw_text_wrap(x, y, scaleX, scaleY, color, wrapX, buf);
|
||||
}
|
||||
|
||||
void pp2d_draw_wtextf(float x, float y, float scaleX, float scaleY, u32 color, const wchar_t* text, ...)
|
||||
{
|
||||
wchar_t buffer[256];
|
||||
va_list args;
|
||||
va_start(args, text);
|
||||
vswprintf(buffer, 256, text, args);
|
||||
pp2d_draw_wtext(x, y, scaleX, scaleY, color, buffer);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void pp2d_end_draw(void)
|
||||
{
|
||||
C3D_FrameEnd(0);
|
||||
}
|
||||
|
||||
void pp2d_exit(void)
|
||||
{
|
||||
for (size_t id = 0; id < MAX_TEXTURES; id++)
|
||||
{
|
||||
pp2d_free_texture(id);
|
||||
}
|
||||
|
||||
linearFree(textVtxArray);
|
||||
free(glyphSheets);
|
||||
|
||||
shaderProgramFree(&program);
|
||||
DVLB_Free(vshader_dvlb);
|
||||
|
||||
C3D_Fini();
|
||||
gfxExit();
|
||||
}
|
||||
|
||||
static bool pp2d_fast_draw_vbo(int x, int y, int height, int width, float left, float right, float top, float bottom, float depth)
|
||||
{
|
||||
if ((textVtxArrayPos+4) >= TEXT_VTX_ARRAY_COUNT)
|
||||
return false;
|
||||
|
||||
pp2d_add_text_vertex( x, y + height, depth, left, bottom);
|
||||
pp2d_add_text_vertex(x + width, y + height, depth, right, bottom);
|
||||
pp2d_add_text_vertex( x, y, depth, left, top);
|
||||
pp2d_add_text_vertex(x + width, y, depth, right, top);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void pp2d_free_texture(size_t id)
|
||||
{
|
||||
if (id >= MAX_TEXTURES)
|
||||
return;
|
||||
|
||||
if (!textures[id].allocated)
|
||||
return;
|
||||
|
||||
C3D_TexDelete(&textures[id].tex);
|
||||
textures[id].width = 0;
|
||||
textures[id].height = 0;
|
||||
textures[id].allocated = false;
|
||||
}
|
||||
|
||||
Result pp2d_init(void)
|
||||
{
|
||||
Result res = 0;
|
||||
|
||||
gfxInitDefault();
|
||||
C3D_Init(C3D_DEFAULT_CMDBUF_SIZE);
|
||||
|
||||
topLeft = C3D_RenderTargetCreate(SCREEN_HEIGHT, TOP_WIDTH, GPU_RB_RGBA8, GPU_RB_DEPTH24_STENCIL8);
|
||||
C3D_RenderTargetSetClear(topLeft, C3D_CLEAR_ALL, BACKGROUND_COLOR, 0);
|
||||
C3D_RenderTargetSetOutput(topLeft, GFX_TOP, GFX_LEFT, DISPLAY_TRANSFER_FLAGS);
|
||||
|
||||
topRight = C3D_RenderTargetCreate(SCREEN_HEIGHT, TOP_WIDTH, GPU_RB_RGBA8, GPU_RB_DEPTH24_STENCIL8);
|
||||
C3D_RenderTargetSetClear(topRight, C3D_CLEAR_ALL, BACKGROUND_COLOR, 0);
|
||||
C3D_RenderTargetSetOutput(topRight, GFX_TOP, GFX_RIGHT, DISPLAY_TRANSFER_FLAGS);
|
||||
|
||||
bot = C3D_RenderTargetCreate(SCREEN_HEIGHT, BOTTOM_WIDTH, GPU_RB_RGBA8, GPU_RB_DEPTH24_STENCIL8);
|
||||
C3D_RenderTargetSetClear(bot, C3D_CLEAR_ALL, BACKGROUND_COLOR, 0);
|
||||
C3D_RenderTargetSetOutput(bot, GFX_BOTTOM, GFX_LEFT, DISPLAY_TRANSFER_FLAGS);
|
||||
|
||||
res = fontEnsureMapped();
|
||||
if (R_FAILED(res))
|
||||
return res;
|
||||
|
||||
pp2d_set_texture_filter(GPU_NEAREST, GPU_NEAREST);
|
||||
|
||||
#ifdef BUILDTOOLS
|
||||
vshader_dvlb = DVLB_ParseFile((u32*)vshader_shbin, vshader_shbin_len);
|
||||
#else
|
||||
vshader_dvlb = DVLB_ParseFile((u32*)vshader_shbin, vshader_shbin_size);
|
||||
#endif
|
||||
|
||||
shaderProgramInit(&program);
|
||||
shaderProgramSetVsh(&program, &vshader_dvlb->DVLE[0]);
|
||||
C3D_BindProgram(&program);
|
||||
|
||||
uLoc_projection = shaderInstanceGetUniformLocation(program.vertexShader, "projection");
|
||||
|
||||
C3D_AttrInfo* attrInfo = C3D_GetAttrInfo();
|
||||
AttrInfo_Init(attrInfo);
|
||||
AttrInfo_AddLoader(attrInfo, 0, GPU_FLOAT, 3);
|
||||
AttrInfo_AddLoader(attrInfo, 1, GPU_FLOAT, 2);
|
||||
|
||||
Mtx_OrthoTilt(&projectionTopLeft, 0, TOP_WIDTH, SCREEN_HEIGHT, 0.0f, 0.0f, 1.0f, true);
|
||||
Mtx_OrthoTilt(&projectionTopRight, 0, TOP_WIDTH, SCREEN_HEIGHT, 0.0f, 0.0f, 1.0f, true);
|
||||
Mtx_OrthoTilt(&projectionBot, 0, BOTTOM_WIDTH, SCREEN_HEIGHT, 0.0f, 0.0f, 1.0f, true);
|
||||
|
||||
C3D_DepthTest(true, GPU_GEQUAL, GPU_WRITE_ALL);
|
||||
|
||||
int i;
|
||||
TGLP_s* glyphInfo = fontGetGlyphInfo();
|
||||
glyphSheets = malloc(sizeof(C3D_Tex)*glyphInfo->nSheets);
|
||||
for (i = 0; i < glyphInfo->nSheets; i ++)
|
||||
{
|
||||
C3D_Tex* tex = &glyphSheets[i];
|
||||
tex->data = fontGetGlyphSheetTex(i);
|
||||
tex->fmt = glyphInfo->sheetFmt;
|
||||
tex->size = glyphInfo->sheetSize;
|
||||
tex->width = glyphInfo->sheetWidth;
|
||||
tex->height = glyphInfo->sheetHeight;
|
||||
tex->param = GPU_TEXTURE_MAG_FILTER(GPU_LINEAR) | GPU_TEXTURE_MIN_FILTER(GPU_LINEAR)
|
||||
| GPU_TEXTURE_WRAP_S(GPU_CLAMP_TO_EDGE) | GPU_TEXTURE_WRAP_T(GPU_CLAMP_TO_EDGE);
|
||||
tex->border = 0;
|
||||
tex->lodParam = 0;
|
||||
}
|
||||
|
||||
textVtxArray = (textVertex_s*)linearAlloc(sizeof(textVertex_s)*TEXT_VTX_ARRAY_COUNT);
|
||||
C3D_BufInfo* bufInfo = C3D_GetBufInfo();
|
||||
BufInfo_Init(bufInfo);
|
||||
BufInfo_Add(bufInfo, textVtxArray, sizeof(textVertex_s), 2, 0x10);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static u32 pp2d_get_next_pow2(u32 v)
|
||||
{
|
||||
v--;
|
||||
v |= v >> 1;
|
||||
v |= v >> 2;
|
||||
v |= v >> 4;
|
||||
v |= v >> 8;
|
||||
v |= v >> 16;
|
||||
v++;
|
||||
return v >= 64 ? v : 64;
|
||||
}
|
||||
|
||||
float pp2d_get_text_height(const char* text, float scaleX, float scaleY)
|
||||
{
|
||||
float height;
|
||||
pp2d_get_text_size_internal(NULL, &height, scaleX, scaleY, -1, text);
|
||||
return height;
|
||||
}
|
||||
|
||||
float pp2d_get_text_height_wrap(const char* text, float scaleX, float scaleY, int wrapX)
|
||||
{
|
||||
float height;
|
||||
pp2d_get_text_size_internal(NULL, &height, scaleX, scaleY, wrapX, text);
|
||||
return height;
|
||||
}
|
||||
|
||||
void pp2d_get_text_size(float* width, float* height, float scaleX, float scaleY, const char* text)
|
||||
{
|
||||
pp2d_get_text_size_internal(width, height, scaleX, scaleY, -1, text);
|
||||
}
|
||||
|
||||
static void pp2d_get_text_size_internal(float* width, float* height, float scaleX, float scaleY, int wrapX, const char* text)
|
||||
{
|
||||
float w = 0.0f;
|
||||
float h = 0.0f;
|
||||
|
||||
ssize_t units;
|
||||
uint32_t code;
|
||||
float x = 0;
|
||||
float firstX = x;
|
||||
const uint8_t* p = (const uint8_t*)text;
|
||||
|
||||
do
|
||||
{
|
||||
if (!*p) break;
|
||||
units = decode_utf8(&code, p);
|
||||
if (units == -1)
|
||||
break;
|
||||
p += units;
|
||||
if (code == '\n' || (wrapX != -1 && x + scaleX * fontGetCharWidthInfo(fontGlyphIndexFromCodePoint(code))->charWidth >= firstX + wrapX))
|
||||
{
|
||||
x = firstX;
|
||||
h += scaleY*fontGetInfo()->lineFeed;
|
||||
p -= code == '\n' ? 0 : 1;
|
||||
}
|
||||
else if (code > 0)
|
||||
{
|
||||
float len = (scaleX * fontGetCharWidthInfo(fontGlyphIndexFromCodePoint(code))->charWidth);
|
||||
w += len;
|
||||
x += len;
|
||||
}
|
||||
} while (code > 0);
|
||||
|
||||
if (width)
|
||||
{
|
||||
*width = w;
|
||||
}
|
||||
|
||||
if (height)
|
||||
{
|
||||
h += scaleY*fontGetInfo()->lineFeed;
|
||||
*height = h;
|
||||
}
|
||||
}
|
||||
|
||||
float pp2d_get_text_width(const char* text, float scaleX, float scaleY)
|
||||
{
|
||||
float width;
|
||||
pp2d_get_text_size_internal(&width, NULL, scaleX, scaleY, -1, text);
|
||||
return width;
|
||||
}
|
||||
|
||||
float pp2d_get_wtext_height(const wchar_t* text, float scaleX, float scaleY)
|
||||
{
|
||||
u32 size = wcslen(text) * sizeof(wchar_t);
|
||||
char buf[size];
|
||||
memset(buf, 0, size);
|
||||
utf32_to_utf8((uint8_t*)buf, (uint32_t*)text, size);
|
||||
buf[size - 1] = '\0';
|
||||
|
||||
float height;
|
||||
pp2d_get_text_size_internal(NULL, &height, scaleX, scaleY, -1, buf);
|
||||
return height;
|
||||
}
|
||||
|
||||
float pp2d_get_wtext_width(const wchar_t* text, float scaleX, float scaleY)
|
||||
{
|
||||
u32 size = wcslen(text) * sizeof(wchar_t);
|
||||
char buf[size];
|
||||
memset(buf, 0, size);
|
||||
utf32_to_utf8((uint8_t*)buf, (uint32_t*)text, size);
|
||||
buf[size - 1] = '\0';
|
||||
|
||||
float width;
|
||||
pp2d_get_text_size_internal(&width, NULL, scaleX, scaleY, -1, buf);
|
||||
return width;
|
||||
}
|
||||
|
||||
void pp2d_load_texture_memory(size_t id, void* buf, u32 width, u32 height)
|
||||
{
|
||||
u32 w_pow2 = pp2d_get_next_pow2(width);
|
||||
u32 h_pow2 = pp2d_get_next_pow2(height);
|
||||
|
||||
C3D_TexInit(&textures[id].tex, (u16)w_pow2, (u16)h_pow2, GPU_RGBA8);
|
||||
C3D_TexSetFilter(&textures[id].tex, textureFilters.magFilter, textureFilters.minFilter);
|
||||
|
||||
textures[id].allocated = true;
|
||||
textures[id].width = width;
|
||||
textures[id].height = height;
|
||||
|
||||
memset(textures[id].tex.data, 0, textures[id].tex.size);
|
||||
for (u32 i = 0; i < width; i++)
|
||||
{
|
||||
for (u32 j = 0; j < height; j++)
|
||||
{
|
||||
u32 dst = ((((j >> 3) * (w_pow2 >> 3) + (i >> 3)) << 6) + ((i & 1) | ((j & 1) << 1) | ((i & 2) << 1) | ((j & 2) << 2) | ((i & 4) << 2) | ((j & 4) << 3))) * 4;
|
||||
u32 src = (j * width + i) * 4;
|
||||
|
||||
memcpy(textures[id].tex.data + dst, buf + src, 4);
|
||||
}
|
||||
}
|
||||
|
||||
C3D_TexFlush(&textures[id].tex);
|
||||
}
|
||||
|
||||
void pp2d_load_texture_png(size_t id, const char* path)
|
||||
{
|
||||
if (id >= MAX_TEXTURES)
|
||||
return;
|
||||
|
||||
u8* image;
|
||||
unsigned width;
|
||||
unsigned height;
|
||||
|
||||
lodepng_decode32_file(&image, &width, &height, path);
|
||||
|
||||
for (u32 i = 0; i < width; i++)
|
||||
{
|
||||
for (u32 j = 0; j < height; j++)
|
||||
{
|
||||
u32 p = (i + j*width) * 4;
|
||||
|
||||
u8 r = *(u8*)(image + p);
|
||||
u8 g = *(u8*)(image + p + 1);
|
||||
u8 b = *(u8*)(image + p + 2);
|
||||
u8 a = *(u8*)(image + p + 3);
|
||||
|
||||
*(image + p) = a;
|
||||
*(image + p + 1) = b;
|
||||
*(image + p + 2) = g;
|
||||
*(image + p + 3) = r;
|
||||
}
|
||||
}
|
||||
|
||||
pp2d_load_texture_memory(id, image, width, height);
|
||||
free(image);
|
||||
}
|
||||
|
||||
void pp2d_load_texture_png_memory(size_t id, void* buf, size_t buf_size)
|
||||
{
|
||||
if (id >= MAX_TEXTURES)
|
||||
return;
|
||||
|
||||
u8* image;
|
||||
unsigned width;
|
||||
unsigned height;
|
||||
|
||||
lodepng_decode32(&image, &width, &height, buf, buf_size);
|
||||
|
||||
for (u32 i = 0; i < width; i++)
|
||||
{
|
||||
for (u32 j = 0; j < height; j++)
|
||||
{
|
||||
u32 p = (i + j*width) * 4;
|
||||
|
||||
u8 r = *(u8*)(image + p);
|
||||
u8 g = *(u8*)(image + p + 1);
|
||||
u8 b = *(u8*)(image + p + 2);
|
||||
u8 a = *(u8*)(image + p + 3);
|
||||
|
||||
*(image + p) = a;
|
||||
*(image + p + 1) = b;
|
||||
*(image + p + 2) = g;
|
||||
*(image + p + 3) = r;
|
||||
}
|
||||
}
|
||||
|
||||
pp2d_load_texture_memory(id, image, width, height);
|
||||
free(image);
|
||||
}
|
||||
|
||||
void pp2d_set_3D(int enable)
|
||||
{
|
||||
gfxSet3D(enable);
|
||||
}
|
||||
|
||||
void pp2d_set_screen_color(gfxScreen_t target, u32 color)
|
||||
{
|
||||
if (target == GFX_TOP)
|
||||
{
|
||||
C3D_RenderTargetSetClear(topLeft, C3D_CLEAR_ALL, color, 0);
|
||||
C3D_RenderTargetSetClear(topRight, C3D_CLEAR_ALL, color, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
C3D_RenderTargetSetClear(bot, C3D_CLEAR_ALL, color, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void pp2d_set_texture_filter(GPU_TEXTURE_FILTER_PARAM magFilter, GPU_TEXTURE_FILTER_PARAM minFilter)
|
||||
{
|
||||
textureFilters.magFilter = magFilter;
|
||||
textureFilters.minFilter = minFilter;
|
||||
}
|
||||
|
||||
static void pp2d_set_text_color(u32 color)
|
||||
{
|
||||
C3D_TexEnv* env = C3D_GetTexEnv(0);
|
||||
C3D_TexEnvSrc(env, C3D_RGB, GPU_CONSTANT, 0, 0);
|
||||
C3D_TexEnvSrc(env, C3D_Alpha, GPU_TEXTURE0, GPU_CONSTANT, 0);
|
||||
C3D_TexEnvOp(env, C3D_Both, 0, 0, 0);
|
||||
C3D_TexEnvFunc(env, C3D_RGB, GPU_REPLACE);
|
||||
C3D_TexEnvFunc(env, C3D_Alpha, GPU_MODULATE);
|
||||
C3D_TexEnvColor(env, color);
|
||||
}
|
||||
|
||||
void pp2d_texture_select(size_t id, int x, int y)
|
||||
{
|
||||
if (id >= MAX_TEXTURES)
|
||||
{
|
||||
textureData.initialized = false;
|
||||
return;
|
||||
}
|
||||
|
||||
textureData.id = id;
|
||||
textureData.x = x;
|
||||
textureData.y = y;
|
||||
textureData.xbegin = 0;
|
||||
textureData.ybegin = 0;
|
||||
textureData.width = textures[id].width;
|
||||
textureData.height = textures[id].height;
|
||||
textureData.color = PP2D_NEUTRAL;
|
||||
textureData.fliptype = NONE;
|
||||
textureData.scaleX = 1;
|
||||
textureData.scaleY = 1;
|
||||
textureData.angle = 0;
|
||||
textureData.depth = DEFAULT_DEPTH;
|
||||
textureData.initialized = true;
|
||||
}
|
||||
|
||||
void pp2d_texture_select_part(size_t id, int x, int y, int xbegin, int ybegin, int width, int height)
|
||||
{
|
||||
if (id >= MAX_TEXTURES)
|
||||
{
|
||||
textureData.initialized = false;
|
||||
return;
|
||||
}
|
||||
|
||||
textureData.id = id;
|
||||
textureData.x = x;
|
||||
textureData.y = y;
|
||||
textureData.xbegin = xbegin;
|
||||
textureData.ybegin = ybegin;
|
||||
textureData.width = width;
|
||||
textureData.height = height;
|
||||
textureData.color = PP2D_NEUTRAL;
|
||||
textureData.fliptype = NONE;
|
||||
textureData.scaleX = 1;
|
||||
textureData.scaleY = 1;
|
||||
textureData.angle = 0;
|
||||
textureData.depth = DEFAULT_DEPTH;
|
||||
textureData.initialized = true;
|
||||
}
|
||||
|
||||
void pp2d_texture_blend(u32 color)
|
||||
{
|
||||
textureData.color = color;
|
||||
}
|
||||
|
||||
void pp2d_texture_scale(float scaleX, float scaleY)
|
||||
{
|
||||
textureData.scaleX = scaleX;
|
||||
textureData.scaleY = scaleY;
|
||||
}
|
||||
|
||||
void pp2d_texture_flip(flipType fliptype)
|
||||
{
|
||||
textureData.fliptype = fliptype;
|
||||
}
|
||||
|
||||
void pp2d_texture_rotate(float angle)
|
||||
{
|
||||
textureData.angle = angle;
|
||||
}
|
||||
|
||||
void pp2d_texture_depth(float depth)
|
||||
{
|
||||
textureData.depth = depth;
|
||||
}
|
||||
|
||||
void pp2d_texture_draw(void)
|
||||
{
|
||||
if (!textureData.initialized)
|
||||
return;
|
||||
|
||||
if ((textVtxArrayPos+4) >= TEXT_VTX_ARRAY_COUNT)
|
||||
return;
|
||||
|
||||
size_t id = textureData.id;
|
||||
|
||||
float left = (float)textureData.xbegin / (float)textures[id].tex.width;
|
||||
float right = (float)(textureData.xbegin + textureData.width) / (float)textures[id].tex.width;
|
||||
float top = (float)(textures[id].tex.height - textureData.ybegin) / (float)textures[id].tex.height;
|
||||
float bottom = (float)(textures[id].tex.height - textureData.ybegin - textureData.height) / (float)textures[id].tex.height;
|
||||
|
||||
// scaling
|
||||
textureData.height *= textureData.scaleY;
|
||||
textureData.width *= textureData.scaleX;
|
||||
|
||||
float vert[4][2] = {
|
||||
{ textureData.x, textureData.height + textureData.y},
|
||||
{textureData.width + textureData.x, textureData.height + textureData.y},
|
||||
{ textureData.x, textureData.y},
|
||||
{textureData.width + textureData.x, textureData.y},
|
||||
};
|
||||
|
||||
// flipping
|
||||
if (textureData.fliptype == BOTH || textureData.fliptype == HORIZONTAL)
|
||||
{
|
||||
float tmp = left;
|
||||
left = right;
|
||||
right = tmp;
|
||||
}
|
||||
|
||||
if (textureData.fliptype == BOTH || textureData.fliptype == VERTICAL)
|
||||
{
|
||||
float tmp = top;
|
||||
top = bottom;
|
||||
bottom = tmp;
|
||||
}
|
||||
|
||||
// rotating
|
||||
textureData.angle = fmod(textureData.angle, 360);
|
||||
if (textureData.angle != 0)
|
||||
{
|
||||
const float rad = textureData.angle/(180/M_PI);
|
||||
const float c = cosf(rad);
|
||||
const float s = sinf(rad);
|
||||
|
||||
const float xcenter = textureData.x + textureData.width/2.0f;
|
||||
const float ycenter = textureData.y + textureData.height/2.0f;
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
float oldx = vert[i][0];
|
||||
float oldy = vert[i][1];
|
||||
|
||||
float newx = c * (oldx - xcenter) - s * (oldy - ycenter) + xcenter;
|
||||
float newy = s * (oldx - xcenter) + c * (oldy - ycenter) + ycenter;
|
||||
|
||||
vert[i][0] = newx;
|
||||
vert[i][1] = newy;
|
||||
}
|
||||
}
|
||||
|
||||
// blending
|
||||
C3D_TexBind(0, &textures[id].tex);
|
||||
C3D_TexEnv* env = C3D_GetTexEnv(0);
|
||||
C3D_TexEnvSrc(env, C3D_Both, GPU_TEXTURE0, GPU_CONSTANT, 0);
|
||||
C3D_TexEnvOp(env, C3D_Both, 0, 0, 0);
|
||||
C3D_TexEnvFunc(env, C3D_Both, GPU_MODULATE);
|
||||
C3D_TexEnvColor(env, textureData.color);
|
||||
|
||||
// rendering
|
||||
pp2d_add_text_vertex(vert[0][0], vert[0][1], textureData.depth, left, bottom);
|
||||
pp2d_add_text_vertex(vert[1][0], vert[1][1], textureData.depth, right, bottom);
|
||||
pp2d_add_text_vertex(vert[2][0], vert[2][1], textureData.depth, left, top);
|
||||
pp2d_add_text_vertex(vert[3][0], vert[3][1], textureData.depth, right, top);
|
||||
|
||||
C3D_DrawArrays(GPU_TRIANGLE_STRIP, textVtxArrayPos - 4, 4);
|
||||
}
|
||||
472
source/pp2d/pp2d/pp2d.h
Normal file
@@ -0,0 +1,472 @@
|
||||
/* MIT License
|
||||
*
|
||||
* Copyright (c) 2017 Bernardo Giordano
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* https://discord.gg/zqXWgsH
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plug & Play 2D
|
||||
* @file pp2d.h
|
||||
* @author Bernardo Giordano
|
||||
* @date 26 October 2017
|
||||
* @brief pp2d header
|
||||
*/
|
||||
|
||||
#ifndef PP2D_H
|
||||
#define PP2D_H
|
||||
|
||||
#include "lodepng.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <3ds.h>
|
||||
#include <citro3d.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <wchar.h>
|
||||
#include "vshader_shbin.h"
|
||||
|
||||
#define TOP_WIDTH 400
|
||||
#define BOTTOM_WIDTH 320
|
||||
#define SCREEN_HEIGHT 240
|
||||
|
||||
/**
|
||||
* @brief Used to transfer the final rendered display to the framebuffer
|
||||
*/
|
||||
#define DISPLAY_TRANSFER_FLAGS \
|
||||
(GX_TRANSFER_FLIP_VERT(0) | GX_TRANSFER_OUT_TILED(0) | GX_TRANSFER_RAW_COPY(0) | \
|
||||
GX_TRANSFER_IN_FORMAT(GX_TRANSFER_FMT_RGBA8) | GX_TRANSFER_OUT_FORMAT(GX_TRANSFER_FMT_RGB8) | \
|
||||
GX_TRANSFER_SCALING(GX_TRANSFER_SCALE_NO))
|
||||
|
||||
/**
|
||||
* @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))
|
||||
|
||||
/**
|
||||
* @brief Creates a 8 byte ABGR color
|
||||
* @param a alpha component of the color
|
||||
* @param b blue component of the color
|
||||
* @param g green component of the color
|
||||
* @param r red component of the color
|
||||
*/
|
||||
#define ABGR8(a, b, g, r) ((((a)&0xFF)<<0) | (((b)&0xFF)<<8) | (((g)&0xFF)<<16) | (((r)&0xFF)<<24))
|
||||
|
||||
/**
|
||||
* @brief Converts a RGB565 color to RGBA8 color (adds maximum alpha)
|
||||
* @param rgb 565 to be converted
|
||||
*/
|
||||
#define RGB565_TO_RGBA8(rgb) \
|
||||
(RGBA8(((rgb>>11)&0x1F)*0xFF/0x1F, ((rgb>>5)&0x3F)*0xFF/0x3F, (rgb&0x1F)*0xFF/0x1F, 255))
|
||||
|
||||
/**
|
||||
* @brief Converts a RGB565 color to ABGR8 color (adds maximum alpha)
|
||||
* @param rgb 565 to be converted
|
||||
*/
|
||||
#define RGB565_TO_ABGR8(rgb) \
|
||||
(RGBA8(255, (rgb&0x1F)*0xFF/0x1F, ((rgb>>5)&0x3F)*0xFF/0x3F, ((rgb>>11)&0x1F)*0xFF/0x1F))
|
||||
|
||||
#define BACKGROUND_COLOR ABGR8(255, 0, 0, 0)
|
||||
#define PP2D_NEUTRAL RGBA8(255, 255, 255, 255)
|
||||
|
||||
#define DEFAULT_DEPTH 0.5f
|
||||
|
||||
#define MAX_TEXTURES 1024
|
||||
|
||||
#define TEXT_VTX_ARRAY_COUNT (4*1024)
|
||||
|
||||
typedef enum {
|
||||
NONE,
|
||||
HORIZONTAL,
|
||||
VERTICAL,
|
||||
BOTH
|
||||
} flipType;
|
||||
|
||||
typedef struct {
|
||||
float position[3];
|
||||
float texcoord[2];
|
||||
} textVertex_s;
|
||||
|
||||
/**
|
||||
* @brief Starts a new frame on the specified screen
|
||||
* @param target GFX_TOP or GFX_BOTTOM
|
||||
*/
|
||||
void pp2d_begin_draw(gfxScreen_t target, gfx3dSide_t side);
|
||||
|
||||
/**
|
||||
* @brief Changes target screen to the specified target
|
||||
* @param target GFX_TOP or GFX_BOTTOM
|
||||
*/
|
||||
void pp2d_draw_on(gfxScreen_t target, gfx3dSide_t side);
|
||||
|
||||
/**
|
||||
* @brief Draw a rectangle
|
||||
* @param x of the top left corner
|
||||
* @param y of the top left corner
|
||||
* @param width on the rectangle
|
||||
* @param height of the rectangle
|
||||
* @param color RGBA8 to fill the rectangle
|
||||
*/
|
||||
void pp2d_draw_rectangle(int x, int y, int width, int height, u32 color);
|
||||
|
||||
/**
|
||||
* @brief Prints a char pointer
|
||||
* @param x position to start drawing
|
||||
* @param y position to start drawing
|
||||
* @param scaleX multiplier for the text width
|
||||
* @param scaleY multiplier for the text height
|
||||
* @param color RGBA8 the text will be drawn
|
||||
* @param text to be printed on the screen
|
||||
*/
|
||||
void pp2d_draw_text(float x, float y, float scaleX, float scaleY, u32 color, const char* text);
|
||||
|
||||
/**
|
||||
* @brief Prints a char pointer in the middle of the target screen
|
||||
* @param target screen to draw the text to
|
||||
* @param y position to start drawing
|
||||
* @param scaleX multiplier for the text width
|
||||
* @param scaleY multiplier for the text height
|
||||
* @param color RGBA8 the text will be drawn
|
||||
* @param text to be printed on the screen
|
||||
*/
|
||||
void pp2d_draw_text_center(gfxScreen_t target, float y, float scaleX, float scaleY, u32 color, const char* text);
|
||||
|
||||
/**
|
||||
* @brief Prints a char pointer in the middle of the target screen
|
||||
* @param x position to start drawing
|
||||
* @param y position to start drawing
|
||||
* @param scaleX multiplier for the text width
|
||||
* @param scaleY multiplier for the text height
|
||||
* @param color RGBA8 the text will be drawn
|
||||
* @param wrapX wrap width
|
||||
* @param text to be printed on the screen
|
||||
*/
|
||||
void pp2d_draw_text_wrap(float x, float y, float scaleX, float scaleY, u32 color, float wrapX, const char* text);
|
||||
|
||||
/**
|
||||
* @brief Prints a char pointer with arguments
|
||||
* @param x position to start drawing
|
||||
* @param y position to start drawing
|
||||
* @param scaleX multiplier for the text width
|
||||
* @param scaleY multiplier for the text height
|
||||
* @param color RGBA8 the text will be drawn
|
||||
* @param text to be printed on the screen
|
||||
* @param ... arguments
|
||||
*/
|
||||
void pp2d_draw_textf(float x, float y, float scaleX, float scaleY, u32 color, const char* text, ...);
|
||||
|
||||
/**
|
||||
* @brief Prints a texture
|
||||
* @param id of the texture
|
||||
* @param x position on the screen to draw the texture
|
||||
* @param y position on the screen to draw the texture
|
||||
*/
|
||||
void pp2d_draw_texture(size_t id, int x, int y);
|
||||
|
||||
/**
|
||||
* @brief Prints a texture with color modulation
|
||||
* @param id of the texture
|
||||
* @param x position on the screen to draw the texture
|
||||
* @param y position on the screen to draw the texture
|
||||
* @param color RGBA8 to modulate the texture with
|
||||
*/
|
||||
void pp2d_draw_texture_blend(size_t id, int x, int y, u32 color);
|
||||
|
||||
/**
|
||||
* @brief Prints a flipped texture
|
||||
* @param id of the texture
|
||||
* @param x position on the screen to draw the texture
|
||||
* @param y position on the screen to draw the texture
|
||||
* @param fliptype HORIZONTAL, VERTICAL or BOTH
|
||||
*/
|
||||
|
||||
void pp2d_draw_texture_flip(size_t id, int x, int y, flipType fliptype);
|
||||
|
||||
/**
|
||||
* @brief Prints a rotated texture
|
||||
* @param id of the texture
|
||||
* @param x position on the screen to draw the texture
|
||||
* @param y position on the screen to draw the texture
|
||||
* @param angle in degrees to rotate the texture
|
||||
*/
|
||||
void pp2d_draw_texture_rotate(size_t id, int x, int y, float angle);
|
||||
|
||||
/**
|
||||
* @brief Prints a texture with a scale factor
|
||||
* @param id of the texture
|
||||
* @param x position on the screen to draw the texture
|
||||
* @param y position on the screen to draw the texture
|
||||
* @param scaleX width scale factor
|
||||
* @param scaleY height scale factor
|
||||
*/
|
||||
void pp2d_draw_texture_scale(size_t id, int x, int y, float scaleX, float scaleY);
|
||||
|
||||
/**
|
||||
* @brief Prints a portion of a texture
|
||||
* @param id of the texture
|
||||
* @param x position on the screen to draw the texture
|
||||
* @param y position on the screen to draw the texture
|
||||
* @param xbegin position to start drawing
|
||||
* @param ybegin position to start drawing
|
||||
* @param width to draw from the xbegin position
|
||||
* @param height to draw from the ybegin position
|
||||
*/
|
||||
void pp2d_draw_texture_part(size_t id, int x, int y, int xbegin, int ybegin, int width, int height);
|
||||
|
||||
/**
|
||||
* @brief Prints a wchar_t pointer
|
||||
* @param x position to start drawing
|
||||
* @param y position to start drawing
|
||||
* @param scaleX multiplier for the text width
|
||||
* @param scaleY multiplier for the text height
|
||||
* @param color RGBA8 the text will be drawn
|
||||
* @param text to be printed on the screen
|
||||
*/
|
||||
void pp2d_draw_wtext(float x, float y, float scaleX, float scaleY, u32 color, const wchar_t* text);
|
||||
|
||||
/**
|
||||
* @brief Prints a wchar_t pointer in the middle of the target screen
|
||||
* @param target screen to draw the text to
|
||||
* @param y position to start drawing
|
||||
* @param scaleX multiplier for the text width
|
||||
* @param scaleY multiplier for the text height
|
||||
* @param color RGBA8 the text will be drawn
|
||||
* @param text to be printed on the screen
|
||||
*/
|
||||
void pp2d_draw_wtext_center(gfxScreen_t target, float y, float scaleX, float scaleY, u32 color, const wchar_t* text);
|
||||
|
||||
/**
|
||||
* @brief Prints a wchar_t pointer
|
||||
* @param x position to start drawing
|
||||
* @param y position to start drawing
|
||||
* @param scaleX multiplier for the text width
|
||||
* @param scaleY multiplier for the text height
|
||||
* @param color RGBA8 the text will be drawn
|
||||
* @param wrapX wrap width
|
||||
* @param text to be printed on the screen
|
||||
*/
|
||||
void pp2d_draw_wtext_wrap(float x, float y, float scaleX, float scaleY, u32 color, float wrapX, const wchar_t* text);
|
||||
|
||||
/**
|
||||
* @brief Prints a wchar_t pointer with arguments
|
||||
* @param x position to start drawing
|
||||
* @param y position to start drawing
|
||||
* @param scaleX multiplier for the text width
|
||||
* @param scaleY multiplier for the text height
|
||||
* @param color RGBA8 the text will be drawn
|
||||
* @param text to be printed on the screen
|
||||
* @param ... arguments
|
||||
*/
|
||||
void pp2d_draw_wtextf(float x, float y, float scaleX, float scaleY, u32 color, const wchar_t* text, ...);
|
||||
|
||||
/**
|
||||
* @brief Ends a frame
|
||||
*/
|
||||
void pp2d_end_draw(void);
|
||||
|
||||
/**
|
||||
* @brief Frees the pp2d environment
|
||||
*/
|
||||
void pp2d_exit(void);
|
||||
|
||||
/**
|
||||
* @brief Inits the pp2d environment
|
||||
* @return 0 if everything went correctly, otherwise returns Result code
|
||||
* @note This will trigger gfxInitDefault by default
|
||||
*/
|
||||
Result pp2d_init(void);
|
||||
|
||||
/**
|
||||
* @brief Calculates a char pointer height
|
||||
* @param text char pointer to calculate the height of
|
||||
* @param scaleX multiplier for the text width
|
||||
* @param scaleY multiplier for the text height
|
||||
* @return height the text will have if rendered in the supplied conditions
|
||||
*/
|
||||
float pp2d_get_text_height(const char* text, float scaleX, float scaleY);
|
||||
|
||||
/**
|
||||
* @brief Calculates a char pointer height
|
||||
* @param text char pointer to calculate the height of
|
||||
* @param scaleX multiplier for the text width
|
||||
* @param scaleY multiplier for the text height
|
||||
* @param wrapX wrap width
|
||||
* @return height the text will have if rendered in the supplied conditions
|
||||
*/
|
||||
float pp2d_get_text_height_wrap(const char* text, float scaleX, float scaleY, int wrapX);
|
||||
|
||||
/**
|
||||
* @brief Calculates width and height for a char pointer
|
||||
* @param width pointer to the width to return
|
||||
* @param height pointer to the height to return
|
||||
* @param scaleX multiplier for the text width
|
||||
* @param scaleY multiplier for the text height
|
||||
* @param text to calculate dimensions of
|
||||
*/
|
||||
void pp2d_get_text_size(float* width, float* height, float scaleX, float scaleY, const char* text);
|
||||
|
||||
/**
|
||||
* @brief Calculates a char pointer width
|
||||
* @param text char pointer to calculate the width of
|
||||
* @param scaleX multiplier for the text width
|
||||
* @param scaleY multiplier for the text height
|
||||
* @return width the text will have if rendered in the supplied conditions
|
||||
*/
|
||||
float pp2d_get_text_width(const char* text, float scaleX, float scaleY);
|
||||
|
||||
/**
|
||||
* @brief Calculates a wchar_t pointer height
|
||||
* @param text wchar_t pointer to calculate the height of
|
||||
* @param scaleX multiplier for the text width
|
||||
* @param scaleY multiplier for the text height
|
||||
* @return height the text will have if rendered in the supplied conditions
|
||||
*/
|
||||
float pp2d_get_wtext_height(const wchar_t* text, float scaleX, float scaleY);
|
||||
|
||||
/**
|
||||
* @brief Calculates a wchar_t pointer width
|
||||
* @param text wchar_t pointer to calculate the width of
|
||||
* @param scaleX multiplier for the text width
|
||||
* @param scaleY multiplier for the text height
|
||||
* @return width the text will have if rendered in the supplied conditions
|
||||
*/
|
||||
float pp2d_get_wtext_width(const wchar_t* text, float scaleX, float scaleY);
|
||||
|
||||
/**
|
||||
* @brief Frees a texture
|
||||
* @param id of the texture to free
|
||||
*/
|
||||
void pp2d_free_texture(size_t id);
|
||||
|
||||
/**
|
||||
* @brief Loads a texture from a a buffer in memory
|
||||
* @param id of the texture
|
||||
* @param buf buffer where the texture is stored
|
||||
* @param width of the texture
|
||||
* @param height of the texture
|
||||
*/
|
||||
void pp2d_load_texture_memory(size_t id, void* buf, u32 width, u32 height);
|
||||
|
||||
/**
|
||||
* @brief Loads a texture from a png file
|
||||
* @param id of the texture
|
||||
* @param path where the png file is located
|
||||
*/
|
||||
void pp2d_load_texture_png(size_t id, const char* path);
|
||||
|
||||
/**
|
||||
* @brief Loads a texture from a buffer in memory
|
||||
* @param id of the texture
|
||||
* @param buf buffer where the png is stored
|
||||
* @param buf_size size of buffer
|
||||
*/
|
||||
void pp2d_load_texture_png_memory(size_t id, void* buf, size_t buf_size);
|
||||
|
||||
/**
|
||||
* @brief Enables 3D service
|
||||
* @param enable integer
|
||||
*/
|
||||
void pp2d_set_3D(int enable);
|
||||
|
||||
/**
|
||||
* @brief Sets a background color for the specified screen
|
||||
* @param target GFX_TOP or GFX_BOTTOM
|
||||
* @param color ABGR8 which will be the background one
|
||||
*/
|
||||
void pp2d_set_screen_color(gfxScreen_t target, u32 color);
|
||||
|
||||
/**
|
||||
* @brief Sets filters to load texture with
|
||||
* @param magFilter GPU_NEAREST or GPU_LINEAR
|
||||
* @param minFilter GPU_NEAREST or GPU_LINEAR
|
||||
*/
|
||||
void pp2d_set_texture_filter(GPU_TEXTURE_FILTER_PARAM magFilter, GPU_TEXTURE_FILTER_PARAM minFilter);
|
||||
|
||||
/**
|
||||
* @brief Inits a texture to be drawn
|
||||
* @param id of the texture
|
||||
* @param x to draw the texture at
|
||||
* @param y to draw the texture at
|
||||
*/
|
||||
void pp2d_texture_select(size_t id, int x, int y);
|
||||
|
||||
/**
|
||||
* @brief Inits a portion of a texture to be drawn
|
||||
* @param id of the texture
|
||||
* @param x position on the screen to draw the texture
|
||||
* @param y position on the screen to draw the texture
|
||||
* @param xbegin position to start drawing
|
||||
* @param ybegin position to start drawing
|
||||
* @param width to draw from the xbegin position
|
||||
* @param height to draw from the ybegin position
|
||||
*/
|
||||
void pp2d_texture_select_part(size_t id, int x, int y, int xbegin, int ybegin, int width, int height);
|
||||
|
||||
/**
|
||||
* @brief Modulates a texture with a color
|
||||
* @param color to modulate the texture
|
||||
*/
|
||||
void pp2d_texture_blend(u32 color);
|
||||
|
||||
/**
|
||||
* @brief Scales a texture
|
||||
* @param scaleX width scale factor
|
||||
* @param scaleY height scale factor
|
||||
*/
|
||||
void pp2d_texture_scale(float scaleX, float scaleY);
|
||||
|
||||
/**
|
||||
* @brief Flips a texture
|
||||
* @param fliptype HORIZONTAL, VERTICAL or BOTH
|
||||
*/
|
||||
void pp2d_texture_flip(flipType fliptype);
|
||||
|
||||
/**
|
||||
* @brief Rotates a texture
|
||||
* @param angle in degrees to rotate the texture
|
||||
*/
|
||||
void pp2d_texture_rotate(float angle);
|
||||
|
||||
/**
|
||||
* @brief Sets the depth of a texture
|
||||
* @param depth factor of the texture
|
||||
*/
|
||||
void pp2d_texture_depth(float depth);
|
||||
|
||||
/**
|
||||
* @brief Renders a texture
|
||||
*/
|
||||
void pp2d_texture_draw(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*PP2D_H*/
|
||||
39
source/pp2d/pp2d/vshader.v.pica
Normal file
@@ -0,0 +1,39 @@
|
||||
; Uniforms
|
||||
.fvec projection[4]
|
||||
|
||||
; Constants
|
||||
.constf myconst(0.0, 1.0, -1.0, 0.1)
|
||||
.constf RGBA_TO_FLOAT4(0.00392156862, 0, 0, 0)
|
||||
.alias zeros myconst.xxxx ; Vector full of zeros
|
||||
.alias ones myconst.yyyy ; Vector full of ones
|
||||
|
||||
; Outputs
|
||||
.out outpos position
|
||||
.out outclr color
|
||||
.out outtc0 texcoord0
|
||||
|
||||
; Inputs (defined as aliases for convenience)
|
||||
.alias inpos v0
|
||||
.alias intex v1
|
||||
|
||||
.bool test
|
||||
|
||||
.proc main
|
||||
; Force the w component of inpos to be 1.0
|
||||
mov r0.xyz, inpos
|
||||
mov r0.w, ones
|
||||
|
||||
; outpos = projectionMatrix * inpos
|
||||
dp4 outpos.x, projection[0], r0
|
||||
dp4 outpos.y, projection[1], r0
|
||||
dp4 outpos.z, projection[2], r0
|
||||
dp4 outpos.w, projection[3], r0
|
||||
|
||||
;outtc0 = intexcoord
|
||||
mov outtc0, intex
|
||||
|
||||
;outclr
|
||||
mul outclr, RGBA_TO_FLOAT4.xxxx, intex
|
||||
|
||||
end
|
||||
.end
|
||||
824
source/remote.c
Normal file
@@ -0,0 +1,824 @@
|
||||
/*
|
||||
* This file is part of Anemone3DS
|
||||
* Copyright (C) 2016-2017 Alex Taber ("astronautlevel"), Dawid Eckert ("daedreth")
|
||||
*
|
||||
* 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 "remote.h"
|
||||
#include "loading.h"
|
||||
#include "draw.h"
|
||||
#include "fs.h"
|
||||
#include "pp2d/pp2d/pp2d.h"
|
||||
|
||||
static Instructions_s browser_instructions[MODE_AMOUNT] = {
|
||||
{
|
||||
.info_line = NULL,
|
||||
.instructions = {
|
||||
{
|
||||
L"\uE000 Download theme",
|
||||
L"\uE001 Go back"
|
||||
},
|
||||
{
|
||||
L"\uE002 Hold for more",
|
||||
L"\uE003 Preview theme"
|
||||
},
|
||||
{
|
||||
L"\uE004 Previous page",
|
||||
L"\uE005 Next page"
|
||||
},
|
||||
{
|
||||
L"Exit",
|
||||
NULL
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
.info_line = NULL,
|
||||
.instructions = {
|
||||
{
|
||||
L"\uE000 Download splash",
|
||||
L"\uE001 Go back"
|
||||
},
|
||||
{
|
||||
L"\uE002 Hold for more",
|
||||
L"\uE003 Preview splash"
|
||||
},
|
||||
{
|
||||
L"\uE004 Previous page",
|
||||
L"\uE005 Next page"
|
||||
},
|
||||
{
|
||||
L"Exit",
|
||||
NULL
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static Instructions_s extra_instructions = {
|
||||
.info_line = L"Release \uE002 to cancel or hold \uE006 and release \uE002 to do stuff",
|
||||
.info_line_color = COLOR_WHITE,
|
||||
.instructions = {
|
||||
{
|
||||
L"\uE079 Jump to page",
|
||||
L"\uE07A Search tags"
|
||||
},
|
||||
{
|
||||
L"\uE07B Toggle splash/theme",
|
||||
NULL
|
||||
},
|
||||
{
|
||||
NULL,
|
||||
NULL
|
||||
},
|
||||
{
|
||||
L"Exit",
|
||||
NULL
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static void load_remote_entry(Entry_s * entry)
|
||||
{
|
||||
char * entry_json = NULL;
|
||||
char * api_url = NULL;
|
||||
asprintf(&api_url, THEMEPLAZA_ENTRY_FORMAT, entry->tp_download_id);
|
||||
u32 json_len = http_get(api_url, NULL, &entry_json);
|
||||
free(api_url);
|
||||
|
||||
if(json_len)
|
||||
{
|
||||
json_error_t error;
|
||||
json_t *root = json_loadb(entry_json, json_len, 0, &error);
|
||||
if(root)
|
||||
{
|
||||
const char *key;
|
||||
json_t *value;
|
||||
json_object_foreach(root, key, value)
|
||||
{
|
||||
if(json_is_string(value))
|
||||
{
|
||||
if(!strcmp(key, THEMEPLAZA_JSON_ENTRY_NAME))
|
||||
{
|
||||
utf8_to_utf16(entry->name, (u8*)json_string_value(value), 0x40);
|
||||
|
||||
}
|
||||
else if(!strcmp(key, THEMEPLAZA_JSON_ENTRY_DESC))
|
||||
utf8_to_utf16(entry->desc, (u8*)json_string_value(value), 0x80);
|
||||
else if(!strcmp(key, THEMEPLAZA_JSON_ENTRY_AUTH))
|
||||
utf8_to_utf16(entry->author, (u8*)json_string_value(value), 0x40);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
DEBUG("json error on line %d: %s\n", error.line, error.text);
|
||||
|
||||
json_decref(root);
|
||||
}
|
||||
free(entry_json);
|
||||
}
|
||||
|
||||
static void load_remote_icon(size_t textureID, json_int_t id)
|
||||
{
|
||||
char * icon_data = NULL;
|
||||
char * icon_url = NULL;
|
||||
asprintf(&icon_url, THEMEPLAZA_ICON_FORMAT, id);
|
||||
u32 icon_size = http_get(icon_url, NULL, &icon_data);
|
||||
free(icon_url);
|
||||
|
||||
pp2d_free_texture(textureID);
|
||||
pp2d_load_texture_png_memory(textureID, icon_data, icon_size);
|
||||
free(icon_data);
|
||||
}
|
||||
|
||||
static void load_remote_entries(Entry_List_s * list, json_t *ids_array)
|
||||
{
|
||||
list->entries_count = json_array_size(ids_array);
|
||||
free(list->entries);
|
||||
list->entries = calloc(list->entries_count, sizeof(Entry_s));
|
||||
free(list->icons_ids);
|
||||
list->icons_ids = calloc(list->entries_count, sizeof(ssize_t));
|
||||
list->entries_loaded = list->entries_count;
|
||||
|
||||
size_t i = 0;
|
||||
json_t * id = NULL;
|
||||
json_array_foreach(ids_array, i, id)
|
||||
{
|
||||
size_t offset = i;
|
||||
Entry_s * current_entry = &list->entries[offset];
|
||||
current_entry->tp_download_id = json_integer_value(id);
|
||||
load_remote_entry(current_entry);
|
||||
|
||||
size_t textureID = list->texture_id_offset + i;
|
||||
load_remote_icon(textureID, current_entry->tp_download_id);
|
||||
list->icons_ids[offset] = textureID;
|
||||
}
|
||||
}
|
||||
|
||||
static void load_remote_list(Entry_List_s * list, json_int_t page, EntryMode mode)
|
||||
{
|
||||
if(page > list->tp_page_count)
|
||||
page = 1;
|
||||
if(page <= 0)
|
||||
page = list->tp_page_count;
|
||||
|
||||
InstallType loading_screen = INSTALL_NONE;
|
||||
if(mode == MODE_THEMES)
|
||||
loading_screen = INSTALL_LOADING_REMOTE_THEMES;
|
||||
else if(mode == MODE_SPLASHES)
|
||||
loading_screen = INSTALL_LOADING_REMOTE_SPLASHES;
|
||||
draw_install(loading_screen);
|
||||
|
||||
char * page_json = NULL;
|
||||
char * api_url = NULL;
|
||||
asprintf(&api_url, THEMEPLAZA_PAGE_FORMAT, page, mode+1, list->tp_search);
|
||||
u32 json_len = http_get(api_url, NULL, &page_json);
|
||||
free(api_url);
|
||||
|
||||
if(json_len)
|
||||
{
|
||||
list->texture_id_offset = TEXTURE_REMOTE_ICONS;
|
||||
list->tp_current_page = page;
|
||||
list->mode = mode;
|
||||
list->entry_size = entry_size[mode];
|
||||
list->entries_per_screen_v = entries_per_screen_v[mode];
|
||||
list->entries_per_screen_h = entries_per_screen_h[mode];
|
||||
|
||||
json_error_t error;
|
||||
json_t *root = json_loadb(page_json, json_len, 0, &error);
|
||||
if(root)
|
||||
{
|
||||
const char *key;
|
||||
json_t *value;
|
||||
json_object_foreach(root, key, value)
|
||||
{
|
||||
if(json_is_integer(value) && !strcmp(key, THEMEPLAZA_JSON_PAGE_COUNT))
|
||||
list->tp_page_count = json_integer_value(value);
|
||||
else if(json_is_array(value) && !strcmp(key, THEMEPLAZA_JSON_PAGE_IDS))
|
||||
load_remote_entries(list, value);
|
||||
else if(json_is_string(value) && !strcmp(key, THEMEPLAZA_JSON_ERROR_MESSAGE) && !strcmp(json_string_value(value), THEMEPLAZA_JSON_ERROR_MESSAGE_NOT_FOUND))
|
||||
throw_error("No results for this search.", ERROR_LEVEL_WARNING);
|
||||
}
|
||||
}
|
||||
else
|
||||
DEBUG("json error on line %d: %s\n", error.line, error.text);
|
||||
|
||||
json_decref(root);
|
||||
}
|
||||
else
|
||||
throw_error("Couldn't download ThemePlaza data.\nMake sure WiFi is on.", ERROR_LEVEL_WARNING);
|
||||
|
||||
free(page_json);
|
||||
}
|
||||
|
||||
static char previous_preview_url[0x100] = {0};
|
||||
static bool load_remote_preview(Entry_List_s list, int * preview_offset)
|
||||
{
|
||||
Entry_s entry = list.entries[list.selected_entry];
|
||||
|
||||
char * preview_url = NULL;
|
||||
asprintf(&preview_url, THEMEPLAZA_PREVIEW_FORMAT, entry.tp_download_id);
|
||||
if(!strncmp(previous_preview_url, preview_url, 0x100))
|
||||
{
|
||||
free(preview_url);
|
||||
return true;
|
||||
}
|
||||
|
||||
draw_install(INSTALL_LOADING_REMOTE_PREVIEW);
|
||||
char * preview_png = NULL;
|
||||
u32 preview_size = http_get(preview_url, NULL, &preview_png);
|
||||
|
||||
if(!preview_size)
|
||||
{
|
||||
free(preview_png);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ret = false;
|
||||
u8 * image = NULL;
|
||||
unsigned int width = 0, height = 0;
|
||||
|
||||
if((lodepng_decode32(&image, &width, &height, (u8*)preview_png, preview_size)) == 0) // no error
|
||||
{
|
||||
for(u32 i = 0; i < width; i++)
|
||||
{
|
||||
for(u32 j = 0; j < height; j++)
|
||||
{
|
||||
u32* pixel = (u32*)(image + (i + j*width) * 4);
|
||||
*pixel = __builtin_bswap32(*pixel); //swap from RGBA to ABGR, needed for pp2d
|
||||
}
|
||||
}
|
||||
|
||||
// mark the new preview as loaded for optimisation
|
||||
strncpy(previous_preview_url, preview_url, 0x100);
|
||||
// free the previously loaded preview. wont do anything if there wasnt one
|
||||
pp2d_free_texture(TEXTURE_REMOTE_PREVIEW);
|
||||
|
||||
pp2d_load_texture_memory(TEXTURE_REMOTE_PREVIEW, image, (u32)width, (u32)height);
|
||||
|
||||
*preview_offset = (width-400)/2;
|
||||
ret = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw_error("Corrupted/invalid preview.png", ERROR_LEVEL_WARNING);
|
||||
}
|
||||
|
||||
free(image);
|
||||
free(preview_url);
|
||||
free(preview_png);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void download_remote_entry(Entry_s * entry, EntryMode mode)
|
||||
{
|
||||
char * download_url = NULL;
|
||||
asprintf(&download_url, THEMEPLAZA_DOWNLOAD_FORMAT, entry->tp_download_id);
|
||||
|
||||
char * zip_buf = NULL;
|
||||
char * filename = NULL;
|
||||
draw_install(INSTALL_DOWNLOAD);
|
||||
u32 zip_size = http_get(download_url, &filename, &zip_buf);
|
||||
free(download_url);
|
||||
|
||||
char path_to_file[0x107] = {0};
|
||||
sprintf(path_to_file, "%s%s", main_paths[mode], filename);
|
||||
free(filename);
|
||||
|
||||
char * extension = strrchr(path_to_file, '.');
|
||||
if (extension == NULL || strcmp(extension, ".zip"))
|
||||
strcat(path_to_file, ".zip");
|
||||
|
||||
DEBUG("Saving to sd: %s\n", path_to_file);
|
||||
remake_file(path_to_file, ArchiveSD, zip_size);
|
||||
buf_to_file(zip_size, path_to_file, ArchiveSD, zip_buf);
|
||||
free(zip_buf);
|
||||
}
|
||||
|
||||
static SwkbdCallbackResult jump_menu_callback(void* page_number, const char** ppMessage, const char* text, size_t textlen)
|
||||
{
|
||||
int typed_value = atoi(text);
|
||||
if(typed_value > *(json_int_t*)page_number)
|
||||
{
|
||||
*ppMessage = "The new page has to be\nsmaller or equal to the\nnumber of pages!";
|
||||
return SWKBD_CALLBACK_CONTINUE;
|
||||
}
|
||||
else if(typed_value == 0)
|
||||
{
|
||||
*ppMessage = "The new position has to\nbe positive!";
|
||||
return SWKBD_CALLBACK_CONTINUE;
|
||||
}
|
||||
return SWKBD_CALLBACK_OK;
|
||||
}
|
||||
|
||||
static void jump_menu(Entry_List_s * list)
|
||||
{
|
||||
if(list == NULL) return;
|
||||
|
||||
char numbuf[64] = {0};
|
||||
|
||||
SwkbdState swkbd;
|
||||
|
||||
sprintf(numbuf, "%" JSON_INTEGER_FORMAT, list->tp_page_count);
|
||||
int max_chars = strlen(numbuf);
|
||||
swkbdInit(&swkbd, SWKBD_TYPE_NUMPAD, 2, max_chars);
|
||||
|
||||
sprintf(numbuf, "%" JSON_INTEGER_FORMAT, list->tp_current_page);
|
||||
swkbdSetInitialText(&swkbd, numbuf);
|
||||
|
||||
sprintf(numbuf, "Which page do you want to jump to?");
|
||||
swkbdSetHintText(&swkbd, numbuf);
|
||||
|
||||
swkbdSetButton(&swkbd, SWKBD_BUTTON_LEFT, "Cancel", false);
|
||||
swkbdSetButton(&swkbd, SWKBD_BUTTON_RIGHT, "Jump", true);
|
||||
swkbdSetValidation(&swkbd, SWKBD_NOTEMPTY_NOTBLANK, 0, max_chars);
|
||||
swkbdSetFilterCallback(&swkbd, jump_menu_callback, &list->tp_page_count);
|
||||
|
||||
memset(numbuf, 0, sizeof(numbuf));
|
||||
SwkbdButton button = swkbdInputText(&swkbd, numbuf, sizeof(numbuf));
|
||||
if(button == SWKBD_BUTTON_CONFIRM)
|
||||
{
|
||||
json_int_t newpage = (json_int_t)atoi(numbuf);
|
||||
if(newpage != list->tp_current_page)
|
||||
load_remote_list(list, newpage, list->mode);
|
||||
}
|
||||
}
|
||||
|
||||
static void search_menu(Entry_List_s * list)
|
||||
{
|
||||
const int max_chars = 256;
|
||||
char * search = calloc(max_chars+1, sizeof(char));
|
||||
|
||||
SwkbdState swkbd;
|
||||
|
||||
swkbdInit(&swkbd, SWKBD_TYPE_WESTERN, 2, max_chars);
|
||||
swkbdSetHintText(&swkbd, "Which tags do you want to search for?");
|
||||
|
||||
swkbdSetButton(&swkbd, SWKBD_BUTTON_LEFT, "Cancel", false);
|
||||
swkbdSetButton(&swkbd, SWKBD_BUTTON_RIGHT, "Search", true);
|
||||
swkbdSetValidation(&swkbd, SWKBD_NOTBLANK, 0, max_chars);
|
||||
|
||||
SwkbdButton button = swkbdInputText(&swkbd, search, max_chars);
|
||||
if(button == SWKBD_BUTTON_CONFIRM)
|
||||
{
|
||||
free(list->tp_search);
|
||||
for(unsigned int i = 0; i < strlen(search); i++)
|
||||
{
|
||||
if(search[i] == ' ')
|
||||
search[i] = '+';
|
||||
}
|
||||
list->tp_search = search;
|
||||
load_remote_list(list, 1, list->mode);
|
||||
}
|
||||
else
|
||||
{
|
||||
free(search);
|
||||
}
|
||||
}
|
||||
|
||||
static void change_selected(Entry_List_s * list, int change_value)
|
||||
{
|
||||
if(abs(change_value) >= list->entries_count) return;
|
||||
|
||||
int newval = list->selected_entry + change_value;
|
||||
|
||||
if(abs(change_value) == 1)
|
||||
{
|
||||
if(newval < 0)
|
||||
newval += list->entries_per_screen_h;
|
||||
if(newval/list->entries_per_screen_h != list->selected_entry/list->entries_per_screen_h)
|
||||
newval += list->entries_per_screen_h*(-change_value);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(newval < 0)
|
||||
newval += list->entries_per_screen_h*list->entries_per_screen_v;
|
||||
newval %= list->entries_count;
|
||||
}
|
||||
list->selected_entry = newval;
|
||||
}
|
||||
|
||||
bool themeplaza_browser(EntryMode mode)
|
||||
{
|
||||
bool downloaded = false;
|
||||
|
||||
bool preview_mode = false;
|
||||
int preview_offset = 0;
|
||||
|
||||
Entry_List_s list = {0};
|
||||
Entry_List_s * current_list = &list;
|
||||
current_list->tp_search = strdup("");
|
||||
load_remote_list(current_list, 1, mode);
|
||||
|
||||
bool extra_mode = false;
|
||||
|
||||
while(aptMainLoop())
|
||||
{
|
||||
if(current_list->entries == NULL)
|
||||
break;
|
||||
|
||||
if(preview_mode)
|
||||
draw_preview(TEXTURE_REMOTE_PREVIEW, preview_offset);
|
||||
else
|
||||
{
|
||||
Instructions_s instructions = browser_instructions[mode];
|
||||
if(extra_mode)
|
||||
instructions = extra_instructions;
|
||||
draw_grid_interface(current_list, instructions);
|
||||
}
|
||||
pp2d_end_draw();
|
||||
|
||||
hidScanInput();
|
||||
u32 kDown = hidKeysDown();
|
||||
u32 kHeld = hidKeysHeld();
|
||||
u32 kUp = hidKeysUp();
|
||||
|
||||
|
||||
|
||||
if(kDown & KEY_START)
|
||||
{
|
||||
exit:
|
||||
quit = true;
|
||||
downloaded = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if(extra_mode)
|
||||
{
|
||||
if(kUp & KEY_X)
|
||||
extra_mode = false;
|
||||
if(!extra_mode)
|
||||
{
|
||||
if((kDown | kHeld) & KEY_DLEFT)
|
||||
{
|
||||
change_mode:
|
||||
mode++;
|
||||
mode %= MODE_AMOUNT;
|
||||
|
||||
free(current_list->tp_search);
|
||||
current_list->tp_search = strdup("");
|
||||
|
||||
load_remote_list(current_list, 1, mode);
|
||||
}
|
||||
else if((kDown | kHeld) & KEY_DUP)
|
||||
{
|
||||
jump_menu(current_list);
|
||||
}
|
||||
else if((kDown | kHeld) & KEY_DRIGHT)
|
||||
{
|
||||
|
||||
}
|
||||
else if((kDown | kHeld) & KEY_DDOWN)
|
||||
{
|
||||
search_menu(current_list);
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
int selected_entry = current_list->selected_entry;
|
||||
Entry_s * current_entry = ¤t_list->entries[selected_entry];
|
||||
|
||||
if(kDown & KEY_Y)
|
||||
{
|
||||
toggle_preview:
|
||||
if(!preview_mode)
|
||||
preview_mode = load_remote_preview(*current_list, &preview_offset);
|
||||
else
|
||||
preview_mode = false;
|
||||
}
|
||||
else if(kDown & KEY_B)
|
||||
{
|
||||
if(preview_mode)
|
||||
preview_mode = false;
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
if(preview_mode)
|
||||
goto touch;
|
||||
|
||||
if(kDown & KEY_A)
|
||||
{
|
||||
download_remote_entry(current_entry, mode);
|
||||
downloaded = true;
|
||||
}
|
||||
else if(kDown & KEY_X)
|
||||
{
|
||||
extra_mode = true;
|
||||
}
|
||||
else if(kDown & KEY_L)
|
||||
{
|
||||
load_remote_list(current_list, current_list->tp_current_page-1, mode);
|
||||
}
|
||||
else if(kDown & KEY_R)
|
||||
{
|
||||
load_remote_list(current_list, current_list->tp_current_page+1, mode);
|
||||
}
|
||||
|
||||
// Movement in the UI
|
||||
else if(kDown & KEY_UP)
|
||||
{
|
||||
change_selected(current_list, -current_list->entries_per_screen_h);
|
||||
}
|
||||
else if(kDown & KEY_DOWN)
|
||||
{
|
||||
change_selected(current_list, current_list->entries_per_screen_h);
|
||||
}
|
||||
// Quick moving
|
||||
else if(kDown & KEY_LEFT)
|
||||
{
|
||||
change_selected(current_list, -1);
|
||||
}
|
||||
else if(kDown & KEY_RIGHT)
|
||||
{
|
||||
change_selected(current_list, 1);
|
||||
}
|
||||
|
||||
// Fast scroll using circle pad
|
||||
else if(kHeld & KEY_CPAD_UP)
|
||||
{
|
||||
change_selected(current_list, -1);
|
||||
svcSleepThread(FASTSCROLL_WAIT);
|
||||
}
|
||||
else if(kHeld & KEY_CPAD_DOWN)
|
||||
{
|
||||
change_selected(current_list, 1);
|
||||
svcSleepThread(FASTSCROLL_WAIT);
|
||||
}
|
||||
else if(kHeld & KEY_CPAD_LEFT)
|
||||
{
|
||||
change_selected(current_list, -current_list->entries_per_screen_v);
|
||||
svcSleepThread(FASTSCROLL_WAIT);
|
||||
}
|
||||
else if(kHeld & KEY_CPAD_RIGHT)
|
||||
{
|
||||
change_selected(current_list, current_list->entries_per_screen_v);
|
||||
svcSleepThread(FASTSCROLL_WAIT);
|
||||
}
|
||||
|
||||
touch:
|
||||
if((kDown | kHeld) & KEY_TOUCH)
|
||||
{
|
||||
touchPosition touch = {0};
|
||||
hidTouchRead(&touch);
|
||||
|
||||
u16 x = touch.px;
|
||||
u16 y = touch.py;
|
||||
|
||||
#define BETWEEN(min, x, max) (min < x && x < max)
|
||||
|
||||
int border = 16;
|
||||
if(kDown & KEY_TOUCH)
|
||||
{
|
||||
if(preview_mode)
|
||||
{
|
||||
preview_mode = false;
|
||||
continue;
|
||||
}
|
||||
else if(y < 24)
|
||||
{
|
||||
if(BETWEEN(0, x, 80))
|
||||
{
|
||||
search_menu(current_list);
|
||||
}
|
||||
else if(BETWEEN(320-96, x, 320-72))
|
||||
{
|
||||
break;
|
||||
}
|
||||
else if(BETWEEN(320-72, x, 320-48))
|
||||
{
|
||||
goto exit;
|
||||
}
|
||||
else if(BETWEEN(320-48, x, 320-24))
|
||||
{
|
||||
goto toggle_preview;
|
||||
}
|
||||
else if(BETWEEN(320-24, x, 320))
|
||||
{
|
||||
goto change_mode;
|
||||
}
|
||||
}
|
||||
else if(BETWEEN(240-24, y, 240) && BETWEEN(176, x, 320))
|
||||
{
|
||||
jump_menu(current_list);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(BETWEEN(0, x, border))
|
||||
{
|
||||
load_remote_list(current_list, current_list->tp_current_page-1, mode);
|
||||
}
|
||||
else if(BETWEEN(320-border, x, 320))
|
||||
{
|
||||
load_remote_list(current_list, current_list->tp_current_page+1, mode);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(preview_mode)
|
||||
{
|
||||
preview_mode = false;
|
||||
continue;
|
||||
}
|
||||
else if(BETWEEN(24, y, 240-24))
|
||||
{
|
||||
if(BETWEEN(border, x, 320-border))
|
||||
{
|
||||
x -= border;
|
||||
x /= current_list->entry_size;
|
||||
y -= 24;
|
||||
y /= current_list->entry_size;
|
||||
int new_selected = y*current_list->entries_per_screen_h + x;
|
||||
if(new_selected < current_list->entries_count)
|
||||
current_list->selected_entry = new_selected;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
free(current_list->entries);
|
||||
free(current_list->icons_ids);
|
||||
free(current_list->tp_search);
|
||||
|
||||
return downloaded;
|
||||
}
|
||||
|
||||
u32 http_get(const char *url, char ** filename, char ** buf)
|
||||
{
|
||||
Result ret;
|
||||
httpcContext context;
|
||||
char *new_url = NULL;
|
||||
u32 status_code;
|
||||
u32 content_size = 0;
|
||||
u32 read_size = 0;
|
||||
u32 size = 0;
|
||||
char *last_buf;
|
||||
|
||||
do {
|
||||
ret = httpcOpenContext(&context, HTTPC_METHOD_GET, url, 1);
|
||||
if (ret != 0)
|
||||
{
|
||||
httpcCloseContext(&context);
|
||||
if (new_url != NULL) free(new_url);
|
||||
DEBUG("httpcOpenContext %.8lx\n", ret);
|
||||
return 0;
|
||||
}
|
||||
ret = httpcSetSSLOpt(&context, SSLCOPT_DisableVerify); // should let us do https
|
||||
ret = httpcSetKeepAlive(&context, HTTPC_KEEPALIVE_ENABLED);
|
||||
ret = httpcAddRequestHeaderField(&context, "User-Agent", USER_AGENT);
|
||||
ret = httpcAddRequestHeaderField(&context, "Connection", "Keep-Alive");
|
||||
|
||||
ret = httpcBeginRequest(&context);
|
||||
if (ret != 0)
|
||||
{
|
||||
httpcCloseContext(&context);
|
||||
if (new_url != NULL) free(new_url);
|
||||
DEBUG("httpcBeginRequest %.8lx\n", ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
ret = httpcGetResponseStatusCode(&context, &status_code);
|
||||
if(ret!=0){
|
||||
httpcCloseContext(&context);
|
||||
if(new_url!=NULL) free(new_url);
|
||||
DEBUG("httpcGetResponseStatusCode\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((status_code >= 301 && status_code <= 303) || (status_code >= 307 && status_code <= 308))
|
||||
{
|
||||
if (new_url == NULL) new_url = malloc(0x1000);
|
||||
ret = httpcGetResponseHeader(&context, "Location", new_url, 0x1000);
|
||||
url = new_url;
|
||||
httpcCloseContext(&context);
|
||||
}
|
||||
} while ((status_code >= 301 && status_code <= 303) || (status_code >= 307 && status_code <= 308));
|
||||
|
||||
if (status_code != 200)
|
||||
{
|
||||
httpcCloseContext(&context);
|
||||
if (new_url != NULL) free(new_url);
|
||||
DEBUG("status_code\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
ret = httpcGetDownloadSizeState(&context, NULL, &content_size);
|
||||
if (ret != 0)
|
||||
{
|
||||
httpcCloseContext(&context);
|
||||
if (new_url != NULL) free(new_url);
|
||||
DEBUG("httpcGetDownloadSizeState\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
*buf = malloc(0x1000);
|
||||
if (*buf == NULL)
|
||||
{
|
||||
httpcCloseContext(&context);
|
||||
free(new_url);
|
||||
DEBUG("malloc\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(filename)
|
||||
{
|
||||
char *content_disposition = calloc(1024, sizeof(char));
|
||||
ret = httpcGetResponseHeader(&context, "Content-Disposition", content_disposition, 1024);
|
||||
if (ret != 0)
|
||||
{
|
||||
free(content_disposition);
|
||||
free(new_url);
|
||||
free(*buf);
|
||||
DEBUG("httpcGetResponseHeader\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
char * tok = strtok(content_disposition, "\"");
|
||||
tok = strtok(NULL, "\"");
|
||||
|
||||
if(!(tok))
|
||||
{
|
||||
free(content_disposition);
|
||||
free(new_url);
|
||||
free(*buf);
|
||||
throw_error("Target is not valid!", ERROR_LEVEL_WARNING);
|
||||
DEBUG("filename\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *illegal_characters = "\"?;:/\\+";
|
||||
for (size_t i = 0; i < strlen(tok); i++)
|
||||
{
|
||||
for (size_t n = 0; n < strlen(illegal_characters); n++)
|
||||
{
|
||||
if ((tok)[i] == illegal_characters[n])
|
||||
{
|
||||
(tok)[i] = '-';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*filename = calloc(1024, sizeof(char));
|
||||
strcpy(*filename, tok);
|
||||
free(content_disposition);
|
||||
}
|
||||
|
||||
do {
|
||||
ret = httpcDownloadData(&context, (*(u8**)buf) + size, 0x1000, &read_size);
|
||||
size += read_size;
|
||||
|
||||
if (ret == (s32)HTTPC_RESULTCODE_DOWNLOADPENDING)
|
||||
{
|
||||
last_buf = *buf;
|
||||
*buf = realloc(*buf, size + 0x1000);
|
||||
if (*buf == NULL)
|
||||
{
|
||||
httpcCloseContext(&context);
|
||||
free(new_url);
|
||||
free(last_buf);
|
||||
DEBUG("NULL\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
} while (ret == (s32)HTTPC_RESULTCODE_DOWNLOADPENDING);
|
||||
|
||||
last_buf = *buf;
|
||||
*buf = realloc(*buf, size);
|
||||
if (*buf == NULL)
|
||||
{
|
||||
httpcCloseContext(&context);
|
||||
free(new_url);
|
||||
free(last_buf);
|
||||
DEBUG("realloc\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
httpcCloseContext(&context);
|
||||
free(new_url);
|
||||
|
||||
return size;
|
||||
}
|
||||
@@ -26,87 +26,105 @@
|
||||
#include "splashes.h"
|
||||
#include "unicode.h"
|
||||
#include "fs.h"
|
||||
#include "draw.h"
|
||||
|
||||
Result get_splashes(Splash_s** splashes_list, int *splash_count)
|
||||
{
|
||||
Result res = 0;
|
||||
Handle dir_handle;
|
||||
res = FSUSER_OpenDirectory(&dir_handle, ArchiveSD, fsMakePath(PATH_ASCII, SPLASHES_PATH));
|
||||
if (R_FAILED(res))
|
||||
return res;
|
||||
|
||||
u32 entries_read = 1;
|
||||
while (entries_read)
|
||||
{
|
||||
FS_DirectoryEntry entry = {0};
|
||||
res = FSDIR_Read(dir_handle, &entries_read, 1, &entry);
|
||||
if (R_FAILED(res) || entries_read == 0)
|
||||
break;
|
||||
|
||||
if (!(entry.attributes & FS_ATTRIBUTE_DIRECTORY))
|
||||
continue;
|
||||
|
||||
*splash_count += entries_read;
|
||||
*splashes_list= realloc(*splashes_list, (*splash_count) * sizeof(Splash_s));
|
||||
if (splashes_list == NULL)
|
||||
break;
|
||||
|
||||
Splash_s *current_splash = &(*splashes_list)[*splash_count-1];
|
||||
memset(current_splash, 0, sizeof(Splash_s));
|
||||
|
||||
u16 splash_path[0x106] = {0};
|
||||
struacat(splash_path, SPLASHES_PATH);
|
||||
strucat(splash_path, entry.name);
|
||||
u16 top_path[0x106] = {0};
|
||||
memcpy(top_path, splash_path, 0x106);
|
||||
struacat(top_path, "/splash.bin");
|
||||
u16 bottom_path[0x106] = {0};
|
||||
memcpy(bottom_path, splash_path, 0x106);
|
||||
struacat(bottom_path, "/splashbottom.bin");
|
||||
|
||||
char *temp_buf = NULL;
|
||||
u32 bytes = file_to_buf(fsMakePath(PATH_UTF16, top_path), ArchiveSD, &temp_buf);
|
||||
if (!bytes)
|
||||
{
|
||||
memset(top_path, 0, 0x106 * sizeof(u16));
|
||||
}
|
||||
free(temp_buf);
|
||||
temp_buf = NULL;
|
||||
bytes = file_to_buf(fsMakePath(PATH_UTF16, bottom_path), ArchiveSD, &temp_buf);
|
||||
if (!bytes)
|
||||
{
|
||||
memset(bottom_path, 0, 0x106 * sizeof(u16));
|
||||
}
|
||||
free(temp_buf);
|
||||
memcpy(current_splash->name, entry.name, 0x106);
|
||||
memcpy(current_splash->top_path, top_path, 0x106);
|
||||
memcpy(current_splash->bottom_path, bottom_path, 0x106);
|
||||
}
|
||||
FSDIR_Close(dir_handle);
|
||||
|
||||
return res;
|
||||
}
|
||||
void splash_delete()
|
||||
void splash_delete(void)
|
||||
{
|
||||
remove("/luma/splash.bin");
|
||||
remove("/luma/splashbottom.bin");
|
||||
}
|
||||
void splash_install(Splash_s splash_to_install)
|
||||
|
||||
void splash_install(Entry_s splash)
|
||||
{
|
||||
char *screen_buf;
|
||||
u32 size = file_to_buf(fsMakePath(PATH_UTF16, splash_to_install.top_path), ArchiveSD, &screen_buf);
|
||||
if (size)
|
||||
char *screen_buf = NULL;
|
||||
|
||||
u32 size = load_data("/splash.bin", splash, &screen_buf);
|
||||
if(size != 0)
|
||||
{
|
||||
remake_file("/luma/splash.bin", ArchiveSD, size);
|
||||
buf_to_file(size, "/luma/splash.bin", ArchiveSD, screen_buf);
|
||||
free(screen_buf);
|
||||
}
|
||||
|
||||
size = file_to_buf(fsMakePath(PATH_UTF16, splash_to_install.bottom_path), ArchiveSD, &screen_buf);
|
||||
u32 bottom_size = load_data("/splashbottom.bin", splash, &screen_buf);
|
||||
if(bottom_size != 0)
|
||||
{
|
||||
remake_file("/luma/splashbottom.bin", ArchiveSD, bottom_size);
|
||||
buf_to_file(bottom_size, "/luma/splashbottom.bin", ArchiveSD, screen_buf);
|
||||
}
|
||||
|
||||
if(size == 0 && bottom_size == 0)
|
||||
{
|
||||
throw_error("No splash.bin or splashbottom.bin found.\nIs this a splash?", ERROR_LEVEL_WARNING);
|
||||
}
|
||||
else
|
||||
{
|
||||
char *config_buf;
|
||||
size = file_to_buf(fsMakePath(PATH_ASCII, "/luma/config.bin"), ArchiveSD, &config_buf);
|
||||
if(size)
|
||||
{
|
||||
remake_file("/luma/splashbottom.bin", ArchiveSD, size);
|
||||
buf_to_file(size, "/luma/splashbottom.bin", ArchiveSD, screen_buf);
|
||||
free(screen_buf);
|
||||
if(config_buf[0xC] == 0)
|
||||
{
|
||||
free(config_buf);
|
||||
throw_error("WARNING: Splashes are disabled in Luma Config", ERROR_LEVEL_WARNING);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void splash_check_installed(void * void_arg)
|
||||
{
|
||||
Thread_Arg_s * arg = (Thread_Arg_s *)void_arg;
|
||||
Entry_List_s * list = (Entry_List_s *)arg->thread_arg;
|
||||
if(list == NULL || list->entries == NULL) return;
|
||||
|
||||
#ifndef CITRA_MODE
|
||||
char * top_buf = NULL;
|
||||
u32 top_size = file_to_buf(fsMakePath(PATH_ASCII, "/luma/splash.bin"), ArchiveSD, &top_buf);
|
||||
char * bottom_buf = NULL;
|
||||
u32 bottom_size = file_to_buf(fsMakePath(PATH_ASCII, "/luma/splashbottom.bin"), ArchiveSD, &bottom_buf);
|
||||
|
||||
if(!top_size && !bottom_size)
|
||||
{
|
||||
free(top_buf);
|
||||
free(bottom_buf);
|
||||
return;
|
||||
}
|
||||
|
||||
#define HASH_SIZE_BYTES 256/8
|
||||
u8 top_hash[HASH_SIZE_BYTES] = {0};
|
||||
FSUSER_UpdateSha256Context(top_buf, top_size, top_hash);
|
||||
free(top_buf);
|
||||
top_buf = NULL;
|
||||
u8 bottom_hash[HASH_SIZE_BYTES] = {0};
|
||||
FSUSER_UpdateSha256Context(bottom_buf, bottom_size, bottom_hash);
|
||||
free(bottom_buf);
|
||||
bottom_buf = NULL;
|
||||
|
||||
for(int i = 0; i < list->entries_count && arg->run_thread; i++)
|
||||
{
|
||||
Entry_s * splash = &list->entries[i];
|
||||
top_size = load_data("/splash.bin", *splash, &top_buf);
|
||||
bottom_size = load_data("/splashbottom.bin", *splash, &bottom_buf);
|
||||
|
||||
if(!top_size && !bottom_size)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
u8 splash_top_hash[HASH_SIZE_BYTES] = {0};
|
||||
FSUSER_UpdateSha256Context(top_buf, top_size, splash_top_hash);
|
||||
free(top_buf);
|
||||
top_buf = NULL;
|
||||
u8 splash_bottom_hash[HASH_SIZE_BYTES] = {0};
|
||||
FSUSER_UpdateSha256Context(bottom_buf, bottom_size, splash_bottom_hash);
|
||||
free(bottom_buf);
|
||||
bottom_buf = NULL;
|
||||
|
||||
if(!memcmp(splash_bottom_hash, bottom_hash, HASH_SIZE_BYTES) && !memcmp(splash_top_hash, top_hash, HASH_SIZE_BYTES))
|
||||
{
|
||||
splash->installed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
697
source/themes.c
@@ -27,517 +27,312 @@
|
||||
#include "themes.h"
|
||||
#include "unicode.h"
|
||||
#include "fs.h"
|
||||
#include <time.h>
|
||||
#include "draw.h"
|
||||
|
||||
#include "pp2d/pp2d/pp2d.h"
|
||||
#include "pp2d/pp2d/lodepng.h"
|
||||
#define BODY_CACHE_SIZE 0x150000
|
||||
#define BGM_MAX_SIZE 0x337000
|
||||
|
||||
void load_theme_preview(Theme_s *theme)
|
||||
{
|
||||
//free the previously loaded preview. wont do anything if there wasnt one
|
||||
pp2d_free_texture(TEXTURE_PREVIEW);
|
||||
|
||||
char *preview_buffer = NULL;
|
||||
u64 size = 0;
|
||||
if (!(theme->is_zip))
|
||||
{
|
||||
u16 path_to_preview[0x106] = {0};
|
||||
strucat(path_to_preview, theme->path);
|
||||
struacat(path_to_preview, "/preview.png");
|
||||
size = file_to_buf(fsMakePath(PATH_UTF16, path_to_preview), ArchiveSD, &preview_buffer);
|
||||
} else {
|
||||
size = zip_file_to_buf("preview.png", theme->path, &preview_buffer);
|
||||
}
|
||||
|
||||
if (!size)
|
||||
{
|
||||
free(preview_buffer);
|
||||
return;
|
||||
}
|
||||
|
||||
u8 * image = NULL;
|
||||
unsigned int width = 0, height = 0;
|
||||
|
||||
int result = lodepng_decode32(&image, &width, &height, (u8*)preview_buffer, size);
|
||||
if (result == 0) // no error
|
||||
{
|
||||
for (u32 i = 0; i < width; i++)
|
||||
{
|
||||
for (u32 j = 0; j < height; j++)
|
||||
{
|
||||
u32 p = (i + j*width) * 4;
|
||||
|
||||
u8 r = *(u8*)(image + p);
|
||||
u8 g = *(u8*)(image + p + 1);
|
||||
u8 b = *(u8*)(image + p + 2);
|
||||
u8 a = *(u8*)(image + p + 3);
|
||||
|
||||
*(image + p) = a;
|
||||
*(image + p + 1) = b;
|
||||
*(image + p + 2) = g;
|
||||
*(image + p + 3) = r;
|
||||
}
|
||||
}
|
||||
|
||||
theme->has_preview = true;
|
||||
pp2d_load_texture_memory(TEXTURE_PREVIEW, image, (u32)width, (u32)height);
|
||||
theme->preview_offset = (width-400)/2;
|
||||
}
|
||||
|
||||
free(image);
|
||||
free(preview_buffer);
|
||||
}
|
||||
|
||||
static void parse_smdh(Theme_s *theme, ssize_t textureID, u16 *dir_name)
|
||||
{
|
||||
char *info_buffer = NULL;
|
||||
u64 size = 0;
|
||||
if (!(theme->is_zip))
|
||||
{
|
||||
u16 path_to_smdh[0x106] = {0};
|
||||
strucat(path_to_smdh, theme->path);
|
||||
struacat(path_to_smdh, "/info.smdh");
|
||||
|
||||
size = file_to_buf(fsMakePath(PATH_UTF16, path_to_smdh), ArchiveSD, &info_buffer);
|
||||
} else {
|
||||
size = zip_file_to_buf("info.smdh", theme->path, &info_buffer);
|
||||
}
|
||||
|
||||
if (!size)
|
||||
{
|
||||
free(info_buffer);
|
||||
memset(theme->name, 0, 0x80);
|
||||
memset(theme->desc, 0, 0x100);
|
||||
memset(theme->author, 0, 0x80);
|
||||
memcpy(theme->name, dir_name, 0x80);
|
||||
utf8_to_utf16(theme->desc, (u8*)"No description", 0x100);
|
||||
utf8_to_utf16(theme->author, (u8*)"Unknown author", 0x80);
|
||||
theme->placeholder_color = RGBA8(rand() % 255, rand() % 255, rand() % 255, 255);
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(theme->name, info_buffer + 0x08, 0x80);
|
||||
memcpy(theme->desc, info_buffer + 0x88, 0x100);
|
||||
memcpy(theme->author, info_buffer + 0x188, 0x80);
|
||||
|
||||
u16 *icon_data = malloc(0x1200);
|
||||
memcpy(icon_data, info_buffer + 0x24C0, 0x1200);
|
||||
|
||||
const u32 width = 48, height = 48;
|
||||
u32 *image = malloc(width*height*sizeof(u32));
|
||||
|
||||
for (u32 x = 0; x < width; x++)
|
||||
{
|
||||
for (u32 y = 0; y < height; y++)
|
||||
{
|
||||
unsigned int dest_pixel = (x + y*width);
|
||||
unsigned int source_pixel = (((y >> 3) * (width >> 3) + (x >> 3)) << 6) + ((x & 1) | ((y & 1) << 1) | ((x & 2) << 1) | ((y & 2) << 2) | ((x & 4) << 2) | ((y & 4) << 3));
|
||||
|
||||
u8 r = ((icon_data[source_pixel] >> 11) & 0b11111) << 3;
|
||||
u8 g = ((icon_data[source_pixel] >> 5) & 0b111111) << 2;
|
||||
u8 b = (icon_data[source_pixel] & 0b11111) << 3;
|
||||
u8 a = 0xFF;
|
||||
|
||||
image[dest_pixel] = (r << 24) | (g << 16) | (b << 8) | a;
|
||||
}
|
||||
}
|
||||
|
||||
pp2d_load_texture_memory(textureID, (u8*)image, (u32)width, (u32)height);
|
||||
theme->icon_id = textureID;
|
||||
|
||||
free(image);
|
||||
free(icon_data);
|
||||
free(info_buffer);
|
||||
}
|
||||
|
||||
Result get_themes(Theme_s **themes_list, int *theme_count)
|
||||
static Result install_theme_internal(Entry_List_s themes, int installmode)
|
||||
{
|
||||
Result res = 0;
|
||||
Handle dir_handle;
|
||||
res = FSUSER_OpenDirectory(&dir_handle, ArchiveSD, fsMakePath(PATH_ASCII, THEMES_PATH));
|
||||
if (R_FAILED(res))
|
||||
return res;
|
||||
|
||||
u32 entries_read = 1;
|
||||
while (entries_read)
|
||||
{
|
||||
FS_DirectoryEntry entry = {0};
|
||||
res = FSDIR_Read(dir_handle, &entries_read, 1, &entry);
|
||||
if (R_FAILED(res) || entries_read == 0)
|
||||
break;
|
||||
|
||||
if (!(entry.attributes & FS_ATTRIBUTE_DIRECTORY) && strcmp(entry.shortExt, "ZIP"))
|
||||
continue;
|
||||
|
||||
*theme_count += entries_read;
|
||||
*themes_list = realloc(*themes_list, (*theme_count) * sizeof(Theme_s));
|
||||
if (*themes_list == NULL)
|
||||
break;
|
||||
|
||||
Theme_s* current_theme = &(*themes_list)[*theme_count-1];
|
||||
memset(current_theme, 0, sizeof(Theme_s));
|
||||
|
||||
u16 theme_path[0x106] = {0};
|
||||
struacat(theme_path, THEMES_PATH);
|
||||
strucat(theme_path, entry.name);
|
||||
|
||||
char pathchar[0x106] = {0};
|
||||
utf16_to_utf8((u8*)pathchar, theme_path, 0x106);
|
||||
|
||||
memcpy(current_theme->path, theme_path, 0x106 * sizeof(u16));
|
||||
current_theme->is_zip = !strcmp(entry.shortExt, "ZIP");
|
||||
|
||||
ssize_t iconID = TEXTURE_PREVIEW + *theme_count;
|
||||
parse_smdh(current_theme, iconID, entry.name);
|
||||
}
|
||||
|
||||
FSDIR_Close(dir_handle);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void add_theme(Theme_s **themes_list, int *theme_count, char *path, char *filename)
|
||||
{
|
||||
*theme_count += 1;
|
||||
*themes_list = realloc(*themes_list, (*theme_count) * sizeof(Theme_s));
|
||||
|
||||
Theme_s *current_theme = &(*themes_list)[*theme_count - 1];
|
||||
memset(current_theme, 0, sizeof(Theme_s));
|
||||
|
||||
u16 theme_path[0x106] = {0};
|
||||
utf8_to_utf16(theme_path, (u8*)path, 0x106);
|
||||
|
||||
u16 ufilename[0x106] = {0};
|
||||
utf8_to_utf16(ufilename, (u8*)filename, 0x106);
|
||||
|
||||
memcpy(current_theme->path, theme_path, 0x106 * sizeof(u16));
|
||||
current_theme->is_zip = true;
|
||||
|
||||
ssize_t iconID = TEXTURE_PREVIEW + *theme_count;
|
||||
parse_smdh(current_theme, iconID, ufilename);
|
||||
}
|
||||
|
||||
Result bgm_install(Theme_s bgm_to_install)
|
||||
{
|
||||
char *savedata_buf;
|
||||
char *thememanage_buf;
|
||||
char *music;
|
||||
char* music = NULL;
|
||||
u32 music_size = 0;
|
||||
u32 savedata_size;
|
||||
u32 shuffle_music_sizes[MAX_SHUFFLE_THEMES] = {0};
|
||||
char* body = NULL;
|
||||
u32 body_size = 0;
|
||||
u32 shuffle_body_sizes[MAX_SHUFFLE_THEMES] = {0};
|
||||
|
||||
savedata_size = file_to_buf(fsMakePath(PATH_ASCII, "/SaveData.dat"), ArchiveHomeExt, &savedata_buf);
|
||||
savedata_buf[0x141b] = 0;
|
||||
memset(&savedata_buf[0x13b8], 0, 8);
|
||||
savedata_buf[0x13bd] = 3;
|
||||
savedata_buf[0x13b8] = 0xff;
|
||||
Result result = buf_to_file(savedata_size, "/SaveData.dat", ArchiveHomeExt, savedata_buf);
|
||||
free(savedata_buf);
|
||||
|
||||
if (!R_SUCCEEDED(result)) return result;
|
||||
|
||||
if (bgm_to_install.is_zip) // Same as above but this time with bgm
|
||||
if(installmode & THEME_INSTALL_SHUFFLE)
|
||||
{
|
||||
music_size = zip_file_to_buf("bgm.bcstm", bgm_to_install.path, &music);
|
||||
} else {
|
||||
u16 path[0x106] = {0};
|
||||
memcpy(path, bgm_to_install.path, 0x106 * sizeof(u16));
|
||||
struacat(path, "/bgm.bcstm");
|
||||
music_size = file_to_buf(fsMakePath(PATH_UTF16, path), ArchiveSD, &music);
|
||||
if(themes.shuffle_count < 2)
|
||||
{
|
||||
DEBUG("not enough themes selected for shuffle\n");
|
||||
return MAKERESULT(RL_USAGE, RS_INVALIDARG, RM_COMMON, RD_INVALID_SELECTION);
|
||||
}
|
||||
|
||||
if (music_size == 0)
|
||||
if(themes.shuffle_count > MAX_SHUFFLE_THEMES)
|
||||
{
|
||||
music = calloc(1, 3371008);
|
||||
} else if (music_size > 3371008) {
|
||||
free(music);
|
||||
puts("musicrip");
|
||||
return MAKERESULT(RL_PERMANENT, RS_CANCELED, RM_APPLICATION, RD_TOO_LARGE);
|
||||
DEBUG("too many themes selected for shuffle\n");
|
||||
return MAKERESULT(RL_USAGE, RS_INVALIDARG, RM_COMMON, RD_INVALID_SELECTION);
|
||||
}
|
||||
|
||||
result = buf_to_file(music_size == 0 ? 3371008 : music_size, "/BgmCache.bin", ArchiveThemeExt, music);
|
||||
free(music);
|
||||
int shuffle_count = 0;
|
||||
Handle body_cache_handle;
|
||||
|
||||
if (!R_SUCCEEDED(result)) return result;
|
||||
|
||||
file_to_buf(fsMakePath(PATH_ASCII, "/ThemeManage.bin"), ArchiveThemeExt, &thememanage_buf);
|
||||
thememanage_buf[0x00] = 1;
|
||||
thememanage_buf[0x01] = 0;
|
||||
thememanage_buf[0x02] = 0;
|
||||
thememanage_buf[0x03] = 0;
|
||||
thememanage_buf[0x04] = 0;
|
||||
thememanage_buf[0x05] = 0;
|
||||
thememanage_buf[0x06] = 0;
|
||||
thememanage_buf[0x07] = 0;
|
||||
|
||||
u32 *music_size_location = (u32*)(&thememanage_buf[0xC]);
|
||||
*music_size_location = music_size;
|
||||
|
||||
thememanage_buf[0x10] = 0xFF;
|
||||
thememanage_buf[0x14] = 0x01;
|
||||
thememanage_buf[0x18] = 0xFF;
|
||||
thememanage_buf[0x1D] = 0x02;
|
||||
|
||||
memset(&thememanage_buf[0x338], 0, 4);
|
||||
memset(&thememanage_buf[0x340], 0, 4);
|
||||
memset(&thememanage_buf[0x360], 0, 4);
|
||||
memset(&thememanage_buf[0x368], 0, 4);
|
||||
result = buf_to_file(0x800, "/ThemeManage.bin", ArchiveThemeExt, thememanage_buf);
|
||||
free(thememanage_buf);
|
||||
|
||||
if (!R_SUCCEEDED(result)) return result;
|
||||
|
||||
return 0;
|
||||
if(installmode & THEME_INSTALL_BODY)
|
||||
{
|
||||
remake_file("/BodyCache_rd.bin", ArchiveThemeExt, BODY_CACHE_SIZE * MAX_SHUFFLE_THEMES);
|
||||
FSUSER_OpenFile(&body_cache_handle, ArchiveThemeExt, fsMakePath(PATH_ASCII, "/BodyCache_rd.bin"), FS_OPEN_WRITE, 0);
|
||||
}
|
||||
|
||||
// Install a single theme
|
||||
Result single_install(Theme_s theme_to_install)
|
||||
for(int i = 0; i < themes.entries_count; i++)
|
||||
{
|
||||
char *body;
|
||||
char *music;
|
||||
char *savedata_buf;
|
||||
char *thememanage_buf;
|
||||
u32 body_size;
|
||||
u32 music_size;
|
||||
u32 savedata_size;
|
||||
Entry_s * current_theme = &themes.entries[i];
|
||||
|
||||
savedata_size = file_to_buf(fsMakePath(PATH_ASCII, "/SaveData.dat"), ArchiveHomeExt, &savedata_buf);
|
||||
savedata_buf[0x141b] = 0;
|
||||
memset(&savedata_buf[0x13b8], 0, 8);
|
||||
savedata_buf[0x13bd] = 3;
|
||||
savedata_buf[0x13b8] = 0xff;
|
||||
Result result = buf_to_file(savedata_size, "/SaveData.dat", ArchiveHomeExt, savedata_buf);
|
||||
free(savedata_buf);
|
||||
|
||||
if (!R_SUCCEEDED(result)) return result;
|
||||
|
||||
// Open body cache file. Test if theme is zipped
|
||||
if (theme_to_install.is_zip)
|
||||
if(current_theme->in_shuffle)
|
||||
{
|
||||
body_size = zip_file_to_buf("body_LZ.bin", theme_to_install.path, &body);
|
||||
}
|
||||
else
|
||||
if(installmode & THEME_INSTALL_BODY)
|
||||
{
|
||||
u16 path[0x106] = {0};
|
||||
memcpy(path, theme_to_install.path, 0x106 * sizeof(u16));
|
||||
struacat(path, "/body_lz.bin");
|
||||
body_size = file_to_buf(fsMakePath(PATH_UTF16, path), ArchiveSD, &body);
|
||||
}
|
||||
|
||||
body_size = load_data("/body_LZ.bin", *current_theme, &body);
|
||||
if(body_size == 0)
|
||||
{
|
||||
free(body);
|
||||
puts("bodyrip");
|
||||
DEBUG("body not found\n");
|
||||
throw_error("No body_LZ.bin found - is this a theme?", ERROR_LEVEL_WARNING);
|
||||
return MAKERESULT(RL_PERMANENT, RS_CANCELED, RM_APPLICATION, RD_NOT_FOUND);
|
||||
}
|
||||
|
||||
result = buf_to_file(body_size, "/BodyCache.bin", ArchiveThemeExt, body); // Write body data to file
|
||||
shuffle_body_sizes[shuffle_count] = body_size;
|
||||
FSFILE_Write(body_cache_handle, NULL, BODY_CACHE_SIZE * shuffle_count, body, body_size, FS_WRITE_FLUSH);
|
||||
free(body);
|
||||
|
||||
if (!R_SUCCEEDED(result)) return result;
|
||||
|
||||
if (theme_to_install.is_zip) // Same as above but this time with bgm
|
||||
{
|
||||
music_size = zip_file_to_buf("bgm.bcstm", theme_to_install.path, &music);
|
||||
} else {
|
||||
u16 path[0x106] = {0};
|
||||
memcpy(path, theme_to_install.path, 0x106 * sizeof(u16));
|
||||
struacat(path, "/bgm.bcstm");
|
||||
music_size = file_to_buf(fsMakePath(PATH_UTF16, path), ArchiveSD, &music);
|
||||
}
|
||||
|
||||
if (music_size == 0)
|
||||
if(installmode & THEME_INSTALL_BGM)
|
||||
{
|
||||
char bgm_cache_path[26] = {0};
|
||||
sprintf(bgm_cache_path, "/BgmCache_%.2i.bin", shuffle_count);
|
||||
music_size = load_data("/bgm.bcstm", *current_theme, &music);
|
||||
|
||||
if(music_size > BGM_MAX_SIZE)
|
||||
{
|
||||
music = calloc(1, 3371008);
|
||||
} else if (music_size > 3371008) {
|
||||
free(music);
|
||||
puts("musicrip");
|
||||
DEBUG("bgm too big\n");
|
||||
return MAKERESULT(RL_PERMANENT, RS_CANCELED, RM_APPLICATION, RD_TOO_LARGE);
|
||||
}
|
||||
|
||||
result = buf_to_file(music_size == 0 ? 3371008 : music_size, "/BgmCache.bin", ArchiveThemeExt, music);
|
||||
shuffle_music_sizes[shuffle_count] = music_size;
|
||||
remake_file(bgm_cache_path, ArchiveThemeExt, BGM_MAX_SIZE);
|
||||
buf_to_file(music_size, bgm_cache_path, ArchiveThemeExt, music);
|
||||
free(music);
|
||||
}
|
||||
|
||||
shuffle_count++;
|
||||
}
|
||||
}
|
||||
|
||||
if(installmode & THEME_INSTALL_BGM)
|
||||
{
|
||||
for(int i = shuffle_count; i < MAX_SHUFFLE_THEMES; i++)
|
||||
{
|
||||
char bgm_cache_path[26] = {0};
|
||||
sprintf(bgm_cache_path, "/BgmCache_%.2i.bin", i);
|
||||
remake_file(bgm_cache_path, ArchiveThemeExt, BGM_MAX_SIZE);
|
||||
}
|
||||
}
|
||||
|
||||
if(installmode & THEME_INSTALL_BODY)
|
||||
{
|
||||
FSFILE_Close(body_cache_handle);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Entry_s current_theme = themes.entries[themes.selected_entry];
|
||||
|
||||
if(installmode & THEME_INSTALL_BODY)
|
||||
{
|
||||
body_size = load_data("/body_LZ.bin", current_theme, &body);
|
||||
if(body_size == 0)
|
||||
{
|
||||
free(body);
|
||||
DEBUG("body not found\n");
|
||||
throw_error("No body_LZ.bin found - is this a theme?", ERROR_LEVEL_WARNING);
|
||||
return MAKERESULT(RL_PERMANENT, RS_CANCELED, RM_APPLICATION, RD_NOT_FOUND);
|
||||
}
|
||||
|
||||
res = buf_to_file(body_size, "/BodyCache.bin", ArchiveThemeExt, body); // Write body data to file
|
||||
free(body);
|
||||
|
||||
if(R_FAILED(res)) return res;
|
||||
}
|
||||
|
||||
if(installmode & THEME_INSTALL_BGM)
|
||||
{
|
||||
music_size = load_data("/bgm.bcstm", current_theme, &music);
|
||||
if(music_size > BGM_MAX_SIZE)
|
||||
{
|
||||
free(music);
|
||||
DEBUG("bgm too big\n");
|
||||
return MAKERESULT(RL_PERMANENT, RS_CANCELED, RM_APPLICATION, RD_TOO_LARGE);
|
||||
}
|
||||
|
||||
res = buf_to_file(music_size, "/BgmCache.bin", ArchiveThemeExt, music);
|
||||
free(music);
|
||||
|
||||
if (!R_SUCCEEDED(result)) return result;
|
||||
if(R_FAILED(res)) return res;
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------
|
||||
char* thememanage_buf = NULL;
|
||||
file_to_buf(fsMakePath(PATH_ASCII, "/ThemeManage.bin"), ArchiveThemeExt, &thememanage_buf);
|
||||
thememanage_buf[0x00] = 1;
|
||||
thememanage_buf[0x01] = 0;
|
||||
thememanage_buf[0x02] = 0;
|
||||
thememanage_buf[0x03] = 0;
|
||||
thememanage_buf[0x04] = 0;
|
||||
thememanage_buf[0x05] = 0;
|
||||
thememanage_buf[0x06] = 0;
|
||||
thememanage_buf[0x07] = 0;
|
||||
ThemeManage_bin_s * theme_manage = (ThemeManage_bin_s *)thememanage_buf;
|
||||
|
||||
u32 *body_size_location = (u32*)(&thememanage_buf[0x8]);
|
||||
u32 *music_size_location = (u32*)(&thememanage_buf[0xC]);
|
||||
*body_size_location = body_size;
|
||||
*music_size_location = music_size;
|
||||
theme_manage->unk1 = 1;
|
||||
theme_manage->unk2 = 0;
|
||||
|
||||
thememanage_buf[0x10] = 0xFF;
|
||||
thememanage_buf[0x14] = 0x01;
|
||||
thememanage_buf[0x18] = 0xFF;
|
||||
thememanage_buf[0x1D] = 0x02;
|
||||
if(installmode & THEME_INSTALL_SHUFFLE)
|
||||
{
|
||||
theme_manage->music_size = 0;
|
||||
theme_manage->body_size = 0;
|
||||
|
||||
memset(&thememanage_buf[0x338], 0, 4);
|
||||
memset(&thememanage_buf[0x340], 0, 4);
|
||||
memset(&thememanage_buf[0x360], 0, 4);
|
||||
memset(&thememanage_buf[0x368], 0, 4);
|
||||
result = buf_to_file(0x800, "/ThemeManage.bin", ArchiveThemeExt, thememanage_buf);
|
||||
for(int i = 0; i < MAX_SHUFFLE_THEMES; i++)
|
||||
{
|
||||
theme_manage->shuffle_body_sizes[i] = shuffle_body_sizes[i];
|
||||
theme_manage->shuffle_music_sizes[i] = shuffle_music_sizes[i];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(installmode & THEME_INSTALL_BGM)
|
||||
theme_manage->music_size = music_size;
|
||||
if(installmode & THEME_INSTALL_BODY)
|
||||
theme_manage->body_size = body_size;
|
||||
}
|
||||
|
||||
theme_manage->unk3 = 0xFF;
|
||||
theme_manage->unk4 = 1;
|
||||
theme_manage->dlc_theme_content_index = 0xFF;
|
||||
theme_manage->use_theme_cache = 0x0200;
|
||||
|
||||
res = buf_to_file(0x800, "/ThemeManage.bin", ArchiveThemeExt, thememanage_buf);
|
||||
free(thememanage_buf);
|
||||
if(R_FAILED(res)) return res;
|
||||
//----------------------------------------
|
||||
|
||||
if (!R_SUCCEEDED(result)) return result;
|
||||
//----------------------------------------
|
||||
char* savedata_buf = NULL;
|
||||
u32 savedata_size = file_to_buf(fsMakePath(PATH_ASCII, "/SaveData.dat"), ArchiveHomeExt, &savedata_buf);
|
||||
SaveData_dat_s* savedata = (SaveData_dat_s*)savedata_buf;
|
||||
|
||||
memset(&savedata->theme_entry, 0, sizeof(ThemeEntry_s));
|
||||
savedata->theme_entry.type = 3;
|
||||
savedata->theme_entry.index = 0xff;
|
||||
|
||||
savedata->shuffle = (installmode & THEME_INSTALL_SHUFFLE);
|
||||
if(installmode & THEME_INSTALL_SHUFFLE)
|
||||
{
|
||||
memset(savedata->shuffle_themes, 0, sizeof(ThemeEntry_s)*MAX_SHUFFLE_THEMES);
|
||||
for(int i = 0; i < themes.shuffle_count; i++)
|
||||
{
|
||||
savedata->shuffle_themes[i].type = 3;
|
||||
savedata->shuffle_themes[i].index = i;
|
||||
}
|
||||
}
|
||||
|
||||
res = buf_to_file(savedata_size, "/SaveData.dat", ArchiveHomeExt, savedata_buf);
|
||||
free(savedata_buf);
|
||||
if(R_FAILED(res)) return res;
|
||||
//----------------------------------------
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Result shuffle_install(Theme_s *themes_list, int theme_count)
|
||||
inline Result theme_install(Entry_s theme)
|
||||
{
|
||||
u8 count = 0;
|
||||
Theme_s *shuffle_themes[10] = {0};
|
||||
u32 body_sizes[10] = {0};
|
||||
u32 bgm_sizes[10] = {0};
|
||||
for (int i = 0; i < theme_count; i++)
|
||||
{
|
||||
if (count > 10) return MAKERESULT(RL_USAGE, RS_INVALIDARG, RM_COMMON, RD_INVALID_SELECTION);
|
||||
if (themes_list[i].in_shuffle)
|
||||
{
|
||||
shuffle_themes[count++] = &themes_list[i];
|
||||
themes_list[i].in_shuffle = false;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
printu(shuffle_themes[i]->name);
|
||||
Entry_List_s list = {0};
|
||||
list.entries_count = 1;
|
||||
list.entries = &theme;
|
||||
list.selected_entry = 0;
|
||||
return install_theme_internal(list, THEME_INSTALL_BODY | THEME_INSTALL_BGM);
|
||||
}
|
||||
|
||||
char *savedata_buf;
|
||||
u32 size = file_to_buf(fsMakePath(PATH_ASCII, "/SaveData.dat"), ArchiveHomeExt, &savedata_buf);
|
||||
if (size == 0)
|
||||
inline Result bgm_install(Entry_s theme)
|
||||
{
|
||||
return MAKERESULT(RL_USAGE, RS_CANCELED, RM_APPLICATION, RD_NOT_FOUND);
|
||||
Entry_List_s list = {0};
|
||||
list.entries_count = 1;
|
||||
list.entries = &theme;
|
||||
list.selected_entry = 0;
|
||||
return install_theme_internal(list, THEME_INSTALL_BGM);
|
||||
}
|
||||
|
||||
savedata_buf[0x141b] = 1;
|
||||
memset(&savedata_buf[0x13b8], 0, 8);
|
||||
savedata_buf[0x13bd] = 3;
|
||||
savedata_buf[0x13b8] = 0xff;
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
inline Result no_bgm_install(Entry_s theme)
|
||||
{
|
||||
memset(&savedata_buf[0x13c0 + 0x8 * i], 0, 8); // clear any existing theme structure. 8 is the length of the theme structure, so 8 * i is the pos of the current one
|
||||
if (count > i) // if we are still installing themes...
|
||||
{
|
||||
savedata_buf[0x13c0 + (8 * i)] = i; // index
|
||||
savedata_buf[0x13c0 + (8 * i) + 5] = 3; // persistence (?)
|
||||
}
|
||||
Entry_List_s list = {0};
|
||||
list.entries_count = 1;
|
||||
list.entries = &theme;
|
||||
list.selected_entry = 0;
|
||||
return install_theme_internal(list, THEME_INSTALL_BODY);
|
||||
}
|
||||
|
||||
Result result = buf_to_file(size, "/SaveData.dat", ArchiveHomeExt, savedata_buf);
|
||||
inline Result shuffle_install(Entry_List_s themes)
|
||||
{
|
||||
return install_theme_internal(themes, THEME_INSTALL_SHUFFLE | THEME_INSTALL_BODY | THEME_INSTALL_BGM);
|
||||
}
|
||||
|
||||
void themes_check_installed(void * void_arg)
|
||||
{
|
||||
Thread_Arg_s * arg = (Thread_Arg_s *)void_arg;
|
||||
Entry_List_s * list = (Entry_List_s *)arg->thread_arg;
|
||||
if(list == NULL || list->entries == NULL) return;
|
||||
|
||||
#ifndef CITRA_MODE
|
||||
char* savedata_buf = NULL;
|
||||
u32 savedata_size = file_to_buf(fsMakePath(PATH_ASCII, "/SaveData.dat"), ArchiveHomeExt, &savedata_buf);
|
||||
if(!savedata_size) return;
|
||||
SaveData_dat_s* savedata = (SaveData_dat_s*)savedata_buf;
|
||||
bool shuffle = savedata->shuffle;
|
||||
free(savedata_buf);
|
||||
|
||||
if (!R_SUCCEEDED(result)) return result;
|
||||
#define HASH_SIZE_BYTES 256/8
|
||||
u8 body_hash[MAX_SHUFFLE_THEMES][HASH_SIZE_BYTES];
|
||||
memset(body_hash, 0, MAX_SHUFFLE_THEMES*HASH_SIZE_BYTES);
|
||||
|
||||
remake_file("/BodyCache_rd.bin", ArchiveThemeExt, 0x150000 * 10); // Enough space for 10 theme files
|
||||
Handle body_cache_handle;
|
||||
FSUSER_OpenFile(&body_cache_handle, ArchiveThemeExt, fsMakePath(PATH_ASCII, "/BodyCache_rd.bin"), FS_OPEN_WRITE, 0);
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
if (count > i)
|
||||
{
|
||||
if (shuffle_themes[i]->is_zip)
|
||||
{
|
||||
char *body_buf;
|
||||
u32 body_size = zip_file_to_buf("body_LZ.bin", shuffle_themes[i]->path, &body_buf);
|
||||
body_sizes[i] = body_size;
|
||||
FSFILE_Write(body_cache_handle, NULL, 0x150000 * i, body_buf, body_size, FS_WRITE_FLUSH);
|
||||
free(body_buf);
|
||||
} else {
|
||||
u16 path[0x106] = {0};
|
||||
strucat(path, shuffle_themes[i]->path);
|
||||
struacat(path, "/body_LZ.bin");
|
||||
char *body_buf;
|
||||
u32 body_size = file_to_buf(fsMakePath(PATH_UTF16, path), ArchiveSD, &body_buf);
|
||||
body_sizes[i] = body_size;
|
||||
FSFILE_Write(body_cache_handle, NULL, 0x150000 * i, body_buf, body_size, FS_WRITE_FLUSH);
|
||||
free(body_buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
char* thememanage_buf = NULL;
|
||||
u32 theme_manage_size = file_to_buf(fsMakePath(PATH_ASCII, "/ThemeManage.bin"), ArchiveThemeExt, &thememanage_buf);
|
||||
if(!theme_manage_size) return;
|
||||
ThemeManage_bin_s * theme_manage = (ThemeManage_bin_s *)thememanage_buf;
|
||||
|
||||
FSFILE_Close(body_cache_handle);
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
char bgm_cache_path[17] = {0};
|
||||
sprintf(bgm_cache_path, "/BgmCache_%.2i.bin", i);
|
||||
remake_file(bgm_cache_path, ArchiveThemeExt, 3371008);
|
||||
if (count > i)
|
||||
{
|
||||
char *music_buf;
|
||||
u32 music_size;
|
||||
|
||||
if (shuffle_themes[i]->is_zip)
|
||||
{
|
||||
music_size = zip_file_to_buf("bgm.bcstm", shuffle_themes[i]->path, &music_buf);
|
||||
} else {
|
||||
u16 path[0x106] = {0};
|
||||
strucat(path, shuffle_themes[i]->path);
|
||||
struacat(path, "/bgm.bcstm");
|
||||
music_size = file_to_buf(fsMakePath(PATH_UTF16, path), ArchiveSD, &music_buf);
|
||||
}
|
||||
|
||||
if (!music_size)
|
||||
{
|
||||
char *empty = calloc(1, 3371008);
|
||||
buf_to_file(3371008, bgm_cache_path, ArchiveThemeExt, empty);
|
||||
bgm_sizes[i] = 0;
|
||||
free(empty);
|
||||
continue;
|
||||
}
|
||||
bgm_sizes[i] = music_size;
|
||||
buf_to_file(music_size, bgm_cache_path, ArchiveThemeExt, music_buf);
|
||||
free(music_buf);
|
||||
} else {
|
||||
char *empty = calloc(1, 3371008);
|
||||
buf_to_file(3371008, bgm_cache_path, ArchiveThemeExt, empty);
|
||||
bgm_sizes[i] = 0;
|
||||
free(empty);
|
||||
}
|
||||
}
|
||||
|
||||
char *thememanage_buf;
|
||||
file_to_buf(fsMakePath(PATH_ASCII, "/ThemeManage.bin"), ArchiveThemeExt, &thememanage_buf);
|
||||
thememanage_buf[0x00] = 1; // Unknown, normally 0x1 with size of 4
|
||||
thememanage_buf[0x01] = 0;
|
||||
thememanage_buf[0x02] = 0;
|
||||
thememanage_buf[0x03] = 0;
|
||||
thememanage_buf[0x04] = 0; // Unknown, normally 0 with size of 4
|
||||
thememanage_buf[0x05] = 0;
|
||||
thememanage_buf[0x06] = 0;
|
||||
thememanage_buf[0x07] = 0;
|
||||
thememanage_buf[0x10] = 0xFF; // Unknown
|
||||
thememanage_buf[0x14] = 0x01; // Unkown
|
||||
thememanage_buf[0x18] = 0xFF; // DLC theme index - 0xFF indicates no DLC theme
|
||||
thememanage_buf[0x1D] = 0x02; // Unknown, usually 0x200 to indicate theme-cache is being used
|
||||
|
||||
u32 *bodysizeloc = (u32*) (&thememanage_buf[0x08]); // Set non-shuffle theme sizes to 0
|
||||
u32 *bgmsizeloc = (u32*) (&thememanage_buf[0x0C]);
|
||||
*bodysizeloc = (u32) 0;
|
||||
*bgmsizeloc = (u32) 0;
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
bodysizeloc = (u32*) (&thememanage_buf[0x338 + (4 * i)]); // body size info for shuffle themes starts at 0x338 and is 4 bytes for each theme
|
||||
bgmsizeloc = (u32*) (&thememanage_buf[0x360 + (4 * i)]); // same thing for bgm but starting at 0x360
|
||||
*bodysizeloc = body_sizes[i]; // We don't need to check if we've already installed all the themes because all sizes initialized to 0
|
||||
*bgmsizeloc = bgm_sizes[i];
|
||||
}
|
||||
|
||||
result = buf_to_file(0x800, "/ThemeManage.bin", ArchiveThemeExt, thememanage_buf);
|
||||
u32 single_body_size = theme_manage->body_size;
|
||||
u32 shuffle_body_sizes[MAX_SHUFFLE_THEMES] = {0};
|
||||
memcpy(shuffle_body_sizes, theme_manage->shuffle_body_sizes, sizeof(u32)*MAX_SHUFFLE_THEMES);
|
||||
free(thememanage_buf);
|
||||
|
||||
if (!R_SUCCEEDED(result)) return result;
|
||||
if(shuffle)
|
||||
{
|
||||
char * body_buf = NULL;
|
||||
u32 body_cache_size = file_to_buf(fsMakePath(PATH_ASCII, "/BodyCache_rd.bin"), ArchiveThemeExt, &body_buf);
|
||||
if(!body_cache_size) return;
|
||||
|
||||
return MAKERESULT(RL_SUCCESS, RS_SUCCESS, RM_COMMON, RD_SUCCESS);
|
||||
for(int i = 0; i < MAX_SHUFFLE_THEMES; i++)
|
||||
{
|
||||
FSUSER_UpdateSha256Context(body_buf + BODY_CACHE_SIZE*i, shuffle_body_sizes[i], body_hash[i]);
|
||||
}
|
||||
|
||||
free(body_buf);
|
||||
}
|
||||
else
|
||||
{
|
||||
char * body_buf = NULL;
|
||||
u32 body_size = file_to_buf(fsMakePath(PATH_ASCII, "/BodyCache.bin"), ArchiveThemeExt, &body_buf);
|
||||
if(!body_size) return;
|
||||
|
||||
u8 * hash = body_hash[0];
|
||||
FSUSER_UpdateSha256Context(body_buf, single_body_size, hash);
|
||||
free(body_buf);
|
||||
}
|
||||
|
||||
int total_installed = 0;
|
||||
for(int i = 0; i < list->entries_count && total_installed < MAX_SHUFFLE_THEMES && arg->run_thread; i++)
|
||||
{
|
||||
Entry_s * theme = &list->entries[i];
|
||||
char * theme_body = NULL;
|
||||
u32 theme_body_size = load_data("/body_LZ.bin", *theme, &theme_body);
|
||||
if(!theme_body_size) return;
|
||||
|
||||
u8 theme_body_hash[HASH_SIZE_BYTES];
|
||||
FSUSER_UpdateSha256Context(theme_body, theme_body_size, theme_body_hash);
|
||||
free(theme_body);
|
||||
|
||||
for(int j = 0; j < MAX_SHUFFLE_THEMES; j++)
|
||||
{
|
||||
if(!memcmp(body_hash[j], theme_body_hash, HASH_SIZE_BYTES))
|
||||
{
|
||||
theme->installed = true;
|
||||
total_installed++;
|
||||
if(!shuffle) break; //only need to check the first if the installed theme inst shuffle
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||