mirror of
https://github.com/Xevion/easy7zip.git
synced 2025-12-06 13:14:59 -06:00
4.44 beta
This commit is contained in:
committed by
Kornel Lesiński
parent
804edc5756
commit
d9666cf046
@@ -1,20 +0,0 @@
|
|||||||
/* 7zAlloc.h */
|
|
||||||
|
|
||||||
#ifndef __7Z_ALLOC_H
|
|
||||||
#define __7Z_ALLOC_H
|
|
||||||
|
|
||||||
#include <stddef.h>
|
|
||||||
|
|
||||||
typedef struct _ISzAlloc
|
|
||||||
{
|
|
||||||
void *(*Alloc)(size_t size);
|
|
||||||
void (*Free)(void *address); /* address can be 0 */
|
|
||||||
} ISzAlloc;
|
|
||||||
|
|
||||||
void *SzAlloc(size_t size);
|
|
||||||
void SzFree(void *address);
|
|
||||||
|
|
||||||
void *SzAllocTemp(size_t size);
|
|
||||||
void SzFreeTemp(void *address);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
/* 7zBuffer.h */
|
|
||||||
|
|
||||||
#ifndef __7Z_BUFFER_H
|
|
||||||
#define __7Z_BUFFER_H
|
|
||||||
|
|
||||||
#include <stddef.h>
|
|
||||||
#include "7zTypes.h"
|
|
||||||
|
|
||||||
typedef struct _CSzByteBuffer
|
|
||||||
{
|
|
||||||
size_t Capacity;
|
|
||||||
Byte *Items;
|
|
||||||
}CSzByteBuffer;
|
|
||||||
|
|
||||||
void SzByteBufferInit(CSzByteBuffer *buffer);
|
|
||||||
int SzByteBufferCreate(CSzByteBuffer *buffer, size_t newCapacity, void * (*allocFunc)(size_t size));
|
|
||||||
void SzByteBufferFree(CSzByteBuffer *buffer, void (*freeFunc)(void *));
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,76 +0,0 @@
|
|||||||
/* 7zCrc.c */
|
|
||||||
|
|
||||||
#include "7zCrc.h"
|
|
||||||
|
|
||||||
#define kCrcPoly 0xEDB88320
|
|
||||||
|
|
||||||
UInt32 g_CrcTable[256];
|
|
||||||
|
|
||||||
void InitCrcTable()
|
|
||||||
{
|
|
||||||
UInt32 i;
|
|
||||||
for (i = 0; i < 256; i++)
|
|
||||||
{
|
|
||||||
UInt32 r = i;
|
|
||||||
int j;
|
|
||||||
for (j = 0; j < 8; j++)
|
|
||||||
if (r & 1)
|
|
||||||
r = (r >> 1) ^ kCrcPoly;
|
|
||||||
else
|
|
||||||
r >>= 1;
|
|
||||||
g_CrcTable[i] = r;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void CrcInit(UInt32 *crc) { *crc = 0xFFFFFFFF; }
|
|
||||||
UInt32 CrcGetDigest(UInt32 *crc) { return *crc ^ 0xFFFFFFFF; }
|
|
||||||
|
|
||||||
void CrcUpdateByte(UInt32 *crc, Byte b)
|
|
||||||
{
|
|
||||||
*crc = g_CrcTable[((Byte)(*crc)) ^ b] ^ (*crc >> 8);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CrcUpdateUInt16(UInt32 *crc, UInt16 v)
|
|
||||||
{
|
|
||||||
CrcUpdateByte(crc, (Byte)v);
|
|
||||||
CrcUpdateByte(crc, (Byte)(v >> 8));
|
|
||||||
}
|
|
||||||
|
|
||||||
void CrcUpdateUInt32(UInt32 *crc, UInt32 v)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
for (i = 0; i < 4; i++)
|
|
||||||
CrcUpdateByte(crc, (Byte)(v >> (8 * i)));
|
|
||||||
}
|
|
||||||
|
|
||||||
void CrcUpdateUInt64(UInt32 *crc, UInt64 v)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
for (i = 0; i < 8; i++)
|
|
||||||
{
|
|
||||||
CrcUpdateByte(crc, (Byte)(v));
|
|
||||||
v >>= 8;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void CrcUpdate(UInt32 *crc, const void *data, size_t size)
|
|
||||||
{
|
|
||||||
UInt32 v = *crc;
|
|
||||||
const Byte *p = (const Byte *)data;
|
|
||||||
for (; size > 0 ; size--, p++)
|
|
||||||
v = g_CrcTable[((Byte)(v)) ^ *p] ^ (v >> 8);
|
|
||||||
*crc = v;
|
|
||||||
}
|
|
||||||
|
|
||||||
UInt32 CrcCalculateDigest(const void *data, size_t size)
|
|
||||||
{
|
|
||||||
UInt32 crc;
|
|
||||||
CrcInit(&crc);
|
|
||||||
CrcUpdate(&crc, data, size);
|
|
||||||
return CrcGetDigest(&crc);
|
|
||||||
}
|
|
||||||
|
|
||||||
int CrcVerifyDigest(UInt32 digest, const void *data, size_t size)
|
|
||||||
{
|
|
||||||
return (CrcCalculateDigest(data, size) == digest);
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
/* 7zDecode.h */
|
|
||||||
|
|
||||||
#ifndef __7Z_DECODE_H
|
|
||||||
#define __7Z_DECODE_H
|
|
||||||
|
|
||||||
#include "7zItem.h"
|
|
||||||
#include "7zAlloc.h"
|
|
||||||
#ifdef _LZMA_IN_CB
|
|
||||||
#include "7zIn.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
SZ_RESULT SzDecode(const CFileSize *packSizes, const CFolder *folder,
|
|
||||||
#ifdef _LZMA_IN_CB
|
|
||||||
ISzInStream *stream,
|
|
||||||
#else
|
|
||||||
const Byte *inBuffer,
|
|
||||||
#endif
|
|
||||||
Byte *outBuffer, size_t outSize,
|
|
||||||
size_t *outSizeProcessed, ISzAlloc *allocMain);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
/* 7zExtract.h */
|
|
||||||
|
|
||||||
#ifndef __7Z_EXTRACT_H
|
|
||||||
#define __7Z_EXTRACT_H
|
|
||||||
|
|
||||||
#include "7zIn.h"
|
|
||||||
|
|
||||||
/*
|
|
||||||
SzExtract extracts file from archive
|
|
||||||
|
|
||||||
*outBuffer must be 0 before first call for each new archive.
|
|
||||||
|
|
||||||
Extracting cache:
|
|
||||||
If you need to decompress more than one file, you can send
|
|
||||||
these values from previous call:
|
|
||||||
*blockIndex,
|
|
||||||
*outBuffer,
|
|
||||||
*outBufferSize
|
|
||||||
You can consider "*outBuffer" as cache of solid block. If your archive is solid,
|
|
||||||
it will increase decompression speed.
|
|
||||||
|
|
||||||
If you use external function, you can declare these 3 cache variables
|
|
||||||
(blockIndex, outBuffer, outBufferSize) as static in that external function.
|
|
||||||
|
|
||||||
Free *outBuffer and set *outBuffer to 0, if you want to flush cache.
|
|
||||||
*/
|
|
||||||
|
|
||||||
SZ_RESULT SzExtract(
|
|
||||||
ISzInStream *inStream,
|
|
||||||
CArchiveDatabaseEx *db,
|
|
||||||
UInt32 fileIndex, /* index of file */
|
|
||||||
UInt32 *blockIndex, /* index of solid block */
|
|
||||||
Byte **outBuffer, /* pointer to pointer to output buffer (allocated with allocMain) */
|
|
||||||
size_t *outBufferSize, /* buffer size for output buffer */
|
|
||||||
size_t *offset, /* offset of stream for required file in *outBuffer */
|
|
||||||
size_t *outSizeProcessed, /* size of file in *outBuffer */
|
|
||||||
ISzAlloc *allocMain,
|
|
||||||
ISzAlloc *allocTemp);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
/* 7zHeader.h */
|
|
||||||
|
|
||||||
#ifndef __7Z_HEADER_H
|
|
||||||
#define __7Z_HEADER_H
|
|
||||||
|
|
||||||
#include "7zTypes.h"
|
|
||||||
|
|
||||||
#define k7zSignatureSize 6
|
|
||||||
extern Byte k7zSignature[k7zSignatureSize];
|
|
||||||
|
|
||||||
#define k7zMajorVersion 0
|
|
||||||
|
|
||||||
#define k7zStartHeaderSize 0x20
|
|
||||||
|
|
||||||
enum EIdEnum
|
|
||||||
{
|
|
||||||
k7zIdEnd,
|
|
||||||
|
|
||||||
k7zIdHeader,
|
|
||||||
|
|
||||||
k7zIdArchiveProperties,
|
|
||||||
|
|
||||||
k7zIdAdditionalStreamsInfo,
|
|
||||||
k7zIdMainStreamsInfo,
|
|
||||||
k7zIdFilesInfo,
|
|
||||||
|
|
||||||
k7zIdPackInfo,
|
|
||||||
k7zIdUnPackInfo,
|
|
||||||
k7zIdSubStreamsInfo,
|
|
||||||
|
|
||||||
k7zIdSize,
|
|
||||||
k7zIdCRC,
|
|
||||||
|
|
||||||
k7zIdFolder,
|
|
||||||
|
|
||||||
k7zIdCodersUnPackSize,
|
|
||||||
k7zIdNumUnPackStream,
|
|
||||||
|
|
||||||
k7zIdEmptyStream,
|
|
||||||
k7zIdEmptyFile,
|
|
||||||
k7zIdAnti,
|
|
||||||
|
|
||||||
k7zIdName,
|
|
||||||
k7zIdCreationTime,
|
|
||||||
k7zIdLastAccessTime,
|
|
||||||
k7zIdLastWriteTime,
|
|
||||||
k7zIdWinAttributes,
|
|
||||||
k7zIdComment,
|
|
||||||
|
|
||||||
k7zIdEncodedHeader,
|
|
||||||
|
|
||||||
k7zIdStartPos
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
/* 7zIn.h */
|
|
||||||
|
|
||||||
#ifndef __7Z_IN_H
|
|
||||||
#define __7Z_IN_H
|
|
||||||
|
|
||||||
#include "7zHeader.h"
|
|
||||||
#include "7zItem.h"
|
|
||||||
#include "7zAlloc.h"
|
|
||||||
|
|
||||||
typedef struct _CInArchiveInfo
|
|
||||||
{
|
|
||||||
CFileSize StartPositionAfterHeader;
|
|
||||||
CFileSize DataStartPosition;
|
|
||||||
}CInArchiveInfo;
|
|
||||||
|
|
||||||
typedef struct _CArchiveDatabaseEx
|
|
||||||
{
|
|
||||||
CArchiveDatabase Database;
|
|
||||||
CInArchiveInfo ArchiveInfo;
|
|
||||||
UInt32 *FolderStartPackStreamIndex;
|
|
||||||
CFileSize *PackStreamStartPositions;
|
|
||||||
UInt32 *FolderStartFileIndex;
|
|
||||||
UInt32 *FileIndexToFolderIndexMap;
|
|
||||||
}CArchiveDatabaseEx;
|
|
||||||
|
|
||||||
void SzArDbExInit(CArchiveDatabaseEx *db);
|
|
||||||
void SzArDbExFree(CArchiveDatabaseEx *db, void (*freeFunc)(void *));
|
|
||||||
CFileSize SzArDbGetFolderStreamPos(CArchiveDatabaseEx *db, UInt32 folderIndex, UInt32 indexInFolder);
|
|
||||||
CFileSize SzArDbGetFolderFullPackSize(CArchiveDatabaseEx *db, UInt32 folderIndex);
|
|
||||||
|
|
||||||
typedef struct _ISzInStream
|
|
||||||
{
|
|
||||||
#ifdef _LZMA_IN_CB
|
|
||||||
SZ_RESULT (*Read)(
|
|
||||||
void *object, /* pointer to ISzInStream itself */
|
|
||||||
void **buffer, /* out: pointer to buffer with data */
|
|
||||||
size_t maxRequiredSize, /* max required size to read */
|
|
||||||
size_t *processedSize); /* real processed size.
|
|
||||||
processedSize can be less than maxRequiredSize.
|
|
||||||
If processedSize == 0, then there are no more
|
|
||||||
bytes in stream. */
|
|
||||||
#else
|
|
||||||
SZ_RESULT (*Read)(void *object, void *buffer, size_t size, size_t *processedSize);
|
|
||||||
#endif
|
|
||||||
SZ_RESULT (*Seek)(void *object, CFileSize pos);
|
|
||||||
} ISzInStream;
|
|
||||||
|
|
||||||
|
|
||||||
int SzArchiveOpen(
|
|
||||||
ISzInStream *inStream,
|
|
||||||
CArchiveDatabaseEx *db,
|
|
||||||
ISzAlloc *allocMain,
|
|
||||||
ISzAlloc *allocTemp);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,90 +0,0 @@
|
|||||||
/* 7zItem.h */
|
|
||||||
|
|
||||||
#ifndef __7Z_ITEM_H
|
|
||||||
#define __7Z_ITEM_H
|
|
||||||
|
|
||||||
#include "7zMethodID.h"
|
|
||||||
#include "7zHeader.h"
|
|
||||||
#include "7zBuffer.h"
|
|
||||||
|
|
||||||
typedef struct _CCoderInfo
|
|
||||||
{
|
|
||||||
UInt32 NumInStreams;
|
|
||||||
UInt32 NumOutStreams;
|
|
||||||
CMethodID MethodID;
|
|
||||||
CSzByteBuffer Properties;
|
|
||||||
}CCoderInfo;
|
|
||||||
|
|
||||||
void SzCoderInfoInit(CCoderInfo *coder);
|
|
||||||
void SzCoderInfoFree(CCoderInfo *coder, void (*freeFunc)(void *p));
|
|
||||||
|
|
||||||
typedef struct _CBindPair
|
|
||||||
{
|
|
||||||
UInt32 InIndex;
|
|
||||||
UInt32 OutIndex;
|
|
||||||
}CBindPair;
|
|
||||||
|
|
||||||
typedef struct _CFolder
|
|
||||||
{
|
|
||||||
UInt32 NumCoders;
|
|
||||||
CCoderInfo *Coders;
|
|
||||||
UInt32 NumBindPairs;
|
|
||||||
CBindPair *BindPairs;
|
|
||||||
UInt32 NumPackStreams;
|
|
||||||
UInt32 *PackStreams;
|
|
||||||
CFileSize *UnPackSizes;
|
|
||||||
int UnPackCRCDefined;
|
|
||||||
UInt32 UnPackCRC;
|
|
||||||
|
|
||||||
UInt32 NumUnPackStreams;
|
|
||||||
}CFolder;
|
|
||||||
|
|
||||||
void SzFolderInit(CFolder *folder);
|
|
||||||
CFileSize SzFolderGetUnPackSize(CFolder *folder);
|
|
||||||
int SzFolderFindBindPairForInStream(CFolder *folder, UInt32 inStreamIndex);
|
|
||||||
UInt32 SzFolderGetNumOutStreams(CFolder *folder);
|
|
||||||
CFileSize SzFolderGetUnPackSize(CFolder *folder);
|
|
||||||
|
|
||||||
/* #define CArchiveFileTime UInt64 */
|
|
||||||
|
|
||||||
typedef struct _CFileItem
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
CArchiveFileTime LastWriteTime;
|
|
||||||
CFileSize StartPos;
|
|
||||||
UInt32 Attributes;
|
|
||||||
*/
|
|
||||||
CFileSize Size;
|
|
||||||
UInt32 FileCRC;
|
|
||||||
char *Name;
|
|
||||||
|
|
||||||
Byte IsFileCRCDefined;
|
|
||||||
Byte HasStream;
|
|
||||||
Byte IsDirectory;
|
|
||||||
Byte IsAnti;
|
|
||||||
/*
|
|
||||||
int AreAttributesDefined;
|
|
||||||
int IsLastWriteTimeDefined;
|
|
||||||
int IsStartPosDefined;
|
|
||||||
*/
|
|
||||||
}CFileItem;
|
|
||||||
|
|
||||||
void SzFileInit(CFileItem *fileItem);
|
|
||||||
|
|
||||||
typedef struct _CArchiveDatabase
|
|
||||||
{
|
|
||||||
UInt32 NumPackStreams;
|
|
||||||
CFileSize *PackSizes;
|
|
||||||
Byte *PackCRCsDefined;
|
|
||||||
UInt32 *PackCRCs;
|
|
||||||
UInt32 NumFolders;
|
|
||||||
CFolder *Folders;
|
|
||||||
UInt32 NumFiles;
|
|
||||||
CFileItem *Files;
|
|
||||||
}CArchiveDatabase;
|
|
||||||
|
|
||||||
void SzArchiveDatabaseInit(CArchiveDatabase *db);
|
|
||||||
void SzArchiveDatabaseFree(CArchiveDatabase *db, void (*freeFunc)(void *));
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
/* 7zMethodID.h */
|
|
||||||
|
|
||||||
#ifndef __7Z_METHOD_ID_H
|
|
||||||
#define __7Z_METHOD_ID_H
|
|
||||||
|
|
||||||
#include "7zTypes.h"
|
|
||||||
|
|
||||||
#define kMethodIDSize 15
|
|
||||||
|
|
||||||
typedef struct _CMethodID
|
|
||||||
{
|
|
||||||
Byte ID[kMethodIDSize];
|
|
||||||
Byte IDSize;
|
|
||||||
} CMethodID;
|
|
||||||
|
|
||||||
int AreMethodsEqual(CMethodID *a1, CMethodID *a2);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,288 +0,0 @@
|
|||||||
// BlockSort.cpp
|
|
||||||
|
|
||||||
#include "StdAfx.h"
|
|
||||||
|
|
||||||
#include "BlockSort.h"
|
|
||||||
|
|
||||||
#include "Common/Alloc.h"
|
|
||||||
|
|
||||||
namespace NCompress {
|
|
||||||
|
|
||||||
static const int kNumHashBytes = 2;
|
|
||||||
static const UInt32 kNumHashValues = 1 << (kNumHashBytes * 8);
|
|
||||||
|
|
||||||
static const int kNumFlagsBits = 5; // 32 Flags in UInt32 word
|
|
||||||
static const UInt32 kNumFlagsInWord = (1 << kNumFlagsBits);
|
|
||||||
static const UInt32 kFlagsMask = kNumFlagsInWord - 1;
|
|
||||||
static const UInt32 kAllFlags = 0xFFFFFFFF;
|
|
||||||
|
|
||||||
bool CBlockSorter::Create(UInt32 blockSizeMax)
|
|
||||||
{
|
|
||||||
if (Indices != 0 && blockSizeMax == BlockSizeMax)
|
|
||||||
return true;
|
|
||||||
Free();
|
|
||||||
BlockSizeMax = blockSizeMax;
|
|
||||||
Indices = (UInt32 *)::BigAlloc((blockSizeMax * 2 +
|
|
||||||
((blockSizeMax + kFlagsMask) >> kNumFlagsBits) + kNumHashValues) * sizeof(UInt32));
|
|
||||||
return (Indices != 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CBlockSorter::Free()
|
|
||||||
{
|
|
||||||
::BigFree(Indices);
|
|
||||||
Indices = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// SortGroup - is recursive Radix-Range-Sort function with Bubble-Sort optimization
|
|
||||||
// It uses both mask & maskSize (Range-Sort), since it can change values (Groups)
|
|
||||||
// during sorting
|
|
||||||
// returns: 0 - if there are groups, 1 - no more groups
|
|
||||||
UInt32 CBlockSorter::SortGroup(UInt32 groupOffset, UInt32 groupSize, UInt32 mask, UInt32 maskSize)
|
|
||||||
{
|
|
||||||
if (groupSize <= 2)
|
|
||||||
{
|
|
||||||
if (groupSize <= 1)
|
|
||||||
return 0;
|
|
||||||
UInt32 *ind2 = Indices + groupOffset;
|
|
||||||
UInt32 stringPos = ind2[0] + NumSortedBytes;
|
|
||||||
if (stringPos >= BlockSize)
|
|
||||||
stringPos -= BlockSize;
|
|
||||||
UInt32 group = Groups[stringPos];
|
|
||||||
stringPos = ind2[1] + NumSortedBytes;
|
|
||||||
if (stringPos >= BlockSize)
|
|
||||||
stringPos -= BlockSize;
|
|
||||||
if (group == Groups[stringPos])
|
|
||||||
return 1;
|
|
||||||
if (group > Groups[stringPos])
|
|
||||||
{
|
|
||||||
UInt32 temp = ind2[0];
|
|
||||||
ind2[0] = ind2[1];
|
|
||||||
ind2[1] = temp;
|
|
||||||
}
|
|
||||||
Flags[groupOffset >> kNumFlagsBits] &= ~(1 << (groupOffset & kFlagsMask));
|
|
||||||
Groups[ind2[1]] = groupOffset + 1;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check that all strings are in one group (cannot sort)
|
|
||||||
UInt32 *ind2 = Indices + groupOffset;
|
|
||||||
{
|
|
||||||
UInt32 stringPos = ind2[0] + NumSortedBytes;
|
|
||||||
if (stringPos >= BlockSize)
|
|
||||||
stringPos -= BlockSize;
|
|
||||||
UInt32 group = Groups[stringPos];
|
|
||||||
UInt32 j;
|
|
||||||
for (j = 1; j < groupSize; j++)
|
|
||||||
{
|
|
||||||
stringPos = ind2[j] + NumSortedBytes;
|
|
||||||
if (stringPos >= BlockSize)
|
|
||||||
stringPos -= BlockSize;
|
|
||||||
if (Groups[stringPos] != group)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (j == groupSize)
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (groupSize <= 15)
|
|
||||||
{
|
|
||||||
// Bubble-Sort
|
|
||||||
UInt32 lastChange = groupSize;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
UInt32 stringPos = ind2[0] + NumSortedBytes;
|
|
||||||
if (stringPos >= BlockSize)
|
|
||||||
stringPos -= BlockSize;
|
|
||||||
UInt32 group = Groups[stringPos];
|
|
||||||
|
|
||||||
UInt32 sortSize = lastChange;
|
|
||||||
lastChange = 0;
|
|
||||||
for (UInt32 j = 1; j < sortSize; j++)
|
|
||||||
{
|
|
||||||
stringPos = ind2[j] + NumSortedBytes;
|
|
||||||
if (stringPos >= BlockSize)
|
|
||||||
stringPos -= BlockSize;
|
|
||||||
if (Groups[stringPos] < group)
|
|
||||||
{
|
|
||||||
UInt32 temp = ind2[j];
|
|
||||||
ind2[j] = ind2[j - 1];
|
|
||||||
ind2[j - 1] = temp;
|
|
||||||
lastChange = j;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
group = Groups[stringPos];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while(lastChange > 1);
|
|
||||||
|
|
||||||
// Write Flags
|
|
||||||
UInt32 stringPos = ind2[0] + NumSortedBytes;
|
|
||||||
if (stringPos >= BlockSize)
|
|
||||||
stringPos -= BlockSize;
|
|
||||||
UInt32 group = Groups[stringPos];
|
|
||||||
|
|
||||||
UInt32 j;
|
|
||||||
for (j = 1; j < groupSize; j++)
|
|
||||||
{
|
|
||||||
stringPos = ind2[j] + NumSortedBytes;
|
|
||||||
if (stringPos >= BlockSize)
|
|
||||||
stringPos -= BlockSize;
|
|
||||||
if (Groups[stringPos] != group)
|
|
||||||
{
|
|
||||||
group = Groups[stringPos];
|
|
||||||
UInt32 t = groupOffset + j - 1;
|
|
||||||
Flags[t >> kNumFlagsBits] &= ~(1 << (t & kFlagsMask));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write new Groups values and Check that there are groups
|
|
||||||
UInt32 thereAreGroups = 0;
|
|
||||||
for (j = 0; j < groupSize; j++)
|
|
||||||
{
|
|
||||||
UInt32 group = groupOffset + j;
|
|
||||||
for (;;)
|
|
||||||
{
|
|
||||||
Groups[ind2[j]] = group;
|
|
||||||
if ((Flags[(groupOffset + j) >> kNumFlagsBits] & (1 << ((groupOffset + j) & kFlagsMask))) == 0)
|
|
||||||
break;
|
|
||||||
j++;
|
|
||||||
thereAreGroups = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return thereAreGroups;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Radix-Range Sort
|
|
||||||
UInt32 i;
|
|
||||||
for (;;)
|
|
||||||
{
|
|
||||||
if (maskSize == 0)
|
|
||||||
return 1;
|
|
||||||
UInt32 j = groupSize;
|
|
||||||
i = 0;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
UInt32 stringPos = ind2[i] + NumSortedBytes;
|
|
||||||
if (stringPos >= BlockSize)
|
|
||||||
stringPos -= BlockSize;
|
|
||||||
if (Groups[stringPos] >= mask)
|
|
||||||
{
|
|
||||||
for (j--; j > i; j--)
|
|
||||||
{
|
|
||||||
stringPos = ind2[j] + NumSortedBytes;
|
|
||||||
if (stringPos >= BlockSize)
|
|
||||||
stringPos -= BlockSize;
|
|
||||||
if (Groups[stringPos] < mask)
|
|
||||||
{
|
|
||||||
UInt32 temp = ind2[i];
|
|
||||||
ind2[i] = ind2[j];
|
|
||||||
ind2[j] = temp;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (i >= j)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while(++i < j);
|
|
||||||
maskSize >>= 1;
|
|
||||||
if (i == 0)
|
|
||||||
mask += maskSize;
|
|
||||||
else if (i == groupSize)
|
|
||||||
mask -= maskSize;
|
|
||||||
else
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
UInt32 t = (groupOffset + i - 1);
|
|
||||||
Flags[t >> kNumFlagsBits] &= ~(1 << (t & kFlagsMask));
|
|
||||||
|
|
||||||
for (UInt32 j = i; j < groupSize; j++)
|
|
||||||
Groups[ind2[j]] = groupOffset + i;
|
|
||||||
|
|
||||||
UInt32 res = SortGroup(groupOffset, i, mask - maskSize, maskSize);
|
|
||||||
return res | SortGroup(groupOffset + i, groupSize - i, mask + maskSize, maskSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
UInt32 CBlockSorter::Sort(const Byte *data, UInt32 blockSize)
|
|
||||||
{
|
|
||||||
BlockSize = blockSize;
|
|
||||||
UInt32 *counters = Indices + blockSize;
|
|
||||||
Groups = counters + kNumHashValues;
|
|
||||||
Flags = Groups + blockSize;
|
|
||||||
UInt32 i;
|
|
||||||
|
|
||||||
// Radix-Sort for 2 bytes
|
|
||||||
for (i = 0; i < kNumHashValues; i++)
|
|
||||||
counters[i] = 0;
|
|
||||||
for (i = 0; i < blockSize - 1; i++)
|
|
||||||
counters[((UInt32)data[i] << 8) | data[i + 1]]++;
|
|
||||||
counters[((UInt32)data[i] << 8) | data[0]]++;
|
|
||||||
|
|
||||||
{
|
|
||||||
{
|
|
||||||
UInt32 numWords = (blockSize + kFlagsMask) >> kNumFlagsBits;
|
|
||||||
for (i = 0; i < numWords; i++)
|
|
||||||
Flags[i] = kAllFlags;
|
|
||||||
}
|
|
||||||
|
|
||||||
UInt32 sum = 0;
|
|
||||||
for (i = 0; i < kNumHashValues; i++)
|
|
||||||
{
|
|
||||||
UInt32 groupSize = counters[i];
|
|
||||||
if (groupSize > 0)
|
|
||||||
{
|
|
||||||
UInt32 t = sum + groupSize - 1;
|
|
||||||
Flags[t >> kNumFlagsBits] &= ~(1 << (t & kFlagsMask));
|
|
||||||
sum += groupSize;
|
|
||||||
}
|
|
||||||
counters[i] = sum - groupSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < blockSize - 1; i++)
|
|
||||||
Groups[i] = counters[((UInt32)data[i] << 8) | data[i + 1]];
|
|
||||||
Groups[i] = counters[((UInt32)data[i] << 8) | data[0]];
|
|
||||||
|
|
||||||
for (i = 0; i < blockSize - 1; i++)
|
|
||||||
Indices[counters[((UInt32)data[i] << 8) | data[i + 1]]++] = i;
|
|
||||||
Indices[counters[((UInt32)data[i] << 8) | data[0]]++] = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
UInt32 mask;
|
|
||||||
for (mask = 2; mask < blockSize; mask <<= 1);
|
|
||||||
mask >>= 1;
|
|
||||||
for (NumSortedBytes = kNumHashBytes; ; NumSortedBytes <<= 1)
|
|
||||||
{
|
|
||||||
UInt32 newLimit = 0;
|
|
||||||
for (i = 0; i < blockSize;)
|
|
||||||
{
|
|
||||||
if ((Flags[i >> kNumFlagsBits] & (1 << (i & kFlagsMask))) == 0)
|
|
||||||
{
|
|
||||||
i++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
UInt32 groupSize;
|
|
||||||
for(groupSize = 1;
|
|
||||||
(Flags[(i + groupSize) >> kNumFlagsBits] & (1 << ((i + groupSize) & kFlagsMask))) != 0;
|
|
||||||
groupSize++);
|
|
||||||
|
|
||||||
groupSize++;
|
|
||||||
|
|
||||||
if (NumSortedBytes >= blockSize)
|
|
||||||
for (UInt32 j = 0; j < groupSize; j++)
|
|
||||||
{
|
|
||||||
UInt32 t = (i + j);
|
|
||||||
Flags[t >> kNumFlagsBits] &= ~(1 << (t & kFlagsMask));
|
|
||||||
Groups[Indices[t]] = t;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
if (SortGroup(i, groupSize, mask, mask) != 0)
|
|
||||||
newLimit = i + groupSize;
|
|
||||||
i += groupSize;
|
|
||||||
}
|
|
||||||
if (newLimit == 0)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return Groups[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
// BlockSort.h
|
|
||||||
|
|
||||||
#ifndef __BLOCKSORT_H
|
|
||||||
#define __BLOCKSORT_H
|
|
||||||
|
|
||||||
#include "Common/Types.h"
|
|
||||||
|
|
||||||
namespace NCompress {
|
|
||||||
|
|
||||||
class CBlockSorter
|
|
||||||
{
|
|
||||||
UInt32 *Groups;
|
|
||||||
UInt32 *Flags;
|
|
||||||
UInt32 BlockSize;
|
|
||||||
UInt32 NumSortedBytes;
|
|
||||||
UInt32 BlockSizeMax;
|
|
||||||
UInt32 SortGroup(UInt32 groupOffset, UInt32 groupSize, UInt32 mask, UInt32 maskSize);
|
|
||||||
public:
|
|
||||||
UInt32 *Indices;
|
|
||||||
CBlockSorter(): Indices(0) {}
|
|
||||||
~CBlockSorter() { Free(); }
|
|
||||||
bool Create(UInt32 blockSizeMax);
|
|
||||||
void Free();
|
|
||||||
UInt32 Sort(const Byte *data, UInt32 blockSize);
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,325 +0,0 @@
|
|||||||
// Compression/HuffmanEncoder.cpp
|
|
||||||
|
|
||||||
#include "StdAfx.h"
|
|
||||||
|
|
||||||
#include "HuffmanEncoder.h"
|
|
||||||
#include "Common/Defs.h"
|
|
||||||
#include "Common/Alloc.h"
|
|
||||||
|
|
||||||
namespace NCompression {
|
|
||||||
namespace NHuffman {
|
|
||||||
|
|
||||||
static const char *kIncorrectBitLenCountsMessage = "Incorrect bit len counts";
|
|
||||||
|
|
||||||
CEncoder::CEncoder():
|
|
||||||
m_Items(0),
|
|
||||||
m_Heap(0),
|
|
||||||
m_Depth(0)
|
|
||||||
{}
|
|
||||||
|
|
||||||
void CEncoder::Free()
|
|
||||||
{
|
|
||||||
MyFree(m_Items);
|
|
||||||
MyFree(m_Heap);
|
|
||||||
MyFree(m_Depth);
|
|
||||||
m_Items = 0;
|
|
||||||
m_Heap = 0;
|
|
||||||
m_Depth = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CEncoder::Create(UInt32 numSymbols,
|
|
||||||
const Byte *extraBits, UInt32 extraBase, UInt32 maxLength)
|
|
||||||
{
|
|
||||||
m_NumSymbols = numSymbols;
|
|
||||||
m_ExtraBits = extraBits;
|
|
||||||
m_ExtraBase = extraBase;
|
|
||||||
m_MaxLength = maxLength;
|
|
||||||
m_HeapSize = numSymbols * 2 + 1;
|
|
||||||
Free();
|
|
||||||
m_Items = (CItem *)MyAlloc(m_HeapSize * sizeof(CItem));
|
|
||||||
m_Heap = (UInt32 *)MyAlloc(m_HeapSize * sizeof(UInt32));
|
|
||||||
m_Depth = (Byte *)MyAlloc(m_HeapSize * sizeof(Byte));
|
|
||||||
if (m_Items == 0 || m_Heap == 0 || m_Depth == 0)
|
|
||||||
{
|
|
||||||
Free();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
CEncoder::~CEncoder()
|
|
||||||
{
|
|
||||||
Free();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CEncoder::StartNewBlock()
|
|
||||||
{
|
|
||||||
for (UInt32 i = 0; i < m_NumSymbols; i++)
|
|
||||||
m_Items[i].Freq = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const int kSmallest = 1;
|
|
||||||
|
|
||||||
// ===========================================================================
|
|
||||||
// Remove the smallest element from the heap and recreate the heap with
|
|
||||||
// one less element. Updates heap and m_HeapLength.
|
|
||||||
|
|
||||||
UInt32 CEncoder::RemoveSmallest()
|
|
||||||
{
|
|
||||||
UInt32 top = m_Heap[kSmallest];
|
|
||||||
m_Heap[kSmallest] = m_Heap[m_HeapLength--];
|
|
||||||
DownHeap(kSmallest);
|
|
||||||
return top;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ===========================================================================
|
|
||||||
// Compares to subtrees, using the tree m_Depth as tie breaker when
|
|
||||||
// the subtrees have equal frequency. This minimizes the worst case length.
|
|
||||||
|
|
||||||
bool CEncoder::Smaller(int n, int m)
|
|
||||||
{
|
|
||||||
return (m_Items[n].Freq < m_Items[m].Freq ||
|
|
||||||
(m_Items[n].Freq == m_Items[m].Freq && m_Depth[n] <= m_Depth[m]));
|
|
||||||
}
|
|
||||||
|
|
||||||
// ===========================================================================
|
|
||||||
// Restore the m_Heap property by moving down the tree starting at node k,
|
|
||||||
// exchanging a node with the smallest of its two sons if necessary, stopping
|
|
||||||
// when the m_Heap property is re-established (each father CompareFreqs than its
|
|
||||||
// two sons).
|
|
||||||
|
|
||||||
void CEncoder::DownHeap(UInt32 k)
|
|
||||||
{
|
|
||||||
UInt32 symbol = m_Heap[k];
|
|
||||||
for (UInt32 j = k << 1; j <= m_HeapLength;) // j: left son of k
|
|
||||||
{
|
|
||||||
// Set j to the smallest of the two sons:
|
|
||||||
if (j < m_HeapLength && Smaller(m_Heap[j+1], m_Heap[j]))
|
|
||||||
j++;
|
|
||||||
UInt32 htemp = m_Heap[j]; // htemp required because of bug in SASC compiler
|
|
||||||
if (Smaller(symbol, htemp)) // Exit if v is smaller than both sons
|
|
||||||
break;
|
|
||||||
m_Heap[k] = htemp; // Exchange v with the smallest son
|
|
||||||
k = j;
|
|
||||||
j <<= 1; // And continue down the tree, setting j to the left son of k
|
|
||||||
}
|
|
||||||
m_Heap[k] = symbol;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ===========================================================================
|
|
||||||
// Compute the optimal bit lengths for a tree and update the total bit length
|
|
||||||
// for the current block.
|
|
||||||
// IN assertion: the fields freq and dad are set, heap[heapMax] and
|
|
||||||
// above are the tree nodes sorted by increasing frequency.
|
|
||||||
// OUT assertions: the field len is set to the optimal bit length, the
|
|
||||||
// array m_BitLenCounters contains the frequencies for each bit length.
|
|
||||||
// The length m_BlockBitLength is updated; static_len is also updated if stree is
|
|
||||||
// not null.
|
|
||||||
|
|
||||||
void CEncoder::GenerateBitLen(UInt32 maxCode, UInt32 heapMax)
|
|
||||||
{
|
|
||||||
int overflow = 0; // number of elements with bit length too large
|
|
||||||
|
|
||||||
for (UInt32 i = 0; i <= kNumBitsInLongestCode; i++)
|
|
||||||
m_BitLenCounters[i] = 0;
|
|
||||||
|
|
||||||
/* In a first pass, compute the optimal bit lengths (which may
|
|
||||||
* overflow in the case of the bit length tree).
|
|
||||||
*/
|
|
||||||
m_Items[m_Heap[heapMax]].Len = 0; /* root of the heap */
|
|
||||||
UInt32 h; /* heap index */
|
|
||||||
for (h = heapMax+1; h < m_HeapSize; h++)
|
|
||||||
{
|
|
||||||
UInt32 symbol = m_Heap[h];
|
|
||||||
UInt32 len = m_Items[m_Items[symbol].Dad].Len + 1;
|
|
||||||
if (len > m_MaxLength)
|
|
||||||
{
|
|
||||||
len = m_MaxLength;
|
|
||||||
overflow++;
|
|
||||||
}
|
|
||||||
m_Items[symbol].Len = len; // We overwrite m_Items[symbol].Dad which is no longer needed
|
|
||||||
if (symbol > maxCode)
|
|
||||||
continue; // not a leaf node
|
|
||||||
m_BitLenCounters[len]++;
|
|
||||||
UInt32 extraBits;
|
|
||||||
if (m_ExtraBits != 0 && symbol >= m_ExtraBase)
|
|
||||||
extraBits = m_ExtraBits[symbol - m_ExtraBase];
|
|
||||||
else
|
|
||||||
extraBits = 0;
|
|
||||||
m_BlockBitLength += (m_Items[symbol].Freq * (len + extraBits));
|
|
||||||
}
|
|
||||||
if (overflow == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// This happens for example on obj2 and pic of the Calgary corpus
|
|
||||||
// Find the first bit length which could increase:
|
|
||||||
do
|
|
||||||
{
|
|
||||||
UInt32 bits = m_MaxLength-1;
|
|
||||||
while (m_BitLenCounters[bits] == 0)
|
|
||||||
bits--;
|
|
||||||
m_BitLenCounters[bits]--; // move one leaf down the m_Items
|
|
||||||
m_BitLenCounters[bits + 1] += 2; // move one overflow item as its brother
|
|
||||||
m_BitLenCounters[m_MaxLength]--;
|
|
||||||
// The brother of the overflow item also moves one step up,
|
|
||||||
// but this does not affect m_BitLenCounters[m_MaxLength]
|
|
||||||
overflow -= 2;
|
|
||||||
}
|
|
||||||
while (overflow > 0);
|
|
||||||
|
|
||||||
// Now recompute all bit lengths, scanning in increasing frequency.
|
|
||||||
// h is still equal to HEAP_SIZE. (It is simpler to reconstruct all
|
|
||||||
// lengths instead of fixing only the wrong ones. This idea is taken
|
|
||||||
// from 'ar' written by Haruhiko Okumura.)
|
|
||||||
for (UInt32 bits = m_MaxLength; bits != 0; bits--)
|
|
||||||
{
|
|
||||||
UInt32 numNodes = m_BitLenCounters[bits];
|
|
||||||
while (numNodes != 0)
|
|
||||||
{
|
|
||||||
UInt32 m = m_Heap[--h];
|
|
||||||
if (m > maxCode)
|
|
||||||
continue;
|
|
||||||
if (m_Items[m].Len != (unsigned) bits)
|
|
||||||
{
|
|
||||||
m_BlockBitLength += ((long)bits - (long)m_Items[m].Len) * (long)m_Items[m].Freq;
|
|
||||||
m_Items[m].Len = bits;
|
|
||||||
}
|
|
||||||
numNodes--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// ===========================================================================
|
|
||||||
// Generate the codes for a given tree and bit counts (which need not be
|
|
||||||
// optimal).
|
|
||||||
// IN assertion: the array m_BitLenCounters contains the bit length statistics for
|
|
||||||
// the given tree and the field len is set for all tree elements.
|
|
||||||
// OUT assertion: the field code is set for all tree elements of non
|
|
||||||
// zero code length.
|
|
||||||
|
|
||||||
// UInt32 maxCode = largest code with non zero frequency
|
|
||||||
|
|
||||||
|
|
||||||
void CEncoder::GenerateCodes(UInt32 maxCode)
|
|
||||||
{
|
|
||||||
UInt32 nextCodes[kNumBitsInLongestCode + 1]; // next code value for each bit length
|
|
||||||
UInt32 code = 0; // running code value
|
|
||||||
// The distribution counts are first used to generate the code values
|
|
||||||
// without bit reversal.
|
|
||||||
for (UInt32 bits = 1; bits <= kNumBitsInLongestCode; bits++)
|
|
||||||
nextCodes[bits] = code = (code + m_BitLenCounters[bits - 1]) << 1;
|
|
||||||
// Check that the bit counts in m_BitLenCounters are consistent. The last code
|
|
||||||
// must be all ones.
|
|
||||||
if (code + m_BitLenCounters[kNumBitsInLongestCode] - 1 != (1 << kNumBitsInLongestCode) - 1)
|
|
||||||
throw kIncorrectBitLenCountsMessage;
|
|
||||||
for (UInt32 n = 0; n <= maxCode; n++)
|
|
||||||
{
|
|
||||||
int len = m_Items[n].Len;
|
|
||||||
if (len == 0)
|
|
||||||
continue;
|
|
||||||
m_Items[n].Code = nextCodes[len]++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// ===========================================================================
|
|
||||||
// Construct one Huffman tree and assigns the code bit strings and lengths.
|
|
||||||
// Update the total bit length for the current block.
|
|
||||||
// IN assertion: the field freq is set for all tree elements.
|
|
||||||
// OUT assertions: the fields len and code are set to the optimal bit length
|
|
||||||
// and corresponding code. The length m_BlockBitLength is updated; static_len is
|
|
||||||
// also updated if stree is not null. The field max_code is set.
|
|
||||||
|
|
||||||
void CEncoder::BuildTree(Byte *levels)
|
|
||||||
{
|
|
||||||
m_BlockBitLength = 0;
|
|
||||||
int maxCode = -1; // WAS = -1; largest code with non zero frequency */
|
|
||||||
|
|
||||||
// Construct the initial m_Heap, with least frequent element in
|
|
||||||
// m_Heap[kSmallest]. The sons of m_Heap[n] are m_Heap[2*n] and m_Heap[2*n+1].
|
|
||||||
// m_Heap[0] is not used.
|
|
||||||
//
|
|
||||||
|
|
||||||
m_HeapLength = 0;
|
|
||||||
UInt32 n; // iterate over m_Heap elements
|
|
||||||
for (n = 0; n < m_NumSymbols; n++)
|
|
||||||
{
|
|
||||||
if (m_Items[n].Freq != 0)
|
|
||||||
{
|
|
||||||
m_Heap[++m_HeapLength] = maxCode = n;
|
|
||||||
m_Depth[n] = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
m_Items[n].Len = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// The pkzip format requires that at least one distance code exists,
|
|
||||||
// and that at least one bit should be sent even if there is only one
|
|
||||||
// possible code. So to avoid special checks later on we force at least
|
|
||||||
// two codes of non zero frequency.
|
|
||||||
while (m_HeapLength < 2)
|
|
||||||
{
|
|
||||||
int aNewNode = m_Heap[++m_HeapLength] = (maxCode < 2 ? ++maxCode : 0);
|
|
||||||
m_Items[aNewNode].Freq = 1;
|
|
||||||
m_Depth[aNewNode] = 0;
|
|
||||||
m_BlockBitLength--;
|
|
||||||
// if (stree) static_len -= stree[aNewNode].Len;
|
|
||||||
// aNewNode is 0 or 1 so it does not have m_ExtraBits bits
|
|
||||||
}
|
|
||||||
|
|
||||||
// The elements m_Heap[m_HeapLength/2+1 .. m_HeapLength] are leaves of the m_Items,
|
|
||||||
// establish sub-heaps of increasing lengths:
|
|
||||||
for (n = m_HeapLength / 2; n >= 1; n--)
|
|
||||||
DownHeap(n);
|
|
||||||
|
|
||||||
// Construct the Huffman tree by repeatedly combining the least two
|
|
||||||
// frequent nodes.
|
|
||||||
int node = m_NumSymbols; // next internal node of the tree
|
|
||||||
UInt32 heapMax = m_NumSymbols * 2+ 1;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
n = RemoveSmallest(); /* n = node of least frequency */
|
|
||||||
UInt32 m = m_Heap[kSmallest]; /* m = node of next least frequency */
|
|
||||||
|
|
||||||
m_Heap[--heapMax] = n; /* keep the nodes sorted by frequency */
|
|
||||||
m_Heap[--heapMax] = m;
|
|
||||||
|
|
||||||
// Create a new node father of n and m
|
|
||||||
m_Items[node].Freq = m_Items[n].Freq + m_Items[m].Freq;
|
|
||||||
m_Depth[node] = (Byte) (MyMax(m_Depth[n], m_Depth[m]) + 1);
|
|
||||||
m_Items[n].Dad = m_Items[m].Dad = node;
|
|
||||||
// and insert the new node in the m_Heap
|
|
||||||
m_Heap[kSmallest] = node++;
|
|
||||||
DownHeap(kSmallest);
|
|
||||||
|
|
||||||
}
|
|
||||||
while (m_HeapLength >= 2);
|
|
||||||
|
|
||||||
m_Heap[--heapMax] = m_Heap[kSmallest];
|
|
||||||
|
|
||||||
// At this point, the fields freq and dad are set. We can now
|
|
||||||
// generate the bit lengths.
|
|
||||||
GenerateBitLen(maxCode, heapMax);
|
|
||||||
|
|
||||||
// The field len is now set, we can generate the bit codes
|
|
||||||
GenerateCodes (maxCode);
|
|
||||||
|
|
||||||
for (n = 0; n < m_NumSymbols; n++)
|
|
||||||
levels[n] = Byte(m_Items[n].Len);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CEncoder::ReverseBits()
|
|
||||||
{
|
|
||||||
for (UInt32 symbol = 0; symbol < m_NumSymbols; symbol++)
|
|
||||||
{
|
|
||||||
CItem &item = m_Items[symbol];
|
|
||||||
UInt32 value = item.Code;
|
|
||||||
UInt32 reverseValue = 0;
|
|
||||||
for(UInt32 i = item.Len; i != 0; i--, value >>= 1)
|
|
||||||
reverseValue = (reverseValue << 1) | (value & 1);
|
|
||||||
item.Code = reverseValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}}
|
|
||||||
@@ -1,82 +0,0 @@
|
|||||||
// Compression/HuffmanEncoder.h
|
|
||||||
|
|
||||||
#ifndef __COMPRESSION_HUFFMANENCODER_H
|
|
||||||
#define __COMPRESSION_HUFFMANENCODER_H
|
|
||||||
|
|
||||||
#include "../../../Common/Types.h"
|
|
||||||
|
|
||||||
namespace NCompression {
|
|
||||||
namespace NHuffman {
|
|
||||||
|
|
||||||
const int kNumBitsInLongestCode = 20;
|
|
||||||
|
|
||||||
struct CItem
|
|
||||||
{
|
|
||||||
UInt32 Freq;
|
|
||||||
UInt32 Code;
|
|
||||||
UInt32 Dad;
|
|
||||||
UInt32 Len;
|
|
||||||
};
|
|
||||||
|
|
||||||
class CEncoder
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
UInt32 m_NumSymbols; // number of symbols in adwSymbol
|
|
||||||
|
|
||||||
CItem *m_Items;
|
|
||||||
UInt32 *m_Heap;
|
|
||||||
UInt32 m_HeapSize;
|
|
||||||
Byte *m_Depth;
|
|
||||||
const Byte *m_ExtraBits;
|
|
||||||
UInt32 m_ExtraBase;
|
|
||||||
UInt32 m_MaxLength;
|
|
||||||
|
|
||||||
UInt32 m_HeapLength;
|
|
||||||
UInt32 m_BitLenCounters[kNumBitsInLongestCode + 1];
|
|
||||||
|
|
||||||
UInt32 RemoveSmallest();
|
|
||||||
bool Smaller(int n, int m);
|
|
||||||
void DownHeap(UInt32 k);
|
|
||||||
void GenerateBitLen(UInt32 maxCode, UInt32 heapMax);
|
|
||||||
void GenerateCodes(UInt32 maxCode);
|
|
||||||
|
|
||||||
UInt32 m_BlockBitLength;
|
|
||||||
|
|
||||||
void Free();
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
CEncoder();
|
|
||||||
~CEncoder();
|
|
||||||
bool Create(UInt32 numSymbols, const Byte *extraBits,
|
|
||||||
UInt32 extraBase, UInt32 maxLength);
|
|
||||||
void StartNewBlock();
|
|
||||||
|
|
||||||
void AddSymbol(UInt32 symbol) { m_Items[symbol].Freq++; }
|
|
||||||
|
|
||||||
UInt32 GetPrice(const Byte *length) const
|
|
||||||
{
|
|
||||||
UInt32 price = 0;
|
|
||||||
for (UInt32 i = 0; i < m_NumSymbols; i++)
|
|
||||||
{
|
|
||||||
price += length[i] * m_Items[i].Freq;
|
|
||||||
if (m_ExtraBits && i >= m_ExtraBase)
|
|
||||||
price += m_ExtraBits[i - m_ExtraBase] * m_Items[i].Freq;
|
|
||||||
}
|
|
||||||
return price;
|
|
||||||
};
|
|
||||||
void SetFreq(UInt32 symbol, UInt32 value) { m_Items[symbol].Freq = value; };
|
|
||||||
|
|
||||||
void BuildTree(Byte *levels);
|
|
||||||
UInt32 GetBlockBitLength() const { return m_BlockBitLength; }
|
|
||||||
|
|
||||||
template <class TBitEncoder>
|
|
||||||
void CodeOneValue(TBitEncoder *bitEncoder, UInt32 symbol)
|
|
||||||
{ bitEncoder->WriteBits(m_Items[symbol].Code, m_Items[symbol].Len); }
|
|
||||||
|
|
||||||
void ReverseBits();
|
|
||||||
};
|
|
||||||
|
|
||||||
}}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
// BinTree.h
|
|
||||||
|
|
||||||
#include "../LZInWindow.h"
|
|
||||||
#include "../IMatchFinder.h"
|
|
||||||
|
|
||||||
namespace BT_NAMESPACE {
|
|
||||||
|
|
||||||
typedef UInt32 CIndex;
|
|
||||||
const UInt32 kMaxValForNormalize = (UInt32(1) << 31) - 1;
|
|
||||||
|
|
||||||
class CMatchFinder:
|
|
||||||
public IMatchFinder,
|
|
||||||
public CLZInWindow,
|
|
||||||
public CMyUnknownImp,
|
|
||||||
public IMatchFinderSetNumPasses
|
|
||||||
{
|
|
||||||
UInt32 _cyclicBufferPos;
|
|
||||||
UInt32 _cyclicBufferSize; // it must be historySize + 1
|
|
||||||
UInt32 _matchMaxLen;
|
|
||||||
CIndex *_hash;
|
|
||||||
CIndex *_son;
|
|
||||||
UInt32 _hashMask;
|
|
||||||
UInt32 _cutValue;
|
|
||||||
UInt32 _hashSizeSum;
|
|
||||||
|
|
||||||
void Normalize();
|
|
||||||
void FreeThisClassMemory();
|
|
||||||
void FreeMemory();
|
|
||||||
|
|
||||||
MY_UNKNOWN_IMP
|
|
||||||
|
|
||||||
STDMETHOD(SetStream)(ISequentialInStream *inStream);
|
|
||||||
STDMETHOD_(void, ReleaseStream)();
|
|
||||||
STDMETHOD(Init)();
|
|
||||||
HRESULT MovePos();
|
|
||||||
STDMETHOD_(Byte, GetIndexByte)(Int32 index);
|
|
||||||
STDMETHOD_(UInt32, GetMatchLen)(Int32 index, UInt32 back, UInt32 limit);
|
|
||||||
STDMETHOD_(UInt32, GetNumAvailableBytes)();
|
|
||||||
STDMETHOD_(const Byte *, GetPointerToCurrentPos)();
|
|
||||||
STDMETHOD_(Int32, NeedChangeBufferPos)(UInt32 numCheckBytes);
|
|
||||||
STDMETHOD_(void, ChangeBufferPos)();
|
|
||||||
|
|
||||||
STDMETHOD(Create)(UInt32 historySize, UInt32 keepAddBufferBefore,
|
|
||||||
UInt32 matchMaxLen, UInt32 keepAddBufferAfter);
|
|
||||||
STDMETHOD(GetMatches)(UInt32 *distances);
|
|
||||||
STDMETHOD(Skip)(UInt32 num);
|
|
||||||
|
|
||||||
public:
|
|
||||||
CMatchFinder();
|
|
||||||
virtual ~CMatchFinder();
|
|
||||||
virtual void SetNumPasses(UInt32 numPasses) { _cutValue = numPasses; }
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
// BinTree2.h
|
|
||||||
|
|
||||||
#ifndef __BINTREE2_H
|
|
||||||
#define __BINTREE2_H
|
|
||||||
|
|
||||||
#define BT_NAMESPACE NBT2
|
|
||||||
|
|
||||||
#include "BinTreeMain.h"
|
|
||||||
|
|
||||||
#undef BT_NAMESPACE
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
// BinTree3.h
|
|
||||||
|
|
||||||
#ifndef __BINTREE3_H
|
|
||||||
#define __BINTREE3_H
|
|
||||||
|
|
||||||
#define BT_NAMESPACE NBT3
|
|
||||||
|
|
||||||
#define HASH_ARRAY_2
|
|
||||||
|
|
||||||
#include "BinTreeMain.h"
|
|
||||||
|
|
||||||
#undef HASH_ARRAY_2
|
|
||||||
|
|
||||||
#undef BT_NAMESPACE
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
// BinTree3Z.h
|
|
||||||
|
|
||||||
#ifndef __BINTREE3Z_H
|
|
||||||
#define __BINTREE3Z_H
|
|
||||||
|
|
||||||
#define BT_NAMESPACE NBT3Z
|
|
||||||
|
|
||||||
#define HASH_ZIP
|
|
||||||
|
|
||||||
#include "BinTreeMain.h"
|
|
||||||
|
|
||||||
#undef HASH_ZIP
|
|
||||||
|
|
||||||
#undef BT_NAMESPACE
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
// BinTree4.h
|
|
||||||
|
|
||||||
#ifndef __BINTREE4_H
|
|
||||||
#define __BINTREE4_H
|
|
||||||
|
|
||||||
#define BT_NAMESPACE NBT4
|
|
||||||
|
|
||||||
#define HASH_ARRAY_2
|
|
||||||
#define HASH_ARRAY_3
|
|
||||||
|
|
||||||
#include "BinTreeMain.h"
|
|
||||||
|
|
||||||
#undef HASH_ARRAY_2
|
|
||||||
#undef HASH_ARRAY_3
|
|
||||||
|
|
||||||
#undef BT_NAMESPACE
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,531 +0,0 @@
|
|||||||
// BinTreeMain.h
|
|
||||||
|
|
||||||
#include "../../../../Common/Defs.h"
|
|
||||||
#include "../../../../Common/CRC.h"
|
|
||||||
#include "../../../../Common/Alloc.h"
|
|
||||||
|
|
||||||
#include "BinTree.h"
|
|
||||||
|
|
||||||
// #include <xmmintrin.h>
|
|
||||||
// It's for prefetch
|
|
||||||
// But prefetch doesn't give big gain in K8.
|
|
||||||
|
|
||||||
namespace BT_NAMESPACE {
|
|
||||||
|
|
||||||
#ifdef HASH_ARRAY_2
|
|
||||||
static const UInt32 kHash2Size = 1 << 10;
|
|
||||||
#define kNumHashDirectBytes 0
|
|
||||||
#ifdef HASH_ARRAY_3
|
|
||||||
static const UInt32 kNumHashBytes = 4;
|
|
||||||
static const UInt32 kHash3Size = 1 << 16;
|
|
||||||
#else
|
|
||||||
static const UInt32 kNumHashBytes = 3;
|
|
||||||
#endif
|
|
||||||
static const UInt32 kHashSize = 0;
|
|
||||||
static const UInt32 kMinMatchCheck = kNumHashBytes;
|
|
||||||
static const UInt32 kStartMaxLen = 1;
|
|
||||||
#else
|
|
||||||
#ifdef HASH_ZIP
|
|
||||||
#define kNumHashDirectBytes 0
|
|
||||||
static const UInt32 kNumHashBytes = 3;
|
|
||||||
static const UInt32 kHashSize = 1 << 16;
|
|
||||||
static const UInt32 kMinMatchCheck = kNumHashBytes;
|
|
||||||
static const UInt32 kStartMaxLen = 1;
|
|
||||||
#else
|
|
||||||
#define kNumHashDirectBytes 2
|
|
||||||
static const UInt32 kNumHashBytes = 2;
|
|
||||||
static const UInt32 kHashSize = 1 << (8 * kNumHashBytes);
|
|
||||||
static const UInt32 kMinMatchCheck = kNumHashBytes + 1;
|
|
||||||
static const UInt32 kStartMaxLen = 1;
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef HASH_ARRAY_2
|
|
||||||
#ifdef HASH_ARRAY_3
|
|
||||||
static const UInt32 kHash3Offset = kHash2Size;
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static const UInt32 kFixHashSize = 0
|
|
||||||
#ifdef HASH_ARRAY_2
|
|
||||||
+ kHash2Size
|
|
||||||
#ifdef HASH_ARRAY_3
|
|
||||||
+ kHash3Size
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
;
|
|
||||||
|
|
||||||
CMatchFinder::CMatchFinder():
|
|
||||||
_hash(0)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void CMatchFinder::FreeThisClassMemory()
|
|
||||||
{
|
|
||||||
BigFree(_hash);
|
|
||||||
_hash = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CMatchFinder::FreeMemory()
|
|
||||||
{
|
|
||||||
FreeThisClassMemory();
|
|
||||||
CLZInWindow::Free();
|
|
||||||
}
|
|
||||||
|
|
||||||
CMatchFinder::~CMatchFinder()
|
|
||||||
{
|
|
||||||
FreeMemory();
|
|
||||||
}
|
|
||||||
|
|
||||||
STDMETHODIMP CMatchFinder::Create(UInt32 historySize, UInt32 keepAddBufferBefore,
|
|
||||||
UInt32 matchMaxLen, UInt32 keepAddBufferAfter)
|
|
||||||
{
|
|
||||||
if (historySize > kMaxValForNormalize - 256)
|
|
||||||
{
|
|
||||||
FreeMemory();
|
|
||||||
return E_INVALIDARG;
|
|
||||||
}
|
|
||||||
_cutValue =
|
|
||||||
#ifdef _HASH_CHAIN
|
|
||||||
8 + (matchMaxLen >> 2);
|
|
||||||
#else
|
|
||||||
16 + (matchMaxLen >> 1);
|
|
||||||
#endif
|
|
||||||
UInt32 sizeReserv = (historySize + keepAddBufferBefore +
|
|
||||||
matchMaxLen + keepAddBufferAfter) / 2 + 256;
|
|
||||||
if (CLZInWindow::Create(historySize + keepAddBufferBefore,
|
|
||||||
matchMaxLen + keepAddBufferAfter, sizeReserv))
|
|
||||||
{
|
|
||||||
_matchMaxLen = matchMaxLen;
|
|
||||||
UInt32 newCyclicBufferSize = historySize + 1;
|
|
||||||
if (_hash != 0 && newCyclicBufferSize == _cyclicBufferSize)
|
|
||||||
return S_OK;
|
|
||||||
FreeThisClassMemory();
|
|
||||||
_cyclicBufferSize = newCyclicBufferSize; // don't change it
|
|
||||||
|
|
||||||
UInt32 hs = kHashSize;
|
|
||||||
|
|
||||||
#ifdef HASH_ARRAY_2
|
|
||||||
hs = historySize - 1;
|
|
||||||
hs |= (hs >> 1);
|
|
||||||
hs |= (hs >> 2);
|
|
||||||
hs |= (hs >> 4);
|
|
||||||
hs |= (hs >> 8);
|
|
||||||
hs >>= 1;
|
|
||||||
hs |= 0xFFFF;
|
|
||||||
if (hs > (1 << 24))
|
|
||||||
{
|
|
||||||
#ifdef HASH_ARRAY_3
|
|
||||||
hs >>= 1;
|
|
||||||
#else
|
|
||||||
hs = (1 << 24) - 1;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
_hashMask = hs;
|
|
||||||
hs++;
|
|
||||||
#endif
|
|
||||||
_hashSizeSum = hs + kFixHashSize;
|
|
||||||
UInt32 numItems = _hashSizeSum + _cyclicBufferSize
|
|
||||||
#ifndef _HASH_CHAIN
|
|
||||||
* 2
|
|
||||||
#endif
|
|
||||||
;
|
|
||||||
size_t sizeInBytes = (size_t)numItems * sizeof(CIndex);
|
|
||||||
if (sizeInBytes / sizeof(CIndex) != numItems)
|
|
||||||
return E_OUTOFMEMORY;
|
|
||||||
_hash = (CIndex *)BigAlloc(sizeInBytes);
|
|
||||||
_son = _hash + _hashSizeSum;
|
|
||||||
if (_hash != 0)
|
|
||||||
return S_OK;
|
|
||||||
}
|
|
||||||
FreeMemory();
|
|
||||||
return E_OUTOFMEMORY;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const UInt32 kEmptyHashValue = 0;
|
|
||||||
|
|
||||||
STDMETHODIMP CMatchFinder::SetStream(ISequentialInStream *stream)
|
|
||||||
{
|
|
||||||
CLZInWindow::SetStream(stream);
|
|
||||||
return S_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
STDMETHODIMP CMatchFinder::Init()
|
|
||||||
{
|
|
||||||
RINOK(CLZInWindow::Init());
|
|
||||||
for(UInt32 i = 0; i < _hashSizeSum; i++)
|
|
||||||
_hash[i] = kEmptyHashValue;
|
|
||||||
_cyclicBufferPos = 0;
|
|
||||||
ReduceOffsets(-1);
|
|
||||||
return S_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
STDMETHODIMP_(void) CMatchFinder::ReleaseStream()
|
|
||||||
{
|
|
||||||
// ReleaseStream();
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef HASH_ARRAY_2
|
|
||||||
#ifdef HASH_ARRAY_3
|
|
||||||
|
|
||||||
#define HASH_CALC { \
|
|
||||||
UInt32 temp = CCRC::Table[cur[0]] ^ cur[1]; \
|
|
||||||
hash2Value = temp & (kHash2Size - 1); \
|
|
||||||
hash3Value = (temp ^ (UInt32(cur[2]) << 8)) & (kHash3Size - 1); \
|
|
||||||
hashValue = (temp ^ (UInt32(cur[2]) << 8) ^ (CCRC::Table[cur[3]] << 5)) & _hashMask; }
|
|
||||||
|
|
||||||
#else // no HASH_ARRAY_3
|
|
||||||
#define HASH_CALC { \
|
|
||||||
UInt32 temp = CCRC::Table[cur[0]] ^ cur[1]; \
|
|
||||||
hash2Value = temp & (kHash2Size - 1); \
|
|
||||||
hashValue = (temp ^ (UInt32(cur[2]) << 8)) & _hashMask; }
|
|
||||||
#endif // HASH_ARRAY_3
|
|
||||||
#else // no HASH_ARRAY_2
|
|
||||||
#ifdef HASH_ZIP
|
|
||||||
inline UInt32 Hash(const Byte *pointer)
|
|
||||||
{
|
|
||||||
return ((UInt32(pointer[0]) << 8) ^ CCRC::Table[pointer[1]] ^ pointer[2]) & (kHashSize - 1);
|
|
||||||
}
|
|
||||||
#else // no HASH_ZIP
|
|
||||||
inline UInt32 Hash(const Byte *pointer)
|
|
||||||
{
|
|
||||||
return pointer[0] ^ (UInt32(pointer[1]) << 8);
|
|
||||||
}
|
|
||||||
#endif // HASH_ZIP
|
|
||||||
#endif // HASH_ARRAY_2
|
|
||||||
|
|
||||||
STDMETHODIMP CMatchFinder::GetMatches(UInt32 *distances)
|
|
||||||
{
|
|
||||||
UInt32 lenLimit;
|
|
||||||
if (_pos + _matchMaxLen <= _streamPos)
|
|
||||||
lenLimit = _matchMaxLen;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
lenLimit = _streamPos - _pos;
|
|
||||||
if(lenLimit < kMinMatchCheck)
|
|
||||||
{
|
|
||||||
distances[0] = 0;
|
|
||||||
return MovePos();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int offset = 1;
|
|
||||||
|
|
||||||
UInt32 matchMinPos = (_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0;
|
|
||||||
const Byte *cur = _buffer + _pos;
|
|
||||||
|
|
||||||
UInt32 maxLen = kStartMaxLen; // to avoid items for len < hashSize;
|
|
||||||
|
|
||||||
#ifdef HASH_ARRAY_2
|
|
||||||
UInt32 hash2Value;
|
|
||||||
#ifdef HASH_ARRAY_3
|
|
||||||
UInt32 hash3Value;
|
|
||||||
#endif
|
|
||||||
UInt32 hashValue;
|
|
||||||
HASH_CALC;
|
|
||||||
#else
|
|
||||||
UInt32 hashValue = Hash(cur);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
UInt32 curMatch = _hash[kFixHashSize + hashValue];
|
|
||||||
#ifdef HASH_ARRAY_2
|
|
||||||
UInt32 curMatch2 = _hash[hash2Value];
|
|
||||||
#ifdef HASH_ARRAY_3
|
|
||||||
UInt32 curMatch3 = _hash[kHash3Offset + hash3Value];
|
|
||||||
#endif
|
|
||||||
_hash[hash2Value] = _pos;
|
|
||||||
if(curMatch2 > matchMinPos)
|
|
||||||
if (_buffer[curMatch2] == cur[0])
|
|
||||||
{
|
|
||||||
distances[offset++] = maxLen = 2;
|
|
||||||
distances[offset++] = _pos - curMatch2 - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef HASH_ARRAY_3
|
|
||||||
_hash[kHash3Offset + hash3Value] = _pos;
|
|
||||||
if(curMatch3 > matchMinPos)
|
|
||||||
if (_buffer[curMatch3] == cur[0])
|
|
||||||
{
|
|
||||||
if (curMatch3 == curMatch2)
|
|
||||||
offset -= 2;
|
|
||||||
distances[offset++] = maxLen = 3;
|
|
||||||
distances[offset++] = _pos - curMatch3 - 1;
|
|
||||||
curMatch2 = curMatch3;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
if (offset != 1 && curMatch2 == curMatch)
|
|
||||||
{
|
|
||||||
offset -= 2;
|
|
||||||
maxLen = kStartMaxLen;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
_hash[kFixHashSize + hashValue] = _pos;
|
|
||||||
|
|
||||||
CIndex *son = _son;
|
|
||||||
|
|
||||||
#ifdef _HASH_CHAIN
|
|
||||||
son[_cyclicBufferPos] = curMatch;
|
|
||||||
#else
|
|
||||||
CIndex *ptr0 = son + (_cyclicBufferPos << 1) + 1;
|
|
||||||
CIndex *ptr1 = son + (_cyclicBufferPos << 1);
|
|
||||||
|
|
||||||
UInt32 len0, len1;
|
|
||||||
len0 = len1 = kNumHashDirectBytes;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if kNumHashDirectBytes != 0
|
|
||||||
if(curMatch > matchMinPos)
|
|
||||||
{
|
|
||||||
if (_buffer[curMatch + kNumHashDirectBytes] != cur[kNumHashDirectBytes])
|
|
||||||
{
|
|
||||||
distances[offset++] = maxLen = kNumHashDirectBytes;
|
|
||||||
distances[offset++] = _pos - curMatch - 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
UInt32 count = _cutValue;
|
|
||||||
for (;;)
|
|
||||||
{
|
|
||||||
if(curMatch <= matchMinPos || count-- == 0)
|
|
||||||
{
|
|
||||||
#ifndef _HASH_CHAIN
|
|
||||||
*ptr0 = *ptr1 = kEmptyHashValue;
|
|
||||||
#endif
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
UInt32 delta = _pos - curMatch;
|
|
||||||
UInt32 cyclicPos = (delta <= _cyclicBufferPos) ?
|
|
||||||
(_cyclicBufferPos - delta):
|
|
||||||
(_cyclicBufferPos - delta + _cyclicBufferSize);
|
|
||||||
CIndex *pair = son +
|
|
||||||
#ifdef _HASH_CHAIN
|
|
||||||
cyclicPos;
|
|
||||||
#else
|
|
||||||
(cyclicPos << 1);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// _mm_prefetch((const char *)pair, _MM_HINT_T0);
|
|
||||||
|
|
||||||
const Byte *pb = _buffer + curMatch;
|
|
||||||
UInt32 len =
|
|
||||||
#ifdef _HASH_CHAIN
|
|
||||||
kNumHashDirectBytes;
|
|
||||||
if (pb[maxLen] == cur[maxLen])
|
|
||||||
#else
|
|
||||||
MyMin(len0, len1);
|
|
||||||
#endif
|
|
||||||
if (pb[len] == cur[len])
|
|
||||||
{
|
|
||||||
while(++len != lenLimit)
|
|
||||||
if (pb[len] != cur[len])
|
|
||||||
break;
|
|
||||||
if (maxLen < len)
|
|
||||||
{
|
|
||||||
distances[offset++] = maxLen = len;
|
|
||||||
distances[offset++] = delta - 1;
|
|
||||||
if (len == lenLimit)
|
|
||||||
{
|
|
||||||
#ifndef _HASH_CHAIN
|
|
||||||
*ptr1 = pair[0];
|
|
||||||
*ptr0 = pair[1];
|
|
||||||
#endif
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#ifdef _HASH_CHAIN
|
|
||||||
curMatch = *pair;
|
|
||||||
#else
|
|
||||||
if (pb[len] < cur[len])
|
|
||||||
{
|
|
||||||
*ptr1 = curMatch;
|
|
||||||
ptr1 = pair + 1;
|
|
||||||
curMatch = *ptr1;
|
|
||||||
len1 = len;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
*ptr0 = curMatch;
|
|
||||||
ptr0 = pair;
|
|
||||||
curMatch = *ptr0;
|
|
||||||
len0 = len;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
distances[0] = offset - 1;
|
|
||||||
if (++_cyclicBufferPos == _cyclicBufferSize)
|
|
||||||
_cyclicBufferPos = 0;
|
|
||||||
RINOK(CLZInWindow::MovePos());
|
|
||||||
if (_pos == kMaxValForNormalize)
|
|
||||||
Normalize();
|
|
||||||
return S_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
STDMETHODIMP CMatchFinder::Skip(UInt32 num)
|
|
||||||
{
|
|
||||||
do
|
|
||||||
{
|
|
||||||
#ifdef _HASH_CHAIN
|
|
||||||
if (_streamPos - _pos < kNumHashBytes)
|
|
||||||
{
|
|
||||||
RINOK(MovePos());
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
UInt32 lenLimit;
|
|
||||||
if (_pos + _matchMaxLen <= _streamPos)
|
|
||||||
lenLimit = _matchMaxLen;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
lenLimit = _streamPos - _pos;
|
|
||||||
if(lenLimit < kMinMatchCheck)
|
|
||||||
{
|
|
||||||
RINOK(MovePos());
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
UInt32 matchMinPos = (_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0;
|
|
||||||
#endif
|
|
||||||
const Byte *cur = _buffer + _pos;
|
|
||||||
|
|
||||||
#ifdef HASH_ARRAY_2
|
|
||||||
UInt32 hash2Value;
|
|
||||||
#ifdef HASH_ARRAY_3
|
|
||||||
UInt32 hash3Value;
|
|
||||||
UInt32 hashValue;
|
|
||||||
HASH_CALC;
|
|
||||||
_hash[kHash3Offset + hash3Value] = _pos;
|
|
||||||
#else
|
|
||||||
UInt32 hashValue;
|
|
||||||
HASH_CALC;
|
|
||||||
#endif
|
|
||||||
_hash[hash2Value] = _pos;
|
|
||||||
#else
|
|
||||||
UInt32 hashValue = Hash(cur);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
UInt32 curMatch = _hash[kFixHashSize + hashValue];
|
|
||||||
_hash[kFixHashSize + hashValue] = _pos;
|
|
||||||
|
|
||||||
#ifdef _HASH_CHAIN
|
|
||||||
_son[_cyclicBufferPos] = curMatch;
|
|
||||||
#else
|
|
||||||
CIndex *son = _son;
|
|
||||||
CIndex *ptr0 = son + (_cyclicBufferPos << 1) + 1;
|
|
||||||
CIndex *ptr1 = son + (_cyclicBufferPos << 1);
|
|
||||||
|
|
||||||
UInt32 len0, len1;
|
|
||||||
len0 = len1 = kNumHashDirectBytes;
|
|
||||||
UInt32 count = _cutValue;
|
|
||||||
for (;;)
|
|
||||||
{
|
|
||||||
if(curMatch <= matchMinPos || count-- == 0)
|
|
||||||
{
|
|
||||||
*ptr0 = *ptr1 = kEmptyHashValue;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
UInt32 delta = _pos - curMatch;
|
|
||||||
UInt32 cyclicPos = (delta <= _cyclicBufferPos) ?
|
|
||||||
(_cyclicBufferPos - delta):
|
|
||||||
(_cyclicBufferPos - delta + _cyclicBufferSize);
|
|
||||||
CIndex *pair = son + (cyclicPos << 1);
|
|
||||||
|
|
||||||
// _mm_prefetch((const char *)pair, _MM_HINT_T0);
|
|
||||||
|
|
||||||
const Byte *pb = _buffer + curMatch;
|
|
||||||
UInt32 len = MyMin(len0, len1);
|
|
||||||
|
|
||||||
if (pb[len] == cur[len])
|
|
||||||
{
|
|
||||||
while(++len != lenLimit)
|
|
||||||
if (pb[len] != cur[len])
|
|
||||||
break;
|
|
||||||
if (len == lenLimit)
|
|
||||||
{
|
|
||||||
*ptr1 = pair[0];
|
|
||||||
*ptr0 = pair[1];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (pb[len] < cur[len])
|
|
||||||
{
|
|
||||||
*ptr1 = curMatch;
|
|
||||||
ptr1 = pair + 1;
|
|
||||||
curMatch = *ptr1;
|
|
||||||
len1 = len;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
*ptr0 = curMatch;
|
|
||||||
ptr0 = pair;
|
|
||||||
curMatch = *ptr0;
|
|
||||||
len0 = len;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
if (++_cyclicBufferPos == _cyclicBufferSize)
|
|
||||||
_cyclicBufferPos = 0;
|
|
||||||
RINOK(CLZInWindow::MovePos());
|
|
||||||
if (_pos == kMaxValForNormalize)
|
|
||||||
Normalize();
|
|
||||||
}
|
|
||||||
while(--num != 0);
|
|
||||||
return S_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CMatchFinder::Normalize()
|
|
||||||
{
|
|
||||||
UInt32 subValue = _pos - _cyclicBufferSize;
|
|
||||||
CIndex *items = _hash;
|
|
||||||
UInt32 numItems = (_hashSizeSum + _cyclicBufferSize
|
|
||||||
#ifndef _HASH_CHAIN
|
|
||||||
* 2
|
|
||||||
#endif
|
|
||||||
);
|
|
||||||
for (UInt32 i = 0; i < numItems; i++)
|
|
||||||
{
|
|
||||||
UInt32 value = items[i];
|
|
||||||
if (value <= subValue)
|
|
||||||
value = kEmptyHashValue;
|
|
||||||
else
|
|
||||||
value -= subValue;
|
|
||||||
items[i] = value;
|
|
||||||
}
|
|
||||||
ReduceOffsets(subValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
HRESULT CMatchFinder::MovePos()
|
|
||||||
{
|
|
||||||
if (++_cyclicBufferPos == _cyclicBufferSize)
|
|
||||||
_cyclicBufferPos = 0;
|
|
||||||
RINOK(CLZInWindow::MovePos());
|
|
||||||
if (_pos == kMaxValForNormalize)
|
|
||||||
Normalize();
|
|
||||||
return S_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
STDMETHODIMP_(Byte) CMatchFinder::GetIndexByte(Int32 index)
|
|
||||||
{ return CLZInWindow::GetIndexByte(index); }
|
|
||||||
|
|
||||||
STDMETHODIMP_(UInt32) CMatchFinder::GetMatchLen(Int32 index,
|
|
||||||
UInt32 back, UInt32 limit)
|
|
||||||
{ return CLZInWindow::GetMatchLen(index, back, limit); }
|
|
||||||
|
|
||||||
STDMETHODIMP_(UInt32) CMatchFinder::GetNumAvailableBytes()
|
|
||||||
{ return CLZInWindow::GetNumAvailableBytes(); }
|
|
||||||
|
|
||||||
STDMETHODIMP_(const Byte *) CMatchFinder::GetPointerToCurrentPos()
|
|
||||||
{ return CLZInWindow::GetPointerToCurrentPos(); }
|
|
||||||
|
|
||||||
STDMETHODIMP_(Int32) CMatchFinder::NeedChangeBufferPos(UInt32 numCheckBytes)
|
|
||||||
{ return CLZInWindow::NeedMove(numCheckBytes) ? 1: 0; }
|
|
||||||
|
|
||||||
STDMETHODIMP_(void) CMatchFinder::ChangeBufferPos()
|
|
||||||
{ CLZInWindow::MoveBlock();}
|
|
||||||
|
|
||||||
#undef HASH_CALC
|
|
||||||
#undef kNumHashDirectBytes
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
// HC2.h
|
|
||||||
|
|
||||||
#ifndef __HC2_H
|
|
||||||
#define __HC2_H
|
|
||||||
|
|
||||||
#define BT_NAMESPACE NHC2
|
|
||||||
|
|
||||||
#include "HCMain.h"
|
|
||||||
|
|
||||||
#undef BT_NAMESPACE
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
// HC3.h
|
|
||||||
|
|
||||||
#ifndef __HC3_H
|
|
||||||
#define __HC3_H
|
|
||||||
|
|
||||||
#define BT_NAMESPACE NHC3
|
|
||||||
|
|
||||||
#define HASH_ARRAY_2
|
|
||||||
|
|
||||||
#include "HCMain.h"
|
|
||||||
|
|
||||||
#undef HASH_ARRAY_2
|
|
||||||
#undef BT_NAMESPACE
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
// HC4.h
|
|
||||||
|
|
||||||
#ifndef __HC4_H
|
|
||||||
#define __HC4_H
|
|
||||||
|
|
||||||
#define BT_NAMESPACE NHC4
|
|
||||||
|
|
||||||
#define HASH_ARRAY_2
|
|
||||||
#define HASH_ARRAY_3
|
|
||||||
|
|
||||||
#include "HCMain.h"
|
|
||||||
|
|
||||||
#undef HASH_ARRAY_2
|
|
||||||
#undef HASH_ARRAY_3
|
|
||||||
|
|
||||||
#undef BT_NAMESPACE
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
// HCMain.h
|
|
||||||
|
|
||||||
#define _HASH_CHAIN
|
|
||||||
#include "../BinTree/BinTreeMain.h"
|
|
||||||
#undef _HASH_CHAIN
|
|
||||||
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
// MatchFinders/IMatchFinder.h
|
|
||||||
|
|
||||||
#ifndef __IMATCHFINDER_H
|
|
||||||
#define __IMATCHFINDER_H
|
|
||||||
|
|
||||||
struct IInWindowStream: public IUnknown
|
|
||||||
{
|
|
||||||
STDMETHOD(SetStream)(ISequentialInStream *inStream) PURE;
|
|
||||||
STDMETHOD_(void, ReleaseStream)() PURE;
|
|
||||||
STDMETHOD(Init)() PURE;
|
|
||||||
STDMETHOD_(Byte, GetIndexByte)(Int32 index) PURE;
|
|
||||||
STDMETHOD_(UInt32, GetMatchLen)(Int32 index, UInt32 distance, UInt32 limit) PURE;
|
|
||||||
STDMETHOD_(UInt32, GetNumAvailableBytes)() PURE;
|
|
||||||
STDMETHOD_(const Byte *, GetPointerToCurrentPos)() PURE;
|
|
||||||
STDMETHOD_(Int32, NeedChangeBufferPos)(UInt32 numCheckBytes) PURE;
|
|
||||||
STDMETHOD_(void, ChangeBufferPos)() PURE;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct IMatchFinder: public IInWindowStream
|
|
||||||
{
|
|
||||||
STDMETHOD(Create)(UInt32 historySize, UInt32 keepAddBufferBefore,
|
|
||||||
UInt32 matchMaxLen, UInt32 keepAddBufferAfter) PURE;
|
|
||||||
STDMETHOD(GetMatches)(UInt32 *distances) PURE;
|
|
||||||
STDMETHOD(Skip)(UInt32 num) PURE;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct IMatchFinderSetNumPasses
|
|
||||||
{
|
|
||||||
virtual void SetNumPasses(UInt32 numPasses) PURE;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,105 +0,0 @@
|
|||||||
// LZInWindow.cpp
|
|
||||||
|
|
||||||
#include "StdAfx.h"
|
|
||||||
|
|
||||||
#include "LZInWindow.h"
|
|
||||||
#include "../../../Common/MyCom.h"
|
|
||||||
#include "../../../Common/Alloc.h"
|
|
||||||
|
|
||||||
void CLZInWindow::Free()
|
|
||||||
{
|
|
||||||
::BigFree(_bufferBase);
|
|
||||||
_bufferBase = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CLZInWindow::Create(UInt32 keepSizeBefore, UInt32 keepSizeAfter, UInt32 keepSizeReserv)
|
|
||||||
{
|
|
||||||
_keepSizeBefore = keepSizeBefore;
|
|
||||||
_keepSizeAfter = keepSizeAfter;
|
|
||||||
UInt32 blockSize = keepSizeBefore + keepSizeAfter + keepSizeReserv;
|
|
||||||
if (_bufferBase == 0 || _blockSize != blockSize)
|
|
||||||
{
|
|
||||||
Free();
|
|
||||||
_blockSize = blockSize;
|
|
||||||
if (_blockSize != 0)
|
|
||||||
_bufferBase = (Byte *)::BigAlloc(_blockSize);
|
|
||||||
}
|
|
||||||
_pointerToLastSafePosition = _bufferBase + _blockSize - keepSizeAfter;
|
|
||||||
if (_blockSize == 0)
|
|
||||||
return true;
|
|
||||||
return (_bufferBase != 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CLZInWindow::SetStream(ISequentialInStream *stream)
|
|
||||||
{
|
|
||||||
_stream = stream;
|
|
||||||
}
|
|
||||||
|
|
||||||
HRESULT CLZInWindow::Init()
|
|
||||||
{
|
|
||||||
_buffer = _bufferBase;
|
|
||||||
_pos = 0;
|
|
||||||
_streamPos = 0;
|
|
||||||
_streamEndWasReached = false;
|
|
||||||
return ReadBlock();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
void CLZInWindow::ReleaseStream()
|
|
||||||
{
|
|
||||||
_stream.Release();
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
///////////////////////////////////////////
|
|
||||||
// ReadBlock
|
|
||||||
|
|
||||||
// In State:
|
|
||||||
// (_buffer + _streamPos) <= (_bufferBase + _blockSize)
|
|
||||||
// Out State:
|
|
||||||
// _posLimit <= _blockSize - _keepSizeAfter;
|
|
||||||
// if(_streamEndWasReached == false):
|
|
||||||
// _streamPos >= _pos + _keepSizeAfter
|
|
||||||
// _posLimit = _streamPos - _keepSizeAfter;
|
|
||||||
// else
|
|
||||||
//
|
|
||||||
|
|
||||||
HRESULT CLZInWindow::ReadBlock()
|
|
||||||
{
|
|
||||||
if(_streamEndWasReached)
|
|
||||||
return S_OK;
|
|
||||||
for (;;)
|
|
||||||
{
|
|
||||||
UInt32 size = (UInt32)(_bufferBase - _buffer) + _blockSize - _streamPos;
|
|
||||||
if(size == 0)
|
|
||||||
return S_OK;
|
|
||||||
UInt32 numReadBytes;
|
|
||||||
RINOK(_stream->Read(_buffer + _streamPos, size, &numReadBytes));
|
|
||||||
if(numReadBytes == 0)
|
|
||||||
{
|
|
||||||
_posLimit = _streamPos;
|
|
||||||
const Byte *pointerToPostion = _buffer + _posLimit;
|
|
||||||
if(pointerToPostion > _pointerToLastSafePosition)
|
|
||||||
_posLimit = (UInt32)(_pointerToLastSafePosition - _buffer);
|
|
||||||
_streamEndWasReached = true;
|
|
||||||
return S_OK;
|
|
||||||
}
|
|
||||||
_streamPos += numReadBytes;
|
|
||||||
if(_streamPos >= _pos + _keepSizeAfter)
|
|
||||||
{
|
|
||||||
_posLimit = _streamPos - _keepSizeAfter;
|
|
||||||
return S_OK;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void CLZInWindow::MoveBlock()
|
|
||||||
{
|
|
||||||
UInt32 offset = (UInt32)(_buffer - _bufferBase) + _pos - _keepSizeBefore;
|
|
||||||
// we need one additional byte, since MovePos moves on 1 byte.
|
|
||||||
if (offset > 0)
|
|
||||||
offset--;
|
|
||||||
UInt32 numBytes = (UInt32)(_buffer - _bufferBase) + _streamPos - offset;
|
|
||||||
memmove(_bufferBase, _bufferBase + offset, numBytes);
|
|
||||||
_buffer -= offset;
|
|
||||||
}
|
|
||||||
@@ -1,87 +0,0 @@
|
|||||||
// LZInWindow.h
|
|
||||||
|
|
||||||
#ifndef __LZ_IN_WINDOW_H
|
|
||||||
#define __LZ_IN_WINDOW_H
|
|
||||||
|
|
||||||
#include "../../IStream.h"
|
|
||||||
|
|
||||||
class CLZInWindow
|
|
||||||
{
|
|
||||||
Byte *_bufferBase; // pointer to buffer with data
|
|
||||||
ISequentialInStream *_stream;
|
|
||||||
UInt32 _posLimit; // offset (from _buffer) when new block reading must be done
|
|
||||||
bool _streamEndWasReached; // if (true) then _streamPos shows real end of stream
|
|
||||||
const Byte *_pointerToLastSafePosition;
|
|
||||||
protected:
|
|
||||||
Byte *_buffer; // Pointer to virtual Buffer begin
|
|
||||||
UInt32 _blockSize; // Size of Allocated memory block
|
|
||||||
UInt32 _pos; // offset (from _buffer) of curent byte
|
|
||||||
UInt32 _keepSizeBefore; // how many BYTEs must be kept in buffer before _pos
|
|
||||||
UInt32 _keepSizeAfter; // how many BYTEs must be kept buffer after _pos
|
|
||||||
UInt32 _streamPos; // offset (from _buffer) of first not read byte from Stream
|
|
||||||
|
|
||||||
void MoveBlock();
|
|
||||||
HRESULT ReadBlock();
|
|
||||||
void Free();
|
|
||||||
public:
|
|
||||||
CLZInWindow(): _bufferBase(0) {}
|
|
||||||
virtual ~CLZInWindow() { Free(); }
|
|
||||||
|
|
||||||
// keepSizeBefore + keepSizeAfter + keepSizeReserv < 4G)
|
|
||||||
bool Create(UInt32 keepSizeBefore, UInt32 keepSizeAfter, UInt32 keepSizeReserv = (1<<17));
|
|
||||||
|
|
||||||
void SetStream(ISequentialInStream *stream);
|
|
||||||
HRESULT Init();
|
|
||||||
// void ReleaseStream();
|
|
||||||
|
|
||||||
Byte *GetBuffer() const { return _buffer; }
|
|
||||||
|
|
||||||
const Byte *GetPointerToCurrentPos() const { return _buffer + _pos; }
|
|
||||||
|
|
||||||
HRESULT MovePos()
|
|
||||||
{
|
|
||||||
_pos++;
|
|
||||||
if (_pos > _posLimit)
|
|
||||||
{
|
|
||||||
const Byte *pointerToPostion = _buffer + _pos;
|
|
||||||
if(pointerToPostion > _pointerToLastSafePosition)
|
|
||||||
MoveBlock();
|
|
||||||
return ReadBlock();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return S_OK;
|
|
||||||
}
|
|
||||||
Byte GetIndexByte(Int32 index) const { return _buffer[(size_t)_pos + index]; }
|
|
||||||
|
|
||||||
// index + limit have not to exceed _keepSizeAfter;
|
|
||||||
// -2G <= index < 2G
|
|
||||||
UInt32 GetMatchLen(Int32 index, UInt32 distance, UInt32 limit) const
|
|
||||||
{
|
|
||||||
if(_streamEndWasReached)
|
|
||||||
if ((_pos + index) + limit > _streamPos)
|
|
||||||
limit = _streamPos - (_pos + index);
|
|
||||||
distance++;
|
|
||||||
const Byte *pby = _buffer + (size_t)_pos + index;
|
|
||||||
UInt32 i;
|
|
||||||
for(i = 0; i < limit && pby[i] == pby[(size_t)i - distance]; i++);
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
UInt32 GetNumAvailableBytes() const { return _streamPos - _pos; }
|
|
||||||
|
|
||||||
void ReduceOffsets(Int32 subValue)
|
|
||||||
{
|
|
||||||
_buffer += subValue;
|
|
||||||
_posLimit -= subValue;
|
|
||||||
_pos -= subValue;
|
|
||||||
_streamPos -= subValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool NeedMove(UInt32 numCheckBytes)
|
|
||||||
{
|
|
||||||
size_t reserv = (size_t)(_pointerToLastSafePosition - (_buffer + _pos));
|
|
||||||
return (reserv <= numCheckBytes);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,295 +0,0 @@
|
|||||||
// MT.cpp
|
|
||||||
|
|
||||||
#include "StdAfx.h"
|
|
||||||
|
|
||||||
#include "../../../../Common/Alloc.h"
|
|
||||||
|
|
||||||
#include "MT.h"
|
|
||||||
|
|
||||||
static const UInt32 kBlockSize = (1 << 14);
|
|
||||||
|
|
||||||
static DWORD WINAPI MFThread(void *threadCoderInfo)
|
|
||||||
{
|
|
||||||
return ((CMatchFinderMT *)threadCoderInfo)->ThreadFunc();
|
|
||||||
}
|
|
||||||
|
|
||||||
CMatchFinderMT::CMatchFinderMT():
|
|
||||||
m_Buffer(0),
|
|
||||||
m_NeedStart(true)
|
|
||||||
{
|
|
||||||
m_BlockIndex = kNumMTBlocks - 1;
|
|
||||||
m_CS[m_BlockIndex].Enter();
|
|
||||||
if (!m_Thread.Create(MFThread, this))
|
|
||||||
throw 271826;
|
|
||||||
}
|
|
||||||
|
|
||||||
CMatchFinderMT::~CMatchFinderMT()
|
|
||||||
{
|
|
||||||
m_Exit = true;
|
|
||||||
m_CS[m_BlockIndex].Leave();
|
|
||||||
m_CanChangeBufferPos.Set();
|
|
||||||
if (m_NeedStart)
|
|
||||||
m_MtCanStart.Set();
|
|
||||||
m_Thread.Wait();
|
|
||||||
FreeMem();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CMatchFinderMT::FreeMem()
|
|
||||||
{
|
|
||||||
::MyFree(m_Buffer);
|
|
||||||
m_Buffer = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
STDMETHODIMP CMatchFinderMT::Create(UInt32 sizeHistory, UInt32 keepAddBufferBefore,
|
|
||||||
UInt32 matchMaxLen, UInt32 keepAddBufferAfter)
|
|
||||||
{
|
|
||||||
FreeMem();
|
|
||||||
m_MatchMaxLen = matchMaxLen;
|
|
||||||
if (kBlockSize <= matchMaxLen * 4)
|
|
||||||
return E_INVALIDARG;
|
|
||||||
UInt32 bufferSize = kBlockSize * kNumMTBlocks;
|
|
||||||
m_Buffer = (UInt32 *)::MyAlloc(bufferSize * sizeof(UInt32));
|
|
||||||
if (m_Buffer == 0)
|
|
||||||
return E_OUTOFMEMORY;
|
|
||||||
keepAddBufferBefore += bufferSize;
|
|
||||||
keepAddBufferAfter += (kBlockSize + 1);
|
|
||||||
return m_MatchFinder->Create(sizeHistory, keepAddBufferBefore, matchMaxLen, keepAddBufferAfter);
|
|
||||||
}
|
|
||||||
|
|
||||||
// UInt32 blockSizeMult = 800
|
|
||||||
HRESULT CMatchFinderMT::SetMatchFinder(IMatchFinder *matchFinder)
|
|
||||||
{
|
|
||||||
m_MatchFinder = matchFinder;
|
|
||||||
return S_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
STDMETHODIMP CMatchFinderMT::SetStream(ISequentialInStream *s)
|
|
||||||
{
|
|
||||||
return m_MatchFinder->SetStream(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Call it after ReleaseStream / SetStream
|
|
||||||
STDMETHODIMP CMatchFinderMT::Init()
|
|
||||||
{
|
|
||||||
m_NeedStart = true;
|
|
||||||
m_Pos = 0;
|
|
||||||
m_PosLimit = 0;
|
|
||||||
|
|
||||||
HRESULT result = m_MatchFinder->Init();
|
|
||||||
if (result == S_OK)
|
|
||||||
m_DataCurrentPos = m_MatchFinder->GetPointerToCurrentPos();
|
|
||||||
m_NumAvailableBytes = m_MatchFinder->GetNumAvailableBytes();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ReleaseStream is required to finish multithreading
|
|
||||||
STDMETHODIMP_(void) CMatchFinderMT::ReleaseStream()
|
|
||||||
{
|
|
||||||
m_StopWriting = true;
|
|
||||||
m_CS[m_BlockIndex].Leave();
|
|
||||||
if (!m_NeedStart)
|
|
||||||
{
|
|
||||||
m_CanChangeBufferPos.Set();
|
|
||||||
m_MtWasStopped.Lock();
|
|
||||||
m_NeedStart = true;
|
|
||||||
}
|
|
||||||
m_MatchFinder->ReleaseStream();
|
|
||||||
m_BlockIndex = kNumMTBlocks - 1;
|
|
||||||
m_CS[m_BlockIndex].Enter();
|
|
||||||
}
|
|
||||||
|
|
||||||
STDMETHODIMP_(Byte) CMatchFinderMT::GetIndexByte(Int32 index)
|
|
||||||
{
|
|
||||||
return m_DataCurrentPos[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
STDMETHODIMP_(UInt32) CMatchFinderMT::GetMatchLen(Int32 index, UInt32 distance, UInt32 limit)
|
|
||||||
{
|
|
||||||
if ((Int32)(index + limit) > m_NumAvailableBytes)
|
|
||||||
limit = m_NumAvailableBytes - (index);
|
|
||||||
distance++;
|
|
||||||
const Byte *pby = m_DataCurrentPos + index;
|
|
||||||
UInt32 i;
|
|
||||||
for(i = 0; i < limit && pby[i] == pby[(size_t)i - distance]; i++);
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
STDMETHODIMP_(const Byte *) CMatchFinderMT::GetPointerToCurrentPos()
|
|
||||||
{
|
|
||||||
return m_DataCurrentPos;
|
|
||||||
}
|
|
||||||
|
|
||||||
STDMETHODIMP_(UInt32) CMatchFinderMT::GetNumAvailableBytes()
|
|
||||||
{
|
|
||||||
return m_NumAvailableBytes;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CMatchFinderMT::GetNextBlock()
|
|
||||||
{
|
|
||||||
if (m_NeedStart)
|
|
||||||
{
|
|
||||||
m_NeedStart = false;
|
|
||||||
for (UInt32 i = 0; i < kNumMTBlocks; i++)
|
|
||||||
m_StopReading[i] = false;
|
|
||||||
m_StopWriting = false;
|
|
||||||
m_Exit = false;
|
|
||||||
m_MtWasStarted.Reset();
|
|
||||||
m_MtWasStopped.Reset();
|
|
||||||
m_CanChangeBufferPos.Reset();
|
|
||||||
m_BufferPosWasChanged.Reset();
|
|
||||||
m_MtCanStart.Set();
|
|
||||||
m_MtWasStarted.Lock();
|
|
||||||
m_Result = S_OK;
|
|
||||||
}
|
|
||||||
for (;;)
|
|
||||||
{
|
|
||||||
UInt32 nextIndex = (m_BlockIndex == kNumMTBlocks - 1) ? 0 : m_BlockIndex + 1;
|
|
||||||
m_CS[nextIndex].Enter();
|
|
||||||
if (!m_StopReading[nextIndex])
|
|
||||||
{
|
|
||||||
m_CS[m_BlockIndex].Leave();
|
|
||||||
m_BlockIndex = nextIndex;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
m_StopReading[nextIndex] = false;
|
|
||||||
m_CS[nextIndex].Leave();
|
|
||||||
m_CanChangeBufferPos.Set();
|
|
||||||
m_BufferPosWasChanged.Lock();
|
|
||||||
m_CS[nextIndex].Enter();
|
|
||||||
m_CS[m_BlockIndex].Leave();
|
|
||||||
m_BlockIndex = nextIndex;
|
|
||||||
}
|
|
||||||
m_Pos = m_BlockIndex * kBlockSize;
|
|
||||||
m_PosLimit = m_Buffer[m_Pos++];
|
|
||||||
m_NumAvailableBytes = m_Buffer[m_Pos++];
|
|
||||||
m_Result = m_Results[m_BlockIndex];
|
|
||||||
}
|
|
||||||
|
|
||||||
STDMETHODIMP CMatchFinderMT::GetMatches(UInt32 *distances)
|
|
||||||
{
|
|
||||||
if (m_Pos == m_PosLimit)
|
|
||||||
GetNextBlock();
|
|
||||||
|
|
||||||
if (m_Result != S_OK)
|
|
||||||
return m_Result;
|
|
||||||
m_NumAvailableBytes--;
|
|
||||||
m_DataCurrentPos++;
|
|
||||||
|
|
||||||
const UInt32 *buffer = m_Buffer + m_Pos;
|
|
||||||
UInt32 len = *buffer++;
|
|
||||||
*distances++ = len;
|
|
||||||
m_Pos += 1 + len;
|
|
||||||
for (UInt32 i = 0; i != len; i += 2)
|
|
||||||
{
|
|
||||||
distances[i] = buffer[i];
|
|
||||||
distances[i + 1] = buffer[i + 1];
|
|
||||||
}
|
|
||||||
return S_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
STDMETHODIMP CMatchFinderMT::Skip(UInt32 num)
|
|
||||||
{
|
|
||||||
do
|
|
||||||
{
|
|
||||||
if (m_Pos == m_PosLimit)
|
|
||||||
GetNextBlock();
|
|
||||||
|
|
||||||
if (m_Result != S_OK)
|
|
||||||
return m_Result;
|
|
||||||
m_NumAvailableBytes--;
|
|
||||||
m_DataCurrentPos++;
|
|
||||||
|
|
||||||
UInt32 len = m_Buffer[m_Pos++];
|
|
||||||
m_Pos += len;
|
|
||||||
}
|
|
||||||
while(--num != 0);
|
|
||||||
return S_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
STDMETHODIMP_(Int32) CMatchFinderMT::NeedChangeBufferPos(UInt32 /* numCheckBytes */)
|
|
||||||
{
|
|
||||||
throw 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
STDMETHODIMP_(void) CMatchFinderMT::ChangeBufferPos()
|
|
||||||
{
|
|
||||||
throw 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
DWORD CMatchFinderMT::ThreadFunc()
|
|
||||||
{
|
|
||||||
for (;;)
|
|
||||||
{
|
|
||||||
bool needStartEvent = true;
|
|
||||||
m_MtCanStart.Lock();
|
|
||||||
HRESULT result = S_OK;
|
|
||||||
UInt32 blockIndex = 0;
|
|
||||||
for (;;)
|
|
||||||
{
|
|
||||||
m_CS[blockIndex].Enter();
|
|
||||||
if (needStartEvent)
|
|
||||||
{
|
|
||||||
m_MtWasStarted.Set();
|
|
||||||
needStartEvent = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
m_CS[(blockIndex == 0) ? kNumMTBlocks - 1 : blockIndex - 1].Leave();
|
|
||||||
if (m_Exit)
|
|
||||||
return 0;
|
|
||||||
if (m_StopWriting)
|
|
||||||
{
|
|
||||||
m_MtWasStopped.Set();
|
|
||||||
m_CS[blockIndex].Leave();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (result == S_OK)
|
|
||||||
{
|
|
||||||
IMatchFinder *mf = m_MatchFinder;
|
|
||||||
if (mf->NeedChangeBufferPos(kBlockSize) != 0)
|
|
||||||
{
|
|
||||||
// m_AskChangeBufferPos.Set();
|
|
||||||
m_StopReading[blockIndex] = true;
|
|
||||||
m_CS[blockIndex].Leave();
|
|
||||||
m_CanChangeBufferPos.Lock();
|
|
||||||
m_CS[blockIndex].Enter();
|
|
||||||
const Byte *bufferPosBefore = mf->GetPointerToCurrentPos();
|
|
||||||
mf->ChangeBufferPos();
|
|
||||||
m_DataCurrentPos += mf->GetPointerToCurrentPos() - bufferPosBefore;
|
|
||||||
m_BufferPosWasChanged.Set();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
UInt32 curPos = blockIndex * kBlockSize;
|
|
||||||
UInt32 limit = curPos + kBlockSize - m_MatchMaxLen - m_MatchMaxLen - 1;
|
|
||||||
UInt32 *buffer = m_Buffer;
|
|
||||||
m_Results[blockIndex] = S_OK;
|
|
||||||
curPos++;
|
|
||||||
UInt32 numAvailableBytes = mf->GetNumAvailableBytes();
|
|
||||||
buffer[curPos++] = numAvailableBytes;
|
|
||||||
|
|
||||||
while (numAvailableBytes-- != 0 && curPos < limit)
|
|
||||||
{
|
|
||||||
result = mf->GetMatches(buffer + curPos);
|
|
||||||
if (result != S_OK)
|
|
||||||
{
|
|
||||||
m_Results[blockIndex] = result;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
curPos += buffer[curPos] + 1;
|
|
||||||
}
|
|
||||||
buffer[blockIndex * kBlockSize] = curPos;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
UInt32 curPos = blockIndex * kBlockSize;
|
|
||||||
m_Buffer[curPos] = curPos + 2; // size of buffer
|
|
||||||
m_Buffer[curPos + 1] = 0; // NumAvailableBytes
|
|
||||||
m_Results[blockIndex] = result; // error
|
|
||||||
}
|
|
||||||
if (++blockIndex == kNumMTBlocks)
|
|
||||||
blockIndex = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,79 +0,0 @@
|
|||||||
// LZ/MT.h
|
|
||||||
|
|
||||||
#ifndef __LZ_MT_H
|
|
||||||
#define __LZ_MT_H
|
|
||||||
|
|
||||||
#include "../../../../Common/MyCom.h"
|
|
||||||
|
|
||||||
#include "../../../../Windows/Thread.h"
|
|
||||||
#include "../../../../Windows/Synchronization.h"
|
|
||||||
|
|
||||||
#include "../../../ICoder.h"
|
|
||||||
#include "../IMatchFinder.h"
|
|
||||||
|
|
||||||
const UInt32 kNumMTBlocks = (1 << 6);
|
|
||||||
|
|
||||||
class CMatchFinderMT:
|
|
||||||
public IMatchFinder,
|
|
||||||
public CMyUnknownImp
|
|
||||||
{
|
|
||||||
MY_UNKNOWN_IMP
|
|
||||||
|
|
||||||
STDMETHOD(SetStream)(ISequentialInStream *inStream);
|
|
||||||
STDMETHOD_(void, ReleaseStream)();
|
|
||||||
STDMETHOD(Init)();
|
|
||||||
STDMETHOD_(Byte, GetIndexByte)(Int32 index);
|
|
||||||
STDMETHOD_(UInt32, GetMatchLen)(Int32 index, UInt32 distance, UInt32 limit);
|
|
||||||
STDMETHOD_(UInt32, GetNumAvailableBytes)();
|
|
||||||
STDMETHOD_(const Byte *, GetPointerToCurrentPos)();
|
|
||||||
STDMETHOD(Create)(UInt32 sizeHistory, UInt32 keepAddBufferBefore,
|
|
||||||
UInt32 matchMaxLen, UInt32 keepAddBufferAfter);
|
|
||||||
STDMETHOD(GetMatches)(UInt32 *distances);
|
|
||||||
STDMETHOD(Skip)(UInt32 num);
|
|
||||||
|
|
||||||
STDMETHOD_(Int32, NeedChangeBufferPos)(UInt32 numCheckBytes);
|
|
||||||
STDMETHOD_(void, ChangeBufferPos)();
|
|
||||||
|
|
||||||
UInt32 m_Pos;
|
|
||||||
UInt32 m_PosLimit;
|
|
||||||
UInt32 m_MatchMaxLen;
|
|
||||||
|
|
||||||
UInt32 *m_Buffer;
|
|
||||||
|
|
||||||
bool m_NeedStart;
|
|
||||||
UInt32 m_BlockIndex;
|
|
||||||
HRESULT m_Result;
|
|
||||||
UInt32 m_NumAvailableBytes;
|
|
||||||
const Byte *m_DataCurrentPos;
|
|
||||||
|
|
||||||
// Common variables
|
|
||||||
|
|
||||||
CMyComPtr<IMatchFinder> m_MatchFinder;
|
|
||||||
NWindows::CThread m_Thread;
|
|
||||||
NWindows::NSynchronization::CAutoResetEvent m_MtCanStart;
|
|
||||||
NWindows::NSynchronization::CAutoResetEvent m_MtWasStarted;
|
|
||||||
NWindows::NSynchronization::CAutoResetEvent m_MtWasStopped;
|
|
||||||
NWindows::NSynchronization::CAutoResetEvent m_CanChangeBufferPos;
|
|
||||||
NWindows::NSynchronization::CAutoResetEvent m_BufferPosWasChanged;
|
|
||||||
|
|
||||||
NWindows::NSynchronization::CCriticalSection m_CS[kNumMTBlocks];
|
|
||||||
|
|
||||||
HRESULT m_Results[kNumMTBlocks];
|
|
||||||
bool m_StopReading[kNumMTBlocks];
|
|
||||||
bool m_Exit;
|
|
||||||
bool m_StopWriting;
|
|
||||||
|
|
||||||
////////////////////////////
|
|
||||||
|
|
||||||
void FreeMem();
|
|
||||||
void GetNextBlock();
|
|
||||||
public:
|
|
||||||
|
|
||||||
DWORD ThreadFunc();
|
|
||||||
|
|
||||||
CMatchFinderMT();
|
|
||||||
~CMatchFinderMT();
|
|
||||||
HRESULT SetMatchFinder(IMatchFinder *matchFinder);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
// StdAfx.h
|
|
||||||
|
|
||||||
#ifndef __STDAFX_H
|
|
||||||
#define __STDAFX_H
|
|
||||||
|
|
||||||
#include "../../../../Common/MyWindows.h"
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
// DLLExports.cpp
|
|
||||||
|
|
||||||
#include "StdAfx.h"
|
|
||||||
|
|
||||||
#include "Common/MyInitGuid.h"
|
|
||||||
#include "Common/ComTry.h"
|
|
||||||
|
|
||||||
#include "Rar20Decoder.h"
|
|
||||||
|
|
||||||
// {23170F69-40C1-278B-0403-020000000000}
|
|
||||||
DEFINE_GUID(CLSID_CCompressRar20Decoder,
|
|
||||||
0x23170F69, 0x40C1, 0x278B, 0x04, 0x03, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00);
|
|
||||||
|
|
||||||
extern "C"
|
|
||||||
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
|
|
||||||
{
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
STDAPI CreateObject(const GUID *clsid, const GUID *iid, void **outObject)
|
|
||||||
{
|
|
||||||
COM_TRY_BEGIN
|
|
||||||
*outObject = 0;
|
|
||||||
if (*clsid != CLSID_CCompressRar20Decoder)
|
|
||||||
return CLASS_E_CLASSNOTAVAILABLE;
|
|
||||||
if (*iid != IID_ICompressCoder)
|
|
||||||
return E_NOINTERFACE;
|
|
||||||
CMyComPtr<ICompressCoder> coder = (ICompressCoder *)new
|
|
||||||
NCompress::NRar20::CDecoder;
|
|
||||||
*outObject = coder.Detach();
|
|
||||||
COM_TRY_END
|
|
||||||
return S_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
STDAPI GetNumberOfMethods(UINT32 *numMethods)
|
|
||||||
{
|
|
||||||
*numMethods = 1;
|
|
||||||
return S_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
STDAPI GetMethodProperty(UINT32 index, PROPID propID, PROPVARIANT *value)
|
|
||||||
{
|
|
||||||
if (index != 0)
|
|
||||||
return E_INVALIDARG;
|
|
||||||
::VariantClear((tagVARIANT *)value);
|
|
||||||
switch(propID)
|
|
||||||
{
|
|
||||||
case NMethodPropID::kID:
|
|
||||||
{
|
|
||||||
const char id[] = { 0x04, 0x03, 0x02 };
|
|
||||||
if ((value->bstrVal = ::SysAllocStringByteLen(id, sizeof(id))) != 0)
|
|
||||||
value->vt = VT_BSTR;
|
|
||||||
return S_OK;
|
|
||||||
}
|
|
||||||
case NMethodPropID::kName:
|
|
||||||
if ((value->bstrVal = ::SysAllocString(L"Rar20")) != 0)
|
|
||||||
value->vt = VT_BSTR;
|
|
||||||
return S_OK;
|
|
||||||
case NMethodPropID::kDecoder:
|
|
||||||
if ((value->bstrVal = ::SysAllocStringByteLen(
|
|
||||||
(const char *)&CLSID_CCompressRar20Decoder, sizeof(GUID))) != 0)
|
|
||||||
value->vt = VT_BSTR;
|
|
||||||
return S_OK;
|
|
||||||
}
|
|
||||||
return S_OK;
|
|
||||||
}
|
|
||||||
@@ -1,65 +0,0 @@
|
|||||||
// Rar20CoderConst.h
|
|
||||||
// According to unRAR license,
|
|
||||||
// this code may not be used to develop a
|
|
||||||
// RAR (WinRAR) compatible archiver
|
|
||||||
|
|
||||||
#ifndef __RAR20_CONST_H
|
|
||||||
#define __RAR20_CONST_H
|
|
||||||
|
|
||||||
#include "Rar20ExtConst.h"
|
|
||||||
|
|
||||||
namespace NCompress {
|
|
||||||
namespace NRar20 {
|
|
||||||
|
|
||||||
const UInt32 kMainTableSize = 298;
|
|
||||||
const UInt32 kLenTableSize = 28;
|
|
||||||
|
|
||||||
const UInt32 kDistTableStart = kMainTableSize;
|
|
||||||
const UInt32 kLenTableStart = kDistTableStart + kDistTableSize;
|
|
||||||
|
|
||||||
const UInt32 kHeapTablesSizesSum = kMainTableSize + kDistTableSize + kLenTableSize;
|
|
||||||
|
|
||||||
const UInt32 kLevelTableSize = 19;
|
|
||||||
|
|
||||||
const UInt32 kMMTablesSizesSum = kMMTableSize * 4;
|
|
||||||
|
|
||||||
const UInt32 kMaxTableSize = kMMTablesSizesSum;
|
|
||||||
|
|
||||||
const UInt32 kTableDirectLevels = 16;
|
|
||||||
const UInt32 kTableLevelRepNumber = kTableDirectLevels;
|
|
||||||
const UInt32 kTableLevel0Number = kTableLevelRepNumber + 1;
|
|
||||||
const UInt32 kTableLevel0Number2 = kTableLevel0Number + 1;
|
|
||||||
|
|
||||||
const UInt32 kLevelMask = 0xF;
|
|
||||||
|
|
||||||
|
|
||||||
const UInt32 kRepBothNumber = 256;
|
|
||||||
const UInt32 kRepNumber = kRepBothNumber + 1;
|
|
||||||
const UInt32 kLen2Number = kRepNumber + 4;
|
|
||||||
|
|
||||||
const UInt32 kLen2NumNumbers = 8;
|
|
||||||
const UInt32 kReadTableNumber = kLen2Number + kLen2NumNumbers;
|
|
||||||
const UInt32 kMatchNumber = kReadTableNumber + 1;
|
|
||||||
|
|
||||||
const Byte kLenStart[kLenTableSize] = {0,1,2,3,4,5,6,7,8,10,12,14,16,20,24,28,32,40,48,56,64,80,96,112,128,160,192,224};
|
|
||||||
const Byte kLenDirectBits[kLenTableSize] = {0,0,0,0,0,0,0,0,1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5};
|
|
||||||
|
|
||||||
const UInt32 kDistStart[kDistTableSize] = {0,1,2,3,4,6,8,12,16,24,32,48,64,96,128,192,256,384,512,768,1024,1536,2048,3072,4096,6144,8192,12288,16384,24576,32768U,49152U,65536,98304,131072,196608,262144,327680,393216,458752,524288,589824,655360,720896,786432,851968,917504,983040};
|
|
||||||
const Byte kDistDirectBits[kDistTableSize] = {0,0,0,0,1,1,2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16};
|
|
||||||
|
|
||||||
const Byte kLevelDirectBits[kLevelTableSize] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 7};
|
|
||||||
|
|
||||||
const Byte kLen2DistStarts[kLen2NumNumbers]={0,4,8,16,32,64,128,192};
|
|
||||||
const Byte kLen2DistDirectBits[kLen2NumNumbers]={2,2,3, 4, 5, 6, 6, 6};
|
|
||||||
|
|
||||||
const UInt32 kDistLimit2 = 0x101 - 1;
|
|
||||||
const UInt32 kDistLimit3 = 0x2000 - 1;
|
|
||||||
const UInt32 kDistLimit4 = 0x40000 - 1;
|
|
||||||
|
|
||||||
const UInt32 kMatchMaxLen = 255 + 2;
|
|
||||||
const UInt32 kMatchMaxLenMax = 255 + 5;
|
|
||||||
const UInt32 kNormalMatchMinLen = 3;
|
|
||||||
|
|
||||||
}}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,322 +0,0 @@
|
|||||||
// Rar20Decoder.cpp
|
|
||||||
// According to unRAR license,
|
|
||||||
// this code may not be used to develop a
|
|
||||||
// RAR (WinRAR) compatible archiver
|
|
||||||
|
|
||||||
#include "StdAfx.h"
|
|
||||||
|
|
||||||
#include "Rar20Decoder.h"
|
|
||||||
#include "Rar20Const.h"
|
|
||||||
|
|
||||||
namespace NCompress {
|
|
||||||
namespace NRar20 {
|
|
||||||
|
|
||||||
class CException
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
enum ECauseType
|
|
||||||
{
|
|
||||||
kData
|
|
||||||
} Cause;
|
|
||||||
CException(ECauseType cause): Cause(cause) {}
|
|
||||||
};
|
|
||||||
|
|
||||||
static const char *kNumberErrorMessage = "Number error";
|
|
||||||
|
|
||||||
static const UInt32 kHistorySize = 1 << 20;
|
|
||||||
|
|
||||||
static const int kNumStats = 11;
|
|
||||||
|
|
||||||
static const UInt32 kWindowReservSize = (1 << 22) + 256;
|
|
||||||
|
|
||||||
CDecoder::CDecoder():
|
|
||||||
m_IsSolid(false)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void CDecoder::InitStructures()
|
|
||||||
{
|
|
||||||
m_Predictor.Init();
|
|
||||||
for(int i = 0; i < kNumRepDists; i++)
|
|
||||||
m_RepDists[i] = 0;
|
|
||||||
m_RepDistPtr = 0;
|
|
||||||
m_LastLength = 0;
|
|
||||||
memset(m_LastLevels, 0, kMaxTableSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
#define RIF(x) { if (!(x)) return false; }
|
|
||||||
|
|
||||||
bool CDecoder::ReadTables(void)
|
|
||||||
{
|
|
||||||
Byte levelLevels[kLevelTableSize];
|
|
||||||
Byte newLevels[kMaxTableSize];
|
|
||||||
m_AudioMode = (m_InBitStream.ReadBits(1) == 1);
|
|
||||||
|
|
||||||
if (m_InBitStream.ReadBits(1) == 0)
|
|
||||||
memset(m_LastLevels, 0, kMaxTableSize);
|
|
||||||
int numLevels;
|
|
||||||
if (m_AudioMode)
|
|
||||||
{
|
|
||||||
m_NumChannels = m_InBitStream.ReadBits(2) + 1;
|
|
||||||
if (m_Predictor.CurrentChannel >= m_NumChannels)
|
|
||||||
m_Predictor.CurrentChannel = 0;
|
|
||||||
numLevels = m_NumChannels * kMMTableSize;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
numLevels = kHeapTablesSizesSum;
|
|
||||||
|
|
||||||
int i;
|
|
||||||
for (i = 0; i < kLevelTableSize; i++)
|
|
||||||
levelLevels[i] = Byte(m_InBitStream.ReadBits(4));
|
|
||||||
RIF(m_LevelDecoder.SetCodeLengths(levelLevels));
|
|
||||||
i = 0;
|
|
||||||
while (i < numLevels)
|
|
||||||
{
|
|
||||||
UInt32 number = m_LevelDecoder.DecodeSymbol(&m_InBitStream);
|
|
||||||
if (number < kTableDirectLevels)
|
|
||||||
{
|
|
||||||
newLevels[i] = Byte((number + m_LastLevels[i]) & kLevelMask);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (number == kTableLevelRepNumber)
|
|
||||||
{
|
|
||||||
int t = m_InBitStream.ReadBits(2) + 3;
|
|
||||||
for (int reps = t; reps > 0 && i < numLevels ; reps--, i++)
|
|
||||||
newLevels[i] = newLevels[i - 1];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
int num;
|
|
||||||
if (number == kTableLevel0Number)
|
|
||||||
num = m_InBitStream.ReadBits(3) + 3;
|
|
||||||
else if (number == kTableLevel0Number2)
|
|
||||||
num = m_InBitStream.ReadBits(7) + 11;
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
for (;num > 0 && i < numLevels; num--)
|
|
||||||
newLevels[i++] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (m_AudioMode)
|
|
||||||
for (i = 0; i < m_NumChannels; i++)
|
|
||||||
{
|
|
||||||
RIF(m_MMDecoders[i].SetCodeLengths(&newLevels[i * kMMTableSize]));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
RIF(m_MainDecoder.SetCodeLengths(&newLevels[0]));
|
|
||||||
RIF(m_DistDecoder.SetCodeLengths(&newLevels[kMainTableSize]));
|
|
||||||
RIF(m_LenDecoder.SetCodeLengths(&newLevels[kMainTableSize + kDistTableSize]));
|
|
||||||
}
|
|
||||||
memcpy(m_LastLevels, newLevels, kMaxTableSize);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CDecoder::ReadLastTables()
|
|
||||||
{
|
|
||||||
// it differs a little from pure RAR sources;
|
|
||||||
// UInt64 ttt = m_InBitStream.GetProcessedSize() + 2;
|
|
||||||
// + 2 works for: return 0xFF; in CInBuffer::ReadByte.
|
|
||||||
if (m_InBitStream.GetProcessedSize() + 7 <= m_PackSize) // test it: probably incorrect;
|
|
||||||
// if (m_InBitStream.GetProcessedSize() + 2 <= m_PackSize) // test it: probably incorrect;
|
|
||||||
if (m_AudioMode)
|
|
||||||
{
|
|
||||||
UInt32 symbol = m_MMDecoders[m_Predictor.CurrentChannel].DecodeSymbol(&m_InBitStream);
|
|
||||||
if (symbol == 256)
|
|
||||||
return ReadTables();
|
|
||||||
if (symbol >= kMMTableSize)
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
UInt32 number = m_MainDecoder.DecodeSymbol(&m_InBitStream);
|
|
||||||
if (number == kReadTableNumber)
|
|
||||||
return ReadTables();
|
|
||||||
if (number >= kMainTableSize)
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
class CCoderReleaser
|
|
||||||
{
|
|
||||||
CDecoder *m_Coder;
|
|
||||||
public:
|
|
||||||
CCoderReleaser(CDecoder *coder): m_Coder(coder) {}
|
|
||||||
~CCoderReleaser()
|
|
||||||
{
|
|
||||||
m_Coder->ReleaseStreams();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
STDMETHODIMP CDecoder::CodeReal(ISequentialInStream *inStream,
|
|
||||||
ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,
|
|
||||||
ICompressProgressInfo *progress)
|
|
||||||
{
|
|
||||||
if (inSize == NULL || outSize == NULL)
|
|
||||||
return E_INVALIDARG;
|
|
||||||
|
|
||||||
if (!m_OutWindowStream.Create(kHistorySize))
|
|
||||||
return E_OUTOFMEMORY;
|
|
||||||
if (!m_InBitStream.Create(1 << 20))
|
|
||||||
return E_OUTOFMEMORY;
|
|
||||||
|
|
||||||
m_PackSize = *inSize;
|
|
||||||
|
|
||||||
UInt64 pos = 0, unPackSize = *outSize;
|
|
||||||
|
|
||||||
m_OutWindowStream.SetStream(outStream);
|
|
||||||
m_OutWindowStream.Init(m_IsSolid);
|
|
||||||
m_InBitStream.SetStream(inStream);
|
|
||||||
m_InBitStream.Init();
|
|
||||||
|
|
||||||
CCoderReleaser coderReleaser(this);
|
|
||||||
if (!m_IsSolid)
|
|
||||||
{
|
|
||||||
InitStructures();
|
|
||||||
if (unPackSize == 0)
|
|
||||||
{
|
|
||||||
if (m_InBitStream.GetProcessedSize() + 2 <= m_PackSize) // test it: probably incorrect;
|
|
||||||
if (!ReadTables())
|
|
||||||
return S_FALSE;
|
|
||||||
return S_OK;
|
|
||||||
}
|
|
||||||
if (!ReadTables())
|
|
||||||
return S_FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
while(pos < unPackSize)
|
|
||||||
{
|
|
||||||
if (m_AudioMode)
|
|
||||||
while(pos < unPackSize)
|
|
||||||
{
|
|
||||||
UInt32 symbol = m_MMDecoders[m_Predictor.CurrentChannel].DecodeSymbol(&m_InBitStream);
|
|
||||||
if (symbol == 256)
|
|
||||||
{
|
|
||||||
if (progress != 0)
|
|
||||||
{
|
|
||||||
UInt64 packSize = m_InBitStream.GetProcessedSize();
|
|
||||||
RINOK(progress->SetRatioInfo(&packSize, &pos));
|
|
||||||
}
|
|
||||||
if (!ReadTables())
|
|
||||||
return S_FALSE;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (symbol >= kMMTableSize)
|
|
||||||
return S_FALSE;
|
|
||||||
Byte byPredict = m_Predictor.Predict();
|
|
||||||
Byte byReal = (Byte)(byPredict - (Byte)symbol);
|
|
||||||
m_Predictor.Update(byReal, byPredict);
|
|
||||||
m_OutWindowStream.PutByte(byReal);
|
|
||||||
if (++m_Predictor.CurrentChannel == m_NumChannels)
|
|
||||||
m_Predictor.CurrentChannel = 0;
|
|
||||||
pos++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
while(pos < unPackSize)
|
|
||||||
{
|
|
||||||
UInt32 number = m_MainDecoder.DecodeSymbol(&m_InBitStream);
|
|
||||||
UInt32 length, distance;
|
|
||||||
if (number < 256)
|
|
||||||
{
|
|
||||||
m_OutWindowStream.PutByte(Byte(number));
|
|
||||||
pos++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
else if (number >= kMatchNumber)
|
|
||||||
{
|
|
||||||
number -= kMatchNumber;
|
|
||||||
length = kNormalMatchMinLen + UInt32(kLenStart[number]) +
|
|
||||||
m_InBitStream.ReadBits(kLenDirectBits[number]);
|
|
||||||
number = m_DistDecoder.DecodeSymbol(&m_InBitStream);
|
|
||||||
if (number >= kDistTableSize)
|
|
||||||
return S_FALSE;
|
|
||||||
distance = kDistStart[number] + m_InBitStream.ReadBits(kDistDirectBits[number]);
|
|
||||||
if (distance >= kDistLimit3)
|
|
||||||
{
|
|
||||||
length += 2 - ((distance - kDistLimit4) >> 31);
|
|
||||||
// length++;
|
|
||||||
// if (distance >= kDistLimit4)
|
|
||||||
// length++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (number == kRepBothNumber)
|
|
||||||
{
|
|
||||||
length = m_LastLength;
|
|
||||||
distance = m_RepDists[(m_RepDistPtr + 4 - 1) & 3];
|
|
||||||
}
|
|
||||||
else if (number < kLen2Number)
|
|
||||||
{
|
|
||||||
distance = m_RepDists[(m_RepDistPtr - (number - kRepNumber + 1)) & 3];
|
|
||||||
number = m_LenDecoder.DecodeSymbol(&m_InBitStream);
|
|
||||||
if (number >= kLenTableSize)
|
|
||||||
return S_FALSE;
|
|
||||||
length = 2 + kLenStart[number] + m_InBitStream.ReadBits(kLenDirectBits[number]);
|
|
||||||
if (distance >= kDistLimit2)
|
|
||||||
{
|
|
||||||
length++;
|
|
||||||
if (distance >= kDistLimit3)
|
|
||||||
{
|
|
||||||
length += 2 - ((distance - kDistLimit4) >> 31);
|
|
||||||
// length++;
|
|
||||||
// if (distance >= kDistLimit4)
|
|
||||||
// length++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (number < kReadTableNumber)
|
|
||||||
{
|
|
||||||
number -= kLen2Number;
|
|
||||||
distance = kLen2DistStarts[number] +
|
|
||||||
m_InBitStream.ReadBits(kLen2DistDirectBits[number]);
|
|
||||||
length = 2;
|
|
||||||
}
|
|
||||||
else if (number == kReadTableNumber)
|
|
||||||
{
|
|
||||||
if (progress != 0)
|
|
||||||
{
|
|
||||||
UInt64 packSize = m_InBitStream.GetProcessedSize();
|
|
||||||
RINOK(progress->SetRatioInfo(&packSize, &pos));
|
|
||||||
}
|
|
||||||
if (!ReadTables())
|
|
||||||
return S_FALSE;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return S_FALSE;
|
|
||||||
m_RepDists[m_RepDistPtr++ & 3] = distance;
|
|
||||||
m_LastLength = length;
|
|
||||||
if (!m_OutWindowStream.CopyBlock(distance, length))
|
|
||||||
return S_FALSE;
|
|
||||||
pos += length;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (pos > unPackSize)
|
|
||||||
throw CException(CException::kData);
|
|
||||||
|
|
||||||
if (!ReadLastTables())
|
|
||||||
return S_FALSE;
|
|
||||||
return m_OutWindowStream.Flush();
|
|
||||||
}
|
|
||||||
|
|
||||||
STDMETHODIMP CDecoder::Code(ISequentialInStream *inStream,
|
|
||||||
ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,
|
|
||||||
ICompressProgressInfo *progress)
|
|
||||||
{
|
|
||||||
try { return CodeReal(inStream, outStream, inSize, outSize, progress); }
|
|
||||||
catch(const CLZOutWindowException &e) { return e.ErrorCode; }
|
|
||||||
catch(...) { return S_FALSE; }
|
|
||||||
}
|
|
||||||
|
|
||||||
STDMETHODIMP CDecoder::SetDecoderProperties2(const Byte *data, UInt32 size)
|
|
||||||
{
|
|
||||||
if (size < 1)
|
|
||||||
return E_INVALIDARG;
|
|
||||||
m_IsSolid = (data[0] != 0);
|
|
||||||
return S_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
}}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
// Rar20ExtConst.h
|
|
||||||
// According to unRAR license,
|
|
||||||
// this code may not be used to develop a
|
|
||||||
// RAR (WinRAR) compatible archiver
|
|
||||||
|
|
||||||
#ifndef __RAR20_EXTCONST_H
|
|
||||||
#define __RAR20_EXTCONST_H
|
|
||||||
|
|
||||||
#include "../../../Common/Types.h"
|
|
||||||
|
|
||||||
namespace NCompress {
|
|
||||||
namespace NRar20 {
|
|
||||||
|
|
||||||
const UInt32 kNumRepDists = 4;
|
|
||||||
const UInt32 kDistTableSize = 48;
|
|
||||||
|
|
||||||
const int kMMTableSize = 256 + 1;
|
|
||||||
|
|
||||||
}}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,128 +0,0 @@
|
|||||||
// Rar20Multimedia.cpp
|
|
||||||
// According to unRAR license,
|
|
||||||
// this code may not be used to develop a
|
|
||||||
// RAR (WinRAR) compatible archiver
|
|
||||||
|
|
||||||
#include "StdAfx.h"
|
|
||||||
|
|
||||||
#include "Rar20Multimedia.h"
|
|
||||||
|
|
||||||
namespace NCompress {
|
|
||||||
namespace NRar20 {
|
|
||||||
namespace NMultimedia {
|
|
||||||
|
|
||||||
void CAudioVariables::Init()
|
|
||||||
{
|
|
||||||
memset(this, 0, sizeof(CAudioVariables));
|
|
||||||
}
|
|
||||||
|
|
||||||
void CPredictor::Init()
|
|
||||||
{
|
|
||||||
for(int i = 0; i < kNumChanelsMax; i++)
|
|
||||||
m_AudioVariablesArray[i].Init();
|
|
||||||
m_ChannelDelta = 0;
|
|
||||||
CurrentChannel = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
Byte CPredictor::Predict()
|
|
||||||
{
|
|
||||||
CAudioVariables *v = &m_AudioVariablesArray[CurrentChannel];
|
|
||||||
v->ByteCount++;
|
|
||||||
v->D4 = v->D3;
|
|
||||||
v->D3 = v->D2;
|
|
||||||
v->D2 = v->LastDelta-v->D1;
|
|
||||||
v->D1 = v->LastDelta;
|
|
||||||
int pCh = 8 * v->LastChar +
|
|
||||||
v->K1 * v->D1 +
|
|
||||||
v->K2 * v->D2 +
|
|
||||||
v->K3 * v->D3 +
|
|
||||||
v->K4 * v->D4 +
|
|
||||||
v->K5*m_ChannelDelta;
|
|
||||||
pCh = (pCh >> 3) & 0xFF;
|
|
||||||
return Byte(pCh);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CPredictor::Update(Byte realValue, int predictedValue)
|
|
||||||
{
|
|
||||||
struct CAudioVariables *v = &m_AudioVariablesArray[CurrentChannel];
|
|
||||||
|
|
||||||
int delta = predictedValue - realValue;
|
|
||||||
int i = ((signed char)delta) << 3;
|
|
||||||
|
|
||||||
v->Dif[0] += abs(i);
|
|
||||||
v->Dif[1] += abs(i - v->D1);
|
|
||||||
v->Dif[2] += abs(i + v->D1);
|
|
||||||
v->Dif[3] += abs(i - v->D2);
|
|
||||||
v->Dif[4] += abs(i + v->D2);
|
|
||||||
v->Dif[5] += abs(i - v->D3);
|
|
||||||
v->Dif[6] += abs(i + v->D3);
|
|
||||||
v->Dif[7] += abs(i - v->D4);
|
|
||||||
v->Dif[8] += abs(i + v->D4);
|
|
||||||
v->Dif[9] += abs(i - m_ChannelDelta);
|
|
||||||
v->Dif[10] += abs(i + m_ChannelDelta);
|
|
||||||
|
|
||||||
m_ChannelDelta = v->LastDelta = (signed char)(realValue - v->LastChar);
|
|
||||||
v->LastChar = realValue;
|
|
||||||
|
|
||||||
UInt32 numMinDif, minDif;
|
|
||||||
if ((v->ByteCount & 0x1F)==0)
|
|
||||||
{
|
|
||||||
minDif = v->Dif[0];
|
|
||||||
numMinDif = 0;
|
|
||||||
v->Dif[0] = 0;
|
|
||||||
for (i = 1; i < sizeof(v->Dif) / sizeof(v->Dif[0]); i++)
|
|
||||||
{
|
|
||||||
if (v->Dif[i] < minDif)
|
|
||||||
{
|
|
||||||
minDif = v->Dif[i];
|
|
||||||
numMinDif = i;
|
|
||||||
}
|
|
||||||
v->Dif[i] = 0;
|
|
||||||
}
|
|
||||||
switch(numMinDif)
|
|
||||||
{
|
|
||||||
case 1:
|
|
||||||
if (v->K1 >= -16)
|
|
||||||
v->K1--;
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
if (v->K1 < 16)
|
|
||||||
v->K1++;
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
if (v->K2 >= -16)
|
|
||||||
v->K2--;
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
if (v->K2 < 16)
|
|
||||||
v->K2++;
|
|
||||||
break;
|
|
||||||
case 5:
|
|
||||||
if (v->K3 >= -16)
|
|
||||||
v->K3--;
|
|
||||||
break;
|
|
||||||
case 6:
|
|
||||||
if (v->K3 < 16)
|
|
||||||
v->K3++;
|
|
||||||
break;
|
|
||||||
case 7:
|
|
||||||
if (v->K4 >= -16)
|
|
||||||
v->K4--;
|
|
||||||
break;
|
|
||||||
case 8:
|
|
||||||
if (v->K4 < 16)
|
|
||||||
v->K4++;
|
|
||||||
break;
|
|
||||||
case 9:
|
|
||||||
if (v->K5 >= -16)
|
|
||||||
v->K5--;
|
|
||||||
break;
|
|
||||||
case 10:
|
|
||||||
if (v->K5 < 16)
|
|
||||||
v->K5++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}}}
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
// Rar20Multimedia.h
|
|
||||||
// According to unRAR license,
|
|
||||||
// this code may not be used to develop a
|
|
||||||
// RAR (WinRAR) compatible archiver
|
|
||||||
|
|
||||||
#ifndef __RAR20_MULTIMEDIA_H
|
|
||||||
#define __RAR20_MULTIMEDIA_H
|
|
||||||
|
|
||||||
#include "../../../Common/Types.h"
|
|
||||||
|
|
||||||
namespace NCompress {
|
|
||||||
namespace NRar20 {
|
|
||||||
namespace NMultimedia {
|
|
||||||
|
|
||||||
struct CAudioVariables
|
|
||||||
{
|
|
||||||
int K1,K2,K3,K4,K5;
|
|
||||||
int D1,D2,D3,D4;
|
|
||||||
int LastDelta;
|
|
||||||
UInt32 Dif[11];
|
|
||||||
UInt32 ByteCount;
|
|
||||||
int LastChar;
|
|
||||||
|
|
||||||
void Init();
|
|
||||||
};
|
|
||||||
|
|
||||||
const int kNumChanelsMax = 4;
|
|
||||||
|
|
||||||
class CPredictor
|
|
||||||
{
|
|
||||||
CAudioVariables m_AudioVariablesArray[kNumChanelsMax];
|
|
||||||
int m_ChannelDelta;
|
|
||||||
public:
|
|
||||||
int CurrentChannel;
|
|
||||||
|
|
||||||
void Init();
|
|
||||||
Byte Predict();
|
|
||||||
void Update(Byte realValue, int predictedValue);
|
|
||||||
};
|
|
||||||
|
|
||||||
}}}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,128 +0,0 @@
|
|||||||
#ifndef _RAR_ARCHIVE_
|
|
||||||
#define _RAR_ARCHIVE_
|
|
||||||
|
|
||||||
class Pack;
|
|
||||||
|
|
||||||
enum {EN_LOCK=1,EN_VOL=2,EN_FIRSTVOL=4};
|
|
||||||
|
|
||||||
class Archive:public File
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
bool IsSignature(byte *D);
|
|
||||||
void UpdateLatestTime(FileHeader *CurBlock);
|
|
||||||
void Protect(int RecSectors);
|
|
||||||
void ConvertNameCase(char *Name);
|
|
||||||
void ConvertNameCase(wchar *Name);
|
|
||||||
void ConvertUnknownHeader();
|
|
||||||
bool AddArcComment(char *NameToShow);
|
|
||||||
int ReadOldHeader();
|
|
||||||
void PrepareExtraTime(FileHeader *hd,EXTTIME_MODE etm,EXTTIME_MODE etc,EXTTIME_MODE eta,EXTTIME_MODE etarc,Array<byte> &TimeData);
|
|
||||||
|
|
||||||
#if !defined(SHELL_EXT) && !defined(NOCRYPT)
|
|
||||||
CryptData HeadersCrypt;
|
|
||||||
byte HeadersSalt[SALT_SIZE];
|
|
||||||
#endif
|
|
||||||
#ifndef SHELL_EXT
|
|
||||||
ComprDataIO SubDataIO;
|
|
||||||
byte SubDataSalt[SALT_SIZE];
|
|
||||||
#endif
|
|
||||||
RAROptions *Cmd,DummyCmd;
|
|
||||||
|
|
||||||
MarkHeader MarkHead;
|
|
||||||
OldMainHeader OldMhd;
|
|
||||||
|
|
||||||
int RecoverySectors;
|
|
||||||
Int64 RecoveryPos;
|
|
||||||
|
|
||||||
RarTime LatestTime;
|
|
||||||
int LastReadBlock;
|
|
||||||
int CurHeaderType;
|
|
||||||
|
|
||||||
bool SilentOpen;
|
|
||||||
public:
|
|
||||||
Archive(RAROptions *InitCmd=NULL);
|
|
||||||
bool IsArchive(bool EnableBroken);
|
|
||||||
int SearchBlock(int BlockType);
|
|
||||||
int SearchSubBlock(const char *Type);
|
|
||||||
int ReadBlock(int BlockType);
|
|
||||||
void WriteBlock(int BlockType,BaseBlock *wb=NULL);
|
|
||||||
int PrepareNamesToWrite(char *Name,wchar *NameW,char *DestName,byte *DestNameW);
|
|
||||||
void SetLhdSize();
|
|
||||||
int ReadHeader();
|
|
||||||
void CheckArc(bool EnableBroken);
|
|
||||||
void CheckOpen(char *Name,wchar *NameW=NULL);
|
|
||||||
bool WCheckOpen(char *Name,wchar *NameW=NULL);
|
|
||||||
bool TestLock(int Mode);
|
|
||||||
void MakeTemp();
|
|
||||||
void CopyMainHeader(Archive &Src,bool CopySFX=true,char *NameToDisplay=NULL);
|
|
||||||
bool ProcessToFileHead(Archive &Src,bool LastBlockAdded,
|
|
||||||
Pack *Pack=NULL,const char *SkipName=NULL);
|
|
||||||
void TmpToArc(Archive &Src);
|
|
||||||
void CloseNew(int AdjustRecovery,bool CloseVolume);
|
|
||||||
void WriteEndBlock(bool CloseVolume);
|
|
||||||
void CopyFileRecord(Archive &Src);
|
|
||||||
void CopyArchiveData(Archive &Src);
|
|
||||||
bool GetComment(Array<byte> &CmtData);
|
|
||||||
void ViewComment();
|
|
||||||
void ViewFileComment();
|
|
||||||
void SetLatestTime(RarTime *NewTime);
|
|
||||||
void SeekToNext();
|
|
||||||
bool CheckAccess();
|
|
||||||
bool IsArcDir();
|
|
||||||
bool IsArcLabel();
|
|
||||||
void ConvertAttributes();
|
|
||||||
int GetRecoverySize(bool Required);
|
|
||||||
void VolSubtractHeaderSize(int SubSize);
|
|
||||||
void AddSubData(byte *SrcData,int DataSize,File *SrcFile,char *Name,bool AllowSplit);
|
|
||||||
bool ReadSubData(Array<byte> *UnpData,File *DestFile);
|
|
||||||
int GetHeaderType() {return(CurHeaderType);};
|
|
||||||
int ReadCommentData(Array<byte> &CmtData);
|
|
||||||
void WriteCommentData(byte *Data,int DataSize,bool FileComment);
|
|
||||||
RAROptions* GetRAROptions() {return(Cmd);}
|
|
||||||
void SetSilentOpen(bool Mode) {SilentOpen=Mode;}
|
|
||||||
|
|
||||||
BaseBlock ShortBlock;
|
|
||||||
MainHeader NewMhd;
|
|
||||||
FileHeader NewLhd;
|
|
||||||
EndArcHeader EndArcHead;
|
|
||||||
SubBlockHeader SubBlockHead;
|
|
||||||
FileHeader SubHead;
|
|
||||||
CommentHeader CommHead;
|
|
||||||
ProtectHeader ProtectHead;
|
|
||||||
AVHeader AVHead;
|
|
||||||
SignHeader SignHead;
|
|
||||||
UnixOwnersHeader UOHead;
|
|
||||||
MacFInfoHeader MACHead;
|
|
||||||
EAHeader EAHead;
|
|
||||||
StreamHeader StreamHead;
|
|
||||||
|
|
||||||
Int64 CurBlockPos;
|
|
||||||
Int64 NextBlockPos;
|
|
||||||
|
|
||||||
bool OldFormat;
|
|
||||||
bool Solid;
|
|
||||||
bool Volume;
|
|
||||||
bool MainComment;
|
|
||||||
bool Locked;
|
|
||||||
bool Signed;
|
|
||||||
bool NotFirstVolume;
|
|
||||||
bool Protected;
|
|
||||||
bool Encrypted;
|
|
||||||
uint SFXSize;
|
|
||||||
bool BrokenFileHeader;
|
|
||||||
|
|
||||||
bool Splitting;
|
|
||||||
|
|
||||||
ushort HeaderCRC;
|
|
||||||
|
|
||||||
Int64 VolWrite;
|
|
||||||
Int64 AddingFilesSize;
|
|
||||||
uint AddingHeadersSize;
|
|
||||||
|
|
||||||
bool NewArchive;
|
|
||||||
|
|
||||||
char FirstVolumeName[NM];
|
|
||||||
wchar FirstVolumeNameW[NM];
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,121 +0,0 @@
|
|||||||
#ifndef _RAR_ARRAY_
|
|
||||||
#define _RAR_ARRAY_
|
|
||||||
|
|
||||||
extern ErrorHandler ErrHandler;
|
|
||||||
|
|
||||||
template <class T> class Array
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
T *Buffer;
|
|
||||||
int BufSize;
|
|
||||||
int AllocSize;
|
|
||||||
public:
|
|
||||||
Array();
|
|
||||||
Array(int Size);
|
|
||||||
~Array();
|
|
||||||
inline void CleanData();
|
|
||||||
inline T& operator [](int Item);
|
|
||||||
inline int Size();
|
|
||||||
void Add(int Items);
|
|
||||||
void Alloc(int Items);
|
|
||||||
void Reset();
|
|
||||||
void operator = (Array<T> &Src);
|
|
||||||
void Push(T Item);
|
|
||||||
};
|
|
||||||
|
|
||||||
template <class T> void Array<T>::CleanData()
|
|
||||||
{
|
|
||||||
Buffer=NULL;
|
|
||||||
BufSize=0;
|
|
||||||
AllocSize=0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template <class T> Array<T>::Array()
|
|
||||||
{
|
|
||||||
CleanData();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template <class T> Array<T>::Array(int Size)
|
|
||||||
{
|
|
||||||
Buffer=(T *)rarmalloc(sizeof(T)*Size);
|
|
||||||
if (Buffer==NULL && Size!=0)
|
|
||||||
ErrHandler.MemoryError();
|
|
||||||
|
|
||||||
AllocSize=BufSize=Size;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template <class T> Array<T>::~Array()
|
|
||||||
{
|
|
||||||
if (Buffer!=NULL)
|
|
||||||
rarfree(Buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template <class T> inline T& Array<T>::operator [](int Item)
|
|
||||||
{
|
|
||||||
return(Buffer[Item]);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template <class T> inline int Array<T>::Size()
|
|
||||||
{
|
|
||||||
return(BufSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template <class T> void Array<T>::Add(int Items)
|
|
||||||
{
|
|
||||||
BufSize+=Items;
|
|
||||||
if (BufSize>AllocSize)
|
|
||||||
{
|
|
||||||
int Suggested=AllocSize+AllocSize/4+32;
|
|
||||||
int NewSize=Max(BufSize,Suggested);
|
|
||||||
|
|
||||||
Buffer=(T *)rarrealloc(Buffer,NewSize*sizeof(T));
|
|
||||||
if (Buffer==NULL)
|
|
||||||
ErrHandler.MemoryError();
|
|
||||||
AllocSize=NewSize;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template <class T> void Array<T>::Alloc(int Items)
|
|
||||||
{
|
|
||||||
if (Items>AllocSize)
|
|
||||||
Add(Items-BufSize);
|
|
||||||
else
|
|
||||||
BufSize=Items;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template <class T> void Array<T>::Reset()
|
|
||||||
{
|
|
||||||
if (Buffer!=NULL)
|
|
||||||
{
|
|
||||||
rarfree(Buffer);
|
|
||||||
Buffer=NULL;
|
|
||||||
}
|
|
||||||
BufSize=0;
|
|
||||||
AllocSize=0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template <class T> void Array<T>::operator =(Array<T> &Src)
|
|
||||||
{
|
|
||||||
Reset();
|
|
||||||
Alloc(Src.BufSize);
|
|
||||||
if (Src.BufSize!=0)
|
|
||||||
memcpy((void *)Buffer,(void *)Src.Buffer,Src.BufSize*sizeof(T));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template <class T> void Array<T>::Push(T Item)
|
|
||||||
{
|
|
||||||
Add(1);
|
|
||||||
(*this)[Size()-1]=Item;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
#ifndef _RAR_CMDDATA_
|
|
||||||
#define _RAR_CMDDATA_
|
|
||||||
|
|
||||||
#define DefaultStoreList "ace;arj;bz2;cab;gz;jpeg;jpg;lha;lzh;mp3;rar;zip;taz;tgz;z"
|
|
||||||
|
|
||||||
class CommandData:public RAROptions
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
void ProcessSwitchesString(char *Str);
|
|
||||||
void ProcessSwitch(char *Switch);
|
|
||||||
void BadSwitch(char *Switch);
|
|
||||||
bool ExclCheckArgs(StringList *Args,char *CheckName,bool CheckFullPath,int MatchMode);
|
|
||||||
uint GetExclAttr(char *Str);
|
|
||||||
|
|
||||||
bool FileLists;
|
|
||||||
bool NoMoreSwitches;
|
|
||||||
bool TimeConverted;
|
|
||||||
bool BareOutput;
|
|
||||||
public:
|
|
||||||
CommandData();
|
|
||||||
~CommandData();
|
|
||||||
void Init();
|
|
||||||
void Close();
|
|
||||||
void ParseArg(char *Arg,wchar *ArgW);
|
|
||||||
void ParseDone();
|
|
||||||
void ParseEnvVar();
|
|
||||||
void ReadConfig(int argc,char *argv[]);
|
|
||||||
bool IsConfigEnabled(int argc,char *argv[]);
|
|
||||||
void OutTitle();
|
|
||||||
void OutHelp();
|
|
||||||
bool IsSwitch(int Ch);
|
|
||||||
bool ExclCheck(char *CheckName,bool CheckFullPath);
|
|
||||||
bool StoreCheck(char *CheckName);
|
|
||||||
bool TimeCheck(RarTime &ft);
|
|
||||||
int IsProcessFile(FileHeader &NewLhd,bool *ExactMatch=NULL,int MatchType=MATCH_WILDSUBPATH);
|
|
||||||
void ProcessCommand();
|
|
||||||
void AddArcName(char *Name,wchar *NameW);
|
|
||||||
bool GetArcName(char *Name,wchar *NameW,int MaxSize);
|
|
||||||
bool CheckWinSize();
|
|
||||||
|
|
||||||
int GetRecoverySize(char *Str,int DefSize);
|
|
||||||
|
|
||||||
char Command[NM+16];
|
|
||||||
wchar CommandW[NM+16];
|
|
||||||
|
|
||||||
char ArcName[NM];
|
|
||||||
wchar ArcNameW[NM];
|
|
||||||
|
|
||||||
StringList *FileArgs;
|
|
||||||
StringList *ExclArgs;
|
|
||||||
StringList *InclArgs;
|
|
||||||
StringList *ArcNames;
|
|
||||||
StringList *StoreArgs;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
|
|
||||||
|
|
||||||
inline unsigned int RangeCoder::GetChar()
|
|
||||||
{
|
|
||||||
return(UnpackRead->GetChar());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void RangeCoder::InitDecoder(Unpack *UnpackRead)
|
|
||||||
{
|
|
||||||
RangeCoder::UnpackRead=UnpackRead;
|
|
||||||
|
|
||||||
low=code=0;
|
|
||||||
range=uint(-1);
|
|
||||||
for (int i=0;i < 4;i++)
|
|
||||||
code=(code << 8) | GetChar();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#define ARI_DEC_NORMALIZE(code,low,range,read) \
|
|
||||||
{ \
|
|
||||||
while ((low^(low+range))<TOP || range<BOT && ((range=-low&(BOT-1)),1)) \
|
|
||||||
{ \
|
|
||||||
code=(code << 8) | read->GetChar(); \
|
|
||||||
range <<= 8; \
|
|
||||||
low <<= 8; \
|
|
||||||
} \
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
inline int RangeCoder::GetCurrentCount()
|
|
||||||
{
|
|
||||||
return (code-low)/(range /= SubRange.scale);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
inline uint RangeCoder::GetCurrentShiftCount(uint SHIFT)
|
|
||||||
{
|
|
||||||
return (code-low)/(range >>= SHIFT);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
inline void RangeCoder::Decode()
|
|
||||||
{
|
|
||||||
low += range*SubRange.LowCount;
|
|
||||||
range *= SubRange.HighCount-SubRange.LowCount;
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
/****************************************************************************
|
|
||||||
* Contents: 'Carryless rangecoder' by Dmitry Subbotin *
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
const uint TOP=1 << 24, BOT=1 << 15;
|
|
||||||
|
|
||||||
class RangeCoder
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
void InitDecoder(Unpack *UnpackRead);
|
|
||||||
inline int GetCurrentCount();
|
|
||||||
inline uint GetCurrentShiftCount(uint SHIFT);
|
|
||||||
inline void Decode();
|
|
||||||
inline void PutChar(unsigned int c);
|
|
||||||
inline unsigned int GetChar();
|
|
||||||
|
|
||||||
uint low, code, range;
|
|
||||||
struct SUBRANGE
|
|
||||||
{
|
|
||||||
uint LowCount, HighCount, scale;
|
|
||||||
} SubRange;
|
|
||||||
|
|
||||||
Unpack *UnpackRead;
|
|
||||||
};
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
#ifndef _RAR_COMPRESS_
|
|
||||||
#define _RAR_COMPRESS_
|
|
||||||
|
|
||||||
class ComprDataIO;
|
|
||||||
class PackingFileTable;
|
|
||||||
|
|
||||||
#define CODEBUFSIZE 0x4000
|
|
||||||
#define MAXWINSIZE 0x400000
|
|
||||||
#define MAXWINMASK (MAXWINSIZE-1)
|
|
||||||
|
|
||||||
#define LOW_DIST_REP_COUNT 16
|
|
||||||
|
|
||||||
#define NC 299 /* alphabet = {0, 1, 2, ..., NC - 1} */
|
|
||||||
#define DC 60
|
|
||||||
#define LDC 17
|
|
||||||
#define RC 28
|
|
||||||
#define HUFF_TABLE_SIZE (NC+DC+RC+LDC)
|
|
||||||
#define BC 20
|
|
||||||
|
|
||||||
#define NC20 298 /* alphabet = {0, 1, 2, ..., NC - 1} */
|
|
||||||
#define DC20 48
|
|
||||||
#define RC20 28
|
|
||||||
#define BC20 19
|
|
||||||
#define MC20 257
|
|
||||||
|
|
||||||
enum {CODE_HUFFMAN,CODE_LZ,CODE_LZ2,CODE_REPEATLZ,CODE_CACHELZ,
|
|
||||||
CODE_STARTFILE,CODE_ENDFILE,CODE_VM,CODE_VMDATA};
|
|
||||||
|
|
||||||
|
|
||||||
enum FilterType {
|
|
||||||
FILTER_NONE, FILTER_PPM /*dummy*/, FILTER_E8, FILTER_E8E9,
|
|
||||||
FILTER_UPCASETOLOW, FILTER_AUDIO, FILTER_RGB, FILTER_DELTA,
|
|
||||||
FILTER_ITANIUM, FILTER_E8E9V2
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
#ifndef _RAR_CONSIO_
|
|
||||||
#define _RAR_CONSIO_
|
|
||||||
|
|
||||||
enum {ALARM_SOUND,ERROR_SOUND,QUESTION_SOUND};
|
|
||||||
|
|
||||||
enum PASSWORD_TYPE {PASSWORD_GLOBAL,PASSWORD_FILE,PASSWORD_ARCHIVE};
|
|
||||||
|
|
||||||
void InitConsoleOptions(MESSAGE_TYPE MsgStream,bool Sound);
|
|
||||||
|
|
||||||
#ifndef SILENT
|
|
||||||
void mprintf(const char *fmt,...);
|
|
||||||
void eprintf(const char *fmt,...);
|
|
||||||
void Alarm();
|
|
||||||
void GetPasswordText(char *Str,int MaxLength);
|
|
||||||
unsigned int GetKey();
|
|
||||||
bool GetPassword(PASSWORD_TYPE Type,const char *FileName,char *Password,int MaxLength);
|
|
||||||
int Ask(const char *AskStr);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int KbdAnsi(char *Addr,int Size);
|
|
||||||
void OutComment(char *Comment,int Size);
|
|
||||||
|
|
||||||
#ifdef SILENT
|
|
||||||
#ifdef __GNUC__
|
|
||||||
#define mprintf(args...)
|
|
||||||
#define eprintf(args...)
|
|
||||||
#else
|
|
||||||
inline void mprintf(const char *fmt,const char *a=NULL,const char *b=NULL) {}
|
|
||||||
inline void eprintf(const char *fmt,const char *a=NULL,const char *b=NULL) {}
|
|
||||||
inline void mprintf(const char *fmt,int b) {}
|
|
||||||
inline void eprintf(const char *fmt,int b) {}
|
|
||||||
inline void mprintf(const char *fmt,const char *a,int b) {}
|
|
||||||
inline void eprintf(const char *fmt,const char *a,int b) {}
|
|
||||||
#endif
|
|
||||||
inline void Alarm() {}
|
|
||||||
inline void GetPasswordText(char *Str,int MaxLength) {}
|
|
||||||
inline unsigned int GetKey() {return(0);}
|
|
||||||
inline bool GetPassword(PASSWORD_TYPE Type,const char *FileName,char *Password,int MaxLength) {return(false);}
|
|
||||||
inline int Ask(const char *AskStr) {return(0);}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,61 +0,0 @@
|
|||||||
#include "rar.hpp"
|
|
||||||
|
|
||||||
uint CRCTab[256];
|
|
||||||
|
|
||||||
void InitCRC()
|
|
||||||
{
|
|
||||||
for (int I=0;I<256;I++)
|
|
||||||
{
|
|
||||||
uint C=I;
|
|
||||||
for (int J=0;J<8;J++)
|
|
||||||
C=(C & 1) ? (C>>1)^0xEDB88320L : (C>>1);
|
|
||||||
CRCTab[I]=C;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
uint CRC(uint StartCRC,const void *Addr,uint Size)
|
|
||||||
{
|
|
||||||
if (CRCTab[1]==0)
|
|
||||||
InitCRC();
|
|
||||||
byte *Data=(byte *)Addr;
|
|
||||||
#if defined(LITTLE_ENDIAN) && defined(PRESENT_INT32)
|
|
||||||
while (Size>0 && ((long)Data & 7))
|
|
||||||
{
|
|
||||||
StartCRC=CRCTab[(byte)(StartCRC^Data[0])]^(StartCRC>>8);
|
|
||||||
Size--;
|
|
||||||
Data++;
|
|
||||||
}
|
|
||||||
while (Size>=8)
|
|
||||||
{
|
|
||||||
StartCRC^=*(uint32 *)Data;
|
|
||||||
StartCRC=CRCTab[(byte)StartCRC]^(StartCRC>>8);
|
|
||||||
StartCRC=CRCTab[(byte)StartCRC]^(StartCRC>>8);
|
|
||||||
StartCRC=CRCTab[(byte)StartCRC]^(StartCRC>>8);
|
|
||||||
StartCRC=CRCTab[(byte)StartCRC]^(StartCRC>>8);
|
|
||||||
StartCRC^=*(uint32 *)(Data+4);
|
|
||||||
StartCRC=CRCTab[(byte)StartCRC]^(StartCRC>>8);
|
|
||||||
StartCRC=CRCTab[(byte)StartCRC]^(StartCRC>>8);
|
|
||||||
StartCRC=CRCTab[(byte)StartCRC]^(StartCRC>>8);
|
|
||||||
StartCRC=CRCTab[(byte)StartCRC]^(StartCRC>>8);
|
|
||||||
Data+=8;
|
|
||||||
Size-=8;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
for (int I=0;I<Size;I++)
|
|
||||||
StartCRC=CRCTab[(byte)(StartCRC^Data[I])]^(StartCRC>>8);
|
|
||||||
return(StartCRC);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifndef SFX_MODULE
|
|
||||||
ushort OldCRC(ushort StartCRC,const void *Addr,uint Size)
|
|
||||||
{
|
|
||||||
byte *Data=(byte *)Addr;
|
|
||||||
for (int I=0;I<Size;I++)
|
|
||||||
{
|
|
||||||
StartCRC=(StartCRC+Data[I])&0xffff;
|
|
||||||
StartCRC=((StartCRC<<1)|(StartCRC>>15))&0xffff;
|
|
||||||
}
|
|
||||||
return(StartCRC);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
#ifndef _RAR_CRC_
|
|
||||||
#define _RAR_CRC_
|
|
||||||
|
|
||||||
extern uint CRCTab[256];
|
|
||||||
|
|
||||||
void InitCRC();
|
|
||||||
uint CRC(uint StartCRC,const void *Addr,uint Size);
|
|
||||||
ushort OldCRC(ushort StartCRC,const void *Addr,uint Size);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,60 +0,0 @@
|
|||||||
#ifndef _RAR_CRYPT_
|
|
||||||
#define _RAR_CRYPT_
|
|
||||||
|
|
||||||
enum { OLD_DECODE=0,OLD_ENCODE=1,NEW_CRYPT=2 };
|
|
||||||
|
|
||||||
struct CryptKeyCacheItem
|
|
||||||
{
|
|
||||||
#ifndef _SFX_RTL_
|
|
||||||
CryptKeyCacheItem()
|
|
||||||
{
|
|
||||||
*Password=0;
|
|
||||||
}
|
|
||||||
|
|
||||||
~CryptKeyCacheItem()
|
|
||||||
{
|
|
||||||
memset(AESKey,0,sizeof(AESKey));
|
|
||||||
memset(AESInit,0,sizeof(AESInit));
|
|
||||||
memset(Password,0,sizeof(Password));
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
byte AESKey[16],AESInit[16];
|
|
||||||
char Password[MAXPASSWORD];
|
|
||||||
bool SaltPresent;
|
|
||||||
byte Salt[SALT_SIZE];
|
|
||||||
};
|
|
||||||
|
|
||||||
class CryptData
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
void Encode13(byte *Data,uint Count);
|
|
||||||
void Decode13(byte *Data,uint Count);
|
|
||||||
void Crypt15(byte *Data,uint Count);
|
|
||||||
void UpdKeys(byte *Buf);
|
|
||||||
void Swap(byte *Ch1,byte *Ch2);
|
|
||||||
void SetOldKeys(char *Password);
|
|
||||||
|
|
||||||
Rijndael rin;
|
|
||||||
|
|
||||||
byte SubstTable[256];
|
|
||||||
uint Key[4];
|
|
||||||
ushort OldKey[4];
|
|
||||||
byte PN1,PN2,PN3;
|
|
||||||
|
|
||||||
byte AESKey[16],AESInit[16];
|
|
||||||
|
|
||||||
static CryptKeyCacheItem Cache[4];
|
|
||||||
static int CachePos;
|
|
||||||
public:
|
|
||||||
void SetCryptKeys(char *Password,byte *Salt,bool Encrypt,bool OldOnly=false);
|
|
||||||
void SetAV15Encryption();
|
|
||||||
void SetCmt13Encryption();
|
|
||||||
void EncryptBlock20(byte *Buf);
|
|
||||||
void DecryptBlock20(byte *Buf);
|
|
||||||
void EncryptBlock(byte *Buf,int Size);
|
|
||||||
void DecryptBlock(byte *Buf,int Size);
|
|
||||||
void Crypt(byte *Data,uint Count,int Method);
|
|
||||||
static void SetSalt(byte *Salt,int SaltSize);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
#ifndef _RAR_ENCNAME_
|
|
||||||
#define _RAR_ENCNAME_
|
|
||||||
|
|
||||||
class EncodeFileName
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
void AddFlags(int Value);
|
|
||||||
|
|
||||||
byte *EncName;
|
|
||||||
byte Flags;
|
|
||||||
int FlagBits;
|
|
||||||
int FlagsPos;
|
|
||||||
int DestSize;
|
|
||||||
public:
|
|
||||||
EncodeFileName();
|
|
||||||
int Encode(char *Name,wchar *NameW,byte *EncName);
|
|
||||||
void Decode(char *Name,byte *EncName,int EncSize,wchar *NameW,int MaxDecSize);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,356 +0,0 @@
|
|||||||
#include "rar.hpp"
|
|
||||||
|
|
||||||
|
|
||||||
static bool UserBreak;
|
|
||||||
|
|
||||||
ErrorHandler::ErrorHandler()
|
|
||||||
{
|
|
||||||
Clean();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ErrorHandler::Clean()
|
|
||||||
{
|
|
||||||
ExitCode=SUCCESS;
|
|
||||||
ErrCount=0;
|
|
||||||
EnableBreak=true;
|
|
||||||
Silent=false;
|
|
||||||
DoShutdown=false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ErrorHandler::MemoryError()
|
|
||||||
{
|
|
||||||
MemoryErrorMsg();
|
|
||||||
Throw(MEMORY_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ErrorHandler::OpenError(const char *FileName)
|
|
||||||
{
|
|
||||||
#ifndef SILENT
|
|
||||||
OpenErrorMsg(FileName);
|
|
||||||
Throw(OPEN_ERROR);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ErrorHandler::CloseError(const char *FileName)
|
|
||||||
{
|
|
||||||
#ifndef SILENT
|
|
||||||
if (!UserBreak)
|
|
||||||
{
|
|
||||||
ErrMsg(NULL,St(MErrFClose),FileName);
|
|
||||||
SysErrMsg();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#if !defined(SILENT) || defined(RARDLL)
|
|
||||||
Throw(FATAL_ERROR);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ErrorHandler::ReadError(const char *FileName)
|
|
||||||
{
|
|
||||||
#ifndef SILENT
|
|
||||||
ReadErrorMsg(NULL,FileName);
|
|
||||||
#endif
|
|
||||||
#if !defined(SILENT) || defined(RARDLL)
|
|
||||||
Throw(FATAL_ERROR);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool ErrorHandler::AskRepeatRead(const char *FileName)
|
|
||||||
{
|
|
||||||
#if !defined(SILENT) && !defined(SFX_MODULE) && !defined(_WIN_CE)
|
|
||||||
if (!Silent)
|
|
||||||
{
|
|
||||||
mprintf("\n");
|
|
||||||
Log(NULL,St(MErrRead),FileName);
|
|
||||||
return(Ask(St(MRetryAbort))==1);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
return(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ErrorHandler::WriteError(const char *ArcName,const char *FileName)
|
|
||||||
{
|
|
||||||
#ifndef SILENT
|
|
||||||
WriteErrorMsg(ArcName,FileName);
|
|
||||||
#endif
|
|
||||||
#if !defined(SILENT) || defined(RARDLL)
|
|
||||||
Throw(WRITE_ERROR);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef _WIN_32
|
|
||||||
void ErrorHandler::WriteErrorFAT(const char *FileName)
|
|
||||||
{
|
|
||||||
#if !defined(SILENT) && !defined(SFX_MODULE)
|
|
||||||
SysErrMsg();
|
|
||||||
ErrMsg(NULL,St(MNTFSRequired),FileName);
|
|
||||||
#endif
|
|
||||||
#if !defined(SILENT) && !defined(SFX_MODULE) || defined(RARDLL)
|
|
||||||
Throw(WRITE_ERROR);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
bool ErrorHandler::AskRepeatWrite(const char *FileName)
|
|
||||||
{
|
|
||||||
#if !defined(SILENT) && !defined(_WIN_CE)
|
|
||||||
if (!Silent)
|
|
||||||
{
|
|
||||||
mprintf("\n");
|
|
||||||
Log(NULL,St(MErrWrite),FileName);
|
|
||||||
return(Ask(St(MRetryAbort))==1);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
return(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ErrorHandler::SeekError(const char *FileName)
|
|
||||||
{
|
|
||||||
#ifndef SILENT
|
|
||||||
if (!UserBreak)
|
|
||||||
{
|
|
||||||
ErrMsg(NULL,St(MErrSeek),FileName);
|
|
||||||
SysErrMsg();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#if !defined(SILENT) || defined(RARDLL)
|
|
||||||
Throw(FATAL_ERROR);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ErrorHandler::MemoryErrorMsg()
|
|
||||||
{
|
|
||||||
#ifndef SILENT
|
|
||||||
ErrMsg(NULL,St(MErrOutMem));
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ErrorHandler::OpenErrorMsg(const char *FileName)
|
|
||||||
{
|
|
||||||
OpenErrorMsg(NULL,FileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ErrorHandler::OpenErrorMsg(const char *ArcName,const char *FileName)
|
|
||||||
{
|
|
||||||
#ifndef SILENT
|
|
||||||
Log(ArcName && *ArcName ? ArcName:NULL,St(MCannotOpen),FileName);
|
|
||||||
Alarm();
|
|
||||||
SysErrMsg();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ErrorHandler::CreateErrorMsg(const char *FileName)
|
|
||||||
{
|
|
||||||
CreateErrorMsg(NULL,FileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ErrorHandler::CreateErrorMsg(const char *ArcName,const char *FileName)
|
|
||||||
{
|
|
||||||
#ifndef SILENT
|
|
||||||
Log(ArcName && *ArcName ? ArcName:NULL,St(MCannotCreate),FileName);
|
|
||||||
Alarm();
|
|
||||||
#if defined(_WIN_32) && !defined(_WIN_CE) && !defined(SFX_MODULE) && defined(MAXPATH)
|
|
||||||
if (GetLastError()==ERROR_PATH_NOT_FOUND)
|
|
||||||
{
|
|
||||||
int NameLength=strlen(FileName);
|
|
||||||
if (!IsFullPath(FileName))
|
|
||||||
{
|
|
||||||
char CurDir[NM];
|
|
||||||
GetCurrentDirectory(sizeof(CurDir),CurDir);
|
|
||||||
NameLength+=strlen(CurDir)+1;
|
|
||||||
}
|
|
||||||
if (NameLength>MAXPATH)
|
|
||||||
{
|
|
||||||
Log(ArcName && *ArcName ? ArcName:NULL,St(MMaxPathLimit),MAXPATH);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
SysErrMsg();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ErrorHandler::ReadErrorMsg(const char *ArcName,const char *FileName)
|
|
||||||
{
|
|
||||||
#ifndef SILENT
|
|
||||||
ErrMsg(ArcName,St(MErrRead),FileName);
|
|
||||||
SysErrMsg();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ErrorHandler::WriteErrorMsg(const char *ArcName,const char *FileName)
|
|
||||||
{
|
|
||||||
#ifndef SILENT
|
|
||||||
ErrMsg(ArcName,St(MErrWrite),FileName);
|
|
||||||
SysErrMsg();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ErrorHandler::Exit(int ExitCode)
|
|
||||||
{
|
|
||||||
#ifndef SFX_MODULE
|
|
||||||
Alarm();
|
|
||||||
#endif
|
|
||||||
Throw(ExitCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef GUI
|
|
||||||
void ErrorHandler::ErrMsg(const char *ArcName,const char *fmt,...)
|
|
||||||
{
|
|
||||||
safebuf char Msg[NM+1024];
|
|
||||||
va_list argptr;
|
|
||||||
va_start(argptr,fmt);
|
|
||||||
vsprintf(Msg,fmt,argptr);
|
|
||||||
va_end(argptr);
|
|
||||||
#ifdef _WIN_32
|
|
||||||
if (UserBreak)
|
|
||||||
Sleep(5000);
|
|
||||||
#endif
|
|
||||||
Alarm();
|
|
||||||
if (*Msg)
|
|
||||||
{
|
|
||||||
Log(ArcName,"\n%s",Msg);
|
|
||||||
mprintf("\n%s\n",St(MProgAborted));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
void ErrorHandler::SetErrorCode(int Code)
|
|
||||||
{
|
|
||||||
switch(Code)
|
|
||||||
{
|
|
||||||
case WARNING:
|
|
||||||
case USER_BREAK:
|
|
||||||
if (ExitCode==SUCCESS)
|
|
||||||
ExitCode=Code;
|
|
||||||
break;
|
|
||||||
case FATAL_ERROR:
|
|
||||||
if (ExitCode==SUCCESS || ExitCode==WARNING)
|
|
||||||
ExitCode=FATAL_ERROR;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
ExitCode=Code;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
ErrCount++;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#if !defined(GUI) && !defined(_SFX_RTL_)
|
|
||||||
#ifdef _WIN_32
|
|
||||||
BOOL __stdcall ProcessSignal(DWORD SigType)
|
|
||||||
#else
|
|
||||||
#if defined(__sun)
|
|
||||||
extern "C"
|
|
||||||
#endif
|
|
||||||
void _stdfunction ProcessSignal(int SigType)
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
#ifdef _WIN_32
|
|
||||||
if (SigType==CTRL_LOGOFF_EVENT)
|
|
||||||
return(TRUE);
|
|
||||||
#endif
|
|
||||||
UserBreak=true;
|
|
||||||
mprintf(St(MBreak));
|
|
||||||
for (int I=0;
|
|
||||||
// Igor Pavlov
|
|
||||||
// !File::RemoveCreated() &&
|
|
||||||
I<3;I++)
|
|
||||||
{
|
|
||||||
#ifdef _WIN_32
|
|
||||||
Sleep(100);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
#if defined(USE_RC) && !defined(SFX_MODULE) && !defined(_WIN_CE)
|
|
||||||
ExtRes.UnloadDLL();
|
|
||||||
#endif
|
|
||||||
exit(USER_BREAK);
|
|
||||||
#ifdef _WIN_32
|
|
||||||
return(TRUE);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
void ErrorHandler::SetSignalHandlers(bool Enable)
|
|
||||||
{
|
|
||||||
EnableBreak=Enable;
|
|
||||||
#if !defined(GUI) && !defined(_SFX_RTL_)
|
|
||||||
#ifdef _WIN_32
|
|
||||||
SetConsoleCtrlHandler(Enable ? ProcessSignal:NULL,TRUE);
|
|
||||||
// signal(SIGBREAK,Enable ? ProcessSignal:SIG_IGN);
|
|
||||||
#else
|
|
||||||
signal(SIGINT,Enable ? ProcessSignal:SIG_IGN);
|
|
||||||
signal(SIGTERM,Enable ? ProcessSignal:SIG_IGN);
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ErrorHandler::Throw(int Code)
|
|
||||||
{
|
|
||||||
if (Code==USER_BREAK && !EnableBreak)
|
|
||||||
return;
|
|
||||||
ErrHandler.SetErrorCode(Code);
|
|
||||||
#ifdef ALLOW_EXCEPTIONS
|
|
||||||
throw Code;
|
|
||||||
#else
|
|
||||||
// Igor Pavlov
|
|
||||||
// File::RemoveCreated();
|
|
||||||
exit(Code);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ErrorHandler::SysErrMsg()
|
|
||||||
{
|
|
||||||
#if defined(_WIN_32) && !defined(SFX_MODULE) && !defined(SILENT)
|
|
||||||
#define STRCHR strchr
|
|
||||||
#define ERRCHAR char
|
|
||||||
ERRCHAR *lpMsgBuf=NULL;
|
|
||||||
int ErrType=GetLastError();
|
|
||||||
if (ErrType!=0 && FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
|
|
||||||
NULL,ErrType,MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
|
||||||
(LPTSTR)&lpMsgBuf,0,NULL))
|
|
||||||
{
|
|
||||||
ERRCHAR *CurMsg=lpMsgBuf;
|
|
||||||
while (CurMsg!=NULL)
|
|
||||||
{
|
|
||||||
while (*CurMsg=='\r' || *CurMsg=='\n')
|
|
||||||
CurMsg++;
|
|
||||||
if (*CurMsg==0)
|
|
||||||
break;
|
|
||||||
ERRCHAR *EndMsg=STRCHR(CurMsg,'\r');
|
|
||||||
if (EndMsg==NULL)
|
|
||||||
EndMsg=STRCHR(CurMsg,'\n');
|
|
||||||
if (EndMsg!=NULL)
|
|
||||||
{
|
|
||||||
*EndMsg=0;
|
|
||||||
EndMsg++;
|
|
||||||
}
|
|
||||||
Log(NULL,"\n%s",CurMsg);
|
|
||||||
CurMsg=EndMsg;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
LocalFree( lpMsgBuf );
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
@@ -1,61 +0,0 @@
|
|||||||
#ifndef _RAR_ERRHANDLER_
|
|
||||||
#define _RAR_ERRHANDLER_
|
|
||||||
|
|
||||||
#if (defined(GUI) || !defined(_WIN_32)) && !defined(SFX_MODULE) && !defined(_WIN_CE) || defined(RARDLL)
|
|
||||||
#define ALLOW_EXCEPTIONS
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define rarmalloc malloc
|
|
||||||
#define rarcalloc calloc
|
|
||||||
#define rarrealloc realloc
|
|
||||||
#define rarfree free
|
|
||||||
#define rarstrdup strdup
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
enum { SUCCESS,WARNING,FATAL_ERROR,CRC_ERROR,LOCK_ERROR,WRITE_ERROR,
|
|
||||||
OPEN_ERROR,USER_ERROR,MEMORY_ERROR,CREATE_ERROR,USER_BREAK=255};
|
|
||||||
|
|
||||||
class ErrorHandler
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
void ErrMsg(const char *ArcName,const char *fmt,...);
|
|
||||||
|
|
||||||
int ExitCode;
|
|
||||||
int ErrCount;
|
|
||||||
bool EnableBreak;
|
|
||||||
bool Silent;
|
|
||||||
bool DoShutdown;
|
|
||||||
public:
|
|
||||||
ErrorHandler();
|
|
||||||
void Clean();
|
|
||||||
void MemoryError();
|
|
||||||
void OpenError(const char *FileName);
|
|
||||||
void CloseError(const char *FileName);
|
|
||||||
void ReadError(const char *FileName);
|
|
||||||
bool AskRepeatRead(const char *FileName);
|
|
||||||
void WriteError(const char *ArcName,const char *FileName);
|
|
||||||
void WriteErrorFAT(const char *FileName);
|
|
||||||
bool AskRepeatWrite(const char *FileName);
|
|
||||||
void SeekError(const char *FileName);
|
|
||||||
void MemoryErrorMsg();
|
|
||||||
void OpenErrorMsg(const char *FileName);
|
|
||||||
void OpenErrorMsg(const char *ArcName,const char *FileName);
|
|
||||||
void CreateErrorMsg(const char *FileName);
|
|
||||||
void CreateErrorMsg(const char *ArcName,const char *FileName);
|
|
||||||
void ReadErrorMsg(const char *ArcName,const char *FileName);
|
|
||||||
void WriteErrorMsg(const char *ArcName,const char *FileName);
|
|
||||||
void Exit(int ExitCode);
|
|
||||||
void SetErrorCode(int Code);
|
|
||||||
int GetErrorCode() {return(ExitCode);}
|
|
||||||
int GetErrorCount() {return(ErrCount);}
|
|
||||||
void SetSignalHandlers(bool Enable);
|
|
||||||
void Throw(int Code);
|
|
||||||
void SetSilent(bool Mode) {Silent=Mode;};
|
|
||||||
void SetShutdown(bool Mode) {DoShutdown=Mode;};
|
|
||||||
void SysErrMsg();
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
#ifndef _RAR_EXTINFO_
|
|
||||||
#define _RAR_EXTINFO_
|
|
||||||
|
|
||||||
|
|
||||||
void SetExtraInfo(CommandData *Cmd,Archive &Arc,char *Name,wchar *NameW);
|
|
||||||
void SetExtraInfoNew(CommandData *Cmd,Archive &Arc,char *Name,wchar *NameW);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
#ifndef _RAR_EXTRACT_
|
|
||||||
#define _RAR_EXTRACT_
|
|
||||||
|
|
||||||
enum EXTRACT_ARC_CODE {EXTRACT_ARC_NEXT,EXTRACT_ARC_REPEAT};
|
|
||||||
|
|
||||||
class CmdExtract
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
ComprDataIO DataIO;
|
|
||||||
Unpack *Unp;
|
|
||||||
long TotalFileCount;
|
|
||||||
|
|
||||||
long FileCount;
|
|
||||||
long MatchedArgs;
|
|
||||||
bool FirstFile;
|
|
||||||
bool AllMatchesExact;
|
|
||||||
bool ReconstructDone;
|
|
||||||
|
|
||||||
char ArcName[NM];
|
|
||||||
wchar ArcNameW[NM];
|
|
||||||
|
|
||||||
char Password[MAXPASSWORD];
|
|
||||||
bool PasswordAll;
|
|
||||||
bool PrevExtracted;
|
|
||||||
bool SignatureFound;
|
|
||||||
char DestFileName[NM];
|
|
||||||
wchar DestFileNameW[NM];
|
|
||||||
bool PasswordCancelled;
|
|
||||||
public:
|
|
||||||
CmdExtract();
|
|
||||||
~CmdExtract();
|
|
||||||
void DoExtract(CommandData *Cmd);
|
|
||||||
void ExtractArchiveInit(CommandData *Cmd,Archive &Arc);
|
|
||||||
EXTRACT_ARC_CODE ExtractArchive(CommandData *Cmd);
|
|
||||||
bool ExtractCurrentFile(CommandData *Cmd,Archive &Arc,int HeaderSize,
|
|
||||||
bool &Repeat);
|
|
||||||
static void UnstoreFile(ComprDataIO &DataIO,Int64 DestUnpSize);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
#ifndef _RAR_FILECREATE_
|
|
||||||
#define _RAR_FILECREATE_
|
|
||||||
|
|
||||||
bool FileCreate(RAROptions *Cmd,File *NewFile,char *Name,wchar *NameW,
|
|
||||||
OVERWRITE_MODE Mode,bool *UserReject,Int64 FileSize=INT64ERR,
|
|
||||||
uint FileTime=0);
|
|
||||||
|
|
||||||
#if defined(_WIN_32) && !defined(_WIN_CE)
|
|
||||||
bool UpdateExistingShortName(char *Name,wchar *NameW);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,100 +0,0 @@
|
|||||||
#ifndef _RAR_FILE_
|
|
||||||
#define _RAR_FILE_
|
|
||||||
|
|
||||||
#ifdef _WIN_32
|
|
||||||
typedef HANDLE FileHandle;
|
|
||||||
#define BAD_HANDLE INVALID_HANDLE_VALUE
|
|
||||||
#else
|
|
||||||
typedef FILE* FileHandle;
|
|
||||||
#define BAD_HANDLE NULL
|
|
||||||
#endif
|
|
||||||
|
|
||||||
class RAROptions;
|
|
||||||
|
|
||||||
enum FILE_HANDLETYPE {FILE_HANDLENORMAL,FILE_HANDLESTD,FILE_HANDLEERR};
|
|
||||||
|
|
||||||
enum FILE_ERRORTYPE {FILE_SUCCESS,FILE_NOTFOUND,FILE_READERROR};
|
|
||||||
|
|
||||||
struct FileStat
|
|
||||||
{
|
|
||||||
uint FileAttr;
|
|
||||||
uint FileTime;
|
|
||||||
Int64 FileSize;
|
|
||||||
bool IsDir;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class File
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
void AddFileToList(FileHandle hFile);
|
|
||||||
|
|
||||||
FileHandle hFile;
|
|
||||||
bool LastWrite;
|
|
||||||
FILE_HANDLETYPE HandleType;
|
|
||||||
bool SkipClose;
|
|
||||||
bool IgnoreReadErrors;
|
|
||||||
bool NewFile;
|
|
||||||
bool AllowDelete;
|
|
||||||
bool AllowExceptions;
|
|
||||||
#ifdef _WIN_32
|
|
||||||
bool NoSequentialRead;
|
|
||||||
#endif
|
|
||||||
protected:
|
|
||||||
bool OpenShared;
|
|
||||||
public:
|
|
||||||
char FileName[NM];
|
|
||||||
wchar FileNameW[NM];
|
|
||||||
|
|
||||||
FILE_ERRORTYPE ErrorType;
|
|
||||||
|
|
||||||
uint CloseCount;
|
|
||||||
public:
|
|
||||||
File();
|
|
||||||
virtual ~File();
|
|
||||||
void operator = (File &SrcFile);
|
|
||||||
bool Open(const char *Name,const wchar *NameW=NULL,bool OpenShared=false,bool Update=false);
|
|
||||||
void TOpen(const char *Name,const wchar *NameW=NULL);
|
|
||||||
bool WOpen(const char *Name,const wchar *NameW=NULL);
|
|
||||||
bool Create(const char *Name,const wchar *NameW=NULL);
|
|
||||||
void TCreate(const char *Name,const wchar *NameW=NULL);
|
|
||||||
bool WCreate(const char *Name,const wchar *NameW=NULL);
|
|
||||||
bool Close();
|
|
||||||
void Flush();
|
|
||||||
bool Delete();
|
|
||||||
bool Rename(const char *NewName);
|
|
||||||
void Write(const void *Data,int Size);
|
|
||||||
int Read(void *Data,int Size);
|
|
||||||
int DirectRead(void *Data,int Size);
|
|
||||||
void Seek(Int64 Offset,int Method);
|
|
||||||
bool RawSeek(Int64 Offset,int Method);
|
|
||||||
Int64 Tell();
|
|
||||||
void Prealloc(Int64 Size);
|
|
||||||
byte GetByte();
|
|
||||||
void PutByte(byte Byte);
|
|
||||||
bool Truncate();
|
|
||||||
void SetOpenFileTime(RarTime *ftm,RarTime *ftc=NULL,RarTime *fta=NULL);
|
|
||||||
void SetCloseFileTime(RarTime *ftm,RarTime *fta=NULL);
|
|
||||||
static void SetCloseFileTimeByName(const char *Name,RarTime *ftm,RarTime *fta);
|
|
||||||
void SetOpenFileStat(RarTime *ftm,RarTime *ftc,RarTime *fta);
|
|
||||||
void SetCloseFileStat(RarTime *ftm,RarTime *fta,uint FileAttr);
|
|
||||||
void GetOpenFileTime(RarTime *ft);
|
|
||||||
bool IsOpened() {return(hFile!=BAD_HANDLE);};
|
|
||||||
Int64 FileLength();
|
|
||||||
void SetHandleType(FILE_HANDLETYPE Type);
|
|
||||||
FILE_HANDLETYPE GetHandleType() {return(HandleType);};
|
|
||||||
bool IsDevice();
|
|
||||||
void fprintf(const char *fmt,...);
|
|
||||||
static bool RemoveCreated();
|
|
||||||
FileHandle GetHandle() {return(hFile);};
|
|
||||||
void SetIgnoreReadErrors(bool Mode) {IgnoreReadErrors=Mode;};
|
|
||||||
char *GetName() {return(FileName);}
|
|
||||||
long Copy(File &Dest,Int64 Length=INT64ERR);
|
|
||||||
void SetAllowDelete(bool Allow) {AllowDelete=Allow;}
|
|
||||||
void SetExceptions(bool Allow) {AllowExceptions=Allow;}
|
|
||||||
#ifdef _WIN_32
|
|
||||||
void RemoveSequentialFlag() {NoSequentialRead=true;}
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
#ifndef _RAR_FILEFN_
|
|
||||||
#define _RAR_FILEFN_
|
|
||||||
|
|
||||||
enum MKDIR_CODE {MKDIR_SUCCESS,MKDIR_ERROR,MKDIR_BADPATH};
|
|
||||||
|
|
||||||
MKDIR_CODE MakeDir(const char *Name,const wchar *NameW,uint Attr);
|
|
||||||
void CreatePath(const char *Path,const wchar *PathW,bool SkipLastName);
|
|
||||||
void SetDirTime(const char *Name,RarTime *ftm,RarTime *ftc,RarTime *fta);
|
|
||||||
bool IsRemovable(const char *Name);
|
|
||||||
Int64 GetFreeDisk(const char *Name);
|
|
||||||
bool FileExist(const char *Name,const wchar *NameW=NULL);
|
|
||||||
bool WildFileExist(const char *Name,const wchar *NameW=NULL);
|
|
||||||
bool IsDir(uint Attr);
|
|
||||||
bool IsUnreadable(uint Attr);
|
|
||||||
bool IsLabel(uint Attr);
|
|
||||||
bool IsLink(uint Attr);
|
|
||||||
void SetSFXMode(const char *FileName);
|
|
||||||
void EraseDiskContents(const char *FileName);
|
|
||||||
bool IsDeleteAllowed(uint FileAttr);
|
|
||||||
void PrepareToDelete(const char *Name,const wchar *NameW=NULL);
|
|
||||||
uint GetFileAttr(const char *Name,const wchar *NameW=NULL);
|
|
||||||
bool SetFileAttr(const char *Name,const wchar *NameW,uint Attr);
|
|
||||||
void ConvertNameToFull(const char *Src,char *Dest);
|
|
||||||
void ConvertNameToFull(const wchar *Src,wchar *Dest);
|
|
||||||
char* MkTemp(char *Name);
|
|
||||||
|
|
||||||
|
|
||||||
uint CalcFileCRC(File *SrcFile,Int64 Size=INT64ERR);
|
|
||||||
bool RenameFile(const char *SrcName,const wchar *SrcNameW,const char *DestName,const wchar *DestNameW);
|
|
||||||
bool DelFile(const char *Name);
|
|
||||||
bool DelFile(const char *Name,const wchar *NameW);
|
|
||||||
bool DelDir(const char *Name);
|
|
||||||
bool DelDir(const char *Name,const wchar *NameW);
|
|
||||||
|
|
||||||
#if defined(_WIN_32) && !defined(_WIN_CE)
|
|
||||||
bool SetFileCompression(char *Name,wchar *NameW,bool State);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
#ifndef _RAR_FILESTR_
|
|
||||||
#define _RAR_FILESTR_
|
|
||||||
|
|
||||||
bool ReadTextFile(char *Name,StringList *List,bool Config,
|
|
||||||
bool AbortOnError=false,bool ConvertToAnsi=false,
|
|
||||||
bool Unquote=false,bool SkipComments=false);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
#ifndef _RAR_FINDDATA_
|
|
||||||
#define _RAR_FINDDATA_
|
|
||||||
|
|
||||||
struct FindData
|
|
||||||
{
|
|
||||||
char Name[NM];
|
|
||||||
wchar NameW[NM];
|
|
||||||
Int64 Size;
|
|
||||||
uint FileAttr;
|
|
||||||
uint FileTime;
|
|
||||||
bool IsDir;
|
|
||||||
RarTime mtime;
|
|
||||||
RarTime ctime;
|
|
||||||
RarTime atime;
|
|
||||||
#ifdef _WIN_32
|
|
||||||
char ShortName[NM];
|
|
||||||
FILETIME ftCreationTime;
|
|
||||||
FILETIME ftLastAccessTime;
|
|
||||||
FILETIME ftLastWriteTime;
|
|
||||||
#endif
|
|
||||||
bool Error;
|
|
||||||
};
|
|
||||||
|
|
||||||
class FindFile
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
#ifdef _WIN_32
|
|
||||||
static HANDLE Win32Find(HANDLE hFind,const char *Mask,const wchar *MaskW,struct FindData *fd);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
char FindMask[NM];
|
|
||||||
wchar FindMaskW[NM];
|
|
||||||
int FirstCall;
|
|
||||||
#ifdef _WIN_32
|
|
||||||
HANDLE hFind;
|
|
||||||
#else
|
|
||||||
DIR *dirp;
|
|
||||||
#endif
|
|
||||||
public:
|
|
||||||
FindFile();
|
|
||||||
~FindFile();
|
|
||||||
void SetMask(const char *FindMask);
|
|
||||||
void SetMaskW(const wchar *FindMaskW);
|
|
||||||
bool Next(struct FindData *fd,bool GetSymLink=false);
|
|
||||||
static bool FastFind(const char *FindMask,const wchar *FindMaskW,struct FindData *fd,bool GetSymLink=false);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
#include "rar.hpp"
|
|
||||||
|
|
||||||
BitInput::BitInput()
|
|
||||||
{
|
|
||||||
InBuf=new byte[MAX_SIZE];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
BitInput::~BitInput()
|
|
||||||
{
|
|
||||||
delete[] InBuf;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void BitInput::faddbits(int Bits)
|
|
||||||
{
|
|
||||||
addbits(Bits);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
unsigned int BitInput::fgetbits()
|
|
||||||
{
|
|
||||||
return(getbits());
|
|
||||||
}
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
#ifndef _RAR_GETBITS_
|
|
||||||
#define _RAR_GETBITS_
|
|
||||||
|
|
||||||
class BitInput
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
enum BufferSize {MAX_SIZE=0x8000};
|
|
||||||
protected:
|
|
||||||
int InAddr,InBit;
|
|
||||||
public:
|
|
||||||
BitInput();
|
|
||||||
~BitInput();
|
|
||||||
|
|
||||||
byte *InBuf;
|
|
||||||
|
|
||||||
void InitBitInput()
|
|
||||||
{
|
|
||||||
InAddr=InBit=0;
|
|
||||||
}
|
|
||||||
void addbits(int Bits)
|
|
||||||
{
|
|
||||||
Bits+=InBit;
|
|
||||||
InAddr+=Bits>>3;
|
|
||||||
InBit=Bits&7;
|
|
||||||
}
|
|
||||||
unsigned int getbits()
|
|
||||||
{
|
|
||||||
unsigned int BitField=(uint)InBuf[InAddr] << 16;
|
|
||||||
BitField|=(uint)InBuf[InAddr+1] << 8;
|
|
||||||
BitField|=(uint)InBuf[InAddr+2];
|
|
||||||
BitField >>= (8-InBit);
|
|
||||||
return(BitField & 0xffff);
|
|
||||||
}
|
|
||||||
void faddbits(int Bits);
|
|
||||||
unsigned int fgetbits();
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
#ifndef _RAR_GLOBAL_
|
|
||||||
#define _RAR_GLOBAL_
|
|
||||||
|
|
||||||
#ifdef INCLUDEGLOBAL
|
|
||||||
#define EXTVAR
|
|
||||||
#else
|
|
||||||
#define EXTVAR extern
|
|
||||||
#endif
|
|
||||||
|
|
||||||
EXTVAR ErrorHandler ErrHandler;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,304 +0,0 @@
|
|||||||
#ifndef _RAR_HEADERS_
|
|
||||||
#define _RAR_HEADERS_
|
|
||||||
|
|
||||||
#define SIZEOF_MARKHEAD 7
|
|
||||||
#define SIZEOF_OLDMHD 7
|
|
||||||
#define SIZEOF_NEWMHD 13
|
|
||||||
#define SIZEOF_OLDLHD 21
|
|
||||||
#define SIZEOF_NEWLHD 32
|
|
||||||
#define SIZEOF_SHORTBLOCKHEAD 7
|
|
||||||
#define SIZEOF_LONGBLOCKHEAD 11
|
|
||||||
#define SIZEOF_SUBBLOCKHEAD 14
|
|
||||||
#define SIZEOF_COMMHEAD 13
|
|
||||||
#define SIZEOF_PROTECTHEAD 26
|
|
||||||
#define SIZEOF_AVHEAD 14
|
|
||||||
#define SIZEOF_SIGNHEAD 15
|
|
||||||
#define SIZEOF_UOHEAD 18
|
|
||||||
#define SIZEOF_MACHEAD 22
|
|
||||||
#define SIZEOF_EAHEAD 24
|
|
||||||
#define SIZEOF_BEEAHEAD 24
|
|
||||||
#define SIZEOF_STREAMHEAD 26
|
|
||||||
|
|
||||||
#define PACK_VER 29
|
|
||||||
#define PACK_CRYPT_VER 29
|
|
||||||
#define UNP_VER 29
|
|
||||||
#define CRYPT_VER 29
|
|
||||||
#define AV_VER 20
|
|
||||||
#define PROTECT_VER 20
|
|
||||||
|
|
||||||
#define MHD_VOLUME 0x0001
|
|
||||||
#define MHD_COMMENT 0x0002
|
|
||||||
#define MHD_LOCK 0x0004
|
|
||||||
#define MHD_SOLID 0x0008
|
|
||||||
#define MHD_PACK_COMMENT 0x0010
|
|
||||||
#define MHD_NEWNUMBERING 0x0010
|
|
||||||
#define MHD_AV 0x0020
|
|
||||||
#define MHD_PROTECT 0x0040
|
|
||||||
#define MHD_PASSWORD 0x0080
|
|
||||||
#define MHD_FIRSTVOLUME 0x0100
|
|
||||||
|
|
||||||
#define LHD_SPLIT_BEFORE 0x0001
|
|
||||||
#define LHD_SPLIT_AFTER 0x0002
|
|
||||||
#define LHD_PASSWORD 0x0004
|
|
||||||
#define LHD_COMMENT 0x0008
|
|
||||||
#define LHD_SOLID 0x0010
|
|
||||||
|
|
||||||
#define LHD_WINDOWMASK 0x00e0
|
|
||||||
#define LHD_WINDOW64 0x0000
|
|
||||||
#define LHD_WINDOW128 0x0020
|
|
||||||
#define LHD_WINDOW256 0x0040
|
|
||||||
#define LHD_WINDOW512 0x0060
|
|
||||||
#define LHD_WINDOW1024 0x0080
|
|
||||||
#define LHD_WINDOW2048 0x00a0
|
|
||||||
#define LHD_WINDOW4096 0x00c0
|
|
||||||
#define LHD_DIRECTORY 0x00e0
|
|
||||||
|
|
||||||
#define LHD_LARGE 0x0100
|
|
||||||
#define LHD_UNICODE 0x0200
|
|
||||||
#define LHD_SALT 0x0400
|
|
||||||
#define LHD_VERSION 0x0800
|
|
||||||
#define LHD_EXTTIME 0x1000
|
|
||||||
#define LHD_EXTFLAGS 0x2000
|
|
||||||
|
|
||||||
#define SKIP_IF_UNKNOWN 0x4000
|
|
||||||
#define LONG_BLOCK 0x8000
|
|
||||||
|
|
||||||
#define EARC_NEXT_VOLUME 0x0001
|
|
||||||
#define EARC_DATACRC 0x0002
|
|
||||||
#define EARC_REVSPACE 0x0004
|
|
||||||
#define EARC_VOLNUMBER 0x0008
|
|
||||||
|
|
||||||
enum HEADER_TYPE {
|
|
||||||
MARK_HEAD=0x72,MAIN_HEAD=0x73,FILE_HEAD=0x74,COMM_HEAD=0x75,AV_HEAD=0x76,
|
|
||||||
SUB_HEAD=0x77,PROTECT_HEAD=0x78,SIGN_HEAD=0x79,NEWSUB_HEAD=0x7a,
|
|
||||||
ENDARC_HEAD=0x7b
|
|
||||||
};
|
|
||||||
|
|
||||||
enum { EA_HEAD=0x100,UO_HEAD=0x101,MAC_HEAD=0x102,BEEA_HEAD=0x103,
|
|
||||||
NTACL_HEAD=0x104,STREAM_HEAD=0x105 };
|
|
||||||
|
|
||||||
enum HOST_SYSTEM {
|
|
||||||
HOST_MSDOS=0,HOST_OS2=1,HOST_WIN32=2,HOST_UNIX=3,HOST_MACOS=4,
|
|
||||||
HOST_BEOS=5,HOST_MAX
|
|
||||||
};
|
|
||||||
|
|
||||||
#define SUBHEAD_TYPE_CMT "CMT"
|
|
||||||
#define SUBHEAD_TYPE_ACL "ACL"
|
|
||||||
#define SUBHEAD_TYPE_STREAM "STM"
|
|
||||||
#define SUBHEAD_TYPE_UOWNER "UOW"
|
|
||||||
#define SUBHEAD_TYPE_AV "AV"
|
|
||||||
#define SUBHEAD_TYPE_RR "RR"
|
|
||||||
#define SUBHEAD_TYPE_OS2EA "EA2"
|
|
||||||
#define SUBHEAD_TYPE_BEOSEA "EABE"
|
|
||||||
|
|
||||||
/* new file inherits a subblock when updating a host file */
|
|
||||||
#define SUBHEAD_FLAGS_INHERITED 0x80000000
|
|
||||||
|
|
||||||
#define SUBHEAD_FLAGS_CMT_UNICODE 0x00000001
|
|
||||||
|
|
||||||
struct OldMainHeader
|
|
||||||
{
|
|
||||||
byte Mark[4];
|
|
||||||
ushort HeadSize;
|
|
||||||
byte Flags;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
struct OldFileHeader
|
|
||||||
{
|
|
||||||
uint PackSize;
|
|
||||||
uint UnpSize;
|
|
||||||
ushort FileCRC;
|
|
||||||
ushort HeadSize;
|
|
||||||
uint FileTime;
|
|
||||||
byte FileAttr;
|
|
||||||
byte Flags;
|
|
||||||
byte UnpVer;
|
|
||||||
byte NameSize;
|
|
||||||
byte Method;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
struct MarkHeader
|
|
||||||
{
|
|
||||||
byte Mark[7];
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
struct BaseBlock
|
|
||||||
{
|
|
||||||
ushort HeadCRC;
|
|
||||||
HEADER_TYPE HeadType;//byte
|
|
||||||
ushort Flags;
|
|
||||||
ushort HeadSize;
|
|
||||||
|
|
||||||
bool IsSubBlock()
|
|
||||||
{
|
|
||||||
if (HeadType==SUB_HEAD)
|
|
||||||
return(true);
|
|
||||||
if (HeadType==NEWSUB_HEAD && (Flags & LHD_SOLID)!=0)
|
|
||||||
return(true);
|
|
||||||
return(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct BlockHeader:BaseBlock
|
|
||||||
{
|
|
||||||
union {
|
|
||||||
uint DataSize;
|
|
||||||
uint PackSize;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
struct MainHeader:BlockHeader
|
|
||||||
{
|
|
||||||
ushort HighPosAV;
|
|
||||||
uint PosAV;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#define SALT_SIZE 8
|
|
||||||
|
|
||||||
struct FileHeader:BlockHeader
|
|
||||||
{
|
|
||||||
uint UnpSize;
|
|
||||||
byte HostOS;
|
|
||||||
uint FileCRC;
|
|
||||||
uint FileTime;
|
|
||||||
byte UnpVer;
|
|
||||||
byte Method;
|
|
||||||
ushort NameSize;
|
|
||||||
union {
|
|
||||||
uint FileAttr;
|
|
||||||
uint SubFlags;
|
|
||||||
};
|
|
||||||
/* optional */
|
|
||||||
uint HighPackSize;
|
|
||||||
uint HighUnpSize;
|
|
||||||
/* names */
|
|
||||||
char FileName[NM];
|
|
||||||
wchar FileNameW[NM];
|
|
||||||
/* optional */
|
|
||||||
Array<byte> SubData;
|
|
||||||
byte Salt[SALT_SIZE];
|
|
||||||
|
|
||||||
RarTime mtime;
|
|
||||||
RarTime ctime;
|
|
||||||
RarTime atime;
|
|
||||||
RarTime arctime;
|
|
||||||
/* dummy */
|
|
||||||
Int64 FullPackSize;
|
|
||||||
Int64 FullUnpSize;
|
|
||||||
|
|
||||||
void Clear(int SubDataSize)
|
|
||||||
{
|
|
||||||
SubData.Alloc(SubDataSize);
|
|
||||||
Flags=LONG_BLOCK;
|
|
||||||
SubFlags=0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CmpName(const char *Name)
|
|
||||||
{
|
|
||||||
return(strcmp(FileName,Name)==0);
|
|
||||||
}
|
|
||||||
|
|
||||||
FileHeader& operator = (FileHeader &hd)
|
|
||||||
{
|
|
||||||
SubData.Reset();
|
|
||||||
memcpy(this,&hd,sizeof(*this));
|
|
||||||
SubData.CleanData();
|
|
||||||
SubData=hd.SubData;
|
|
||||||
return(*this);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
struct EndArcHeader:BaseBlock
|
|
||||||
{
|
|
||||||
uint ArcDataCRC;
|
|
||||||
ushort VolNumber;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
struct SubBlockHeader:BlockHeader
|
|
||||||
{
|
|
||||||
ushort SubType;
|
|
||||||
byte Level;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
struct CommentHeader:BaseBlock
|
|
||||||
{
|
|
||||||
ushort UnpSize;
|
|
||||||
byte UnpVer;
|
|
||||||
byte Method;
|
|
||||||
ushort CommCRC;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
struct ProtectHeader:BlockHeader
|
|
||||||
{
|
|
||||||
byte Version;
|
|
||||||
ushort RecSectors;
|
|
||||||
uint TotalBlocks;
|
|
||||||
byte Mark[8];
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
struct AVHeader:BaseBlock
|
|
||||||
{
|
|
||||||
byte UnpVer;
|
|
||||||
byte Method;
|
|
||||||
byte AVVer;
|
|
||||||
uint AVInfoCRC;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
struct SignHeader:BaseBlock
|
|
||||||
{
|
|
||||||
uint CreationTime;
|
|
||||||
ushort ArcNameSize;
|
|
||||||
ushort UserNameSize;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
struct UnixOwnersHeader:SubBlockHeader
|
|
||||||
{
|
|
||||||
ushort OwnerNameSize;
|
|
||||||
ushort GroupNameSize;
|
|
||||||
/* dummy */
|
|
||||||
char OwnerName[NM];
|
|
||||||
char GroupName[NM];
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
struct EAHeader:SubBlockHeader
|
|
||||||
{
|
|
||||||
uint UnpSize;
|
|
||||||
byte UnpVer;
|
|
||||||
byte Method;
|
|
||||||
uint EACRC;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
struct StreamHeader:SubBlockHeader
|
|
||||||
{
|
|
||||||
uint UnpSize;
|
|
||||||
byte UnpVer;
|
|
||||||
byte Method;
|
|
||||||
uint StreamCRC;
|
|
||||||
ushort StreamNameSize;
|
|
||||||
/* dummy */
|
|
||||||
byte StreamName[NM];
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
struct MacFInfoHeader:SubBlockHeader
|
|
||||||
{
|
|
||||||
uint fileType;
|
|
||||||
uint fileCreator;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,274 +0,0 @@
|
|||||||
#include "rar.hpp"
|
|
||||||
|
|
||||||
#ifndef NATIVE_INT64
|
|
||||||
|
|
||||||
Int64::Int64()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Int64::Int64(uint n)
|
|
||||||
{
|
|
||||||
HighPart=0;
|
|
||||||
LowPart=n;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Int64::Int64(uint HighPart,uint LowPart)
|
|
||||||
{
|
|
||||||
Int64::HighPart=HighPart;
|
|
||||||
Int64::LowPart=LowPart;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
Int64 Int64::operator = (Int64 n)
|
|
||||||
{
|
|
||||||
HighPart=n.HighPart;
|
|
||||||
LowPart=n.LowPart;
|
|
||||||
return(*this);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
Int64 Int64::operator << (int n)
|
|
||||||
{
|
|
||||||
Int64 res=*this;
|
|
||||||
while (n--)
|
|
||||||
{
|
|
||||||
res.HighPart<<=1;
|
|
||||||
if (res.LowPart & 0x80000000)
|
|
||||||
res.HighPart|=1;
|
|
||||||
res.LowPart<<=1;
|
|
||||||
}
|
|
||||||
return(res);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Int64 Int64::operator >> (int n)
|
|
||||||
{
|
|
||||||
Int64 res=*this;
|
|
||||||
while (n--)
|
|
||||||
{
|
|
||||||
res.LowPart>>=1;
|
|
||||||
if (res.HighPart & 1)
|
|
||||||
res.LowPart|=0x80000000;
|
|
||||||
res.HighPart>>=1;
|
|
||||||
}
|
|
||||||
return(res);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Int64 operator / (Int64 n1,Int64 n2)
|
|
||||||
{
|
|
||||||
if (n1.HighPart==0 && n2.HighPart==0)
|
|
||||||
return(Int64(0,n1.LowPart/n2.LowPart));
|
|
||||||
int ShiftCount=0;
|
|
||||||
while (n1>n2)
|
|
||||||
{
|
|
||||||
n2=n2<<1;
|
|
||||||
if (++ShiftCount>64)
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
Int64 res=0;
|
|
||||||
while (ShiftCount-- >= 0)
|
|
||||||
{
|
|
||||||
res=res<<1;
|
|
||||||
if (n1>=n2)
|
|
||||||
{
|
|
||||||
n1-=n2;
|
|
||||||
++res;
|
|
||||||
}
|
|
||||||
n2=n2>>1;
|
|
||||||
}
|
|
||||||
return(res);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Int64 operator * (Int64 n1,Int64 n2)
|
|
||||||
{
|
|
||||||
if (n1<0x10000 && n2<0x10000)
|
|
||||||
return(Int64(0,n1.LowPart*n2.LowPart));
|
|
||||||
Int64 res=0;
|
|
||||||
for (int I=0;I<64;I++)
|
|
||||||
{
|
|
||||||
if (n2.LowPart & 1)
|
|
||||||
res+=n1;
|
|
||||||
n1=n1<<1;
|
|
||||||
n2=n2>>1;
|
|
||||||
}
|
|
||||||
return(res);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Int64 operator % (Int64 n1,Int64 n2)
|
|
||||||
{
|
|
||||||
if (n1.HighPart==0 && n2.HighPart==0)
|
|
||||||
return(Int64(0,n1.LowPart%n2.LowPart));
|
|
||||||
return(n1-n1/n2*n2);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Int64 operator + (Int64 n1,Int64 n2)
|
|
||||||
{
|
|
||||||
n1.LowPart+=n2.LowPart;
|
|
||||||
if (n1.LowPart<n2.LowPart)
|
|
||||||
n1.HighPart++;
|
|
||||||
n1.HighPart+=n2.HighPart;
|
|
||||||
return(n1);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Int64 operator - (Int64 n1,Int64 n2)
|
|
||||||
{
|
|
||||||
if (n1.LowPart<n2.LowPart)
|
|
||||||
n1.HighPart--;
|
|
||||||
n1.LowPart-=n2.LowPart;
|
|
||||||
n1.HighPart-=n2.HighPart;
|
|
||||||
return(n1);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Int64 operator += (Int64 &n1,Int64 n2)
|
|
||||||
{
|
|
||||||
n1=n1+n2;
|
|
||||||
return(n1);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Int64 operator -= (Int64 &n1,Int64 n2)
|
|
||||||
{
|
|
||||||
n1=n1-n2;
|
|
||||||
return(n1);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Int64 operator *= (Int64 &n1,Int64 n2)
|
|
||||||
{
|
|
||||||
n1=n1*n2;
|
|
||||||
return(n1);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Int64 operator /= (Int64 &n1,Int64 n2)
|
|
||||||
{
|
|
||||||
n1=n1/n2;
|
|
||||||
return(n1);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Int64 operator | (Int64 n1,Int64 n2)
|
|
||||||
{
|
|
||||||
n1.LowPart|=n2.LowPart;
|
|
||||||
n1.HighPart|=n2.HighPart;
|
|
||||||
return(n1);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Int64 operator & (Int64 n1,Int64 n2)
|
|
||||||
{
|
|
||||||
n1.LowPart&=n2.LowPart;
|
|
||||||
n1.HighPart&=n2.HighPart;
|
|
||||||
return(n1);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
inline void operator -= (Int64 &n1,unsigned int n2)
|
|
||||||
{
|
|
||||||
if (n1.LowPart<n2)
|
|
||||||
n1.HighPart--;
|
|
||||||
n1.LowPart-=n2;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
inline void operator ++ (Int64 &n)
|
|
||||||
{
|
|
||||||
if (++n.LowPart == 0)
|
|
||||||
++n.HighPart;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
inline void operator -- (Int64 &n)
|
|
||||||
{
|
|
||||||
if (n.LowPart-- == 0)
|
|
||||||
n.HighPart--;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
bool operator == (Int64 n1,Int64 n2)
|
|
||||||
{
|
|
||||||
return(n1.LowPart==n2.LowPart && n1.HighPart==n2.HighPart);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool operator > (Int64 n1,Int64 n2)
|
|
||||||
{
|
|
||||||
return((int)n1.HighPart>(int)n2.HighPart || n1.HighPart==n2.HighPart && n1.LowPart>n2.LowPart);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool operator < (Int64 n1,Int64 n2)
|
|
||||||
{
|
|
||||||
return((int)n1.HighPart<(int)n2.HighPart || n1.HighPart==n2.HighPart && n1.LowPart<n2.LowPart);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool operator != (Int64 n1,Int64 n2)
|
|
||||||
{
|
|
||||||
return(n1.LowPart!=n2.LowPart || n1.HighPart!=n2.HighPart);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool operator >= (Int64 n1,Int64 n2)
|
|
||||||
{
|
|
||||||
return(n1>n2 || n1==n2);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool operator <= (Int64 n1,Int64 n2)
|
|
||||||
{
|
|
||||||
return(n1<n2 || n1==n2);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Int64::Set(uint HighPart,uint LowPart)
|
|
||||||
{
|
|
||||||
Int64::HighPart=HighPart;
|
|
||||||
Int64::LowPart=LowPart;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void itoa(Int64 n,char *Str)
|
|
||||||
{
|
|
||||||
if (n<=0xffffffff)
|
|
||||||
{
|
|
||||||
sprintf(Str,"%u",int64to32(n));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
char NumStr[50];
|
|
||||||
int Pos=0;
|
|
||||||
|
|
||||||
do
|
|
||||||
{
|
|
||||||
NumStr[Pos++]=int64to32(n%10)+'0';
|
|
||||||
n=n/10;
|
|
||||||
} while (n!=0);
|
|
||||||
|
|
||||||
for (int I=0;I<Pos;I++)
|
|
||||||
Str[I]=NumStr[Pos-I-1];
|
|
||||||
Str[Pos]=0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Int64 atoil(char *Str)
|
|
||||||
{
|
|
||||||
Int64 n=0;
|
|
||||||
while (*Str>='0' && *Str<='9')
|
|
||||||
{
|
|
||||||
n=n*10+*Str-'0';
|
|
||||||
Str++;
|
|
||||||
}
|
|
||||||
return(n);
|
|
||||||
}
|
|
||||||
@@ -1,86 +0,0 @@
|
|||||||
#ifndef _RAR_INT64_
|
|
||||||
#define _RAR_INT64_
|
|
||||||
|
|
||||||
#if defined(__BORLANDC__) || defined(_MSC_VER)
|
|
||||||
#define NATIVE_INT64
|
|
||||||
typedef __int64 Int64;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(__GNUC__) || defined(__HP_aCC)
|
|
||||||
#define NATIVE_INT64
|
|
||||||
typedef long long Int64;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef NATIVE_INT64
|
|
||||||
|
|
||||||
#define int64to32(x) ((uint)(x))
|
|
||||||
#define int32to64(high,low) ((((Int64)(high))<<32)+(low))
|
|
||||||
#define is64plus(x) (x>=0)
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
class Int64
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Int64();
|
|
||||||
Int64(uint n);
|
|
||||||
Int64(uint HighPart,uint LowPart);
|
|
||||||
|
|
||||||
// Int64 operator = (Int64 n);
|
|
||||||
Int64 operator << (int n);
|
|
||||||
Int64 operator >> (int n);
|
|
||||||
|
|
||||||
friend Int64 operator / (Int64 n1,Int64 n2);
|
|
||||||
friend Int64 operator * (Int64 n1,Int64 n2);
|
|
||||||
friend Int64 operator % (Int64 n1,Int64 n2);
|
|
||||||
friend Int64 operator + (Int64 n1,Int64 n2);
|
|
||||||
friend Int64 operator - (Int64 n1,Int64 n2);
|
|
||||||
friend Int64 operator += (Int64 &n1,Int64 n2);
|
|
||||||
friend Int64 operator -= (Int64 &n1,Int64 n2);
|
|
||||||
friend Int64 operator *= (Int64 &n1,Int64 n2);
|
|
||||||
friend Int64 operator /= (Int64 &n1,Int64 n2);
|
|
||||||
friend Int64 operator | (Int64 n1,Int64 n2);
|
|
||||||
friend Int64 operator & (Int64 n1,Int64 n2);
|
|
||||||
inline friend void operator -= (Int64 &n1,unsigned int n2)
|
|
||||||
{
|
|
||||||
if (n1.LowPart<n2)
|
|
||||||
n1.HighPart--;
|
|
||||||
n1.LowPart-=n2;
|
|
||||||
}
|
|
||||||
inline friend void operator ++ (Int64 &n)
|
|
||||||
{
|
|
||||||
if (++n.LowPart == 0)
|
|
||||||
++n.HighPart;
|
|
||||||
}
|
|
||||||
inline friend void operator -- (Int64 &n)
|
|
||||||
{
|
|
||||||
if (n.LowPart-- == 0)
|
|
||||||
n.HighPart--;
|
|
||||||
}
|
|
||||||
friend bool operator == (Int64 n1,Int64 n2);
|
|
||||||
friend bool operator > (Int64 n1,Int64 n2);
|
|
||||||
friend bool operator < (Int64 n1,Int64 n2);
|
|
||||||
friend bool operator != (Int64 n1,Int64 n2);
|
|
||||||
friend bool operator >= (Int64 n1,Int64 n2);
|
|
||||||
friend bool operator <= (Int64 n1,Int64 n2);
|
|
||||||
|
|
||||||
void Set(uint HighPart,uint LowPart);
|
|
||||||
uint GetLowPart() {return(LowPart);}
|
|
||||||
|
|
||||||
uint LowPart;
|
|
||||||
uint HighPart;
|
|
||||||
};
|
|
||||||
|
|
||||||
inline uint int64to32(Int64 n) {return(n.GetLowPart());}
|
|
||||||
#define int32to64(high,low) (Int64((high),(low)))
|
|
||||||
#define is64plus(x) ((int)(x).HighPart>=0)
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define INT64ERR int32to64(0x80000000,0)
|
|
||||||
#define INT64MAX int32to64(0x7fffffff,0)
|
|
||||||
|
|
||||||
void itoa(Int64 n,char *Str);
|
|
||||||
Int64 atoil(char *Str);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
#ifndef _RAR_ISNT_
|
|
||||||
#define _RAR_ISNT_
|
|
||||||
|
|
||||||
int WinNT();
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
#ifndef _RAR_LIST_
|
|
||||||
#define _RAR_LIST_
|
|
||||||
|
|
||||||
void ListArchive(CommandData *Cmd);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,340 +0,0 @@
|
|||||||
#define MYesNo "_Yes_No"
|
|
||||||
#define MYesNoAll "_Yes_No_All"
|
|
||||||
#define MYesNoAllRenQ "_Yes_No_All_nEver_Rename_Quit"
|
|
||||||
#define MContinueQuit "_Continue_Quit"
|
|
||||||
#define MRetryAbort "_Retry_Abort"
|
|
||||||
#define MCopyright "\nRAR %s Copyright (c) 1993-%d Alexander Roshal %d %s %d"
|
|
||||||
#define MRegTo "\nRegistered to %s\n"
|
|
||||||
#define MShare "\nShareware version Type RAR -? for help\n"
|
|
||||||
#define MUCopyright "\nUNRAR %s freeware Copyright (c) 1993-%d Alexander Roshal\n"
|
|
||||||
#define MBeta "beta"
|
|
||||||
#define MMonthJan "Jan"
|
|
||||||
#define MMonthFeb "Feb"
|
|
||||||
#define MMonthMar "Mar"
|
|
||||||
#define MMonthApr "Apr"
|
|
||||||
#define MMonthMay "May"
|
|
||||||
#define MMonthJun "Jun"
|
|
||||||
#define MMonthJul "Jul"
|
|
||||||
#define MMonthAug "Aug"
|
|
||||||
#define MMonthSep "Sep"
|
|
||||||
#define MMonthOct "Oct"
|
|
||||||
#define MMonthNov "Nov"
|
|
||||||
#define MMonthDec "Dec"
|
|
||||||
#define MRARTitle1 "\nUsage: rar <command> -<switch 1> -<switch N> <archive> <files...>"
|
|
||||||
#define MUNRARTitle1 "\nUsage: unrar <command> -<switch 1> -<switch N> <archive> <files...>"
|
|
||||||
#define MRARTitle2 "\n <@listfiles...> <path_to_extract\\>"
|
|
||||||
#define MCHelpCmd "\n\n<Commands>"
|
|
||||||
#define MCHelpCmdA "\n a Add files to archive"
|
|
||||||
#define MCHelpCmdC "\n c Add archive comment"
|
|
||||||
#define MCHelpCmdCF "\n cf Add files comment"
|
|
||||||
#define MCHelpCmdCW "\n cw Write archive comment to file"
|
|
||||||
#define MCHelpCmdD "\n d Delete files from archive"
|
|
||||||
#define MCHelpCmdE "\n e Extract files to current directory"
|
|
||||||
#define MCHelpCmdF "\n f Freshen files in archive"
|
|
||||||
#define MCHelpCmdI "\n i[par]=<str> Find string in archives"
|
|
||||||
#define MCHelpCmdK "\n k Lock archive"
|
|
||||||
#define MCHelpCmdL "\n l[t,b] List archive [technical, bare]"
|
|
||||||
#define MCHelpCmdM "\n m[f] Move to archive [files only]"
|
|
||||||
#define MCHelpCmdP "\n p Print file to stdout"
|
|
||||||
#define MCHelpCmdR "\n r Repair archive"
|
|
||||||
#define MCHelpCmdRC "\n rc Reconstruct missing volumes"
|
|
||||||
#define MCHelpCmdRN "\n rn Rename archived files"
|
|
||||||
#define MCHelpCmdRR "\n rr[N] Add data recovery record"
|
|
||||||
#define MCHelpCmdRV "\n rv[N] Create recovery volumes"
|
|
||||||
#define MCHelpCmdS "\n s[name|-] Convert archive to or from SFX"
|
|
||||||
#define MCHelpCmdT "\n t Test archive files"
|
|
||||||
#define MCHelpCmdU "\n u Update files in archive"
|
|
||||||
#define MCHelpCmdV "\n v[t,b] Verbosely list archive [technical,bare]"
|
|
||||||
#define MCHelpCmdX "\n x Extract files with full path"
|
|
||||||
#define MCHelpSw "\n\n<Switches>"
|
|
||||||
#define MCHelpSwm "\n - Stop switches scanning"
|
|
||||||
#define MCHelpSwAC "\n ac Clear Archive attribute after compression or extraction"
|
|
||||||
#define MCHelpSwAD "\n ad Append archive name to destination path"
|
|
||||||
#define MCHelpSwAG "\n ag[format] Generate archive name using the current date"
|
|
||||||
#define MCHelpSwAO "\n ao Add files with Archive attribute set"
|
|
||||||
#define MCHelpSwAP "\n ap<path> Set path inside archive"
|
|
||||||
#define MCHelpSwAS "\n as Synchronize archive contents"
|
|
||||||
#define MCHelpSwAV "\n av Put authenticity verification (registered versions only)"
|
|
||||||
#define MCHelpSwAVm "\n av- Disable authenticity verification check"
|
|
||||||
#define MCHelpSwCm "\n c- Disable comments show"
|
|
||||||
#define MCHelpSwCFGm "\n cfg- Disable read configuration"
|
|
||||||
#define MCHelpSwCL "\n cl Convert names to lower case"
|
|
||||||
#define MCHelpSwCU "\n cu Convert names to upper case"
|
|
||||||
#define MCHelpSwDF "\n df Delete files after archiving"
|
|
||||||
#define MCHelpSwDH "\n dh Open shared files"
|
|
||||||
#define MCHelpSwDS "\n ds Disable name sort for solid archive"
|
|
||||||
#define MCHelpSwEa "\n e[+]<attr> Set file exclude and include attributes"
|
|
||||||
#define MCHelpSwED "\n ed Do not add empty directories"
|
|
||||||
#define MCHelpSwEE "\n ee Do not save and extract extended attributes"
|
|
||||||
#define MCHelpSwEN "\n en Do not put 'end of archive' block"
|
|
||||||
#define MCHelpSwEP "\n ep Exclude paths from names"
|
|
||||||
#define MCHelpSwEP1 "\n ep1 Exclude base directory from names"
|
|
||||||
#define MCHelpSwEP2 "\n ep2 Expand paths to full"
|
|
||||||
#define MCHelpSwEP3 "\n ep3 Expand paths to full including the drive letter"
|
|
||||||
#define MCHelpSwF "\n f Freshen files"
|
|
||||||
#define MCHelpSwHP "\n hp[password] Encrypt both file data and headers"
|
|
||||||
#define MCHelpSwIDP "\n id[c,d,p,q] Disable messages"
|
|
||||||
#define MCHelpSwIEML "\n ieml[addr] Send archive by email"
|
|
||||||
#define MCHelpSwIERR "\n ierr Send all messages to stderr"
|
|
||||||
#define MCHelpSwILOG "\n ilog[name] Log errors to file (registered versions only)"
|
|
||||||
#define MCHelpSwINUL "\n inul Disable all messages"
|
|
||||||
#define MCHelpSwIOFF "\n ioff Turn PC off after completing an operation"
|
|
||||||
#define MCHelpSwISND "\n isnd Enable sound"
|
|
||||||
#define MCHelpSwK "\n k Lock archive"
|
|
||||||
#define MCHelpSwKB "\n kb Keep broken extracted files"
|
|
||||||
#define MCHelpSwMn "\n m<0..5> Set compression level (0-store...3-default...5-maximal)"
|
|
||||||
#define MCHelpSwMC "\n mc<par> Set advanced compression parameters"
|
|
||||||
#define MCHelpSwMD "\n md<size> Dictionary size in KB (64,128,256,512,1024,2048,4096 or A-G)"
|
|
||||||
#define MCHelpSwMS "\n ms[ext;ext] Specify file types to store"
|
|
||||||
#define MCHelpSwN "\n n<file> Include only specified file"
|
|
||||||
#define MCHelpSwNa "\n n@ Read file names to include from stdin"
|
|
||||||
#define MCHelpSwNal "\n n@<list> Include files in specified list file"
|
|
||||||
#define MCHelpSwOp "\n o+ Overwrite existing files"
|
|
||||||
#define MCHelpSwOm "\n o- Do not overwrite existing files"
|
|
||||||
#define MCHelpSwOC "\n oc Set NTFS Compressed attribute"
|
|
||||||
#define MCHelpSwOL "\n ol Save symbolic links as the link instead of the file"
|
|
||||||
#define MCHelpSwOS "\n os Save NTFS streams"
|
|
||||||
#define MCHelpSwOW "\n ow Save or restore file owner and group"
|
|
||||||
#define MCHelpSwP "\n p[password] Set password"
|
|
||||||
#define MCHelpSwPm "\n p- Do not query password"
|
|
||||||
#define MCHelpSwR "\n r Recurse subdirectories"
|
|
||||||
#define MCHelpSwR0 "\n r0 Recurse subdirectories for wildcard names only"
|
|
||||||
#define MCHelpSwRI "\n ri<P>[:<S>] Set priority (0-default,1-min..15-max) and sleep time in ms"
|
|
||||||
#define MCHelpSwRR "\n rr[N] Add data recovery record"
|
|
||||||
#define MCHelpSwRV "\n rv[N] Create recovery volumes"
|
|
||||||
#define MCHelpSwS "\n s[<N>,v[-],e] Create solid archive"
|
|
||||||
#define MCHelpSwSm "\n s- Disable solid archiving"
|
|
||||||
#define MCHelpSwSFX "\n sfx[name] Create SFX archive"
|
|
||||||
#define MCHelpSwSI "\n si[name] Read data from standard input (stdin)"
|
|
||||||
#define MCHelpSwT "\n t Test files after archiving"
|
|
||||||
#define MCHelpSwTK "\n tk Keep original archive time"
|
|
||||||
#define MCHelpSwTL "\n tl Set archive time to latest file"
|
|
||||||
#define MCHelpSwTN "\n tn<time> Process files newer than <time>"
|
|
||||||
#define MCHelpSwTO "\n to<time> Process files older than <time>"
|
|
||||||
#define MCHelpSwTA "\n ta<date> Process files modified after <date> in YYYYMMDDHHMMSS format"
|
|
||||||
#define MCHelpSwTB "\n tb<date> Process files modified before <date> in YYYYMMDDHHMMSS format"
|
|
||||||
#define MCHelpSwTS "\n ts<m,c,a>[N] Save or restore file time (modification, creation, access)"
|
|
||||||
#define MCHelpSwU "\n u Update files"
|
|
||||||
#define MCHelpSwV "\n v Create volumes with size autodetection or list all volumes"
|
|
||||||
#define MCHelpSwVUnr "\n v List all volumes"
|
|
||||||
#define MCHelpSwVn "\n v<size>[k,b] Create volumes with size=<size>*1000 [*1024, *1]"
|
|
||||||
#define MCHelpSwVD "\n vd Erase disk contents before creating volume"
|
|
||||||
#define MCHelpSwVER "\n ver[n] File version control"
|
|
||||||
#define MCHelpSwVN "\n vn Use the old style volume naming scheme"
|
|
||||||
#define MCHelpSwVP "\n vp Pause before each volume"
|
|
||||||
#define MCHelpSwW "\n w<path> Assign work directory"
|
|
||||||
#define MCHelpSwX "\n x<file> Exclude specified file"
|
|
||||||
#define MCHelpSwXa "\n x@ Read file names to exclude from stdin"
|
|
||||||
#define MCHelpSwXal "\n x@<list> Exclude files in specified list file"
|
|
||||||
#define MCHelpSwY "\n y Assume Yes on all queries"
|
|
||||||
#define MCHelpSwZ "\n z<file> Read archive comment from file"
|
|
||||||
#define MBadArc "\nERROR: Bad archive %s\n"
|
|
||||||
#define MAskPsw "Enter password (will not be echoed)"
|
|
||||||
#define MAskPswEcho "Enter password"
|
|
||||||
#define MReAskPsw "\nReenter password: "
|
|
||||||
#define MFor " for "
|
|
||||||
#define MNotMatchPsw "\nERROR: Passwords do not match\n"
|
|
||||||
#define MErrWrite "Write error in the file %s"
|
|
||||||
#define MErrRead "Read error in the file %s"
|
|
||||||
#define MErrSeek "Seek error in the file %s"
|
|
||||||
#define MErrFClose "Cannot close the file %s"
|
|
||||||
#define MErrOutMem "Not enough memory"
|
|
||||||
#define MErrBrokenArc "Corrupt archive - use 'Repair' command"
|
|
||||||
#define MProgAborted "Program aborted"
|
|
||||||
#define MErrRename "\nCannot rename %s to %s"
|
|
||||||
#define MAbsNextVol "\nCannot find volume %s"
|
|
||||||
#define MBreak "\nUser break\n"
|
|
||||||
#define MAskCreatVol "\nCreate next volume ?"
|
|
||||||
#define MAskNextDisk "\nDisk full. Insert next"
|
|
||||||
#define MCreatVol "\n\nCreating %sarchive %s\n"
|
|
||||||
#define MAskNextVol "\nInsert disk with %s"
|
|
||||||
#define MTestVol "\n\nTesting archive %s\n"
|
|
||||||
#define MExtrVol "\n\nExtracting from %s\n"
|
|
||||||
#define MConverting "\nConverting %s"
|
|
||||||
#define MCvtToSFX "\nConvert archives to SFX"
|
|
||||||
#define MCvtFromSFX "\nRemoving SFX module"
|
|
||||||
#define MNotSFX "\n%s is not SFX archive"
|
|
||||||
#define MNotRAR "\n%s is not RAR archive"
|
|
||||||
#define MNotFirstVol "\n%s is not the first volume"
|
|
||||||
#define MCvtOldFormat "\n%s - cannot convert to SFX archive with old format"
|
|
||||||
#define MCannotCreate "\nCannot create %s"
|
|
||||||
#define MCannotOpen "\nCannot open %s"
|
|
||||||
#define MUnknownMeth "\nUnknown method in %s"
|
|
||||||
#define MVerRequired "\nYou need RAR %d.%d to unpack it"
|
|
||||||
#define MOk " OK"
|
|
||||||
#define MDone "\nDone"
|
|
||||||
#define MLockingArc "\nLocking archive"
|
|
||||||
#define MNotMdfOld "\n\nERROR: Cannot modify old format archive"
|
|
||||||
#define MNotMdfLock "\n\nERROR: Locked archive"
|
|
||||||
#define MNotMdfVol "\n\nERROR: Cannot modify volume"
|
|
||||||
#define MVerifyAV "\nVerifying authenticity information ... "
|
|
||||||
#define MFailedAV " Failed\n"
|
|
||||||
#define MStrAV1 "\n\nArchive %s"
|
|
||||||
#define MStrAV2 "\ncreated at %s"
|
|
||||||
#define MStrAV3 "\nby %s\n"
|
|
||||||
#define MLogFailedAV "Invalid authenticity information"
|
|
||||||
#define MAddingAV "\nAdding authenticity verification "
|
|
||||||
#define MAVOldStyle "\n\nOld style authenticity information"
|
|
||||||
#define MPackAskReg "\nEvaluation copy. Please register.\n"
|
|
||||||
#define MCreateArchive "\nCreating %sarchive %s\n"
|
|
||||||
#define MUpdateArchive "\nUpdating %sarchive %s\n"
|
|
||||||
#define MAddSolid "solid "
|
|
||||||
#define MAddFile "\nAdding %-58s "
|
|
||||||
#define MUpdFile "\nUpdating %-58s "
|
|
||||||
#define MAddPoints "\n... %-58s "
|
|
||||||
#define MCannotUpdPswSolid "\nERROR: Cannot update solid archives with password\n"
|
|
||||||
#define MMoveDelFiles "\n\nDeleting files %s..."
|
|
||||||
#define MMoveDelDirs "and directories"
|
|
||||||
#define MMoveDelFile "\nDeleting %-30s"
|
|
||||||
#define MMoveDeleted " deleted"
|
|
||||||
#define MMoveNotDeleted " NOT DELETED"
|
|
||||||
#define MClearAttrib "\n\nClearing attributes..."
|
|
||||||
#define MMoveDelDir "\nDeleting directory %-30s"
|
|
||||||
#define MWarErrFOpen "\nWARNING: Cannot open %d %s"
|
|
||||||
#define MErrOpenFiles "files"
|
|
||||||
#define MErrOpenFile "file"
|
|
||||||
#define MAddNoFiles "\nWARNING: No files"
|
|
||||||
#define MMdfEncrSol "\n%s: encrypted"
|
|
||||||
#define MCannotMdfEncrSol "\nCannot modify solid archive containing encrypted files"
|
|
||||||
#define MAddAnalyze "\nAnalyzing archived files: "
|
|
||||||
#define MRepacking "\nRepacking archived files: "
|
|
||||||
#define MCRCFailed "\n%-20s - CRC failed"
|
|
||||||
#define MExtrTest "\n\nTesting archive %s\n"
|
|
||||||
#define MExtracting "\n\nExtracting from %s\n"
|
|
||||||
#define MUseCurPsw "\n%s - use current password ?"
|
|
||||||
#define MCreatDir "\nCreating %-56s"
|
|
||||||
#define MExtrSkipFile "\nSkipping %-56s"
|
|
||||||
#define MExtrTestFile "\nTesting %-56s"
|
|
||||||
#define MExtrFile "\nExtracting %-56s"
|
|
||||||
#define MExtrPoints "\n... %-56s"
|
|
||||||
#define MExtrErrMkDir "\nCannot create directory %s"
|
|
||||||
#define MExtrPrinting "\n------ Printing %s\n\n"
|
|
||||||
#define MEncrBadCRC "\nEncrypted file: CRC failed in %s (password incorrect ?)"
|
|
||||||
#define MExtrNoFiles "\nNo files to extract"
|
|
||||||
#define MExtrAllOk "\nAll OK"
|
|
||||||
#define MExtrTotalErr "\nTotal errors: %ld"
|
|
||||||
#define MFileExists "\n\n%s already exists. Overwrite it ?"
|
|
||||||
#define MAskOverwrite "\nOverwrite %s ?"
|
|
||||||
#define MAskNewName "\nEnter new name: "
|
|
||||||
#define MLogMainHead "\nThe archive header is corrupt"
|
|
||||||
#define MLogFileHead "\n%s - the file header is corrupt"
|
|
||||||
#define MLogCommHead "\nThe comment header is corrupt\n"
|
|
||||||
#define MLogProtectHead "The data recovery header is corrupt"
|
|
||||||
#define MReadStdinCmt "\nReading comment from stdin\n"
|
|
||||||
#define MReadCommFrom "\nReading comment from %s"
|
|
||||||
#define MDelComment "\nDeleting comment from %s"
|
|
||||||
#define MAddComment "\nAdding comment to %s"
|
|
||||||
#define MFCommAdd "\nAdding file comments"
|
|
||||||
#define MAskFComm "\n\nReading comment for %s : %s from stdin\n"
|
|
||||||
#define MLogCommBrk "\nThe archive comment is corrupt"
|
|
||||||
#define MCommAskCont "\nPress 'Enter' to continue or 'Q' to quit:"
|
|
||||||
#define MLogBrokFCmt "\nThe file comment is corrupt"
|
|
||||||
#define MAbsDestName "\nDestination file name required"
|
|
||||||
#define MWriteCommTo "\nWrite comment to %s"
|
|
||||||
#define MCommNotPres "\nComment is not present"
|
|
||||||
#define MDelFrom "\nDeleting from %s"
|
|
||||||
#define MDeleting "\nDeleting %s"
|
|
||||||
#define MEraseArc "\nErasing empty archive %s"
|
|
||||||
#define MNoDelFiles "\nNo files to delete"
|
|
||||||
#define MLogTitle "\n\n-------- %2d %s %d, archive %s\n"
|
|
||||||
#define MPathTooLong "\nERROR: Path too long\n"
|
|
||||||
#define MListSolid "Solid "
|
|
||||||
#define MListSFX "SFX "
|
|
||||||
#define MListVol1 "volume"
|
|
||||||
#define MListVol2 "Volume"
|
|
||||||
#define MListArc1 "archive"
|
|
||||||
#define MListArc2 "Archive"
|
|
||||||
#define MListRecRec "\nRecovery record is present\n"
|
|
||||||
#define MListLock "\nLock is present\n"
|
|
||||||
#define MListPathComm "\nPathname/Comment\n "
|
|
||||||
#define MListName "\n Name "
|
|
||||||
#define MListTitle " Size Packed Ratio Date Time Attr CRC Meth Ver\n"
|
|
||||||
#define MListTechTitle " Host OS Solid Old\n"
|
|
||||||
#define MListEAHead "\n OS/2 extended attributes"
|
|
||||||
#define MListUOHead "\n Unix Owner/Group data: %-14s %-14s"
|
|
||||||
#define MListBeEAHead "\n BeOS extended attributes"
|
|
||||||
#define MListNTACLHead "\n NTFS security data"
|
|
||||||
#define MListStrmHead "\n NTFS stream: %s"
|
|
||||||
#define MListUnkHead "\n Unknown subheader type: 0x%04x"
|
|
||||||
#define MFileComment "\nComment: "
|
|
||||||
#define MYes "Yes"
|
|
||||||
#define MNo "No"
|
|
||||||
#define MListNoFiles " 0 files\n"
|
|
||||||
#define MRprReconstr "\nReconstructing %s"
|
|
||||||
#define MRprBuild "\nBuilding %s"
|
|
||||||
#define MRprOldFormat "\nCannot repair archive with old format"
|
|
||||||
#define MRprFind "\nFound %s"
|
|
||||||
#define MRprAskIsSol "\nThe archive header is corrupt. Mark archive as solid ?"
|
|
||||||
#define MRprNoFiles "\nNo files found"
|
|
||||||
#define MRprSuspEntry "\n\nSuspicious entry %s"
|
|
||||||
#define MRprDir "\nDirectory"
|
|
||||||
#define MRprSuspSize "\nSize %ld Packed %ld"
|
|
||||||
#define MRprSuspAdd "\nAdd it to archive ?"
|
|
||||||
#define MLogUnexpEOF "\nUnexpected end of archive"
|
|
||||||
#define MRepAskReconst "\nReconstruct archive structure ?"
|
|
||||||
#define MRecScanning "\nScanning..."
|
|
||||||
#define MRecRNotFound "\nData recovery record not found"
|
|
||||||
#define MRecRFound "\nData recovery record found"
|
|
||||||
#define MRecSecDamage "\nSector %ld (offsets %lX...%lX) damaged"
|
|
||||||
#define MRecCorrected " - data recovered"
|
|
||||||
#define MRecFailed " - cannot recover data"
|
|
||||||
#define MAddRecRec "\nAdding data recovery record"
|
|
||||||
#define MEraseForVolume "\n\nErasing contents of drive %c:\n"
|
|
||||||
#define MGetOwnersError "\nWARNING: Cannot get %s owner and group\n"
|
|
||||||
#define MErrGetOwnerID "\nWARNING: Cannot get owner %s ID\n"
|
|
||||||
#define MErrGetGroupID "\nWARNING: Cannot get group %s ID\n"
|
|
||||||
#define MOwnersBroken "\nERROR: %s group and owner data are corrupt\n"
|
|
||||||
#define MSetOwnersError "\nWARNING: Cannot set %s owner and group\n"
|
|
||||||
#define MErrLnkRead "\nWARNING: Cannot read symbolic link %s"
|
|
||||||
#define MErrCreateLnk "\nWARNING: Cannot create link %s"
|
|
||||||
#define MSymLinkExists "\nWARNING: Symbolic link %s already exists"
|
|
||||||
#define MAskRetryCreate "\nCannot create %s. Retry ?"
|
|
||||||
#define MListMACHead1 "\n MacOS file type: %c%c%c%c ; "
|
|
||||||
#define MListMACHead2 "file creator: %c%c%c%c\n"
|
|
||||||
#define MDataBadCRC "\n%-20s : packed data CRC failed in volume %s"
|
|
||||||
#define MFileRO "\n%s is read-only"
|
|
||||||
#define MACLGetError "\nWARNING: Cannot get %s security data\n"
|
|
||||||
#define MACLSetError "\nWARNING: Cannot set %s security data\n"
|
|
||||||
#define MACLBroken "\nERROR: %s security data are corrupt\n"
|
|
||||||
#define MACLUnknown "\nWARNING: Unknown format of %s security data\n"
|
|
||||||
#define MStreamBroken "\nERROR: %s stream data are corrupt\n"
|
|
||||||
#define MStreamUnknown "\nWARNING: Unknown format of %s stream data\n"
|
|
||||||
#define MInvalidName "\nERROR: Invalid file name %s"
|
|
||||||
#define MEABroken "\nERROR: %s extended attributes are corrupt\n"
|
|
||||||
#define MEAUnknHeader "\nWARNING: %s - unknown format of extended attributes\n"
|
|
||||||
#define MCannotSetEA "\nWARNING: cannot set extended attributes to %s\n"
|
|
||||||
#define MCannotGetEA "\nERROR: Cannot get extended attributes of %s\n"
|
|
||||||
#define MShowEA " (+EA)"
|
|
||||||
#define MSkipEA "\n...skipping extended attributes"
|
|
||||||
#define MProcessArc "\n\nProcessing archive %s"
|
|
||||||
#define MSyncScanError "\nFile search errors, cannot synchronize archive"
|
|
||||||
#define MCorrectingName "\nWARNING: Attempting to correct the invalid file name"
|
|
||||||
#define MUnpCannotMerge "\nWARNING: You need to start extraction from a previous volume to unpack %s"
|
|
||||||
#define MUnknownOption "\nERROR: Unknown option: %s"
|
|
||||||
#define MSubHeadCorrupt "\nERROR: Corrupt data header found, ignored"
|
|
||||||
#define MSubHeadUnknown "\nWARNING: Unknown data header format, ignored"
|
|
||||||
#define MSubHeadDataCRC "\nERROR: Corrupt %s data block"
|
|
||||||
#define MSubHeadType "\nData header type: %s"
|
|
||||||
#define MScanError "\nCannot read contents of %s"
|
|
||||||
#define MNotVolume "\n%s is not volume"
|
|
||||||
#define MRecVolDiffSets "\nERROR: %s and %s belong to different sets"
|
|
||||||
#define MRecVolMissing "\n%d volumes missing"
|
|
||||||
#define MRecVolFound "\n%d recovery volumes found"
|
|
||||||
#define MRecVolAllExist "\nNothing to reconstruct"
|
|
||||||
#define MRecVolCannotFix "\nReconstruction impossible"
|
|
||||||
#define MReconstructing "\nReconstructing..."
|
|
||||||
#define MCreating "\nCreating %s"
|
|
||||||
#define MRenaming "\nRenaming %s to %s"
|
|
||||||
#define MNTFSRequired "\nWrite error: only NTFS file system supports files larger than 4 GB"
|
|
||||||
#define MErrChangeAttr "\nWARNING: Cannot change attributes of %s"
|
|
||||||
#define MWrongSFXVer "\nERROR: default SFX module does not support RAR %d.%d archives"
|
|
||||||
#define MCannotEncName "\nCannot encrypt archive already contained encrypted files"
|
|
||||||
#define MCannotEmail "\nCannot email the file %s"
|
|
||||||
#define MCopyrightS "\nRAR SFX archive"
|
|
||||||
#define MSHelpCmd "\n\n<Commands>"
|
|
||||||
#define MSHelpCmdE "\n -x Extract from archive (default)"
|
|
||||||
#define MSHelpCmdT "\n -t Test archive files"
|
|
||||||
#define MSHelpCmdV "\n -v Verbosely list contents of archive"
|
|
||||||
#define MMaxPathLimit "\nTotal path and file name length must not exceed %d characters"
|
|
||||||
#define MRecVolLimit "\nTotal number of usual and recovery volumes must not exceed 255"
|
|
||||||
#define MVolumeNumber "volume %d"
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
#ifndef _RAR_LOG_
|
|
||||||
#define _RAR_LOG_
|
|
||||||
|
|
||||||
void InitLogOptions(char *LogName);
|
|
||||||
|
|
||||||
#ifndef SILENT
|
|
||||||
void Log(const char *ArcName,const char *Format,...);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef SILENT
|
|
||||||
#ifdef __GNUC__
|
|
||||||
#define Log(args...)
|
|
||||||
#else
|
|
||||||
inline void Log(const char *a,const char *b,const char *c=NULL,const char *d=NULL) {}
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
#ifndef _RAR_MATCH_
|
|
||||||
#define _RAR_MATCH_
|
|
||||||
|
|
||||||
enum {MATCH_NAMES,MATCH_PATH,MATCH_EXACTPATH,MATCH_SUBPATH,MATCH_WILDSUBPATH};
|
|
||||||
|
|
||||||
#define MATCH_MODEMASK 0x0000ffff
|
|
||||||
|
|
||||||
bool CmpName(char *Wildcard,char *Name,int CmpPath);
|
|
||||||
bool CmpName(wchar *Wildcard,wchar *Name,int CmpPath);
|
|
||||||
|
|
||||||
int stricompc(const char *Str1,const char *Str2);
|
|
||||||
int stricompcw(const wchar *Str1,const wchar *Str2);
|
|
||||||
int strnicompc(const char *Str1,const char *Str2,int N);
|
|
||||||
int strnicompcw(const wchar *Str1,const wchar *Str2,int N);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,600 +0,0 @@
|
|||||||
/****************************************************************************
|
|
||||||
* This file is part of PPMd project *
|
|
||||||
* Written and distributed to public domain by Dmitry Shkarin 1997, *
|
|
||||||
* 1999-2000 *
|
|
||||||
* Contents: model description and encoding/decoding routines *
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
inline PPM_CONTEXT* PPM_CONTEXT::createChild(ModelPPM *Model,STATE* pStats,
|
|
||||||
STATE& FirstState)
|
|
||||||
{
|
|
||||||
PPM_CONTEXT* pc = (PPM_CONTEXT*) Model->SubAlloc.AllocContext();
|
|
||||||
if ( pc )
|
|
||||||
{
|
|
||||||
pc->NumStats=1;
|
|
||||||
pc->OneState=FirstState;
|
|
||||||
pc->Suffix=this;
|
|
||||||
pStats->Successor=pc;
|
|
||||||
}
|
|
||||||
return pc;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
ModelPPM::ModelPPM()
|
|
||||||
{
|
|
||||||
MinContext=NULL;
|
|
||||||
MaxContext=NULL;
|
|
||||||
MedContext=NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ModelPPM::RestartModelRare()
|
|
||||||
{
|
|
||||||
int i, k, m;
|
|
||||||
memset(CharMask,0,sizeof(CharMask));
|
|
||||||
SubAlloc.InitSubAllocator();
|
|
||||||
InitRL=-(MaxOrder < 12 ? MaxOrder:12)-1;
|
|
||||||
MinContext = MaxContext = (PPM_CONTEXT*) SubAlloc.AllocContext();
|
|
||||||
MinContext->Suffix=NULL;
|
|
||||||
OrderFall=MaxOrder;
|
|
||||||
MinContext->U.SummFreq=(MinContext->NumStats=256)+1;
|
|
||||||
FoundState=MinContext->U.Stats=(STATE*)SubAlloc.AllocUnits(256/2);
|
|
||||||
for (RunLength=InitRL, PrevSuccess=i=0;i < 256;i++)
|
|
||||||
{
|
|
||||||
MinContext->U.Stats[i].Symbol=i;
|
|
||||||
MinContext->U.Stats[i].Freq=1;
|
|
||||||
MinContext->U.Stats[i].Successor=NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const ushort InitBinEsc[]={
|
|
||||||
0x3CDD,0x1F3F,0x59BF,0x48F3,0x64A1,0x5ABC,0x6632,0x6051
|
|
||||||
};
|
|
||||||
|
|
||||||
for (i=0;i < 128;i++)
|
|
||||||
for (k=0;k < 8;k++)
|
|
||||||
for (m=0;m < 64;m += 8)
|
|
||||||
BinSumm[i][k+m]=BIN_SCALE-InitBinEsc[k]/(i+2);
|
|
||||||
for (i=0;i < 25;i++)
|
|
||||||
for (k=0;k < 16;k++)
|
|
||||||
SEE2Cont[i][k].init(5*i+10);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ModelPPM::StartModelRare(int MaxOrder)
|
|
||||||
{
|
|
||||||
int i, k, m ,Step;
|
|
||||||
EscCount=1;
|
|
||||||
/*
|
|
||||||
if (MaxOrder < 2)
|
|
||||||
{
|
|
||||||
memset(CharMask,0,sizeof(CharMask));
|
|
||||||
OrderFall=ModelPPM::MaxOrder;
|
|
||||||
MinContext=MaxContext;
|
|
||||||
while (MinContext->Suffix != NULL)
|
|
||||||
{
|
|
||||||
MinContext=MinContext->Suffix;
|
|
||||||
OrderFall--;
|
|
||||||
}
|
|
||||||
FoundState=MinContext->U.Stats;
|
|
||||||
MinContext=MaxContext;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
*/
|
|
||||||
{
|
|
||||||
ModelPPM::MaxOrder=MaxOrder;
|
|
||||||
RestartModelRare();
|
|
||||||
NS2BSIndx[0]=2*0;
|
|
||||||
NS2BSIndx[1]=2*1;
|
|
||||||
memset(NS2BSIndx+2,2*2,9);
|
|
||||||
memset(NS2BSIndx+11,2*3,256-11);
|
|
||||||
for (i=0;i < 3;i++)
|
|
||||||
NS2Indx[i]=i;
|
|
||||||
for (m=i, k=Step=1;i < 256;i++)
|
|
||||||
{
|
|
||||||
NS2Indx[i]=m;
|
|
||||||
if ( !--k )
|
|
||||||
{
|
|
||||||
k = ++Step;
|
|
||||||
m++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
memset(HB2Flag,0,0x40);
|
|
||||||
memset(HB2Flag+0x40,0x08,0x100-0x40);
|
|
||||||
DummySEE2Cont.Shift=PERIOD_BITS;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void PPM_CONTEXT::rescale(ModelPPM *Model)
|
|
||||||
{
|
|
||||||
int OldNS=NumStats, i=NumStats-1, Adder, EscFreq;
|
|
||||||
STATE* p1, * p;
|
|
||||||
for (p=Model->FoundState;p != U.Stats;p--)
|
|
||||||
_PPMD_SWAP(p[0],p[-1]);
|
|
||||||
U.Stats->Freq += 4;
|
|
||||||
U.SummFreq += 4;
|
|
||||||
EscFreq=U.SummFreq-p->Freq;
|
|
||||||
Adder=(Model->OrderFall != 0);
|
|
||||||
U.SummFreq = (p->Freq=(p->Freq+Adder) >> 1);
|
|
||||||
do
|
|
||||||
{
|
|
||||||
EscFreq -= (++p)->Freq;
|
|
||||||
U.SummFreq += (p->Freq=(p->Freq+Adder) >> 1);
|
|
||||||
if (p[0].Freq > p[-1].Freq)
|
|
||||||
{
|
|
||||||
STATE tmp=*(p1=p);
|
|
||||||
do
|
|
||||||
{
|
|
||||||
p1[0]=p1[-1];
|
|
||||||
} while (--p1 != U.Stats && tmp.Freq > p1[-1].Freq);
|
|
||||||
*p1=tmp;
|
|
||||||
}
|
|
||||||
} while ( --i );
|
|
||||||
if (p->Freq == 0)
|
|
||||||
{
|
|
||||||
do
|
|
||||||
{
|
|
||||||
i++;
|
|
||||||
} while ((--p)->Freq == 0);
|
|
||||||
EscFreq += i;
|
|
||||||
if ((NumStats -= i) == 1)
|
|
||||||
{
|
|
||||||
STATE tmp=*U.Stats;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
tmp.Freq-=(tmp.Freq >> 1);
|
|
||||||
EscFreq>>=1;
|
|
||||||
} while (EscFreq > 1);
|
|
||||||
Model->SubAlloc.FreeUnits(U.Stats,(OldNS+1) >> 1);
|
|
||||||
*(Model->FoundState=&OneState)=tmp; return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
U.SummFreq += (EscFreq -= (EscFreq >> 1));
|
|
||||||
int n0=(OldNS+1) >> 1, n1=(NumStats+1) >> 1;
|
|
||||||
if (n0 != n1)
|
|
||||||
U.Stats = (STATE*) Model->SubAlloc.ShrinkUnits(U.Stats,n0,n1);
|
|
||||||
Model->FoundState=U.Stats;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
inline PPM_CONTEXT* ModelPPM::CreateSuccessors(bool Skip,STATE* p1)
|
|
||||||
{
|
|
||||||
#ifdef __ICL
|
|
||||||
static
|
|
||||||
#endif
|
|
||||||
STATE UpState;
|
|
||||||
PPM_CONTEXT* pc=MinContext, * UpBranch=FoundState->Successor;
|
|
||||||
STATE * p, * ps[MAX_O], ** pps=ps;
|
|
||||||
if ( !Skip )
|
|
||||||
{
|
|
||||||
*pps++ = FoundState;
|
|
||||||
if ( !pc->Suffix )
|
|
||||||
goto NO_LOOP;
|
|
||||||
}
|
|
||||||
if ( p1 )
|
|
||||||
{
|
|
||||||
p=p1;
|
|
||||||
pc=pc->Suffix;
|
|
||||||
goto LOOP_ENTRY;
|
|
||||||
}
|
|
||||||
do
|
|
||||||
{
|
|
||||||
pc=pc->Suffix;
|
|
||||||
if (pc->NumStats != 1)
|
|
||||||
{
|
|
||||||
if ((p=pc->U.Stats)->Symbol != FoundState->Symbol)
|
|
||||||
do
|
|
||||||
{
|
|
||||||
p++;
|
|
||||||
} while (p->Symbol != FoundState->Symbol);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
p=&(pc->OneState);
|
|
||||||
LOOP_ENTRY:
|
|
||||||
if (p->Successor != UpBranch)
|
|
||||||
{
|
|
||||||
pc=p->Successor;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
*pps++ = p;
|
|
||||||
} while ( pc->Suffix );
|
|
||||||
NO_LOOP:
|
|
||||||
if (pps == ps)
|
|
||||||
return pc;
|
|
||||||
UpState.Symbol=*(byte*) UpBranch;
|
|
||||||
UpState.Successor=(PPM_CONTEXT*) (((byte*) UpBranch)+1);
|
|
||||||
if (pc->NumStats != 1)
|
|
||||||
{
|
|
||||||
if ((byte*) pc <= SubAlloc.pText)
|
|
||||||
return(NULL);
|
|
||||||
if ((p=pc->U.Stats)->Symbol != UpState.Symbol)
|
|
||||||
do
|
|
||||||
{
|
|
||||||
p++;
|
|
||||||
} while (p->Symbol != UpState.Symbol);
|
|
||||||
uint cf=p->Freq-1;
|
|
||||||
uint s0=pc->U.SummFreq-pc->NumStats-cf;
|
|
||||||
UpState.Freq=1+((2*cf <= s0)?(5*cf > s0):((2*cf+3*s0-1)/(2*s0)));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
UpState.Freq=pc->OneState.Freq;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
pc = pc->createChild(this,*--pps,UpState);
|
|
||||||
if ( !pc )
|
|
||||||
return NULL;
|
|
||||||
} while (pps != ps);
|
|
||||||
return pc;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
inline void ModelPPM::UpdateModel()
|
|
||||||
{
|
|
||||||
STATE fs = *FoundState, *p = NULL;
|
|
||||||
PPM_CONTEXT *pc, *Successor;
|
|
||||||
uint ns1, ns, cf, sf, s0;
|
|
||||||
if (fs.Freq < MAX_FREQ/4 && (pc=MinContext->Suffix) != NULL)
|
|
||||||
{
|
|
||||||
if (pc->NumStats != 1)
|
|
||||||
{
|
|
||||||
if ((p=pc->U.Stats)->Symbol != fs.Symbol)
|
|
||||||
{
|
|
||||||
do
|
|
||||||
{
|
|
||||||
p++;
|
|
||||||
} while (p->Symbol != fs.Symbol);
|
|
||||||
if (p[0].Freq >= p[-1].Freq)
|
|
||||||
{
|
|
||||||
_PPMD_SWAP(p[0],p[-1]);
|
|
||||||
p--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (p->Freq < MAX_FREQ-9)
|
|
||||||
{
|
|
||||||
p->Freq += 2;
|
|
||||||
pc->U.SummFreq += 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
p=&(pc->OneState);
|
|
||||||
p->Freq += (p->Freq < 32);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ( !OrderFall )
|
|
||||||
{
|
|
||||||
MinContext=MaxContext=FoundState->Successor=CreateSuccessors(TRUE,p);
|
|
||||||
if ( !MinContext )
|
|
||||||
goto RESTART_MODEL;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
*SubAlloc.pText++ = fs.Symbol;
|
|
||||||
Successor = (PPM_CONTEXT*) SubAlloc.pText;
|
|
||||||
if (SubAlloc.pText >= SubAlloc.FakeUnitsStart)
|
|
||||||
goto RESTART_MODEL;
|
|
||||||
if ( fs.Successor )
|
|
||||||
{
|
|
||||||
if ((byte*) fs.Successor <= SubAlloc.pText &&
|
|
||||||
(fs.Successor=CreateSuccessors(FALSE,p)) == NULL)
|
|
||||||
goto RESTART_MODEL;
|
|
||||||
if ( !--OrderFall )
|
|
||||||
{
|
|
||||||
Successor=fs.Successor;
|
|
||||||
SubAlloc.pText -= (MaxContext != MinContext);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
FoundState->Successor=Successor;
|
|
||||||
fs.Successor=MinContext;
|
|
||||||
}
|
|
||||||
s0=MinContext->U.SummFreq-(ns=MinContext->NumStats)-(fs.Freq-1);
|
|
||||||
for (pc=MaxContext;pc != MinContext;pc=pc->Suffix)
|
|
||||||
{
|
|
||||||
if ((ns1=pc->NumStats) != 1)
|
|
||||||
{
|
|
||||||
if ((ns1 & 1) == 0)
|
|
||||||
{
|
|
||||||
pc->U.Stats=(STATE*) SubAlloc.ExpandUnits(pc->U.Stats,ns1 >> 1);
|
|
||||||
if ( !pc->U.Stats )
|
|
||||||
goto RESTART_MODEL;
|
|
||||||
}
|
|
||||||
pc->U.SummFreq += (2*ns1 < ns)+2*((4*ns1 <= ns) & (pc->U.SummFreq <= 8*ns1));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
p=(STATE*) SubAlloc.AllocUnits(1);
|
|
||||||
if ( !p )
|
|
||||||
goto RESTART_MODEL;
|
|
||||||
*p=pc->OneState;
|
|
||||||
pc->U.Stats=p;
|
|
||||||
if (p->Freq < MAX_FREQ/4-1)
|
|
||||||
p->Freq += p->Freq;
|
|
||||||
else
|
|
||||||
p->Freq = MAX_FREQ-4;
|
|
||||||
pc->U.SummFreq=p->Freq+InitEsc+(ns > 3);
|
|
||||||
}
|
|
||||||
cf=2*fs.Freq*(pc->U.SummFreq+6);
|
|
||||||
sf=s0+pc->U.SummFreq;
|
|
||||||
if (cf < 6*sf)
|
|
||||||
{
|
|
||||||
cf=1+(cf > sf)+(cf >= 4*sf);
|
|
||||||
pc->U.SummFreq += 3;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
cf=4+(cf >= 9*sf)+(cf >= 12*sf)+(cf >= 15*sf);
|
|
||||||
pc->U.SummFreq += cf;
|
|
||||||
}
|
|
||||||
p=pc->U.Stats+ns1;
|
|
||||||
p->Successor=Successor;
|
|
||||||
p->Symbol = fs.Symbol;
|
|
||||||
p->Freq = cf;
|
|
||||||
pc->NumStats=++ns1;
|
|
||||||
}
|
|
||||||
MaxContext=MinContext=fs.Successor;
|
|
||||||
return;
|
|
||||||
RESTART_MODEL:
|
|
||||||
RestartModelRare();
|
|
||||||
EscCount=0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Tabulated escapes for exponential symbol distribution
|
|
||||||
static const byte ExpEscape[16]={ 25,14, 9, 7, 5, 5, 4, 4, 4, 3, 3, 3, 2, 2, 2, 2 };
|
|
||||||
#define GET_MEAN(SUMM,SHIFT,ROUND) ((SUMM+(1 << (SHIFT-ROUND))) >> (SHIFT))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
inline void PPM_CONTEXT::decodeBinSymbol(ModelPPM *Model)
|
|
||||||
{
|
|
||||||
STATE& rs=OneState;
|
|
||||||
Model->HiBitsFlag=Model->HB2Flag[Model->FoundState->Symbol];
|
|
||||||
ushort& bs=Model->BinSumm[rs.Freq-1][Model->PrevSuccess+
|
|
||||||
Model->NS2BSIndx[Suffix->NumStats-1]+
|
|
||||||
Model->HiBitsFlag+2*Model->HB2Flag[rs.Symbol]+
|
|
||||||
((Model->RunLength >> 26) & 0x20)];
|
|
||||||
if (Model->Coder.GetCurrentShiftCount(TOT_BITS) < bs)
|
|
||||||
{
|
|
||||||
Model->FoundState=&rs;
|
|
||||||
rs.Freq += (rs.Freq < 128);
|
|
||||||
Model->Coder.SubRange.LowCount=0;
|
|
||||||
Model->Coder.SubRange.HighCount=bs;
|
|
||||||
bs = SHORT16(bs+INTERVAL-GET_MEAN(bs,PERIOD_BITS,2));
|
|
||||||
Model->PrevSuccess=1;
|
|
||||||
Model->RunLength++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Model->Coder.SubRange.LowCount=bs;
|
|
||||||
bs = SHORT16(bs-GET_MEAN(bs,PERIOD_BITS,2));
|
|
||||||
Model->Coder.SubRange.HighCount=BIN_SCALE;
|
|
||||||
Model->InitEsc=ExpEscape[bs >> 10];
|
|
||||||
Model->NumMasked=1;
|
|
||||||
Model->CharMask[rs.Symbol]=Model->EscCount;
|
|
||||||
Model->PrevSuccess=0;
|
|
||||||
Model->FoundState=NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
inline void PPM_CONTEXT::update1(ModelPPM *Model,STATE* p)
|
|
||||||
{
|
|
||||||
(Model->FoundState=p)->Freq += 4;
|
|
||||||
U.SummFreq += 4;
|
|
||||||
if (p[0].Freq > p[-1].Freq)
|
|
||||||
{
|
|
||||||
_PPMD_SWAP(p[0],p[-1]);
|
|
||||||
Model->FoundState=--p;
|
|
||||||
if (p->Freq > MAX_FREQ)
|
|
||||||
rescale(Model);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
inline bool PPM_CONTEXT::decodeSymbol1(ModelPPM *Model)
|
|
||||||
{
|
|
||||||
Model->Coder.SubRange.scale=U.SummFreq;
|
|
||||||
STATE* p=U.Stats;
|
|
||||||
int i, HiCnt;
|
|
||||||
int count=Model->Coder.GetCurrentCount();
|
|
||||||
if (count>=Model->Coder.SubRange.scale)
|
|
||||||
return(false);
|
|
||||||
if (count < (HiCnt=p->Freq))
|
|
||||||
{
|
|
||||||
Model->PrevSuccess=(2*(Model->Coder.SubRange.HighCount=HiCnt) > Model->Coder.SubRange.scale);
|
|
||||||
Model->RunLength += Model->PrevSuccess;
|
|
||||||
(Model->FoundState=p)->Freq=(HiCnt += 4);
|
|
||||||
U.SummFreq += 4;
|
|
||||||
if (HiCnt > MAX_FREQ)
|
|
||||||
rescale(Model);
|
|
||||||
Model->Coder.SubRange.LowCount=0;
|
|
||||||
return(true);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
if (Model->FoundState==NULL)
|
|
||||||
return(false);
|
|
||||||
Model->PrevSuccess=0;
|
|
||||||
i=NumStats-1;
|
|
||||||
while ((HiCnt += (++p)->Freq) <= count)
|
|
||||||
if (--i == 0)
|
|
||||||
{
|
|
||||||
Model->HiBitsFlag=Model->HB2Flag[Model->FoundState->Symbol];
|
|
||||||
Model->Coder.SubRange.LowCount=HiCnt;
|
|
||||||
Model->CharMask[p->Symbol]=Model->EscCount;
|
|
||||||
i=(Model->NumMasked=NumStats)-1;
|
|
||||||
Model->FoundState=NULL;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
Model->CharMask[(--p)->Symbol]=Model->EscCount;
|
|
||||||
} while ( --i );
|
|
||||||
Model->Coder.SubRange.HighCount=Model->Coder.SubRange.scale;
|
|
||||||
return(true);
|
|
||||||
}
|
|
||||||
Model->Coder.SubRange.LowCount=(Model->Coder.SubRange.HighCount=HiCnt)-p->Freq;
|
|
||||||
update1(Model,p);
|
|
||||||
return(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
inline void PPM_CONTEXT::update2(ModelPPM *Model,STATE* p)
|
|
||||||
{
|
|
||||||
(Model->FoundState=p)->Freq += 4;
|
|
||||||
U.SummFreq += 4;
|
|
||||||
if (p->Freq > MAX_FREQ)
|
|
||||||
rescale(Model);
|
|
||||||
Model->EscCount++;
|
|
||||||
Model->RunLength=Model->InitRL;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
inline SEE2_CONTEXT* PPM_CONTEXT::makeEscFreq2(ModelPPM *Model,int Diff)
|
|
||||||
{
|
|
||||||
SEE2_CONTEXT* psee2c;
|
|
||||||
if (NumStats != 256)
|
|
||||||
{
|
|
||||||
psee2c=Model->SEE2Cont[Model->NS2Indx[Diff-1]]+
|
|
||||||
(Diff < Suffix->NumStats-NumStats)+
|
|
||||||
2*(U.SummFreq < 11*NumStats)+4*(Model->NumMasked > Diff)+
|
|
||||||
Model->HiBitsFlag;
|
|
||||||
Model->Coder.SubRange.scale=psee2c->getMean();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
psee2c=&Model->DummySEE2Cont;
|
|
||||||
Model->Coder.SubRange.scale=1;
|
|
||||||
}
|
|
||||||
return psee2c;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
inline bool PPM_CONTEXT::decodeSymbol2(ModelPPM *Model)
|
|
||||||
{
|
|
||||||
int count, HiCnt, i=NumStats-Model->NumMasked;
|
|
||||||
SEE2_CONTEXT* psee2c=makeEscFreq2(Model,i);
|
|
||||||
STATE* ps[256], ** pps=ps, * p=U.Stats-1;
|
|
||||||
HiCnt=0;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
do
|
|
||||||
{
|
|
||||||
p++;
|
|
||||||
} while (Model->CharMask[p->Symbol] == Model->EscCount);
|
|
||||||
HiCnt += p->Freq;
|
|
||||||
*pps++ = p;
|
|
||||||
} while ( --i );
|
|
||||||
Model->Coder.SubRange.scale += HiCnt;
|
|
||||||
count=Model->Coder.GetCurrentCount();
|
|
||||||
if (count>=Model->Coder.SubRange.scale)
|
|
||||||
return(false);
|
|
||||||
p=*(pps=ps);
|
|
||||||
if (count < HiCnt)
|
|
||||||
{
|
|
||||||
HiCnt=0;
|
|
||||||
while ((HiCnt += p->Freq) <= count)
|
|
||||||
p=*++pps;
|
|
||||||
Model->Coder.SubRange.LowCount = (Model->Coder.SubRange.HighCount=HiCnt)-p->Freq;
|
|
||||||
psee2c->update();
|
|
||||||
update2(Model,p);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Model->Coder.SubRange.LowCount=HiCnt;
|
|
||||||
Model->Coder.SubRange.HighCount=Model->Coder.SubRange.scale;
|
|
||||||
i=NumStats-Model->NumMasked;
|
|
||||||
pps--;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
Model->CharMask[(*++pps)->Symbol]=Model->EscCount;
|
|
||||||
} while ( --i );
|
|
||||||
psee2c->Summ += Model->Coder.SubRange.scale;
|
|
||||||
Model->NumMasked = NumStats;
|
|
||||||
}
|
|
||||||
return(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
inline void ModelPPM::ClearMask()
|
|
||||||
{
|
|
||||||
EscCount=1;
|
|
||||||
memset(CharMask,0,sizeof(CharMask));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool ModelPPM::DecodeInit(Unpack *UnpackRead,int &EscChar)
|
|
||||||
{
|
|
||||||
int MaxOrder=UnpackRead->GetChar();
|
|
||||||
|
|
||||||
// Igor Pavlov
|
|
||||||
bool Reset = ((MaxOrder & 0x20) != 0);
|
|
||||||
|
|
||||||
int MaxMB;
|
|
||||||
if (Reset)
|
|
||||||
MaxMB=UnpackRead->GetChar();
|
|
||||||
else
|
|
||||||
if (SubAlloc.GetAllocatedMemory()==0)
|
|
||||||
return(false);
|
|
||||||
if (MaxOrder & 0x40)
|
|
||||||
EscChar=UnpackRead->GetChar();
|
|
||||||
Coder.InitDecoder(UnpackRead);
|
|
||||||
if (Reset)
|
|
||||||
{
|
|
||||||
MaxOrder=(MaxOrder & 0x1f)+1;
|
|
||||||
if (MaxOrder>16)
|
|
||||||
MaxOrder=16+(MaxOrder-16)*3;
|
|
||||||
if (MaxOrder==1)
|
|
||||||
{
|
|
||||||
SubAlloc.StopSubAllocator();
|
|
||||||
return(false);
|
|
||||||
}
|
|
||||||
SubAlloc.StartSubAllocator(MaxMB+1);
|
|
||||||
StartModelRare(MaxOrder);
|
|
||||||
}
|
|
||||||
return(MinContext!=NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int ModelPPM::DecodeChar()
|
|
||||||
{
|
|
||||||
if ((byte*)MinContext <= SubAlloc.pText || (byte*)MinContext>SubAlloc.HeapEnd)
|
|
||||||
return(-1);
|
|
||||||
if (MinContext->NumStats != 1)
|
|
||||||
{
|
|
||||||
if (!MinContext->decodeSymbol1(this))
|
|
||||||
return(-1);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
MinContext->decodeBinSymbol(this);
|
|
||||||
Coder.Decode();
|
|
||||||
while ( !FoundState )
|
|
||||||
{
|
|
||||||
ARI_DEC_NORMALIZE(Coder.code,Coder.low,Coder.range,Coder.UnpackRead);
|
|
||||||
do
|
|
||||||
{
|
|
||||||
OrderFall++;
|
|
||||||
MinContext=MinContext->Suffix;
|
|
||||||
if ((byte*)MinContext <= SubAlloc.pText || (byte*)MinContext>SubAlloc.HeapEnd)
|
|
||||||
return(-1);
|
|
||||||
} while (MinContext->NumStats == NumMasked);
|
|
||||||
if (!MinContext->decodeSymbol2(this))
|
|
||||||
return(-1);
|
|
||||||
Coder.Decode();
|
|
||||||
}
|
|
||||||
int Symbol=FoundState->Symbol;
|
|
||||||
if (!OrderFall && (byte*) FoundState->Successor > SubAlloc.pText)
|
|
||||||
MinContext=MaxContext=FoundState->Successor;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
UpdateModel();
|
|
||||||
if (EscCount == 0)
|
|
||||||
ClearMask();
|
|
||||||
}
|
|
||||||
ARI_DEC_NORMALIZE(Coder.code,Coder.low,Coder.range,Coder.UnpackRead);
|
|
||||||
return(Symbol);
|
|
||||||
}
|
|
||||||
@@ -1,126 +0,0 @@
|
|||||||
#ifndef _RAR_PPMMODEL_
|
|
||||||
#define _RAR_PPMMODEL_
|
|
||||||
|
|
||||||
#include "coder.hpp"
|
|
||||||
#include "suballoc.hpp"
|
|
||||||
|
|
||||||
const int MAX_O=64; /* maximum allowed model order */
|
|
||||||
|
|
||||||
const int INT_BITS=7, PERIOD_BITS=7, TOT_BITS=INT_BITS+PERIOD_BITS,
|
|
||||||
INTERVAL=1 << INT_BITS, BIN_SCALE=1 << TOT_BITS, MAX_FREQ=124;
|
|
||||||
|
|
||||||
#pragma pack(1)
|
|
||||||
|
|
||||||
struct SEE2_CONTEXT
|
|
||||||
{ // SEE-contexts for PPM-contexts with masked symbols
|
|
||||||
ushort Summ;
|
|
||||||
byte Shift, Count;
|
|
||||||
void init(int InitVal)
|
|
||||||
{
|
|
||||||
Summ=InitVal << (Shift=PERIOD_BITS-4);
|
|
||||||
Count=4;
|
|
||||||
}
|
|
||||||
uint getMean()
|
|
||||||
{
|
|
||||||
uint RetVal=SHORT16(Summ) >> Shift;
|
|
||||||
Summ -= RetVal;
|
|
||||||
return RetVal+(RetVal == 0);
|
|
||||||
}
|
|
||||||
void update()
|
|
||||||
{
|
|
||||||
if (Shift < PERIOD_BITS && --Count == 0)
|
|
||||||
{
|
|
||||||
Summ += Summ;
|
|
||||||
Count=3 << Shift++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class ModelPPM;
|
|
||||||
struct PPM_CONTEXT;
|
|
||||||
|
|
||||||
struct STATE
|
|
||||||
{
|
|
||||||
byte Symbol;
|
|
||||||
byte Freq;
|
|
||||||
PPM_CONTEXT* Successor;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct FreqData
|
|
||||||
{
|
|
||||||
ushort SummFreq;
|
|
||||||
STATE _PACK_ATTR * Stats;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct PPM_CONTEXT
|
|
||||||
{
|
|
||||||
ushort NumStats;
|
|
||||||
union
|
|
||||||
{
|
|
||||||
FreqData U;
|
|
||||||
STATE OneState;
|
|
||||||
};
|
|
||||||
|
|
||||||
PPM_CONTEXT* Suffix;
|
|
||||||
inline void encodeBinSymbol(ModelPPM *Model,int symbol); // MaxOrder:
|
|
||||||
inline void encodeSymbol1(ModelPPM *Model,int symbol); // ABCD context
|
|
||||||
inline void encodeSymbol2(ModelPPM *Model,int symbol); // BCD suffix
|
|
||||||
inline void decodeBinSymbol(ModelPPM *Model); // BCDE successor
|
|
||||||
inline bool decodeSymbol1(ModelPPM *Model); // other orders:
|
|
||||||
inline bool decodeSymbol2(ModelPPM *Model); // BCD context
|
|
||||||
inline void update1(ModelPPM *Model,STATE* p); // CD suffix
|
|
||||||
inline void update2(ModelPPM *Model,STATE* p); // BCDE successor
|
|
||||||
void rescale(ModelPPM *Model);
|
|
||||||
inline PPM_CONTEXT* createChild(ModelPPM *Model,STATE* pStats,STATE& FirstState);
|
|
||||||
inline SEE2_CONTEXT* makeEscFreq2(ModelPPM *Model,int Diff);
|
|
||||||
};
|
|
||||||
#ifdef _AIX
|
|
||||||
#pragma pack(pop)
|
|
||||||
#else
|
|
||||||
#pragma pack()
|
|
||||||
#endif
|
|
||||||
|
|
||||||
const uint UNIT_SIZE=sizeof(PPM_CONTEXT);
|
|
||||||
const uint FIXED_UNIT_SIZE=12;
|
|
||||||
|
|
||||||
/*
|
|
||||||
inline PPM_CONTEXT::PPM_CONTEXT(STATE* pStats,PPM_CONTEXT* ShorterContext):
|
|
||||||
NumStats(1), Suffix(ShorterContext) { pStats->Successor=this; }
|
|
||||||
inline PPM_CONTEXT::PPM_CONTEXT(): NumStats(0) {}
|
|
||||||
*/
|
|
||||||
|
|
||||||
template <class T>
|
|
||||||
inline void _PPMD_SWAP(T& t1,T& t2) { T tmp=t1; t1=t2; t2=tmp; }
|
|
||||||
|
|
||||||
|
|
||||||
class ModelPPM
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
friend struct PPM_CONTEXT;
|
|
||||||
|
|
||||||
_PACK_ATTR SEE2_CONTEXT SEE2Cont[25][16], DummySEE2Cont;
|
|
||||||
|
|
||||||
struct PPM_CONTEXT *MinContext, *MedContext, *MaxContext;
|
|
||||||
STATE* FoundState; // found next state transition
|
|
||||||
int NumMasked, InitEsc, OrderFall, MaxOrder, RunLength, InitRL;
|
|
||||||
byte CharMask[256], NS2Indx[256], NS2BSIndx[256], HB2Flag[256];
|
|
||||||
byte EscCount, PrevSuccess, HiBitsFlag;
|
|
||||||
ushort BinSumm[128][64]; // binary SEE-contexts
|
|
||||||
|
|
||||||
RangeCoder Coder;
|
|
||||||
SubAllocator SubAlloc;
|
|
||||||
|
|
||||||
void RestartModelRare();
|
|
||||||
void StartModelRare(int MaxOrder);
|
|
||||||
inline PPM_CONTEXT* CreateSuccessors(bool Skip,STATE* p1);
|
|
||||||
|
|
||||||
inline void UpdateModel();
|
|
||||||
inline void ClearMask();
|
|
||||||
public:
|
|
||||||
ModelPPM();
|
|
||||||
bool DecodeInit(Unpack *UnpackRead,int &EscChar);
|
|
||||||
int DecodeChar();
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,129 +0,0 @@
|
|||||||
#ifndef _RAR_OPTIONS_
|
|
||||||
#define _RAR_OPTIONS_
|
|
||||||
|
|
||||||
#define DEFAULT_RECOVERY -1
|
|
||||||
|
|
||||||
#define DEFAULT_RECVOLUMES -10
|
|
||||||
|
|
||||||
enum PathExclMode {
|
|
||||||
EXCL_NONE,EXCL_BASEPATH,EXCL_SKIPWHOLEPATH,EXCL_SAVEFULLPATH,
|
|
||||||
EXCL_SKIPABSPATH,EXCL_ABSPATH
|
|
||||||
};
|
|
||||||
enum {SOLID_NONE=0,SOLID_NORMAL=1,SOLID_COUNT=2,SOLID_FILEEXT=4,
|
|
||||||
SOLID_VOLUME_DEPENDENT=8,SOLID_VOLUME_INDEPENDENT=16};
|
|
||||||
enum {ARCTIME_NONE,ARCTIME_KEEP,ARCTIME_LATEST};
|
|
||||||
enum EXTTIME_MODE {
|
|
||||||
EXTTIME_NONE,EXTTIME_1S,EXTTIME_HIGH1,EXTTIME_HIGH2,EXTTIME_HIGH3
|
|
||||||
};
|
|
||||||
enum {NAMES_ORIGINALCASE,NAMES_UPPERCASE,NAMES_LOWERCASE};
|
|
||||||
enum MESSAGE_TYPE {MSG_STDOUT,MSG_STDERR,MSG_ERRONLY,MSG_NULL};
|
|
||||||
enum OVERWRITE_MODE { OVERWRITE_ASK,OVERWRITE_ALL,OVERWRITE_NONE};
|
|
||||||
|
|
||||||
#define MAX_FILTERS 16
|
|
||||||
enum FilterState {FILTER_DEFAULT=0,FILTER_AUTO,FILTER_FORCE,FILTER_DISABLE};
|
|
||||||
|
|
||||||
|
|
||||||
struct FilterMode
|
|
||||||
{
|
|
||||||
FilterState State;
|
|
||||||
int Param1;
|
|
||||||
int Param2;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class RAROptions
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
RAROptions();
|
|
||||||
~RAROptions();
|
|
||||||
void Init();
|
|
||||||
|
|
||||||
uint ExclFileAttr;
|
|
||||||
uint InclFileAttr;
|
|
||||||
bool InclAttrSet;
|
|
||||||
uint WinSize;
|
|
||||||
char TempPath[NM];
|
|
||||||
char SFXModule[NM];
|
|
||||||
char ExtrPath[NM];
|
|
||||||
wchar ExtrPathW[NM];
|
|
||||||
char CommentFile[NM];
|
|
||||||
char ArcPath[NM];
|
|
||||||
char Password[MAXPASSWORD];
|
|
||||||
bool EncryptHeaders;
|
|
||||||
char LogName[NM];
|
|
||||||
MESSAGE_TYPE MsgStream;
|
|
||||||
bool Sound;
|
|
||||||
OVERWRITE_MODE Overwrite;
|
|
||||||
int Method;
|
|
||||||
int Recovery;
|
|
||||||
int RecVolNumber;
|
|
||||||
bool DisablePercentage;
|
|
||||||
bool DisableCopyright;
|
|
||||||
bool DisableDone;
|
|
||||||
int Solid;
|
|
||||||
int SolidCount;
|
|
||||||
bool ClearArc;
|
|
||||||
bool AddArcOnly;
|
|
||||||
bool AV;
|
|
||||||
bool DisableComment;
|
|
||||||
bool FreshFiles;
|
|
||||||
bool UpdateFiles;
|
|
||||||
PathExclMode ExclPath;
|
|
||||||
int Recurse;
|
|
||||||
Int64 VolSize;
|
|
||||||
Array<Int64> NextVolSizes;
|
|
||||||
int CurVolNum;
|
|
||||||
bool AllYes;
|
|
||||||
bool DisableViewAV;
|
|
||||||
bool DisableSortSolid;
|
|
||||||
int ArcTime;
|
|
||||||
int ConvertNames;
|
|
||||||
bool ProcessOwners;
|
|
||||||
bool SaveLinks;
|
|
||||||
int Priority;
|
|
||||||
int SleepTime;
|
|
||||||
bool KeepBroken;
|
|
||||||
bool EraseDisk;
|
|
||||||
bool OpenShared;
|
|
||||||
bool ExclEmptyDir;
|
|
||||||
bool DeleteFiles;
|
|
||||||
bool SyncFiles;
|
|
||||||
bool GenerateArcName;
|
|
||||||
char GenerateMask[80];
|
|
||||||
bool ProcessEA;
|
|
||||||
bool SaveStreams;
|
|
||||||
bool SetCompressedAttr;
|
|
||||||
uint FileTimeOlder;
|
|
||||||
uint FileTimeNewer;
|
|
||||||
RarTime FileTimeBefore;
|
|
||||||
RarTime FileTimeAfter;
|
|
||||||
bool OldNumbering;
|
|
||||||
bool Lock;
|
|
||||||
bool Test;
|
|
||||||
bool VolumePause;
|
|
||||||
FilterMode FilterModes[MAX_FILTERS];
|
|
||||||
char EmailTo[NM];
|
|
||||||
int VersionControl;
|
|
||||||
bool NoEndBlock;
|
|
||||||
bool AppendArcNameToPath;
|
|
||||||
bool Shutdown;
|
|
||||||
EXTTIME_MODE xmtime;
|
|
||||||
EXTTIME_MODE xctime;
|
|
||||||
EXTTIME_MODE xatime;
|
|
||||||
EXTTIME_MODE xarctime;
|
|
||||||
char CompressStdin[NM];
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef RARDLL
|
|
||||||
char DllDestName[NM];
|
|
||||||
wchar DllDestNameW[NM];
|
|
||||||
int DllOpMode;
|
|
||||||
int DllError;
|
|
||||||
LONG UserData;
|
|
||||||
UNRARCALLBACK Callback;
|
|
||||||
CHANGEVOLPROC ChangeVolProc;
|
|
||||||
PROCESSDATAPROC ProcessDataProc;
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
@@ -1,235 +0,0 @@
|
|||||||
#ifndef _RAR_OS_
|
|
||||||
#define _RAR_OS_
|
|
||||||
|
|
||||||
#define FALSE 0
|
|
||||||
#define TRUE 1
|
|
||||||
|
|
||||||
#ifdef __EMX__
|
|
||||||
#define INCL_BASE
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(_WIN_32) || defined(_EMX)
|
|
||||||
#define ENABLE_BAD_ALLOC
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#if defined(_WIN_32) || defined(_EMX)
|
|
||||||
|
|
||||||
#define LITTLE_ENDIAN
|
|
||||||
#define NM 1024
|
|
||||||
|
|
||||||
#ifdef _WIN_32
|
|
||||||
|
|
||||||
// Igor Pavlov
|
|
||||||
#ifndef STRICT
|
|
||||||
#define STRICT
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#undef WINVER
|
|
||||||
#undef _WIN32_WINNT
|
|
||||||
#define WINVER 0x0400
|
|
||||||
#define _WIN32_WINNT 0x0300
|
|
||||||
|
|
||||||
#define WIN32_LEAN_AND_MEAN
|
|
||||||
|
|
||||||
#include <windows.h>
|
|
||||||
#include <prsht.h>
|
|
||||||
|
|
||||||
#ifndef _WIN_CE
|
|
||||||
#include <winioctl.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef _WIN_CE
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <dos.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if !defined(_EMX) && !defined(_MSC_VER) && !defined(_WIN_CE)
|
|
||||||
#define ENABLE_MKTEMP
|
|
||||||
#include <dir.h>
|
|
||||||
#endif
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
#define for if (0) ; else for
|
|
||||||
#ifndef _WIN_CE
|
|
||||||
#include <direct.h>
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
#include <dirent.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef _WIN_CE
|
|
||||||
#include <share.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(ENABLE_BAD_ALLOC) && !defined(_WIN_CE)
|
|
||||||
#include <new.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef _EMX
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <pwd.h>
|
|
||||||
#include <grp.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#ifdef _DJGPP
|
|
||||||
#include <utime.h>
|
|
||||||
#else
|
|
||||||
#include <os2.h>
|
|
||||||
#include <sys/utime.h>
|
|
||||||
#include <emx/syscalls.h>
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
#if defined(_MSC_VER) || defined(__MINGW32__)
|
|
||||||
#include <exception>
|
|
||||||
#else
|
|
||||||
#include <except.h>
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdarg.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <ctype.h>
|
|
||||||
#ifndef _WIN_CE
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <dos.h>
|
|
||||||
#include <io.h>
|
|
||||||
#include <time.h>
|
|
||||||
#include <signal.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
|
||||||
#ifdef _WIN_32
|
|
||||||
#pragma hdrstop
|
|
||||||
#endif
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define ENABLE_ACCESS
|
|
||||||
|
|
||||||
#define DefConfigName "rar.ini"
|
|
||||||
#define DefLogName "rar.log"
|
|
||||||
|
|
||||||
|
|
||||||
#define PATHDIVIDER "\\"
|
|
||||||
#define PATHDIVIDERW L"\\"
|
|
||||||
#define CPATHDIVIDER '\\'
|
|
||||||
#define MASKALL "*"
|
|
||||||
#define MASKALLW L"*"
|
|
||||||
|
|
||||||
#define READBINARY "rb"
|
|
||||||
#define READTEXT "rt"
|
|
||||||
#define UPDATEBINARY "r+b"
|
|
||||||
#define CREATEBINARY "w+b"
|
|
||||||
#define APPENDTEXT "at"
|
|
||||||
|
|
||||||
#if defined(_WIN_32)
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
#define _stdfunction __cdecl
|
|
||||||
#else
|
|
||||||
#define _stdfunction _USERENTRY
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
#define _stdfunction
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef _UNIX
|
|
||||||
|
|
||||||
#define NM 1024
|
|
||||||
|
|
||||||
#ifdef _BEOS
|
|
||||||
#include <be/kernel/fs_info.h>
|
|
||||||
#include <be/kernel/fs_attr.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <sys/file.h>
|
|
||||||
#if defined(__QNXNTO__)
|
|
||||||
#include <sys/param.h>
|
|
||||||
#endif
|
|
||||||
#if defined(__FreeBSD__) || defined (__NetBSD__) || defined (__OpenBSD__) || defined(__APPLE__)
|
|
||||||
#include <sys/param.h>
|
|
||||||
#include <sys/mount.h>
|
|
||||||
#else
|
|
||||||
#endif
|
|
||||||
#include <pwd.h>
|
|
||||||
#include <grp.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdarg.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <ctype.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <dirent.h>
|
|
||||||
#include <time.h>
|
|
||||||
#include <signal.h>
|
|
||||||
#include <utime.h>
|
|
||||||
#include <locale.h>
|
|
||||||
|
|
||||||
#ifdef S_IFLNK
|
|
||||||
#define SAVE_LINKS
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define ENABLE_ACCESS
|
|
||||||
|
|
||||||
#define DefConfigName ".rarrc"
|
|
||||||
#define DefLogName ".rarlog"
|
|
||||||
|
|
||||||
|
|
||||||
#define PATHDIVIDER "/"
|
|
||||||
#define PATHDIVIDERW L"/"
|
|
||||||
#define CPATHDIVIDER '/'
|
|
||||||
#define MASKALL "*"
|
|
||||||
#define MASKALLW L"*"
|
|
||||||
|
|
||||||
#define READBINARY "r"
|
|
||||||
#define READTEXT "r"
|
|
||||||
#define UPDATEBINARY "r+"
|
|
||||||
#define CREATEBINARY "w+"
|
|
||||||
#define APPENDTEXT "a"
|
|
||||||
|
|
||||||
#define _stdfunction
|
|
||||||
|
|
||||||
#ifdef _APPLE
|
|
||||||
#ifndef BIG_ENDIAN
|
|
||||||
#define BIG_ENDIAN
|
|
||||||
#endif
|
|
||||||
#ifdef LITTLE_ENDIAN
|
|
||||||
#undef LITTLE_ENDIAN
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(__sparc) || defined(sparc) || defined(__hpux)
|
|
||||||
#ifndef BIG_ENDIAN
|
|
||||||
#define BIG_ENDIAN
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef const char* MSGID;
|
|
||||||
|
|
||||||
#define safebuf static
|
|
||||||
|
|
||||||
#if defined(LITTLE_ENDIAN) && defined(BIG_ENDIAN)
|
|
||||||
#if defined(BYTE_ORDER) && BYTE_ORDER == BIG_ENDIAN
|
|
||||||
#undef LITTLE_ENDIAN
|
|
||||||
#elif defined(BYTE_ORDER) && BYTE_ORDER == LITTLE_ENDIAN
|
|
||||||
#undef BIG_ENDIAN
|
|
||||||
#else
|
|
||||||
#error "Both LITTLE_ENDIAN and BIG_ENDIAN are defined. Undef something one"
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if !defined(BIG_ENDIAN) && !defined(_WIN_CE) && defined(_WIN_32)
|
|
||||||
#define ALLOW_NOT_ALIGNED_INT
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // _RAR_OS_
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
#ifndef _RAR_PATHFN_
|
|
||||||
#define _RAR_PATHFN_
|
|
||||||
|
|
||||||
char* PointToName(const char *Path);
|
|
||||||
wchar* PointToName(const wchar *Path);
|
|
||||||
char* PointToLastChar(const char *Path);
|
|
||||||
char* ConvertPath(const char *SrcPath,char *DestPath);
|
|
||||||
wchar* ConvertPath(const wchar *SrcPath,wchar *DestPath);
|
|
||||||
void SetExt(char *Name,const char *NewExt);
|
|
||||||
void SetExt(wchar *Name,const wchar *NewExt);
|
|
||||||
void SetSFXExt(char *SFXName);
|
|
||||||
void SetSFXExt(wchar *SFXName);
|
|
||||||
char *GetExt(const char *Name);
|
|
||||||
wchar *GetExt(const wchar *Name);
|
|
||||||
bool CmpExt(const char *Name,const char *Ext);
|
|
||||||
bool IsWildcard(const char *Str,const wchar *StrW=NULL);
|
|
||||||
bool IsPathDiv(int Ch);
|
|
||||||
bool IsDriveDiv(int Ch);
|
|
||||||
int GetPathDisk(const char *Path);
|
|
||||||
void AddEndSlash(char *Path);
|
|
||||||
void AddEndSlash(wchar *Path);
|
|
||||||
void GetFilePath(const char *FullName,char *Path);
|
|
||||||
void GetFilePath(const wchar *FullName,wchar *Path);
|
|
||||||
void RemoveNameFromPath(char *Path);
|
|
||||||
void RemoveNameFromPath(wchar *Path);
|
|
||||||
bool EnumConfigPaths(char *Path,int Number);
|
|
||||||
void GetConfigName(const char *Name,char *FullName,bool CheckExist);
|
|
||||||
char* GetVolNumPart(char *ArcName);
|
|
||||||
void NextVolumeName(char *ArcName,bool OldNumbering);
|
|
||||||
bool IsNameUsable(const char *Name);
|
|
||||||
void MakeNameUsable(char *Name,bool Extended);
|
|
||||||
char* UnixSlashToDos(char *SrcName,char *DestName=NULL,uint MaxLength=NM);
|
|
||||||
char* DosSlashToUnix(char *SrcName,char *DestName=NULL,uint MaxLength=NM);
|
|
||||||
bool IsFullPath(const char *Path);
|
|
||||||
bool IsDiskLetter(const char *Path);
|
|
||||||
void GetPathRoot(const char *Path,char *Root);
|
|
||||||
int ParseVersionFileName(char *Name,wchar *NameW,bool Truncate);
|
|
||||||
char* VolNameToFirstName(const char *VolName,char *FirstName,bool NewNumbering);
|
|
||||||
wchar* GetWideName(const char *Name,const wchar *NameW,wchar *DestW);
|
|
||||||
|
|
||||||
|
|
||||||
inline char* GetOutputName(const char *Name) {return((char *)Name);};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,80 +0,0 @@
|
|||||||
#ifndef _RAR_RARCOMMON_
|
|
||||||
#define _RAR_RARCOMMON_
|
|
||||||
|
|
||||||
#include "raros.hpp"
|
|
||||||
#include "os.hpp"
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef RARDLL
|
|
||||||
#include "dll.hpp"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef _WIN_CE
|
|
||||||
#include "version.hpp"
|
|
||||||
#endif
|
|
||||||
#include "rartypes.hpp"
|
|
||||||
#include "rardefs.hpp"
|
|
||||||
#include "rarlang.hpp"
|
|
||||||
#include "int64.hpp"
|
|
||||||
#include "unicode.hpp"
|
|
||||||
#include "errhnd.hpp"
|
|
||||||
#include "array.hpp"
|
|
||||||
#include "timefn.hpp"
|
|
||||||
#include "headers.hpp"
|
|
||||||
#include "rarfn.hpp"
|
|
||||||
#include "pathfn.hpp"
|
|
||||||
#include "strfn.hpp"
|
|
||||||
#include "strlist.hpp"
|
|
||||||
#include "file.hpp"
|
|
||||||
#include "sha1.hpp"
|
|
||||||
#include "crc.hpp"
|
|
||||||
#include "rijndael.hpp"
|
|
||||||
#include "crypt.hpp"
|
|
||||||
#include "filefn.hpp"
|
|
||||||
#include "filestr.hpp"
|
|
||||||
#include "find.hpp"
|
|
||||||
#include "scantree.hpp"
|
|
||||||
#include "savepos.hpp"
|
|
||||||
#include "getbits.hpp"
|
|
||||||
#include "rdwrfn.hpp"
|
|
||||||
#include "options.hpp"
|
|
||||||
#include "archive.hpp"
|
|
||||||
#include "match.hpp"
|
|
||||||
#include "cmddata.hpp"
|
|
||||||
#include "filcreat.hpp"
|
|
||||||
#include "consio.hpp"
|
|
||||||
#include "system.hpp"
|
|
||||||
#include "isnt.hpp"
|
|
||||||
#include "log.hpp"
|
|
||||||
#include "rawread.hpp"
|
|
||||||
#include "encname.hpp"
|
|
||||||
#include "resource.hpp"
|
|
||||||
#include "compress.hpp"
|
|
||||||
|
|
||||||
|
|
||||||
#include "rarvm.hpp"
|
|
||||||
#include "model.hpp"
|
|
||||||
|
|
||||||
|
|
||||||
#include "unpack.hpp"
|
|
||||||
|
|
||||||
|
|
||||||
#include "extinfo.hpp"
|
|
||||||
#include "extract.hpp"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "list.hpp"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "rs.hpp"
|
|
||||||
#include "recvol.hpp"
|
|
||||||
#include "volume.hpp"
|
|
||||||
#include "smallfn.hpp"
|
|
||||||
#include "ulinks.hpp"
|
|
||||||
|
|
||||||
#include "global.hpp"
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
#ifndef _RAR_DEFS_
|
|
||||||
#define _RAR_DEFS_
|
|
||||||
|
|
||||||
#define Min(x,y) (((x)<(y)) ? (x):(y))
|
|
||||||
#define Max(x,y) (((x)>(y)) ? (x):(y))
|
|
||||||
|
|
||||||
#define MAXPASSWORD 128
|
|
||||||
|
|
||||||
#define DefSFXName "default.sfx"
|
|
||||||
#define DefSortListName "rarfiles.lst"
|
|
||||||
|
|
||||||
#ifndef FA_RDONLY
|
|
||||||
#define FA_RDONLY 0x01
|
|
||||||
#define FA_HIDDEN 0x02
|
|
||||||
#define FA_SYSTEM 0x04
|
|
||||||
#define FA_LABEL 0x08
|
|
||||||
#define FA_DIREC 0x10
|
|
||||||
#define FA_ARCH 0x20
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
#ifndef _RAR_FN_
|
|
||||||
#define _RAR_FN_
|
|
||||||
|
|
||||||
void RARInitData();
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
#ifndef _RAR_LANG_
|
|
||||||
#define _RAR_LANG_
|
|
||||||
|
|
||||||
#ifdef USE_RC
|
|
||||||
#include "rarres.hpp"
|
|
||||||
#else
|
|
||||||
#include "loclang.hpp"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
#ifndef _RAR_RAROS_
|
|
||||||
#define _RAR_RAROS_
|
|
||||||
|
|
||||||
#ifdef __EMX__
|
|
||||||
#define _EMX
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __DJGPP__
|
|
||||||
#define _DJGPP
|
|
||||||
#define _EMX
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(__WIN32__) || defined(_WIN32)
|
|
||||||
#define _WIN_32
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef _WIN32_WCE
|
|
||||||
#define _WIN_32
|
|
||||||
#define _WIN_CE
|
|
||||||
#ifdef WM_FILECHANGEINFO
|
|
||||||
#define PC2002
|
|
||||||
#else
|
|
||||||
#undef PC2002
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __BEOS__
|
|
||||||
#define _UNIX
|
|
||||||
#define _BEOS
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __APPLE__
|
|
||||||
#define _UNIX
|
|
||||||
#define _APPLE
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if !defined(_EMX) && !defined(_WIN_32) && !defined(_BEOS) && !defined(_APPLE)
|
|
||||||
#define _UNIX
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
#ifndef _RAR_TYPES_
|
|
||||||
#define _RAR_TYPES_
|
|
||||||
|
|
||||||
typedef unsigned char byte; //8 bits
|
|
||||||
typedef unsigned short ushort; //preferably 16 bits, but can be more
|
|
||||||
typedef unsigned int uint; //32 bits or more
|
|
||||||
|
|
||||||
typedef unsigned int uint32; //32 bits exactly
|
|
||||||
typedef int sint32; //signed 32 bits exactly
|
|
||||||
#define PRESENT_INT32
|
|
||||||
|
|
||||||
#if defined(_WIN_32) || defined(__GNUC__) || defined(__sgi) || defined(_AIX) || defined(__sun) || defined(__hpux)
|
|
||||||
typedef wchar_t wchar;
|
|
||||||
#else
|
|
||||||
typedef ushort wchar;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define SHORT16(x) (sizeof(ushort)==2 ? (ushort)(x):((x)&0xffff))
|
|
||||||
#define UINT32(x) (sizeof(uint32)==4 ? (uint32)(x):((x)&0xffffffff))
|
|
||||||
|
|
||||||
#endif
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,110 +0,0 @@
|
|||||||
#ifndef _RAR_VM_
|
|
||||||
#define _RAR_VM_
|
|
||||||
|
|
||||||
#define VM_STANDARDFILTERS
|
|
||||||
|
|
||||||
#ifndef SFX_MODULE
|
|
||||||
#define VM_OPTIMIZE
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#define VM_MEMSIZE 0x40000
|
|
||||||
#define VM_MEMMASK (VM_MEMSIZE-1)
|
|
||||||
#define VM_GLOBALMEMADDR 0x3C000
|
|
||||||
#define VM_GLOBALMEMSIZE 0x2000
|
|
||||||
#define VM_FIXEDGLOBALSIZE 64
|
|
||||||
|
|
||||||
enum VM_Commands
|
|
||||||
{
|
|
||||||
VM_MOV, VM_CMP, VM_ADD, VM_SUB, VM_JZ, VM_JNZ, VM_INC, VM_DEC,
|
|
||||||
VM_JMP, VM_XOR, VM_AND, VM_OR, VM_TEST, VM_JS, VM_JNS, VM_JB,
|
|
||||||
VM_JBE, VM_JA, VM_JAE, VM_PUSH, VM_POP, VM_CALL, VM_RET, VM_NOT,
|
|
||||||
VM_SHL, VM_SHR, VM_SAR, VM_NEG, VM_PUSHA,VM_POPA, VM_PUSHF,VM_POPF,
|
|
||||||
VM_MOVZX,VM_MOVSX,VM_XCHG, VM_MUL, VM_DIV, VM_ADC, VM_SBB, VM_PRINT,
|
|
||||||
|
|
||||||
#ifdef VM_OPTIMIZE
|
|
||||||
VM_MOVB, VM_MOVD, VM_CMPB, VM_CMPD,
|
|
||||||
|
|
||||||
VM_ADDB, VM_ADDD, VM_SUBB, VM_SUBD, VM_INCB, VM_INCD, VM_DECB, VM_DECD,
|
|
||||||
VM_NEGB, VM_NEGD,
|
|
||||||
#endif
|
|
||||||
|
|
||||||
VM_STANDARD
|
|
||||||
};
|
|
||||||
|
|
||||||
enum VM_StandardFilters {
|
|
||||||
VMSF_NONE, VMSF_E8, VMSF_E8E9, VMSF_ITANIUM, VMSF_RGB, VMSF_AUDIO,
|
|
||||||
VMSF_DELTA, VMSF_UPCASE
|
|
||||||
};
|
|
||||||
|
|
||||||
enum VM_Flags {VM_FC=1,VM_FZ=2,VM_FS=0x80000000};
|
|
||||||
|
|
||||||
enum VM_OpType {VM_OPREG,VM_OPINT,VM_OPREGMEM,VM_OPNONE};
|
|
||||||
|
|
||||||
struct VM_PreparedOperand
|
|
||||||
{
|
|
||||||
VM_OpType Type;
|
|
||||||
uint Data;
|
|
||||||
uint Base;
|
|
||||||
uint *Addr;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct VM_PreparedCommand
|
|
||||||
{
|
|
||||||
VM_Commands OpCode;
|
|
||||||
bool ByteMode;
|
|
||||||
VM_PreparedOperand Op1,Op2;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
struct VM_PreparedProgram
|
|
||||||
{
|
|
||||||
VM_PreparedProgram() {AltCmd=NULL;}
|
|
||||||
|
|
||||||
Array<VM_PreparedCommand> Cmd;
|
|
||||||
VM_PreparedCommand *AltCmd;
|
|
||||||
int CmdCount;
|
|
||||||
|
|
||||||
Array<byte> GlobalData;
|
|
||||||
Array<byte> StaticData;
|
|
||||||
uint InitR[7];
|
|
||||||
|
|
||||||
byte *FilteredData;
|
|
||||||
unsigned int FilteredDataSize;
|
|
||||||
};
|
|
||||||
|
|
||||||
class RarVM:private BitInput
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
inline uint GetValue(bool ByteMode,uint *Addr);
|
|
||||||
inline void SetValue(bool ByteMode,uint *Addr,uint Value);
|
|
||||||
inline uint* GetOperand(VM_PreparedOperand *CmdOp);
|
|
||||||
void PrintState(uint IP);
|
|
||||||
void DecodeArg(VM_PreparedOperand &Op,bool ByteMode);
|
|
||||||
#ifdef VM_OPTIMIZE
|
|
||||||
void Optimize(VM_PreparedProgram *Prg);
|
|
||||||
#endif
|
|
||||||
bool ExecuteCode(VM_PreparedCommand *PreparedCode,int CodeSize);
|
|
||||||
#ifdef VM_STANDARDFILTERS
|
|
||||||
VM_StandardFilters IsStandardFilter(byte *Code,int CodeSize);
|
|
||||||
void ExecuteStandardFilter(VM_StandardFilters FilterType);
|
|
||||||
unsigned int FilterItanium_GetBits(byte *Data,int BitPos,int BitCount);
|
|
||||||
void FilterItanium_SetBits(byte *Data,unsigned int BitField,int BitPos,
|
|
||||||
int BitCount);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
byte *Mem;
|
|
||||||
uint R[8];
|
|
||||||
uint Flags;
|
|
||||||
public:
|
|
||||||
RarVM();
|
|
||||||
~RarVM();
|
|
||||||
void Init();
|
|
||||||
void Prepare(byte *Code,int CodeSize,VM_PreparedProgram *Prg);
|
|
||||||
void Execute(VM_PreparedProgram *Prg);
|
|
||||||
void SetValue(uint *Addr,uint Value);
|
|
||||||
void SetMemory(unsigned int Pos,byte *Data,unsigned int DataSize);
|
|
||||||
static uint ReadData(BitInput &Inp);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
#define VMCF_OP0 0
|
|
||||||
#define VMCF_OP1 1
|
|
||||||
#define VMCF_OP2 2
|
|
||||||
#define VMCF_OPMASK 3
|
|
||||||
#define VMCF_BYTEMODE 4
|
|
||||||
#define VMCF_JUMP 8
|
|
||||||
#define VMCF_PROC 16
|
|
||||||
#define VMCF_USEFLAGS 32
|
|
||||||
#define VMCF_CHFLAGS 64
|
|
||||||
|
|
||||||
static byte VM_CmdFlags[]=
|
|
||||||
{
|
|
||||||
/* VM_MOV */ VMCF_OP2 | VMCF_BYTEMODE ,
|
|
||||||
/* VM_CMP */ VMCF_OP2 | VMCF_BYTEMODE | VMCF_CHFLAGS ,
|
|
||||||
/* VM_ADD */ VMCF_OP2 | VMCF_BYTEMODE | VMCF_CHFLAGS ,
|
|
||||||
/* VM_SUB */ VMCF_OP2 | VMCF_BYTEMODE | VMCF_CHFLAGS ,
|
|
||||||
/* VM_JZ */ VMCF_OP1 | VMCF_JUMP | VMCF_USEFLAGS ,
|
|
||||||
/* VM_JNZ */ VMCF_OP1 | VMCF_JUMP | VMCF_USEFLAGS ,
|
|
||||||
/* VM_INC */ VMCF_OP1 | VMCF_BYTEMODE | VMCF_CHFLAGS ,
|
|
||||||
/* VM_DEC */ VMCF_OP1 | VMCF_BYTEMODE | VMCF_CHFLAGS ,
|
|
||||||
/* VM_JMP */ VMCF_OP1 | VMCF_JUMP ,
|
|
||||||
/* VM_XOR */ VMCF_OP2 | VMCF_BYTEMODE | VMCF_CHFLAGS ,
|
|
||||||
/* VM_AND */ VMCF_OP2 | VMCF_BYTEMODE | VMCF_CHFLAGS ,
|
|
||||||
/* VM_OR */ VMCF_OP2 | VMCF_BYTEMODE | VMCF_CHFLAGS ,
|
|
||||||
/* VM_TEST */ VMCF_OP2 | VMCF_BYTEMODE | VMCF_CHFLAGS ,
|
|
||||||
/* VM_JS */ VMCF_OP1 | VMCF_JUMP | VMCF_USEFLAGS ,
|
|
||||||
/* VM_JNS */ VMCF_OP1 | VMCF_JUMP | VMCF_USEFLAGS ,
|
|
||||||
/* VM_JB */ VMCF_OP1 | VMCF_JUMP | VMCF_USEFLAGS ,
|
|
||||||
/* VM_JBE */ VMCF_OP1 | VMCF_JUMP | VMCF_USEFLAGS ,
|
|
||||||
/* VM_JA */ VMCF_OP1 | VMCF_JUMP | VMCF_USEFLAGS ,
|
|
||||||
/* VM_JAE */ VMCF_OP1 | VMCF_JUMP | VMCF_USEFLAGS ,
|
|
||||||
/* VM_PUSH */ VMCF_OP1 ,
|
|
||||||
/* VM_POP */ VMCF_OP1 ,
|
|
||||||
/* VM_CALL */ VMCF_OP1 | VMCF_PROC ,
|
|
||||||
/* VM_RET */ VMCF_OP0 | VMCF_PROC ,
|
|
||||||
/* VM_NOT */ VMCF_OP1 | VMCF_BYTEMODE ,
|
|
||||||
/* VM_SHL */ VMCF_OP2 | VMCF_BYTEMODE | VMCF_CHFLAGS ,
|
|
||||||
/* VM_SHR */ VMCF_OP2 | VMCF_BYTEMODE | VMCF_CHFLAGS ,
|
|
||||||
/* VM_SAR */ VMCF_OP2 | VMCF_BYTEMODE | VMCF_CHFLAGS ,
|
|
||||||
/* VM_NEG */ VMCF_OP1 | VMCF_BYTEMODE | VMCF_CHFLAGS ,
|
|
||||||
/* VM_PUSHA */ VMCF_OP0 ,
|
|
||||||
/* VM_POPA */ VMCF_OP0 ,
|
|
||||||
/* VM_PUSHF */ VMCF_OP0 | VMCF_USEFLAGS ,
|
|
||||||
/* VM_POPF */ VMCF_OP0 | VMCF_CHFLAGS ,
|
|
||||||
/* VM_MOVZX */ VMCF_OP2 ,
|
|
||||||
/* VM_MOVSX */ VMCF_OP2 ,
|
|
||||||
/* VM_XCHG */ VMCF_OP2 | VMCF_BYTEMODE ,
|
|
||||||
/* VM_MUL */ VMCF_OP2 | VMCF_BYTEMODE ,
|
|
||||||
/* VM_DIV */ VMCF_OP2 | VMCF_BYTEMODE ,
|
|
||||||
/* VM_ADC */ VMCF_OP2 | VMCF_BYTEMODE | VMCF_USEFLAGS | VMCF_CHFLAGS ,
|
|
||||||
/* VM_SBB */ VMCF_OP2 | VMCF_BYTEMODE | VMCF_USEFLAGS | VMCF_CHFLAGS ,
|
|
||||||
/* VM_PRINT */ VMCF_OP0
|
|
||||||
};
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
#ifndef _RAR_RAWREAD_
|
|
||||||
#define _RAR_RAWREAD_
|
|
||||||
|
|
||||||
class RawRead
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
Array<byte> Data;
|
|
||||||
File *SrcFile;
|
|
||||||
int DataSize;
|
|
||||||
int ReadPos;
|
|
||||||
#ifndef SHELL_EXT
|
|
||||||
CryptData *Crypt;
|
|
||||||
#endif
|
|
||||||
public:
|
|
||||||
RawRead(File *SrcFile);
|
|
||||||
void Read(int Size);
|
|
||||||
void Read(byte *SrcData,int Size);
|
|
||||||
void Get(byte &Field);
|
|
||||||
void Get(ushort &Field);
|
|
||||||
void Get(uint &Field);
|
|
||||||
void Get8(Int64 &Field);
|
|
||||||
void Get(byte *Field,int Size);
|
|
||||||
void Get(wchar *Field,int Size);
|
|
||||||
uint GetCRC(bool ProcessedOnly);
|
|
||||||
int Size() {return DataSize;}
|
|
||||||
int PaddedSize() {return Data.Size()-DataSize;}
|
|
||||||
#ifndef SHELL_EXT
|
|
||||||
void SetCrypt(CryptData *Crypt) {RawRead::Crypt=Crypt;}
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,306 +0,0 @@
|
|||||||
#include "rar.hpp"
|
|
||||||
|
|
||||||
// Igor Pavlov
|
|
||||||
#include "../../../Common/StreamUtils.h"
|
|
||||||
|
|
||||||
ComprDataIO::ComprDataIO()
|
|
||||||
{
|
|
||||||
Init();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ComprDataIO::Init()
|
|
||||||
{
|
|
||||||
UnpackFromMemory=false;
|
|
||||||
UnpackToMemory=false;
|
|
||||||
UnpPackedSize=0;
|
|
||||||
ShowProgress=true;
|
|
||||||
TestMode=false;
|
|
||||||
SkipUnpCRC=false;
|
|
||||||
PackVolume=false;
|
|
||||||
UnpVolume=false;
|
|
||||||
NextVolumeMissing=false;
|
|
||||||
SrcFile=NULL;
|
|
||||||
DestFile=NULL;
|
|
||||||
UnpWrSize=0;
|
|
||||||
Command=NULL;
|
|
||||||
Encryption=0;
|
|
||||||
Decryption=0;
|
|
||||||
TotalPackRead=0;
|
|
||||||
CurPackRead=CurPackWrite=CurUnpRead=CurUnpWrite=0;
|
|
||||||
PackFileCRC=UnpFileCRC=PackedCRC=0xffffffff;
|
|
||||||
LastPercent=-1;
|
|
||||||
// Igor Pavlov
|
|
||||||
/*
|
|
||||||
SubHead=NULL;
|
|
||||||
SubHeadPos=NULL;
|
|
||||||
*/
|
|
||||||
CurrentCommand=0;
|
|
||||||
ProcessedArcSize=TotalArcSize=0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int ComprDataIO::UnpRead(byte *Addr,uint Count)
|
|
||||||
{
|
|
||||||
int RetCode=0,TotalRead=0;
|
|
||||||
byte *ReadAddr;
|
|
||||||
ReadAddr=Addr;
|
|
||||||
while (Count > 0)
|
|
||||||
{
|
|
||||||
Archive *SrcArc=(Archive *)SrcFile;
|
|
||||||
|
|
||||||
uint ReadSize=(Count>UnpPackedSize) ? int64to32(UnpPackedSize):Count;
|
|
||||||
if (UnpackFromMemory)
|
|
||||||
{
|
|
||||||
memcpy(Addr,UnpackFromMemoryAddr,UnpackFromMemorySize);
|
|
||||||
RetCode=UnpackFromMemorySize;
|
|
||||||
UnpackFromMemorySize=0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Igor Pavlov
|
|
||||||
if (!SrcFile)
|
|
||||||
// if (!SrcFile->IsOpened())
|
|
||||||
return(-1);
|
|
||||||
|
|
||||||
// Igor Pavlov
|
|
||||||
UInt32 processedSize;
|
|
||||||
HRESULT result = ReadStream(SrcFile, ReadAddr, ReadSize, &processedSize);
|
|
||||||
RetCode = processedSize;
|
|
||||||
|
|
||||||
// Igor Pavlov
|
|
||||||
/*
|
|
||||||
FileHeader *hd=SubHead!=NULL ? SubHead:&SrcArc->NewLhd;
|
|
||||||
if (hd->Flags & LHD_SPLIT_AFTER)
|
|
||||||
PackedCRC=CRC(PackedCRC,ReadAddr,ReadSize);
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
CurUnpRead+=RetCode;
|
|
||||||
ReadAddr+=RetCode;
|
|
||||||
TotalRead+=RetCode;
|
|
||||||
Count-=RetCode;
|
|
||||||
UnpPackedSize-=RetCode;
|
|
||||||
if (UnpPackedSize == 0 && UnpVolume)
|
|
||||||
{
|
|
||||||
#ifndef NOVOLUME
|
|
||||||
if (!MergeArchive(*SrcArc,this,true,CurrentCommand))
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
NextVolumeMissing=true;
|
|
||||||
return(-1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
// Igor Pavlov
|
|
||||||
/*
|
|
||||||
Archive *SrcArc=(Archive *)SrcFile;
|
|
||||||
if (SrcArc!=NULL)
|
|
||||||
ShowUnpRead(SrcArc->CurBlockPos+CurUnpRead,UnpArcSize);
|
|
||||||
*/
|
|
||||||
if (RetCode!=-1)
|
|
||||||
{
|
|
||||||
RetCode=TotalRead;
|
|
||||||
#ifndef NOCRYPT
|
|
||||||
if (Decryption)
|
|
||||||
#ifndef SFX_MODULE
|
|
||||||
if (Decryption<20)
|
|
||||||
Decrypt.Crypt(Addr,RetCode,(Decryption==15) ? NEW_CRYPT : OLD_DECODE);
|
|
||||||
else
|
|
||||||
if (Decryption==20)
|
|
||||||
for (uint I=0;I<RetCode;I+=16)
|
|
||||||
Decrypt.DecryptBlock20(&Addr[I]);
|
|
||||||
else
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
int CryptSize=(RetCode & 0xf)==0 ? RetCode:((RetCode & ~0xf)+16);
|
|
||||||
Decrypt.DecryptBlock(Addr,CryptSize);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
Wait();
|
|
||||||
return(RetCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ComprDataIO::UnpWrite(byte *Addr,uint Count)
|
|
||||||
{
|
|
||||||
#ifdef RARDLL
|
|
||||||
RAROptions *Cmd=((Archive *)SrcFile)->GetRAROptions();
|
|
||||||
if (Cmd->DllOpMode!=RAR_SKIP)
|
|
||||||
{
|
|
||||||
if (Cmd->Callback!=NULL &&
|
|
||||||
Cmd->Callback(UCM_PROCESSDATA,Cmd->UserData,(LONG)Addr,Count)==-1)
|
|
||||||
ErrHandler.Exit(USER_BREAK);
|
|
||||||
if (Cmd->ProcessDataProc!=NULL)
|
|
||||||
{
|
|
||||||
#ifdef _WIN_32
|
|
||||||
_EBX=_ESP;
|
|
||||||
#endif
|
|
||||||
int RetCode=Cmd->ProcessDataProc(Addr,Count);
|
|
||||||
#ifdef _WIN_32
|
|
||||||
_ESP=_EBX;
|
|
||||||
#endif
|
|
||||||
if (RetCode==0)
|
|
||||||
ErrHandler.Exit(USER_BREAK);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
UnpWrAddr=Addr;
|
|
||||||
UnpWrSize=Count;
|
|
||||||
if (UnpackToMemory)
|
|
||||||
{
|
|
||||||
if (Count <= UnpackToMemorySize)
|
|
||||||
{
|
|
||||||
memcpy(UnpackToMemoryAddr,Addr,Count);
|
|
||||||
UnpackToMemoryAddr+=Count;
|
|
||||||
UnpackToMemorySize-=Count;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
if (!TestMode)
|
|
||||||
{
|
|
||||||
// Igor Pavlov
|
|
||||||
// DestFile->Write(Addr,Count);
|
|
||||||
WriteStream(DestFile, Addr,Count, 0);
|
|
||||||
}
|
|
||||||
CurUnpWrite+=Count;
|
|
||||||
// Igor Pavlov
|
|
||||||
/*
|
|
||||||
if (!SkipUnpCRC)
|
|
||||||
#ifndef SFX_MODULE
|
|
||||||
if (((Archive *)SrcFile)->OldFormat)
|
|
||||||
UnpFileCRC=OldCRC((ushort)UnpFileCRC,Addr,Count);
|
|
||||||
else
|
|
||||||
#endif
|
|
||||||
UnpFileCRC=CRC(UnpFileCRC,Addr,Count);
|
|
||||||
*/
|
|
||||||
ShowUnpWrite();
|
|
||||||
Wait();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void ComprDataIO::ShowUnpRead(Int64 ArcPos,Int64 ArcSize)
|
|
||||||
{
|
|
||||||
if (ShowProgress && SrcFile!=NULL)
|
|
||||||
{
|
|
||||||
Archive *SrcArc=(Archive *)SrcFile;
|
|
||||||
RAROptions *Cmd=SrcArc->GetRAROptions();
|
|
||||||
if (TotalArcSize!=0)
|
|
||||||
ArcSize=TotalArcSize;
|
|
||||||
ArcPos+=ProcessedArcSize;
|
|
||||||
if (!SrcArc->Volume)
|
|
||||||
{
|
|
||||||
int CurPercent=ToPercent(ArcPos,ArcSize);
|
|
||||||
if (!Cmd->DisablePercentage && CurPercent!=LastPercent)
|
|
||||||
{
|
|
||||||
mprintf("\b\b\b\b%3d%%",CurPercent);
|
|
||||||
LastPercent=CurPercent;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ComprDataIO::ShowUnpWrite()
|
|
||||||
{
|
|
||||||
// Igor Pavlov
|
|
||||||
if (Progress)
|
|
||||||
{
|
|
||||||
UInt64 unPackSize = CurUnpWrite;
|
|
||||||
HRESULT result = Progress->SetRatioInfo(NULL, &unPackSize);
|
|
||||||
if (result != S_OK)
|
|
||||||
throw CExitCode(result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Igor Pavlov
|
|
||||||
/*
|
|
||||||
void ComprDataIO::SetFiles(File *SrcFile,File *DestFile)
|
|
||||||
{
|
|
||||||
if (SrcFile!=NULL)
|
|
||||||
ComprDataIO::SrcFile=SrcFile;
|
|
||||||
if (DestFile!=NULL)
|
|
||||||
ComprDataIO::DestFile=DestFile;
|
|
||||||
LastPercent=-1;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
void ComprDataIO::GetUnpackedData(byte **Data,uint *Size)
|
|
||||||
{
|
|
||||||
*Data=UnpWrAddr;
|
|
||||||
*Size=UnpWrSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Igor Pavlov
|
|
||||||
/*
|
|
||||||
void ComprDataIO::SetEncryption(int Method,char *Password,byte *Salt,bool Encrypt)
|
|
||||||
{
|
|
||||||
if (Encrypt)
|
|
||||||
{
|
|
||||||
Encryption=*Password ? Method:0;
|
|
||||||
#ifndef NOCRYPT
|
|
||||||
Crypt.SetCryptKeys(Password,Salt,Encrypt);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Decryption=*Password ? Method:0;
|
|
||||||
#ifndef NOCRYPT
|
|
||||||
Decrypt.SetCryptKeys(Password,Salt,Encrypt,Method<29);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef SFX_MODULE
|
|
||||||
void ComprDataIO::SetAV15Encryption()
|
|
||||||
{
|
|
||||||
Decryption=15;
|
|
||||||
Decrypt.SetAV15Encryption();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef SFX_MODULE
|
|
||||||
void ComprDataIO::SetCmt13Encryption()
|
|
||||||
{
|
|
||||||
Decryption=13;
|
|
||||||
Decrypt.SetCmt13Encryption();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void ComprDataIO::SetUnpackToMemory(byte *Addr,uint Size)
|
|
||||||
{
|
|
||||||
UnpackToMemory=true;
|
|
||||||
UnpackToMemoryAddr=Addr;
|
|
||||||
UnpackToMemorySize=Size;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Igor Pavlov
|
|
||||||
void ComprDataIO::SetFiles(ISequentialInStream *srcFile,
|
|
||||||
ISequentialOutStream *destFile, ICompressProgressInfo *progress)
|
|
||||||
{
|
|
||||||
SrcFile = srcFile;
|
|
||||||
DestFile = destFile;
|
|
||||||
Progress = progress;
|
|
||||||
LastPercent = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,104 +0,0 @@
|
|||||||
#ifndef _RAR_DATAIO_
|
|
||||||
#define _RAR_DATAIO_
|
|
||||||
|
|
||||||
// Igor Pavlov
|
|
||||||
#include "../../../ICoder.h"
|
|
||||||
|
|
||||||
class CmdAdd;
|
|
||||||
class Unpack;
|
|
||||||
|
|
||||||
// Igor Pavlov
|
|
||||||
struct CExitCode
|
|
||||||
{
|
|
||||||
HRESULT Result;
|
|
||||||
CExitCode(HRESULT result): Result(result) {};
|
|
||||||
};
|
|
||||||
|
|
||||||
class ComprDataIO
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
void ShowUnpRead(Int64 ArcPos,Int64 ArcSize);
|
|
||||||
void ShowUnpWrite();
|
|
||||||
|
|
||||||
|
|
||||||
bool UnpackFromMemory;
|
|
||||||
uint UnpackFromMemorySize;
|
|
||||||
byte *UnpackFromMemoryAddr;
|
|
||||||
|
|
||||||
bool UnpackToMemory;
|
|
||||||
uint UnpackToMemorySize;
|
|
||||||
byte *UnpackToMemoryAddr;
|
|
||||||
|
|
||||||
uint UnpWrSize;
|
|
||||||
byte *UnpWrAddr;
|
|
||||||
|
|
||||||
Int64 UnpPackedSize;
|
|
||||||
|
|
||||||
bool ShowProgress;
|
|
||||||
bool TestMode;
|
|
||||||
bool SkipUnpCRC;
|
|
||||||
|
|
||||||
// Igor Pavlov
|
|
||||||
// File *SrcFile;
|
|
||||||
// File *DestFile;
|
|
||||||
ISequentialInStream *SrcFile;
|
|
||||||
ISequentialOutStream *DestFile;
|
|
||||||
ICompressProgressInfo *Progress;
|
|
||||||
|
|
||||||
CmdAdd *Command;
|
|
||||||
|
|
||||||
// Igor Pavlov
|
|
||||||
/*
|
|
||||||
FileHeader *SubHead;
|
|
||||||
Int64 *SubHeadPos;
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef NOCRYPT
|
|
||||||
CryptData Crypt;
|
|
||||||
CryptData Decrypt;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
int LastPercent;
|
|
||||||
|
|
||||||
char CurrentCommand;
|
|
||||||
|
|
||||||
public:
|
|
||||||
ComprDataIO();
|
|
||||||
void Init();
|
|
||||||
int UnpRead(byte *Addr,uint Count);
|
|
||||||
void UnpWrite(byte *Addr,uint Count);
|
|
||||||
void EnableShowProgress(bool Show) {ShowProgress=Show;}
|
|
||||||
void GetUnpackedData(byte **Data,uint *Size);
|
|
||||||
void SetPackedSizeToRead(Int64 Size) {UnpPackedSize=Size;}
|
|
||||||
void SetTestMode(bool Mode) {TestMode=Mode;}
|
|
||||||
void SetSkipUnpCRC(bool Skip) {SkipUnpCRC=Skip;}
|
|
||||||
// Igor Pavlov
|
|
||||||
// void SetFiles(File *SrcFile,File *DestFile);
|
|
||||||
void SetFiles(ISequentialInStream *srcFile,
|
|
||||||
ISequentialOutStream *destFile, ICompressProgressInfo *progress);
|
|
||||||
|
|
||||||
void SetCommand(CmdAdd *Cmd) {Command=Cmd;}
|
|
||||||
// Igor Pavlov
|
|
||||||
// void SetSubHeader(FileHeader *hd,Int64 *Pos) {SubHead=hd;SubHeadPos=Pos;}
|
|
||||||
// void SetEncryption(int Method,char *Password,byte *Salt,bool Encrypt);
|
|
||||||
// void SetAV15Encryption();
|
|
||||||
// void SetCmt13Encryption();
|
|
||||||
void SetUnpackToMemory(byte *Addr,uint Size);
|
|
||||||
void SetCurrentCommand(char Cmd) {CurrentCommand=Cmd;}
|
|
||||||
|
|
||||||
bool PackVolume;
|
|
||||||
bool UnpVolume;
|
|
||||||
bool NextVolumeMissing;
|
|
||||||
Int64 TotalPackRead;
|
|
||||||
Int64 UnpArcSize;
|
|
||||||
Int64 CurPackRead,CurPackWrite,CurUnpRead,CurUnpWrite;
|
|
||||||
Int64 ProcessedArcSize,TotalArcSize;
|
|
||||||
|
|
||||||
uint PackFileCRC,UnpFileCRC,PackedCRC;
|
|
||||||
|
|
||||||
int Encryption;
|
|
||||||
int Decryption;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
#ifndef _RAR_RECVOL_
|
|
||||||
#define _RAR_RECVOL_
|
|
||||||
|
|
||||||
class RecVolumes
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
File *SrcFile[256];
|
|
||||||
Array<byte> Buf;
|
|
||||||
public:
|
|
||||||
RecVolumes();
|
|
||||||
~RecVolumes();
|
|
||||||
void Make(RAROptions *Cmd,char *ArcName,wchar *ArcNameW);
|
|
||||||
bool Restore(RAROptions *Cmd,const char *Name,const wchar *NameW,bool Silent);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
#include "rar.hpp"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#if !defined(SILENT) || !defined(RARDLL)
|
|
||||||
const char *St(MSGID StringId)
|
|
||||||
{
|
|
||||||
return(StringId);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
#ifndef _RAR_RESOURCE_
|
|
||||||
#define _RAR_RESOURCE_
|
|
||||||
|
|
||||||
#if defined(SILENT) && defined(RARDLL)
|
|
||||||
#define St(x) ("")
|
|
||||||
#else
|
|
||||||
const char *St(MSGID StringId);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
inline const char *StT(MSGID StringId) {return(St(StringId));}
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
#ifndef _RIJNDAEL_H_
|
|
||||||
#define _RIJNDAEL_H_
|
|
||||||
|
|
||||||
/**************************************************************************
|
|
||||||
* This code is based on Szymon Stefanek AES implementation: *
|
|
||||||
* http://www.esat.kuleuven.ac.be/~rijmen/rijndael/rijndael-cpplib.tar.gz *
|
|
||||||
* *
|
|
||||||
* Dynamic tables generation is based on the Brian Gladman's work: *
|
|
||||||
* http://fp.gladman.plus.com/cryptography_technology/rijndael *
|
|
||||||
**************************************************************************/
|
|
||||||
|
|
||||||
#define _MAX_KEY_COLUMNS (256/32)
|
|
||||||
#define _MAX_ROUNDS 14
|
|
||||||
#define MAX_IV_SIZE 16
|
|
||||||
|
|
||||||
class Rijndael
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
enum Direction { Encrypt , Decrypt };
|
|
||||||
private:
|
|
||||||
void keySched(byte key[_MAX_KEY_COLUMNS][4]);
|
|
||||||
void keyEncToDec();
|
|
||||||
void encrypt(const byte a[16], byte b[16]);
|
|
||||||
void decrypt(const byte a[16], byte b[16]);
|
|
||||||
void GenerateTables();
|
|
||||||
|
|
||||||
Direction m_direction;
|
|
||||||
byte m_initVector[MAX_IV_SIZE];
|
|
||||||
byte m_expandedKey[_MAX_ROUNDS+1][4][4];
|
|
||||||
public:
|
|
||||||
Rijndael();
|
|
||||||
void init(Direction dir,const byte *key,byte *initVector);
|
|
||||||
int blockEncrypt(const byte *input, int inputLen, byte *outBuffer);
|
|
||||||
int blockDecrypt(const byte *input, int inputLen, byte *outBuffer);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // _RIJNDAEL_H_
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
#ifndef _RAR_RS_
|
|
||||||
#define _RAR_RS_
|
|
||||||
|
|
||||||
#define MAXPAR 255
|
|
||||||
#define MAXPOL 512
|
|
||||||
|
|
||||||
class RSCoder
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
void gfInit();
|
|
||||||
int gfMult(int a,int b);
|
|
||||||
void pnInit();
|
|
||||||
void pnMult(int *p1,int *p2,int *r);
|
|
||||||
|
|
||||||
int gfExp[MAXPOL];
|
|
||||||
int gfLog[MAXPAR+1];
|
|
||||||
|
|
||||||
int GXPol[MAXPOL*2];
|
|
||||||
|
|
||||||
int ErrorLocs[MAXPAR+1],ErrCount;
|
|
||||||
int Dn[MAXPAR+1];
|
|
||||||
|
|
||||||
int ParSize;
|
|
||||||
int PolB[MAXPOL];
|
|
||||||
bool FirstBlockDone;
|
|
||||||
public:
|
|
||||||
RSCoder(int ParSize);
|
|
||||||
void Encode(byte *Data,int DataSize,byte *DestData);
|
|
||||||
bool Decode(byte *Data,int DataSize,int *EraLoc,int EraSize);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
#ifndef _RAR_SAVEPOS_
|
|
||||||
#define _RAR_SAVEPOS_
|
|
||||||
|
|
||||||
class SaveFilePos
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
File *SaveFile;
|
|
||||||
Int64 SavePos;
|
|
||||||
uint CloseCount;
|
|
||||||
public:
|
|
||||||
SaveFilePos(File &SaveFile);
|
|
||||||
~SaveFilePos();
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
#ifndef _RAR_SCANTREE_
|
|
||||||
#define _RAR_SCANTREE_
|
|
||||||
|
|
||||||
enum { RECURSE_NONE=0,RECURSE_ALWAYS,RECURSE_WILDCARDS };
|
|
||||||
enum { SCAN_SKIPDIRS=0,SCAN_GETDIRS,SCAN_GETDIRSTWICE,SCAN_GETCURDIRS };
|
|
||||||
enum { SCAN_SUCCESS,SCAN_DONE,SCAN_ERROR,SCAN_NEXT };
|
|
||||||
|
|
||||||
#define MAXSCANDEPTH (NM/2)
|
|
||||||
|
|
||||||
class CommandData;
|
|
||||||
|
|
||||||
class ScanTree
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
bool PrepareMasks();
|
|
||||||
int FindProc(FindData *FindData);
|
|
||||||
|
|
||||||
FindFile *FindStack[MAXSCANDEPTH];
|
|
||||||
int Depth;
|
|
||||||
|
|
||||||
int SetAllMaskDepth;
|
|
||||||
|
|
||||||
StringList *FileMasks;
|
|
||||||
int Recurse;
|
|
||||||
bool GetLinks;
|
|
||||||
int GetDirs;
|
|
||||||
int Errors;
|
|
||||||
|
|
||||||
char CurMask[NM];
|
|
||||||
wchar CurMaskW[NM];
|
|
||||||
char OrigCurMask[NM];
|
|
||||||
wchar OrigCurMaskW[NM];
|
|
||||||
bool SearchAllInRoot;
|
|
||||||
bool FastFindFile;
|
|
||||||
int SpecPathLength;
|
|
||||||
int SpecPathLengthW;
|
|
||||||
|
|
||||||
char ErrArcName[NM];
|
|
||||||
|
|
||||||
CommandData *Cmd;
|
|
||||||
public:
|
|
||||||
ScanTree(StringList *FileMasks,int Recurse,bool GetLinks,int GetDirs);
|
|
||||||
~ScanTree();
|
|
||||||
int GetNext(FindData *FindData);
|
|
||||||
int GetSpecPathLength() {return(SpecPathLength);};
|
|
||||||
int GetSpecPathLengthW() {return(SpecPathLengthW);};
|
|
||||||
int GetErrors() {return(Errors);};
|
|
||||||
void SetErrArcName(const char *Name) {strcpy(ErrArcName,Name);}
|
|
||||||
void SetCommandData(CommandData *Cmd) {ScanTree::Cmd=Cmd;}
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
#ifndef _RAR_SHA1_
|
|
||||||
#define _RAR_SHA1_
|
|
||||||
|
|
||||||
#define HW 5
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
uint32 state[5];
|
|
||||||
uint32 count[2];
|
|
||||||
unsigned char buffer[64];
|
|
||||||
} hash_context;
|
|
||||||
|
|
||||||
void hash_initial( hash_context * c );
|
|
||||||
void hash_process( hash_context * c, unsigned char * data, unsigned len );
|
|
||||||
void hash_final( hash_context * c, uint32[HW] );
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
#include "rar.hpp"
|
|
||||||
|
|
||||||
int ToPercent(Int64 N1,Int64 N2)
|
|
||||||
{
|
|
||||||
if (N2==0)
|
|
||||||
return(0);
|
|
||||||
if (N2<N1)
|
|
||||||
return(100);
|
|
||||||
return(int64to32(N1*100/N2));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void RARInitData()
|
|
||||||
{
|
|
||||||
InitCRC();
|
|
||||||
ErrHandler.Clean();
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
#ifndef _RAR_SMALLFN_
|
|
||||||
#define _RAR_SMALLFN_
|
|
||||||
|
|
||||||
int ToPercent(Int64 N1,Int64 N2);
|
|
||||||
void RARInitData();
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
#ifndef _RAR_STRFN_
|
|
||||||
#define _RAR_STRFN_
|
|
||||||
|
|
||||||
const char *NullToEmpty(const char *Str);
|
|
||||||
const wchar *NullToEmpty(const wchar *Str);
|
|
||||||
char *IntNameToExt(const char *Name);
|
|
||||||
void ExtToInt(const char *Src,char *Dest);
|
|
||||||
void IntToExt(const char *Src,char *Dest);
|
|
||||||
char* strlower(char *Str);
|
|
||||||
char* strupper(char *Str);
|
|
||||||
int stricomp(const char *Str1,const char *Str2);
|
|
||||||
int strnicomp(const char *Str1,const char *Str2,int N);
|
|
||||||
char* RemoveEOL(char *Str);
|
|
||||||
char* RemoveLF(char *Str);
|
|
||||||
unsigned int loctolower(byte ch);
|
|
||||||
unsigned int loctoupper(byte ch);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool LowAscii(const char *Str);
|
|
||||||
bool LowAscii(const wchar *Str);
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
#ifndef _RAR_STRLIST_
|
|
||||||
#define _RAR_STRLIST_
|
|
||||||
|
|
||||||
class StringList
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
Array<char> StringData;
|
|
||||||
unsigned int CurPos;
|
|
||||||
|
|
||||||
Array<wchar> StringDataW;
|
|
||||||
unsigned int CurPosW;
|
|
||||||
|
|
||||||
Array<int> PosDataW;
|
|
||||||
uint PosDataItem;
|
|
||||||
|
|
||||||
uint StringsCount;
|
|
||||||
|
|
||||||
uint SaveCurPos[16],SaveCurPosW[16],SavePosDataItem[16],SavePosNumber;
|
|
||||||
public:
|
|
||||||
StringList();
|
|
||||||
~StringList();
|
|
||||||
void Reset();
|
|
||||||
unsigned int AddString(const char *Str);
|
|
||||||
unsigned int AddString(const char *Str,const wchar *StrW);
|
|
||||||
bool GetString(char *Str,int MaxLength);
|
|
||||||
bool GetString(char *Str,wchar *StrW,int MaxLength);
|
|
||||||
bool GetString(char *Str,wchar *StrW,int MaxLength,int StringNum);
|
|
||||||
char* GetString();
|
|
||||||
bool GetString(char **Str,wchar **StrW);
|
|
||||||
char* GetString(unsigned int StringPos);
|
|
||||||
void Rewind();
|
|
||||||
unsigned int ItemsCount() {return(StringsCount);};
|
|
||||||
int GetBufferSize();
|
|
||||||
bool Search(char *Str,wchar *StrW,bool CaseSensitive);
|
|
||||||
void SavePosition();
|
|
||||||
void RestorePosition();
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,241 +0,0 @@
|
|||||||
/****************************************************************************
|
|
||||||
* This file is part of PPMd project *
|
|
||||||
* Written and distributed to public domain by Dmitry Shkarin 1997, *
|
|
||||||
* 1999-2000 *
|
|
||||||
* Contents: memory allocation routines *
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
SubAllocator::SubAllocator()
|
|
||||||
{
|
|
||||||
Clean();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void SubAllocator::Clean()
|
|
||||||
{
|
|
||||||
SubAllocatorSize=0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
inline void SubAllocator::InsertNode(void* p,int indx)
|
|
||||||
{
|
|
||||||
((RAR_NODE*) p)->next=FreeList[indx].next;
|
|
||||||
FreeList[indx].next=(RAR_NODE*) p;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
inline void* SubAllocator::RemoveNode(int indx)
|
|
||||||
{
|
|
||||||
RAR_NODE* RetVal=FreeList[indx].next;
|
|
||||||
FreeList[indx].next=RetVal->next;
|
|
||||||
return RetVal;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
inline uint SubAllocator::U2B(int NU)
|
|
||||||
{
|
|
||||||
return /*8*NU+4*NU*/UNIT_SIZE*NU;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
inline void SubAllocator::SplitBlock(void* pv,int OldIndx,int NewIndx)
|
|
||||||
{
|
|
||||||
int i, UDiff=Indx2Units[OldIndx]-Indx2Units[NewIndx];
|
|
||||||
byte* p=((byte*) pv)+U2B(Indx2Units[NewIndx]);
|
|
||||||
if (Indx2Units[i=Units2Indx[UDiff-1]] != UDiff)
|
|
||||||
{
|
|
||||||
InsertNode(p,--i);
|
|
||||||
p += U2B(i=Indx2Units[i]);
|
|
||||||
UDiff -= i;
|
|
||||||
}
|
|
||||||
InsertNode(p,Units2Indx[UDiff-1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void SubAllocator::StopSubAllocator()
|
|
||||||
{
|
|
||||||
if ( SubAllocatorSize )
|
|
||||||
{
|
|
||||||
SubAllocatorSize=0;
|
|
||||||
rarfree(HeapStart);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool SubAllocator::StartSubAllocator(int SASize)
|
|
||||||
{
|
|
||||||
uint t=SASize << 20;
|
|
||||||
if (SubAllocatorSize == t)
|
|
||||||
return TRUE;
|
|
||||||
StopSubAllocator();
|
|
||||||
uint AllocSize=t/FIXED_UNIT_SIZE*UNIT_SIZE+UNIT_SIZE;
|
|
||||||
if ((HeapStart=(byte *)rarmalloc(AllocSize)) == NULL)
|
|
||||||
{
|
|
||||||
ErrHandler.MemoryError();
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
HeapEnd=HeapStart+AllocSize-UNIT_SIZE;
|
|
||||||
SubAllocatorSize=t;
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void SubAllocator::InitSubAllocator()
|
|
||||||
{
|
|
||||||
int i, k;
|
|
||||||
memset(FreeList,0,sizeof(FreeList));
|
|
||||||
pText=HeapStart;
|
|
||||||
uint Size2=FIXED_UNIT_SIZE*(SubAllocatorSize/8/FIXED_UNIT_SIZE*7);
|
|
||||||
uint RealSize2=Size2/FIXED_UNIT_SIZE*UNIT_SIZE;
|
|
||||||
uint Size1=SubAllocatorSize-Size2;
|
|
||||||
uint RealSize1=Size1/FIXED_UNIT_SIZE*UNIT_SIZE+Size1%FIXED_UNIT_SIZE;
|
|
||||||
HiUnit=HeapStart+SubAllocatorSize;
|
|
||||||
LoUnit=UnitsStart=HeapStart+RealSize1;
|
|
||||||
FakeUnitsStart=HeapStart+Size1;
|
|
||||||
HiUnit=LoUnit+RealSize2;
|
|
||||||
for (i=0,k=1;i < N1 ;i++,k += 1)
|
|
||||||
Indx2Units[i]=k;
|
|
||||||
for (k++;i < N1+N2 ;i++,k += 2)
|
|
||||||
Indx2Units[i]=k;
|
|
||||||
for (k++;i < N1+N2+N3 ;i++,k += 3)
|
|
||||||
Indx2Units[i]=k;
|
|
||||||
for (k++;i < N1+N2+N3+N4;i++,k += 4)
|
|
||||||
Indx2Units[i]=k;
|
|
||||||
for (GlueCount=k=i=0;k < 128;k++)
|
|
||||||
{
|
|
||||||
i += (Indx2Units[i] < k+1);
|
|
||||||
Units2Indx[k]=i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
inline void SubAllocator::GlueFreeBlocks()
|
|
||||||
{
|
|
||||||
RAR_MEM_BLK s0, * p, * p1;
|
|
||||||
int i, k, sz;
|
|
||||||
if (LoUnit != HiUnit)
|
|
||||||
*LoUnit=0;
|
|
||||||
for (i=0, s0.next=s0.prev=&s0;i < N_INDEXES;i++)
|
|
||||||
while ( FreeList[i].next )
|
|
||||||
{
|
|
||||||
p=(RAR_MEM_BLK*)RemoveNode(i);
|
|
||||||
p->insertAt(&s0);
|
|
||||||
p->Stamp=0xFFFF;
|
|
||||||
p->NU=Indx2Units[i];
|
|
||||||
}
|
|
||||||
for (p=s0.next;p != &s0;p=p->next)
|
|
||||||
while ((p1=p+p->NU)->Stamp == 0xFFFF && int(p->NU)+p1->NU < 0x10000)
|
|
||||||
{
|
|
||||||
p1->remove();
|
|
||||||
p->NU += p1->NU;
|
|
||||||
}
|
|
||||||
while ((p=s0.next) != &s0)
|
|
||||||
{
|
|
||||||
for (p->remove(), sz=p->NU;sz > 128;sz -= 128, p += 128)
|
|
||||||
InsertNode(p,N_INDEXES-1);
|
|
||||||
if (Indx2Units[i=Units2Indx[sz-1]] != sz)
|
|
||||||
{
|
|
||||||
k=sz-Indx2Units[--i];
|
|
||||||
InsertNode(p+(sz-k),k-1);
|
|
||||||
}
|
|
||||||
InsertNode(p,i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void* SubAllocator::AllocUnitsRare(int indx)
|
|
||||||
{
|
|
||||||
if ( !GlueCount )
|
|
||||||
{
|
|
||||||
GlueCount = 255;
|
|
||||||
GlueFreeBlocks();
|
|
||||||
if ( FreeList[indx].next )
|
|
||||||
return RemoveNode(indx);
|
|
||||||
}
|
|
||||||
int i=indx;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
if (++i == N_INDEXES)
|
|
||||||
{
|
|
||||||
GlueCount--;
|
|
||||||
i=U2B(Indx2Units[indx]);
|
|
||||||
int j=12*Indx2Units[indx];
|
|
||||||
if (FakeUnitsStart-pText > j)
|
|
||||||
{
|
|
||||||
FakeUnitsStart-=j;
|
|
||||||
UnitsStart -= i;
|
|
||||||
return(UnitsStart);
|
|
||||||
}
|
|
||||||
return(NULL);
|
|
||||||
}
|
|
||||||
} while ( !FreeList[i].next );
|
|
||||||
void* RetVal=RemoveNode(i);
|
|
||||||
SplitBlock(RetVal,i,indx);
|
|
||||||
return RetVal;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
inline void* SubAllocator::AllocUnits(int NU)
|
|
||||||
{
|
|
||||||
int indx=Units2Indx[NU-1];
|
|
||||||
if ( FreeList[indx].next )
|
|
||||||
return RemoveNode(indx);
|
|
||||||
void* RetVal=LoUnit;
|
|
||||||
LoUnit += U2B(Indx2Units[indx]);
|
|
||||||
if (LoUnit <= HiUnit)
|
|
||||||
return RetVal;
|
|
||||||
LoUnit -= U2B(Indx2Units[indx]);
|
|
||||||
return AllocUnitsRare(indx);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void* SubAllocator::AllocContext()
|
|
||||||
{
|
|
||||||
if (HiUnit != LoUnit)
|
|
||||||
return (HiUnit -= UNIT_SIZE);
|
|
||||||
if ( FreeList->next )
|
|
||||||
return RemoveNode(0);
|
|
||||||
return AllocUnitsRare(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void* SubAllocator::ExpandUnits(void* OldPtr,int OldNU)
|
|
||||||
{
|
|
||||||
int i0=Units2Indx[OldNU-1], i1=Units2Indx[OldNU-1+1];
|
|
||||||
if (i0 == i1)
|
|
||||||
return OldPtr;
|
|
||||||
void* ptr=AllocUnits(OldNU+1);
|
|
||||||
if ( ptr )
|
|
||||||
{
|
|
||||||
memcpy(ptr,OldPtr,U2B(OldNU));
|
|
||||||
InsertNode(OldPtr,i0);
|
|
||||||
}
|
|
||||||
return ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void* SubAllocator::ShrinkUnits(void* OldPtr,int OldNU,int NewNU)
|
|
||||||
{
|
|
||||||
int i0=Units2Indx[OldNU-1], i1=Units2Indx[NewNU-1];
|
|
||||||
if (i0 == i1)
|
|
||||||
return OldPtr;
|
|
||||||
if ( FreeList[i1].next )
|
|
||||||
{
|
|
||||||
void* ptr=RemoveNode(i1);
|
|
||||||
memcpy(ptr,OldPtr,U2B(NewNU));
|
|
||||||
InsertNode(OldPtr,i0);
|
|
||||||
return ptr;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
SplitBlock(OldPtr,i0,i1);
|
|
||||||
return OldPtr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void SubAllocator::FreeUnits(void* ptr,int OldNU)
|
|
||||||
{
|
|
||||||
InsertNode(ptr,Units2Indx[OldNU-1]);
|
|
||||||
}
|
|
||||||
@@ -1,81 +0,0 @@
|
|||||||
/****************************************************************************
|
|
||||||
* This file is part of PPMd project *
|
|
||||||
* Written and distributed to public domain by Dmitry Shkarin 1997, *
|
|
||||||
* 1999-2000 *
|
|
||||||
* Contents: interface to memory allocation routines *
|
|
||||||
****************************************************************************/
|
|
||||||
#if !defined(_SUBALLOC_H_)
|
|
||||||
#define _SUBALLOC_H_
|
|
||||||
|
|
||||||
const int N1=4, N2=4, N3=4, N4=(128+3-1*N1-2*N2-3*N3)/4;
|
|
||||||
const int N_INDEXES=N1+N2+N3+N4;
|
|
||||||
|
|
||||||
#if defined(__GNUC__)
|
|
||||||
#define _PACK_ATTR __attribute__ ((packed))
|
|
||||||
#else
|
|
||||||
#define _PACK_ATTR
|
|
||||||
#endif /* defined(__GNUC__) */
|
|
||||||
|
|
||||||
#pragma pack(1)
|
|
||||||
struct RAR_MEM_BLK
|
|
||||||
{
|
|
||||||
ushort Stamp, NU;
|
|
||||||
RAR_MEM_BLK* next, * prev;
|
|
||||||
void insertAt(RAR_MEM_BLK* p)
|
|
||||||
{
|
|
||||||
next=(prev=p)->next;
|
|
||||||
p->next=next->prev=this;
|
|
||||||
}
|
|
||||||
void remove()
|
|
||||||
{
|
|
||||||
prev->next=next;
|
|
||||||
next->prev=prev;
|
|
||||||
}
|
|
||||||
} _PACK_ATTR;
|
|
||||||
|
|
||||||
#ifdef _AIX
|
|
||||||
#pragma pack(pop)
|
|
||||||
#else
|
|
||||||
#pragma pack()
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
struct RAR_NODE
|
|
||||||
{
|
|
||||||
RAR_NODE* next;
|
|
||||||
};
|
|
||||||
|
|
||||||
class SubAllocator
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
inline void InsertNode(void* p,int indx);
|
|
||||||
inline void* RemoveNode(int indx);
|
|
||||||
inline uint U2B(int NU);
|
|
||||||
inline void SplitBlock(void* pv,int OldIndx,int NewIndx);
|
|
||||||
uint GetUsedMemory();
|
|
||||||
inline void GlueFreeBlocks();
|
|
||||||
void* AllocUnitsRare(int indx);
|
|
||||||
|
|
||||||
long SubAllocatorSize;
|
|
||||||
byte Indx2Units[N_INDEXES], Units2Indx[128], GlueCount;
|
|
||||||
byte *HeapStart,*LoUnit, *HiUnit;
|
|
||||||
struct RAR_NODE FreeList[N_INDEXES];
|
|
||||||
public:
|
|
||||||
SubAllocator();
|
|
||||||
~SubAllocator() {StopSubAllocator();}
|
|
||||||
void Clean();
|
|
||||||
bool StartSubAllocator(int SASize);
|
|
||||||
void StopSubAllocator();
|
|
||||||
void InitSubAllocator();
|
|
||||||
inline void* AllocContext();
|
|
||||||
inline void* AllocUnits(int NU);
|
|
||||||
inline void* ExpandUnits(void* ptr,int OldNU);
|
|
||||||
inline void* ShrinkUnits(void* ptr,int OldNU,int NewNU);
|
|
||||||
inline void FreeUnits(void* ptr,int OldNU);
|
|
||||||
long GetAllocatedMemory() {return(SubAllocatorSize);};
|
|
||||||
|
|
||||||
byte *pText, *UnitsStart,*HeapEnd,*FakeUnitsStart;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* !defined(_SUBALLOC_H_) */
|
|
||||||
@@ -1,79 +0,0 @@
|
|||||||
#include "rar.hpp"
|
|
||||||
|
|
||||||
#ifndef _WIN_CE
|
|
||||||
static int SleepTime=0;
|
|
||||||
|
|
||||||
void InitSystemOptions(int SleepTime)
|
|
||||||
{
|
|
||||||
::SleepTime=SleepTime;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#if !defined(SFX_MODULE) && !defined(_WIN_CE)
|
|
||||||
|
|
||||||
#if defined(_WIN_32) && !defined(BELOW_NORMAL_PRIORITY_CLASS)
|
|
||||||
#define BELOW_NORMAL_PRIORITY_CLASS 0x00004000
|
|
||||||
#define ABOVE_NORMAL_PRIORITY_CLASS 0x00008000
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void SetPriority(int Priority)
|
|
||||||
{
|
|
||||||
#ifdef _WIN_32
|
|
||||||
uint PriorityClass;
|
|
||||||
int PriorityLevel;
|
|
||||||
if (Priority<1 || Priority>15)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (Priority==1)
|
|
||||||
{
|
|
||||||
PriorityClass=IDLE_PRIORITY_CLASS;
|
|
||||||
PriorityLevel=THREAD_PRIORITY_IDLE;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
if (Priority<7)
|
|
||||||
{
|
|
||||||
PriorityClass=IDLE_PRIORITY_CLASS;
|
|
||||||
PriorityLevel=Priority-4;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
if (Priority==7)
|
|
||||||
{
|
|
||||||
PriorityClass=BELOW_NORMAL_PRIORITY_CLASS;
|
|
||||||
PriorityLevel=THREAD_PRIORITY_ABOVE_NORMAL;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
if (Priority<10)
|
|
||||||
{
|
|
||||||
PriorityClass=NORMAL_PRIORITY_CLASS;
|
|
||||||
PriorityLevel=Priority-7;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
if (Priority==10)
|
|
||||||
{
|
|
||||||
PriorityClass=ABOVE_NORMAL_PRIORITY_CLASS;
|
|
||||||
PriorityLevel=THREAD_PRIORITY_NORMAL;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
PriorityClass=HIGH_PRIORITY_CLASS;
|
|
||||||
PriorityLevel=Priority-13;
|
|
||||||
}
|
|
||||||
SetPriorityClass(GetCurrentProcess(),PriorityClass);
|
|
||||||
SetThreadPriority(GetCurrentThread(),PriorityLevel);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
void Wait()
|
|
||||||
{
|
|
||||||
#if defined(_WIN_32) && !defined(_WIN_CE) && !defined(SFX_MODULE)
|
|
||||||
if (SleepTime!=0)
|
|
||||||
Sleep(SleepTime);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
#ifndef _RAR_SYSTEM_
|
|
||||||
#define _RAR_SYSTEM_
|
|
||||||
|
|
||||||
void InitSystemOptions(int SleepTime);
|
|
||||||
void SetPriority(int Priority);
|
|
||||||
void Wait();
|
|
||||||
bool EmailFile(char *FileName,char *MailTo);
|
|
||||||
void Shutdown();
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
#ifndef _RAR_TIMEFN_
|
|
||||||
#define _RAR_TIMEFN_
|
|
||||||
|
|
||||||
struct RarLocalTime
|
|
||||||
{
|
|
||||||
uint Year;
|
|
||||||
uint Month;
|
|
||||||
uint Day;
|
|
||||||
uint Hour;
|
|
||||||
uint Minute;
|
|
||||||
uint Second;
|
|
||||||
uint Reminder;
|
|
||||||
uint wDay;
|
|
||||||
uint yDay;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class RarTime
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
Int64 GetRaw();
|
|
||||||
void SetRaw(Int64 RawTime);
|
|
||||||
|
|
||||||
RarLocalTime rlt;
|
|
||||||
|
|
||||||
Int64 Time;
|
|
||||||
public:
|
|
||||||
RarTime();
|
|
||||||
#ifdef _WIN_32
|
|
||||||
RarTime& operator =(FILETIME &ft);
|
|
||||||
void GetWin32(FILETIME *ft);
|
|
||||||
#endif
|
|
||||||
#if defined(_UNIX) || defined(_EMX)
|
|
||||||
RarTime& operator =(time_t ut);
|
|
||||||
time_t GetUnix();
|
|
||||||
#endif
|
|
||||||
bool operator == (RarTime &rt);
|
|
||||||
bool operator < (RarTime &rt);
|
|
||||||
bool operator <= (RarTime &rt);
|
|
||||||
bool operator > (RarTime &rt);
|
|
||||||
bool operator >= (RarTime &rt);
|
|
||||||
void GetLocal(RarLocalTime *lt) {*lt=rlt;}
|
|
||||||
void SetLocal(RarLocalTime *lt) {rlt=*lt;}
|
|
||||||
uint GetDos();
|
|
||||||
void SetDos(uint DosTime);
|
|
||||||
void GetText(char *DateStr,bool FullYear);
|
|
||||||
void SetIsoText(char *TimeText);
|
|
||||||
void SetAgeText(char *TimeText);
|
|
||||||
void SetCurrentTime();
|
|
||||||
void Reset() {rlt.Year=0;}
|
|
||||||
bool IsSet() {return(rlt.Year!=0);}
|
|
||||||
};
|
|
||||||
|
|
||||||
const char *GetMonthName(int Month);
|
|
||||||
bool IsLeapYear(int Year);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user