From 87b6bb11d12f4bc4ab54f58b944c920f2e859d1b Mon Sep 17 00:00:00 2001 From: Alex Taber Date: Sat, 26 Aug 2017 19:24:17 -0400 Subject: [PATCH] Add smdh parsing (errors out for some reason) --- Makefile | 4 ++-- include/themes.h | 2 ++ include/unicode.h | 1 + source/main.c | 14 ++++++++------ source/themes.c | 18 ++++++++++++++++++ source/unicode.c | 10 ++++++++++ 6 files changed, 41 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 164b883..0c71f8a 100644 --- a/Makefile +++ b/Makefile @@ -39,8 +39,8 @@ INCLUDES := include #--------------------------------------------------------------------------------- ARCH := -march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft -CFLAGS := -g -Wall -Wextra -Wno-pointer-sign -O2 -mword-relocations \ - -fomit-frame-pointer -ffunction-sections \ +CFLAGS := -g -Wall -Wextra -Wno-pointer-sign -mword-relocations \ + -ffunction-sections \ $(ARCH) CFLAGS += $(INCLUDE) -DARM11 -D_3DS diff --git a/include/themes.h b/include/themes.h index 6c2bfd9..121036e 100644 --- a/include/themes.h +++ b/include/themes.h @@ -14,5 +14,7 @@ typedef struct { } theme; Result single_install(theme); +int scan_themes(theme **themes); +void parse_smdh(theme *entry, u16 *path); #endif \ No newline at end of file diff --git a/include/unicode.h b/include/unicode.h index 96f6547..b32ebd0 100644 --- a/include/unicode.h +++ b/include/unicode.h @@ -6,5 +6,6 @@ ssize_t strulen(u16*, ssize_t); void struacat(u16 *input, const char *addition); void printu(u16 *input); +u16 *strucat(u16 *destination, const u16 *source); #endif \ No newline at end of file diff --git a/source/main.c b/source/main.c index ac14b38..3b8d3a7 100644 --- a/source/main.c +++ b/source/main.c @@ -37,17 +37,19 @@ int main(void) consoleInit(GFX_TOP, NULL); int theme_count = get_number_entries("/Themes"); - theme *theme = calloc(1, sizeof(theme)); - u16 path[262] = {0}; - utf8_to_utf16(path, (u8*)"/Themes/Saber Lily", 262 * sizeof(u16)); - memcpy(theme->path, path, 262 * sizeof(u16)); - theme->is_zip = false; while(aptMainLoop()) { hidScanInput(); u32 kDown = hidKeysDown(); - if (kDown & KEY_A) single_install(*theme); + if (kDown & KEY_A) + { + theme *theme = malloc(sizeof(theme)); + u16 path[262] = {0}; + struacat(path, "/Themes/Saber Lily"); + parse_smdh(theme, path); + printu(theme->name); + } if (kDown & KEY_START) { close_archives(); diff --git a/source/themes.c b/source/themes.c index fe6ccb3..91e0435 100644 --- a/source/themes.c +++ b/source/themes.c @@ -113,4 +113,22 @@ Result single_install(theme theme_to_install) printf("Done!\n"); return 0; +} + +void parse_smdh(theme *entry, u16 *path) +{ + u16 path_to_smdh[0x106] = {0}; + printu(path); + strucat(path_to_smdh, path); + struacat(path_to_smdh, "/info.smdh"); + printu(path_to_smdh); + char *info_buffer; + + u64 size = file_to_buf(fsMakePath(PATH_UTF16, path_to_smdh), ArchiveSD, &info_buffer); + printf("Size: %llu\n", size); + memcpy(entry->name, info_buffer + 0x08, 0x80); + memcpy(entry->desc, info_buffer + 0x88, 0x100); + memcpy(entry->author, info_buffer + 0x188, 0x80); + memcpy(entry->icon_data, info_buffer + 0x2040, 0x1200); + free(info_buffer); } \ No newline at end of file diff --git a/source/unicode.c b/source/unicode.c index 8897b62..ab5904d 100644 --- a/source/unicode.c +++ b/source/unicode.c @@ -29,4 +29,14 @@ void printu(u16 *input) for (u16 i = 0; i < buf_len; i++) buf[i] = input[i]; printf("%ls\n", buf); free(buf); +} + +u16 *strucat(u16 *destination, const u16 *source) +{ + ssize_t dest_len = strulen(destination, 0x106); + + ssize_t source_len = strulen(source, 0x106); + + memcpy(&destination[dest_len], source, source_len * sizeof(u16)); + return destination; } \ No newline at end of file