From aa565cc205f60aaf86b42c76e7ea596ca0011244 Mon Sep 17 00:00:00 2001 From: dborth Date: Sun, 25 Jan 2009 07:09:11 +0000 Subject: [PATCH] add unzip progress for auto-update --- source/ngc/filesel.cpp | 2 +- source/ngc/gcunzip.cpp | 2 +- source/ngc/menudraw.h | 1 + source/ngc/networkop.cpp | 2 +- source/unzip/{miniunz.c => miniunz.cpp} | 52 ++++++++++++++++++++++++- source/unzip/miniunz.h | 8 ---- 6 files changed, 54 insertions(+), 13 deletions(-) rename source/unzip/{miniunz.c => miniunz.cpp} (82%) diff --git a/source/ngc/filesel.cpp b/source/ngc/filesel.cpp index 3aec8e6..769e1c6 100644 --- a/source/ngc/filesel.cpp +++ b/source/ngc/filesel.cpp @@ -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 { diff --git a/source/ngc/gcunzip.cpp b/source/ngc/gcunzip.cpp index ef1eb76..64b63fe 100644 --- a/source/ngc/gcunzip.cpp +++ b/source/ngc/gcunzip.cpp @@ -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 diff --git a/source/ngc/menudraw.h b/source/ngc/menudraw.h index c665c3b..9cb18be 100644 --- a/source/ngc/menudraw.h +++ b/source/ngc/menudraw.h @@ -12,6 +12,7 @@ #ifndef _MENUDRAW_H_ #define _MENUDRAW_H_ +#include #include "filesel.h" #define PAGESIZE 13 // max item listing on a screen diff --git a/source/ngc/networkop.cpp b/source/ngc/networkop.cpp index b0c1b6a..23efc7a 100644 --- a/source/ngc/networkop.cpp +++ b/source/ngc/networkop.cpp @@ -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 diff --git a/source/unzip/miniunz.c b/source/unzip/miniunz.cpp similarity index 82% rename from source/unzip/miniunz.c rename to source/unzip/miniunz.cpp index 5fe3819..45e967c 100644 --- a/source/unzip/miniunz.c +++ b/source/unzip/miniunz.cpp @@ -12,15 +12,20 @@ #include #include #include -# include -# include +#include +#include #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