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