From 61f9a207c26e6f7509bb7d5e07f67d88c768321f Mon Sep 17 00:00:00 2001 From: dborth Date: Sat, 3 Oct 2009 19:46:57 +0000 Subject: [PATCH] more small bugfixes --- source/ngc/filebrowser.h | 1 + source/ngc/fileop.cpp | 2 +- source/ngc/gcunzip.cpp | 63 ++++++++++++++++++---------------------- source/ngc/gcunzip.h | 4 +-- 4 files changed, 33 insertions(+), 37 deletions(-) diff --git a/source/ngc/filebrowser.h b/source/ngc/filebrowser.h index 4aae496..0635ab2 100644 --- a/source/ngc/filebrowser.h +++ b/source/ngc/filebrowser.h @@ -35,6 +35,7 @@ typedef struct int isdir; // 0 - file, 1 - directory char filename[MAXJOLIET + 1]; // full filename char displayname[MAXJOLIET + 1]; // name for browser display + int filenum; // file # (for 7z support) int icon; // icon to display } BROWSERENTRY; diff --git a/source/ngc/fileop.cpp b/source/ngc/fileop.cpp index 86b32b8..9dc789b 100644 --- a/source/ngc/fileop.cpp +++ b/source/ngc/fileop.cpp @@ -665,7 +665,7 @@ LoadSzFile(char * filepath, unsigned char * rbuffer) file = fopen (filepath, "rb"); if (file > 0) { - size = SzExtractFile(atoi(browserList[browser.selIndex].filename), rbuffer); + size = SzExtractFile(browserList[browser.selIndex].filenum, rbuffer); fclose (file); } else diff --git a/source/ngc/gcunzip.cpp b/source/ngc/gcunzip.cpp index 8c7acc7..6874f53 100644 --- a/source/ngc/gcunzip.cpp +++ b/source/ngc/gcunzip.cpp @@ -23,10 +23,8 @@ extern "C" { } #include "snes9xGX.h" -#include "networkop.h" #include "fileop.h" #include "filebrowser.h" -#include "video.h" #include "menu.h" #include "gcunzip.h" @@ -101,19 +99,19 @@ IsZipFile (char *buffer) * UnZipBuffer ******************************************************************************/ -int +size_t UnZipBuffer (unsigned char *outbuffer) { PKZIPHEADER pkzip; - int zipoffset = 0; - int zipchunk = 0; + size_t zipoffset = 0; + size_t zipchunk = 0; char out[ZIPCHUNK]; z_stream zs; int res; - int bufferoffset = 0; - int have = 0; + size_t bufferoffset = 0; + size_t have = 0; char readbuffer[ZIPCHUNK]; - int sizeread = 0; + size_t sizeread = 0; // Read Zip Header fseek(file, 0, SEEK_SET); @@ -351,6 +349,18 @@ static SZ_RESULT SzFileSeekImp(void *object, CFileSize pos) return SZ_OK; } +/**************************************************************************** +* SzClose +* +* Closes a 7z file +***************************************************************************/ + +void SzClose() +{ + if(SzDb.Database.NumFiles > 0) + SzArDbExFree(&SzDb, SzAllocImp.Free); +} + /**************************************************************************** * SzParse * @@ -420,9 +430,12 @@ int SzParse(char * filepath) ResetBrowser(); // add '..' folder in case the user wants exit the 7z + AddBrowserEntry(); + sprintf(browserList[0].displayname, "Up One Level"); browserList[0].isdir = 1; browserList[0].length = filelen; + browserList[0].icon = ICON_FOLDER; // get contents and parse them into file list structure unsigned int SzI, SzJ; @@ -435,34 +448,28 @@ int SzParse(char * filepath) if (SzF->IsDirectory) continue; - BROWSERENTRY * newBrowserList = (BROWSERENTRY *)realloc(browserList, (SzJ+1) * sizeof(BROWSERENTRY)); - - if(!newBrowserList) // failed to allocate required memory + if(!AddBrowserEntry()) { ResetBrowser(); ErrorPrompt("Out of memory: too many files!"); - nbfiles = 0; + SzClose(); + SzJ = 0; break; } - else - { - browserList = newBrowserList; - } - memset(&(browserList[SzJ]), 0, sizeof(BROWSERENTRY)); // clear the new entry // parse information about this file to the file list structure - sprintf(browserList[SzJ].filename, "%d", SzI); // the extraction function identifies the file with this number - StripExt(browserList[SzJ].displayname, SzF->Name); + strncpy(browserList[SzJ].filename, SzF->Name, MAXJOLIET); + StripExt(browserList[SzJ].displayname, browserList[SzJ].filename); browserList[SzJ].length = SzF->Size; // filesize browserList[SzJ].isdir = 0; // only files will be displayed (-> no flags) + browserList[SzJ].filenum = SzI; // the extraction function identifies the file with this number SzJ++; } - nbfiles = SzJ; } else { - SzArDbExFree(&SzDb, SzAllocImp.Free); + SzClose(); } } @@ -473,18 +480,6 @@ int SzParse(char * filepath) return nbfiles; } -/**************************************************************************** -* SzClose -* -* Closes a 7z file -***************************************************************************/ - -void SzClose() -{ - if(SzDb.Database.NumFiles > 0) - SzArDbExFree(&SzDb, SzAllocImp.Free); -} - /**************************************************************************** * SzExtractFile * @@ -492,7 +487,7 @@ void SzClose() * Must parse the 7z BEFORE running this function ***************************************************************************/ -int SzExtractFile(int i, unsigned char *buffer) +size_t SzExtractFile(int i, unsigned char *buffer) { // prepare some variables SzBlockIndex = 0xFFFFFFFF; diff --git a/source/ngc/gcunzip.h b/source/ngc/gcunzip.h index 7124e69..f5a1cde 100644 --- a/source/ngc/gcunzip.h +++ b/source/ngc/gcunzip.h @@ -14,9 +14,9 @@ int IsZipFile (char *buffer); char * GetFirstZipFilename(); -int UnZipBuffer (unsigned char *outbuffer); +size_t UnZipBuffer (unsigned char *outbuffer); int SzParse(char * filepath); -int SzExtractFile(int i, unsigned char *buffer); +size_t SzExtractFile(int i, unsigned char *buffer); void SzClose(); #endif