From 9a227b92bf35ea84a727e7c14dccc1e419753f42 Mon Sep 17 00:00:00 2001 From: d0k3 Date: Thu, 2 Aug 2018 00:43:33 +0200 Subject: [PATCH] Ability to setup a default font --- arm9/source/filesys/filetype.h | 1 + arm9/source/filesys/support.c | 45 ++++++++++++++++++++++++++++++++++ arm9/source/filesys/support.h | 2 ++ arm9/source/godmode.c | 12 ++++++++- 4 files changed, 59 insertions(+), 1 deletion(-) diff --git a/arm9/source/filesys/filetype.h b/arm9/source/filesys/filetype.h index 64e57a7..9f207c2 100644 --- a/arm9/source/filesys/filetype.h +++ b/arm9/source/filesys/filetype.h @@ -67,6 +67,7 @@ #define FTYPE_SCRIPT(tp) (tp&(TXT_SCRIPT)) #define FTYPE_FONT(tp) (tp&(FONT_PBM)) #define FTYPE_GFX(tp) (tp&(GFX_PNG)) +#define FTYPE_SETABLE(tp) (tp&(FONT_PBM)) #define FTYPE_BOOTABLE(tp) (tp&(SYS_FIRM)) #define FTYPE_INSTALLABLE(tp) (tp&(SYS_FIRM)) #define FTYPE_AGBSAVE(tp) (tp&(SYS_AGBSAVE)) diff --git a/arm9/source/filesys/support.c b/arm9/source/filesys/support.c index 348c0da..f0ecade 100644 --- a/arm9/source/filesys/support.c +++ b/arm9/source/filesys/support.c @@ -48,6 +48,51 @@ size_t LoadSupportFile(const char* fname, void* buffer, size_t max_len) return 0; } +bool SaveSupportFile(const char* fname, void* buffer, size_t len) +{ + const char* base_paths[] = { SUPPORT_FILE_PATHS }; + int idx = -1; + + // check for existing support file path + for (u32 i = 0; (idx < 0) && (i < countof(base_paths)); i++) { + if (fvx_stat(base_paths[i], NULL) == FR_OK) + idx = i; + } + + // create path if required + for (u32 i = 0; (idx < 0) && (i < countof(base_paths)); i++) { + if (fvx_rmkdir(base_paths[i]) == FR_OK) + idx = i; + } + + // write support file + if (idx >= 0) { + char path[256]; + snprintf(path, 256, "%s/%s", base_paths[idx], fname); + fvx_unlink(path); + if (fvx_qwrite(path, buffer, 0, len, NULL) == FR_OK) + return true; + } + + return false; +} + +bool SetAsSupportFile(const char* fname, const char* source) +{ + u32 len = fvx_qsize(source); + if (!len) return false; + + void* buffer = malloc(len); + if (!buffer) return false; + + bool res = false; + if (fvx_qread(source, buffer, 0, len, NULL) == FR_OK) + res = SaveSupportFile(fname, buffer, len); + free(buffer); + + return res; +} + bool GetSupportDir(char* path, const char* dname) { const char* base_paths[] = { SUPPORT_DIR_PATHS }; diff --git a/arm9/source/filesys/support.h b/arm9/source/filesys/support.h index 5f074e8..1146157 100644 --- a/arm9/source/filesys/support.h +++ b/arm9/source/filesys/support.h @@ -8,6 +8,8 @@ bool CheckSupportFile(const char* fname); size_t LoadSupportFile(const char* fname, void* buffer, size_t max_len); +bool SaveSupportFile(const char* fname, void* buffer, size_t len); +bool SetAsSupportFile(const char* fname, const char* source); bool CheckSupportDir(const char* fpath); bool FileSelectorSupport(char* result, const char* text, const char* dname, const char* pattern); diff --git a/arm9/source/godmode.c b/arm9/source/godmode.c index 0185969..19ac675 100644 --- a/arm9/source/godmode.c +++ b/arm9/source/godmode.c @@ -1044,6 +1044,7 @@ u32 FileHandlerMenu(char* current_path, u32* cursor, u32* scroll, PaneData** pan bool scriptable = (FTYPE_SCRIPT(filetype)); bool fontable = (FTYPE_FONT(filetype)); bool viewable = (FTYPE_GFX(filetype)); + bool setable = (FTYPE_SETABLE(filetype)); bool bootable = (FTYPE_BOOTABLE(filetype)); bool installable = (FTYPE_INSTALLABLE(filetype)); bool agbexportable = (FTYPE_AGBSAVE(filetype) && (drvtype & DRV_VIRTUAL) && (drvtype & DRV_SYSNAND)); @@ -1109,7 +1110,7 @@ u32 FileHandlerMenu(char* current_path, u32* cursor, u32* scroll, PaneData** pan (filetype & BIN_LEGKEY) ? "Build " KEYDB_NAME : (filetype & BIN_NCCHNFO)? "NCCHinfo options..." : (filetype & TXT_SCRIPT) ? "Execute GM9 script" : - (filetype & FONT_PBM) ? "Set as active font" : + (filetype & FONT_PBM) ? "Font options..." : (filetype & GFX_PNG) ? "View PNG file" : (filetype & HDR_NAND) ? "Rebuild NCSD header" : (filetype & NOIMG_NAND) ? "Rebuild NCSD header" : "???"; @@ -1259,6 +1260,7 @@ u32 FileHandlerMenu(char* current_path, u32* cursor, u32* scroll, PaneData** pan int view = (viewable) ? ++n_opt : -1; int agbexport = (agbexportable) ? ++n_opt : -1; int agbimport = (agbimportable) ? ++n_opt : -1; + int setup = (setable) ? ++n_opt : -1; if (mount > 0) optionstr[mount-1] = (filetype & GAME_TMD) ? "Mount CXI/NDS to drive" : "Mount image to drive"; if (restore > 0) optionstr[restore-1] = "Restore SysNAND (safe)"; if (ebackup > 0) optionstr[ebackup-1] = "Update embedded backup"; @@ -1290,6 +1292,7 @@ u32 FileHandlerMenu(char* current_path, u32* cursor, u32* scroll, PaneData** pan if (font > 0) optionstr[font-1] = "Set as active font"; if (agbexport > 0) optionstr[agbexport-1] = "Dump GBA VC save"; if (agbimport > 0) optionstr[agbimport-1] = "Inject GBA VC save"; + if (setup > 0) optionstr[setup-1] = "Set as default"; // auto select when there is only one option user_select = (n_opt <= 1) ? n_opt : (int) ShowSelectPrompt(n_opt, optionstr, (n_marked > 1) ? @@ -1831,6 +1834,13 @@ u32 FileHandlerMenu(char* current_path, u32* cursor, u32* scroll, PaneData** pan } return 0; } + else if (user_select == setup) { // set as default (font) + if (filetype & FONT_PBM) { + if (SetAsSupportFile("font.pbm", file_path)) + ShowPrompt(false, "%s\nFont will be active on next boot", pathstr); + } + return 0; + } return FileHandlerMenu(current_path, cursor, scroll, pane); }