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,107 +445,144 @@ 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");
int len = NETWORKBLOCKSIZE; u32 read = 0;
u8 *buffer = (u8*) malloc(NETWORKBLOCKSIZE); u8 *temp = NULL;
int len = NETWORKBLOCKSIZE;
temp = (u8 *) malloc(infilesize);
while (read < infilesize) { bool error = false;
u8 *ptr = temp;
gprintf("\nrecieving shit");
while (read < infilesize) {
ShowProgress(tr("Receiving file from:"), GetIncommingIP(), NULL, read, infilesize, true); ShowProgress(tr("Receiving file from:"), GetIncommingIP(), NULL, read, infilesize, true);
if (infilesize - read < (u32) len) if (infilesize - read < (u32) len)
len = infilesize-read; len = infilesize-read;
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;
}
ptr += result;
read += result;
}
ProgressStop();
fwrite(temp, 1, len, file); char filename[101];
char tmptxt[200];
read += result;
}
free(buffer);
fclose(file);
ProgressStop();
if (read != infilesize) { //bool installWad=0;
WindowPrompt(tr("Error:"), tr("No data could be read."), tr("OK")); if (!error) {
remove(filepath); gprintf("\nno error yet");
} else {
//determine what type of file we just got network_read((u8*) &filename, 100);
char filename[101]; gprintf("\nfilename: %s",filename);
char tmptxt[200];
network_read((u8*) &filename, 100); // Do we need to unzip this thing?
sprintf(tmptxt,"%s",filename); if (wiiloadVersion[0] > 0 || wiiloadVersion[1] > 4) {
//if we got a wad gprintf("\nusing newer wiiload version");
if (strcasestr(tmptxt,".wad")) {
sprintf(tmptxt,"%s/wad/%s",bootDevice,filename); if (uncfilesize != 0) { // if uncfilesize == 0, it's not compressed
if (checkfile(tmptxt))remove(tmptxt); gprintf("\ntrying to uncompress");
rename(filepath, tmptxt); // It's compressed, uncompress
u8 *unc = (u8 *) malloc(uncfilesize);
uLongf f = uncfilesize;
error = uncompress(unc, &f, temp, infilesize) != Z_OK;
uncfilesize = f;
//check and make sure the wad we just saved is the correct size free(temp);
u32 lSize; temp = unc;
file = fopen(tmptxt, "rb"); }
}
// obtain file size: if (!error) {
fseek (file , 0 , SEEK_END); sprintf(tmptxt,"%s",filename);
lSize = ftell (file); //if we got a wad
if (strcasestr(tmptxt,".wad")) {
FILE *file = fopen(filepath, "wb");
fwrite(temp, 1, (uncfilesize>0?uncfilesize:infilesize), file);
fclose(file);
rewind (file); sprintf(tmptxt,"%s/wad/%s",bootDevice,filename);
if (lSize==infilesize) { if (checkfile(tmptxt))remove(tmptxt);
int pick = WindowPrompt(tr(" Wad Saved as:"), tmptxt, tr("Install"),tr("Uninstall"),tr("Cancel")); rename(filepath, tmptxt);
//install or uninstall it
if (pick==1)
{
HaltGui();
w.Remove(&titleTxt);
w.Remove(&cancelBtn);
w.Remove(&wifiBtn);
w.Remove(&optionBrowser3);
ResumeGui();
Wad_Install(file); //check and make sure the wad we just saved is the correct size
u32 lSize;
file = fopen(tmptxt, "rb");
HaltGui(); // obtain file size:
w.Append(&titleTxt); fseek (file , 0 , SEEK_END);
w.Append(&cancelBtn); lSize = ftell (file);
w.Append(&wifiBtn);
w.Append(&optionBrowser3);
ResumeGui();
} rewind (file);
if (pick==2)Wad_Uninstall(file); if (lSize==(uncfilesize>0?uncfilesize:infilesize)) {
} gprintf("\nsize is ok");
//close that beast, we're done with it int pick = WindowPrompt(tr(" Wad Saved as:"), tmptxt, tr("Install"),tr("Uninstall"),tr("Cancel"));
fclose (file); //install or uninstall it
if (pick==1)
{
HaltGui();
w.Remove(&titleTxt);
w.Remove(&cancelBtn);
w.Remove(&wifiBtn);
w.Remove(&optionBrowser3);
ResumeGui();
//do we want to keep the file in the wad folder Wad_Install(file);
if (WindowPrompt(tr("Delete ?"), tmptxt, tr("Delete"),tr("Keep"))!=0)
remove(tmptxt);
} else { HaltGui();
WindowPrompt(tr("ERROR:"),tr("The file is not a .wad"),tr("OK")); w.Append(&titleTxt);
remove(filepath); w.Append(&cancelBtn);
} w.Append(&wifiBtn);
} w.Append(&optionBrowser3);
} ResumeGui();
CloseConnection();
}
if (pick==2)Wad_Uninstall(file);
}
else gprintf("\nBad size");
//close that beast, we're done with it
fclose (file);
//do we want to keep the file in the wad folder
if (WindowPrompt(tr("Delete ?"), tmptxt, tr("Delete"),tr("Keep"))!=0)
remove(tmptxt);
}
else {
WindowPrompt(tr("ERROR:"), tr("Not a WAD file."), tr("OK"));
}
}
}
if (error || read != infilesize) {
WindowPrompt(tr("Error:"), tr("No data could be read."), tr("OK"));
if(temp)free(temp);
}
}
CloseConnection();
ResumeNetworkWait(); ResumeNetworkWait();
} }