From a2d694fabebc4543fe40e128fcb2a9f68ecd4ab0 Mon Sep 17 00:00:00 2001 From: dborth Date: Tue, 14 Oct 2008 09:21:58 +0000 Subject: [PATCH] 7z support fully functional --- source/ngc/dvd.c | 12 ++++++---- source/ngc/dvd.h | 6 +++++ source/ngc/fileop.c | 55 +++++++++++++++++++++----------------------- source/ngc/fileop.h | 3 ++- source/ngc/filesel.c | 7 ------ source/ngc/gcunzip.c | 36 ++++++----------------------- source/ngc/gcunzip.h | 4 +--- source/ngc/smbop.c | 10 ++++---- source/ngc/smbop.h | 4 +++- source/sz/7zDecode.h | 2 +- 10 files changed, 60 insertions(+), 79 deletions(-) diff --git a/source/ngc/dvd.c b/source/ngc/dvd.c index fb4946f..c4ad891 100644 --- a/source/ngc/dvd.c +++ b/source/ngc/dvd.c @@ -21,10 +21,11 @@ #include "menudraw.h" #include "gcunzip.h" +#include "fceuconfig.h" -u64 dvddir = 0; -u64 dvdrootdir = 0; -int dvddirlength = 0; +u64 dvddir = 0; // offset of currently selected file or folder +int dvddirlength = 0; // length of currently selected file or folder +u64 dvdrootdir = 0; // offset of DVD root bool isWii = false; #ifdef HW_DOL @@ -563,6 +564,9 @@ LoadDVDFile (unsigned char *buffer, int length) u64 discoffset; char readbuffer[2048]; + dvddir = filelist[selection].offset; + dvddirlength = filelist[selection].length; + // How many 2k blocks to read blocks = dvddirlength / 2048; offset = 0; @@ -579,7 +583,7 @@ LoadDVDFile (unsigned char *buffer, int length) if (IsZipFile (readbuffer)) { - return UnZipDVDFile (buffer, discoffset); // unzip from dvd + return UnZipBuffer (buffer, METHOD_DVD); // unzip from dvd } else { diff --git a/source/ngc/dvd.h b/source/ngc/dvd.h index 2927778..2eb6bb4 100644 --- a/source/ngc/dvd.h +++ b/source/ngc/dvd.h @@ -19,5 +19,11 @@ bool TestDVD(); int dvd_read (void *dst, unsigned int len, u64 offset); int dvd_safe_read (void *dst, unsigned int len, u64 offset); bool SwitchDVDFolder(char dir[]); +#ifdef HW_DOL +void dvd_motor_off (); +#endif + +extern u64 dvddir; +extern int dvddirlength; #endif diff --git a/source/ngc/fileop.c b/source/ngc/fileop.c index fb376a1..42ce9ba 100644 --- a/source/ngc/fileop.c +++ b/source/ngc/fileop.c @@ -23,7 +23,8 @@ #include "menudraw.h" #include "filesel.h" -FILE * filehandle; +// FAT file pointer - the only one we should ever use! +FILE * fatfile; /**************************************************************************** * fat_is_mounted @@ -171,7 +172,6 @@ LoadFATFile (char * rbuffer, int length) { char zipbuffer[2048]; char filepath[MAXPATHLEN]; - FILE *handle; u32 size; if (!MakeROMPath(filepath, METHOD_SD)) @@ -180,33 +180,33 @@ LoadFATFile (char * rbuffer, int length) return -1; } - handle = fopen (filepath, "rb"); - if (handle > 0) + fatfile = fopen (filepath, "rb"); + if (fatfile > 0) { if(length > 0) // do a partial read (eg: to check file header) { - fread (rbuffer, 1, length, handle); + fread (rbuffer, 1, length, fatfile); size = length; } else // load whole file { - fread (zipbuffer, 1, 2048, handle); + fread (zipbuffer, 1, 2048, fatfile); if (IsZipFile (zipbuffer)) { - size = UnZipFATFile ((unsigned char *)rbuffer, handle); // unzip from FAT + size = UnZipBuffer ((unsigned char *)rbuffer, METHOD_SD); // unzip from FAT } else { // Just load the file up - fseek(handle, 0, SEEK_END); - size = ftell(handle); // get filesize - fseek(handle, 2048, SEEK_SET); // seek back to point where we left off + fseek(fatfile, 0, SEEK_END); + size = ftell(fatfile); // get filesize + fseek(fatfile, 2048, SEEK_SET); // seek back to point where we left off memcpy (rbuffer, zipbuffer, 2048); // copy what we already read - fread (rbuffer + 2048, 1, size - 2048, handle); + fread (rbuffer + 2048, 1, size - 2048, fatfile); } } - fclose (handle); + fclose (fatfile); return size; } else @@ -225,11 +225,11 @@ int LoadFATSzFile(char * filepath, unsigned char * rbuffer) { u32 size; - FILE *handle = fopen (filepath, "rb"); - if (handle > 0) + fatfile = fopen (filepath, "rb"); + if (fatfile > 0) { size = SzExtractFile(filelist[selection].offset, rbuffer); - fclose (handle); + fclose (fatfile); return size; } else @@ -253,12 +253,11 @@ LoadSaveBufferFromFAT (char *filepath, bool silent) int LoadBufferFromFAT (char * sbuffer, char *filepath, bool silent) { - FILE *handle; int size = 0; - handle = fopen (filepath, "rb"); + fatfile = fopen (filepath, "rb"); - if (handle <= 0) + if (fatfile <= 0) { if ( !silent ) { @@ -270,11 +269,11 @@ LoadBufferFromFAT (char * sbuffer, char *filepath, bool silent) } // Just load the file up - fseek(handle, 0, SEEK_END); // go to end of file - size = ftell(handle); // get filesize - fseek(handle, 0, SEEK_SET); // go to start of file - fread (sbuffer, 1, size, handle); - fclose (handle); + fseek(fatfile, 0, SEEK_END); // go to end of file + size = ftell(fatfile); // get filesize + fseek(fatfile, 0, SEEK_SET); // go to start of file + fread (sbuffer, 1, size, fatfile); + fclose (fatfile); return size; } @@ -285,13 +284,11 @@ LoadBufferFromFAT (char * sbuffer, char *filepath, bool silent) int SaveBufferToFAT (char *filepath, int datasize, bool silent) { - FILE *handle; - if (datasize) { - handle = fopen (filepath, "wb"); + fatfile = fopen (filepath, "wb"); - if (handle <= 0) + if (fatfile <= 0) { char msg[100]; sprintf(msg, "Couldn't save %s", filepath); @@ -299,8 +296,8 @@ SaveBufferToFAT (char *filepath, int datasize, bool silent) return 0; } - fwrite (savebuffer, 1, datasize, handle); - fclose (handle); + fwrite (savebuffer, 1, datasize, fatfile); + fclose (fatfile); } return datasize; } diff --git a/source/ngc/fileop.h b/source/ngc/fileop.h index b4dce38..754fa58 100644 --- a/source/ngc/fileop.h +++ b/source/ngc/fileop.h @@ -24,12 +24,13 @@ bool ChangeFATInterface(int method, bool silent); int ParseFATdirectory(int method); -int LoadFATSzFile(char * filepath, unsigned char * rbuffer); int LoadFATFile (char * fbuffer, int length); +int LoadFATSzFile(char * filepath, unsigned char * rbuffer); int SaveBufferToFAT (char *filepath, int datasize, bool silent); int LoadSaveBufferFromFAT (char *filepath, bool silent); int LoadBufferFromFAT (char * buffer, char *filepath, bool silent); extern char currFATdir[MAXPATHLEN]; +extern FILE * fatfile; #endif diff --git a/source/ngc/filesel.c b/source/ngc/filesel.c index d77d021..a8cfd85 100644 --- a/source/ngc/filesel.c +++ b/source/ngc/filesel.c @@ -40,9 +40,6 @@ int nesGameType; int maxfiles; extern int screenheight; -extern u64 dvddir; -extern int dvddirlength; - // Global file entry table FILEENTRIES filelist[MAXFILES]; bool inSz = false; @@ -457,11 +454,7 @@ int FileSelector (int method) if(inSz) size = SzExtractFile(filelist[selection].offset, nesrom); else - { - dvddir = filelist[selection].offset; - dvddirlength = filelist[selection].length; size = LoadDVDFile(nesrom, 0); - } break; case METHOD_SMB: diff --git a/source/ngc/gcunzip.c b/source/ngc/gcunzip.c index 03e97eb..09ffbee 100644 --- a/source/ngc/gcunzip.c +++ b/source/ngc/gcunzip.c @@ -26,10 +26,6 @@ #include "menudraw.h" #include "gcunzip.h" -FILE* fatfile; // FAT -u64 discoffset; // DVD -SMBFILE smbfile; // SMB - /* * PKWare Zip Header - adopted into zip standard */ @@ -101,6 +97,7 @@ UnZipBuffer (unsigned char *outbuffer, int method) int have = 0; char readbuffer[ZIPCHUNK]; char msg[128]; + u64 discoffset = 0; // Read Zip Header switch (method) @@ -112,6 +109,7 @@ UnZipBuffer (unsigned char *outbuffer, int method) break; case METHOD_DVD: + discoffset = dvddir; dvd_read (readbuffer, ZIPCHUNK, discoffset); break; @@ -213,27 +211,6 @@ UnZipBuffer (unsigned char *outbuffer, int method) return 0; } -// Reading from FAT -int -UnZipFATFile (unsigned char *outbuffer, FILE* infile) -{ - fatfile = infile; - return UnZipBuffer(outbuffer, METHOD_SD); -} -// Reading from DVD -int -UnZipDVDFile (unsigned char *outbuffer, u64 inoffset) -{ - discoffset = inoffset; - return UnZipBuffer(outbuffer, METHOD_DVD); -} -// Reading from SMB -int -UnZipSMBFile (unsigned char *outbuffer, SMBFILE infile) -{ - smbfile = infile; - return UnZipBuffer(outbuffer, METHOD_SMB); -} /**************************************************************************** * GetFirstZipFilename @@ -293,7 +270,8 @@ char szerrormsg[][30] = { "7z: CRC Error", "7z: Not implemented", "7z: Fail", - "7z: Archive error" + "7z: Archive error", + "7z: Dictionary too large", }; SZ_RESULT SzRes; @@ -448,7 +426,7 @@ int SzParse(char * filepath, int method) if (SzRes != SZ_OK) { - WaitPrompt(szerrormsg[(SzRes - 1)]); + SzDisplayError(SzRes); // free memory used by the 7z SDK SzClose(); } @@ -567,11 +545,11 @@ int SzExtractFile(int i, unsigned char *buffer) if(SzRes != SZ_OK) { // display error message - WaitPrompt(szerrormsg[(SzRes - 1)]); + SzDisplayError(SzRes); return 0; } else { - return SzOutSizeProcessed; + return SzOutSizeProcessed; } } diff --git a/source/ngc/gcunzip.h b/source/ngc/gcunzip.h index 932f084..89b8f5f 100644 --- a/source/ngc/gcunzip.h +++ b/source/ngc/gcunzip.h @@ -16,9 +16,7 @@ extern int IsZipFile (char *buffer); char * GetFirstZipFilename(int method); -int UnZipFATFile (unsigned char *outbuffer, FILE* infile); // Reading from FAT -int UnZipDVDFile (unsigned char *outbuffer, u64 inoffset); // Reading from DVD -int UnZipSMBFile (unsigned char *outbuffer, SMBFILE infile); // Reading from SMB +int UnZipBuffer (unsigned char *outbuffer, int method); int SzParse(char * filepath, int method); int SzExtractFile(int i, unsigned char *buffer); void SzClose(); diff --git a/source/ngc/smbop.c b/source/ngc/smbop.c index 258e4ed..68dd79f 100644 --- a/source/ngc/smbop.c +++ b/source/ngc/smbop.c @@ -31,7 +31,10 @@ bool networkShareInit = false; unsigned int SMBTimer = 0; #define SMBTIMEOUT ( 3600 ) // Some implementations timeout in 10 minutes +// SMB connection/file handles - the only ones we should ever use! SMBCONN smbconn; +SMBFILE smbfile; + #define ZIPCHUNK 16384 /**************************************************************************** @@ -254,7 +257,7 @@ LoadSMBSzFile(char * filepath, unsigned char * rbuffer) if(!ConnectShare (NOTSILENT)) return 0; - SMBFILE smbfile = OpenSMBFile(filepath); + smbfile = OpenSMBFile(filepath); if (smbfile) { @@ -278,7 +281,6 @@ SaveBufferToSMB (char *filepath, int datasize, bool silent) if(!ConnectShare (NOTSILENT)) return 0; - SMBFILE smbfile; int dsize = datasize; int wrote = 0; int boffset = 0; @@ -331,7 +333,7 @@ LoadBufferFromSMB (char * sbuffer, char *filepath, int length, bool silent) if(!ConnectShare (NOTSILENT)) return 0; - SMBFILE smbfile = OpenSMBFile(filepath); + smbfile = OpenSMBFile(filepath); int ret; int boffset = 0; @@ -356,7 +358,7 @@ LoadBufferFromSMB (char * sbuffer, char *filepath, int length, bool silent) if (IsZipFile (sbuffer)) { - boffset = UnZipSMBFile ((unsigned char *)sbuffer, smbfile); // unzip from SMB + boffset = UnZipBuffer ((unsigned char *)sbuffer, METHOD_SMB); // unzip from SMB } else { diff --git a/source/ngc/smbop.h b/source/ngc/smbop.h index 2a3822d..e356707 100644 --- a/source/ngc/smbop.h +++ b/source/ngc/smbop.h @@ -19,11 +19,13 @@ bool ConnectShare (bool silent); char * SMBPath(char * path); int UpdateSMBdirname(); int ParseSMBdirectory (); -SMBFILE OpenSMBFile(); +SMBFILE OpenSMBFile(char * filepath); int LoadSMBFile (char * fbuffer, int length); int LoadSMBSzFile(char * filepath, unsigned char * rbuffer); int LoadSaveBufferFromSMB (char *filepath, bool silent); int LoadBufferFromSMB (char * sbuffer, char *filepath, int length, bool silent); int SaveBufferToSMB (char *filepath, int datasize, bool silent); +extern SMBFILE smbfile; + #endif diff --git a/source/sz/7zDecode.h b/source/sz/7zDecode.h index 4f4d35d..9f15ba1 100644 --- a/source/sz/7zDecode.h +++ b/source/sz/7zDecode.h @@ -24,7 +24,7 @@ SZ_RESULT SzDecode(const CFileSize *packSizes, const CFolder *folder, #ifdef _LZMA_OUT_READ #ifndef _LZMA_TEMP_BUFFER_SIZE -#define _LZMA_TEMP_BUFFER_SIZE (1024) // size of the temporary buffer in bytes +#define _LZMA_TEMP_BUFFER_SIZE (2048) // size of the temporary buffer in bytes #endif SZ_RESULT SzDecode2(const CFileSize *packSizes, const CFolder *folder,