partial 7z fix (smaller files work now)

This commit is contained in:
dborth 2008-10-13 20:28:25 +00:00
parent a0ea70a18b
commit 844662ca7c

View File

@ -102,22 +102,22 @@ UnZipBuffer (unsigned char *outbuffer, int method)
char readbuffer[ZIPCHUNK]; char readbuffer[ZIPCHUNK];
char msg[128]; char msg[128];
/*** Read Zip Header ***/ // Read Zip Header
switch (method) switch (method)
{ {
case METHOD_SD: case METHOD_SD:
case METHOD_USB: case METHOD_USB:
fseek(fatfile, 0, SEEK_SET); fseek(fatfile, 0, SEEK_SET);
fread (readbuffer, 1, ZIPCHUNK, fatfile); fread (readbuffer, 1, ZIPCHUNK, fatfile);
break; break;
case METHOD_DVD: case METHOD_DVD:
dvd_read (readbuffer, ZIPCHUNK, discoffset); dvd_read (readbuffer, ZIPCHUNK, discoffset);
break; break;
case METHOD_SMB: case METHOD_SMB:
SMB_ReadFile(readbuffer, ZIPCHUNK, 0, smbfile); SMB_ReadFile(readbuffer, ZIPCHUNK, 0, smbfile);
break; break;
} }
/*** Copy PKZip header to local, used as info ***/ /*** Copy PKZip header to local, used as info ***/
@ -177,7 +177,7 @@ UnZipBuffer (unsigned char *outbuffer, int method)
} }
while (zs.avail_out == 0); while (zs.avail_out == 0);
/*** Readup the next 2k block ***/ // Readup the next 2k block
zipoffset = 0; zipoffset = 0;
zipchunk = ZIPCHUNK; zipchunk = ZIPCHUNK;
@ -185,18 +185,18 @@ UnZipBuffer (unsigned char *outbuffer, int method)
{ {
case METHOD_SD: case METHOD_SD:
case METHOD_USB: case METHOD_USB:
fread (readbuffer, 1, ZIPCHUNK, fatfile); fread (readbuffer, 1, ZIPCHUNK, fatfile);
break; break;
case METHOD_DVD: case METHOD_DVD:
readoffset += ZIPCHUNK; readoffset += ZIPCHUNK;
dvd_read (readbuffer, ZIPCHUNK, discoffset+readoffset); dvd_read (readbuffer, ZIPCHUNK, discoffset+readoffset);
break; break;
case METHOD_SMB: case METHOD_SMB:
readoffset += ZIPCHUNK; readoffset += ZIPCHUNK;
SMB_ReadFile(readbuffer, ZIPCHUNK, readoffset, smbfile); SMB_ReadFile(readbuffer, ZIPCHUNK, readoffset, smbfile);
break; break;
} }
} }
while (res != Z_STREAM_END); while (res != Z_STREAM_END);
@ -253,16 +253,16 @@ GetFirstZipFilename (int method)
{ {
case METHOD_SD: // SD Card case METHOD_SD: // SD Card
case METHOD_USB: // USB case METHOD_USB: // USB
LoadFATFile (tempbuffer, ZIPCHUNK); LoadFATFile (tempbuffer, ZIPCHUNK);
break; break;
case METHOD_DVD: // DVD case METHOD_DVD: // DVD
LoadDVDFile ((unsigned char *)tempbuffer, ZIPCHUNK); LoadDVDFile ((unsigned char *)tempbuffer, ZIPCHUNK);
break; break;
case METHOD_SMB: // From SMB case METHOD_SMB: // From SMB
LoadSMBFile (tempbuffer, ZIPCHUNK); LoadSMBFile (tempbuffer, ZIPCHUNK);
break; break;
} }
tempbuffer[28] = 0; // truncate - filename length is 2 bytes long (bytes 26-27) tempbuffer[28] = 0; // truncate - filename length is 2 bytes long (bytes 26-27)
@ -307,7 +307,9 @@ size_t SzBufferSize;
size_t SzOffset; size_t SzOffset;
size_t SzOutSizeProcessed; size_t SzOutSizeProcessed;
CFileItem *SzF; CFileItem *SzF;
char sz_buffer[2048]; char sz_buffer[2048];
int szMethod = 0;
/**************************************************************************** /****************************************************************************
* Is7ZipFile * Is7ZipFile
@ -337,54 +339,33 @@ void SzDisplayError(SZ_RESULT res)
WaitPrompt(szerrormsg[(res - 1)]); WaitPrompt(szerrormsg[(res - 1)]);
} }
// function used by the 7zip SDK to read data from FAT // function used by the 7zip SDK to read data from SD/USB/DVD/SMB
SZ_RESULT SzFatFileReadImp(void *object, void **buffer, size_t maxRequiredSize, size_t *processedSize) SZ_RESULT SzFileReadImp(void *object, void **buffer, size_t maxRequiredSize, size_t *processedSize)
{ {
// the void* object is a SzFileInStream // the void* object is a SzFileInStream
SzFileInStream *s = (SzFileInStream *)object; SzFileInStream *s = (SzFileInStream *)object;
// read data // calculate offset
fseek(fatfile, s->pos, SEEK_SET);
fread (sz_buffer, 1, maxRequiredSize, fatfile);
*buffer = sz_buffer;
*processedSize = maxRequiredSize;
s->pos += *processedSize;
return SZ_OK;
}
// function used by the 7zip SDK to read data from DVD
SZ_RESULT SzDvdFileReadImp(void *object, void **buffer, size_t maxRequiredSize, size_t *processedSize)
{
// the void* object is a SzFileInStream
SzFileInStream *s = (SzFileInStream *)object;
// calculate dvd sector offset
u64 offset = (u64)(s->offset + s->pos); u64 offset = (u64)(s->offset + s->pos);
if(maxRequiredSize > 2048) if(maxRequiredSize > 2048)
{ maxRequiredSize = 2048;
maxRequiredSize = 2048;
}
// read data // read data
dvd_safe_read(sz_buffer, maxRequiredSize, offset); switch(szMethod)
*buffer = sz_buffer; {
*processedSize = maxRequiredSize; case METHOD_SD:
s->pos += *processedSize; case METHOD_USB:
fseek(fatfile, offset, SEEK_SET);
return SZ_OK; fread (sz_buffer, 1, maxRequiredSize, fatfile);
} break;
case METHOD_DVD:
// function used by the 7zip SDK to read data from SMB dvd_safe_read(sz_buffer, maxRequiredSize, offset);
SZ_RESULT SzSMBFileReadImp(void *object, void **buffer, size_t maxRequiredSize, size_t *processedSize) break;
{ case METHOD_SMB:
// the void* object is a SzFileInStream SMB_ReadFile(sz_buffer, maxRequiredSize, offset, smbfile);
SzFileInStream *s = (SzFileInStream *)object; break;
}
// read data
SMB_ReadFile(sz_buffer, maxRequiredSize, s->pos, smbfile);
*buffer = sz_buffer; *buffer = sz_buffer;
*processedSize = maxRequiredSize; *processedSize = maxRequiredSize;
@ -428,23 +409,27 @@ int SzParse(char * filepath, int method)
SzArchiveStream.len = filelist[selection].length; SzArchiveStream.len = filelist[selection].length;
SzArchiveStream.pos = 0; SzArchiveStream.pos = 0;
// set handler functions for reading data from FAT/SMB/DVD // open file
switch (method) switch (method)
{ {
case METHOD_SD: case METHOD_SD:
case METHOD_USB: case METHOD_USB:
fatfile = fopen (filepath, "rb"); fatfile = fopen (filepath, "rb");
SzArchiveStream.InStream.Read = SzFatFileReadImp; if(!fatfile)
break; return 0;
case METHOD_DVD:
SzArchiveStream.InStream.Read = SzDvdFileReadImp;
break; break;
case METHOD_SMB: case METHOD_SMB:
smbfile = OpenSMBFile(filepath); smbfile = OpenSMBFile(filepath);
SzArchiveStream.InStream.Read = SzSMBFileReadImp; if(!smbfile)
return 0;
break; break;
} }
// set szMethod to current chosen load method
szMethod = method;
// set handler functions for reading data from FAT/SMB/DVD
SzArchiveStream.InStream.Read = SzFileReadImp;
SzArchiveStream.InStream.Seek = SzFileSeekImp; SzArchiveStream.InStream.Seek = SzFileSeekImp;
// set default 7Zip SDK handlers for allocation and freeing memory // set default 7Zip SDK handlers for allocation and freeing memory
@ -463,8 +448,9 @@ int SzParse(char * filepath, int method)
if (SzRes != SZ_OK) if (SzRes != SZ_OK)
{ {
WaitPrompt(szerrormsg[(SzRes - 1)]);
// free memory used by the 7z SDK // free memory used by the 7z SDK
SzArDbExFree(&SzDb, SzAllocImp.Free); SzClose();
} }
else // archive opened successfully else // archive opened successfully
{ {
@ -519,6 +505,7 @@ int SzParse(char * filepath, int method)
SzArDbExFree(&SzDb, SzAllocImp.Free); SzArDbExFree(&SzDb, SzAllocImp.Free);
} }
} }
// close file // close file
switch (method) switch (method)
{ {