Compare commits
48 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ef456c7e9e | |||
| 1103885baf | |||
| 5564ffe31b | |||
| 97ab2307f8 | |||
|
|
47c64828a4 | ||
| d3aa231c3f | |||
|
|
3fb86c80be | ||
|
|
67566330a5 | ||
| 68805337bf | |||
|
|
416cca88d3 | ||
| 2be3bde64d | |||
| c46c5ff8cb | |||
|
|
6b5b391d7b | ||
|
|
dc1cbda232 | ||
|
|
e63a4066a1 | ||
| 2e71fc5954 | |||
| 778e1a8331 | |||
| 0871f4f30b | |||
| 62f4356a17 | |||
|
|
3e2c5994ca | ||
|
|
674fa9d9bf | ||
|
|
897dc52424 | ||
|
|
379cea8db1 | ||
|
|
e46783a3c4 | ||
|
|
3fd4548d64 | ||
|
|
34ede05b93 | ||
|
|
80b9aa9cdb | ||
|
|
33cce81914 | ||
|
|
424fffd35f | ||
|
|
5b067cfac0 | ||
|
|
539e95253c | ||
|
|
a77b29da92 | ||
|
|
dcac5401c1 | ||
|
|
1467b1f72b | ||
|
|
9199936215 | ||
|
|
91fa4fa412 | ||
|
|
1c6ae493d5 | ||
|
|
4eb969e84d | ||
|
|
70a40fae44 | ||
|
|
3d17509229 | ||
|
|
a38508c30f | ||
|
|
0ddb35d3d7 | ||
|
|
e03d150840 | ||
|
|
4607885fe6 | ||
|
|
d3a8f79958 | ||
|
|
a08c032ccc | ||
|
|
bdaa8b52cc | ||
|
|
8dc7f54f7e |
6
Makefile
@@ -49,11 +49,13 @@ 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)
|
||||
|
||||
CFLAGS += $(INCLUDE) -DARM11 -D_3DS -D_GNU_SOURCE
|
||||
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)\""
|
||||
|
||||
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ A Theme and Splashscreen Manager for the Nintendo3DS, written in C.
|
||||
* zlib, 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.
|
||||
* 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`.
|
||||
|
||||
@@ -29,8 +29,6 @@
|
||||
|
||||
#include "common.h"
|
||||
|
||||
struct quirc* context;
|
||||
u16 *buf;
|
||||
bool qr_mode;
|
||||
|
||||
void init_qr(void);
|
||||
|
||||
@@ -40,9 +40,15 @@
|
||||
#define SHUFFLE_INSTALL 1
|
||||
#define BGM_INSTALL 2
|
||||
#define UNINSTALL 3
|
||||
#define DOWNLOADING 3
|
||||
|
||||
#define ERROR 0
|
||||
#define WARNING 1
|
||||
static const int THEMES_PER_SCREEN = 4;
|
||||
|
||||
bool homebrew;
|
||||
bool splash_mode;
|
||||
|
||||
enum TextureID {
|
||||
TEXTURE_FONT_RESERVED = 0, //used by pp2d for the font
|
||||
TEXTURE_ARROW,
|
||||
|
||||
@@ -34,11 +34,11 @@
|
||||
void init_screens(void);
|
||||
void exit_screens(void);
|
||||
|
||||
void draw_themext_error(void);
|
||||
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);
|
||||
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);
|
||||
#endif
|
||||
@@ -39,7 +39,7 @@ Result close_archives(void);
|
||||
u64 file_to_buf(FS_Path path, FS_Archive archive, char** buf);
|
||||
u32 zip_file_to_buf(char *file_name, u16 *zip_path, char **buf);
|
||||
|
||||
u32 buf_to_file(u32 size, char *path, FS_Archive archive, char *buf);
|
||||
Result buf_to_file(u32 size, char *path, FS_Archive archive, char *buf);
|
||||
void remake_file(char *path, FS_Archive archive, u32 size);
|
||||
|
||||
#endif
|
||||
@@ -30,12 +30,23 @@
|
||||
#include "common.h"
|
||||
|
||||
typedef struct{
|
||||
u16 name[0x106];
|
||||
u16 top_path[0x106];
|
||||
u16 bottom_path[0x106];
|
||||
u16 name[0x40];
|
||||
u16 desc[0x80];
|
||||
u16 author[0x40];
|
||||
|
||||
u32 placeholder_color;
|
||||
ssize_t icon_id;
|
||||
|
||||
u16 path[0x106];
|
||||
bool is_zip;
|
||||
} Splash_s;
|
||||
|
||||
Splash_s *splashes_list;
|
||||
int splash_count;
|
||||
|
||||
Result get_splashes(Splash_s** splashes_list, int *splash_count);
|
||||
void splash_install(Splash_s splash_to_install);
|
||||
void splash_delete();
|
||||
void load_splash_preview(Splash_s *splash);
|
||||
|
||||
#endif
|
||||
@@ -51,7 +51,7 @@ int theme_count;
|
||||
|
||||
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);
|
||||
void del_theme(u16 *path);
|
||||
Result single_install(Theme_s theme);
|
||||
Result shuffle_install(Theme_s *themes_list, int theme_count);
|
||||
Result bgm_install(Theme_s bgm_to_install);
|
||||
|
||||
BIN
meta/banner.png
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
BIN
meta/icon.png
|
Before Width: | Height: | Size: 6.2 KiB After Width: | Height: | Size: 6.2 KiB |
BIN
romfs/arrow.png
|
Before Width: | Height: | Size: 2.9 KiB After Width: | Height: | Size: 2.8 KiB |
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 443 B |
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 271 B |
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 272 B |
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 272 B |
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 272 B |
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 806 B |
|
Before Width: | Height: | Size: 449 B After Width: | Height: | Size: 466 B |
@@ -30,20 +30,34 @@
|
||||
#include "draw.h"
|
||||
#include "fs.h"
|
||||
#include "themes.h"
|
||||
#include "pp2d/pp2d/pp2d.h"
|
||||
|
||||
u32 transfer_size;
|
||||
Handle event;
|
||||
struct quirc* context;
|
||||
|
||||
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_SetFrameRate(SELECT_OUT1_OUT2, FRAME_RATE_10);
|
||||
|
||||
CAMU_SetNoiseFilter(SELECT_OUT1_OUT2, true);
|
||||
CAMU_SetAutoExposure(SELECT_OUT1_OUT2, true);
|
||||
CAMU_SetAutoWhiteBalance(SELECT_OUT1_OUT2, true);
|
||||
|
||||
CAMU_SetTrimming(PORT_CAM1, false);
|
||||
CAMU_SetTrimming(PORT_CAM2, false);
|
||||
|
||||
buf = malloc(sizeof(u16) * 400 * 240 * 2);
|
||||
CAMU_GetMaxBytes(&transfer_size, 400, 240);
|
||||
CAMU_SetTransferBytes(PORT_BOTH, transfer_size, 400, 240);
|
||||
|
||||
CAMU_Activate(SELECT_OUT1_OUT2);
|
||||
event = 0;
|
||||
|
||||
CAMU_ClearBuffer(PORT_BOTH);
|
||||
CAMU_SynchronizeVsyncTiming(SELECT_OUT1, SELECT_OUT2);
|
||||
CAMU_StartCapture(PORT_BOTH);
|
||||
|
||||
context = quirc_new();
|
||||
quirc_resize(context, 400, 240);
|
||||
@@ -51,27 +65,71 @@ void init_qr(void)
|
||||
|
||||
void exit_qr(void)
|
||||
{
|
||||
CAMU_StopCapture(PORT_BOTH);
|
||||
CAMU_Activate(SELECT_NONE);
|
||||
camExit();
|
||||
quirc_destroy(context);
|
||||
free(buf);
|
||||
}
|
||||
|
||||
void scan_qr(u16 *buf)
|
||||
{
|
||||
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, splash_mode ? "/Splashes/" : "/Themes/");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
u16 *buf = malloc(sizeof(u16) * 400 * 240 * 4);
|
||||
if (buf == NULL) return;
|
||||
CAMU_SetReceiving(&event, buf, PORT_CAM1, 240 * 400 * 2, transfer_size);
|
||||
svcWaitSynchronization(event, U64_MAX);
|
||||
svcCloseHandle(event);
|
||||
CAMU_StopCapture(PORT_BOTH);
|
||||
svcCloseHandle(cam_handle);
|
||||
CAMU_Activate(PORT_NONE);
|
||||
CAMU_Activate(SELECT_NONE);
|
||||
pp2d_begin_draw(GFX_TOP);
|
||||
u32 *rgba8_buf = malloc(240 * 400 * sizeof(u32));
|
||||
if (rgba8_buf == NULL) return;
|
||||
for (int i = 0; i < 240 * 400; i++)
|
||||
{
|
||||
rgba8_buf[i] = RGB565_TO_ABGR8(buf[i]);
|
||||
}
|
||||
pp2d_load_texture_memory(TEXTURE_QR, rgba8_buf, 400, 240);
|
||||
pp2d_draw_texture(TEXTURE_QR, 0, 0);
|
||||
pp2d_draw_rectangle(0, 216, 400, 24, RGBA8(55, 122, 168, 255));
|
||||
pp2d_draw_text_center(GFX_TOP, 220, 0.5, 0.5, RGBA8(255, 255, 255, 255), "Hold \uE005 To Quit");
|
||||
pp2d_end_draw();
|
||||
free(rgba8_buf);
|
||||
pp2d_free_texture(TEXTURE_QR);
|
||||
scan_qr(buf);
|
||||
free(buf);
|
||||
CAMU_Activate(SELECT_OUT1_OUT2);
|
||||
CAMU_StartCapture(PORT_BOTH);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -96,7 +154,7 @@ Result http_get(char *url, char *path)
|
||||
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)
|
||||
{
|
||||
@@ -158,9 +216,9 @@ Result http_get(char *url, char *path)
|
||||
filename = strtok(NULL, "\"");
|
||||
|
||||
char *illegal_characters = "\"?;:/\\+";
|
||||
for (ssize_t i = 0; i < strlen(filename); i++)
|
||||
for (size_t i = 0; i < strlen(filename); i++)
|
||||
{
|
||||
for (ssize_t n = 0; n < strlen(illegal_characters); n++)
|
||||
for (size_t n = 0; n < strlen(illegal_characters); n++)
|
||||
{
|
||||
if (filename[i] == illegal_characters[n])
|
||||
{
|
||||
@@ -201,7 +259,8 @@ Result http_get(char *url, char *path)
|
||||
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);
|
||||
if (splash_mode) get_splashes(&splashes_list, &splash_count);
|
||||
else get_themes(&themes_list, &theme_count);
|
||||
|
||||
exit_qr();
|
||||
|
||||
|
||||
140
source/draw.c
@@ -25,18 +25,22 @@
|
||||
*/
|
||||
|
||||
#include "draw.h"
|
||||
#include "common.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)
|
||||
@@ -64,55 +68,9 @@ void exit_screens(void)
|
||||
static int theme_vertical_scroll = 0;
|
||||
static int splash_vertical_scroll = 0;
|
||||
|
||||
void draw_qr(void)
|
||||
void draw_themext_error(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/");
|
||||
}
|
||||
}
|
||||
throw_error("Theme extdata does not exist\nSet a default theme from the home menu", ERROR);
|
||||
}
|
||||
|
||||
void draw_base_interface(void)
|
||||
@@ -139,22 +97,60 @@ void draw_base_interface(void)
|
||||
pp2d_draw_on(GFX_BOTTOM);
|
||||
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);
|
||||
}
|
||||
void throw_error(char* error, int error_type) {
|
||||
|
||||
switch (error_type) {
|
||||
case ERROR:
|
||||
while (aptMainLoop())
|
||||
{
|
||||
hidScanInput();
|
||||
u32 kDown = hidKeysDown();
|
||||
draw_base_interface();
|
||||
pp2d_draw_text(70, 120, 0.8, 0.8, COLOR_RED, error);
|
||||
pp2d_draw_wtext(70, 150, 0.8, 0.8, COLOR_WHITE, L"Press \uE000 to shut down.");
|
||||
pp2d_end_draw();
|
||||
if (kDown & KEY_A) {
|
||||
if (homebrew)
|
||||
APT_HardwareResetAsync();
|
||||
else {
|
||||
srvPublishToSubscriber(0x202, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
case WARNING:
|
||||
while (aptMainLoop())
|
||||
{
|
||||
hidScanInput();
|
||||
u32 kDown = hidKeysDown();
|
||||
draw_base_interface();
|
||||
pp2d_draw_text(70, 120, 0.8, 0.8, COLOR_YELLOW, error);
|
||||
pp2d_draw_wtext(70, 150, 0.8, 0.8, COLOR_WHITE, L"Press \uE000 to continue.");
|
||||
pp2d_end_draw();
|
||||
if (kDown & KEY_A) break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
pp2d_end_draw();
|
||||
}
|
||||
void draw_theme_install(int install_type)
|
||||
{
|
||||
draw_base_interface();
|
||||
switch(install_type)
|
||||
{
|
||||
case 0:
|
||||
pp2d_draw_text(20, 30, 0.7, 0.7, COLOR_WHITE, "Installing a single theme...");
|
||||
pp2d_draw_text_center(GFX_TOP, 120, 0.8, 0.8, COLOR_WHITE, "Installing a single theme...");
|
||||
break;
|
||||
case 1:
|
||||
pp2d_draw_text(20, 30, 0.7, 0.7, COLOR_WHITE, "Installing a shuffle theme...");
|
||||
pp2d_draw_text_center(GFX_TOP, 120, 0.8, 0.8, COLOR_WHITE, "Installing a shuffle theme...");
|
||||
break;
|
||||
case 2:
|
||||
pp2d_draw_text(20, 30, 0.7, 0.7, COLOR_WHITE, "Installing BGM...");
|
||||
pp2d_draw_text_center(GFX_TOP, 120, 0.8, 0.8, COLOR_WHITE, "Installing BGM...");
|
||||
break;
|
||||
case 3:
|
||||
pp2d_draw_text_center(GFX_TOP, 120, 0.8, 0.8, COLOR_WHITE, "Downloading...");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -162,7 +158,7 @@ void draw_theme_install(int install_type)
|
||||
pp2d_end_draw();
|
||||
}
|
||||
|
||||
void draw_theme_interface(Theme_s * themes_list, int theme_count, int selected_theme, bool preview_mode)
|
||||
void draw_theme_interface(Theme_s * themes_list, int theme_count, int selected_theme, bool preview_mode, int shuffle_theme_count)
|
||||
{
|
||||
|
||||
if (themes_list == NULL)
|
||||
@@ -191,14 +187,14 @@ void draw_theme_interface(Theme_s * themes_list, int theme_count, int selected_t
|
||||
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(20, 30, 0.7, 0.7, COLOR_WHITE, title);
|
||||
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(44, 50, 0.5, 0.5, COLOR_WHITE, author);
|
||||
wchar_t description[0x80] = {0};
|
||||
utf16_to_utf32((u32*)description, current_theme.desc, 0x80);
|
||||
pp2d_draw_wtext(20, 65, 0.5, 0.5, COLOR_WHITE, description);
|
||||
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");
|
||||
@@ -209,6 +205,8 @@ void draw_theme_interface(Theme_s * themes_list, int theme_count, int selected_t
|
||||
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++) {
|
||||
@@ -269,10 +267,10 @@ void draw_splash_install(int install_type)
|
||||
switch (install_type)
|
||||
{
|
||||
case SINGLE_INSTALL:
|
||||
pp2d_draw_textf(20, 30, 0.7, 0.7, COLOR_WHITE, "Installing a splash...");
|
||||
pp2d_draw_text_center(GFX_TOP, 110, 0.7, 0.7, COLOR_WHITE, "Installing a splash...");
|
||||
break;
|
||||
case UNINSTALL:
|
||||
pp2d_draw_textf(20, 30, 0.7, 0.7, COLOR_WHITE, "Uninstalling a splash...");
|
||||
pp2d_draw_text_center(GFX_TOP, 110, 0.7, 0.7, COLOR_WHITE, "Uninstalling a splash...");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -289,15 +287,26 @@ void draw_splash_interface(Splash_s *splashes_list, int splash_count, int select
|
||||
pp2d_end_draw();
|
||||
return;
|
||||
}
|
||||
|
||||
Splash_s current_splash = splashes_list[selected_splash];
|
||||
|
||||
if (preview_mode)
|
||||
{
|
||||
// TODO: Splash Previews
|
||||
pp2d_begin_draw(GFX_TOP);
|
||||
pp2d_draw_texture_part(TEXTURE_PREVIEW, 0, 0, 0, 0, 400, 240);
|
||||
pp2d_draw_on(GFX_BOTTOM);
|
||||
pp2d_draw_texture_part(TEXTURE_PREVIEW, 0, 0, 40, 240, 320, 240);
|
||||
} else {
|
||||
draw_base_interface();
|
||||
pp2d_draw_text_center(GFX_TOP, 4, 0.5, 0.5, COLOR_WHITE, "Splash mode");
|
||||
wchar_t title[0x40] = {0};
|
||||
utf16_to_utf32((u32*)title, current_splash.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_splash.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_splash.desc, 0xb0);
|
||||
pp2d_draw_wtext_wrap(20, 65, 0.5, 0.5, COLOR_WHITE, 363, description);
|
||||
|
||||
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");
|
||||
@@ -337,7 +346,12 @@ void draw_splash_interface(Splash_s *splashes_list, int splash_count, int select
|
||||
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_draw_wtext(54, 40 + vertical_offset, 0.55, 0.55, font_color, name);
|
||||
|
||||
if (!current_splash.placeholder_color)
|
||||
pp2d_draw_texture(current_splash.icon_id, 0, 24 + vertical_offset);
|
||||
else
|
||||
pp2d_draw_rectangle(0, 24 + vertical_offset, 48, 48, current_splash.placeholder_color);
|
||||
}
|
||||
}
|
||||
pp2d_end_draw();
|
||||
|
||||
19
source/fs.c
@@ -38,7 +38,7 @@ int filename_compare(__attribute__((unused)) unzFile file, const char *current_f
|
||||
|
||||
Result open_archives(void)
|
||||
{
|
||||
|
||||
romfsInit();
|
||||
u8 regionCode;
|
||||
u32 archive1;
|
||||
u32 archive2;
|
||||
@@ -85,7 +85,11 @@ Result open_archives(void)
|
||||
retValue = FSUSER_OpenArchive(&ArchiveThemeExt, ARCHIVE_EXTDATA, theme);
|
||||
if(R_FAILED(retValue)) return retValue;
|
||||
|
||||
romfsInit();
|
||||
Handle test_handle;
|
||||
retValue = FSUSER_OpenFile(&test_handle, ArchiveThemeExt, fsMakePath(PATH_ASCII, "/ThemeManage.bin"), FS_OPEN_READ, 0);
|
||||
if(R_FAILED(retValue)) return retValue;
|
||||
FSFILE_Close(test_handle);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -111,7 +115,7 @@ u64 file_to_buf(FS_Path path, FS_Archive archive, char** buf)
|
||||
|
||||
u64 size;
|
||||
FSFILE_GetSize(file, &size);
|
||||
*buf = malloc(size);
|
||||
*buf = calloc(1, size);
|
||||
FSFILE_Read(file, NULL, 0, *buf, size);
|
||||
FSFILE_Close(file);
|
||||
return size;
|
||||
@@ -135,7 +139,7 @@ u32 zip_file_to_buf(char *file_name, u16 *zip_path, char **buf)
|
||||
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);
|
||||
*buf = calloc(1, file_size);
|
||||
unzOpenCurrentFile(zip_handle);
|
||||
unzReadCurrentFile(zip_handle, *buf, file_size);
|
||||
unzCloseCurrentFile(zip_handle);
|
||||
@@ -151,17 +155,16 @@ u32 zip_file_to_buf(char *file_name, u16 *zip_path, char **buf)
|
||||
}
|
||||
}
|
||||
|
||||
u32 buf_to_file(u32 size, char *path, FS_Archive archive, char *buf)
|
||||
Result buf_to_file(u32 size, char *path, FS_Archive archive, char *buf)
|
||||
{
|
||||
Handle handle;
|
||||
u32 bytes = 0;
|
||||
Result res = FSUSER_OpenFile(&handle, archive, fsMakePath(PATH_ASCII, path), FS_OPEN_WRITE, 0);
|
||||
if (R_FAILED(res)) return res;
|
||||
res = FSFILE_Write(handle, &bytes, 0, buf, size, FS_WRITE_FLUSH);
|
||||
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;
|
||||
return bytes;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void remake_file(char *path, FS_Archive archive, u32 size)
|
||||
|
||||
@@ -33,14 +33,15 @@
|
||||
#include <time.h>
|
||||
|
||||
int __stacksize__ = 64 * 1024;
|
||||
Result archive_result;
|
||||
|
||||
int init_services(void)
|
||||
{
|
||||
cfguInit();
|
||||
ptmuInit();
|
||||
httpcInit(0);
|
||||
open_archives();
|
||||
bool homebrew = true;
|
||||
archive_result = open_archives();
|
||||
homebrew = true;
|
||||
if (!envIsHomebrew())
|
||||
{
|
||||
homebrew = false;
|
||||
@@ -79,8 +80,8 @@ int main(void)
|
||||
free(themes_list);
|
||||
themes_list = NULL;
|
||||
}
|
||||
int splash_count = 0;
|
||||
Splash_s *splashes_list = NULL;
|
||||
splash_count = 0;
|
||||
splashes_list = NULL;
|
||||
res = get_splashes(&splashes_list, &splash_count);
|
||||
if (R_FAILED(res))
|
||||
{
|
||||
@@ -89,7 +90,7 @@ int main(void)
|
||||
splashes_list = NULL;
|
||||
}
|
||||
|
||||
bool splash_mode = false;
|
||||
splash_mode = false;
|
||||
int selected_splash = 0;
|
||||
int selected_theme = 0;
|
||||
int previously_selected = 0;
|
||||
@@ -104,10 +105,10 @@ int main(void)
|
||||
|
||||
if (qr_mode)
|
||||
{
|
||||
draw_qr();
|
||||
take_picture();
|
||||
} else if (!splash_mode)
|
||||
{
|
||||
draw_theme_interface(themes_list, theme_count, selected_theme, preview_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);
|
||||
}
|
||||
@@ -123,9 +124,17 @@ int main(void)
|
||||
else if (kDown & KEY_L)
|
||||
{
|
||||
splash_mode = !splash_mode;
|
||||
} else if (kDown & KEY_R)
|
||||
}
|
||||
|
||||
if (R_FAILED(archive_result) && !splash_mode)
|
||||
{
|
||||
if (splash_mode || preview_mode) {
|
||||
draw_themext_error();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (kDown & KEY_R)
|
||||
{
|
||||
if (preview_mode) {
|
||||
continue;
|
||||
} else {
|
||||
qr_mode = !qr_mode;
|
||||
@@ -149,11 +158,17 @@ int main(void)
|
||||
if (kDown & KEY_Y)
|
||||
{
|
||||
if (!preview_mode)
|
||||
{
|
||||
if (!splash_mode)
|
||||
{
|
||||
if (!current_theme->has_preview)
|
||||
load_theme_preview(current_theme);
|
||||
|
||||
preview_mode = current_theme->has_preview;
|
||||
} else {
|
||||
load_splash_preview(current_splash);
|
||||
preview_mode = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
preview_mode = false;
|
||||
@@ -185,6 +200,9 @@ int main(void)
|
||||
draw_theme_install(SINGLE_INSTALL);
|
||||
single_install(*current_theme);
|
||||
}
|
||||
//these two are here just so I don't forget how to implement them - HM
|
||||
//del_theme(current_theme->path);
|
||||
//get_themes(&themes_list, &theme_count);
|
||||
}
|
||||
|
||||
else if (kDown & KEY_B)
|
||||
@@ -217,6 +235,7 @@ int main(void)
|
||||
{
|
||||
draw_theme_install(SHUFFLE_INSTALL);
|
||||
shuffle_install(themes_list, theme_count);
|
||||
shuffle_theme_count = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -302,6 +321,32 @@ int main(void)
|
||||
selected_theme = 0;
|
||||
}
|
||||
}
|
||||
else if (kDown & KEY_CPAD_LEFT)
|
||||
{
|
||||
svcSleepThread(100000000);
|
||||
|
||||
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);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
if (!splash_mode && selected_theme != previously_selected)
|
||||
{
|
||||
|
||||
@@ -26,6 +26,125 @@
|
||||
#include "splashes.h"
|
||||
#include "unicode.h"
|
||||
#include "fs.h"
|
||||
#include "themes.h"
|
||||
#include "pp2d/pp2d/pp2d.h"
|
||||
|
||||
void load_splash_preview(Splash_s *splash)
|
||||
{
|
||||
//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 (!(splash->is_zip))
|
||||
{
|
||||
u16 path_to_preview[0x106] = {0};
|
||||
strucat(path_to_preview, splash->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", splash->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;
|
||||
}
|
||||
}
|
||||
|
||||
pp2d_load_texture_memory(TEXTURE_PREVIEW, image, (u32)width, (u32)height);
|
||||
}
|
||||
|
||||
free(image);
|
||||
free(preview_buffer);
|
||||
}
|
||||
|
||||
|
||||
static void parse_smdh(Splash_s *splash, ssize_t textureID, u16 *splash_name)
|
||||
{
|
||||
char *info_buffer = NULL;
|
||||
u64 size = 0;
|
||||
if (!(splash->is_zip))
|
||||
{
|
||||
u16 path_to_smdh[0x106] = {0};
|
||||
strucat(path_to_smdh, splash->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", splash->path, &info_buffer);
|
||||
}
|
||||
|
||||
if (!size)
|
||||
{
|
||||
free(info_buffer);
|
||||
memset(splash->name, 0, 0x80);
|
||||
memset(splash->desc, 0, 0x100);
|
||||
memset(splash->author, 0, 0x80);
|
||||
memcpy(splash->name, splash_name, 0x80);
|
||||
utf8_to_utf16(splash->desc, (u8*)"No description", 0x100);
|
||||
utf8_to_utf16(splash->author, (u8*)"Unknown author", 0x80);
|
||||
splash->placeholder_color = RGBA8(rand() % 255, rand() % 255, rand() % 255, 255);
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(splash->name, info_buffer + 0x08, 0x80);
|
||||
memcpy(splash->desc, info_buffer + 0x88, 0x100);
|
||||
memcpy(splash->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);
|
||||
splash->icon_id = textureID;
|
||||
|
||||
free(image);
|
||||
free(icon_data);
|
||||
free(info_buffer);
|
||||
}
|
||||
|
||||
Result get_splashes(Splash_s** splashes_list, int *splash_count)
|
||||
{
|
||||
@@ -35,6 +154,13 @@ Result get_splashes(Splash_s** splashes_list, int *splash_count)
|
||||
if (R_FAILED(res))
|
||||
return res;
|
||||
|
||||
if (*splashes_list != NULL)
|
||||
{
|
||||
free(*splashes_list);
|
||||
*splashes_list = NULL;
|
||||
*splash_count = 0;
|
||||
}
|
||||
|
||||
u32 entries_read = 1;
|
||||
while (entries_read)
|
||||
{
|
||||
@@ -43,7 +169,7 @@ Result get_splashes(Splash_s** splashes_list, int *splash_count)
|
||||
if (R_FAILED(res) || entries_read == 0)
|
||||
break;
|
||||
|
||||
if (!(entry.attributes & FS_ATTRIBUTE_DIRECTORY))
|
||||
if (!(entry.attributes & FS_ATTRIBUTE_DIRECTORY) && strcmp(entry.shortExt, "ZIP"))
|
||||
continue;
|
||||
|
||||
*splash_count += entries_read;
|
||||
@@ -54,33 +180,18 @@ Result get_splashes(Splash_s** splashes_list, int *splash_count)
|
||||
Splash_s *current_splash = &(*splashes_list)[*splash_count-1];
|
||||
memset(current_splash, 0, sizeof(Splash_s));
|
||||
|
||||
u16 splash_path[0x106] = {0};
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
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);
|
||||
char pathchar[0x106] = {0};
|
||||
utf16_to_utf8((u8*) pathchar, splash_path, 0x106);
|
||||
|
||||
memcpy(current_splash->path, splash_path, 0x106 * sizeof(u16));
|
||||
current_splash->is_zip = !strcmp(entry.shortExt, "ZIP");
|
||||
|
||||
ssize_t iconID = TEXTURE_PREVIEW + theme_count + *splash_count;
|
||||
parse_smdh(current_splash, iconID, entry.name);
|
||||
}
|
||||
FSDIR_Close(dir_handle);
|
||||
|
||||
@@ -93,20 +204,49 @@ void splash_delete()
|
||||
}
|
||||
void splash_install(Splash_s splash_to_install)
|
||||
{
|
||||
char *screen_buf;
|
||||
u32 size = file_to_buf(fsMakePath(PATH_UTF16, splash_to_install.top_path), ArchiveSD, &screen_buf);
|
||||
char *screen_buf = NULL;
|
||||
u32 size = 0;
|
||||
if (splash_to_install.is_zip)
|
||||
{
|
||||
size = zip_file_to_buf("splash.bin", splash_to_install.path, &screen_buf);
|
||||
if (size)
|
||||
{
|
||||
remake_file("/luma/splash.bin", ArchiveSD, size);
|
||||
buf_to_file(size, "/luma/splash.bin", ArchiveSD, screen_buf);
|
||||
free(screen_buf);
|
||||
screen_buf = NULL;
|
||||
size = 0;
|
||||
}
|
||||
|
||||
size = file_to_buf(fsMakePath(PATH_UTF16, splash_to_install.bottom_path), ArchiveSD, &screen_buf);
|
||||
size = zip_file_to_buf("splashbottom.bin", splash_to_install.path, &screen_buf);
|
||||
if (size)
|
||||
{
|
||||
remake_file("/luma/splashbottom.bin", ArchiveSD, size);
|
||||
buf_to_file(size, "/luma/splashbottom.bin", ArchiveSD, screen_buf);
|
||||
free(screen_buf);
|
||||
screen_buf = NULL;
|
||||
size = 0;
|
||||
}
|
||||
} else {
|
||||
u16 path[0x106] = {0};
|
||||
memcpy(path, splash_to_install.path, 0x106 * sizeof(u16));
|
||||
struacat(path, "/splash.bin");
|
||||
size = file_to_buf(fsMakePath(PATH_UTF16, path), ArchiveSD, &screen_buf);
|
||||
if (size)
|
||||
{
|
||||
buf_to_file(size, "/luma/splash.bin", ArchiveSD, screen_buf);
|
||||
free(screen_buf);
|
||||
screen_buf = NULL;
|
||||
size = 0;
|
||||
}
|
||||
|
||||
memcpy(path, splash_to_install.path, 0x106 * sizeof(u16));
|
||||
struacat(path, "/splashbottom.bin");
|
||||
size = file_to_buf(fsMakePath(PATH_UTF16, path), ArchiveSD, &screen_buf);
|
||||
if (size)
|
||||
{
|
||||
buf_to_file(size, "/luma/splashbottom.bin", ArchiveSD, screen_buf);
|
||||
free(screen_buf);
|
||||
screen_buf = NULL;
|
||||
size = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -158,7 +158,15 @@ Result get_themes(Theme_s **themes_list, int *theme_count)
|
||||
if (R_FAILED(res))
|
||||
return res;
|
||||
|
||||
if (*themes_list != NULL) //used for QR reading and also for theme deletion
|
||||
{
|
||||
free(*themes_list);
|
||||
*themes_list = NULL;
|
||||
*theme_count = 0;
|
||||
}
|
||||
|
||||
u32 entries_read = 1;
|
||||
|
||||
while (entries_read)
|
||||
{
|
||||
FS_DirectoryEntry entry = {0};
|
||||
@@ -196,25 +204,18 @@ Result get_themes(Theme_s **themes_list, int *theme_count)
|
||||
return res;
|
||||
}
|
||||
|
||||
void add_theme(Theme_s **themes_list, int *theme_count, char *path, char *filename)
|
||||
void del_theme(u16 *path)
|
||||
{
|
||||
*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);
|
||||
Handle dir_handle;
|
||||
Result res = FSUSER_OpenDirectory(&dir_handle, ArchiveSD, fsMakePath(PATH_UTF16, path));
|
||||
if (R_SUCCEEDED(res))
|
||||
{
|
||||
FSDIR_Close(dir_handle);
|
||||
FSUSER_DeleteDirectoryRecursively(ArchiveSD, fsMakePath(PATH_UTF16, path));
|
||||
} else
|
||||
{
|
||||
FSUSER_DeleteFile(ArchiveSD, fsMakePath(PATH_UTF16, path));
|
||||
}
|
||||
}
|
||||
|
||||
Result bgm_install(Theme_s bgm_to_install)
|
||||
@@ -230,9 +231,11 @@ Result bgm_install(Theme_s bgm_to_install)
|
||||
memset(&savedata_buf[0x13b8], 0, 8);
|
||||
savedata_buf[0x13bd] = 3;
|
||||
savedata_buf[0x13b8] = 0xff;
|
||||
u32 size = buf_to_file(savedata_size, "/SaveData.dat", ArchiveHomeExt, savedata_buf);
|
||||
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
|
||||
{
|
||||
music_size = zip_file_to_buf("bgm.bcstm", bgm_to_install.path, &music);
|
||||
@@ -245,7 +248,6 @@ Result bgm_install(Theme_s bgm_to_install)
|
||||
|
||||
if (music_size == 0)
|
||||
{
|
||||
free(music);
|
||||
music = calloc(1, 3371008);
|
||||
} else if (music_size > 3371008) {
|
||||
free(music);
|
||||
@@ -253,10 +255,10 @@ Result bgm_install(Theme_s bgm_to_install)
|
||||
return MAKERESULT(RL_PERMANENT, RS_CANCELED, RM_APPLICATION, RD_TOO_LARGE);
|
||||
}
|
||||
|
||||
size = buf_to_file(music_size, "/BgmCache.bin", ArchiveThemeExt, music);
|
||||
result = buf_to_file(music_size == 0 ? 3371008 : music_size, "/BgmCache.bin", ArchiveThemeExt, music);
|
||||
free(music);
|
||||
|
||||
if (size == 0) return MAKERESULT(RL_PERMANENT, RS_CANCELED, RM_APPLICATION, RD_NOT_FOUND);
|
||||
if (!R_SUCCEEDED(result)) return result;
|
||||
|
||||
file_to_buf(fsMakePath(PATH_ASCII, "/ThemeManage.bin"), ArchiveThemeExt, &thememanage_buf);
|
||||
thememanage_buf[0x00] = 1;
|
||||
@@ -280,9 +282,11 @@ Result bgm_install(Theme_s bgm_to_install)
|
||||
memset(&thememanage_buf[0x340], 0, 4);
|
||||
memset(&thememanage_buf[0x360], 0, 4);
|
||||
memset(&thememanage_buf[0x368], 0, 4);
|
||||
size = buf_to_file(0x800, "/ThemeManage.bin", ArchiveThemeExt, thememanage_buf);
|
||||
result = buf_to_file(0x800, "/ThemeManage.bin", ArchiveThemeExt, thememanage_buf);
|
||||
free(thememanage_buf);
|
||||
|
||||
if (!R_SUCCEEDED(result)) return result;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -302,9 +306,11 @@ Result single_install(Theme_s theme_to_install)
|
||||
memset(&savedata_buf[0x13b8], 0, 8);
|
||||
savedata_buf[0x13bd] = 3;
|
||||
savedata_buf[0x13b8] = 0xff;
|
||||
u32 size = buf_to_file(savedata_size, "/SaveData.dat", ArchiveHomeExt, savedata_buf);
|
||||
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)
|
||||
{
|
||||
@@ -325,10 +331,10 @@ Result single_install(Theme_s theme_to_install)
|
||||
return MAKERESULT(RL_PERMANENT, RS_CANCELED, RM_APPLICATION, RD_NOT_FOUND);
|
||||
}
|
||||
|
||||
size = buf_to_file(body_size, "/BodyCache.bin", ArchiveThemeExt, body); // Write body data to file
|
||||
result = buf_to_file(body_size, "/BodyCache.bin", ArchiveThemeExt, body); // Write body data to file
|
||||
free(body);
|
||||
|
||||
if (size == 0) return MAKERESULT(RL_PERMANENT, RS_CANCELED, RM_APPLICATION, RD_NOT_FOUND);
|
||||
if (!R_SUCCEEDED(result)) return result;
|
||||
|
||||
if (theme_to_install.is_zip) // Same as above but this time with bgm
|
||||
{
|
||||
@@ -342,7 +348,6 @@ Result single_install(Theme_s theme_to_install)
|
||||
|
||||
if (music_size == 0)
|
||||
{
|
||||
free(music);
|
||||
music = calloc(1, 3371008);
|
||||
} else if (music_size > 3371008) {
|
||||
free(music);
|
||||
@@ -350,10 +355,10 @@ Result single_install(Theme_s theme_to_install)
|
||||
return MAKERESULT(RL_PERMANENT, RS_CANCELED, RM_APPLICATION, RD_TOO_LARGE);
|
||||
}
|
||||
|
||||
size = buf_to_file(music_size, "/BgmCache.bin", ArchiveThemeExt, music);
|
||||
result = buf_to_file(music_size == 0 ? 3371008 : music_size, "/BgmCache.bin", ArchiveThemeExt, music);
|
||||
free(music);
|
||||
|
||||
if (size == 0) return MAKERESULT(RL_PERMANENT, RS_CANCELED, RM_APPLICATION, RD_NOT_FOUND);
|
||||
if (!R_SUCCEEDED(result)) return result;
|
||||
|
||||
file_to_buf(fsMakePath(PATH_ASCII, "/ThemeManage.bin"), ArchiveThemeExt, &thememanage_buf);
|
||||
thememanage_buf[0x00] = 1;
|
||||
@@ -379,9 +384,11 @@ Result single_install(Theme_s theme_to_install)
|
||||
memset(&thememanage_buf[0x340], 0, 4);
|
||||
memset(&thememanage_buf[0x360], 0, 4);
|
||||
memset(&thememanage_buf[0x368], 0, 4);
|
||||
size = buf_to_file(0x800, "/ThemeManage.bin", ArchiveThemeExt, thememanage_buf);
|
||||
result = buf_to_file(0x800, "/ThemeManage.bin", ArchiveThemeExt, thememanage_buf);
|
||||
free(thememanage_buf);
|
||||
|
||||
if (!R_SUCCEEDED(result)) return result;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -393,10 +400,11 @@ Result shuffle_install(Theme_s *themes_list, int theme_count)
|
||||
u32 bgm_sizes[10] = {0};
|
||||
for (int i = 0; i < theme_count; i++)
|
||||
{
|
||||
if (count > 9) return MAKERESULT(RL_USAGE, RS_INVALIDARG, RM_COMMON, RD_INVALID_SELECTION);
|
||||
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++)
|
||||
@@ -426,9 +434,11 @@ Result shuffle_install(Theme_s *themes_list, int theme_count)
|
||||
}
|
||||
}
|
||||
|
||||
buf_to_file(size, "/SaveData.dat", ArchiveHomeExt, savedata_buf);
|
||||
Result result = buf_to_file(size, "/SaveData.dat", ArchiveHomeExt, savedata_buf);
|
||||
free(savedata_buf);
|
||||
|
||||
if (!R_SUCCEEDED(result)) return result;
|
||||
|
||||
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);
|
||||
@@ -525,8 +535,10 @@ Result shuffle_install(Theme_s *themes_list, int theme_count)
|
||||
*bgmsizeloc = bgm_sizes[i];
|
||||
}
|
||||
|
||||
buf_to_file(0x800, "/ThemeManage.bin", ArchiveThemeExt, thememanage_buf);
|
||||
result = buf_to_file(0x800, "/ThemeManage.bin", ArchiveThemeExt, thememanage_buf);
|
||||
free(thememanage_buf);
|
||||
|
||||
if (!R_SUCCEEDED(result)) return result;
|
||||
|
||||
return MAKERESULT(RL_SUCCESS, RS_SUCCESS, RM_COMMON, RD_SUCCESS);
|
||||
}
|
||||
|
||||