This commit is contained in:
dborth 2008-10-14 23:35:19 +00:00
parent f5d6042073
commit d9f13b8203
2 changed files with 114 additions and 59 deletions

View File

@ -445,9 +445,12 @@ int FileSelector (int method)
WaitPrompt((char*) "Maximum filepath length reached!"); WaitPrompt((char*) "Maximum filepath length reached!");
return -1; return -1;
} }
maxfiles = SzParse(szpath, method); int szfiles = SzParse(szpath, method);
if(maxfiles) if(szfiles)
{
maxfiles = szfiles;
inSz = true; inSz = true;
}
} }
else else
{ {

View File

@ -244,66 +244,118 @@ SZ_RESULT SzDecode2(const CFileSize *packSizes, const CFolder *folder,
// allocate memory for the temporary buffer // allocate memory for the temporary buffer
Byte *tmpBuffer = (Byte *)allocMain->Alloc(_LZMA_TEMP_BUFFER_SIZE); Byte *tmpBuffer = (Byte *)allocMain->Alloc(_LZMA_TEMP_BUFFER_SIZE);
// decompress data in _LZMA_TEMP_BUFFER_SIZE byte steps and copy the wanted file to outBuffer // variables containing the number of the first and the last bytes of the buffer
size_t bytesLeft = *fileSize; // total bytes remaining to be read size_t bufferStart, bufferEnd;
size_t bytesToRead = 0; // bytes to read on this pass bufferStart = bufferEnd = 0;
size_t bytesRead = 0; // total bytes read
size_t offset = 0; // buffer offset
do
{
if(bytesLeft > _LZMA_TEMP_BUFFER_SIZE)
bytesToRead = _LZMA_TEMP_BUFFER_SIZE;
else
bytesToRead = bytesLeft;
bytesLeft -= bytesToRead; // integers contains the offset, the size and the already copied data which will be
// copied from the tmpBuffer to outBuffer
size_t copyOffset, copySize, copyDone;
copyOffset = copySize = copyDone = 0;
// decompress next bytes UInt32 i = 0;
result = LzmaDecode(&state, int bytesToCopy = 0;
#ifdef _LZMA_IN_CB
&lzmaCallback.InCallback,
#else
//inBuffer, (SizeT)inSize, &inProcessed, //TODO!
#endif
tmpBuffer, bytesToRead, &outSizeProcessedLoc
);
// check result // decompress data in _LZMA_TEMP_BUFFER_SIZE byte steps and copy the wanted file to outBuffer
if(result == LZMA_RESULT_DATA_ERROR) do
return SZE_DATA_ERROR; {
else if(result != LZMA_RESULT_OK) if((*fileSize - copyDone) >= _LZMA_TEMP_BUFFER_SIZE)
return SZE_FAIL; bytesToCopy = _LZMA_TEMP_BUFFER_SIZE;
else
bytesToCopy = (*fileSize - copyDone);
// normally this should never happen // decompress next bytes
if(outSizeProcessedLoc > _LZMA_TEMP_BUFFER_SIZE) result = LzmaDecode(&state,
{ #ifdef _LZMA_IN_CB
return SZE_FAIL; &lzmaCallback.InCallback,
} #else
//inBuffer, (SizeT)inSize, &inProcessed, //TODO!
#endif
tmpBuffer, bytesToCopy, &outSizeProcessedLoc
);
memcpy(outBuffer + offset, tmpBuffer, outSizeProcessedLoc); // check result
bytesRead += bytesToRead; if(result == LZMA_RESULT_DATA_ERROR)
offset += outSizeProcessedLoc; {
} return SZE_DATA_ERROR;
while(bytesLeft > 0); }
if(result != LZMA_RESULT_OK)
{
return SZE_FAIL;
}
/* result = LzmaDecode(&state, // normally this should never happen
#ifdef _LZMA_IN_CB if(outSizeProcessedLoc > _LZMA_TEMP_BUFFER_SIZE)
&lzmaCallback.InCallback, {
#else return SZE_FAIL;
inBuffer, (SizeT)inSize, &inProcessed, }
#endif
outBuffer, (SizeT)outSize, &outSizeProcessedLoc);*/ // update bufferStart and bufferEnd
//*outSizeProcessed = (size_t)outSizeProcessedLoc; bufferStart = _LZMA_TEMP_BUFFER_SIZE * i;
*outSizeProcessed = offset; bufferEnd = bufferStart + outSizeProcessedLoc;
allocMain->Free(tmpBuffer); // free the temporary buffer again i++;
allocMain->Free(state.Probs);
allocMain->Free(state.Dictionary); // calculate copy offset and size
/* if (result == LZMA_RESULT_DATA_ERROR) if(*fileOffset > bufferEnd)
return SZE_DATA_ERROR; {
if (result != LZMA_RESULT_OK) // we haven't reached the start of the file yet
return SZE_FAIL;*/ continue;
return SZ_OK; }
}
return SZE_NOTIMPL; // calculate offset
} if(*fileOffset < bufferStart)
#endif {
// the file has already started before this decompression step
copyOffset = 0;
}
else
{
// the file starts somewhere inside this buffer
copyDone = 0;
copyOffset = _LZMA_TEMP_BUFFER_SIZE - (bufferEnd - *fileOffset);
}
// calculate size
if((*fileOffset + *fileSize) > bufferEnd)
{
// we'll need the whole buffer after copyOffset
copySize = _LZMA_TEMP_BUFFER_SIZE - copyOffset;
}
else
{
// we'll stop somewhere inside the buffer
copySize = (*fileOffset + *fileSize) - (bufferStart + copyOffset);
}
// copy bytes to the real output buffer
if(copySize == 0)
{
continue;
}
// printf("memcpy(outBuffer + %d, tmpBuffer + %d, %d)\n", copyDone, copyOffset, copySize);
memcpy(outBuffer + copyDone, tmpBuffer + copyOffset, copySize);
copyDone += copySize;
}
while((*fileOffset + *fileSize) > bufferEnd);
/* result = LzmaDecode(&state,
#ifdef _LZMA_IN_CB
&lzmaCallback.InCallback,
#else
inBuffer, (SizeT)inSize, &inProcessed,
#endif
outBuffer, (SizeT)outSize, &outSizeProcessedLoc);*/
//*outSizeProcessed = (size_t)outSizeProcessedLoc;
*outSizeProcessed = copyDone;
allocMain->Free(tmpBuffer); // free the temporary buffer again
allocMain->Free(state.Probs);
allocMain->Free(state.Dictionary);
/* if (result == LZMA_RESULT_DATA_ERROR)
return SZE_DATA_ERROR;
if (result != LZMA_RESULT_OK)
return SZE_FAIL;*/
return SZ_OK;
}
return SZE_NOTIMPL;
}
#endif