* Added initial support for the new wiiload (compressed protocol), uncompressed protocol is also supported

* Added initial (untested!) support for the zip file format, which is supported by the HBC
* Began working on compressed wad files. Uncompressing fails for now, so uploading WAD files should be done with the previous version of Wiiload.
* Fixed issue 902 (hence the large commit).
This commit is contained in:
e.bovendeur 2009-09-30 23:10:58 +00:00
parent b83a379014
commit 1cc7d3acd6
132 changed files with 60352 additions and 60174 deletions

View File

@ -22,6 +22,10 @@
#include "filelist.h"
#include "sys.h"
#include "network/http.h"
#include <zlib.h>
#include "Settings/cfg.h"
#include "unzip/unzip.h"
#include "unzip/miniunz.h"
/*** Extern functions ***/
extern void ResumeGui();
@ -32,8 +36,12 @@ extern GuiWindow * mainWindow;
extern GuiSound * bgMusic;
extern GuiImage * bgImg;
extern u32 infilesize;
extern u32 uncfilesize;
extern char wiiloadVersion[2];
extern u8 shutdown;
extern u8 reset;
extern struct SSettings Settings;
extern void *innetbuffer;
/*** Variables used elsewhere ***/
u8 boothomebrew = 0;
@ -802,8 +810,10 @@ int MenuHomebrewBrowse() {
u32 read = 0;
u8 *temp = NULL;
int len = NETWORKBLOCKSIZE;
temp = (u8*) malloc(len);
temp = (u8 *) malloc(infilesize);
bool error = false;
u8 *ptr = temp;
while (read < infilesize) {
ShowProgress(tr("Receiving file from:"), GetIncommingIP(), NULL, read, infilesize, true);
@ -813,37 +823,87 @@ int MenuHomebrewBrowse() {
else
len = NETWORKBLOCKSIZE;
int result = network_read(temp, len);
int result = network_read(ptr, len);
if (result < 0) {
WindowPrompt(tr("Error while transfering data."), 0, tr("OK"));
FreeHomebrewBuffer();
error = true;
break;
}
if (!result)
if (!result) {
break;
}
CopyHomebrewMemory(read, temp, len);
ptr += result;
read += result;
}
char filename[101];
if (!error) {
network_read((u8*) &filename, 100);
// Do we need to unzip this thing?
if (wiiloadVersion[0] > 0 || wiiloadVersion[1] > 4) {
// We need to unzip...
if (temp[0] == 'P' && temp[1] == 'K' && temp[2] == 0x03 && temp[2] == 0x04) {
// It's a zip file, unzip to the apps directory
// Zip archive, ask for permission to install the zip
char zippath[255];
sprintf((char *) &zippath, "%s%s", Settings.homebrewapps_path, filename);
FILE *fp = fopen(zippath, "wb");
if (fp != NULL)
{
fwrite(temp, 1, infilesize, fp);
fclose(fp);
// Now unzip the zip file...
unzFile uf = unzOpen(zippath);
if (uf==NULL) {
error = true;
} else {
extractZip(uf,0,1,0);
unzCloseCurrentFile(uf);
remove(zippath);
}
}
} else if (uncfilesize != 0) { // if uncfilesize == 0, it's not compressed
// 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 && strstr(filename,".zip") == NULL) {
innetbuffer = temp;
}
}
ProgressStop();
if (read != infilesize) {
if (error || read != infilesize) {
WindowPrompt(tr("Error:"), tr("No data could be read."), tr("OK"));
FreeHomebrewBuffer();
} else {
char filename[101];
network_read((u8*) &filename, 100);
if (strstr(filename,".dol") || strstr(filename,".DOL")
|| strstr(filename,".elf") || strstr(filename,".ELF")) {
boothomebrew = 2;
menu = MENU_EXIT;
CloseConnection();
break;
} else if (strstr(filename,".zip")) {
WindowPrompt(tr("SUCCESS:"), tr("Uploaded zip file installed to homebrew directory."), tr("OK"));
CloseConnection();
} else {
FreeHomebrewBuffer();
WindowPrompt(tr("ERROR:"), tr("Not a dol/elf file."), tr("OK"));

View File

@ -22,6 +22,7 @@
/*** Incomming filesize ***/
u32 infilesize = 0;
u32 uncfilesize = 0;
bool updateavailable = false;
s32 connection;
@ -32,6 +33,7 @@ static bool checkincomming = false;
static bool waitforanswer = false;
static char IP[16];
char incommingIP[50];
char wiiloadVersion[2];
static lwp_t networkthread = LWP_THREAD_NULL;
static bool networkHalt = true;
@ -250,7 +252,14 @@ int NetworkWait() {
unsigned char haxx[9];
//skip haxx
net_read(connection, &haxx, 8);
wiiloadVersion[0] = haxx[4];
wiiloadVersion[1] = haxx[5];
net_read(connection, &infilesize, 4);
if (haxx[4] > 0 || haxx[5] > 4) {
net_read(connection, &uncfilesize, 4); // Compressed protocol, read another 4 bytes
}
waitforanswer = true;
checkincomming = false;
networkHalt = true;

View File

@ -24,6 +24,7 @@
#include "wad/wad.h"
#include "xml/xml.h"
#include "../wad/title.h"
#include "unzip/inflate.h"
/*** Extern functions ***/
extern void ResumeGui();
@ -34,7 +35,8 @@ extern GuiWindow * mainWindow;
extern u8 shutdown;
extern u8 reset;
extern u32 infilesize;
extern u32 uncfilesize;
extern char wiiloadVersion[2];
/********************************************************************************
* TitleBrowser- opens a browser with a list of installed Titles
@ -417,7 +419,12 @@ int TitleBrowser(u32 type) {
int choice = WindowPrompt(filesizetxt, temp, tr("OK"), tr("Cancel"));
if(choice == 1) {
FILE *file = fopen(filepath, "wb");
bool compressed = (wiiloadVersion[0] > 1 || wiiloadVersion[1] > 4) && uncfilesize != 0;
char currentPath[100];
sprintf(currentPath, compressed ? "%s.z" : "%s", filepath);
FILE *file = fopen(currentPath, "wb");
int len = NETWORKBLOCKSIZE;
u8 *buffer = (u8*) malloc(NETWORKBLOCKSIZE);
@ -449,6 +456,24 @@ int TitleBrowser(u32 type) {
}
free(buffer);
fclose(file);
if (compressed) {
FILE *cfile = fopen(currentPath, "rb");
FILE *ufile = fopen(filepath, "wb");
int r;
if (( r = inflateFile(cfile, ufile)) != Z_OK) {
char buf[100];
sprintf((char *) &buf, "Inflate failed: %d", r);
WindowPrompt(tr("Compressed:"), (char *) &buf, tr("OK"));
}
fclose(cfile);
fclose(ufile);
remove(currentPath);
}
ProgressStop();
if (read != infilesize) {
@ -456,6 +481,10 @@ int TitleBrowser(u32 type) {
remove(filepath);
} else {
if (compressed) {
infilesize = uncfilesize;
}
//determine what type of file we just got
char filename[101];
char tmptxt[200];

62
source/unzip/inflate.c Normal file
View File

@ -0,0 +1,62 @@
#include "inflate.h"
#define CHUNK 1024
int inflateFile(FILE *source, FILE *dest)
{
int ret;
unsigned have;
z_stream strm;
unsigned char in[CHUNK];
unsigned char out[CHUNK];
/* allocate inflate state */
strm.zalloc = Z_NULL;
strm.zfree = Z_NULL;
strm.opaque = Z_NULL;
strm.avail_in = 0;
strm.next_in = Z_NULL;
ret = inflateInit(&strm);
if (ret != Z_OK)
return ret;
/* decompress until deflate stream ends or end of file */
do {
strm.avail_in = fread(in, 1, CHUNK, source);
if (ferror(source)) {
(void)inflateEnd(&strm);
return Z_ERRNO;
}
if (strm.avail_in == 0)
break;
strm.next_in = in;
/* run inflate() on input until output buffer not full */
do {
strm.avail_out = CHUNK;
strm.next_out = out;
ret = inflate(&strm, Z_NO_FLUSH);
switch (ret) {
case Z_NEED_DICT:
(void)inflateEnd(&strm);
return -20;
case Z_DATA_ERROR:
(void)inflateEnd(&strm);
return -21;
case Z_MEM_ERROR:
(void)inflateEnd(&strm);
return -22;
}
have = CHUNK - strm.avail_out;
if (fwrite(out, 1, have, dest) != have || ferror(dest)) {
(void)inflateEnd(&strm);
return Z_ERRNO;
}
} while (strm.avail_out == 0);
/* done when inflate() says it's done */
} while (ret != Z_STREAM_END);
/* clean up and return */
(void)inflateEnd(&strm);
return ret == Z_STREAM_END ? Z_OK : Z_DATA_ERROR;
}

18
source/unzip/inflate.h Normal file
View File

@ -0,0 +1,18 @@
#ifndef _INFLATE_H
#define _INFLATE_H
#include <stdio.h>
#include <zlib.h>
#ifdef __cplusplus
extern "C" {
#endif
int inflateFile(FILE *source, FILE *dest);
#ifdef __cplusplus
}
#endif
#endif //_INFLATE_H