add unzip progress for auto-update

This commit is contained in:
dborth 2009-01-25 07:09:11 +00:00
parent 07099ba282
commit aa565cc205
6 changed files with 54 additions and 13 deletions

View File

@ -491,7 +491,7 @@ int FileSelector (int method)
if(!MakeFilePath(filepath, FILE_ROM, method))
return 0;
size = LoadFileBuf((char *)nesrom, filepath, browserList[browser.selIndex].length, method, NOTSILENT);
size = LoadFile((char *)nesrom, filepath, browserList[browser.selIndex].length, method, NOTSILENT);
}
else
{

View File

@ -235,7 +235,7 @@ GetFirstZipFilename (int method)
return NULL;
// read start of ZIP
if(LoadFileBuf (tempbuffer, filepath, ZIPCHUNK, method, NOTSILENT))
if(LoadFile (tempbuffer, filepath, ZIPCHUNK, method, NOTSILENT))
{
tempbuffer[28] = 0; // truncate - filename length is 2 bytes long (bytes 26-27)
int namelength = tempbuffer[26]; // filename length starts 26 bytes in

View File

@ -12,6 +12,7 @@
#ifndef _MENUDRAW_H_
#define _MENUDRAW_H_
#include <gccore.h>
#include "filesel.h"
#define PAGESIZE 13 // max item listing on a screen

View File

@ -138,7 +138,7 @@ bool DownloadUpdate()
retval = http_request(updateURL, hfile, NULL, (1024*1024*5));
fclose (hfile);
}
ShowAction("Installing...");
bool unzipResult = unzipArchive(updateFile, (char *)"sd:/");
remove(updateFile); // delete update file

View File

@ -12,15 +12,20 @@
#include <time.h>
#include <errno.h>
#include <fcntl.h>
# include <unistd.h>
# include <utime.h>
#include <unistd.h>
#include <utime.h>
#include "unzip.h"
#include "menudraw.h"
#define CASESENSITIVITY (0)
#define WRITEBUFFERSIZE (1024*256)
#define MAXFILENAME (256)
// used to display unzip progress
static uLong total_size;
static uLong total_unzipped;
static int mymkdir(const char* dirname)
{
int ret=0;
@ -204,6 +209,9 @@ static int do_extract_currentfile(unzFile uf,const int* popt_extract_without_pat
err=UNZ_ERRNO;
break;
}
total_unzipped += size_buf;
// show progress
ShowProgress("Unzipping...", total_unzipped, total_size);
}
while (err>0);
if (fout)
@ -227,6 +235,42 @@ static int do_extract_currentfile(unzFile uf,const int* popt_extract_without_pat
return err;
}
static uLong zipSize(unzFile uf)
{
uLong i;
unz_global_info gi;
int err;
uLong total = 0;
unz_file_info file_info;
char filename_inzip[256];
err = unzGetGlobalInfo (uf,&gi);
for (i=0;i<gi.number_entry;i++)
{
err = unzGetCurrentFileInfo(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0);
if (err!=UNZ_OK)
return err;
total += file_info.uncompressed_size;
if ((i+1)<gi.number_entry)
{
err = unzGoToNextFile(uf);
if (err!=UNZ_OK)
return err;
}
}
err = unzGoToFirstFile(uf);
if (err!=UNZ_OK)
return err;
return total;
}
int extractZip(unzFile uf,int opt_extract_without_path,int opt_overwrite,const char* password)
{
@ -234,6 +278,10 @@ int extractZip(unzFile uf,int opt_extract_without_path,int opt_overwrite,const c
unz_global_info gi;
int err;
total_size = zipSize(uf);
total_unzipped = 0;
ShowProgress("Unzipping...", total_unzipped, total_size);
err = unzGetGlobalInfo (uf,&gi);
//if (err!=UNZ_OK)
// printf("error %d with zipfile in unzGetGlobalInfo \n",err);

View File

@ -2,16 +2,8 @@
#ifndef _miniunz_H
#define _miniunz_H
#ifdef __cplusplus
extern "C" {
#endif
int extractZip(unzFile uf,int opt_extract_without_path,int opt_overwrite,const char* password);
int extractZipOnefile(unzFile uf,const char* filename,int opt_extract_without_path,int opt_overwrite,const char* password);
int makedir(char *newdir);
#ifdef __cplusplus
}
#endif
#endif