fix wad (un)installing from TCP. tested and working with wiiload 0.5.

maybe still works with older versions, too.
This commit is contained in:
giantpune 2010-02-05 06:11:07 +00:00
parent 0068e80b59
commit f8b9a0f704
2 changed files with 128 additions and 84 deletions

View File

@ -2,8 +2,8 @@
<app version="1"> <app version="1">
<name> USB Loader GX</name> <name> USB Loader GX</name>
<coder>USB Loader GX Team</coder> <coder>USB Loader GX Team</coder>
<version>1.0 r903</version> <version>1.0 r905</version>
<release_date>201002011252</release_date> <release_date>201002050448</release_date>
<short_description>Loads games from USB-devices</short_description> <short_description>Loads games from USB-devices</short_description>
<long_description>USB Loader GX is a libwiigui based USB iso loader with a wii-like GUI. You can install games to your HDDs and boot them with shorter loading times. <long_description>USB Loader GX is a libwiigui based USB iso loader with a wii-like GUI. You can install games to your HDDs and boot them with shorter loading times.
The interactive GUI is completely controllable with WiiMote, Classic Controller or GC Controller. The interactive GUI is completely controllable with WiiMote, Classic Controller or GC Controller.

View File

@ -33,6 +33,13 @@
struct discHdr * titleList=NULL; struct discHdr * titleList=NULL;
//discHdr ** titleList; //discHdr ** titleList;
u32 titleCnt; u32 titleCnt;
extern u32 infilesize;
extern u32 uncfilesize;
extern char wiiloadVersion[2];
#include <zlib.h>
#include "settings/cfg.h"
#include "unzip/unzip.h"
#include "unzip/miniunz.h"
extern struct discHdr * gameList; extern struct discHdr * gameList;
extern u32 gameCnt; extern u32 gameCnt;
@ -417,7 +424,7 @@ int TitleBrowser(u32 type) {
char filesizetxt[50]; char filesizetxt[50];
char temp[50]; char temp[50];
char filepath[100]; char filepath[100];
u32 read = 0; // u32 read = 0;
//make sure there is a folder for this to be saved in //make sure there is a folder for this to be saved in
struct stat st; struct stat st;
@ -438,13 +445,18 @@ int TitleBrowser(u32 type) {
snprintf(temp, sizeof(temp), tr("Load file from: %s ?"), GetIncommingIP()); snprintf(temp, sizeof(temp), tr("Load file from: %s ?"), GetIncommingIP());
int choice = WindowPrompt(filesizetxt, temp, tr("OK"), tr("Cancel")); int choice = WindowPrompt(filesizetxt, temp, tr("OK"), tr("Cancel"));
gprintf("\nchoice:%d",choice);
if (choice == 1) { if (choice == 1) {
FILE *file = fopen(filepath, "wb");
u32 read = 0;
u8 *temp = NULL;
int len = NETWORKBLOCKSIZE; int len = NETWORKBLOCKSIZE;
u8 *buffer = (u8*) malloc(NETWORKBLOCKSIZE); temp = (u8 *) malloc(infilesize);
bool error = false;
u8 *ptr = temp;
gprintf("\nrecieving shit");
while (read < infilesize) { while (read < infilesize) {
ShowProgress(tr("Receiving file from:"), GetIncommingIP(), NULL, read, infilesize, true); ShowProgress(tr("Receiving file from:"), GetIncommingIP(), NULL, read, infilesize, true);
@ -454,39 +466,58 @@ int TitleBrowser(u32 type) {
else else
len = NETWORKBLOCKSIZE; len = NETWORKBLOCKSIZE;
int result = network_read(buffer, len); int result = network_read(ptr, len);
if (result < 0) { if (result < 0) {
WindowPrompt(tr("Error while transfering data."), 0, tr("OK")); WindowPrompt(tr("Error while transfering data."), 0, tr("OK"));
fclose(file); error = true;
remove(filepath);
break; break;
} }
if (!result) if (!result) {
gprintf("\n!RESULT");
break; break;
}
fwrite(temp, 1, len, file); ptr += result;
read += result; read += result;
} }
free(buffer);
fclose(file);
ProgressStop(); ProgressStop();
if (read != infilesize) {
WindowPrompt(tr("Error:"), tr("No data could be read."), tr("OK"));
remove(filepath);
} else {
//determine what type of file we just got
char filename[101]; char filename[101];
char tmptxt[200]; char tmptxt[200];
//bool installWad=0;
if (!error) {
gprintf("\nno error yet");
network_read((u8*) &filename, 100); network_read((u8*) &filename, 100);
gprintf("\nfilename: %s",filename);
// Do we need to unzip this thing?
if (wiiloadVersion[0] > 0 || wiiloadVersion[1] > 4) {
gprintf("\nusing newer wiiload version");
if (uncfilesize != 0) { // if uncfilesize == 0, it's not compressed
gprintf("\ntrying to uncompress");
// It's compressed, uncompress
u8 *unc = (u8 *) malloc(uncfilesize);
uLongf f = uncfilesize;
error = uncompress(unc, &f, temp, infilesize) != Z_OK;
uncfilesize = f;
free(temp);
temp = unc;
}
}
if (!error) {
sprintf(tmptxt,"%s",filename); sprintf(tmptxt,"%s",filename);
//if we got a wad //if we got a wad
if (strcasestr(tmptxt,".wad")) { if (strcasestr(tmptxt,".wad")) {
FILE *file = fopen(filepath, "wb");
fwrite(temp, 1, (uncfilesize>0?uncfilesize:infilesize), file);
fclose(file);
sprintf(tmptxt,"%s/wad/%s",bootDevice,filename); sprintf(tmptxt,"%s/wad/%s",bootDevice,filename);
if (checkfile(tmptxt))remove(tmptxt); if (checkfile(tmptxt))remove(tmptxt);
@ -501,7 +532,8 @@ int TitleBrowser(u32 type) {
lSize = ftell (file); lSize = ftell (file);
rewind (file); rewind (file);
if (lSize==infilesize) { if (lSize==(uncfilesize>0?uncfilesize:infilesize)) {
gprintf("\nsize is ok");
int pick = WindowPrompt(tr(" Wad Saved as:"), tmptxt, tr("Install"),tr("Uninstall"),tr("Cancel")); int pick = WindowPrompt(tr(" Wad Saved as:"), tmptxt, tr("Install"),tr("Uninstall"),tr("Cancel"));
//install or uninstall it //install or uninstall it
if (pick==1) if (pick==1)
@ -525,19 +557,31 @@ int TitleBrowser(u32 type) {
} }
if (pick==2)Wad_Uninstall(file); if (pick==2)Wad_Uninstall(file);
} }
else gprintf("\nBad size");
//close that beast, we're done with it //close that beast, we're done with it
fclose (file); fclose (file);
//do we want to keep the file in the wad folder //do we want to keep the file in the wad folder
if (WindowPrompt(tr("Delete ?"), tmptxt, tr("Delete"),tr("Keep"))!=0) if (WindowPrompt(tr("Delete ?"), tmptxt, tr("Delete"),tr("Keep"))!=0)
remove(tmptxt); remove(tmptxt);
}
else {
WindowPrompt(tr("ERROR:"), tr("Not a WAD file."), tr("OK"));
}
}
}
} else {
WindowPrompt(tr("ERROR:"),tr("The file is not a .wad"),tr("OK"));
remove(filepath); if (error || read != infilesize) {
} WindowPrompt(tr("Error:"), tr("No data could be read."), tr("OK"));
if(temp)free(temp);
} }
} }
CloseConnection(); CloseConnection();
ResumeNetworkWait(); ResumeNetworkWait();
} }