mirror of
https://github.com/dborth/fceugx.git
synced 2025-01-08 06:40:45 +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)
|
if (state.Dictionary == 0)
|
||||||
{
|
{
|
||||||
allocMain->Free(state.Probs);
|
allocMain->Free(state.Probs);
|
||||||
return SZE_OUTOFMEMORY;
|
return SZE_OUTOFMEMORYDIC;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LzmaDecoderInit(&state);
|
LzmaDecoderInit(&state);
|
||||||
@ -244,20 +244,20 @@ 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);
|
||||||
|
|
||||||
// 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
|
// 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
|
do
|
||||||
{
|
{
|
||||||
|
if(bytesLeft > _LZMA_TEMP_BUFFER_SIZE)
|
||||||
|
bytesToRead = _LZMA_TEMP_BUFFER_SIZE;
|
||||||
|
else
|
||||||
|
bytesToRead = bytesLeft;
|
||||||
|
|
||||||
|
bytesLeft -= bytesToRead;
|
||||||
|
|
||||||
// decompress next bytes
|
// decompress next bytes
|
||||||
result = LzmaDecode(&state,
|
result = LzmaDecode(&state,
|
||||||
#ifdef _LZMA_IN_CB
|
#ifdef _LZMA_IN_CB
|
||||||
@ -265,18 +265,14 @@ SZ_RESULT SzDecode2(const CFileSize *packSizes, const CFolder *folder,
|
|||||||
#else
|
#else
|
||||||
//inBuffer, (SizeT)inSize, &inProcessed, //TODO!
|
//inBuffer, (SizeT)inSize, &inProcessed, //TODO!
|
||||||
#endif
|
#endif
|
||||||
tmpBuffer, _LZMA_TEMP_BUFFER_SIZE, &outSizeProcessedLoc
|
tmpBuffer, bytesToRead, &outSizeProcessedLoc
|
||||||
);
|
);
|
||||||
|
|
||||||
// check result
|
// check result
|
||||||
if(result == LZMA_RESULT_DATA_ERROR)
|
if(result == LZMA_RESULT_DATA_ERROR)
|
||||||
{
|
|
||||||
return SZE_DATA_ERROR;
|
return SZE_DATA_ERROR;
|
||||||
}
|
else if(result != LZMA_RESULT_OK)
|
||||||
if(result != LZMA_RESULT_OK)
|
|
||||||
{
|
|
||||||
return SZE_FAIL;
|
return SZE_FAIL;
|
||||||
}
|
|
||||||
|
|
||||||
// normally this should never happen
|
// normally this should never happen
|
||||||
if(outSizeProcessedLoc > _LZMA_TEMP_BUFFER_SIZE)
|
if(outSizeProcessedLoc > _LZMA_TEMP_BUFFER_SIZE)
|
||||||
@ -284,53 +280,11 @@ SZ_RESULT SzDecode2(const CFileSize *packSizes, const CFolder *folder,
|
|||||||
return SZE_FAIL;
|
return SZE_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// update bufferStart and bufferEnd
|
memcpy(outBuffer + offset, tmpBuffer, outSizeProcessedLoc);
|
||||||
bufferStart = _LZMA_TEMP_BUFFER_SIZE * i;
|
bytesRead += bytesToRead;
|
||||||
bufferEnd = bufferStart + outSizeProcessedLoc;
|
offset += outSizeProcessedLoc;
|
||||||
i++;
|
|
||||||
|
|
||||||
// calculate copy offset and size
|
|
||||||
if(*fileOffset > bufferEnd)
|
|
||||||
{
|
|
||||||
// we haven't reached the start of the file yet
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
while(bytesLeft > 0);
|
||||||
// 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);
|
|
||||||
|
|
||||||
/* result = LzmaDecode(&state,
|
/* result = LzmaDecode(&state,
|
||||||
#ifdef _LZMA_IN_CB
|
#ifdef _LZMA_IN_CB
|
||||||
@ -340,7 +294,7 @@ SZ_RESULT SzDecode2(const CFileSize *packSizes, const CFolder *folder,
|
|||||||
#endif
|
#endif
|
||||||
outBuffer, (SizeT)outSize, &outSizeProcessedLoc);*/
|
outBuffer, (SizeT)outSize, &outSizeProcessedLoc);*/
|
||||||
//*outSizeProcessed = (size_t)outSizeProcessedLoc;
|
//*outSizeProcessed = (size_t)outSizeProcessedLoc;
|
||||||
*outSizeProcessed = copyDone;
|
*outSizeProcessed = offset;
|
||||||
allocMain->Free(tmpBuffer); // free the temporary buffer again
|
allocMain->Free(tmpBuffer); // free the temporary buffer again
|
||||||
allocMain->Free(state.Probs);
|
allocMain->Free(state.Probs);
|
||||||
allocMain->Free(state.Dictionary);
|
allocMain->Free(state.Dictionary);
|
||||||
|
@ -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 (1 << 15) // size of the temporary buffer in bytes
|
#define _LZMA_TEMP_BUFFER_SIZE (1024) // 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,
|
||||||
|
@ -232,15 +232,15 @@ SZ_RESULT SzExtract2(
|
|||||||
for(i = db->FolderStartFileIndex[folderIndex]; i < fileIndex; i++)
|
for(i = db->FolderStartFileIndex[folderIndex]; i < fileIndex; i++)
|
||||||
*offset += (UInt32)db->Database.Files[i].Size;
|
*offset += (UInt32)db->Database.Files[i].Size;
|
||||||
*outSizeProcessed = (size_t)fileItem->Size;*/
|
*outSizeProcessed = (size_t)fileItem->Size;*/
|
||||||
CFileItem *fileItem = db->Database.Files + fileIndex;
|
//CFileItem *fileItem = db->Database.Files + fileIndex;
|
||||||
if (/**offset +*/ *outSizeProcessed > *outBufferSize)
|
if (/**offset +*/ *outSizeProcessed > *outBufferSize)
|
||||||
return SZE_FAIL;
|
return SZE_FAIL;
|
||||||
{
|
{
|
||||||
if (fileItem->IsFileCRCDefined)
|
//if (fileItem->IsFileCRCDefined)
|
||||||
{
|
//{
|
||||||
if (!CrcVerifyDigest(fileItem->FileCRC, *outBuffer/* + *offset*/, *outSizeProcessed))
|
// if (!CrcVerifyDigest(fileItem->FileCRC, *outBuffer/* + *offset*/, *outSizeProcessed))
|
||||||
res = SZE_CRC_ERROR; // why does SzExtract return SZE_FAIL when we can return SZE_CRC_ERROR?
|
// 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_ARCHIVE_ERROR (6)
|
||||||
|
|
||||||
|
#define SZE_OUTOFMEMORYDIC (7)
|
||||||
|
|
||||||
#define RINOK(x) { int __result_ = (x); if(__result_ != 0) return __result_; }
|
#define RINOK(x) { int __result_ = (x); if(__result_ != 0) return __result_; }
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user