7z support fully functional

This commit is contained in:
dborth 2008-10-14 09:21:58 +00:00
parent 79bcbc1b72
commit a2d694fabe
10 changed files with 60 additions and 79 deletions

View File

@ -21,10 +21,11 @@
#include "menudraw.h" #include "menudraw.h"
#include "gcunzip.h" #include "gcunzip.h"
#include "fceuconfig.h"
u64 dvddir = 0; u64 dvddir = 0; // offset of currently selected file or folder
u64 dvdrootdir = 0; int dvddirlength = 0; // length of currently selected file or folder
int dvddirlength = 0; u64 dvdrootdir = 0; // offset of DVD root
bool isWii = false; bool isWii = false;
#ifdef HW_DOL #ifdef HW_DOL
@ -563,6 +564,9 @@ LoadDVDFile (unsigned char *buffer, int length)
u64 discoffset; u64 discoffset;
char readbuffer[2048]; char readbuffer[2048];
dvddir = filelist[selection].offset;
dvddirlength = filelist[selection].length;
// How many 2k blocks to read // How many 2k blocks to read
blocks = dvddirlength / 2048; blocks = dvddirlength / 2048;
offset = 0; offset = 0;
@ -579,7 +583,7 @@ LoadDVDFile (unsigned char *buffer, int length)
if (IsZipFile (readbuffer)) if (IsZipFile (readbuffer))
{ {
return UnZipDVDFile (buffer, discoffset); // unzip from dvd return UnZipBuffer (buffer, METHOD_DVD); // unzip from dvd
} }
else else
{ {

View File

@ -19,5 +19,11 @@ bool TestDVD();
int dvd_read (void *dst, unsigned int len, u64 offset); int dvd_read (void *dst, unsigned int len, u64 offset);
int dvd_safe_read (void *dst, unsigned int len, u64 offset); int dvd_safe_read (void *dst, unsigned int len, u64 offset);
bool SwitchDVDFolder(char dir[]); bool SwitchDVDFolder(char dir[]);
#ifdef HW_DOL
void dvd_motor_off ();
#endif
extern u64 dvddir;
extern int dvddirlength;
#endif #endif

View File

@ -23,7 +23,8 @@
#include "menudraw.h" #include "menudraw.h"
#include "filesel.h" #include "filesel.h"
FILE * filehandle; // FAT file pointer - the only one we should ever use!
FILE * fatfile;
/**************************************************************************** /****************************************************************************
* fat_is_mounted * fat_is_mounted
@ -171,7 +172,6 @@ LoadFATFile (char * rbuffer, int length)
{ {
char zipbuffer[2048]; char zipbuffer[2048];
char filepath[MAXPATHLEN]; char filepath[MAXPATHLEN];
FILE *handle;
u32 size; u32 size;
if (!MakeROMPath(filepath, METHOD_SD)) if (!MakeROMPath(filepath, METHOD_SD))
@ -180,33 +180,33 @@ LoadFATFile (char * rbuffer, int length)
return -1; return -1;
} }
handle = fopen (filepath, "rb"); fatfile = fopen (filepath, "rb");
if (handle > 0) if (fatfile > 0)
{ {
if(length > 0) // do a partial read (eg: to check file header) if(length > 0) // do a partial read (eg: to check file header)
{ {
fread (rbuffer, 1, length, handle); fread (rbuffer, 1, length, fatfile);
size = length; size = length;
} }
else // load whole file else // load whole file
{ {
fread (zipbuffer, 1, 2048, handle); fread (zipbuffer, 1, 2048, fatfile);
if (IsZipFile (zipbuffer)) if (IsZipFile (zipbuffer))
{ {
size = UnZipFATFile ((unsigned char *)rbuffer, handle); // unzip from FAT size = UnZipBuffer ((unsigned char *)rbuffer, METHOD_SD); // unzip from FAT
} }
else else
{ {
// Just load the file up // Just load the file up
fseek(handle, 0, SEEK_END); fseek(fatfile, 0, SEEK_END);
size = ftell(handle); // get filesize size = ftell(fatfile); // get filesize
fseek(handle, 2048, SEEK_SET); // seek back to point where we left off fseek(fatfile, 2048, SEEK_SET); // seek back to point where we left off
memcpy (rbuffer, zipbuffer, 2048); // copy what we already read 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; return size;
} }
else else
@ -225,11 +225,11 @@ int
LoadFATSzFile(char * filepath, unsigned char * rbuffer) LoadFATSzFile(char * filepath, unsigned char * rbuffer)
{ {
u32 size; u32 size;
FILE *handle = fopen (filepath, "rb"); fatfile = fopen (filepath, "rb");
if (handle > 0) if (fatfile > 0)
{ {
size = SzExtractFile(filelist[selection].offset, rbuffer); size = SzExtractFile(filelist[selection].offset, rbuffer);
fclose (handle); fclose (fatfile);
return size; return size;
} }
else else
@ -253,12 +253,11 @@ LoadSaveBufferFromFAT (char *filepath, bool silent)
int int
LoadBufferFromFAT (char * sbuffer, char *filepath, bool silent) LoadBufferFromFAT (char * sbuffer, char *filepath, bool silent)
{ {
FILE *handle;
int size = 0; int size = 0;
handle = fopen (filepath, "rb"); fatfile = fopen (filepath, "rb");
if (handle <= 0) if (fatfile <= 0)
{ {
if ( !silent ) if ( !silent )
{ {
@ -270,11 +269,11 @@ LoadBufferFromFAT (char * sbuffer, char *filepath, bool silent)
} }
// Just load the file up // Just load the file up
fseek(handle, 0, SEEK_END); // go to end of file fseek(fatfile, 0, SEEK_END); // go to end of file
size = ftell(handle); // get filesize size = ftell(fatfile); // get filesize
fseek(handle, 0, SEEK_SET); // go to start of file fseek(fatfile, 0, SEEK_SET); // go to start of file
fread (sbuffer, 1, size, handle); fread (sbuffer, 1, size, fatfile);
fclose (handle); fclose (fatfile);
return size; return size;
} }
@ -285,13 +284,11 @@ LoadBufferFromFAT (char * sbuffer, char *filepath, bool silent)
int int
SaveBufferToFAT (char *filepath, int datasize, bool silent) SaveBufferToFAT (char *filepath, int datasize, bool silent)
{ {
FILE *handle;
if (datasize) if (datasize)
{ {
handle = fopen (filepath, "wb"); fatfile = fopen (filepath, "wb");
if (handle <= 0) if (fatfile <= 0)
{ {
char msg[100]; char msg[100];
sprintf(msg, "Couldn't save %s", filepath); sprintf(msg, "Couldn't save %s", filepath);
@ -299,8 +296,8 @@ SaveBufferToFAT (char *filepath, int datasize, bool silent)
return 0; return 0;
} }
fwrite (savebuffer, 1, datasize, handle); fwrite (savebuffer, 1, datasize, fatfile);
fclose (handle); fclose (fatfile);
} }
return datasize; return datasize;
} }

View File

@ -24,12 +24,13 @@
bool ChangeFATInterface(int method, bool silent); bool ChangeFATInterface(int method, bool silent);
int ParseFATdirectory(int method); int ParseFATdirectory(int method);
int LoadFATSzFile(char * filepath, unsigned char * rbuffer);
int LoadFATFile (char * fbuffer, int length); int LoadFATFile (char * fbuffer, int length);
int LoadFATSzFile(char * filepath, unsigned char * rbuffer);
int SaveBufferToFAT (char *filepath, int datasize, bool silent); int SaveBufferToFAT (char *filepath, int datasize, bool silent);
int LoadSaveBufferFromFAT (char *filepath, bool silent); int LoadSaveBufferFromFAT (char *filepath, bool silent);
int LoadBufferFromFAT (char * buffer, char *filepath, bool silent); int LoadBufferFromFAT (char * buffer, char *filepath, bool silent);
extern char currFATdir[MAXPATHLEN]; extern char currFATdir[MAXPATHLEN];
extern FILE * fatfile;
#endif #endif

View File

@ -40,9 +40,6 @@ int nesGameType;
int maxfiles; int maxfiles;
extern int screenheight; extern int screenheight;
extern u64 dvddir;
extern int dvddirlength;
// Global file entry table // Global file entry table
FILEENTRIES filelist[MAXFILES]; FILEENTRIES filelist[MAXFILES];
bool inSz = false; bool inSz = false;
@ -457,11 +454,7 @@ int FileSelector (int method)
if(inSz) if(inSz)
size = SzExtractFile(filelist[selection].offset, nesrom); size = SzExtractFile(filelist[selection].offset, nesrom);
else else
{
dvddir = filelist[selection].offset;
dvddirlength = filelist[selection].length;
size = LoadDVDFile(nesrom, 0); size = LoadDVDFile(nesrom, 0);
}
break; break;
case METHOD_SMB: case METHOD_SMB:

View File

@ -26,10 +26,6 @@
#include "menudraw.h" #include "menudraw.h"
#include "gcunzip.h" #include "gcunzip.h"
FILE* fatfile; // FAT
u64 discoffset; // DVD
SMBFILE smbfile; // SMB
/* /*
* PKWare Zip Header - adopted into zip standard * PKWare Zip Header - adopted into zip standard
*/ */
@ -101,6 +97,7 @@ UnZipBuffer (unsigned char *outbuffer, int method)
int have = 0; int have = 0;
char readbuffer[ZIPCHUNK]; char readbuffer[ZIPCHUNK];
char msg[128]; char msg[128];
u64 discoffset = 0;
// Read Zip Header // Read Zip Header
switch (method) switch (method)
@ -112,6 +109,7 @@ UnZipBuffer (unsigned char *outbuffer, int method)
break; break;
case METHOD_DVD: case METHOD_DVD:
discoffset = dvddir;
dvd_read (readbuffer, ZIPCHUNK, discoffset); dvd_read (readbuffer, ZIPCHUNK, discoffset);
break; break;
@ -213,27 +211,6 @@ UnZipBuffer (unsigned char *outbuffer, int method)
return 0; 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 * GetFirstZipFilename
@ -293,7 +270,8 @@ char szerrormsg[][30] = {
"7z: CRC Error", "7z: CRC Error",
"7z: Not implemented", "7z: Not implemented",
"7z: Fail", "7z: Fail",
"7z: Archive error" "7z: Archive error",
"7z: Dictionary too large",
}; };
SZ_RESULT SzRes; SZ_RESULT SzRes;
@ -448,7 +426,7 @@ int SzParse(char * filepath, int method)
if (SzRes != SZ_OK) if (SzRes != SZ_OK)
{ {
WaitPrompt(szerrormsg[(SzRes - 1)]); SzDisplayError(SzRes);
// free memory used by the 7z SDK // free memory used by the 7z SDK
SzClose(); SzClose();
} }
@ -567,11 +545,11 @@ int SzExtractFile(int i, unsigned char *buffer)
if(SzRes != SZ_OK) if(SzRes != SZ_OK)
{ {
// display error message // display error message
WaitPrompt(szerrormsg[(SzRes - 1)]); SzDisplayError(SzRes);
return 0; return 0;
} }
else else
{ {
return SzOutSizeProcessed; return SzOutSizeProcessed;
} }
} }

View File

@ -16,9 +16,7 @@
extern int IsZipFile (char *buffer); extern int IsZipFile (char *buffer);
char * GetFirstZipFilename(int method); char * GetFirstZipFilename(int method);
int UnZipFATFile (unsigned char *outbuffer, FILE* infile); // Reading from FAT int UnZipBuffer (unsigned char *outbuffer, int method);
int UnZipDVDFile (unsigned char *outbuffer, u64 inoffset); // Reading from DVD
int UnZipSMBFile (unsigned char *outbuffer, SMBFILE infile); // Reading from SMB
int SzParse(char * filepath, int method); int SzParse(char * filepath, int method);
int SzExtractFile(int i, unsigned char *buffer); int SzExtractFile(int i, unsigned char *buffer);
void SzClose(); void SzClose();

View File

@ -31,7 +31,10 @@ bool networkShareInit = false;
unsigned int SMBTimer = 0; unsigned int SMBTimer = 0;
#define SMBTIMEOUT ( 3600 ) // Some implementations timeout in 10 minutes #define SMBTIMEOUT ( 3600 ) // Some implementations timeout in 10 minutes
// SMB connection/file handles - the only ones we should ever use!
SMBCONN smbconn; SMBCONN smbconn;
SMBFILE smbfile;
#define ZIPCHUNK 16384 #define ZIPCHUNK 16384
/**************************************************************************** /****************************************************************************
@ -254,7 +257,7 @@ LoadSMBSzFile(char * filepath, unsigned char * rbuffer)
if(!ConnectShare (NOTSILENT)) if(!ConnectShare (NOTSILENT))
return 0; return 0;
SMBFILE smbfile = OpenSMBFile(filepath); smbfile = OpenSMBFile(filepath);
if (smbfile) if (smbfile)
{ {
@ -278,7 +281,6 @@ SaveBufferToSMB (char *filepath, int datasize, bool silent)
if(!ConnectShare (NOTSILENT)) if(!ConnectShare (NOTSILENT))
return 0; return 0;
SMBFILE smbfile;
int dsize = datasize; int dsize = datasize;
int wrote = 0; int wrote = 0;
int boffset = 0; int boffset = 0;
@ -331,7 +333,7 @@ LoadBufferFromSMB (char * sbuffer, char *filepath, int length, bool silent)
if(!ConnectShare (NOTSILENT)) if(!ConnectShare (NOTSILENT))
return 0; return 0;
SMBFILE smbfile = OpenSMBFile(filepath); smbfile = OpenSMBFile(filepath);
int ret; int ret;
int boffset = 0; int boffset = 0;
@ -356,7 +358,7 @@ LoadBufferFromSMB (char * sbuffer, char *filepath, int length, bool silent)
if (IsZipFile (sbuffer)) if (IsZipFile (sbuffer))
{ {
boffset = UnZipSMBFile ((unsigned char *)sbuffer, smbfile); // unzip from SMB boffset = UnZipBuffer ((unsigned char *)sbuffer, METHOD_SMB); // unzip from SMB
} }
else else
{ {

View File

@ -19,11 +19,13 @@ bool ConnectShare (bool silent);
char * SMBPath(char * path); char * SMBPath(char * path);
int UpdateSMBdirname(); int UpdateSMBdirname();
int ParseSMBdirectory (); int ParseSMBdirectory ();
SMBFILE OpenSMBFile(); SMBFILE OpenSMBFile(char * filepath);
int LoadSMBFile (char * fbuffer, int length); int LoadSMBFile (char * fbuffer, int length);
int LoadSMBSzFile(char * filepath, unsigned char * rbuffer); int LoadSMBSzFile(char * filepath, unsigned char * rbuffer);
int LoadSaveBufferFromSMB (char *filepath, bool silent); int LoadSaveBufferFromSMB (char *filepath, bool silent);
int LoadBufferFromSMB (char * sbuffer, char *filepath, int length, bool silent); int LoadBufferFromSMB (char * sbuffer, char *filepath, int length, bool silent);
int SaveBufferToSMB (char *filepath, int datasize, bool silent); int SaveBufferToSMB (char *filepath, int datasize, bool silent);
extern SMBFILE smbfile;
#endif #endif

View File

@ -24,7 +24,7 @@ SZ_RESULT SzDecode(const CFileSize *packSizes, const CFolder *folder,
#ifdef _LZMA_OUT_READ #ifdef _LZMA_OUT_READ
#ifndef _LZMA_TEMP_BUFFER_SIZE #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 #endif
SZ_RESULT SzDecode2(const CFileSize *packSizes, const CFolder *folder, SZ_RESULT SzDecode2(const CFileSize *packSizes, const CFolder *folder,