1 #include "include/usbld.h"
2 #include "include/lang.h"
3 #include "include/util.h"
4 #include "include/fntsys.h"
5 #include "include/ioman.h"
8 static char *internalEnglish
[LANG_STR_COUNT
] = {
10 " WELCOME TO OPEN PS2 LOADER. MAIN CODE BASED ON SOURCE CODE OF HD PROJECT <http://psx-scene.com> ADAPTATION TO USB ADVANCE FORMAT AND INITIAL GUI BY IFCARO <http://ps2dev.ifcaro.net> MOST OF LOADER CORE IS MADE BY JIMMIKAELKAEL. ALL THE GUI IMPROVEMENTS ARE MADE BY VOLCA. THANKS FOR USING OUR PROGRAM ^^",
17 "Error writing settings!",
26 "Network startup error",
31 "Remove all settings",
32 "Removed all keys for the game",
40 "Error while loading the Game ID",
42 "Error loading the language file",
43 "Disable Debug Colors",
44 "No controller detected, waiting...",
51 "USB device start mode",
52 "HDD device start mode",
53 "ETH device start mode",
54 "Applications start mode",
58 "HDL Server Starting...",
59 "HDL Server Running... Press [O] to stop",
60 "Press [X] to terminate HDL server",
61 "HDL Server Unloading...",
74 "Item will be permanently deleted, continue ?",
79 "Enable Delete and Rename actions",
80 "Check USB game fragmentation",
81 "Remember last played game",
82 "Error, the game is fragmented",
83 "Error, could not run the item",
85 "Leave empty for GUEST auth.",
86 "Load alternate core",
87 "Alternative data read method",
92 "Reduced cdvdfsv buffer",
94 "Alternate IGR combo",
95 "Changing the size will reformat the VMC",
107 "Invalid VMC file, size is incorrect",
108 "VMC file need to be created",
109 "Error with VMC file, continue with physical MC ?",
115 "Leave empty to exit to Browser",
116 "Value in minute(s), 0 to disable spin down",
117 "Automatic HDD spin down",
125 static int guiLangID
= 0;
126 static char **lang_strs
= internalEnglish
;
127 static int nValidEntries
= LANG_STR_COUNT
;
129 static int nLanguages
= 0;
130 static language_t languages
[MAX_LANGUAGE_FILES
];
131 static char **guiLangNames
;
133 // localised string getter
134 char *_l(unsigned int id
) {
135 return lang_strs
[id
];
138 static void lngFreeFromFile() {
143 for(; strId
< nValidEntries
; strId
++) {
144 free(lang_strs
[strId
]);
145 lang_strs
[strId
] = NULL
;
151 static int lngLoadFromFile(char* path
, char *name
) {
152 file_buffer_t
* fileBuffer
= openFileBuffer(path
, O_RDONLY
, 1, 1024);
154 // file exists, try to read it and load the custom lang
155 lang_strs
= (char**) malloc(LANG_STR_COUNT
* sizeof(char**));
158 while (strId
< LANG_STR_COUNT
&& readFileBuffer(fileBuffer
, &lang_strs
[strId
])) {
161 closeFileBuffer(fileBuffer
);
163 LOG("LANG: #### Loaded %d entries\n", strId
);
165 // remember how many entries were read from the file (for the free later)
166 nValidEntries
= strId
;
168 // if necessary complete lang with default internal
169 while (strId
< LANG_STR_COUNT
) {
170 LOG("LANG: #### Default entry added: %s\n", internalEnglish
[strId
]);
171 lang_strs
[strId
] = internalEnglish
[strId
];
177 snprintf(path
, 255, "%s/font_%s.ttf", gBaseMCDir
, name
);
179 LOG("#### Custom font path: %s\n", path
);
181 void* customFont
= readFile(path
, -1, &size
);
183 fntReplace(FNT_DEFAULT
, customFont
, size
, 1, 1); // consider fonts loaded through language as default, so they won't be reset-ed when changing themes
185 fntSetDefault(FNT_DEFAULT
);
192 char* lngGetValue() {
193 return guiLangNames
[guiLangID
];
196 static int lngReadEntry(int index
, char* path
, char* separator
, char* name
, unsigned int mode
) {
197 if (!FIO_SO_ISDIR(mode
)) {
198 if(strstr(name
, ".lng") || strstr(name
, ".LNG")) {
200 language_t
* currLang
= &languages
[index
];
202 // filepath for this language file
203 int length
= strlen(path
) + 1 + strlen(name
) + 1;
204 currLang
->filePath
= (char*) malloc(length
* sizeof(char));
205 sprintf(currLang
->filePath
, "%s%s%s", path
, separator
, name
);
207 // extract name for this language (will be used for the English translation)
208 length
= strlen(name
) - 5 - 4 + 1;
209 currLang
->name
= (char*) malloc(length
* sizeof(char));
210 memcpy(currLang
->name
, name
+ 5, length
);
211 currLang
->name
[length
- 1] = '\0';
213 /*file_buffer_t* fileBuffer = openFileBuffer(currLang->filePath, 1, 1024);
215 // read localized name of language from file
216 if (readLineContext(fileBuffer, &currLang->name))
217 readLineContext(fileBuffer, &currLang->fontName);
218 closeFileBuffer(fileBuffer);
230 nLanguages
= listDir(gBaseMCDir
, "/", MAX_LANGUAGE_FILES
, &lngReadEntry
);
232 // build the languages name list
233 guiLangNames
= (char**) malloc((nLanguages
+ 2) * sizeof(char**));
235 // add default internal (english)
236 guiLangNames
[0] = internalEnglish
[0];
239 for (; i
< nLanguages
; i
++) {
240 guiLangNames
[i
+ 1] = languages
[i
].name
;
243 guiLangNames
[nLanguages
+ 1] = NULL
;
250 for (; i
< nLanguages
; i
++) {
251 free(languages
[i
].name
);
252 free(languages
[i
].filePath
);
260 void lngSetGuiValue(int langID
) {
261 if (guiLangID
!= langID
) {
266 language_t
* currLang
= &languages
[langID
- 1];
267 if (lngLoadFromFile(currLang
->filePath
, currLang
->name
)) {
273 lang_strs
= internalEnglish
;
278 int lngGetGuiValue() {
282 int lngFindGuiID(char* lang
) {
285 for (; i
< nLanguages
; i
++) {
286 if (stricmp(languages
[i
].name
, lang
) == 0)
287 return i
+ 1; // shift for Gui id
293 char **lngGetGuiList() {