Skip to content

Commit 9a227b9

Browse files
committed
Ability to setup a default font
1 parent 03d1255 commit 9a227b9

File tree

4 files changed

+59
-1
lines changed

4 files changed

+59
-1
lines changed

arm9/source/filesys/filetype.h

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
#define FTYPE_SCRIPT(tp) (tp&(TXT_SCRIPT))
6868
#define FTYPE_FONT(tp) (tp&(FONT_PBM))
6969
#define FTYPE_GFX(tp) (tp&(GFX_PNG))
70+
#define FTYPE_SETABLE(tp) (tp&(FONT_PBM))
7071
#define FTYPE_BOOTABLE(tp) (tp&(SYS_FIRM))
7172
#define FTYPE_INSTALLABLE(tp) (tp&(SYS_FIRM))
7273
#define FTYPE_AGBSAVE(tp) (tp&(SYS_AGBSAVE))

arm9/source/filesys/support.c

+45
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,51 @@ size_t LoadSupportFile(const char* fname, void* buffer, size_t max_len)
4848
return 0;
4949
}
5050

51+
bool SaveSupportFile(const char* fname, void* buffer, size_t len)
52+
{
53+
const char* base_paths[] = { SUPPORT_FILE_PATHS };
54+
int idx = -1;
55+
56+
// check for existing support file path
57+
for (u32 i = 0; (idx < 0) && (i < countof(base_paths)); i++) {
58+
if (fvx_stat(base_paths[i], NULL) == FR_OK)
59+
idx = i;
60+
}
61+
62+
// create path if required
63+
for (u32 i = 0; (idx < 0) && (i < countof(base_paths)); i++) {
64+
if (fvx_rmkdir(base_paths[i]) == FR_OK)
65+
idx = i;
66+
}
67+
68+
// write support file
69+
if (idx >= 0) {
70+
char path[256];
71+
snprintf(path, 256, "%s/%s", base_paths[idx], fname);
72+
fvx_unlink(path);
73+
if (fvx_qwrite(path, buffer, 0, len, NULL) == FR_OK)
74+
return true;
75+
}
76+
77+
return false;
78+
}
79+
80+
bool SetAsSupportFile(const char* fname, const char* source)
81+
{
82+
u32 len = fvx_qsize(source);
83+
if (!len) return false;
84+
85+
void* buffer = malloc(len);
86+
if (!buffer) return false;
87+
88+
bool res = false;
89+
if (fvx_qread(source, buffer, 0, len, NULL) == FR_OK)
90+
res = SaveSupportFile(fname, buffer, len);
91+
free(buffer);
92+
93+
return res;
94+
}
95+
5196
bool GetSupportDir(char* path, const char* dname)
5297
{
5398
const char* base_paths[] = { SUPPORT_DIR_PATHS };

arm9/source/filesys/support.h

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
bool CheckSupportFile(const char* fname);
1010
size_t LoadSupportFile(const char* fname, void* buffer, size_t max_len);
11+
bool SaveSupportFile(const char* fname, void* buffer, size_t len);
12+
bool SetAsSupportFile(const char* fname, const char* source);
1113

1214
bool CheckSupportDir(const char* fpath);
1315
bool FileSelectorSupport(char* result, const char* text, const char* dname, const char* pattern);

arm9/source/godmode.c

+11-1
Original file line numberDiff line numberDiff line change
@@ -1044,6 +1044,7 @@ u32 FileHandlerMenu(char* current_path, u32* cursor, u32* scroll, PaneData** pan
10441044
bool scriptable = (FTYPE_SCRIPT(filetype));
10451045
bool fontable = (FTYPE_FONT(filetype));
10461046
bool viewable = (FTYPE_GFX(filetype));
1047+
bool setable = (FTYPE_SETABLE(filetype));
10471048
bool bootable = (FTYPE_BOOTABLE(filetype));
10481049
bool installable = (FTYPE_INSTALLABLE(filetype));
10491050
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
11091110
(filetype & BIN_LEGKEY) ? "Build " KEYDB_NAME :
11101111
(filetype & BIN_NCCHNFO)? "NCCHinfo options..." :
11111112
(filetype & TXT_SCRIPT) ? "Execute GM9 script" :
1112-
(filetype & FONT_PBM) ? "Set as active font" :
1113+
(filetype & FONT_PBM) ? "Font options..." :
11131114
(filetype & GFX_PNG) ? "View PNG file" :
11141115
(filetype & HDR_NAND) ? "Rebuild NCSD header" :
11151116
(filetype & NOIMG_NAND) ? "Rebuild NCSD header" : "???";
@@ -1259,6 +1260,7 @@ u32 FileHandlerMenu(char* current_path, u32* cursor, u32* scroll, PaneData** pan
12591260
int view = (viewable) ? ++n_opt : -1;
12601261
int agbexport = (agbexportable) ? ++n_opt : -1;
12611262
int agbimport = (agbimportable) ? ++n_opt : -1;
1263+
int setup = (setable) ? ++n_opt : -1;
12621264
if (mount > 0) optionstr[mount-1] = (filetype & GAME_TMD) ? "Mount CXI/NDS to drive" : "Mount image to drive";
12631265
if (restore > 0) optionstr[restore-1] = "Restore SysNAND (safe)";
12641266
if (ebackup > 0) optionstr[ebackup-1] = "Update embedded backup";
@@ -1290,6 +1292,7 @@ u32 FileHandlerMenu(char* current_path, u32* cursor, u32* scroll, PaneData** pan
12901292
if (font > 0) optionstr[font-1] = "Set as active font";
12911293
if (agbexport > 0) optionstr[agbexport-1] = "Dump GBA VC save";
12921294
if (agbimport > 0) optionstr[agbimport-1] = "Inject GBA VC save";
1295+
if (setup > 0) optionstr[setup-1] = "Set as default";
12931296

12941297
// auto select when there is only one option
12951298
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
18311834
}
18321835
return 0;
18331836
}
1837+
else if (user_select == setup) { // set as default (font)
1838+
if (filetype & FONT_PBM) {
1839+
if (SetAsSupportFile("font.pbm", file_path))
1840+
ShowPrompt(false, "%s\nFont will be active on next boot", pathstr);
1841+
}
1842+
return 0;
1843+
}
18341844

18351845
return FileHandlerMenu(current_path, cursor, scroll, pane);
18361846
}

0 commit comments

Comments
 (0)