usbloadergx/source/language/UpdateLanguage.cpp
dimok321 500dc4020f *Reworked the whole WiiTDB.xml parsing. This is now done with mxml due to a lack of memory the file is now streamed. Now the full wiitdb.xml file with all languages is always used. The update of WiiTDB is also changed. It is now only updated if the version of the wiitdb.xml file does not match the version of the online file.
*WiiTDB now falls back to english if the locale language is not found for Titles/Synopsis
*Some clean up and memory leak fixes in game info prompt and adjusted the info get to the new WiiTDB reading method.
*Added a few new useful functions from WiiXplorer (DownloadToFileWithProgress, ShowError,...)
*Disabled the console output after the GUI is started up. The info is only output to gecko in GUI mode now.
2010-12-03 18:38:57 +00:00

79 lines
2.2 KiB
C++

/****************************************************************************
* languagefile updater
* for USB Loader GX *giantpune*
***************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/dir.h>
#include "UpdateLanguage.h"
#include "FileOperations/fileops.h"
#include "FileOperations/DirList.h"
#include "menu.h"
#include "network/networkops.h"
#include "network/http.h"
int updateLanguageFiles()
{
char languageFiles[50][MAXLANGUAGEFILES];
DirList Dir(Settings.languagefiles_path);
//give up now if we didn't find any
if (Dir.GetFilecount() == 0) return -2;
//now from the files we got, get only the .lang files
for (int cnt = 0; cnt < Dir.GetFilecount(); cnt++)
{
char filename[64];
strlcpy(filename, Dir.GetFilename(cnt), sizeof(filename));
if (strcasestr(filename, ".lang"))
{
strcpy(languageFiles[cnt], filename);
}
}
CreateSubfolder(Settings.languagefiles_path);
//we assume that the network will already be init by another function
// ( that has gui eletents in it because this one doesn't)
int done = 0, j = 0;
if (IsNetworkInit())
{
//build the URL, save path, and download each file and save it
while (j < Dir.GetFilecount())
{
char savepath[150];
char codeurl[200];
snprintf(codeurl, sizeof(codeurl), "http://usbloader-gui.googlecode.com/svn/trunk/Languages/%s",
languageFiles[j]);
snprintf(savepath, sizeof(savepath), "%s/%s", Settings.languagefiles_path, languageFiles[j]);
struct block file = downloadfile(codeurl);
if (file.data != NULL)
{
FILE * pfile;
pfile = fopen(savepath, "wb");
if (pfile != NULL)
{
fwrite(file.data, 1, file.size, pfile);
fclose(pfile);
free(file.data);
done++;
}
}
j++;
}
}
//if there was no network init
else return -1;
// return the number of files we updated
return done;
}