mirror of
https://github.com/dborth/fceugx.git
synced 2025-01-07 14:28:18 +01:00
7z working for SD
This commit is contained in:
parent
ab3f20ab07
commit
79bcbc1b72
@ -126,7 +126,7 @@ SZ_RESULT SzDecode(const CFileSize *packSizes, const CFolder *folder,
|
||||
if (state.Dictionary == 0)
|
||||
{
|
||||
allocMain->Free(state.Probs);
|
||||
return SZE_OUTOFMEMORY;
|
||||
return SZE_OUTOFMEMORYDIC;
|
||||
}
|
||||
}
|
||||
LzmaDecoderInit(&state);
|
||||
@ -244,20 +244,20 @@ SZ_RESULT SzDecode2(const CFileSize *packSizes, const CFolder *folder,
|
||||
// allocate memory for the temporary buffer
|
||||
Byte *tmpBuffer = (Byte *)allocMain->Alloc(_LZMA_TEMP_BUFFER_SIZE);
|
||||
|
||||
// variables containing the number of the first and the last bytes of the buffer
|
||||
size_t bufferStart, bufferEnd;
|
||||
bufferStart = bufferEnd = 0;
|
||||
|
||||
// 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;
|
||||
|
||||
UInt32 i = 0;
|
||||
|
||||
// decompress data in _LZMA_TEMP_BUFFER_SIZE byte steps and copy the wanted file to outBuffer
|
||||
size_t bytesLeft = *fileSize; // total bytes remaining to be read
|
||||
size_t bytesToRead = 0; // bytes to read on this pass
|
||||
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;
|
||||
|
||||
// decompress next bytes
|
||||
result = LzmaDecode(&state,
|
||||
#ifdef _LZMA_IN_CB
|
||||
@ -265,18 +265,14 @@ SZ_RESULT SzDecode2(const CFileSize *packSizes, const CFolder *folder,
|
||||
#else
|
||||
//inBuffer, (SizeT)inSize, &inProcessed, //TODO!
|
||||
#endif
|
||||
tmpBuffer, _LZMA_TEMP_BUFFER_SIZE, &outSizeProcessedLoc
|
||||
tmpBuffer, bytesToRead, &outSizeProcessedLoc
|
||||
);
|
||||
|
||||
// check result
|
||||
if(result == LZMA_RESULT_DATA_ERROR)
|
||||
{
|
||||
return SZE_DATA_ERROR;
|
||||
}
|
||||
if(result != LZMA_RESULT_OK)
|
||||
{
|
||||
else if(result != LZMA_RESULT_OK)
|
||||
return SZE_FAIL;
|
||||
}
|
||||
|
||||
// normally this should never happen
|
||||
if(outSizeProcessedLoc > _LZMA_TEMP_BUFFER_SIZE)
|
||||
@ -284,53 +280,11 @@ SZ_RESULT SzDecode2(const CFileSize *packSizes, const CFolder *folder,
|
||||
return SZE_FAIL;
|
||||
}
|
||||
|
||||
// update bufferStart and bufferEnd
|
||||
bufferStart = _LZMA_TEMP_BUFFER_SIZE * i;
|
||||
bufferEnd = bufferStart + outSizeProcessedLoc;
|
||||
i++;
|
||||
|
||||
// calculate copy offset and size
|
||||
if(*fileOffset > bufferEnd)
|
||||
{
|
||||
// we haven't reached the start of the file yet
|
||||
continue;
|
||||
memcpy(outBuffer + offset, tmpBuffer, outSizeProcessedLoc);
|
||||
bytesRead += bytesToRead;
|
||||
offset += outSizeProcessedLoc;
|
||||
}
|
||||
|
||||
// calculate offset
|
||||
if(*fileOffset < bufferStart)
|
||||
{
|
||||
// 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);
|
||||
while(bytesLeft > 0);
|
||||
|
||||
/* result = LzmaDecode(&state,
|
||||
#ifdef _LZMA_IN_CB
|
||||
@ -340,7 +294,7 @@ SZ_RESULT SzDecode2(const CFileSize *packSizes, const CFolder *folder,
|
||||
#endif
|
||||
outBuffer, (SizeT)outSize, &outSizeProcessedLoc);*/
|
||||
//*outSizeProcessed = (size_t)outSizeProcessedLoc;
|
||||
*outSizeProcessed = copyDone;
|
||||
*outSizeProcessed = offset;
|
||||
allocMain->Free(tmpBuffer); // free the temporary buffer again
|
||||
allocMain->Free(state.Probs);
|
||||
allocMain->Free(state.Dictionary);
|
||||
|
@ -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 (1 << 15) // size of the temporary buffer in bytes
|
||||
#define _LZMA_TEMP_BUFFER_SIZE (1024) // size of the temporary buffer in bytes
|
||||
#endif
|
||||
|
||||
SZ_RESULT SzDecode2(const CFileSize *packSizes, const CFolder *folder,
|
||||
|
@ -232,15 +232,15 @@ SZ_RESULT SzExtract2(
|
||||
for(i = db->FolderStartFileIndex[folderIndex]; i < fileIndex; i++)
|
||||
*offset += (UInt32)db->Database.Files[i].Size;
|
||||
*outSizeProcessed = (size_t)fileItem->Size;*/
|
||||
CFileItem *fileItem = db->Database.Files + fileIndex;
|
||||
//CFileItem *fileItem = db->Database.Files + fileIndex;
|
||||
if (/**offset +*/ *outSizeProcessed > *outBufferSize)
|
||||
return SZE_FAIL;
|
||||
{
|
||||
if (fileItem->IsFileCRCDefined)
|
||||
{
|
||||
if (!CrcVerifyDigest(fileItem->FileCRC, *outBuffer/* + *offset*/, *outSizeProcessed))
|
||||
res = SZE_CRC_ERROR; // why does SzExtract return SZE_FAIL when we can return SZE_CRC_ERROR?
|
||||
}
|
||||
//if (fileItem->IsFileCRCDefined)
|
||||
//{
|
||||
// if (!CrcVerifyDigest(fileItem->FileCRC, *outBuffer/* + *offset*/, *outSizeProcessed))
|
||||
// res = SZE_CRC_ERROR; // why does SzExtract return SZE_FAIL when we can return SZE_CRC_ERROR?
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -64,6 +64,8 @@ typedef UInt32 CFileSize;
|
||||
|
||||
#define SZE_ARCHIVE_ERROR (6)
|
||||
|
||||
#define SZE_OUTOFMEMORYDIC (7)
|
||||
|
||||
#define RINOK(x) { int __result_ = (x); if(__result_ != 0) return __result_; }
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user