Skip to content

Commit

Permalink
add support for reading language files from all devices (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
KrahJohlito authored and Tupakaveli committed Aug 22, 2019
1 parent 38e50a0 commit 1d3c470
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 13 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -49,6 +49,7 @@ USB modes:
| "CFG" | for saving per-game configuration files | all |
| "ART" | for game art images | all |
| "THM" | for themes support | all |
| "LNG" | for translation support | all |
| "CHT" | for cheats files | all |
| "CFG-DEV" | for saving per-game configuration files, when used from a OPL dev build - aka beta build | all |

Expand Down
1 change: 1 addition & 0 deletions include/lang.h
Expand Up @@ -283,6 +283,7 @@ typedef struct
char *name;
} language_t;

int lngAddLanguages(char *path, const char *separator);
void lngInit(void);
char *lngGetValue(void);
void lngEnd(void);
Expand Down
3 changes: 3 additions & 0 deletions src/ethsupport.c
Expand Up @@ -258,6 +258,9 @@ static void ethInitSMB(void)
sprintf(path, "%sTHM", ethPrefix);
thmAddElements(path, "\\", ethGameList.mode);

sprintf(path, "%sLNG", ethPrefix);
lngAddLanguages(path, "\\");

sbCreateFolders(ethPrefix, 1);
} else if (gPCShareName[0] || !(gNetworkStartup >= ERROR_ETH_SMB_OPENSHARE)) {
ethDisplayErrorStatus();
Expand Down
2 changes: 2 additions & 0 deletions src/hddsupport.c
Expand Up @@ -41,6 +41,8 @@ static void hddInitModules(void)
char path[256];
sprintf(path, "%sTHM", hddPrefix);
thmAddElements(path, "/", hddGameList.mode);
sprintf(path, "%sLNG", hddPrefix);
lngAddLanguages(path, "/");

sbCreateFolders(hddPrefix, 0);
}
Expand Down
46 changes: 34 additions & 12 deletions src/lang.c
Expand Up @@ -351,10 +351,10 @@ static int lngLoadFromFile(char *path, char *name)
}

if (lngLoadFont(gBaseMCDir, name) != 0) {
if (lngLoadFont("mass0:", name) != 0) {
if (lngLoadFont("mass0:LNG", name) != 0) {
if (configGetInt(configGetByType(CONFIG_OPL), CONFIG_OPL_HDD_MODE, &HddStartMode) && (HddStartMode == START_MODE_AUTO)) {
hddLoadModules();
lngLoadFont("pfs0:", name);
lngLoadFont("pfs0:LNG", name);
}
}
}
Expand Down Expand Up @@ -388,24 +388,23 @@ static int lngReadEntry(int index, const char *path, const char *separator, cons
currLang->name[length - 1] = '\0';

/*file_buffer_t* fileBuffer = openFileBuffer(currLang->filePath, 1, 1024);
if (fileBuffer) {
// read localized name of language from file
if (readLineContext(fileBuffer, &currLang->name))
readLineContext(fileBuffer, &currLang->fontName);
closeFileBuffer(fileBuffer);
}*/
if (fileBuffer) {
// read localized name of language from file
if (readLineContext(fileBuffer, &currLang->name))
readLineContext(fileBuffer, &currLang->fontName);
closeFileBuffer(fileBuffer);
}*/

index++;
}
}
return index;
}

void lngInit(void)
static void lngRebuildLangNames(void)
{
fntInit();

nLanguages = listDir(gBaseMCDir, "/", MAX_LANGUAGE_FILES, &lngReadEntry);
if (guiLangNames)
free(guiLangNames);

// build the languages name list
guiLangNames = (char **)malloc((nLanguages + 2) * sizeof(char **));
Expand All @@ -421,6 +420,29 @@ void lngInit(void)
guiLangNames[nLanguages + 1] = NULL;
}

int lngAddLanguages(char *path, const char *separator)
{
int result;

result = listDir(path, separator, MAX_LANGUAGE_FILES - nLanguages, &lngReadEntry);
nLanguages += result;
lngRebuildLangNames();

const char *temp;
if (configGetStr(configGetByType(CONFIG_OPL), "language_text", &temp)) {
lngSetGuiValue(lngFindGuiID(temp));
}

return result;
}

void lngInit(void)
{
fntInit();

lngAddLanguages(gBaseMCDir, "/");
}

void lngEnd(void)
{
lngFreeFromFile();
Expand Down
2 changes: 1 addition & 1 deletion src/supportbase.c
Expand Up @@ -751,7 +751,7 @@ static void sbCreateFoldersFromList(const char *path, const char **folders)

void sbCreateFolders(const char *path, int createDiscImgFolders)
{
const char *basicFolders[] = { OPL_FOLDER, "THM", "ART", "VMC", "CHT", "APPS", NULL };
const char *basicFolders[] = { OPL_FOLDER, "THM", "LNG", "ART", "VMC", "CHT", "APPS", NULL };
const char *discImgFolders[] = { "CD", "DVD", NULL };

sbCreateFoldersFromList(path, basicFolders);
Expand Down
8 changes: 8 additions & 0 deletions src/usbsupport.c
Expand Up @@ -117,6 +117,7 @@ static int usbNeedsUpdate(void)
char path[256];
static unsigned int OldGeneration = 0;
static unsigned char ThemesLoaded = 0;
static unsigned char LanguagesLoaded = 0;
int result = 0;
iox_stat_t stat;

Expand Down Expand Up @@ -152,6 +153,13 @@ static int usbNeedsUpdate(void)
ThemesLoaded = 1;
}

// update Languages
if (!LanguagesLoaded) {
sprintf(path, "%sLNG", usbPrefix);
if (lngAddLanguages(path, "/") > 0)
LanguagesLoaded = 1;
}

sbCreateFolders(usbPrefix, 1);

return result;
Expand Down

0 comments on commit 1d3c470

Please sign in to comment.