This commit is contained in:
dborth 2009-12-01 08:35:26 +00:00
parent cd86156b34
commit fa3bc5f315

View File

@ -302,30 +302,28 @@ static void SzDisplayError(SZ_RESULT res)
// function used by the 7zip SDK to read data from SD/USB/DVD/SMB // function used by the 7zip SDK to read data from SD/USB/DVD/SMB
static SZ_RESULT SzFileReadImp(void *object, void **buffer, size_t maxRequiredSize, size_t *processedSize) static SZ_RESULT SzFileReadImp(void *object, void **buffer, size_t maxRequiredSize, size_t *processedSize)
{ {
u32 seekok = 0; size_t sizeread = 0;
u32 sizeread = 0;
if(maxRequiredSize == 0)
return SZ_OK;
// the void* object is a SzFileInStream // the void* object is a SzFileInStream
SzFileInStream *s = (SzFileInStream *) object; SzFileInStream *s = (SzFileInStream *) object;
// calculate offset
u64 offset = (u64) (s->offset + s->pos);
if (maxRequiredSize > 2048) if (maxRequiredSize > 2048)
maxRequiredSize = 2048; maxRequiredSize = 2048;
// read data // read data
seekok = fseek(file, offset, SEEK_SET);
sizeread = fread(sz_buffer, 1, maxRequiredSize, file); sizeread = fread(sz_buffer, 1, maxRequiredSize, file);
if(seekok != 0 || sizeread <= 0) if(sizeread <= 0)
return SZE_FAILREAD; return SZE_FAILREAD;
*buffer = sz_buffer; *buffer = sz_buffer;
*processedSize = maxRequiredSize; *processedSize = sizeread;
s->pos += *processedSize; s->pos += sizeread;
if(maxRequiredSize > 1024) // only show progress for large reads if(sizeread > 1024) // only show progress for large reads
// this isn't quite right, but oh well // this isn't quite right, but oh well
ShowProgress ("Loading...", s->pos, browserList[browser.selIndex].length); ShowProgress ("Loading...", s->pos, browserList[browser.selIndex].length);
@ -343,6 +341,9 @@ static SZ_RESULT SzFileSeekImp(void *object, CFileSize pos)
return SZE_FAIL; return SZE_FAIL;
// save new position and return // save new position and return
if(fseek(file, (long)pos, SEEK_SET) != 0)
return SZE_FAIL;
s->pos = pos; s->pos = pos;
return SZ_OK; return SZ_OK;
} }