From 5fc499ff7840436507e0f81fa1d99e9b1915e62c Mon Sep 17 00:00:00 2001 From: Alex Taber Date: Mon, 4 Sep 2017 02:42:27 -0400 Subject: [PATCH] Automatically update themes list when a new theme is downloaded --- include/themes.h | 4 ++++ source/camera.c | 5 +++++ source/main.c | 9 ++++++--- source/themes.c | 21 +++++++++++++++++++++ 4 files changed, 36 insertions(+), 3 deletions(-) diff --git a/include/themes.h b/include/themes.h index 94847e6..2f75126 100644 --- a/include/themes.h +++ b/include/themes.h @@ -46,8 +46,12 @@ typedef struct { bool in_shuffle; } Theme_s; +Theme_s * themes_list; +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); Result single_install(Theme_s theme); Result shuffle_install(Theme_s *themes_list, int theme_count); Result bgm_install(Theme_s bgm_to_install); diff --git a/source/camera.c b/source/camera.c index 3af719d..1de37a8 100644 --- a/source/camera.c +++ b/source/camera.c @@ -29,6 +29,7 @@ #include "quirc/quirc.h" #include "draw.h" #include "fs.h" +#include "themes.h" void init_qr(void) { @@ -187,5 +188,9 @@ 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); + + exit_qr(); + return 0; } \ No newline at end of file diff --git a/source/main.c b/source/main.c index a53a05b..d482cea 100644 --- a/source/main.c +++ b/source/main.c @@ -69,10 +69,9 @@ int main(void) srand(time(NULL)); bool homebrew = init_services(); init_screens(); - init_qr(); - int theme_count = 0; - Theme_s * themes_list = NULL; + themes_list = NULL; + theme_count = 0; Result res = get_themes(&themes_list, &theme_count); if (R_FAILED(res)) { @@ -126,9 +125,13 @@ int main(void) } else if (kDown & KEY_R) { qr_mode = !qr_mode; + if (qr_mode) init_qr(); + else exit_qr(); continue; } + if (qr_mode) continue; + if (themes_list == NULL && !splash_mode) continue; diff --git a/source/themes.c b/source/themes.c index 1b5ff85..31d3164 100644 --- a/source/themes.c +++ b/source/themes.c @@ -196,6 +196,27 @@ 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) +{ + *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;