add unzip progress for auto-update

This commit is contained in:
dborth 2009-01-25 07:09:37 +00:00
parent 3f55b4fbc7
commit 7eea07a60c
4 changed files with 52 additions and 11 deletions

View File

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

View File

@ -126,7 +126,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