*Changed to download files under their real filename

*Small change to the download request function, added filename reading
This commit is contained in:
dimok321 2009-11-02 22:15:28 +00:00
parent 12e42498dc
commit d3d2055583
5 changed files with 717 additions and 696 deletions

File diff suppressed because one or more lines are too long

View File

@ -1 +1 @@
<pd><ViewState><e p="gui\source\mload" x="false"></e><e p="gui\source\settings" x="false"></e><e p="gui\source\images" x="false"></e><e p="gui\source\prompts" x="true"></e><e p="gui\source\banner" x="false"></e><e p="gui\source\cheats" x="false"></e><e p="gui\source\network" x="true"></e><e p="gui\source\unzip" x="false"></e><e p="gui\source\usbloader" x="true"></e><e p="gui\source\xml" x="false"></e><e p="gui\source\fonts" x="false"></e><e p="gui\source\ramdisc" x="false"></e><e p="gui\source\sounds" x="false"></e><e p="gui\source\wad" x="false"></e><e p="gui" x="true"></e><e p="gui\source\homebrewboot" x="false"></e><e p="gui\source\language" x="false"></e><e p="gui\source" x="true"></e><e p="gui\source\libwbfs" x="false"></e><e p="gui\source\libwiigui" x="true"></e><e p="gui\source\patches" x="false"></e><e p="gui\source\themes" x="false"></e></ViewState></pd>
<pd><ViewState><e p="gui\source\mload" x="false"></e><e p="gui\source\settings" x="false"></e><e p="gui\source\images" x="false"></e><e p="gui\source\prompts" x="true"></e><e p="gui\source\banner" x="false"></e><e p="gui\source\cheats" x="false"></e><e p="gui\source\network" x="true"></e><e p="gui\source\unzip" x="false"></e><e p="gui\source\usbloader" x="true"></e><e p="gui\source\xml" x="false"></e><e p="gui\source\fonts" x="false"></e><e p="gui\source\ramdisk" x="false"></e><e p="gui\source\sounds" x="false"></e><e p="gui\source\wad" x="false"></e><e p="gui" x="true"></e><e p="gui\source\homebrewboot" x="false"></e><e p="gui\source\language" x="false"></e><e p="gui\source" x="true"></e><e p="gui\source\libwbfs" x="false"></e><e p="gui\source\libwiigui" x="true"></e><e p="gui\source\patches" x="false"></e><e p="gui\source\themes" x="false"></e></ViewState></pd>

View File

@ -99,7 +99,7 @@ bool ShutdownWC24() {
return onlinefix;
}
s32 network_request(const char * request) {
s32 network_request(const char * request, char * filename) {
char buf[1024];
char *ptr = NULL;
@ -122,6 +122,24 @@ s32 network_request(const char * request) {
/* HTTP request OK? */
if (!strstr(buf, "HTTP/1.1 200 OK"))
return -1;
if(filename)
{
/* Get filename */
ptr = strstr(buf, "filename=\"");
if(ptr)
{
ptr += sizeof("filename=\"")-1;
for(cnt = 0; ptr[cnt] != '\r' && ptr[cnt] != '\n' && ptr[cnt] != '"'; cnt++)
{
filename[cnt] = ptr[cnt];
filename[cnt+1] = '\0';
}
}
}
/* Retrieve content size */
ptr = strstr(buf, "Content-Length:");
if (!ptr)
@ -156,7 +174,7 @@ s32 network_read(u8 *buf, u32 len) {
/****************************************************************************
* Download request
***************************************************************************/
s32 download_request(const char * url) {
s32 download_request(const char * url, char * filename) {
//Check if the url starts with "http://", if not it is not considered a valid url
if (strncmp(url, "http://", strlen("http://")) != 0) {
@ -190,7 +208,7 @@ s32 download_request(const char * url) {
char header[strlen(path)+strlen(domain)+strlen(url)+100];
sprintf(header, "GET %s HTTP/1.1\r\nHost: %s\r\nReferer: %s\r\nConnection: close\r\n\r\n", path, domain, url);
s32 filesize = network_request(header);
s32 filesize = network_request(header, filename);
return filesize;
}

View File

@ -15,9 +15,9 @@ bool IsNetworkInit(void);
char * GetNetworkIP(void);
char * GetIncommingIP(void);
bool ShutdownWC24();
s32 network_request(const char * request);
s32 network_request(const char * request, char * filename);
s32 network_read(u8 *buf, u32 len);
s32 download_request(const char * url);
s32 download_request(const char * url, char * filename = NULL);
void CloseConnection();
int CheckUpdate();

View File

@ -39,7 +39,10 @@ bool DownloadTheme(const char *url, const char *title)
if(!url)
return false;
int filesize = download_request(url);
char filename[255];
memset(filename, 0, sizeof(filename));
int filesize = download_request(url, (char *) &filename);
if(filesize <= 0)
{
@ -54,7 +57,7 @@ bool DownloadTheme(const char *url, const char *title)
subfoldercreate(path);
snprintf(filepath, sizeof(filepath), "%s/%s.zip", path, title);
snprintf(filepath, sizeof(filepath), "%s/%s", path, filename);
FILE *file = fopen(filepath, "wb");
if(!file)
@ -74,7 +77,7 @@ bool DownloadTheme(const char *url, const char *title)
if((u32) blocksize > filesize-done)
blocksize = filesize-done;
ShowProgress(tr("Downloading file"), 0, (char*) title, done, filesize, true);
ShowProgress(tr("Downloading file"), 0, (char*) filename, done, filesize, true);
int ret = network_read(buffer, blocksize);
if(ret < 0)
@ -436,7 +439,7 @@ int Theme_Downloader()
w.Append(&HomeBtn);
ResumeGui();
ShowProgress(tr("Downloading Page List:"), 0, (char *) tr("Please wait..."), 0, pagesize);
ShowProgress(tr("Downloading Page List:"), "", (char *) tr("Please wait..."), 0, pagesize);
snprintf(url, sizeof(url), "%sthemes.php?creator=&sort=1&page=%i", THEME_LINK, currentpage);