2009-07-29 19:18:04 +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"
|
|
|
|
#include "listfiles.h"
|
|
|
|
#include "menu.h"
|
|
|
|
#include "network/networkops.h"
|
|
|
|
#include "network/http.h"
|
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
int updateLanguageFiles() {
|
2009-08-09 10:07:27 +02:00
|
|
|
char languageFiles[50][MAXLANGUAGEFILES];
|
2009-07-29 19:18:04 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
//get all the files in the language path
|
|
|
|
int countfiles = GetAllDirFiles(Settings.languagefiles_path);
|
2009-07-29 19:18:04 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
//give up now if we didn't find any
|
2009-08-09 10:07:27 +02:00
|
|
|
if (!countfiles) return -2;
|
2009-07-29 19:18:04 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
//now from the files we got, get only the .lang files
|
|
|
|
for (int cnt = 0; cnt < countfiles; cnt++) {
|
|
|
|
char filename[64];
|
|
|
|
strncpy(filename, GetFileName(cnt),63);
|
|
|
|
if (strcasestr(filename,".lang")) {
|
|
|
|
strcpy(languageFiles[cnt],filename);
|
|
|
|
}
|
|
|
|
}
|
2009-07-29 19:18:04 +02:00
|
|
|
|
2009-08-09 10:07:27 +02:00
|
|
|
subfoldercreate(Settings.languagefiles_path);
|
|
|
|
|
2009-07-30 07:41:12 +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)
|
2009-08-09 10:07:27 +02:00
|
|
|
int done = 0,j = 0;
|
2009-07-30 07:41:12 +02:00
|
|
|
if (IsNetworkInit()) {
|
|
|
|
//build the URL, save path, and download each file and save it
|
|
|
|
while (j<countfiles) {
|
|
|
|
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");
|
2009-08-09 10:07:27 +02:00
|
|
|
if(pfile != NULL) {
|
|
|
|
fwrite(file.data,1,file.size,pfile);
|
|
|
|
fclose(pfile);
|
|
|
|
free(file.data);
|
|
|
|
done++;
|
|
|
|
}
|
2009-07-30 07:41:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
//if there was no network init
|
|
|
|
else return -1;
|
|
|
|
|
|
|
|
// return the number of files we updated
|
2009-07-29 19:18:04 +02:00
|
|
|
return done;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|