2009-10-01 01:10:58 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* languagefile updater
|
2011-07-26 00:28:22 +02:00
|
|
|
* for USB Loader GX *giantpune*
|
2009-10-01 01:10:58 +02:00
|
|
|
***************************************************************************/
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/dir.h>
|
|
|
|
|
|
|
|
#include "UpdateLanguage.h"
|
2010-12-18 14:20:45 +01:00
|
|
|
#include "gettext.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-12-18 14:20:45 +01:00
|
|
|
#include "network/URL_List.h"
|
|
|
|
#include "prompts/ProgressWindow.h"
|
|
|
|
#include "utils/ShowError.h"
|
|
|
|
#include "gecko.h"
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2011-10-22 12:37:58 +02:00
|
|
|
static const char * LanguageFilesURL = "http://usbloader-gui.googlecode.com/svn/tags/USBLoaderGX_v2_3/Languages/";
|
2010-12-18 14:20:45 +01:00
|
|
|
|
|
|
|
int DownloadAllLanguageFiles()
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
if(!CreateSubfolder(Settings.languagefiles_path))
|
|
|
|
{
|
|
|
|
ShowError(tr("Could not create path: %s"), Settings.languagefiles_path);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!IsNetworkInit())
|
|
|
|
{
|
|
|
|
ShowError(tr("Network is not initiated."));
|
|
|
|
return -2;
|
|
|
|
}
|
|
|
|
char fullURL[300];
|
|
|
|
|
|
|
|
URL_List LinkList(LanguageFilesURL);
|
|
|
|
int listsize = LinkList.GetURLCount();
|
|
|
|
int files_downloaded = 0;
|
|
|
|
|
|
|
|
ShowProgress(tr("Updating Language Files:"), 0, 0, 0, listsize, false, true);
|
|
|
|
|
|
|
|
for (int i = 0; i < listsize; i++)
|
|
|
|
{
|
|
|
|
const char * filename = strrchr(LinkList.GetURL(i), '/');
|
|
|
|
if(filename) filename++;
|
|
|
|
else filename = LinkList.GetURL(i);
|
|
|
|
|
|
|
|
if(!filename)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
const char * FileExt = strrchr(filename, '.');
|
|
|
|
if (!FileExt || strcasecmp(FileExt, ".lang") != 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
gprintf("%s\n", filename);
|
|
|
|
|
|
|
|
ShowProgress(tr("Updating Language Files:"), 0, filename, i, listsize, false, true);
|
|
|
|
|
|
|
|
snprintf(fullURL, sizeof(fullURL), "%s%s", LanguageFilesURL, filename);
|
|
|
|
|
|
|
|
struct block file = downloadfile(fullURL);
|
|
|
|
if (file.data)
|
|
|
|
{
|
|
|
|
char filepath[300];
|
|
|
|
snprintf(filepath, sizeof(filepath), "%s/%s", Settings.languagefiles_path, filename);
|
|
|
|
FILE * pfile = fopen(filepath, "wb");
|
|
|
|
if(pfile)
|
|
|
|
{
|
|
|
|
fwrite(file.data, 1, file.size, pfile);
|
|
|
|
fclose(pfile);
|
|
|
|
files_downloaded++;
|
|
|
|
}
|
|
|
|
free(file.data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ProgressStop();
|
|
|
|
|
|
|
|
return files_downloaded;
|
2010-12-18 14:20:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int UpdateLanguageFiles()
|
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
if(!CreateSubfolder(Settings.languagefiles_path))
|
|
|
|
{
|
|
|
|
ShowError(tr("Could not create path: %s"), Settings.languagefiles_path);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!IsNetworkInit())
|
|
|
|
{
|
|
|
|
ShowError(tr("Network is not initiated."));
|
|
|
|
return -2;
|
|
|
|
}
|
2010-12-18 14:20:45 +01:00
|
|
|
|
|
|
|
DirList Dir(Settings.languagefiles_path, ".lang");
|
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
//give up now if we didn't find any
|
|
|
|
if (Dir.GetFilecount() == 0) return -2;
|
2010-12-18 14:20:45 +01:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
char savepath[150];
|
|
|
|
char codeurl[200];
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2011-07-26 00:28:22 +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)
|
|
|
|
int done = 0;
|
2010-12-18 14:20:45 +01:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
//build the URL, save path, and download each file and save it
|
|
|
|
for(int i = 0; i < Dir.GetFilecount(); ++i)
|
|
|
|
{
|
|
|
|
snprintf(codeurl, sizeof(codeurl), "%s%s", LanguageFilesURL, Dir.GetFilename(i));
|
|
|
|
snprintf(savepath, sizeof(savepath), "%s/%s", Settings.languagefiles_path, Dir.GetFilename(i));
|
2010-12-18 14:20:45 +01:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
struct block file = downloadfile(codeurl);
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
ShowProgress(tr("Updating Language Files:"), 0, Dir.GetFilename(i), i, Dir.GetFilecount(), false, true);
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
if (file.data != NULL)
|
|
|
|
{
|
|
|
|
FILE * pfile;
|
|
|
|
pfile = fopen(savepath, "wb");
|
|
|
|
if (pfile != NULL)
|
|
|
|
{
|
|
|
|
fwrite(file.data, 1, file.size, pfile);
|
|
|
|
fclose(pfile);
|
|
|
|
done++;
|
|
|
|
}
|
|
|
|
free(file.data);
|
|
|
|
}
|
|
|
|
}
|
2010-12-18 14:20:45 +01:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
ProgressStop();
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
// return the number of files we updated
|
|
|
|
return done;
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|