From f83ea1f6c46f4b9e2c6e97a86479aa640c7ccfee Mon Sep 17 00:00:00 2001 From: Alex Taber Date: Wed, 2 Aug 2017 08:07:58 -0400 Subject: [PATCH] Wot --- include/fs.h | 13 +++++++ include/themes.h | 16 +++++++++ source/fs.c | 93 ++++++++++++++++++++++++++++++++++++++++++++++++ source/main.c | 40 +++++++++++++++++++++ source/themes.c | 17 +++++++++ 5 files changed, 179 insertions(+) create mode 100644 include/fs.h create mode 100644 include/themes.h create mode 100644 source/fs.c create mode 100644 source/main.c create mode 100644 source/themes.c diff --git a/include/fs.h b/include/fs.h new file mode 100644 index 0000000..1716629 --- /dev/null +++ b/include/fs.h @@ -0,0 +1,13 @@ +#ifndef FS_H +#define FS_H + +#include <3ds.h> + +FS_Archive ArchiveSD; +FS_Archive ArchiveHomeExt; +FS_Archive ArchiveThemeExt; + +Result open_archives(void); +int get_number_entries(char*); + +#endif \ No newline at end of file diff --git a/include/themes.h b/include/themes.h new file mode 100644 index 0000000..405de08 --- /dev/null +++ b/include/themes.h @@ -0,0 +1,16 @@ +#ifndef THEMES_H +#define THEMES_H + +typedef struct { + u16 name[0x40]; + u16 desc[0x80]; + u16 author[0x40]; + char icon_data[0x1200]; + u16 path[262]; + ssize_t path_len; + bool is_zip; +} theme; + +Result single_install(theme*); + +#endif \ No newline at end of file diff --git a/source/fs.c b/source/fs.c new file mode 100644 index 0000000..3cdc7b1 --- /dev/null +++ b/source/fs.c @@ -0,0 +1,93 @@ +#include <3ds.h> +#include +#include + +#include "fs.h" + +Result open_archives(void) +{ + + u8 regionCode; + u32 archive1; + u32 archive2; + + Result retValue; + + FS_Path home; + FS_Path theme; + + CFGU_SecureInfoGetRegion(®ionCode); + switch(regionCode) + { + case 1: + archive1 = 0x000002cd; + archive2 = 0x0000008f; + break; + case 2: + archive1 = 0x000002ce; + archive2 = 0x00000098; + break; + case 3: + archive1 = 0x000002cc; + archive2 = 0x00000082; + break; + default: + archive1 = 0x00; + archive2 = 0x00; + } + + retValue = FSUSER_OpenArchive(&ArchiveSD, ARCHIVE_SDMC, fsMakePath(PATH_EMPTY, "")); + if(R_FAILED(retValue)) return retValue; + + 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; + + 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; + return 0; +} + +int get_number_entries(char *path) +{ + int count = 0; + Handle dir_handle; + Result res = FSUSER_OpenDirectory(&dir_handle, ArchiveSD, fsMakePath(PATH_ASCII, path)); + if (R_FAILED(res)) return -1; + + bool done = false; + while (!done) + { + FS_DirectoryEntry *entry = malloc(sizeof(entry)); + u32 entries_read; + FSDIR_Read(dir_handle, &entries_read, 1, entry); + u32 attributes = entry->attributes; + char shortExt[0x4] = {0}; + strcpy(shortExt, entry->shortExt); + free (entry); + if (entries_read && (!strcmp(shortExt, "ZIP") || attributes == 0)) count ++; + else if (!entries_read) break; + } + FSDIR_Close(dir_handle); + return count; +} + +Result file_to_buf(FS_Path path, char* buf) +{ + Handle file; + Result res = FSUSER_OpenFile(&file, ArchiveSD, path, FS_OPEN_READ, 0); + if (R_FAILED(res)) return res; + + u32 size; + FSFILE_GetSize(file, &size); + buf = malloc(size); + res = FSFILE_Read(file, NULL, 0, buf, size); + return res; +} \ No newline at end of file diff --git a/source/main.c b/source/main.c new file mode 100644 index 0000000..144e4ac --- /dev/null +++ b/source/main.c @@ -0,0 +1,40 @@ +#include + +#include "fs.h" +#include "themes.h" + +int init_services(void) +{ + gfxInitDefault(); + cfguInit(); + srvInit(); + hidInit(); + fsInit(); + ptmSysmInit(); + open_archives(); + return 0; +} + +int de_init_services(void) +{ + gfxExit(); + cfguExit(); + srvExit(); + hidExit(); + fsExit(); + ptmSysmExit(); + // close_archives(); // TODO: Implement + return 0; +} + +int main(void) +{ + init_services(); + + int theme_count = get_number_entries("/Themes"); + theme** theme_list = calloc(theme_count, sizeof(theme*)); + + free(theme_list); + de_init_services(); + return 0; +} diff --git a/source/themes.c b/source/themes.c new file mode 100644 index 0000000..382f71c --- /dev/null +++ b/source/themes.c @@ -0,0 +1,17 @@ +#include <3ds.h> +#include + +#include "themes.h" + +Result single_install(theme* theme) +{ + char *body; + + u16 path[262] = {0}; + memcpy(path, theme->path, 262); + u16 body_path[12]; + ssize_t len = utf8_to_utf16(body_path, (u8*) "/body_lz.bin", 12); + memcpy(&path[theme->path_len], body_path, 12); + + file_to_buf(fsMakePath(PATH_UTF16, path), body); +} \ No newline at end of file