mirror of
https://github.com/Xevion/easy7zip.git
synced 2026-01-31 06:24:13 -06:00
4.61 beta
This commit is contained in:
committed by
Kornel Lesiński
parent
c10e6b16f6
commit
b717a4dbfe
@@ -1,7 +1,5 @@
|
|||||||
/* 7zBuf.h -- Byte Buffer
|
/* 7zBuf.h -- Byte Buffer
|
||||||
2008-05-01
|
2008-10-04 : Igor Pavlov : Public domain */
|
||||||
Igor Pavlov
|
|
||||||
Public domain */
|
|
||||||
|
|
||||||
#ifndef __7Z_BUF_H
|
#ifndef __7Z_BUF_H
|
||||||
#define __7Z_BUF_H
|
#define __7Z_BUF_H
|
||||||
@@ -18,4 +16,16 @@ void Buf_Init(CBuf *p);
|
|||||||
int Buf_Create(CBuf *p, size_t size, ISzAlloc *alloc);
|
int Buf_Create(CBuf *p, size_t size, ISzAlloc *alloc);
|
||||||
void Buf_Free(CBuf *p, ISzAlloc *alloc);
|
void Buf_Free(CBuf *p, ISzAlloc *alloc);
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
Byte *data;
|
||||||
|
size_t size;
|
||||||
|
size_t pos;
|
||||||
|
} CDynBuf;
|
||||||
|
|
||||||
|
void DynBuf_Construct(CDynBuf *p);
|
||||||
|
void DynBuf_SeekToBeg(CDynBuf *p);
|
||||||
|
int DynBuf_Write(CDynBuf *p, const Byte *buf, size_t size, ISzAlloc *alloc);
|
||||||
|
void DynBuf_Free(CDynBuf *p, ISzAlloc *alloc);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Executable
+45
@@ -0,0 +1,45 @@
|
|||||||
|
/* 7zBuf2.c -- Byte Buffer
|
||||||
|
2008-10-04 : Igor Pavlov : Public domain */
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include "7zBuf.h"
|
||||||
|
|
||||||
|
void DynBuf_Construct(CDynBuf *p)
|
||||||
|
{
|
||||||
|
p->data = 0;
|
||||||
|
p->size = 0;
|
||||||
|
p->pos = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DynBuf_SeekToBeg(CDynBuf *p)
|
||||||
|
{
|
||||||
|
p->pos = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DynBuf_Write(CDynBuf *p, const Byte *buf, size_t size, ISzAlloc *alloc)
|
||||||
|
{
|
||||||
|
if (size > p->size - p->pos)
|
||||||
|
{
|
||||||
|
size_t newSize = p->pos + size;
|
||||||
|
Byte *data;
|
||||||
|
newSize += newSize / 4;
|
||||||
|
data = (Byte *)alloc->Alloc(alloc, newSize);
|
||||||
|
if (data == 0)
|
||||||
|
return 0;
|
||||||
|
p->size = newSize;
|
||||||
|
memcpy(data, p->data, p->pos);
|
||||||
|
alloc->Free(alloc, p->data);
|
||||||
|
p->data = data;
|
||||||
|
}
|
||||||
|
memcpy(p->data + p->pos, buf, size);
|
||||||
|
p->pos += size;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DynBuf_Free(CDynBuf *p, ISzAlloc *alloc)
|
||||||
|
{
|
||||||
|
alloc->Free(alloc, p->data);
|
||||||
|
p->data = 0;
|
||||||
|
p->size = 0;
|
||||||
|
p->pos = 0;
|
||||||
|
}
|
||||||
Executable
+263
@@ -0,0 +1,263 @@
|
|||||||
|
/* 7zFile.c -- File IO
|
||||||
|
2008-11-22 : Igor Pavlov : Public domain */
|
||||||
|
|
||||||
|
#include "7zFile.h"
|
||||||
|
|
||||||
|
#ifndef USE_WINDOWS_FILE
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef USE_WINDOWS_FILE
|
||||||
|
|
||||||
|
/*
|
||||||
|
ReadFile and WriteFile functions in Windows have BUG:
|
||||||
|
If you Read or Write 64MB or more (probably min_failure_size = 64MB - 32KB + 1)
|
||||||
|
from/to Network file, it returns ERROR_NO_SYSTEM_RESOURCES
|
||||||
|
(Insufficient system resources exist to complete the requested service).
|
||||||
|
Probably in some version of Windows there are problems with other sizes:
|
||||||
|
for 32 MB (maybe also for 16 MB).
|
||||||
|
And message can be "Network connection was lost"
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define kChunkSizeMax (1 << 22)
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void File_Construct(CSzFile *p)
|
||||||
|
{
|
||||||
|
#ifdef USE_WINDOWS_FILE
|
||||||
|
p->handle = INVALID_HANDLE_VALUE;
|
||||||
|
#else
|
||||||
|
p->file = NULL;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
static WRes File_Open(CSzFile *p, const char *name, int writeMode)
|
||||||
|
{
|
||||||
|
#ifdef USE_WINDOWS_FILE
|
||||||
|
p->handle = CreateFileA(name,
|
||||||
|
writeMode ? GENERIC_WRITE : GENERIC_READ,
|
||||||
|
FILE_SHARE_READ, NULL,
|
||||||
|
writeMode ? CREATE_ALWAYS : OPEN_EXISTING,
|
||||||
|
FILE_ATTRIBUTE_NORMAL, NULL);
|
||||||
|
return (p->handle != INVALID_HANDLE_VALUE) ? 0 : GetLastError();
|
||||||
|
#else
|
||||||
|
p->file = fopen(name, writeMode ? "wb+" : "rb");
|
||||||
|
return (p->file != 0) ? 0 : errno;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
WRes InFile_Open(CSzFile *p, const char *name) { return File_Open(p, name, 0); }
|
||||||
|
WRes OutFile_Open(CSzFile *p, const char *name) { return File_Open(p, name, 1); }
|
||||||
|
|
||||||
|
WRes File_Close(CSzFile *p)
|
||||||
|
{
|
||||||
|
#ifdef USE_WINDOWS_FILE
|
||||||
|
if (p->handle != INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
|
if (!CloseHandle(p->handle))
|
||||||
|
return GetLastError();
|
||||||
|
p->handle = INVALID_HANDLE_VALUE;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
if (p->file != NULL)
|
||||||
|
{
|
||||||
|
int res = fclose(p->file);
|
||||||
|
if (res != 0)
|
||||||
|
return res;
|
||||||
|
p->file = NULL;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
WRes File_Read(CSzFile *p, void *data, size_t *size)
|
||||||
|
{
|
||||||
|
size_t originalSize = *size;
|
||||||
|
if (originalSize == 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
#ifdef USE_WINDOWS_FILE
|
||||||
|
|
||||||
|
*size = 0;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
DWORD curSize = (originalSize > kChunkSizeMax) ? kChunkSizeMax : (DWORD)originalSize;
|
||||||
|
DWORD processed = 0;
|
||||||
|
BOOL res = ReadFile(p->handle, data, curSize, &processed, NULL);
|
||||||
|
data = (void *)((Byte *)data + processed);
|
||||||
|
originalSize -= processed;
|
||||||
|
*size += processed;
|
||||||
|
if (!res)
|
||||||
|
return GetLastError();
|
||||||
|
if (processed == 0)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
while (originalSize > 0);
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
*size = fread(data, 1, originalSize, p->file);
|
||||||
|
if (*size == originalSize)
|
||||||
|
return 0;
|
||||||
|
return ferror(p->file);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
WRes File_Write(CSzFile *p, const void *data, size_t *size)
|
||||||
|
{
|
||||||
|
size_t originalSize = *size;
|
||||||
|
if (originalSize == 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
#ifdef USE_WINDOWS_FILE
|
||||||
|
|
||||||
|
*size = 0;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
DWORD curSize = (originalSize > kChunkSizeMax) ? kChunkSizeMax : (DWORD)originalSize;
|
||||||
|
DWORD processed = 0;
|
||||||
|
BOOL res = WriteFile(p->handle, data, curSize, &processed, NULL);
|
||||||
|
data = (void *)((Byte *)data + processed);
|
||||||
|
originalSize -= processed;
|
||||||
|
*size += processed;
|
||||||
|
if (!res)
|
||||||
|
return GetLastError();
|
||||||
|
if (processed == 0)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
while (originalSize > 0);
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
*size = fwrite(data, 1, originalSize, p->file);
|
||||||
|
if (*size == originalSize)
|
||||||
|
return 0;
|
||||||
|
return ferror(p->file);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
WRes File_Seek(CSzFile *p, Int64 *pos, ESzSeek origin)
|
||||||
|
{
|
||||||
|
#ifdef USE_WINDOWS_FILE
|
||||||
|
|
||||||
|
LARGE_INTEGER value;
|
||||||
|
DWORD moveMethod;
|
||||||
|
value.LowPart = (DWORD)*pos;
|
||||||
|
value.HighPart = (LONG)((UInt64)*pos >> 16 >> 16); /* for case when UInt64 is 32-bit only */
|
||||||
|
switch (origin)
|
||||||
|
{
|
||||||
|
case SZ_SEEK_SET: moveMethod = FILE_BEGIN; break;
|
||||||
|
case SZ_SEEK_CUR: moveMethod = FILE_CURRENT; break;
|
||||||
|
case SZ_SEEK_END: moveMethod = FILE_END; break;
|
||||||
|
default: return ERROR_INVALID_PARAMETER;
|
||||||
|
}
|
||||||
|
value.LowPart = SetFilePointer(p->handle, value.LowPart, &value.HighPart, moveMethod);
|
||||||
|
if (value.LowPart == 0xFFFFFFFF)
|
||||||
|
{
|
||||||
|
WRes res = GetLastError();
|
||||||
|
if (res != NO_ERROR)
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
*pos = ((Int64)value.HighPart << 32) | value.LowPart;
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
int moveMethod;
|
||||||
|
int res;
|
||||||
|
switch (origin)
|
||||||
|
{
|
||||||
|
case SZ_SEEK_SET: moveMethod = SEEK_SET; break;
|
||||||
|
case SZ_SEEK_CUR: moveMethod = SEEK_CUR; break;
|
||||||
|
case SZ_SEEK_END: moveMethod = SEEK_END; break;
|
||||||
|
default: return 1;
|
||||||
|
}
|
||||||
|
res = fseek(p->file, (long)*pos, moveMethod);
|
||||||
|
*pos = ftell(p->file);
|
||||||
|
return res;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
WRes File_GetLength(CSzFile *p, UInt64 *length)
|
||||||
|
{
|
||||||
|
#ifdef USE_WINDOWS_FILE
|
||||||
|
|
||||||
|
DWORD sizeHigh;
|
||||||
|
DWORD sizeLow = GetFileSize(p->handle, &sizeHigh);
|
||||||
|
if (sizeLow == 0xFFFFFFFF)
|
||||||
|
{
|
||||||
|
DWORD res = GetLastError();
|
||||||
|
if (res != NO_ERROR)
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
*length = (((UInt64)sizeHigh) << 32) + sizeLow;
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
long pos = ftell(p->file);
|
||||||
|
int res = fseek(p->file, 0, SEEK_END);
|
||||||
|
*length = ftell(p->file);
|
||||||
|
fseek(p->file, pos, SEEK_SET);
|
||||||
|
return res;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* ---------- FileSeqInStream ---------- */
|
||||||
|
|
||||||
|
static SRes FileSeqInStream_Read(void *pp, void *buf, size_t *size)
|
||||||
|
{
|
||||||
|
CFileSeqInStream *p = (CFileSeqInStream *)pp;
|
||||||
|
return File_Read(&p->file, buf, size) == 0 ? SZ_OK : SZ_ERROR_READ;
|
||||||
|
}
|
||||||
|
|
||||||
|
void FileSeqInStream_CreateVTable(CFileSeqInStream *p)
|
||||||
|
{
|
||||||
|
p->s.Read = FileSeqInStream_Read;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* ---------- FileInStream ---------- */
|
||||||
|
|
||||||
|
static SRes FileInStream_Read(void *pp, void *buf, size_t *size)
|
||||||
|
{
|
||||||
|
CFileInStream *p = (CFileInStream *)pp;
|
||||||
|
return (File_Read(&p->file, buf, size) == 0) ? SZ_OK : SZ_ERROR_READ;
|
||||||
|
}
|
||||||
|
|
||||||
|
static SRes FileInStream_Seek(void *pp, Int64 *pos, ESzSeek origin)
|
||||||
|
{
|
||||||
|
CFileInStream *p = (CFileInStream *)pp;
|
||||||
|
return File_Seek(&p->file, pos, origin);
|
||||||
|
}
|
||||||
|
|
||||||
|
void FileInStream_CreateVTable(CFileInStream *p)
|
||||||
|
{
|
||||||
|
p->s.Read = FileInStream_Read;
|
||||||
|
p->s.Seek = FileInStream_Seek;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* ---------- FileOutStream ---------- */
|
||||||
|
|
||||||
|
static size_t FileOutStream_Write(void *pp, const void *data, size_t size)
|
||||||
|
{
|
||||||
|
CFileOutStream *p = (CFileOutStream *)pp;
|
||||||
|
File_Write(&p->file, data, &size);
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
void FileOutStream_CreateVTable(CFileOutStream *p)
|
||||||
|
{
|
||||||
|
p->s.Write = FileOutStream_Write;
|
||||||
|
}
|
||||||
Executable
+74
@@ -0,0 +1,74 @@
|
|||||||
|
/* 7zFile.h -- File IO
|
||||||
|
2008-11-22 : Igor Pavlov : Public domain */
|
||||||
|
|
||||||
|
#ifndef __7Z_FILE_H
|
||||||
|
#define __7Z_FILE_H
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#define USE_WINDOWS_FILE
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef USE_WINDOWS_FILE
|
||||||
|
#include <windows.h>
|
||||||
|
#else
|
||||||
|
#include <stdio.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "Types.h"
|
||||||
|
|
||||||
|
|
||||||
|
/* ---------- File ---------- */
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
#ifdef USE_WINDOWS_FILE
|
||||||
|
HANDLE handle;
|
||||||
|
#else
|
||||||
|
FILE *file;
|
||||||
|
#endif
|
||||||
|
} CSzFile;
|
||||||
|
|
||||||
|
void File_Construct(CSzFile *p);
|
||||||
|
WRes InFile_Open(CSzFile *p, const char *name);
|
||||||
|
WRes OutFile_Open(CSzFile *p, const char *name);
|
||||||
|
WRes File_Close(CSzFile *p);
|
||||||
|
|
||||||
|
/* reads max(*size, remain file's size) bytes */
|
||||||
|
WRes File_Read(CSzFile *p, void *data, size_t *size);
|
||||||
|
|
||||||
|
/* writes *size bytes */
|
||||||
|
WRes File_Write(CSzFile *p, const void *data, size_t *size);
|
||||||
|
|
||||||
|
WRes File_Seek(CSzFile *p, Int64 *pos, ESzSeek origin);
|
||||||
|
WRes File_GetLength(CSzFile *p, UInt64 *length);
|
||||||
|
|
||||||
|
|
||||||
|
/* ---------- FileInStream ---------- */
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
ISeqInStream s;
|
||||||
|
CSzFile file;
|
||||||
|
} CFileSeqInStream;
|
||||||
|
|
||||||
|
void FileSeqInStream_CreateVTable(CFileSeqInStream *p);
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
ISeekInStream s;
|
||||||
|
CSzFile file;
|
||||||
|
} CFileInStream;
|
||||||
|
|
||||||
|
void FileInStream_CreateVTable(CFileInStream *p);
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
ISeqOutStream s;
|
||||||
|
CSzFile file;
|
||||||
|
} CFileOutStream;
|
||||||
|
|
||||||
|
void FileOutStream_CreateVTable(CFileOutStream *p);
|
||||||
|
|
||||||
|
#endif
|
||||||
Executable
+169
@@ -0,0 +1,169 @@
|
|||||||
|
/* 7zStream.c -- 7z Stream functions
|
||||||
|
2008-11-23 : Igor Pavlov : Public domain */
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "Types.h"
|
||||||
|
|
||||||
|
SRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType)
|
||||||
|
{
|
||||||
|
while (size != 0)
|
||||||
|
{
|
||||||
|
size_t processed = size;
|
||||||
|
RINOK(stream->Read(stream, buf, &processed));
|
||||||
|
if (processed == 0)
|
||||||
|
return errorType;
|
||||||
|
buf = (void *)((Byte *)buf + processed);
|
||||||
|
size -= processed;
|
||||||
|
}
|
||||||
|
return SZ_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
SRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size)
|
||||||
|
{
|
||||||
|
return SeqInStream_Read2(stream, buf, size, SZ_ERROR_INPUT_EOF);
|
||||||
|
}
|
||||||
|
|
||||||
|
SRes SeqInStream_ReadByte(ISeqInStream *stream, Byte *buf)
|
||||||
|
{
|
||||||
|
size_t processed = 1;
|
||||||
|
RINOK(stream->Read(stream, buf, &processed));
|
||||||
|
return (processed == 1) ? SZ_OK : SZ_ERROR_INPUT_EOF;
|
||||||
|
}
|
||||||
|
|
||||||
|
SRes LookInStream_SeekTo(ILookInStream *stream, UInt64 offset)
|
||||||
|
{
|
||||||
|
Int64 t = offset;
|
||||||
|
return stream->Seek(stream, &t, SZ_SEEK_SET);
|
||||||
|
}
|
||||||
|
|
||||||
|
SRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size)
|
||||||
|
{
|
||||||
|
void *lookBuf;
|
||||||
|
if (*size == 0)
|
||||||
|
return SZ_OK;
|
||||||
|
RINOK(stream->Look(stream, &lookBuf, size));
|
||||||
|
memcpy(buf, lookBuf, *size);
|
||||||
|
return stream->Skip(stream, *size);
|
||||||
|
}
|
||||||
|
|
||||||
|
SRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType)
|
||||||
|
{
|
||||||
|
while (size != 0)
|
||||||
|
{
|
||||||
|
size_t processed = size;
|
||||||
|
RINOK(stream->Read(stream, buf, &processed));
|
||||||
|
if (processed == 0)
|
||||||
|
return errorType;
|
||||||
|
buf = (void *)((Byte *)buf + processed);
|
||||||
|
size -= processed;
|
||||||
|
}
|
||||||
|
return SZ_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
SRes LookInStream_Read(ILookInStream *stream, void *buf, size_t size)
|
||||||
|
{
|
||||||
|
return LookInStream_Read2(stream, buf, size, SZ_ERROR_INPUT_EOF);
|
||||||
|
}
|
||||||
|
|
||||||
|
static SRes LookToRead_Look_Lookahead(void *pp, void **buf, size_t *size)
|
||||||
|
{
|
||||||
|
SRes res = SZ_OK;
|
||||||
|
CLookToRead *p = (CLookToRead *)pp;
|
||||||
|
size_t size2 = p->size - p->pos;
|
||||||
|
if (size2 == 0 && *size > 0)
|
||||||
|
{
|
||||||
|
p->pos = 0;
|
||||||
|
size2 = LookToRead_BUF_SIZE;
|
||||||
|
res = p->realStream->Read(p->realStream, p->buf, &size2);
|
||||||
|
p->size = size2;
|
||||||
|
}
|
||||||
|
if (size2 < *size)
|
||||||
|
*size = size2;
|
||||||
|
*buf = p->buf + p->pos;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
static SRes LookToRead_Look_Exact(void *pp, void **buf, size_t *size)
|
||||||
|
{
|
||||||
|
SRes res = SZ_OK;
|
||||||
|
CLookToRead *p = (CLookToRead *)pp;
|
||||||
|
size_t size2 = p->size - p->pos;
|
||||||
|
if (size2 == 0 && *size > 0)
|
||||||
|
{
|
||||||
|
p->pos = 0;
|
||||||
|
if (*size > LookToRead_BUF_SIZE)
|
||||||
|
*size = LookToRead_BUF_SIZE;
|
||||||
|
res = p->realStream->Read(p->realStream, p->buf, size);
|
||||||
|
size2 = p->size = *size;
|
||||||
|
}
|
||||||
|
if (size2 < *size)
|
||||||
|
*size = size2;
|
||||||
|
*buf = p->buf + p->pos;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
static SRes LookToRead_Skip(void *pp, size_t offset)
|
||||||
|
{
|
||||||
|
CLookToRead *p = (CLookToRead *)pp;
|
||||||
|
p->pos += offset;
|
||||||
|
return SZ_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
static SRes LookToRead_Read(void *pp, void *buf, size_t *size)
|
||||||
|
{
|
||||||
|
CLookToRead *p = (CLookToRead *)pp;
|
||||||
|
size_t rem = p->size - p->pos;
|
||||||
|
if (rem == 0)
|
||||||
|
return p->realStream->Read(p->realStream, buf, size);
|
||||||
|
if (rem > *size)
|
||||||
|
rem = *size;
|
||||||
|
memcpy(buf, p->buf + p->pos, rem);
|
||||||
|
p->pos += rem;
|
||||||
|
*size = rem;
|
||||||
|
return SZ_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
static SRes LookToRead_Seek(void *pp, Int64 *pos, ESzSeek origin)
|
||||||
|
{
|
||||||
|
CLookToRead *p = (CLookToRead *)pp;
|
||||||
|
p->pos = p->size = 0;
|
||||||
|
return p->realStream->Seek(p->realStream, pos, origin);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LookToRead_CreateVTable(CLookToRead *p, int lookahead)
|
||||||
|
{
|
||||||
|
p->s.Look = lookahead ?
|
||||||
|
LookToRead_Look_Lookahead :
|
||||||
|
LookToRead_Look_Exact;
|
||||||
|
p->s.Skip = LookToRead_Skip;
|
||||||
|
p->s.Read = LookToRead_Read;
|
||||||
|
p->s.Seek = LookToRead_Seek;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LookToRead_Init(CLookToRead *p)
|
||||||
|
{
|
||||||
|
p->pos = p->size = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static SRes SecToLook_Read(void *pp, void *buf, size_t *size)
|
||||||
|
{
|
||||||
|
CSecToLook *p = (CSecToLook *)pp;
|
||||||
|
return LookInStream_LookRead(p->realStream, buf, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SecToLook_CreateVTable(CSecToLook *p)
|
||||||
|
{
|
||||||
|
p->s.Read = SecToLook_Read;
|
||||||
|
}
|
||||||
|
|
||||||
|
static SRes SecToRead_Read(void *pp, void *buf, size_t *size)
|
||||||
|
{
|
||||||
|
CSecToRead *p = (CSecToRead *)pp;
|
||||||
|
return p->realStream->Read(p->realStream, buf, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SecToRead_CreateVTable(CSecToRead *p)
|
||||||
|
{
|
||||||
|
p->s.Read = SecToRead_Read;
|
||||||
|
}
|
||||||
Executable
+7
@@ -0,0 +1,7 @@
|
|||||||
|
#define MY_VER_MAJOR 4
|
||||||
|
#define MY_VER_MINOR 61
|
||||||
|
#define MY_VER_BUILD 0
|
||||||
|
#define MY_VERSION "4.61 beta"
|
||||||
|
#define MY_DATE "2008-10-28"
|
||||||
|
#define MY_COPYRIGHT ": Igor Pavlov : Public domain"
|
||||||
|
#define MY_VERSION_COPYRIGHT_DATE MY_VERSION " " MY_COPYRIGHT " : " MY_DATE
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/* Alloc.c -- Memory allocation functions
|
/* Alloc.c -- Memory allocation functions
|
||||||
2008-08-05
|
2008-09-24
|
||||||
Igor Pavlov
|
Igor Pavlov
|
||||||
Public domain */
|
Public domain */
|
||||||
|
|
||||||
@@ -25,16 +25,21 @@ void *MyAlloc(size_t size)
|
|||||||
if (size == 0)
|
if (size == 0)
|
||||||
return 0;
|
return 0;
|
||||||
#ifdef _SZ_ALLOC_DEBUG
|
#ifdef _SZ_ALLOC_DEBUG
|
||||||
fprintf(stderr, "\nAlloc %10d bytes; count = %10d", size, g_allocCount++);
|
{
|
||||||
#endif
|
void *p = malloc(size);
|
||||||
|
fprintf(stderr, "\nAlloc %10d bytes, count = %10d, addr = %8X", size, g_allocCount++, (unsigned)p);
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
#else
|
||||||
return malloc(size);
|
return malloc(size);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyFree(void *address)
|
void MyFree(void *address)
|
||||||
{
|
{
|
||||||
#ifdef _SZ_ALLOC_DEBUG
|
#ifdef _SZ_ALLOC_DEBUG
|
||||||
if (address != 0)
|
if (address != 0)
|
||||||
fprintf(stderr, "\nFree; count = %10d", --g_allocCount);
|
fprintf(stderr, "\nFree; count = %10d, addr = %8X", --g_allocCount, (unsigned)address);
|
||||||
#endif
|
#endif
|
||||||
free(address);
|
free(address);
|
||||||
}
|
}
|
||||||
|
|||||||
+14
-2
@@ -42,7 +42,7 @@ RSC=rc.exe
|
|||||||
# PROP Ignore_Export_Lib 0
|
# PROP Ignore_Export_Lib 0
|
||||||
# PROP Target_Dir ""
|
# PROP Target_Dir ""
|
||||||
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||||
# ADD CPP /nologo /MD /W3 /GX /O2 /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
# ADD CPP /nologo /MD /W3 /GX /O2 /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /FAs /YX /FD /c
|
||||||
# ADD BASE RSC /l 0x419 /d "NDEBUG"
|
# ADD BASE RSC /l 0x419 /d "NDEBUG"
|
||||||
# ADD RSC /l 0x419 /d "NDEBUG"
|
# ADD RSC /l 0x419 /d "NDEBUG"
|
||||||
BSC32=bscmake.exe
|
BSC32=bscmake.exe
|
||||||
@@ -67,7 +67,7 @@ LINK32=link.exe
|
|||||||
# PROP Ignore_Export_Lib 0
|
# PROP Ignore_Export_Lib 0
|
||||||
# PROP Target_Dir ""
|
# PROP Target_Dir ""
|
||||||
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||||
# ADD CPP /nologo /W4 /Gm /GX /ZI /Od /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
# ADD CPP /nologo /W4 /Gm /GX /ZI /Od /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_SZ_ALLOC_DEBUG2" /D "_SZ_NO_INT_64_A" /YX /FD /GZ /c
|
||||||
# ADD BASE RSC /l 0x419 /d "_DEBUG"
|
# ADD BASE RSC /l 0x419 /d "_DEBUG"
|
||||||
# ADD RSC /l 0x419 /d "_DEBUG"
|
# ADD RSC /l 0x419 /d "_DEBUG"
|
||||||
BSC32=bscmake.exe
|
BSC32=bscmake.exe
|
||||||
@@ -104,6 +104,18 @@ SOURCE=..\..\7zCrc.h
|
|||||||
# End Source File
|
# End Source File
|
||||||
# Begin Source File
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\..\7zFile.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\..\7zFile.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\..\7zStream.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
SOURCE=..\..\Bcj2.c
|
SOURCE=..\..\Bcj2.c
|
||||||
# End Source File
|
# End Source File
|
||||||
# Begin Source File
|
# Begin Source File
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/* 7zAlloc.c -- Allocation functions
|
/* 7zAlloc.c -- Allocation functions
|
||||||
2008-03-28
|
2008-10-04 : Igor Pavlov : Public domain */
|
||||||
Igor Pavlov
|
|
||||||
Public domain */
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "7zAlloc.h"
|
#include "7zAlloc.h"
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/* 7zAlloc.h -- Allocation functions
|
/* 7zAlloc.h -- Allocation functions
|
||||||
2008-03-28
|
2008-10-04 : Igor Pavlov : Public domain */
|
||||||
Igor Pavlov
|
|
||||||
Public domain */
|
|
||||||
|
|
||||||
#ifndef __7Z_ALLOC_H
|
#ifndef __7Z_ALLOC_H
|
||||||
#define __7Z_ALLOC_H
|
#define __7Z_ALLOC_H
|
||||||
|
|||||||
+52
-137
@@ -1,32 +1,23 @@
|
|||||||
/* 7zDecode.c Decoding from 7z folder
|
/* 7zDecode.c -- Decoding from 7z folder
|
||||||
2008-08-05
|
2008-11-23 : Igor Pavlov : Public domain */
|
||||||
Igor Pavlov
|
|
||||||
Copyright (c) 1999-2008 Igor Pavlov
|
|
||||||
Read 7zDecode.h for license options */
|
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "7zDecode.h"
|
|
||||||
#include "../../LzmaDec.h"
|
|
||||||
#include "../../Bra.h"
|
|
||||||
#include "../../Bcj2.h"
|
#include "../../Bcj2.h"
|
||||||
|
#include "../../Bra.h"
|
||||||
|
#include "../../LzmaDec.h"
|
||||||
|
#include "7zDecode.h"
|
||||||
|
|
||||||
#define k_Copy 0
|
#define k_Copy 0
|
||||||
#define k_LZMA 0x30101
|
#define k_LZMA 0x30101
|
||||||
#define k_BCJ 0x03030103
|
#define k_BCJ 0x03030103
|
||||||
#define k_BCJ2 0x0303011B
|
#define k_BCJ2 0x0303011B
|
||||||
|
|
||||||
/*
|
static SRes SzDecodeLzma(CSzCoderInfo *coder, UInt64 inSize, ILookInStream *inStream,
|
||||||
#ifdef _LZMA_IN_CB
|
Byte *outBuffer, SizeT outSize, ISzAlloc *allocMain)
|
||||||
*/
|
|
||||||
|
|
||||||
static SRes SzDecodeLzma(CSzCoderInfo *coder, CFileSize inSize, ISzInStream *inStream,
|
|
||||||
Byte *outBuffer, size_t outSize, ISzAlloc *allocMain)
|
|
||||||
{
|
{
|
||||||
CLzmaDec state;
|
CLzmaDec state;
|
||||||
int res = SZ_OK;
|
SRes res = SZ_OK;
|
||||||
size_t _inSize;
|
|
||||||
Byte *inBuf = NULL;
|
|
||||||
|
|
||||||
LzmaDec_Construct(&state);
|
LzmaDec_Construct(&state);
|
||||||
RINOK(LzmaDec_AllocateProbs(&state, coder->Props.data, (unsigned)coder->Props.size, allocMain));
|
RINOK(LzmaDec_AllocateProbs(&state, coder->Props.data, (unsigned)coder->Props.size, allocMain));
|
||||||
@@ -34,65 +25,60 @@ static SRes SzDecodeLzma(CSzCoderInfo *coder, CFileSize inSize, ISzInStream *inS
|
|||||||
state.dicBufSize = outSize;
|
state.dicBufSize = outSize;
|
||||||
LzmaDec_Init(&state);
|
LzmaDec_Init(&state);
|
||||||
|
|
||||||
_inSize = 0;
|
|
||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
if (_inSize == 0)
|
Byte *inBuf = NULL;
|
||||||
{
|
size_t lookahead = (1 << 18);
|
||||||
_inSize = (1 << 18);
|
if (lookahead > inSize)
|
||||||
if (_inSize > inSize)
|
lookahead = (size_t)inSize;
|
||||||
_inSize = (size_t)(inSize);
|
res = inStream->Look((void *)inStream, (void **)&inBuf, &lookahead);
|
||||||
res = inStream->Read((void *)inStream, (void **)&inBuf, &_inSize);
|
|
||||||
if (res != SZ_OK)
|
if (res != SZ_OK)
|
||||||
break;
|
break;
|
||||||
inSize -= _inSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
{
|
||||||
SizeT inProcessed = _inSize, dicPos = state.dicPos;
|
SizeT inProcessed = (SizeT)lookahead, dicPos = state.dicPos;
|
||||||
ELzmaStatus status;
|
ELzmaStatus status;
|
||||||
res = LzmaDec_DecodeToDic(&state, outSize, inBuf, &inProcessed, LZMA_FINISH_END, &status);
|
res = LzmaDec_DecodeToDic(&state, outSize, inBuf, &inProcessed, LZMA_FINISH_END, &status);
|
||||||
_inSize -= inProcessed;
|
lookahead -= inProcessed;
|
||||||
inBuf = (Byte *)inBuf + inProcessed;
|
inSize -= inProcessed;
|
||||||
if (res != SZ_OK)
|
if (res != SZ_OK)
|
||||||
break;
|
break;
|
||||||
if (state.dicPos == state.dicBufSize || (inProcessed == 0 && dicPos == state.dicPos))
|
if (state.dicPos == state.dicBufSize || (inProcessed == 0 && dicPos == state.dicPos))
|
||||||
{
|
{
|
||||||
if (state.dicBufSize != outSize || _inSize != 0 ||
|
if (state.dicBufSize != outSize || lookahead != 0 ||
|
||||||
(status != LZMA_STATUS_FINISHED_WITH_MARK &&
|
(status != LZMA_STATUS_FINISHED_WITH_MARK &&
|
||||||
status != LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK))
|
status != LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK))
|
||||||
res = SZ_ERROR_DATA;
|
res = SZ_ERROR_DATA;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
res = inStream->Skip((void *)inStream, inProcessed);
|
||||||
|
if (res != SZ_OK)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LzmaDec_FreeProbs(&state, allocMain);
|
LzmaDec_FreeProbs(&state, allocMain);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
static SRes SzDecodeCopy(CFileSize inSize, ISzInStream *inStream, Byte *outBuffer)
|
static SRes SzDecodeCopy(UInt64 inSize, ILookInStream *inStream, Byte *outBuffer)
|
||||||
{
|
{
|
||||||
while (inSize > 0)
|
while (inSize > 0)
|
||||||
{
|
{
|
||||||
void *inBuffer;
|
void *inBuf;
|
||||||
size_t curSize = (1 << 18);
|
size_t curSize = (1 << 18);
|
||||||
if (curSize > inSize)
|
if (curSize > inSize)
|
||||||
curSize = (size_t)(inSize);
|
curSize = (size_t)inSize;
|
||||||
RINOK(inStream->Read((void *)inStream, (void **)&inBuffer, &curSize));
|
RINOK(inStream->Look((void *)inStream, (void **)&inBuf, &curSize));
|
||||||
if (curSize == 0)
|
if (curSize == 0)
|
||||||
return SZ_ERROR_INPUT_EOF;
|
return SZ_ERROR_INPUT_EOF;
|
||||||
memcpy(outBuffer, inBuffer, curSize);
|
memcpy(outBuffer, inBuf, curSize);
|
||||||
outBuffer += curSize;
|
outBuffer += curSize;
|
||||||
inSize -= curSize;
|
inSize -= curSize;
|
||||||
|
RINOK(inStream->Skip((void *)inStream, curSize));
|
||||||
}
|
}
|
||||||
return SZ_OK;
|
return SZ_OK;
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
#endif
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define IS_UNSUPPORTED_METHOD(m) ((m) != k_Copy && (m) != k_LZMA)
|
#define IS_UNSUPPORTED_METHOD(m) ((m) != k_Copy && (m) != k_LZMA)
|
||||||
#define IS_UNSUPPORTED_CODER(c) (IS_UNSUPPORTED_METHOD(c.MethodID) || c.NumInStreams != 1 || c.NumOutStreams != 1)
|
#define IS_UNSUPPORTED_CODER(c) (IS_UNSUPPORTED_METHOD(c.MethodID) || c.NumInStreams != 1 || c.NumOutStreams != 1)
|
||||||
@@ -141,31 +127,23 @@ SRes CheckSupportedFolder(const CSzFolder *f)
|
|||||||
return SZ_ERROR_UNSUPPORTED;
|
return SZ_ERROR_UNSUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
CFileSize GetSum(const CFileSize *values, UInt32 index)
|
UInt64 GetSum(const UInt64 *values, UInt32 index)
|
||||||
{
|
{
|
||||||
CFileSize sum = 0;
|
UInt64 sum = 0;
|
||||||
UInt32 i;
|
UInt32 i;
|
||||||
for (i = 0; i < index; i++)
|
for (i = 0; i < index; i++)
|
||||||
sum += values[i];
|
sum += values[i];
|
||||||
return sum;
|
return sum;
|
||||||
}
|
}
|
||||||
|
|
||||||
SRes SzDecode2(const CFileSize *packSizes, const CSzFolder *folder,
|
SRes SzDecode2(const UInt64 *packSizes, const CSzFolder *folder,
|
||||||
/*
|
ILookInStream *inStream, UInt64 startPos,
|
||||||
#ifdef _LZMA_IN_CB
|
Byte *outBuffer, SizeT outSize, ISzAlloc *allocMain,
|
||||||
*/
|
|
||||||
ISzInStream *inStream, CFileSize startPos,
|
|
||||||
/*
|
|
||||||
#else
|
|
||||||
const Byte *inBuffer,
|
|
||||||
#endif
|
|
||||||
*/
|
|
||||||
Byte *outBuffer, size_t outSize, ISzAlloc *allocMain,
|
|
||||||
Byte *tempBuf[])
|
Byte *tempBuf[])
|
||||||
{
|
{
|
||||||
UInt32 ci;
|
UInt32 ci;
|
||||||
size_t tempSizes[3] = { 0, 0, 0};
|
SizeT tempSizes[3] = { 0, 0, 0};
|
||||||
size_t tempSize3 = 0;
|
SizeT tempSize3 = 0;
|
||||||
Byte *tempBuf3 = 0;
|
Byte *tempBuf3 = 0;
|
||||||
|
|
||||||
RINOK(CheckSupportedFolder(folder));
|
RINOK(CheckSupportedFolder(folder));
|
||||||
@@ -177,19 +155,19 @@ SRes SzDecode2(const CFileSize *packSizes, const CSzFolder *folder,
|
|||||||
if (coder->MethodID == k_Copy || coder->MethodID == k_LZMA)
|
if (coder->MethodID == k_Copy || coder->MethodID == k_LZMA)
|
||||||
{
|
{
|
||||||
UInt32 si = 0;
|
UInt32 si = 0;
|
||||||
CFileSize offset;
|
UInt64 offset;
|
||||||
CFileSize inSize;
|
UInt64 inSize;
|
||||||
Byte *outBufCur = outBuffer;
|
Byte *outBufCur = outBuffer;
|
||||||
size_t outSizeCur = outSize;
|
SizeT outSizeCur = outSize;
|
||||||
if (folder->NumCoders == 4)
|
if (folder->NumCoders == 4)
|
||||||
{
|
{
|
||||||
UInt32 indices[] = { 3, 2, 0 };
|
UInt32 indices[] = { 3, 2, 0 };
|
||||||
CFileSize unpackSize = folder->UnpackSizes[ci];
|
UInt64 unpackSize = folder->UnpackSizes[ci];
|
||||||
si = indices[ci];
|
si = indices[ci];
|
||||||
if (ci < 2)
|
if (ci < 2)
|
||||||
{
|
{
|
||||||
Byte *temp;
|
Byte *temp;
|
||||||
outSizeCur = (size_t)unpackSize;
|
outSizeCur = (SizeT)unpackSize;
|
||||||
if (outSizeCur != unpackSize)
|
if (outSizeCur != unpackSize)
|
||||||
return SZ_ERROR_MEM;
|
return SZ_ERROR_MEM;
|
||||||
temp = (Byte *)IAlloc_Alloc(allocMain, outSizeCur);
|
temp = (Byte *)IAlloc_Alloc(allocMain, outSizeCur);
|
||||||
@@ -200,58 +178,27 @@ SRes SzDecode2(const CFileSize *packSizes, const CSzFolder *folder,
|
|||||||
}
|
}
|
||||||
else if (ci == 2)
|
else if (ci == 2)
|
||||||
{
|
{
|
||||||
if (unpackSize > outSize) // check it
|
if (unpackSize > outSize) /* check it */
|
||||||
return SZ_ERROR_PARAM; // check it
|
return SZ_ERROR_PARAM;
|
||||||
tempBuf3 = outBufCur = outBuffer + (outSize - (size_t)unpackSize);
|
tempBuf3 = outBufCur = outBuffer + (outSize - (size_t)unpackSize);
|
||||||
tempSize3 = outSizeCur = (size_t)unpackSize;
|
tempSize3 = outSizeCur = (SizeT)unpackSize;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return SZ_ERROR_UNSUPPORTED;
|
return SZ_ERROR_UNSUPPORTED;
|
||||||
}
|
}
|
||||||
offset = GetSum(packSizes, si);
|
offset = GetSum(packSizes, si);
|
||||||
inSize = packSizes[si];
|
inSize = packSizes[si];
|
||||||
/*
|
RINOK(LookInStream_SeekTo(inStream, startPos + offset));
|
||||||
#ifdef _LZMA_IN_CB
|
|
||||||
*/
|
|
||||||
RINOK(inStream->Seek(inStream, startPos + offset, SZ_SEEK_SET));
|
|
||||||
/*
|
|
||||||
#endif
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (coder->MethodID == k_Copy)
|
if (coder->MethodID == k_Copy)
|
||||||
{
|
{
|
||||||
if (inSize != outSizeCur) // check it
|
if (inSize != outSizeCur) /* check it */
|
||||||
return SZ_ERROR_DATA;
|
return SZ_ERROR_DATA;
|
||||||
|
|
||||||
/*
|
|
||||||
#ifdef _LZMA_IN_CB
|
|
||||||
*/
|
|
||||||
RINOK(SzDecodeCopy(inSize, inStream, outBufCur));
|
RINOK(SzDecodeCopy(inSize, inStream, outBufCur));
|
||||||
/*
|
|
||||||
#else
|
|
||||||
memcpy(outBufCur, inBuffer + (size_t)offset, (size_t)inSize);
|
|
||||||
#endif
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/*
|
RINOK(SzDecodeLzma(coder, inSize, inStream, outBufCur, outSizeCur, allocMain));
|
||||||
#ifdef _LZMA_IN_CB
|
|
||||||
*/
|
|
||||||
SRes res = SzDecodeLzma(coder, inSize,
|
|
||||||
inStream,
|
|
||||||
outBufCur, outSizeCur, allocMain);
|
|
||||||
/*
|
|
||||||
#else
|
|
||||||
SizeT lzmaOutSizeT = outSizeCur;
|
|
||||||
SizeT lzmaInSizeT = (SizeT)inSize;
|
|
||||||
SRes res = LzmaDecode(outBufCur, &lzmaOutSizeT,
|
|
||||||
inBuffer + (size_t)offset, &lzmaInSizeT,
|
|
||||||
coder->Props.Items, (unsigned)coder->Props.size, LZMA_FINISH_BYTE, allocMain);
|
|
||||||
#endif
|
|
||||||
*/
|
|
||||||
|
|
||||||
RINOK(res);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (coder->MethodID == k_BCJ)
|
else if (coder->MethodID == k_BCJ)
|
||||||
@@ -264,17 +211,13 @@ SRes SzDecode2(const CFileSize *packSizes, const CSzFolder *folder,
|
|||||||
}
|
}
|
||||||
else if (coder->MethodID == k_BCJ2)
|
else if (coder->MethodID == k_BCJ2)
|
||||||
{
|
{
|
||||||
CFileSize offset = GetSum(packSizes, 1);
|
UInt64 offset = GetSum(packSizes, 1);
|
||||||
CFileSize s3Size = packSizes[1];
|
UInt64 s3Size = packSizes[1];
|
||||||
SRes res;
|
SRes res;
|
||||||
if (ci != 3)
|
if (ci != 3)
|
||||||
return SZ_ERROR_UNSUPPORTED;
|
return SZ_ERROR_UNSUPPORTED;
|
||||||
|
RINOK(LookInStream_SeekTo(inStream, startPos + offset));
|
||||||
/*
|
tempSizes[2] = (SizeT)s3Size;
|
||||||
#ifdef _LZMA_IN_CB
|
|
||||||
*/
|
|
||||||
RINOK(inStream->Seek(inStream, startPos + offset, SZ_SEEK_SET));
|
|
||||||
tempSizes[2] = (size_t)s3Size;
|
|
||||||
if (tempSizes[2] != s3Size)
|
if (tempSizes[2] != s3Size)
|
||||||
return SZ_ERROR_MEM;
|
return SZ_ERROR_MEM;
|
||||||
tempBuf[2] = (Byte *)IAlloc_Alloc(allocMain, tempSizes[2]);
|
tempBuf[2] = (Byte *)IAlloc_Alloc(allocMain, tempSizes[2]);
|
||||||
@@ -282,23 +225,12 @@ SRes SzDecode2(const CFileSize *packSizes, const CSzFolder *folder,
|
|||||||
return SZ_ERROR_MEM;
|
return SZ_ERROR_MEM;
|
||||||
res = SzDecodeCopy(s3Size, inStream, tempBuf[2]);
|
res = SzDecodeCopy(s3Size, inStream, tempBuf[2]);
|
||||||
RINOK(res)
|
RINOK(res)
|
||||||
/*
|
|
||||||
#endif
|
|
||||||
*/
|
|
||||||
|
|
||||||
res = Bcj2_Decode(
|
res = Bcj2_Decode(
|
||||||
tempBuf3, tempSize3,
|
tempBuf3, tempSize3,
|
||||||
tempBuf[0], tempSizes[0],
|
tempBuf[0], tempSizes[0],
|
||||||
tempBuf[1], tempSizes[1],
|
tempBuf[1], tempSizes[1],
|
||||||
/*
|
|
||||||
#ifdef _LZMA_IN_CB
|
|
||||||
*/
|
|
||||||
tempBuf[2], tempSizes[2],
|
tempBuf[2], tempSizes[2],
|
||||||
/*
|
|
||||||
#else
|
|
||||||
inBuffer + (size_t)offset, (size_t)s3Size,
|
|
||||||
#endif
|
|
||||||
*/
|
|
||||||
outBuffer, outSize);
|
outBuffer, outSize);
|
||||||
RINOK(res)
|
RINOK(res)
|
||||||
}
|
}
|
||||||
@@ -308,31 +240,14 @@ SRes SzDecode2(const CFileSize *packSizes, const CSzFolder *folder,
|
|||||||
return SZ_OK;
|
return SZ_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
SRes SzDecode(const CFileSize *packSizes, const CSzFolder *folder,
|
SRes SzDecode(const UInt64 *packSizes, const CSzFolder *folder,
|
||||||
/*
|
ILookInStream *inStream, UInt64 startPos,
|
||||||
#ifdef _LZMA_IN_CB
|
|
||||||
*/
|
|
||||||
ISzInStream *inStream, CFileSize startPos,
|
|
||||||
/*
|
|
||||||
#else
|
|
||||||
const Byte *inBuffer,
|
|
||||||
#endif
|
|
||||||
*/
|
|
||||||
Byte *outBuffer, size_t outSize, ISzAlloc *allocMain)
|
Byte *outBuffer, size_t outSize, ISzAlloc *allocMain)
|
||||||
{
|
{
|
||||||
Byte *tempBuf[3] = { 0, 0, 0};
|
Byte *tempBuf[3] = { 0, 0, 0};
|
||||||
int i;
|
int i;
|
||||||
SRes res = SzDecode2(packSizes, folder,
|
SRes res = SzDecode2(packSizes, folder, inStream, startPos,
|
||||||
/*
|
outBuffer, (SizeT)outSize, allocMain, tempBuf);
|
||||||
#ifdef _LZMA_IN_CB
|
|
||||||
*/
|
|
||||||
inStream, startPos,
|
|
||||||
/*
|
|
||||||
#else
|
|
||||||
inBuffer,
|
|
||||||
#endif
|
|
||||||
*/
|
|
||||||
outBuffer, outSize, allocMain, tempBuf);
|
|
||||||
for (i = 0; i < 3; i++)
|
for (i = 0; i < 3; i++)
|
||||||
IAlloc_Free(allocMain, tempBuf[i]);
|
IAlloc_Free(allocMain, tempBuf[i]);
|
||||||
return res;
|
return res;
|
||||||
|
|||||||
+3
-16
@@ -1,26 +1,13 @@
|
|||||||
/* 7zDecode.h -- Decoding from 7z folder
|
/* 7zDecode.h -- Decoding from 7z folder
|
||||||
2008-04-09
|
2008-11-23 : Igor Pavlov : Public domain */
|
||||||
Igor Pavlov
|
|
||||||
Copyright (c) 1999-2008 Igor Pavlov
|
|
||||||
Read 7zItem.h for license options */
|
|
||||||
|
|
||||||
#ifndef __7Z_DECODE_H
|
#ifndef __7Z_DECODE_H
|
||||||
#define __7Z_DECODE_H
|
#define __7Z_DECODE_H
|
||||||
|
|
||||||
#include "7zItem.h"
|
#include "7zItem.h"
|
||||||
|
|
||||||
#include "7zIn.h"
|
SRes SzDecode(const UInt64 *packSizes, const CSzFolder *folder,
|
||||||
|
ILookInStream *stream, UInt64 startPos,
|
||||||
SRes SzDecode(const CFileSize *packSizes, const CSzFolder *folder,
|
|
||||||
/*
|
|
||||||
#ifdef _LZMA_IN_CB
|
|
||||||
*/
|
|
||||||
ISzInStream *stream, CFileSize startPos,
|
|
||||||
/*
|
|
||||||
#else
|
|
||||||
const Byte *inBuffer,
|
|
||||||
#endif
|
|
||||||
*/
|
|
||||||
Byte *outBuffer, size_t outSize, ISzAlloc *allocMain);
|
Byte *outBuffer, size_t outSize, ISzAlloc *allocMain);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,16 +1,13 @@
|
|||||||
/* 7zExtract.c -- Extracting from 7z archive
|
/* 7zExtract.c -- Extracting from 7z archive
|
||||||
2008-08-17
|
2008-11-23 : Igor Pavlov : Public domain */
|
||||||
Igor Pavlov
|
|
||||||
Copyright (c) 1999-2008 Igor Pavlov
|
|
||||||
Read 7zExtract.h for license options */
|
|
||||||
|
|
||||||
#include "7zExtract.h"
|
|
||||||
#include "7zDecode.h"
|
|
||||||
#include "../../7zCrc.h"
|
#include "../../7zCrc.h"
|
||||||
|
#include "7zDecode.h"
|
||||||
|
#include "7zExtract.h"
|
||||||
|
|
||||||
SRes SzAr_Extract(
|
SRes SzAr_Extract(
|
||||||
const CSzArEx *p,
|
const CSzArEx *p,
|
||||||
ISzInStream *inStream,
|
ILookInStream *inStream,
|
||||||
UInt32 fileIndex,
|
UInt32 fileIndex,
|
||||||
UInt32 *blockIndex,
|
UInt32 *blockIndex,
|
||||||
Byte **outBuffer,
|
Byte **outBuffer,
|
||||||
@@ -36,9 +33,9 @@ SRes SzAr_Extract(
|
|||||||
if (*outBuffer == 0 || *blockIndex != folderIndex)
|
if (*outBuffer == 0 || *blockIndex != folderIndex)
|
||||||
{
|
{
|
||||||
CSzFolder *folder = p->db.Folders + folderIndex;
|
CSzFolder *folder = p->db.Folders + folderIndex;
|
||||||
CFileSize unpackSizeSpec = SzFolder_GetUnpackSize(folder);
|
UInt64 unpackSizeSpec = SzFolder_GetUnpackSize(folder);
|
||||||
size_t unpackSize = (size_t)unpackSizeSpec;
|
size_t unpackSize = (size_t)unpackSizeSpec;
|
||||||
CFileSize startOffset = SzArEx_GetFolderStreamPos(p, folderIndex, 0);
|
UInt64 startOffset = SzArEx_GetFolderStreamPos(p, folderIndex, 0);
|
||||||
|
|
||||||
if (unpackSize != unpackSizeSpec)
|
if (unpackSize != unpackSizeSpec)
|
||||||
return SZ_ERROR_MEM;
|
return SZ_ERROR_MEM;
|
||||||
@@ -46,7 +43,7 @@ SRes SzAr_Extract(
|
|||||||
IAlloc_Free(allocMain, *outBuffer);
|
IAlloc_Free(allocMain, *outBuffer);
|
||||||
*outBuffer = 0;
|
*outBuffer = 0;
|
||||||
|
|
||||||
RINOK(inStream->Seek(inStream, startOffset, SZ_SEEK_SET));
|
RINOK(LookInStream_SeekTo(inStream, startOffset));
|
||||||
|
|
||||||
if (res == SZ_OK)
|
if (res == SZ_OK)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
/* 7zExtract.h -- Extracting from 7z archive
|
/* 7zExtract.h -- Extracting from 7z archive
|
||||||
2008-08-05
|
2008-11-23 : Igor Pavlov : Public domain */
|
||||||
Igor Pavlov
|
|
||||||
Copyright (c) 1999-2008 Igor Pavlov
|
|
||||||
Read 7zItem.h for license options */
|
|
||||||
|
|
||||||
#ifndef __7Z_EXTRACT_H
|
#ifndef __7Z_EXTRACT_H
|
||||||
#define __7Z_EXTRACT_H
|
#define __7Z_EXTRACT_H
|
||||||
@@ -31,7 +28,7 @@ Read 7zItem.h for license options */
|
|||||||
|
|
||||||
SRes SzAr_Extract(
|
SRes SzAr_Extract(
|
||||||
const CSzArEx *db,
|
const CSzArEx *db,
|
||||||
ISzInStream *inStream,
|
ILookInStream *inStream,
|
||||||
UInt32 fileIndex, /* index of file */
|
UInt32 fileIndex, /* index of file */
|
||||||
UInt32 *blockIndex, /* index of solid block */
|
UInt32 *blockIndex, /* index of solid block */
|
||||||
Byte **outBuffer, /* pointer to pointer to output buffer (allocated with allocMain) */
|
Byte **outBuffer, /* pointer to pointer to output buffer (allocated with allocMain) */
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
/* 7zHeader.c -- 7z Headers
|
/* 7zHeader.c -- 7z Headers
|
||||||
2008-04-09
|
2008-10-04 : Igor Pavlov : Public domain */
|
||||||
Igor Pavlov
|
|
||||||
Copyright (c) 1999-2008 Igor Pavlov
|
|
||||||
Read 7zHeader.h for license options */
|
|
||||||
|
|
||||||
#include "7zHeader.h"
|
#include "7zHeader.h"
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/* 7zHeader.h -- 7z Headers
|
/* 7zHeader.h -- 7z Headers
|
||||||
2008-07-14
|
2008-10-04 : Igor Pavlov : Public domain */
|
||||||
Copyright (c) 1999-2008 Igor Pavlov
|
|
||||||
Read LzmaDec.h for license options */
|
|
||||||
|
|
||||||
#ifndef __7Z_HEADER_H
|
#ifndef __7Z_HEADER_H
|
||||||
#define __7Z_HEADER_H
|
#define __7Z_HEADER_H
|
||||||
|
|||||||
+94
-159
@@ -1,12 +1,11 @@
|
|||||||
/* 7zIn.c -- 7z Input functions
|
/* 7zIn.c -- 7z Input functions
|
||||||
2008-08-17
|
2008-11-23 : Igor Pavlov : Public domain */
|
||||||
Igor Pavlov
|
|
||||||
Copyright (c) 1999-2008 Igor Pavlov
|
|
||||||
Read 7zIn.h for license options */
|
|
||||||
|
|
||||||
#include "7zIn.h"
|
|
||||||
#include "7zDecode.h"
|
|
||||||
#include "../../7zCrc.h"
|
#include "../../7zCrc.h"
|
||||||
|
#include "../../CpuArch.h"
|
||||||
|
|
||||||
|
#include "7zDecode.h"
|
||||||
|
#include "7zIn.h"
|
||||||
|
|
||||||
#define RINOM(x) { if ((x) == 0) return SZ_ERROR_MEM; }
|
#define RINOM(x) { if ((x) == 0) return SZ_ERROR_MEM; }
|
||||||
|
|
||||||
@@ -30,12 +29,12 @@ void SzArEx_Free(CSzArEx *p, ISzAlloc *alloc)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
CFileSize GetFolderPackStreamSize(int folderIndex, int streamIndex) const
|
UInt64 GetFolderPackStreamSize(int folderIndex, int streamIndex) const
|
||||||
{
|
{
|
||||||
return PackSizes[FolderStartPackStreamIndex[folderIndex] + streamIndex];
|
return PackSizes[FolderStartPackStreamIndex[folderIndex] + streamIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
CFileSize GetFilePackSize(int fileIndex) const
|
UInt64 GetFilePackSize(int fileIndex) const
|
||||||
{
|
{
|
||||||
int folderIndex = FileIndexToFolderIndexMap[fileIndex];
|
int folderIndex = FileIndexToFolderIndexMap[fileIndex];
|
||||||
if (folderIndex >= 0)
|
if (folderIndex >= 0)
|
||||||
@@ -54,7 +53,7 @@ CFileSize GetFilePackSize(int fileIndex) const
|
|||||||
static SRes SzArEx_Fill(CSzArEx *p, ISzAlloc *alloc)
|
static SRes SzArEx_Fill(CSzArEx *p, ISzAlloc *alloc)
|
||||||
{
|
{
|
||||||
UInt32 startPos = 0;
|
UInt32 startPos = 0;
|
||||||
CFileSize startPosSize = 0;
|
UInt64 startPosSize = 0;
|
||||||
UInt32 i;
|
UInt32 i;
|
||||||
UInt32 folderIndex = 0;
|
UInt32 folderIndex = 0;
|
||||||
UInt32 indexInFolder = 0;
|
UInt32 indexInFolder = 0;
|
||||||
@@ -65,7 +64,7 @@ static SRes SzArEx_Fill(CSzArEx *p, ISzAlloc *alloc)
|
|||||||
startPos += p->db.Folders[i].NumPackStreams;
|
startPos += p->db.Folders[i].NumPackStreams;
|
||||||
}
|
}
|
||||||
|
|
||||||
MY_ALLOC(CFileSize, p->PackStreamStartPositions, p->db.NumPackStreams, alloc);
|
MY_ALLOC(UInt64, p->PackStreamStartPositions, p->db.NumPackStreams, alloc);
|
||||||
|
|
||||||
for (i = 0; i < p->db.NumPackStreams; i++)
|
for (i = 0; i < p->db.NumPackStreams; i++)
|
||||||
{
|
{
|
||||||
@@ -115,22 +114,22 @@ static SRes SzArEx_Fill(CSzArEx *p, ISzAlloc *alloc)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CFileSize SzArEx_GetFolderStreamPos(const CSzArEx *p, UInt32 folderIndex, UInt32 indexInFolder)
|
UInt64 SzArEx_GetFolderStreamPos(const CSzArEx *p, UInt32 folderIndex, UInt32 indexInFolder)
|
||||||
{
|
{
|
||||||
return p->ArchiveInfo.DataStartPosition +
|
return p->dataPos +
|
||||||
p->PackStreamStartPositions[p->FolderStartPackStreamIndex[folderIndex] + indexInFolder];
|
p->PackStreamStartPositions[p->FolderStartPackStreamIndex[folderIndex] + indexInFolder];
|
||||||
}
|
}
|
||||||
|
|
||||||
int SzArEx_GetFolderFullPackSize(const CSzArEx *p, UInt32 folderIndex, CFileSize *resSize)
|
int SzArEx_GetFolderFullPackSize(const CSzArEx *p, UInt32 folderIndex, UInt64 *resSize)
|
||||||
{
|
{
|
||||||
UInt32 packStreamIndex = p->FolderStartPackStreamIndex[folderIndex];
|
UInt32 packStreamIndex = p->FolderStartPackStreamIndex[folderIndex];
|
||||||
CSzFolder *folder = p->db.Folders + folderIndex;
|
CSzFolder *folder = p->db.Folders + folderIndex;
|
||||||
CFileSize size = 0;
|
UInt64 size = 0;
|
||||||
UInt32 i;
|
UInt32 i;
|
||||||
for (i = 0; i < folder->NumPackStreams; i++)
|
for (i = 0; i < folder->NumPackStreams; i++)
|
||||||
{
|
{
|
||||||
CFileSize t = size + p->db.PackSizes[packStreamIndex + i];
|
UInt64 t = size + p->db.PackSizes[packStreamIndex + i];
|
||||||
if (t < size) // check it
|
if (t < size) /* check it */
|
||||||
return SZ_ERROR_FAIL;
|
return SZ_ERROR_FAIL;
|
||||||
size = t;
|
size = t;
|
||||||
}
|
}
|
||||||
@@ -173,58 +172,6 @@ SRes SzReadTime(const CObjectVector<CBuf> &dataVector,
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static SRes SafeReadDirect(ISzInStream *inStream, Byte *data, size_t size)
|
|
||||||
{
|
|
||||||
while (size > 0)
|
|
||||||
{
|
|
||||||
void *inBufferSpec;
|
|
||||||
size_t processedSize = size;
|
|
||||||
const Byte *inBuffer;
|
|
||||||
RINOK(inStream->Read(inStream, (void **)&inBufferSpec, &processedSize));
|
|
||||||
inBuffer = (const Byte *)inBufferSpec;
|
|
||||||
if (processedSize == 0)
|
|
||||||
return SZ_ERROR_INPUT_EOF;
|
|
||||||
size -= processedSize;
|
|
||||||
do
|
|
||||||
*data++ = *inBuffer++;
|
|
||||||
while (--processedSize != 0);
|
|
||||||
}
|
|
||||||
return SZ_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
static SRes SafeReadDirectByte(ISzInStream *inStream, Byte *data)
|
|
||||||
{
|
|
||||||
return SafeReadDirect(inStream, data, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
static SRes SafeReadDirectUInt32(ISzInStream *inStream, UInt32 *value, UInt32 *crc)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
*value = 0;
|
|
||||||
for (i = 0; i < 4; i++)
|
|
||||||
{
|
|
||||||
Byte b;
|
|
||||||
RINOK(SafeReadDirectByte(inStream, &b));
|
|
||||||
*value |= ((UInt32)b << (8 * i));
|
|
||||||
*crc = CRC_UPDATE_BYTE(*crc, b);
|
|
||||||
}
|
|
||||||
return SZ_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
static SRes SafeReadDirectUInt64(ISzInStream *inStream, UInt64 *value, UInt32 *crc)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
*value = 0;
|
|
||||||
for (i = 0; i < 8; i++)
|
|
||||||
{
|
|
||||||
Byte b;
|
|
||||||
RINOK(SafeReadDirectByte(inStream, &b));
|
|
||||||
*value |= ((UInt64)b << (8 * i));
|
|
||||||
*crc = CRC_UPDATE_BYTE(*crc, b);
|
|
||||||
}
|
|
||||||
return SZ_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int TestSignatureCandidate(Byte *testBytes)
|
static int TestSignatureCandidate(Byte *testBytes)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
@@ -295,14 +242,6 @@ static SRes SzReadNumber(CSzData *sd, UInt64 *value)
|
|||||||
return SZ_OK;
|
return SZ_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static SRes SzReadSize(CSzData *sd, CFileSize *value)
|
|
||||||
{
|
|
||||||
UInt64 value64;
|
|
||||||
RINOK(SzReadNumber(sd, &value64));
|
|
||||||
*value = (CFileSize)value64;
|
|
||||||
return SZ_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
static SRes SzReadNumber32(CSzData *sd, UInt32 *value)
|
static SRes SzReadNumber32(CSzData *sd, UInt32 *value)
|
||||||
{
|
{
|
||||||
UInt64 value64;
|
UInt64 value64;
|
||||||
@@ -415,24 +354,24 @@ static SRes SzReadHashDigests(
|
|||||||
|
|
||||||
static SRes SzReadPackInfo(
|
static SRes SzReadPackInfo(
|
||||||
CSzData *sd,
|
CSzData *sd,
|
||||||
CFileSize *dataOffset,
|
UInt64 *dataOffset,
|
||||||
UInt32 *numPackStreams,
|
UInt32 *numPackStreams,
|
||||||
CFileSize **packSizes,
|
UInt64 **packSizes,
|
||||||
Byte **packCRCsDefined,
|
Byte **packCRCsDefined,
|
||||||
UInt32 **packCRCs,
|
UInt32 **packCRCs,
|
||||||
ISzAlloc *alloc)
|
ISzAlloc *alloc)
|
||||||
{
|
{
|
||||||
UInt32 i;
|
UInt32 i;
|
||||||
RINOK(SzReadSize(sd, dataOffset));
|
RINOK(SzReadNumber(sd, dataOffset));
|
||||||
RINOK(SzReadNumber32(sd, numPackStreams));
|
RINOK(SzReadNumber32(sd, numPackStreams));
|
||||||
|
|
||||||
RINOK(SzWaitAttribute(sd, k7zIdSize));
|
RINOK(SzWaitAttribute(sd, k7zIdSize));
|
||||||
|
|
||||||
MY_ALLOC(CFileSize, *packSizes, (size_t)*numPackStreams, alloc);
|
MY_ALLOC(UInt64, *packSizes, (size_t)*numPackStreams, alloc);
|
||||||
|
|
||||||
for (i = 0; i < *numPackStreams; i++)
|
for (i = 0; i < *numPackStreams; i++)
|
||||||
{
|
{
|
||||||
RINOK(SzReadSize(sd, (*packSizes) + i));
|
RINOK(SzReadNumber(sd, (*packSizes) + i));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
@@ -498,7 +437,7 @@ static SRes SzGetNextFolderItem(CSzData *sd, CSzFolder *folder, ISzAlloc *alloc)
|
|||||||
return SZ_ERROR_UNSUPPORTED;
|
return SZ_ERROR_UNSUPPORTED;
|
||||||
coder->MethodID = 0;
|
coder->MethodID = 0;
|
||||||
for (j = 0; j < idSize; j++)
|
for (j = 0; j < idSize; j++)
|
||||||
coder->MethodID |= (CMethodID)longID[idSize - 1 - j] << (8 * j);
|
coder->MethodID |= (UInt64)longID[idSize - 1 - j] << (8 * j);
|
||||||
|
|
||||||
if ((mainByte & 0x10) != 0)
|
if ((mainByte & 0x10) != 0)
|
||||||
{
|
{
|
||||||
@@ -548,7 +487,7 @@ static SRes SzGetNextFolderItem(CSzData *sd, CSzFolder *folder, ISzAlloc *alloc)
|
|||||||
|
|
||||||
for (i = 0; i < numBindPairs; i++)
|
for (i = 0; i < numBindPairs; i++)
|
||||||
{
|
{
|
||||||
CBindPair *bindPair = folder->BindPairs + i;;
|
CBindPair *bindPair = folder->BindPairs + i;
|
||||||
RINOK(SzReadNumber32(sd, &bindPair->InIndex));
|
RINOK(SzReadNumber32(sd, &bindPair->InIndex));
|
||||||
RINOK(SzReadNumber32(sd, &bindPair->OutIndex));
|
RINOK(SzReadNumber32(sd, &bindPair->OutIndex));
|
||||||
}
|
}
|
||||||
@@ -609,11 +548,11 @@ static SRes SzReadUnpackInfo(
|
|||||||
CSzFolder *folder = (*folders) + i;
|
CSzFolder *folder = (*folders) + i;
|
||||||
UInt32 numOutStreams = SzFolder_GetNumOutStreams(folder);
|
UInt32 numOutStreams = SzFolder_GetNumOutStreams(folder);
|
||||||
|
|
||||||
MY_ALLOC(CFileSize, folder->UnpackSizes, (size_t)numOutStreams, alloc);
|
MY_ALLOC(UInt64, folder->UnpackSizes, (size_t)numOutStreams, alloc);
|
||||||
|
|
||||||
for (j = 0; j < numOutStreams; j++)
|
for (j = 0; j < numOutStreams; j++)
|
||||||
{
|
{
|
||||||
RINOK(SzReadSize(sd, folder->UnpackSizes + j));
|
RINOK(SzReadNumber(sd, folder->UnpackSizes + j));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -652,7 +591,7 @@ static SRes SzReadSubStreamsInfo(
|
|||||||
UInt32 numFolders,
|
UInt32 numFolders,
|
||||||
CSzFolder *folders,
|
CSzFolder *folders,
|
||||||
UInt32 *numUnpackStreams,
|
UInt32 *numUnpackStreams,
|
||||||
CFileSize **unpackSizes,
|
UInt64 **unpackSizes,
|
||||||
Byte **digestsDefined,
|
Byte **digestsDefined,
|
||||||
UInt32 **digests,
|
UInt32 **digests,
|
||||||
ISzAlloc *allocTemp)
|
ISzAlloc *allocTemp)
|
||||||
@@ -696,7 +635,7 @@ static SRes SzReadSubStreamsInfo(
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
*unpackSizes = (CFileSize *)IAlloc_Alloc(allocTemp, (size_t)*numUnpackStreams * sizeof(CFileSize));
|
*unpackSizes = (UInt64 *)IAlloc_Alloc(allocTemp, (size_t)*numUnpackStreams * sizeof(UInt64));
|
||||||
RINOM(*unpackSizes);
|
RINOM(*unpackSizes);
|
||||||
*digestsDefined = (Byte *)IAlloc_Alloc(allocTemp, (size_t)*numUnpackStreams * sizeof(Byte));
|
*digestsDefined = (Byte *)IAlloc_Alloc(allocTemp, (size_t)*numUnpackStreams * sizeof(Byte));
|
||||||
RINOM(*digestsDefined);
|
RINOM(*digestsDefined);
|
||||||
@@ -710,7 +649,7 @@ static SRes SzReadSubStreamsInfo(
|
|||||||
v3.13 incorrectly worked with empty folders
|
v3.13 incorrectly worked with empty folders
|
||||||
v4.07: we check that folder is empty
|
v4.07: we check that folder is empty
|
||||||
*/
|
*/
|
||||||
CFileSize sum = 0;
|
UInt64 sum = 0;
|
||||||
UInt32 j;
|
UInt32 j;
|
||||||
UInt32 numSubstreams = folders[i].NumUnpackStreams;
|
UInt32 numSubstreams = folders[i].NumUnpackStreams;
|
||||||
if (numSubstreams == 0)
|
if (numSubstreams == 0)
|
||||||
@@ -718,8 +657,8 @@ static SRes SzReadSubStreamsInfo(
|
|||||||
if (type == k7zIdSize)
|
if (type == k7zIdSize)
|
||||||
for (j = 1; j < numSubstreams; j++)
|
for (j = 1; j < numSubstreams; j++)
|
||||||
{
|
{
|
||||||
CFileSize size;
|
UInt64 size;
|
||||||
RINOK(SzReadSize(sd, &size));
|
RINOK(SzReadNumber(sd, &size));
|
||||||
(*unpackSizes)[si++] = size;
|
(*unpackSizes)[si++] = size;
|
||||||
sum += size;
|
sum += size;
|
||||||
}
|
}
|
||||||
@@ -795,10 +734,10 @@ static SRes SzReadSubStreamsInfo(
|
|||||||
|
|
||||||
static SRes SzReadStreamsInfo(
|
static SRes SzReadStreamsInfo(
|
||||||
CSzData *sd,
|
CSzData *sd,
|
||||||
CFileSize *dataOffset,
|
UInt64 *dataOffset,
|
||||||
CSzAr *p,
|
CSzAr *p,
|
||||||
UInt32 *numUnpackStreams,
|
UInt32 *numUnpackStreams,
|
||||||
CFileSize **unpackSizes, /* allocTemp */
|
UInt64 **unpackSizes, /* allocTemp */
|
||||||
Byte **digestsDefined, /* allocTemp */
|
Byte **digestsDefined, /* allocTemp */
|
||||||
UInt32 **digests, /* allocTemp */
|
UInt32 **digests, /* allocTemp */
|
||||||
ISzAlloc *alloc,
|
ISzAlloc *alloc,
|
||||||
@@ -917,7 +856,7 @@ static SRes SzReadFileNames(CSzData *sd, UInt32 numFiles, CSzFileItem *files, IS
|
|||||||
static SRes SzReadHeader2(
|
static SRes SzReadHeader2(
|
||||||
CSzArEx *p, /* allocMain */
|
CSzArEx *p, /* allocMain */
|
||||||
CSzData *sd,
|
CSzData *sd,
|
||||||
CFileSize **unpackSizes, /* allocTemp */
|
UInt64 **unpackSizes, /* allocTemp */
|
||||||
Byte **digestsDefined, /* allocTemp */
|
Byte **digestsDefined, /* allocTemp */
|
||||||
UInt32 **digests, /* allocTemp */
|
UInt32 **digests, /* allocTemp */
|
||||||
Byte **emptyStreamVector, /* allocTemp */
|
Byte **emptyStreamVector, /* allocTemp */
|
||||||
@@ -945,13 +884,13 @@ static SRes SzReadHeader2(
|
|||||||
if (type == k7zIdMainStreamsInfo)
|
if (type == k7zIdMainStreamsInfo)
|
||||||
{
|
{
|
||||||
RINOK(SzReadStreamsInfo(sd,
|
RINOK(SzReadStreamsInfo(sd,
|
||||||
&p->ArchiveInfo.DataStartPosition,
|
&p->dataPos,
|
||||||
&p->db,
|
&p->db,
|
||||||
&numUnpackStreams,
|
&numUnpackStreams,
|
||||||
unpackSizes,
|
unpackSizes,
|
||||||
digestsDefined,
|
digestsDefined,
|
||||||
digests, allocMain, allocTemp));
|
digests, allocMain, allocTemp));
|
||||||
p->ArchiveInfo.DataStartPosition += p->ArchiveInfo.StartPositionAfterHeader;
|
p->dataPos += p->startPosAfterHeader;
|
||||||
RINOK(SzReadID(sd, &type));
|
RINOK(SzReadID(sd, &type));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1070,7 +1009,7 @@ static SRes SzReadHeader(
|
|||||||
ISzAlloc *allocMain,
|
ISzAlloc *allocMain,
|
||||||
ISzAlloc *allocTemp)
|
ISzAlloc *allocTemp)
|
||||||
{
|
{
|
||||||
CFileSize *unpackSizes = 0;
|
UInt64 *unpackSizes = 0;
|
||||||
Byte *digestsDefined = 0;
|
Byte *digestsDefined = 0;
|
||||||
UInt32 *digests = 0;
|
UInt32 *digests = 0;
|
||||||
Byte *emptyStreamVector = 0;
|
Byte *emptyStreamVector = 0;
|
||||||
@@ -1090,21 +1029,21 @@ static SRes SzReadHeader(
|
|||||||
}
|
}
|
||||||
|
|
||||||
static SRes SzReadAndDecodePackedStreams2(
|
static SRes SzReadAndDecodePackedStreams2(
|
||||||
ISzInStream *inStream,
|
ILookInStream *inStream,
|
||||||
CSzData *sd,
|
CSzData *sd,
|
||||||
CBuf *outBuffer,
|
CBuf *outBuffer,
|
||||||
CFileSize baseOffset,
|
UInt64 baseOffset,
|
||||||
CSzAr *p,
|
CSzAr *p,
|
||||||
CFileSize **unpackSizes,
|
UInt64 **unpackSizes,
|
||||||
Byte **digestsDefined,
|
Byte **digestsDefined,
|
||||||
UInt32 **digests,
|
UInt32 **digests,
|
||||||
ISzAlloc *allocTemp)
|
ISzAlloc *allocTemp)
|
||||||
{
|
{
|
||||||
|
|
||||||
UInt32 numUnpackStreams = 0;
|
UInt32 numUnpackStreams = 0;
|
||||||
CFileSize dataStartPos;
|
UInt64 dataStartPos;
|
||||||
CSzFolder *folder;
|
CSzFolder *folder;
|
||||||
CFileSize unpackSize;
|
UInt64 unpackSize;
|
||||||
SRes res;
|
SRes res;
|
||||||
|
|
||||||
RINOK(SzReadStreamsInfo(sd, &dataStartPos, p,
|
RINOK(SzReadStreamsInfo(sd, &dataStartPos, p,
|
||||||
@@ -1118,7 +1057,7 @@ static SRes SzReadAndDecodePackedStreams2(
|
|||||||
folder = p->Folders;
|
folder = p->Folders;
|
||||||
unpackSize = SzFolder_GetUnpackSize(folder);
|
unpackSize = SzFolder_GetUnpackSize(folder);
|
||||||
|
|
||||||
RINOK(inStream->Seek(inStream, dataStartPos, SZ_SEEK_SET));
|
RINOK(LookInStream_SeekTo(inStream, dataStartPos));
|
||||||
|
|
||||||
if (!Buf_Create(outBuffer, (size_t)unpackSize, allocTemp))
|
if (!Buf_Create(outBuffer, (size_t)unpackSize, allocTemp))
|
||||||
return SZ_ERROR_MEM;
|
return SZ_ERROR_MEM;
|
||||||
@@ -1134,14 +1073,14 @@ static SRes SzReadAndDecodePackedStreams2(
|
|||||||
}
|
}
|
||||||
|
|
||||||
static SRes SzReadAndDecodePackedStreams(
|
static SRes SzReadAndDecodePackedStreams(
|
||||||
ISzInStream *inStream,
|
ILookInStream *inStream,
|
||||||
CSzData *sd,
|
CSzData *sd,
|
||||||
CBuf *outBuffer,
|
CBuf *outBuffer,
|
||||||
CFileSize baseOffset,
|
UInt64 baseOffset,
|
||||||
ISzAlloc *allocTemp)
|
ISzAlloc *allocTemp)
|
||||||
{
|
{
|
||||||
CSzAr p;
|
CSzAr p;
|
||||||
CFileSize *unpackSizes = 0;
|
UInt64 *unpackSizes = 0;
|
||||||
Byte *digestsDefined = 0;
|
Byte *digestsDefined = 0;
|
||||||
UInt32 *digests = 0;
|
UInt32 *digests = 0;
|
||||||
SRes res;
|
SRes res;
|
||||||
@@ -1158,105 +1097,101 @@ static SRes SzReadAndDecodePackedStreams(
|
|||||||
|
|
||||||
static SRes SzArEx_Open2(
|
static SRes SzArEx_Open2(
|
||||||
CSzArEx *p,
|
CSzArEx *p,
|
||||||
ISzInStream *inStream,
|
ILookInStream *inStream,
|
||||||
ISzAlloc *allocMain,
|
ISzAlloc *allocMain,
|
||||||
ISzAlloc *allocTemp)
|
ISzAlloc *allocTemp)
|
||||||
{
|
{
|
||||||
Byte signature[k7zSignatureSize];
|
Byte header[k7zStartHeaderSize];
|
||||||
Byte version;
|
UInt64 nextHeaderOffset, nextHeaderSize;
|
||||||
UInt32 crcFromArchive;
|
size_t nextHeaderSizeT;
|
||||||
UInt64 nextHeaderOffset;
|
|
||||||
UInt64 nextHeaderSize;
|
|
||||||
UInt32 nextHeaderCRC;
|
UInt32 nextHeaderCRC;
|
||||||
UInt32 crc = 0;
|
|
||||||
CFileSize pos = 0;
|
|
||||||
CBuf buffer;
|
CBuf buffer;
|
||||||
CSzData sd;
|
|
||||||
SRes res;
|
SRes res;
|
||||||
|
|
||||||
if (SafeReadDirect(inStream, signature, k7zSignatureSize) != SZ_OK)
|
RINOK(LookInStream_Read2(inStream, header, k7zStartHeaderSize, SZ_ERROR_NO_ARCHIVE));
|
||||||
return SZ_ERROR_NO_ARCHIVE;
|
|
||||||
|
|
||||||
if (!TestSignatureCandidate(signature))
|
if (!TestSignatureCandidate(header))
|
||||||
return SZ_ERROR_NO_ARCHIVE;
|
return SZ_ERROR_NO_ARCHIVE;
|
||||||
|
if (header[6] != k7zMajorVersion)
|
||||||
/*
|
|
||||||
p.Clear();
|
|
||||||
p.ArchiveInfo.StartPosition = _arhiveBeginStreamPosition;
|
|
||||||
*/
|
|
||||||
RINOK(SafeReadDirectByte(inStream, &version));
|
|
||||||
if (version != k7zMajorVersion)
|
|
||||||
return SZ_ERROR_UNSUPPORTED;
|
return SZ_ERROR_UNSUPPORTED;
|
||||||
RINOK(SafeReadDirectByte(inStream, &version));
|
|
||||||
|
|
||||||
RINOK(SafeReadDirectUInt32(inStream, &crcFromArchive, &crc));
|
nextHeaderOffset = GetUi64(header + 12);
|
||||||
|
nextHeaderSize = GetUi64(header + 20);
|
||||||
|
nextHeaderCRC = GetUi32(header + 28);
|
||||||
|
|
||||||
crc = CRC_INIT_VAL;
|
p->startPosAfterHeader = k7zStartHeaderSize;
|
||||||
RINOK(SafeReadDirectUInt64(inStream, &nextHeaderOffset, &crc));
|
|
||||||
RINOK(SafeReadDirectUInt64(inStream, &nextHeaderSize, &crc));
|
|
||||||
RINOK(SafeReadDirectUInt32(inStream, &nextHeaderCRC, &crc));
|
|
||||||
|
|
||||||
pos = k7zStartHeaderSize;
|
if (CrcCalc(header + 12, 20) != GetUi32(header + 8))
|
||||||
p->ArchiveInfo.StartPositionAfterHeader = pos;
|
|
||||||
|
|
||||||
if (CRC_GET_DIGEST(crc) != crcFromArchive)
|
|
||||||
return SZ_ERROR_CRC;
|
return SZ_ERROR_CRC;
|
||||||
|
|
||||||
if (nextHeaderSize == 0)
|
nextHeaderSizeT = (size_t)nextHeaderSize;
|
||||||
|
if (nextHeaderSizeT != nextHeaderSize)
|
||||||
|
return SZ_ERROR_MEM;
|
||||||
|
if (nextHeaderSizeT == 0)
|
||||||
return SZ_OK;
|
return SZ_OK;
|
||||||
|
if (nextHeaderOffset > nextHeaderOffset + nextHeaderSize ||
|
||||||
|
nextHeaderOffset > nextHeaderOffset + nextHeaderSize + k7zStartHeaderSize)
|
||||||
|
return SZ_ERROR_NO_ARCHIVE;
|
||||||
|
|
||||||
RINOK(inStream->Seek(inStream, (CFileSize)(pos + nextHeaderOffset), SZ_SEEK_SET));
|
{
|
||||||
|
Int64 pos = 0;
|
||||||
|
RINOK(inStream->Seek(inStream, &pos, SZ_SEEK_END));
|
||||||
|
if ((UInt64)pos < nextHeaderOffset ||
|
||||||
|
(UInt64)pos < k7zStartHeaderSize + nextHeaderOffset ||
|
||||||
|
(UInt64)pos < k7zStartHeaderSize + nextHeaderOffset + nextHeaderSize)
|
||||||
|
return SZ_ERROR_INPUT_EOF;
|
||||||
|
}
|
||||||
|
|
||||||
if (!Buf_Create(&buffer, (size_t)nextHeaderSize, allocTemp))
|
RINOK(LookInStream_SeekTo(inStream, k7zStartHeaderSize + nextHeaderOffset));
|
||||||
|
|
||||||
|
if (!Buf_Create(&buffer, nextHeaderSizeT, allocTemp))
|
||||||
return SZ_ERROR_MEM;
|
return SZ_ERROR_MEM;
|
||||||
|
|
||||||
res = SafeReadDirect(inStream, buffer.data, (size_t)nextHeaderSize);
|
res = LookInStream_Read(inStream, buffer.data, nextHeaderSizeT);
|
||||||
if (res == SZ_OK)
|
if (res == SZ_OK)
|
||||||
{
|
{
|
||||||
res = SZ_ERROR_ARCHIVE;
|
res = SZ_ERROR_ARCHIVE;
|
||||||
if (CrcCalc(buffer.data, (size_t)nextHeaderSize) == nextHeaderCRC)
|
if (CrcCalc(buffer.data, nextHeaderSizeT) == nextHeaderCRC)
|
||||||
{
|
|
||||||
for (;;)
|
|
||||||
{
|
{
|
||||||
|
CSzData sd;
|
||||||
UInt64 type;
|
UInt64 type;
|
||||||
sd.Data = buffer.data;
|
sd.Data = buffer.data;
|
||||||
sd.Size = buffer.size;
|
sd.Size = buffer.size;
|
||||||
res = SzReadID(&sd, &type);
|
res = SzReadID(&sd, &type);
|
||||||
if (res != SZ_OK)
|
if (res == SZ_OK)
|
||||||
break;
|
|
||||||
if (type == k7zIdHeader)
|
|
||||||
{
|
{
|
||||||
res = SzReadHeader(p, &sd, allocMain, allocTemp);
|
if (type == k7zIdEncodedHeader)
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (type != k7zIdEncodedHeader)
|
|
||||||
{
|
|
||||||
res = SZ_ERROR_UNSUPPORTED;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
{
|
{
|
||||||
CBuf outBuffer;
|
CBuf outBuffer;
|
||||||
Buf_Init(&outBuffer);
|
Buf_Init(&outBuffer);
|
||||||
res = SzReadAndDecodePackedStreams(inStream, &sd, &outBuffer,
|
res = SzReadAndDecodePackedStreams(inStream, &sd, &outBuffer, p->startPosAfterHeader, allocTemp);
|
||||||
p->ArchiveInfo.StartPositionAfterHeader,
|
|
||||||
allocTemp);
|
|
||||||
if (res != SZ_OK)
|
if (res != SZ_OK)
|
||||||
{
|
|
||||||
Buf_Free(&outBuffer, allocTemp);
|
Buf_Free(&outBuffer, allocTemp);
|
||||||
break;
|
else
|
||||||
}
|
{
|
||||||
Buf_Free(&buffer, allocTemp);
|
Buf_Free(&buffer, allocTemp);
|
||||||
buffer.data = outBuffer.data;
|
buffer.data = outBuffer.data;
|
||||||
buffer.size = outBuffer.size;
|
buffer.size = outBuffer.size;
|
||||||
|
sd.Data = buffer.data;
|
||||||
|
sd.Size = buffer.size;
|
||||||
|
res = SzReadID(&sd, &type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (res == SZ_OK)
|
||||||
|
{
|
||||||
|
if (type == k7zIdHeader)
|
||||||
|
res = SzReadHeader(p, &sd, allocMain, allocTemp);
|
||||||
|
else
|
||||||
|
res = SZ_ERROR_UNSUPPORTED;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Buf_Free(&buffer, allocTemp);
|
Buf_Free(&buffer, allocTemp);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
SRes SzArEx_Open(CSzArEx *p, ISzInStream *inStream, ISzAlloc *allocMain, ISzAlloc *allocTemp)
|
SRes SzArEx_Open(CSzArEx *p, ILookInStream *inStream, ISzAlloc *allocMain, ISzAlloc *allocTemp)
|
||||||
{
|
{
|
||||||
SRes res = SzArEx_Open2(p, inStream, allocMain, allocTemp);
|
SRes res = SzArEx_Open2(p, inStream, allocMain, allocTemp);
|
||||||
if (res != SZ_OK)
|
if (res != SZ_OK)
|
||||||
|
|||||||
+9
-31
@@ -1,8 +1,5 @@
|
|||||||
/* 7zIn.h -- 7z Input functions
|
/* 7zIn.h -- 7z Input functions
|
||||||
2008-08-05
|
2008-11-23 : Igor Pavlov : Public domain */
|
||||||
Igor Pavlov
|
|
||||||
Copyright (c) 1999-2008 Igor Pavlov
|
|
||||||
Read 7zItem.h for license options */
|
|
||||||
|
|
||||||
#ifndef __7Z_IN_H
|
#ifndef __7Z_IN_H
|
||||||
#define __7Z_IN_H
|
#define __7Z_IN_H
|
||||||
@@ -10,42 +7,23 @@ Read 7zItem.h for license options */
|
|||||||
#include "7zHeader.h"
|
#include "7zHeader.h"
|
||||||
#include "7zItem.h"
|
#include "7zItem.h"
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
CFileSize StartPositionAfterHeader;
|
|
||||||
CFileSize DataStartPosition;
|
|
||||||
} CInArchiveInfo;
|
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
CSzAr db;
|
CSzAr db;
|
||||||
CInArchiveInfo ArchiveInfo;
|
|
||||||
|
UInt64 startPosAfterHeader;
|
||||||
|
UInt64 dataPos;
|
||||||
|
|
||||||
UInt32 *FolderStartPackStreamIndex;
|
UInt32 *FolderStartPackStreamIndex;
|
||||||
CFileSize *PackStreamStartPositions;
|
UInt64 *PackStreamStartPositions;
|
||||||
UInt32 *FolderStartFileIndex;
|
UInt32 *FolderStartFileIndex;
|
||||||
UInt32 *FileIndexToFolderIndexMap;
|
UInt32 *FileIndexToFolderIndexMap;
|
||||||
} CSzArEx;
|
} CSzArEx;
|
||||||
|
|
||||||
void SzArEx_Init(CSzArEx *p);
|
void SzArEx_Init(CSzArEx *p);
|
||||||
void SzArEx_Free(CSzArEx *p, ISzAlloc *alloc);
|
void SzArEx_Free(CSzArEx *p, ISzAlloc *alloc);
|
||||||
CFileSize SzArEx_GetFolderStreamPos(const CSzArEx *p, UInt32 folderIndex, UInt32 indexInFolder);
|
UInt64 SzArEx_GetFolderStreamPos(const CSzArEx *p, UInt32 folderIndex, UInt32 indexInFolder);
|
||||||
int SzArEx_GetFolderFullPackSize(const CSzArEx *p, UInt32 folderIndex, CFileSize *resSize);
|
int SzArEx_GetFolderFullPackSize(const CSzArEx *p, UInt32 folderIndex, UInt64 *resSize);
|
||||||
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
SZ_SEEK_SET = 0,
|
|
||||||
SZ_SEEK_CUR = 1,
|
|
||||||
SZ_SEEK_END = 2
|
|
||||||
} ESzSeek;
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
SRes (*Read)(void *object, void **buf, size_t *size);
|
|
||||||
/* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
|
|
||||||
(output(*size) < input(*size)) is allowed */
|
|
||||||
SRes (*Seek)(void *object, CFileSize pos, ESzSeek origin);
|
|
||||||
} ISzInStream;
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Errors:
|
Errors:
|
||||||
@@ -58,6 +36,6 @@ SZ_ERROR_INPUT_EOF
|
|||||||
SZ_ERROR_FAIL
|
SZ_ERROR_FAIL
|
||||||
*/
|
*/
|
||||||
|
|
||||||
SRes SzArEx_Open(CSzArEx *p, ISzInStream *inStream, ISzAlloc *allocMain, ISzAlloc *allocTemp);
|
SRes SzArEx_Open(CSzArEx *p, ILookInStream *inStream, ISzAlloc *allocMain, ISzAlloc *allocTemp);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
/* 7zItem.c -- 7z Items
|
/* 7zItem.c -- 7z Items
|
||||||
2008-08-05
|
2008-10-04 : Igor Pavlov : Public domain */
|
||||||
Igor Pavlov
|
|
||||||
Copyright (c) 1999-2008 Igor Pavlov
|
|
||||||
Read 7zItem.h for license options */
|
|
||||||
|
|
||||||
#include "7zItem.h"
|
#include "7zItem.h"
|
||||||
|
|
||||||
@@ -72,7 +69,7 @@ int SzFolder_FindBindPairForOutStream(CSzFolder *p, UInt32 outStreamIndex)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
CFileSize SzFolder_GetUnpackSize(CSzFolder *p)
|
UInt64 SzFolder_GetUnpackSize(CSzFolder *p)
|
||||||
{
|
{
|
||||||
int i = (int)SzFolder_GetNumOutStreams(p);
|
int i = (int)SzFolder_GetNumOutStreams(p);
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
|
|||||||
+7
-21
@@ -1,30 +1,16 @@
|
|||||||
/* 7zItem.h -- 7z Items
|
/* 7zItem.h -- 7z Items
|
||||||
2008-07-09
|
2008-10-04 : Igor Pavlov : Public domain */
|
||||||
Igor Pavlov
|
|
||||||
Copyright (c) 1999-2008 Igor Pavlov
|
|
||||||
Read LzmaDec.h for license options */
|
|
||||||
|
|
||||||
#ifndef __7Z_ITEM_H
|
#ifndef __7Z_ITEM_H
|
||||||
#define __7Z_ITEM_H
|
#define __7Z_ITEM_H
|
||||||
|
|
||||||
#include "../../7zBuf.h"
|
#include "../../7zBuf.h"
|
||||||
|
|
||||||
/* #define _SZ_FILE_SIZE_32 */
|
|
||||||
/* You can define _SZ_FILE_SIZE_32, if you don't need support for files larger than 4 GB*/
|
|
||||||
|
|
||||||
#ifdef _SZ_FILE_SIZE_32
|
|
||||||
typedef UInt32 CFileSize;
|
|
||||||
#else
|
|
||||||
typedef UInt64 CFileSize;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef UInt64 CMethodID;
|
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
UInt32 NumInStreams;
|
UInt32 NumInStreams;
|
||||||
UInt32 NumOutStreams;
|
UInt32 NumOutStreams;
|
||||||
CMethodID MethodID;
|
UInt64 MethodID;
|
||||||
CBuf Props;
|
CBuf Props;
|
||||||
} CSzCoderInfo;
|
} CSzCoderInfo;
|
||||||
|
|
||||||
@@ -42,7 +28,7 @@ typedef struct
|
|||||||
CSzCoderInfo *Coders;
|
CSzCoderInfo *Coders;
|
||||||
CBindPair *BindPairs;
|
CBindPair *BindPairs;
|
||||||
UInt32 *PackStreams;
|
UInt32 *PackStreams;
|
||||||
CFileSize *UnpackSizes;
|
UInt64 *UnpackSizes;
|
||||||
UInt32 NumCoders;
|
UInt32 NumCoders;
|
||||||
UInt32 NumBindPairs;
|
UInt32 NumBindPairs;
|
||||||
UInt32 NumPackStreams;
|
UInt32 NumPackStreams;
|
||||||
@@ -53,10 +39,10 @@ typedef struct
|
|||||||
} CSzFolder;
|
} CSzFolder;
|
||||||
|
|
||||||
void SzFolder_Init(CSzFolder *p);
|
void SzFolder_Init(CSzFolder *p);
|
||||||
CFileSize SzFolder_GetUnpackSize(CSzFolder *p);
|
UInt64 SzFolder_GetUnpackSize(CSzFolder *p);
|
||||||
int SzFolder_FindBindPairForInStream(CSzFolder *p, UInt32 inStreamIndex);
|
int SzFolder_FindBindPairForInStream(CSzFolder *p, UInt32 inStreamIndex);
|
||||||
UInt32 SzFolder_GetNumOutStreams(CSzFolder *p);
|
UInt32 SzFolder_GetNumOutStreams(CSzFolder *p);
|
||||||
CFileSize SzFolder_GetUnpackSize(CSzFolder *p);
|
UInt64 SzFolder_GetUnpackSize(CSzFolder *p);
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
@@ -67,7 +53,7 @@ typedef struct
|
|||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
CNtfsFileTime MTime;
|
CNtfsFileTime MTime;
|
||||||
CFileSize Size;
|
UInt64 Size;
|
||||||
char *Name;
|
char *Name;
|
||||||
UInt32 FileCRC;
|
UInt32 FileCRC;
|
||||||
|
|
||||||
@@ -82,7 +68,7 @@ void SzFile_Init(CSzFileItem *p);
|
|||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
CFileSize *PackSizes;
|
UInt64 *PackSizes;
|
||||||
Byte *PackCRCsDefined;
|
Byte *PackCRCsDefined;
|
||||||
UInt32 *PackCRCs;
|
UInt32 *PackCRCs;
|
||||||
CSzFolder *Folders;
|
CSzFolder *Folders;
|
||||||
|
|||||||
+32
-196
@@ -1,34 +1,19 @@
|
|||||||
/* 7zMain.c - Test application for 7z Decoder
|
/* 7zMain.c - Test application for 7z Decoder
|
||||||
2008-08-17
|
2008-11-23 : Igor Pavlov : Public domain */
|
||||||
Igor Pavlov
|
|
||||||
Public domain */
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
#define USE_WINDOWS_FUNCTIONS
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef USE_WINDOWS_FUNCTIONS
|
|
||||||
#include <windows.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "7zIn.h"
|
|
||||||
#include "7zExtract.h"
|
|
||||||
#include "7zAlloc.h"
|
|
||||||
|
|
||||||
#include "../../7zCrc.h"
|
#include "../../7zCrc.h"
|
||||||
|
#include "../../7zFile.h"
|
||||||
|
#include "../../7zVersion.h"
|
||||||
|
|
||||||
|
#include "7zAlloc.h"
|
||||||
|
#include "7zExtract.h"
|
||||||
|
#include "7zIn.h"
|
||||||
|
|
||||||
#ifdef USE_WINDOWS_FUNCTIONS
|
static void ConvertNumberToString(UInt64 value, char *s)
|
||||||
typedef HANDLE MY_FILE_HANDLE;
|
|
||||||
#else
|
|
||||||
typedef FILE *MY_FILE_HANDLE;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void ConvertNumberToString(CFileSize value, char *s)
|
|
||||||
{
|
{
|
||||||
char temp[32];
|
char temp[32];
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
@@ -48,7 +33,7 @@ void ConvertNumberToString(CFileSize value, char *s)
|
|||||||
#define PERIOD_100 (PERIOD_4 * 25 - 1)
|
#define PERIOD_100 (PERIOD_4 * 25 - 1)
|
||||||
#define PERIOD_400 (PERIOD_100 * 4 + 1)
|
#define PERIOD_400 (PERIOD_100 * 4 + 1)
|
||||||
|
|
||||||
void ConvertFileTimeToString(CNtfsFileTime *ft, char *s)
|
static void ConvertFileTimeToString(CNtfsFileTime *ft, char *s)
|
||||||
{
|
{
|
||||||
unsigned year, mon, day, hour, min, sec;
|
unsigned year, mon, day, hour, min, sec;
|
||||||
UInt64 v64 = ft->Low | ((UInt64)ft->High << 32);
|
UInt64 v64 = ft->Low | ((UInt64)ft->High << 32);
|
||||||
@@ -99,140 +84,6 @@ void ConvertFileTimeToString(CNtfsFileTime *ft, char *s)
|
|||||||
sprintf(s, "%04d-%02d-%02d %02d:%02d:%02d", year, mon, day, hour, min, sec);
|
sprintf(s, "%04d-%02d-%02d %02d:%02d:%02d", year, mon, day, hour, min, sec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef USE_WINDOWS_FUNCTIONS
|
|
||||||
/*
|
|
||||||
ReadFile and WriteFile functions in Windows have BUG:
|
|
||||||
If you Read or Write 64MB or more (probably min_failure_size = 64MB - 32KB + 1)
|
|
||||||
from/to Network file, it returns ERROR_NO_SYSTEM_RESOURCES
|
|
||||||
(Insufficient system resources exist to complete the requested service).
|
|
||||||
*/
|
|
||||||
#define kChunkSizeMax (1 << 24)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
size_t MyReadFile(MY_FILE_HANDLE file, void *data, size_t size)
|
|
||||||
{
|
|
||||||
if (size == 0)
|
|
||||||
return 0;
|
|
||||||
#ifdef USE_WINDOWS_FUNCTIONS
|
|
||||||
{
|
|
||||||
size_t processedSize = 0;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
DWORD curSize = (size > kChunkSizeMax) ? kChunkSizeMax : (DWORD)size;
|
|
||||||
DWORD processedLoc = 0;
|
|
||||||
BOOL res = ReadFile(file, data, curSize, &processedLoc, NULL);
|
|
||||||
data = (void *)((unsigned char *)data + processedLoc);
|
|
||||||
size -= processedLoc;
|
|
||||||
processedSize += processedLoc;
|
|
||||||
if (!res || processedLoc == 0)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
while (size > 0);
|
|
||||||
return processedSize;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
return fread(data, 1, size, file);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t MyWriteFile(MY_FILE_HANDLE file, void *data, size_t size)
|
|
||||||
{
|
|
||||||
if (size == 0)
|
|
||||||
return 0;
|
|
||||||
#ifdef USE_WINDOWS_FUNCTIONS
|
|
||||||
{
|
|
||||||
size_t processedSize = 0;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
DWORD curSize = (size > kChunkSizeMax) ? kChunkSizeMax : (DWORD)size;
|
|
||||||
DWORD processedLoc = 0;
|
|
||||||
BOOL res = WriteFile(file, data, curSize, &processedLoc, NULL);
|
|
||||||
data = (void *)((unsigned char *)data + processedLoc);
|
|
||||||
size -= processedLoc;
|
|
||||||
processedSize += processedLoc;
|
|
||||||
if (!res)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
while (size > 0);
|
|
||||||
return processedSize;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
return fwrite(data, 1, size, file);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
int MyCloseFile(MY_FILE_HANDLE file)
|
|
||||||
{
|
|
||||||
#ifdef USE_WINDOWS_FUNCTIONS
|
|
||||||
return (CloseHandle(file) != FALSE) ? 0 : 1;
|
|
||||||
#else
|
|
||||||
return fclose(file);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef struct _CFileInStream
|
|
||||||
{
|
|
||||||
ISzInStream InStream;
|
|
||||||
MY_FILE_HANDLE File;
|
|
||||||
} CFileInStream;
|
|
||||||
|
|
||||||
|
|
||||||
#define kBufferSize (1 << 12)
|
|
||||||
Byte g_Buffer[kBufferSize];
|
|
||||||
|
|
||||||
SRes SzFileReadImp(void *object, void **buffer, size_t *size)
|
|
||||||
{
|
|
||||||
CFileInStream *s = (CFileInStream *)object;
|
|
||||||
if (*size > kBufferSize)
|
|
||||||
*size = kBufferSize;
|
|
||||||
*size = MyReadFile(s->File, g_Buffer, *size);
|
|
||||||
*buffer = g_Buffer;
|
|
||||||
return SZ_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
SRes SzFileSeekImp(void *object, CFileSize pos, ESzSeek origin)
|
|
||||||
{
|
|
||||||
CFileInStream *s = (CFileInStream *)object;
|
|
||||||
|
|
||||||
#ifdef USE_WINDOWS_FUNCTIONS
|
|
||||||
{
|
|
||||||
LARGE_INTEGER value;
|
|
||||||
DWORD moveMethod;
|
|
||||||
value.LowPart = (DWORD)pos;
|
|
||||||
value.HighPart = (LONG)((UInt64)pos >> 32);
|
|
||||||
#ifdef _SZ_FILE_SIZE_32
|
|
||||||
/* VC 6.0 has bug with >> 32 shifts. */
|
|
||||||
value.HighPart = 0;
|
|
||||||
#endif
|
|
||||||
switch (origin)
|
|
||||||
{
|
|
||||||
case SZ_SEEK_SET: moveMethod = FILE_BEGIN; break;
|
|
||||||
case SZ_SEEK_CUR: moveMethod = FILE_CURRENT; break;
|
|
||||||
case SZ_SEEK_END: moveMethod = FILE_END; break;
|
|
||||||
default: return SZ_ERROR_PARAM;
|
|
||||||
}
|
|
||||||
value.LowPart = SetFilePointer(s->File, value.LowPart, &value.HighPart, moveMethod);
|
|
||||||
if (value.LowPart == 0xFFFFFFFF)
|
|
||||||
if (GetLastError() != NO_ERROR)
|
|
||||||
return SZ_ERROR_FAIL;
|
|
||||||
return SZ_OK;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
int moveMethod;
|
|
||||||
int res;
|
|
||||||
switch (origin)
|
|
||||||
{
|
|
||||||
case SZ_SEEK_SET: moveMethod = SEEK_SET; break;
|
|
||||||
case SZ_SEEK_CUR: moveMethod = SEEK_CUR; break;
|
|
||||||
case SZ_SEEK_END: moveMethod = SEEK_END; break;
|
|
||||||
default: return SZ_ERROR_PARAM;
|
|
||||||
}
|
|
||||||
res = fseek(s->File, (long)pos, moveMethod );
|
|
||||||
return (res == 0) ? SZ_OK : SZ_ERROR_FAIL;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void PrintError(char *sz)
|
void PrintError(char *sz)
|
||||||
{
|
{
|
||||||
printf("\nERROR: %s\n", sz);
|
printf("\nERROR: %s\n", sz);
|
||||||
@@ -241,12 +92,13 @@ void PrintError(char *sz)
|
|||||||
int MY_CDECL main(int numargs, char *args[])
|
int MY_CDECL main(int numargs, char *args[])
|
||||||
{
|
{
|
||||||
CFileInStream archiveStream;
|
CFileInStream archiveStream;
|
||||||
|
CLookToRead lookStream;
|
||||||
CSzArEx db;
|
CSzArEx db;
|
||||||
SRes res;
|
SRes res;
|
||||||
ISzAlloc allocImp;
|
ISzAlloc allocImp;
|
||||||
ISzAlloc allocTempImp;
|
ISzAlloc allocTempImp;
|
||||||
|
|
||||||
printf("\n7z ANSI-C Decoder 4.59 Copyright (c) 1999-2008 Igor Pavlov 2008-07-09\n");
|
printf("\n7z ANSI-C Decoder " MY_VERSION_COPYRIGHT_DATE "\n");
|
||||||
if (numargs == 1)
|
if (numargs == 1)
|
||||||
{
|
{
|
||||||
printf(
|
printf(
|
||||||
@@ -263,22 +115,18 @@ int MY_CDECL main(int numargs, char *args[])
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
archiveStream.File =
|
if (InFile_Open(&archiveStream.file, args[2]))
|
||||||
#ifdef USE_WINDOWS_FUNCTIONS
|
|
||||||
CreateFileA(args[2], GENERIC_READ, FILE_SHARE_READ,
|
|
||||||
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
||||||
if (archiveStream.File == INVALID_HANDLE_VALUE)
|
|
||||||
#else
|
|
||||||
archiveStream.File = fopen(args[2], "rb");
|
|
||||||
if (archiveStream.File == 0)
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
PrintError("can not open input file");
|
PrintError("can not open input file");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
archiveStream.InStream.Read = SzFileReadImp;
|
|
||||||
archiveStream.InStream.Seek = SzFileSeekImp;
|
FileInStream_CreateVTable(&archiveStream);
|
||||||
|
LookToRead_CreateVTable(&lookStream, False);
|
||||||
|
|
||||||
|
lookStream.realStream = &archiveStream.s;
|
||||||
|
LookToRead_Init(&lookStream);
|
||||||
|
|
||||||
allocImp.Alloc = SzAlloc;
|
allocImp.Alloc = SzAlloc;
|
||||||
allocImp.Free = SzFree;
|
allocImp.Free = SzFree;
|
||||||
@@ -289,19 +137,14 @@ int MY_CDECL main(int numargs, char *args[])
|
|||||||
CrcGenerateTable();
|
CrcGenerateTable();
|
||||||
|
|
||||||
SzArEx_Init(&db);
|
SzArEx_Init(&db);
|
||||||
res = SzArEx_Open(&db, &archiveStream.InStream, &allocImp, &allocTempImp);
|
res = SzArEx_Open(&db, &lookStream.s, &allocImp, &allocTempImp);
|
||||||
if (res == SZ_OK)
|
if (res == SZ_OK)
|
||||||
{
|
{
|
||||||
char *command = args[1];
|
char *command = args[1];
|
||||||
int listCommand = 0;
|
int listCommand = 0, testCommand = 0, extractCommand = 0;
|
||||||
int testCommand = 0;
|
if (strcmp(command, "l") == 0) listCommand = 1;
|
||||||
int extractCommand = 0;
|
else if (strcmp(command, "t") == 0) testCommand = 1;
|
||||||
if (strcmp(command, "l") == 0)
|
else if (strcmp(command, "e") == 0) extractCommand = 1;
|
||||||
listCommand = 1;
|
|
||||||
if (strcmp(command, "t") == 0)
|
|
||||||
testCommand = 1;
|
|
||||||
else if (strcmp(command, "e") == 0)
|
|
||||||
extractCommand = 1;
|
|
||||||
|
|
||||||
if (listCommand)
|
if (listCommand)
|
||||||
{
|
{
|
||||||
@@ -316,7 +159,7 @@ int MY_CDECL main(int numargs, char *args[])
|
|||||||
else
|
else
|
||||||
strcpy(t, " ");
|
strcpy(t, " ");
|
||||||
|
|
||||||
printf("%10s %s %s\n", s, t, f->Name);
|
printf("%s %10s %s\n", t, s, f->Name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (testCommand || extractCommand)
|
else if (testCommand || extractCommand)
|
||||||
@@ -349,7 +192,7 @@ int MY_CDECL main(int numargs, char *args[])
|
|||||||
printf("\n");
|
printf("\n");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
res = SzAr_Extract(&db, &archiveStream.InStream, i,
|
res = SzAr_Extract(&db, &lookStream.s, i,
|
||||||
&blockIndex, &outBuffer, &outBufferSize,
|
&blockIndex, &outBuffer, &outBufferSize,
|
||||||
&offset, &outSizeProcessed,
|
&offset, &outSizeProcessed,
|
||||||
&allocImp, &allocTempImp);
|
&allocImp, &allocTempImp);
|
||||||
@@ -357,7 +200,7 @@ int MY_CDECL main(int numargs, char *args[])
|
|||||||
break;
|
break;
|
||||||
if (!testCommand)
|
if (!testCommand)
|
||||||
{
|
{
|
||||||
MY_FILE_HANDLE outputHandle;
|
CSzFile outFile;
|
||||||
size_t processedSize;
|
size_t processedSize;
|
||||||
char *fileName = f->Name;
|
char *fileName = f->Name;
|
||||||
size_t nameLen = strlen(f->Name);
|
size_t nameLen = strlen(f->Name);
|
||||||
@@ -368,28 +211,21 @@ int MY_CDECL main(int numargs, char *args[])
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
outputHandle =
|
if (OutFile_Open(&outFile, fileName))
|
||||||
#ifdef USE_WINDOWS_FUNCTIONS
|
|
||||||
CreateFileA(fileName, GENERIC_WRITE, FILE_SHARE_READ,
|
|
||||||
NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
||||||
if (outputHandle == INVALID_HANDLE_VALUE)
|
|
||||||
#else
|
|
||||||
fopen(fileName, "wb+");
|
|
||||||
if (outputHandle == 0)
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
PrintError("can not open output file");
|
PrintError("can not open output file");
|
||||||
res = SZ_ERROR_FAIL;
|
res = SZ_ERROR_FAIL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
processedSize = MyWriteFile(outputHandle, outBuffer + offset, outSizeProcessed);
|
processedSize = outSizeProcessed;
|
||||||
if (processedSize != outSizeProcessed)
|
if (File_Write(&outFile, outBuffer + offset, &processedSize) != 0 ||
|
||||||
|
processedSize != outSizeProcessed)
|
||||||
{
|
{
|
||||||
PrintError("can not write output file");
|
PrintError("can not write output file");
|
||||||
res = SZ_ERROR_FAIL;
|
res = SZ_ERROR_FAIL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (MyCloseFile(outputHandle))
|
if (File_Close(&outFile))
|
||||||
{
|
{
|
||||||
PrintError("can not close output file");
|
PrintError("can not close output file");
|
||||||
res = SZ_ERROR_FAIL;
|
res = SZ_ERROR_FAIL;
|
||||||
@@ -408,7 +244,7 @@ int MY_CDECL main(int numargs, char *args[])
|
|||||||
}
|
}
|
||||||
SzArEx_Free(&db, &allocImp);
|
SzArEx_Free(&db, &allocImp);
|
||||||
|
|
||||||
MyCloseFile(archiveStream.File);
|
File_Close(&archiveStream.file);
|
||||||
if (res == SZ_OK)
|
if (res == SZ_OK)
|
||||||
{
|
{
|
||||||
printf("\nEverything is Ok\n");
|
printf("\nEverything is Ok\n");
|
||||||
|
|||||||
@@ -4,10 +4,13 @@ PROG = 7zDec.exe
|
|||||||
|
|
||||||
C_OBJS = \
|
C_OBJS = \
|
||||||
$O\7zBuf.obj \
|
$O\7zBuf.obj \
|
||||||
|
$O\7zBuf2.obj \
|
||||||
$O\7zCrc.obj \
|
$O\7zCrc.obj \
|
||||||
$O\LzmaDec.obj \
|
$O\LzmaDec.obj \
|
||||||
$O\Bra86.obj \
|
$O\Bra86.obj \
|
||||||
$O\Bcj2.obj \
|
$O\Bcj2.obj \
|
||||||
|
$O\7zFile.obj \
|
||||||
|
$O\7zStream.obj \
|
||||||
|
|
||||||
7Z_OBJS = \
|
7Z_OBJS = \
|
||||||
$O\7zAlloc.obj \
|
$O\7zAlloc.obj \
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ LIB =
|
|||||||
RM = rm -f
|
RM = rm -f
|
||||||
CFLAGS = -c -O2 -Wall
|
CFLAGS = -c -O2 -Wall
|
||||||
|
|
||||||
OBJS = 7zAlloc.o 7zBuf.o 7zCrc.o 7zDecode.o 7zExtract.o 7zHeader.o 7zIn.o 7zItem.o 7zMain.o LzmaDec.o Bra86.o Bcj2.o
|
OBJS = 7zAlloc.o 7zBuf.o 7zBuf2.o 7zCrc.o 7zDecode.o 7zExtract.o 7zHeader.o 7zIn.o 7zItem.o 7zMain.o LzmaDec.o Bra86.o Bcj2.o 7zFile.o 7zStream.o
|
||||||
|
|
||||||
all: $(PROG)
|
all: $(PROG)
|
||||||
|
|
||||||
@@ -17,6 +17,9 @@ $(PROG): $(OBJS)
|
|||||||
7zBuf.o: ../../7zBuf.c
|
7zBuf.o: ../../7zBuf.c
|
||||||
$(CXX) $(CFLAGS) ../../7zBuf.c
|
$(CXX) $(CFLAGS) ../../7zBuf.c
|
||||||
|
|
||||||
|
7zBuf2.o: ../../7zBuf2.c
|
||||||
|
$(CXX) $(CFLAGS) ../../7zBuf2.c
|
||||||
|
|
||||||
7zCrc.o: ../../7zCrc.c
|
7zCrc.o: ../../7zCrc.c
|
||||||
$(CXX) $(CFLAGS) ../../7zCrc.c
|
$(CXX) $(CFLAGS) ../../7zCrc.c
|
||||||
|
|
||||||
@@ -47,6 +50,12 @@ Bra86.o: ../../Bra86.c
|
|||||||
Bcj2.o: ../../Bcj2.c
|
Bcj2.o: ../../Bcj2.c
|
||||||
$(CXX) $(CFLAGS) ../../Bcj2.c
|
$(CXX) $(CFLAGS) ../../Bcj2.c
|
||||||
|
|
||||||
|
7zFile.o: ../../7zFile.c
|
||||||
|
$(CXX) $(CFLAGS) ../../7zFile.c
|
||||||
|
|
||||||
|
7zStream.o: ../../7zStream.c
|
||||||
|
$(CXX) $(CFLAGS) ../../7zStream.c
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
-$(RM) $(PROG) $(OBJS)
|
-$(RM) $(PROG) $(OBJS)
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/* Bcj2.c -- Converter for x86 code (BCJ2)
|
/* Bcj2.c -- Converter for x86 code (BCJ2)
|
||||||
2008-08-17
|
2008-10-04 : Igor Pavlov : Public domain */
|
||||||
Copyright (c) 1999-2008 Igor Pavlov
|
|
||||||
Read Bra.h for license options */
|
|
||||||
|
|
||||||
#include "Bcj2.h"
|
#include "Bcj2.h"
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/* Bcj2.h -- Converter for x86 code (BCJ2)
|
/* Bcj2.h -- Converter for x86 code (BCJ2)
|
||||||
2008-08-05
|
2008-10-04 : Igor Pavlov : Public domain */
|
||||||
Copyright (c) 1999-2008 Igor Pavlov
|
|
||||||
Read Bra.h for license options */
|
|
||||||
|
|
||||||
#ifndef __BCJ2_H
|
#ifndef __BCJ2_H
|
||||||
#define __BCJ2_H
|
#define __BCJ2_H
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/* Bra.c -- converters for RISC code
|
/* Bra.c -- Converters for RISC code
|
||||||
2008-08-05
|
2008-10-04 : Igor Pavlov : Public domain */
|
||||||
Copyright (c) 1999-2008 Igor Pavlov
|
|
||||||
Read Bra.h for license options */
|
|
||||||
|
|
||||||
#include "Bra.h"
|
#include "Bra.h"
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/* Bra.h -- Branch converters for executables
|
/* Bra.h -- Branch converters for executables
|
||||||
2008-08-17
|
2008-10-04 : Igor Pavlov : Public domain */
|
||||||
Copyright (c) 1999-2008 Igor Pavlov
|
|
||||||
Read LzmaDec.h for license options */
|
|
||||||
|
|
||||||
#ifndef __BRA_H
|
#ifndef __BRA_H
|
||||||
#define __BRA_H
|
#define __BRA_H
|
||||||
@@ -43,7 +41,7 @@ in CALL instructions to increase the compression ratio.
|
|||||||
UInt32 ip = 0;
|
UInt32 ip = 0;
|
||||||
for ()
|
for ()
|
||||||
{
|
{
|
||||||
// size must be >= Alignment + LookAhead, if it's not last block
|
; size must be >= Alignment + LookAhead, if it's not last block
|
||||||
SizeT processed = Convert(data, size, ip, 1);
|
SizeT processed = Convert(data, size, ip, 1);
|
||||||
data += processed;
|
data += processed;
|
||||||
size -= processed;
|
size -= processed;
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/* Bra86.c -- converter for x86 code (BCJ)
|
/* Bra86.c -- Converter for x86 code (BCJ)
|
||||||
2008-08-17
|
2008-10-04 : Igor Pavlov : Public domain */
|
||||||
Copyright (c) 1999-2008 Igor Pavlov
|
|
||||||
Read Bra.h for license options */
|
|
||||||
|
|
||||||
#include "Bra.h"
|
#include "Bra.h"
|
||||||
|
|
||||||
|
|||||||
+2
-4
@@ -1,7 +1,5 @@
|
|||||||
/* BraIA64.c -- converter for IA-64 code
|
/* BraIA64.c -- Converter for IA-64 code
|
||||||
2008-08-05
|
2008-10-04 : Igor Pavlov : Public domain */
|
||||||
Copyright (c) 1999-2008 Igor Pavlov
|
|
||||||
Read Bra.h for license options */
|
|
||||||
|
|
||||||
#include "Bra.h"
|
#include "Bra.h"
|
||||||
|
|
||||||
|
|||||||
+1
-3
@@ -1,7 +1,5 @@
|
|||||||
/* LzFind.c -- Match finder for LZ algorithms
|
/* LzFind.c -- Match finder for LZ algorithms
|
||||||
2008-08-17
|
2008-10-04 : Igor Pavlov : Public domain */
|
||||||
Copyright (c) 1999-2008 Igor Pavlov
|
|
||||||
Read LzFind.h for license options */
|
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
|||||||
+1
-10
@@ -1,14 +1,5 @@
|
|||||||
/* LzFind.h -- Match finder for LZ algorithms
|
/* LzFind.h -- Match finder for LZ algorithms
|
||||||
2008-08-05
|
2008-10-04 : Igor Pavlov : Public domain */
|
||||||
Copyright (c) 1999-2008 Igor Pavlov
|
|
||||||
You can use any of the following license options:
|
|
||||||
1) GNU Lesser General Public License (GNU LGPL)
|
|
||||||
2) Common Public License (CPL)
|
|
||||||
3) Common Development and Distribution License (CDDL) Version 1.0
|
|
||||||
4) Igor Pavlov, as the author of this code, expressly permits you to
|
|
||||||
statically or dynamically link your code (or bind by name) to this file,
|
|
||||||
while you keep this file unmodified.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __LZFIND_H
|
#ifndef __LZFIND_H
|
||||||
#define __LZFIND_H
|
#define __LZFIND_H
|
||||||
|
|||||||
+1
-3
@@ -1,7 +1,5 @@
|
|||||||
/* LzFindMt.c -- multithreaded Match finder for LZ algorithms
|
/* LzFindMt.c -- multithreaded Match finder for LZ algorithms
|
||||||
2008-08-17
|
2008-10-04 : Igor Pavlov : Public domain */
|
||||||
Copyright (c) 1999-2008 Igor Pavlov
|
|
||||||
Read LzFind.h for license options */
|
|
||||||
|
|
||||||
#include "LzHash.h"
|
#include "LzHash.h"
|
||||||
|
|
||||||
|
|||||||
+1
-3
@@ -1,7 +1,5 @@
|
|||||||
/* LzFindMt.h -- multithreaded Match finder for LZ algorithms
|
/* LzFindMt.h -- multithreaded Match finder for LZ algorithms
|
||||||
2008-08-05
|
2008-10-04 : Igor Pavlov : Public domain */
|
||||||
Copyright (c) 1999-2008 Igor Pavlov
|
|
||||||
Read LzFind.h for license options */
|
|
||||||
|
|
||||||
#ifndef __LZFINDMT_H
|
#ifndef __LZFINDMT_H
|
||||||
#define __LZFINDMT_H
|
#define __LZFINDMT_H
|
||||||
|
|||||||
+1
-3
@@ -1,7 +1,5 @@
|
|||||||
/* LzHash.h -- HASH functions for LZ algorithms
|
/* LzHash.h -- HASH functions for LZ algorithms
|
||||||
2008-03-26
|
2008-10-04 : Igor Pavlov : Public domain */
|
||||||
Copyright (c) 1999-2008 Igor Pavlov
|
|
||||||
Read LzFind.h for license options */
|
|
||||||
|
|
||||||
#ifndef __LZHASH_H
|
#ifndef __LZHASH_H
|
||||||
#define __LZHASH_H
|
#define __LZHASH_H
|
||||||
|
|||||||
+7
-14
@@ -1,7 +1,5 @@
|
|||||||
/* LzmaDec.c -- LZMA Decoder
|
/* LzmaDec.c -- LZMA Decoder
|
||||||
2008-08-17
|
2008-11-06 : Igor Pavlov : Public domain */
|
||||||
Copyright (c) 1999-2008 Igor Pavlov
|
|
||||||
Read LzmaDec.h for license options */
|
|
||||||
|
|
||||||
#include "LzmaDec.h"
|
#include "LzmaDec.h"
|
||||||
|
|
||||||
@@ -115,12 +113,7 @@ Read LzmaDec.h for license options */
|
|||||||
StopCompilingDueBUG
|
StopCompilingDueBUG
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
static const Byte kLiteralNextStates[kNumStates * 2] =
|
||||||
#define LZMA_STREAM_WAS_FINISHED_ID (-1)
|
|
||||||
#define LZMA_SPEC_LEN_OFFSET (-3)
|
|
||||||
*/
|
|
||||||
|
|
||||||
const Byte kLiteralNextStates[kNumStates * 2] =
|
|
||||||
{
|
{
|
||||||
0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 4, 5,
|
0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 4, 5,
|
||||||
7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10
|
7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10
|
||||||
@@ -132,8 +125,8 @@ const Byte kLiteralNextStates[kNumStates * 2] =
|
|||||||
And it decodes new LZMA-symbols while (buf < bufLimit), but "buf" is without last normalization
|
And it decodes new LZMA-symbols while (buf < bufLimit), but "buf" is without last normalization
|
||||||
Out:
|
Out:
|
||||||
Result:
|
Result:
|
||||||
0 - OK
|
SZ_OK - OK
|
||||||
1 - Error
|
SZ_ERROR_DATA - Error
|
||||||
p->remainLen:
|
p->remainLen:
|
||||||
< kMatchSpecLenStart : normal remain
|
< kMatchSpecLenStart : normal remain
|
||||||
= kMatchSpecLenStart : finished
|
= kMatchSpecLenStart : finished
|
||||||
@@ -390,6 +383,8 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte
|
|||||||
|
|
||||||
len += kMatchMinLen;
|
len += kMatchMinLen;
|
||||||
|
|
||||||
|
if (limit == dicPos)
|
||||||
|
return SZ_ERROR_DATA;
|
||||||
{
|
{
|
||||||
SizeT rem = limit - dicPos;
|
SizeT rem = limit - dicPos;
|
||||||
unsigned curLen = ((rem < len) ? (unsigned)rem : len);
|
unsigned curLen = ((rem < len) ? (unsigned)rem : len);
|
||||||
@@ -464,8 +459,6 @@ static void MY_FAST_CALL LzmaDec_WriteRem(CLzmaDec *p, SizeT limit)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* LzmaDec_DecodeReal2 decodes LZMA-symbols and sets p->needFlush and p->needInit, if required. */
|
|
||||||
|
|
||||||
static int MY_FAST_CALL LzmaDec_DecodeReal2(CLzmaDec *p, SizeT limit, const Byte *bufLimit)
|
static int MY_FAST_CALL LzmaDec_DecodeReal2(CLzmaDec *p, SizeT limit, const Byte *bufLimit)
|
||||||
{
|
{
|
||||||
do
|
do
|
||||||
@@ -811,7 +804,7 @@ SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *sr
|
|||||||
p->buf = src;
|
p->buf = src;
|
||||||
if (LzmaDec_DecodeReal2(p, dicLimit, bufLimit) != 0)
|
if (LzmaDec_DecodeReal2(p, dicLimit, bufLimit) != 0)
|
||||||
return SZ_ERROR_DATA;
|
return SZ_ERROR_DATA;
|
||||||
processed = p->buf - src;
|
processed = (SizeT)(p->buf - src);
|
||||||
(*srcLen) += processed;
|
(*srcLen) += processed;
|
||||||
src += processed;
|
src += processed;
|
||||||
inSize -= processed;
|
inSize -= processed;
|
||||||
|
|||||||
+1
-10
@@ -1,14 +1,5 @@
|
|||||||
/* LzmaDec.h -- LZMA Decoder
|
/* LzmaDec.h -- LZMA Decoder
|
||||||
2008-08-05
|
2008-10-04 : Igor Pavlov : Public domain */
|
||||||
Copyright (c) 1999-2008 Igor Pavlov
|
|
||||||
You can use any of the following license options:
|
|
||||||
1) GNU Lesser General Public License (GNU LGPL)
|
|
||||||
2) Common Public License (CPL)
|
|
||||||
3) Common Development and Distribution License (CDDL) Version 1.0
|
|
||||||
4) Igor Pavlov, as the author of this code, expressly permits you to
|
|
||||||
statically or dynamically link your code (or bind by name) to this file,
|
|
||||||
while you keep this file unmodified.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __LZMADEC_H
|
#ifndef __LZMADEC_H
|
||||||
#define __LZMADEC_H
|
#define __LZMADEC_H
|
||||||
|
|||||||
+5
-5
@@ -1,7 +1,5 @@
|
|||||||
/* LzmaEnc.c -- LZMA Encoder
|
/* LzmaEnc.c -- LZMA Encoder
|
||||||
2008-08-17
|
2008-10-04 : Igor Pavlov : Public domain */
|
||||||
Copyright (c) 1999-2008 Igor Pavlov
|
|
||||||
Read LzmaEnc.h for license options */
|
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
@@ -2092,6 +2090,8 @@ void LzmaEnc_Finish(CLzmaEncHandle pp)
|
|||||||
CLzmaEnc *p = (CLzmaEnc *)pp;
|
CLzmaEnc *p = (CLzmaEnc *)pp;
|
||||||
if (p->mtMode)
|
if (p->mtMode)
|
||||||
MatchFinderMt_ReleaseStream(&p->matchFinderMt);
|
MatchFinderMt_ReleaseStream(&p->matchFinderMt);
|
||||||
|
#else
|
||||||
|
pp = pp;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2154,7 +2154,7 @@ SRes LzmaEnc_CodeOneMemBlock(CLzmaEncHandle pp, Bool reInit,
|
|||||||
RangeEnc_Init(&p->rc);
|
RangeEnc_Init(&p->rc);
|
||||||
p->rc.outStream = &outStream.funcTable;
|
p->rc.outStream = &outStream.funcTable;
|
||||||
|
|
||||||
res = LzmaEnc_CodeOneBlock(pp, True, desiredPackSize, *unpackSize);
|
res = LzmaEnc_CodeOneBlock(p, True, desiredPackSize, *unpackSize);
|
||||||
|
|
||||||
*unpackSize = (UInt32)(p->nowPos64 - nowPos64);
|
*unpackSize = (UInt32)(p->nowPos64 - nowPos64);
|
||||||
*destLen -= outStream.rem;
|
*destLen -= outStream.rem;
|
||||||
@@ -2181,7 +2181,7 @@ SRes LzmaEnc_Encode(CLzmaEncHandle pp, ISeqOutStream *outStream, ISeqInStream *i
|
|||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
res = LzmaEnc_CodeOneBlock(pp, False, 0, 0);
|
res = LzmaEnc_CodeOneBlock(p, False, 0, 0);
|
||||||
if (res != SZ_OK || p->finished != 0)
|
if (res != SZ_OK || p->finished != 0)
|
||||||
break;
|
break;
|
||||||
if (progress != 0)
|
if (progress != 0)
|
||||||
|
|||||||
+1
-3
@@ -1,7 +1,5 @@
|
|||||||
/* LzmaEnc.h -- LZMA Encoder
|
/* LzmaEnc.h -- LZMA Encoder
|
||||||
2008-08-05
|
2008-10-04 : Igor Pavlov : Public domain */
|
||||||
Copyright (c) 1999-2008 Igor Pavlov
|
|
||||||
Read LzFind.h for license options */
|
|
||||||
|
|
||||||
#ifndef __LZMAENC_H
|
#ifndef __LZMAENC_H
|
||||||
#define __LZMAENC_H
|
#define __LZMAENC_H
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/* LzmaLibExports.c -- LZMA library DLL Entry point
|
/* LzmaLibExports.c -- LZMA library DLL Entry point
|
||||||
2008-03-26
|
2008-10-04 : Igor Pavlov : Public domain */
|
||||||
Igor Pavlov
|
|
||||||
Public domain */
|
|
||||||
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
|
|||||||
+76
-133
@@ -1,7 +1,5 @@
|
|||||||
/* LzmaUtil.c -- Test application for LZMA compression
|
/* LzmaUtil.c -- Test application for LZMA compression
|
||||||
2008-08-05
|
2008-11-23 : Igor Pavlov : Public domain */
|
||||||
Igor Pavlov
|
|
||||||
public domain */
|
|
||||||
|
|
||||||
#define _CRT_SECURE_NO_WARNINGS
|
#define _CRT_SECURE_NO_WARNINGS
|
||||||
|
|
||||||
@@ -9,9 +7,11 @@ public domain */
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "../Alloc.h"
|
||||||
|
#include "../7zFile.h"
|
||||||
|
#include "../7zVersion.h"
|
||||||
#include "../LzmaDec.h"
|
#include "../LzmaDec.h"
|
||||||
#include "../LzmaEnc.h"
|
#include "../LzmaEnc.h"
|
||||||
#include "../Alloc.h"
|
|
||||||
|
|
||||||
const char *kCantReadMessage = "Can not read input file";
|
const char *kCantReadMessage = "Can not read input file";
|
||||||
const char *kCantWriteMessage = "Can not write output file";
|
const char *kCantWriteMessage = "Can not write output file";
|
||||||
@@ -22,40 +22,9 @@ static void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); }
|
|||||||
static void SzFree(void *p, void *address) { p = p; MyFree(address); }
|
static void SzFree(void *p, void *address) { p = p; MyFree(address); }
|
||||||
static ISzAlloc g_Alloc = { SzAlloc, SzFree };
|
static ISzAlloc g_Alloc = { SzAlloc, SzFree };
|
||||||
|
|
||||||
#define kInBufferSize (1 << 15)
|
|
||||||
#define kOutBufferSize (1 << 15)
|
|
||||||
|
|
||||||
unsigned char g_InBuffer[kInBufferSize];
|
|
||||||
unsigned char g_OutBuffer[kOutBufferSize];
|
|
||||||
|
|
||||||
size_t MyReadFile(FILE *file, void *data, size_t size)
|
|
||||||
{ return fread(data, 1, size, file); }
|
|
||||||
|
|
||||||
int MyReadFileAndCheck(FILE *file, void *data, size_t size)
|
|
||||||
{ return (MyReadFile(file, data, size) == size); }
|
|
||||||
|
|
||||||
size_t MyWriteFile(FILE *file, const void *data, size_t size)
|
|
||||||
{
|
|
||||||
if (size == 0)
|
|
||||||
return 0;
|
|
||||||
return fwrite(data, 1, size, file);
|
|
||||||
}
|
|
||||||
|
|
||||||
int MyWriteFileAndCheck(FILE *file, const void *data, size_t size)
|
|
||||||
{ return (MyWriteFile(file, data, size) == size); }
|
|
||||||
|
|
||||||
long MyGetFileLength(FILE *file)
|
|
||||||
{
|
|
||||||
long length;
|
|
||||||
fseek(file, 0, SEEK_END);
|
|
||||||
length = ftell(file);
|
|
||||||
fseek(file, 0, SEEK_SET);
|
|
||||||
return length;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PrintHelp(char *buffer)
|
void PrintHelp(char *buffer)
|
||||||
{
|
{
|
||||||
strcat(buffer, "\nLZMA Utility 4.58 Copyright (c) 1999-2008 Igor Pavlov 2008-04-11\n"
|
strcat(buffer, "\nLZMA Utility " MY_VERSION_COPYRIGHT_DATE "\n"
|
||||||
"\nUsage: lzma <e|d> inputFile outputFile\n"
|
"\nUsage: lzma <e|d> inputFile outputFile\n"
|
||||||
" e: encode file\n"
|
" e: encode file\n"
|
||||||
" d: decode file\n");
|
" d: decode file\n");
|
||||||
@@ -83,50 +52,24 @@ int PrintUserError(char *buffer)
|
|||||||
#define IN_BUF_SIZE (1 << 16)
|
#define IN_BUF_SIZE (1 << 16)
|
||||||
#define OUT_BUF_SIZE (1 << 16)
|
#define OUT_BUF_SIZE (1 << 16)
|
||||||
|
|
||||||
static int Decode(FILE *inFile, FILE *outFile, char *rs)
|
static SRes Decode2(CLzmaDec *state, ISeqOutStream *outStream, ISeqInStream *inStream,
|
||||||
{
|
UInt64 unpackSize)
|
||||||
UInt64 unpackSize;
|
|
||||||
int thereIsSize; /* = 1, if there is uncompressed size in headers */
|
|
||||||
int i;
|
|
||||||
int res = 0;
|
|
||||||
|
|
||||||
CLzmaDec state;
|
|
||||||
|
|
||||||
/* header: 5 bytes of LZMA properties and 8 bytes of uncompressed size */
|
|
||||||
unsigned char header[LZMA_PROPS_SIZE + 8];
|
|
||||||
|
|
||||||
/* Read and parse header */
|
|
||||||
|
|
||||||
if (!MyReadFileAndCheck(inFile, header, sizeof(header)))
|
|
||||||
return PrintError(rs, kCantReadMessage);
|
|
||||||
|
|
||||||
unpackSize = 0;
|
|
||||||
thereIsSize = 0;
|
|
||||||
for (i = 0; i < 8; i++)
|
|
||||||
{
|
|
||||||
unsigned char b = header[LZMA_PROPS_SIZE + i];
|
|
||||||
if (b != 0xFF)
|
|
||||||
thereIsSize = 1;
|
|
||||||
unpackSize += (UInt64)b << (i * 8);
|
|
||||||
}
|
|
||||||
|
|
||||||
LzmaDec_Construct(&state);
|
|
||||||
res = LzmaDec_Allocate(&state, header, LZMA_PROPS_SIZE, &g_Alloc);
|
|
||||||
if (res != SZ_OK)
|
|
||||||
return res;
|
|
||||||
{
|
{
|
||||||
|
int thereIsSize = (unpackSize != (UInt64)(Int64)-1);
|
||||||
Byte inBuf[IN_BUF_SIZE];
|
Byte inBuf[IN_BUF_SIZE];
|
||||||
Byte outBuf[OUT_BUF_SIZE];
|
Byte outBuf[OUT_BUF_SIZE];
|
||||||
size_t inPos = 0, inSize = 0, outPos = 0;
|
size_t inPos = 0, inSize = 0, outPos = 0;
|
||||||
LzmaDec_Init(&state);
|
LzmaDec_Init(state);
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
if (inPos == inSize)
|
if (inPos == inSize)
|
||||||
{
|
{
|
||||||
inSize = MyReadFile(inFile, inBuf, IN_BUF_SIZE);
|
inSize = IN_BUF_SIZE;
|
||||||
|
RINOK(inStream->Read(inStream, inBuf, &inSize));
|
||||||
inPos = 0;
|
inPos = 0;
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
SRes res;
|
||||||
SizeT inProcessed = inSize - inPos;
|
SizeT inProcessed = inSize - inPos;
|
||||||
SizeT outProcessed = OUT_BUF_SIZE - outPos;
|
SizeT outProcessed = OUT_BUF_SIZE - outPos;
|
||||||
ELzmaFinishMode finishMode = LZMA_FINISH_ANY;
|
ELzmaFinishMode finishMode = LZMA_FINISH_ANY;
|
||||||
@@ -137,79 +80,69 @@ static int Decode(FILE *inFile, FILE *outFile, char *rs)
|
|||||||
finishMode = LZMA_FINISH_END;
|
finishMode = LZMA_FINISH_END;
|
||||||
}
|
}
|
||||||
|
|
||||||
res = LzmaDec_DecodeToBuf(&state, outBuf + outPos, &outProcessed,
|
res = LzmaDec_DecodeToBuf(state, outBuf + outPos, &outProcessed,
|
||||||
inBuf + inPos, &inProcessed, finishMode, &status);
|
inBuf + inPos, &inProcessed, finishMode, &status);
|
||||||
inPos += (UInt32)inProcessed;
|
inPos += inProcessed;
|
||||||
outPos += outProcessed;
|
outPos += outProcessed;
|
||||||
unpackSize -= outProcessed;
|
unpackSize -= outProcessed;
|
||||||
|
|
||||||
if (outFile != 0)
|
if (outStream)
|
||||||
MyWriteFile(outFile, outBuf, outPos);
|
if (outStream->Write(outStream, outBuf, outPos) != outPos)
|
||||||
|
return SZ_ERROR_WRITE;
|
||||||
|
|
||||||
outPos = 0;
|
outPos = 0;
|
||||||
|
|
||||||
if (res != SZ_OK || thereIsSize && unpackSize == 0)
|
if (res != SZ_OK || thereIsSize && unpackSize == 0)
|
||||||
break;
|
return res;
|
||||||
|
|
||||||
if (inProcessed == 0 && outProcessed == 0)
|
if (inProcessed == 0 && outProcessed == 0)
|
||||||
{
|
{
|
||||||
if (thereIsSize || status != LZMA_STATUS_FINISHED_WITH_MARK)
|
if (thereIsSize || status != LZMA_STATUS_FINISHED_WITH_MARK)
|
||||||
res = SZ_ERROR_DATA;
|
return SZ_ERROR_DATA;
|
||||||
break;
|
return res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static SRes Decode(ISeqOutStream *outStream, ISeqInStream *inStream)
|
||||||
|
{
|
||||||
|
UInt64 unpackSize;
|
||||||
|
int i;
|
||||||
|
SRes res = 0;
|
||||||
|
|
||||||
|
CLzmaDec state;
|
||||||
|
|
||||||
|
/* header: 5 bytes of LZMA properties and 8 bytes of uncompressed size */
|
||||||
|
unsigned char header[LZMA_PROPS_SIZE + 8];
|
||||||
|
|
||||||
|
/* Read and parse header */
|
||||||
|
|
||||||
|
RINOK(SeqInStream_Read(inStream, header, sizeof(header)));
|
||||||
|
|
||||||
|
unpackSize = 0;
|
||||||
|
for (i = 0; i < 8; i++)
|
||||||
|
unpackSize += (UInt64)header[LZMA_PROPS_SIZE + i] << (i * 8);
|
||||||
|
|
||||||
|
LzmaDec_Construct(&state);
|
||||||
|
RINOK(LzmaDec_Allocate(&state, header, LZMA_PROPS_SIZE, &g_Alloc));
|
||||||
|
res = Decode2(&state, outStream, inStream, unpackSize);
|
||||||
LzmaDec_Free(&state, &g_Alloc);
|
LzmaDec_Free(&state, &g_Alloc);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct _CFileSeqInStream
|
static SRes Encode(ISeqOutStream *outStream, ISeqInStream *inStream, UInt64 fileSize, char *rs)
|
||||||
{
|
|
||||||
ISeqInStream funcTable;
|
|
||||||
FILE *file;
|
|
||||||
} CFileSeqInStream;
|
|
||||||
|
|
||||||
static SRes MyRead(void *p, void *buf, size_t *size)
|
|
||||||
{
|
|
||||||
if (*size == 0)
|
|
||||||
return SZ_OK;
|
|
||||||
*size = MyReadFile(((CFileSeqInStream*)p)->file, buf, *size);
|
|
||||||
/*
|
|
||||||
if (*size == 0)
|
|
||||||
return SZE_FAIL;
|
|
||||||
*/
|
|
||||||
return SZ_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef struct _CFileSeqOutStream
|
|
||||||
{
|
|
||||||
ISeqOutStream funcTable;
|
|
||||||
FILE *file;
|
|
||||||
} CFileSeqOutStream;
|
|
||||||
|
|
||||||
static size_t MyWrite(void *pp, const void *buf, size_t size)
|
|
||||||
{
|
|
||||||
return MyWriteFile(((CFileSeqOutStream *)pp)->file, buf, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
static SRes Encode(FILE *inFile, FILE *outFile, char *rs)
|
|
||||||
{
|
{
|
||||||
CLzmaEncHandle enc;
|
CLzmaEncHandle enc;
|
||||||
SRes res;
|
SRes res;
|
||||||
CFileSeqInStream inStream;
|
|
||||||
CFileSeqOutStream outStream;
|
|
||||||
CLzmaEncProps props;
|
CLzmaEncProps props;
|
||||||
|
|
||||||
|
rs = rs;
|
||||||
|
|
||||||
enc = LzmaEnc_Create(&g_Alloc);
|
enc = LzmaEnc_Create(&g_Alloc);
|
||||||
if (enc == 0)
|
if (enc == 0)
|
||||||
return SZ_ERROR_MEM;
|
return SZ_ERROR_MEM;
|
||||||
|
|
||||||
inStream.funcTable.Read = MyRead;
|
|
||||||
inStream.file = inFile;
|
|
||||||
outStream.funcTable.Write = MyWrite;
|
|
||||||
outStream.file = outFile;
|
|
||||||
|
|
||||||
LzmaEncProps_Init(&props);
|
LzmaEncProps_Init(&props);
|
||||||
res = LzmaEnc_SetProps(enc, &props);
|
res = LzmaEnc_SetProps(enc, &props);
|
||||||
|
|
||||||
@@ -217,19 +150,18 @@ static SRes Encode(FILE *inFile, FILE *outFile, char *rs)
|
|||||||
{
|
{
|
||||||
Byte header[LZMA_PROPS_SIZE + 8];
|
Byte header[LZMA_PROPS_SIZE + 8];
|
||||||
size_t headerSize = LZMA_PROPS_SIZE;
|
size_t headerSize = LZMA_PROPS_SIZE;
|
||||||
UInt64 fileSize;
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
res = LzmaEnc_WriteProperties(enc, header, &headerSize);
|
res = LzmaEnc_WriteProperties(enc, header, &headerSize);
|
||||||
fileSize = MyGetFileLength(inFile);
|
|
||||||
for (i = 0; i < 8; i++)
|
for (i = 0; i < 8; i++)
|
||||||
header[headerSize++] = (Byte)(fileSize >> (8 * i));
|
header[headerSize++] = (Byte)(fileSize >> (8 * i));
|
||||||
if (!MyWriteFileAndCheck(outFile, header, headerSize))
|
if (outStream->Write(outStream, header, headerSize) != headerSize)
|
||||||
return PrintError(rs, "writing error");
|
res = SZ_ERROR_WRITE;
|
||||||
|
else
|
||||||
|
{
|
||||||
if (res == SZ_OK)
|
if (res == SZ_OK)
|
||||||
res = LzmaEnc_Encode(enc, &outStream.funcTable, &inStream.funcTable,
|
res = LzmaEnc_Encode(enc, outStream, inStream, NULL, &g_Alloc, &g_Alloc);
|
||||||
NULL, &g_Alloc, &g_Alloc);
|
}
|
||||||
}
|
}
|
||||||
LzmaEnc_Destroy(enc, &g_Alloc, &g_Alloc);
|
LzmaEnc_Destroy(enc, &g_Alloc, &g_Alloc);
|
||||||
return res;
|
return res;
|
||||||
@@ -237,11 +169,18 @@ static SRes Encode(FILE *inFile, FILE *outFile, char *rs)
|
|||||||
|
|
||||||
int main2(int numArgs, const char *args[], char *rs)
|
int main2(int numArgs, const char *args[], char *rs)
|
||||||
{
|
{
|
||||||
FILE *inFile = 0;
|
CFileSeqInStream inStream;
|
||||||
FILE *outFile = 0;
|
CFileOutStream outStream;
|
||||||
char c;
|
char c;
|
||||||
int res;
|
int res;
|
||||||
int encodeMode;
|
int encodeMode;
|
||||||
|
Bool useOutFile = False;
|
||||||
|
|
||||||
|
FileSeqInStream_CreateVTable(&inStream);
|
||||||
|
File_Construct(&inStream.file);
|
||||||
|
|
||||||
|
FileOutStream_CreateVTable(&outStream);
|
||||||
|
File_Construct(&outStream.file);
|
||||||
|
|
||||||
if (numArgs == 1)
|
if (numArgs == 1)
|
||||||
{
|
{
|
||||||
@@ -261,17 +200,16 @@ int main2(int numArgs, const char *args[], char *rs)
|
|||||||
size_t t4 = sizeof(UInt32);
|
size_t t4 = sizeof(UInt32);
|
||||||
size_t t8 = sizeof(UInt64);
|
size_t t8 = sizeof(UInt64);
|
||||||
if (t4 != 4 || t8 != 8)
|
if (t4 != 4 || t8 != 8)
|
||||||
return PrintError(rs, "LZMA UTil needs correct UInt32 and UInt64");
|
return PrintError(rs, "Incorrect UInt32 or UInt64");
|
||||||
}
|
}
|
||||||
|
|
||||||
inFile = fopen(args[2], "rb");
|
if (InFile_Open(&inStream.file, args[2]) != 0)
|
||||||
if (inFile == 0)
|
|
||||||
return PrintError(rs, "Can not open input file");
|
return PrintError(rs, "Can not open input file");
|
||||||
|
|
||||||
if (numArgs > 3)
|
if (numArgs > 3)
|
||||||
{
|
{
|
||||||
outFile = fopen(args[3], "wb+");
|
useOutFile = True;
|
||||||
if (outFile == 0)
|
if (OutFile_Open(&outStream.file, args[3]) != 0)
|
||||||
return PrintError(rs, "Can not open output file");
|
return PrintError(rs, "Can not open output file");
|
||||||
}
|
}
|
||||||
else if (encodeMode)
|
else if (encodeMode)
|
||||||
@@ -279,16 +217,18 @@ int main2(int numArgs, const char *args[], char *rs)
|
|||||||
|
|
||||||
if (encodeMode)
|
if (encodeMode)
|
||||||
{
|
{
|
||||||
res = Encode(inFile, outFile, rs);
|
UInt64 fileSize;
|
||||||
|
File_GetLength(&inStream.file, &fileSize);
|
||||||
|
res = Encode(&outStream.s, &inStream.s, fileSize, rs);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
res = Decode(inFile, outFile, rs);
|
res = Decode(&outStream.s, useOutFile ? &inStream.s : NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (outFile != 0)
|
if (useOutFile)
|
||||||
fclose(outFile);
|
File_Close(&outStream.file);
|
||||||
fclose(inFile);
|
File_Close(&inStream.file);
|
||||||
|
|
||||||
if (res != SZ_OK)
|
if (res != SZ_OK)
|
||||||
{
|
{
|
||||||
@@ -296,7 +236,10 @@ int main2(int numArgs, const char *args[], char *rs)
|
|||||||
return PrintError(rs, kCantAllocateMessage);
|
return PrintError(rs, kCantAllocateMessage);
|
||||||
else if (res == SZ_ERROR_DATA)
|
else if (res == SZ_ERROR_DATA)
|
||||||
return PrintError(rs, kDataErrorMessage);
|
return PrintError(rs, kDataErrorMessage);
|
||||||
else
|
else if (res == SZ_ERROR_WRITE)
|
||||||
|
return PrintError(rs, kCantWriteMessage);
|
||||||
|
else if (res == SZ_ERROR_READ)
|
||||||
|
return PrintError(rs, kCantReadMessage);
|
||||||
return PrintErrorNumber(rs, res);
|
return PrintErrorNumber(rs, res);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -86,6 +86,22 @@ LINK32=link.exe
|
|||||||
# Name "LzmaUtil - Win32 Debug"
|
# Name "LzmaUtil - Win32 Debug"
|
||||||
# Begin Source File
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\7zFile.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\7zFile.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\7zStream.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\7zVersion.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
SOURCE=..\Alloc.c
|
SOURCE=..\Alloc.c
|
||||||
# End Source File
|
# End Source File
|
||||||
# Begin Source File
|
# Begin Source File
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ C_OBJS = \
|
|||||||
$O\LzFindMt.obj \
|
$O\LzFindMt.obj \
|
||||||
$O\LzmaDec.obj \
|
$O\LzmaDec.obj \
|
||||||
$O\LzmaEnc.obj \
|
$O\LzmaEnc.obj \
|
||||||
|
$O\7zFile.obj \
|
||||||
|
$O\7zStream.obj \
|
||||||
$O\Threads.obj \
|
$O\Threads.obj \
|
||||||
|
|
||||||
OBJS = \
|
OBJS = \
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ OBJS = \
|
|||||||
LzFind.o \
|
LzFind.o \
|
||||||
LzmaDec.o \
|
LzmaDec.o \
|
||||||
LzmaEnc.o \
|
LzmaEnc.o \
|
||||||
|
7zFile.o \
|
||||||
|
7zStream.o \
|
||||||
|
|
||||||
|
|
||||||
all: $(PROG)
|
all: $(PROG)
|
||||||
@@ -32,5 +34,11 @@ LzmaDec.o: ../LzmaDec.c
|
|||||||
LzmaEnc.o: ../LzmaEnc.c
|
LzmaEnc.o: ../LzmaEnc.c
|
||||||
$(CXX) $(CFLAGS) ../LzmaEnc.c
|
$(CXX) $(CFLAGS) ../LzmaEnc.c
|
||||||
|
|
||||||
|
7zFile.o: ../7zFile.c
|
||||||
|
$(CXX) $(CFLAGS) ../7zFile.c
|
||||||
|
|
||||||
|
7zStream.o: ../7zStream.c
|
||||||
|
$(CXX) $(CFLAGS) ../7zStream.c
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
-$(RM) $(PROG) $(OBJS)
|
-$(RM) $(PROG) $(OBJS)
|
||||||
|
|||||||
+2
-4
@@ -1,8 +1,6 @@
|
|||||||
/* Crypto/Sha256.c -- SHA-256 Hash function
|
/* Crypto/Sha256.c -- SHA-256 Hash function
|
||||||
2008-08-05
|
2008-11-06 : Igor Pavlov : Public domain
|
||||||
This code is based on public domain code from Wei Dai's Crypto++ library.
|
This code is based on public domain code from Wei Dai's Crypto++ library. */
|
||||||
Igor Pavlov
|
|
||||||
Public domain */
|
|
||||||
|
|
||||||
#include "Sha256.h"
|
#include "Sha256.h"
|
||||||
#include "RotateDefs.h"
|
#include "RotateDefs.h"
|
||||||
|
|||||||
+1
-3
@@ -1,7 +1,5 @@
|
|||||||
/* Crypto/Sha256.h -- SHA-256 Hash function
|
/* Crypto/Sha256.h -- SHA-256 Hash function
|
||||||
2008-08-05
|
2008-10-04 : Igor Pavlov : Public domain */
|
||||||
Igor Pavlov
|
|
||||||
Public domain */
|
|
||||||
|
|
||||||
#ifndef __CRYPTO_SHA256_H
|
#ifndef __CRYPTO_SHA256_H
|
||||||
#define __CRYPTO_SHA256_H
|
#define __CRYPTO_SHA256_H
|
||||||
|
|||||||
+1
-7
@@ -1,13 +1,9 @@
|
|||||||
/* Threads.h -- multithreading library
|
/* Threads.h -- multithreading library
|
||||||
2008-04-11
|
2008-11-22 : Igor Pavlov : Public domain */
|
||||||
Igor Pavlov
|
|
||||||
Public domain */
|
|
||||||
|
|
||||||
#ifndef __7Z_THRESDS_H
|
#ifndef __7Z_THRESDS_H
|
||||||
#define __7Z_THRESDS_H
|
#define __7Z_THRESDS_H
|
||||||
|
|
||||||
#include <windows.h>
|
|
||||||
|
|
||||||
#include "Types.h"
|
#include "Types.h"
|
||||||
|
|
||||||
typedef struct _CThread
|
typedef struct _CThread
|
||||||
@@ -22,8 +18,6 @@ typedef unsigned THREAD_FUNC_RET_TYPE;
|
|||||||
#define THREAD_FUNC_CALL_TYPE MY_STD_CALL
|
#define THREAD_FUNC_CALL_TYPE MY_STD_CALL
|
||||||
#define THREAD_FUNC_DECL THREAD_FUNC_RET_TYPE THREAD_FUNC_CALL_TYPE
|
#define THREAD_FUNC_DECL THREAD_FUNC_RET_TYPE THREAD_FUNC_CALL_TYPE
|
||||||
|
|
||||||
typedef DWORD WRes;
|
|
||||||
|
|
||||||
WRes Thread_Create(CThread *thread, THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter);
|
WRes Thread_Create(CThread *thread, THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter);
|
||||||
WRes Thread_Wait(CThread *thread);
|
WRes Thread_Wait(CThread *thread);
|
||||||
WRes Thread_Close(CThread *thread);
|
WRes Thread_Close(CThread *thread);
|
||||||
|
|||||||
@@ -1,11 +1,15 @@
|
|||||||
/* Types.h -- Basic types
|
/* Types.h -- Basic types
|
||||||
2008-08-05
|
2008-11-23 : Igor Pavlov : Public domain */
|
||||||
Igor Pavlov
|
|
||||||
Public domain */
|
|
||||||
|
|
||||||
#ifndef __7Z_TYPES_H
|
#ifndef __7Z_TYPES_H
|
||||||
#define __7Z_TYPES_H
|
#define __7Z_TYPES_H
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include <windows.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#define SZ_OK 0
|
#define SZ_OK 0
|
||||||
|
|
||||||
#define SZ_ERROR_DATA 1
|
#define SZ_ERROR_DATA 1
|
||||||
@@ -26,6 +30,12 @@ Public domain */
|
|||||||
|
|
||||||
typedef int SRes;
|
typedef int SRes;
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
typedef DWORD WRes;
|
||||||
|
#else
|
||||||
|
typedef int WRes;
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef RINOK
|
#ifndef RINOK
|
||||||
#define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; }
|
#define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; }
|
||||||
#endif
|
#endif
|
||||||
@@ -42,11 +52,11 @@ typedef int Int32;
|
|||||||
typedef unsigned int UInt32;
|
typedef unsigned int UInt32;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* #define _SZ_NO_INT_64 */
|
|
||||||
/* define it if your compiler doesn't support 64-bit integers */
|
|
||||||
|
|
||||||
#ifdef _SZ_NO_INT_64
|
#ifdef _SZ_NO_INT_64
|
||||||
|
|
||||||
|
/* define _SZ_NO_INT_64, if your compiler doesn't support 64-bit integers.
|
||||||
|
NOTES: Some code will work incorrectly in that case! */
|
||||||
|
|
||||||
typedef long Int64;
|
typedef long Int64;
|
||||||
typedef unsigned long UInt64;
|
typedef unsigned long UInt64;
|
||||||
|
|
||||||
@@ -65,7 +75,6 @@ typedef unsigned long long int UInt64;
|
|||||||
#ifdef _LZMA_NO_SYSTEM_SIZE_T
|
#ifdef _LZMA_NO_SYSTEM_SIZE_T
|
||||||
typedef UInt32 SizeT;
|
typedef UInt32 SizeT;
|
||||||
#else
|
#else
|
||||||
#include <stddef.h>
|
|
||||||
typedef size_t SizeT;
|
typedef size_t SizeT;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -104,6 +113,11 @@ typedef struct
|
|||||||
(output(*size) < input(*size)) is allowed */
|
(output(*size) < input(*size)) is allowed */
|
||||||
} ISeqInStream;
|
} ISeqInStream;
|
||||||
|
|
||||||
|
/* it can return SZ_ERROR_INPUT_EOF */
|
||||||
|
SRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size);
|
||||||
|
SRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType);
|
||||||
|
SRes SeqInStream_ReadByte(ISeqInStream *stream, Byte *buf);
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
size_t (*Write)(void *p, const void *buf, size_t size);
|
size_t (*Write)(void *p, const void *buf, size_t size);
|
||||||
@@ -111,6 +125,70 @@ typedef struct
|
|||||||
(result < size) means error */
|
(result < size) means error */
|
||||||
} ISeqOutStream;
|
} ISeqOutStream;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
SZ_SEEK_SET = 0,
|
||||||
|
SZ_SEEK_CUR = 1,
|
||||||
|
SZ_SEEK_END = 2
|
||||||
|
} ESzSeek;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
SRes (*Read)(void *p, void *buf, size_t *size); /* same as ISeqInStream::Read */
|
||||||
|
SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);
|
||||||
|
} ISeekInStream;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
SRes (*Look)(void *p, void **buf, size_t *size);
|
||||||
|
/* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
|
||||||
|
(output(*size) > input(*size)) is not allowed
|
||||||
|
(output(*size) < input(*size)) is allowed */
|
||||||
|
SRes (*Skip)(void *p, size_t offset);
|
||||||
|
/* offset must be <= output(*size) of Look */
|
||||||
|
|
||||||
|
SRes (*Read)(void *p, void *buf, size_t *size);
|
||||||
|
/* reads directly (without buffer). It's same as ISeqInStream::Read */
|
||||||
|
SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);
|
||||||
|
} ILookInStream;
|
||||||
|
|
||||||
|
SRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size);
|
||||||
|
SRes LookInStream_SeekTo(ILookInStream *stream, UInt64 offset);
|
||||||
|
|
||||||
|
/* reads via ILookInStream::Read */
|
||||||
|
SRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType);
|
||||||
|
SRes LookInStream_Read(ILookInStream *stream, void *buf, size_t size);
|
||||||
|
|
||||||
|
#define LookToRead_BUF_SIZE (1 << 14)
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
ILookInStream s;
|
||||||
|
ISeekInStream *realStream;
|
||||||
|
size_t pos;
|
||||||
|
size_t size;
|
||||||
|
Byte buf[LookToRead_BUF_SIZE];
|
||||||
|
} CLookToRead;
|
||||||
|
|
||||||
|
void LookToRead_CreateVTable(CLookToRead *p, int lookahead);
|
||||||
|
void LookToRead_Init(CLookToRead *p);
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
ISeqInStream s;
|
||||||
|
ILookInStream *realStream;
|
||||||
|
} CSecToLook;
|
||||||
|
|
||||||
|
void SecToLook_CreateVTable(CSecToLook *p);
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
ISeqInStream s;
|
||||||
|
ILookInStream *realStream;
|
||||||
|
} CSecToRead;
|
||||||
|
|
||||||
|
void SecToRead_CreateVTable(CSecToRead *p);
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
SRes (*Progress)(void *p, UInt64 inSize, UInt64 outSize);
|
SRes (*Progress)(void *p, UInt64 inSize, UInt64 outSize);
|
||||||
|
|||||||
@@ -9,34 +9,6 @@
|
|||||||
namespace NArchive {
|
namespace NArchive {
|
||||||
namespace NCab {
|
namespace NCab {
|
||||||
|
|
||||||
/*
|
|
||||||
static HRESULT ReadBytes(IInStream *inStream, void *data, UInt32 size)
|
|
||||||
{
|
|
||||||
UInt32 realProcessedSize;
|
|
||||||
RINOK(ReadStream(inStream, data, size, &realProcessedSize));
|
|
||||||
if(realProcessedSize != size)
|
|
||||||
return S_FALSE;
|
|
||||||
return S_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
static HRESULT SafeRead(IInStream *inStream, void *data, UInt32 size)
|
|
||||||
{
|
|
||||||
UInt32 realProcessedSize;
|
|
||||||
RINOK(ReadStream(inStream, data, size, &realProcessedSize));
|
|
||||||
if(realProcessedSize != size)
|
|
||||||
throw CInArchiveException(CInArchiveException::kUnexpectedEndOfArchive);
|
|
||||||
return S_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void SafeInByteRead(::CInBuffer &inBuffer, void *data, UInt32 size)
|
|
||||||
{
|
|
||||||
UInt32 realProcessedSize;
|
|
||||||
inBuffer.ReadBytes(data, size, realProcessedSize);
|
|
||||||
if(realProcessedSize != size)
|
|
||||||
throw CInArchiveException(CInArchiveException::kUnexpectedEndOfArchive);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
Byte CInArchive::ReadByte()
|
Byte CInArchive::ReadByte()
|
||||||
{
|
{
|
||||||
Byte b;
|
Byte b;
|
||||||
@@ -107,43 +79,43 @@ HRESULT CInArchive::Open2(IInStream *stream,
|
|||||||
inBuffer.SetStream(stream);
|
inBuffer.SetStream(stream);
|
||||||
inBuffer.Init();
|
inBuffer.Init();
|
||||||
|
|
||||||
CInArchiveInfo &archiveInfo = database.ArchiveInfo;
|
CInArchiveInfo &ai = database.ArchiveInfo;
|
||||||
|
|
||||||
archiveInfo.Size = ReadUInt32(); // size of this cabinet file in bytes
|
ai.Size = ReadUInt32();
|
||||||
if (ReadUInt32() != 0)
|
if (ReadUInt32() != 0)
|
||||||
return S_FALSE;
|
return S_FALSE;
|
||||||
archiveInfo.FileHeadersOffset = ReadUInt32(); // offset of the first CFFILE entry
|
ai.FileHeadersOffset = ReadUInt32();
|
||||||
if (ReadUInt32() != 0)
|
if (ReadUInt32() != 0)
|
||||||
return S_FALSE;
|
return S_FALSE;
|
||||||
|
|
||||||
archiveInfo.VersionMinor = ReadByte(); // cabinet file format version, minor
|
ai.VersionMinor = ReadByte();
|
||||||
archiveInfo.VersionMajor = ReadByte(); // cabinet file format version, major
|
ai.VersionMajor = ReadByte();
|
||||||
archiveInfo.NumFolders = ReadUInt16(); // number of CFFOLDER entries in this cabinet
|
ai.NumFolders = ReadUInt16();
|
||||||
archiveInfo.NumFiles = ReadUInt16(); // number of CFFILE entries in this cabinet
|
ai.NumFiles = ReadUInt16();
|
||||||
archiveInfo.Flags = ReadUInt16();
|
ai.Flags = ReadUInt16();
|
||||||
if (archiveInfo.Flags > 7)
|
if (ai.Flags > 7)
|
||||||
return S_FALSE;
|
return S_FALSE;
|
||||||
archiveInfo.SetID = ReadUInt16(); // must be the same for all cabinets in a set
|
ai.SetID = ReadUInt16();
|
||||||
archiveInfo.CabinetNumber = ReadUInt16(); // number of this cabinet file in a set
|
ai.CabinetNumber = ReadUInt16();
|
||||||
|
|
||||||
if (archiveInfo.ReserveBlockPresent())
|
if (ai.ReserveBlockPresent())
|
||||||
{
|
{
|
||||||
archiveInfo.PerCabinetAreaSize = ReadUInt16(); // (optional) size of per-cabinet reserved area
|
ai.PerCabinetAreaSize = ReadUInt16();
|
||||||
archiveInfo.PerFolderAreaSize = ReadByte(); // (optional) size of per-folder reserved area
|
ai.PerFolderAreaSize = ReadByte();
|
||||||
archiveInfo.PerDataBlockAreaSize = ReadByte(); // (optional) size of per-datablock reserved area
|
ai.PerDataBlockAreaSize = ReadByte();
|
||||||
|
|
||||||
Skeep(archiveInfo.PerCabinetAreaSize);
|
Skeep(ai.PerCabinetAreaSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
if (archiveInfo.IsTherePrev())
|
if (ai.IsTherePrev())
|
||||||
ReadOtherArchive(archiveInfo.PreviousArchive);
|
ReadOtherArchive(ai.PreviousArchive);
|
||||||
if (archiveInfo.IsThereNext())
|
if (ai.IsThereNext())
|
||||||
ReadOtherArchive(archiveInfo.NextArchive);
|
ReadOtherArchive(ai.NextArchive);
|
||||||
}
|
}
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
for(i = 0; i < archiveInfo.NumFolders; i++)
|
for (i = 0; i < ai.NumFolders; i++)
|
||||||
{
|
{
|
||||||
CFolder folder;
|
CFolder folder;
|
||||||
|
|
||||||
@@ -152,15 +124,15 @@ HRESULT CInArchive::Open2(IInStream *stream,
|
|||||||
folder.CompressionTypeMajor = ReadByte();
|
folder.CompressionTypeMajor = ReadByte();
|
||||||
folder.CompressionTypeMinor = ReadByte();
|
folder.CompressionTypeMinor = ReadByte();
|
||||||
|
|
||||||
Skeep(archiveInfo.PerFolderAreaSize);
|
Skeep(ai.PerFolderAreaSize);
|
||||||
database.Folders.Add(folder);
|
database.Folders.Add(folder);
|
||||||
}
|
}
|
||||||
|
|
||||||
RINOK(stream->Seek(database.StartPosition + archiveInfo.FileHeadersOffset, STREAM_SEEK_SET, NULL));
|
RINOK(stream->Seek(database.StartPosition + ai.FileHeadersOffset, STREAM_SEEK_SET, NULL));
|
||||||
|
|
||||||
inBuffer.SetStream(stream);
|
inBuffer.SetStream(stream);
|
||||||
inBuffer.Init();
|
inBuffer.Init();
|
||||||
for(i = 0; i < archiveInfo.NumFiles; i++)
|
for (i = 0; i < ai.NumFiles; i++)
|
||||||
{
|
{
|
||||||
CItem item;
|
CItem item;
|
||||||
item.Size = ReadUInt32();
|
item.Size = ReadUInt32();
|
||||||
@@ -224,16 +196,10 @@ bool CMvDatabaseEx::AreItemsEqual(int i1, int i2)
|
|||||||
const CDatabaseEx &db2 = Volumes[p2->VolumeIndex];
|
const CDatabaseEx &db2 = Volumes[p2->VolumeIndex];
|
||||||
const CItem &item1 = db1.Items[p1->ItemIndex];
|
const CItem &item1 = db1.Items[p1->ItemIndex];
|
||||||
const CItem &item2 = db2.Items[p2->ItemIndex];;
|
const CItem &item2 = db2.Items[p2->ItemIndex];;
|
||||||
int f1 = GetFolderIndex(p1);
|
return GetFolderIndex(p1) == GetFolderIndex(p2) &&
|
||||||
int f2 = GetFolderIndex(p2);
|
item1.Offset == item2.Offset &&
|
||||||
if (f1 != f2)
|
item1.Size == item2.Size &&
|
||||||
return false;
|
item1.Name == item2.Name;
|
||||||
if (item1.Offset != item2.Offset)
|
|
||||||
return false;
|
|
||||||
if (item1.Size != item2.Size)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMvDatabaseEx::FillSortAndShrink()
|
void CMvDatabaseEx::FillSortAndShrink()
|
||||||
|
|||||||
@@ -346,10 +346,8 @@ HRESULT CInArchive::Open2()
|
|||||||
Clear();
|
Clear();
|
||||||
RINOK(_stream->Seek(kStartPos, STREAM_SEEK_CUR, &_position));
|
RINOK(_stream->Seek(kStartPos, STREAM_SEEK_CUR, &_position));
|
||||||
|
|
||||||
bool primVolDescDefined = false;
|
|
||||||
m_BufferPos = 0;
|
m_BufferPos = 0;
|
||||||
BlockSize = kBlockSize;
|
BlockSize = kBlockSize;
|
||||||
VolDescs.Add(CVolumeDescriptor());
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
Byte sig[7];
|
Byte sig[7];
|
||||||
@@ -396,42 +394,33 @@ HRESULT CInArchive::Open2()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case NVolDescType::kPrimaryVol:
|
case NVolDescType::kPrimaryVol:
|
||||||
{
|
|
||||||
if (primVolDescDefined)
|
|
||||||
return S_FALSE;
|
|
||||||
primVolDescDefined = true;
|
|
||||||
CVolumeDescriptor &volDesc = VolDescs[0];
|
|
||||||
ReadVolumeDescriptor(volDesc);
|
|
||||||
// some burners write "Joliet" Escape Sequence to primary volume
|
|
||||||
memset(volDesc.EscapeSequence, 0, sizeof(volDesc.EscapeSequence));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case NVolDescType::kSupplementaryVol:
|
case NVolDescType::kSupplementaryVol:
|
||||||
{
|
{
|
||||||
CVolumeDescriptor sd;
|
// some ISOs have two PrimaryVols.
|
||||||
ReadVolumeDescriptor(sd);
|
CVolumeDescriptor vd;
|
||||||
VolDescs.Add(sd);
|
ReadVolumeDescriptor(vd);
|
||||||
|
if (sig[0] == NVolDescType::kPrimaryVol)
|
||||||
|
{
|
||||||
|
// some burners write "Joliet" Escape Sequence to primary volume
|
||||||
|
memset(vd.EscapeSequence, 0, sizeof(vd.EscapeSequence));
|
||||||
|
}
|
||||||
|
VolDescs.Add(vd);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MainVolDescIndex = 0;
|
if (VolDescs.IsEmpty())
|
||||||
if (!primVolDescDefined)
|
|
||||||
return S_FALSE;
|
return S_FALSE;
|
||||||
for (int i = VolDescs.Size() - 1; i >= 0; i--)
|
for (MainVolDescIndex = VolDescs.Size() - 1; MainVolDescIndex > 0; MainVolDescIndex--)
|
||||||
{
|
if (VolDescs[MainVolDescIndex].IsJoliet())
|
||||||
if (VolDescs[i].IsJoliet())
|
|
||||||
{
|
|
||||||
MainVolDescIndex = i;
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
|
||||||
// MainVolDescIndex = 0; // to read primary volume
|
// MainVolDescIndex = 0; // to read primary volume
|
||||||
if (VolDescs[MainVolDescIndex].LogicalBlockSize != kBlockSize)
|
const CVolumeDescriptor &vd = VolDescs[MainVolDescIndex];
|
||||||
|
if (vd.LogicalBlockSize != kBlockSize)
|
||||||
return S_FALSE;
|
return S_FALSE;
|
||||||
(CDirRecord &)_rootDir = VolDescs[MainVolDescIndex].RootDirRecord;
|
(CDirRecord &)_rootDir = vd.RootDirRecord;
|
||||||
ReadDir(_rootDir, 0);
|
ReadDir(_rootDir, 0);
|
||||||
CreateRefs(_rootDir);
|
CreateRefs(_rootDir);
|
||||||
ReadBootInfo();
|
ReadBootInfo();
|
||||||
|
|||||||
@@ -264,6 +264,9 @@ struct CSection
|
|||||||
void Parse(const Byte *p);
|
void Parse(const Byte *p);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static bool operator <(const CSection &a1, const CSection &a2) { return (a1.Pa < a2.Pa); }
|
||||||
|
static bool operator ==(const CSection &a1, const CSection &a2) { return (a1.Pa == a2.Pa); }
|
||||||
|
|
||||||
static AString GetName(const Byte *name)
|
static AString GetName(const Byte *name)
|
||||||
{
|
{
|
||||||
const int kNameSize = 8;
|
const int kNameSize = 8;
|
||||||
@@ -726,6 +729,34 @@ HRESULT CHandler::Open2(IInStream *stream)
|
|||||||
if (fileSize > _totalSize)
|
if (fileSize > _totalSize)
|
||||||
return S_FALSE;
|
return S_FALSE;
|
||||||
_totalSizeLimited = (_totalSize < fileSize) ? _totalSize : (UInt32)fileSize;
|
_totalSizeLimited = (_totalSize < fileSize) ? _totalSize : (UInt32)fileSize;
|
||||||
|
|
||||||
|
{
|
||||||
|
CObjectVector<CSection> sections = _sections;
|
||||||
|
sections.Sort();
|
||||||
|
UInt32 limit = (1 << 12);
|
||||||
|
int num = 0;
|
||||||
|
for (int i = 0; i < sections.Size(); i++)
|
||||||
|
{
|
||||||
|
const CSection &s = sections[i];
|
||||||
|
if (s.Pa > limit)
|
||||||
|
{
|
||||||
|
CSection s2;
|
||||||
|
s2.Pa = s2.Va = limit;
|
||||||
|
s2.PSize = s2.VSize = s.Pa - limit;
|
||||||
|
char sz[32];
|
||||||
|
ConvertUInt64ToString(++num, sz);
|
||||||
|
s2.Name = "[data-";
|
||||||
|
s2.Name += sz;
|
||||||
|
s2.Name += "]";
|
||||||
|
_sections.Add(s2);
|
||||||
|
}
|
||||||
|
UInt32 next = s.Pa + s.PSize;
|
||||||
|
if (next < limit)
|
||||||
|
break;
|
||||||
|
limit = next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,9 +9,13 @@ extern "C"
|
|||||||
|
|
||||||
#include "Windows/PropVariant.h"
|
#include "Windows/PropVariant.h"
|
||||||
#include "Windows/Defs.h"
|
#include "Windows/Defs.h"
|
||||||
|
#include "../../MyVersion.h"
|
||||||
#include "../../ICoder.h"
|
#include "../../ICoder.h"
|
||||||
#include "../../IPassword.h"
|
#include "../../IPassword.h"
|
||||||
#include "../../Common/CreateCoder.h"
|
#include "../../Common/CreateCoder.h"
|
||||||
|
#include "../../Common/StreamObjects.h"
|
||||||
|
#include "../../Common/StreamUtils.h"
|
||||||
|
#include "../../Compress/LZMA/LZMAEncoder.h"
|
||||||
#include "../Common/InStreamWithCRC.h"
|
#include "../Common/InStreamWithCRC.h"
|
||||||
|
|
||||||
#include "ZipAddCommon.h"
|
#include "ZipAddCommon.h"
|
||||||
@@ -23,6 +27,54 @@ namespace NZip {
|
|||||||
static const CMethodId kMethodId_ZipBase = 0x040100;
|
static const CMethodId kMethodId_ZipBase = 0x040100;
|
||||||
static const CMethodId kMethodId_BZip2 = 0x040202;
|
static const CMethodId kMethodId_BZip2 = 0x040202;
|
||||||
|
|
||||||
|
static const UInt32 kLzmaPropsSize = 5;
|
||||||
|
static const UInt32 kLzmaHeaderSize = 4 + kLzmaPropsSize;
|
||||||
|
|
||||||
|
class CLzmaEncoder:
|
||||||
|
public ICompressCoder,
|
||||||
|
public CMyUnknownImp
|
||||||
|
{
|
||||||
|
NCompress::NLZMA::CEncoder *EncoderSpec;
|
||||||
|
CMyComPtr<ICompressCoder> Encoder;
|
||||||
|
Byte Header[kLzmaHeaderSize];
|
||||||
|
public:
|
||||||
|
STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,
|
||||||
|
const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
|
||||||
|
HRESULT CLzmaEncoder::SetCoderProperties(const PROPID *propIDs, const PROPVARIANT *props, UInt32 numProps);
|
||||||
|
|
||||||
|
MY_UNKNOWN_IMP
|
||||||
|
};
|
||||||
|
|
||||||
|
HRESULT CLzmaEncoder::SetCoderProperties(const PROPID *propIDs, const PROPVARIANT *props, UInt32 numProps)
|
||||||
|
{
|
||||||
|
if (!Encoder)
|
||||||
|
{
|
||||||
|
EncoderSpec = new NCompress::NLZMA::CEncoder;
|
||||||
|
Encoder = EncoderSpec;
|
||||||
|
}
|
||||||
|
CSequentialOutStreamImp *outStreamSpec = new CSequentialOutStreamImp;
|
||||||
|
CMyComPtr<ISequentialOutStream> outStream(outStreamSpec);
|
||||||
|
outStreamSpec->Init();
|
||||||
|
RINOK(EncoderSpec->SetCoderProperties(propIDs, props, numProps));
|
||||||
|
RINOK(EncoderSpec->WriteCoderProperties(outStream));
|
||||||
|
if (outStreamSpec->GetSize() != kLzmaPropsSize)
|
||||||
|
return E_FAIL;
|
||||||
|
Header[0] = MY_VER_MAJOR;
|
||||||
|
Header[1] = MY_VER_MINOR;
|
||||||
|
Header[2] = kLzmaPropsSize;
|
||||||
|
Header[3] = 0;
|
||||||
|
memcpy(Header + 4, outStreamSpec->GetBuffer(), kLzmaPropsSize);
|
||||||
|
return S_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
HRESULT CLzmaEncoder::Code(ISequentialInStream *inStream, ISequentialOutStream *outStream,
|
||||||
|
const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress)
|
||||||
|
{
|
||||||
|
RINOK(WriteStream(outStream, Header, kLzmaHeaderSize));
|
||||||
|
return Encoder->Code(inStream, outStream, inSize, outSize, progress);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
CAddCommon::CAddCommon(const CCompressionMethodMode &options):
|
CAddCommon::CAddCommon(const CCompressionMethodMode &options):
|
||||||
_options(options),
|
_options(options),
|
||||||
_copyCoderSpec(NULL),
|
_copyCoderSpec(NULL),
|
||||||
@@ -144,6 +196,39 @@ HRESULT CAddCommon::Compress(
|
|||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
if (!_compressEncoder)
|
if (!_compressEncoder)
|
||||||
|
{
|
||||||
|
if (method == NFileHeader::NCompressionMethod::kLZMA)
|
||||||
|
{
|
||||||
|
CLzmaEncoder *_lzmaEncoder = new CLzmaEncoder();
|
||||||
|
_compressEncoder = _lzmaEncoder;
|
||||||
|
NWindows::NCOM::CPropVariant props[] =
|
||||||
|
{
|
||||||
|
#ifdef COMPRESS_MT
|
||||||
|
_options.NumThreads,
|
||||||
|
#endif
|
||||||
|
_options.Algo,
|
||||||
|
_options.DicSize,
|
||||||
|
_options.NumFastBytes,
|
||||||
|
(BSTR)(const wchar_t *)_options.MatchFinder,
|
||||||
|
_options.NumMatchFinderCycles
|
||||||
|
};
|
||||||
|
PROPID propIDs[] =
|
||||||
|
{
|
||||||
|
#ifdef COMPRESS_MT
|
||||||
|
NCoderPropID::kNumThreads,
|
||||||
|
#endif
|
||||||
|
NCoderPropID::kAlgorithm,
|
||||||
|
NCoderPropID::kDictionarySize,
|
||||||
|
NCoderPropID::kNumFastBytes,
|
||||||
|
NCoderPropID::kMatchFinder,
|
||||||
|
NCoderPropID::kMatchFinderCycles
|
||||||
|
};
|
||||||
|
int numProps = sizeof(propIDs) / sizeof(propIDs[0]);
|
||||||
|
if (!_options.NumMatchFinderCyclesDefined)
|
||||||
|
numProps--;
|
||||||
|
RINOK(_lzmaEncoder->SetCoderProperties(propIDs, props, numProps));
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
CMethodId methodId;
|
CMethodId methodId;
|
||||||
switch(method)
|
switch(method)
|
||||||
@@ -164,7 +249,7 @@ HRESULT CAddCommon::Compress(
|
|||||||
if (method == NFileHeader::NCompressionMethod::kDeflated ||
|
if (method == NFileHeader::NCompressionMethod::kDeflated ||
|
||||||
method == NFileHeader::NCompressionMethod::kDeflated64)
|
method == NFileHeader::NCompressionMethod::kDeflated64)
|
||||||
{
|
{
|
||||||
NWindows::NCOM::CPropVariant properties[] =
|
NWindows::NCOM::CPropVariant props[] =
|
||||||
{
|
{
|
||||||
_options.Algo,
|
_options.Algo,
|
||||||
_options.NumPasses,
|
_options.NumPasses,
|
||||||
@@ -185,12 +270,12 @@ HRESULT CAddCommon::Compress(
|
|||||||
_compressEncoder.QueryInterface(IID_ICompressSetCoderProperties, &setCoderProperties);
|
_compressEncoder.QueryInterface(IID_ICompressSetCoderProperties, &setCoderProperties);
|
||||||
if (setCoderProperties)
|
if (setCoderProperties)
|
||||||
{
|
{
|
||||||
RINOK(setCoderProperties->SetCoderProperties(propIDs, properties, numProps));
|
RINOK(setCoderProperties->SetCoderProperties(propIDs, props, numProps));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (method == NFileHeader::NCompressionMethod::kBZip2)
|
else if (method == NFileHeader::NCompressionMethod::kBZip2)
|
||||||
{
|
{
|
||||||
NWindows::NCOM::CPropVariant properties[] =
|
NWindows::NCOM::CPropVariant props[] =
|
||||||
{
|
{
|
||||||
_options.DicSize,
|
_options.DicSize,
|
||||||
_options.NumPasses
|
_options.NumPasses
|
||||||
@@ -210,7 +295,8 @@ HRESULT CAddCommon::Compress(
|
|||||||
_compressEncoder.QueryInterface(IID_ICompressSetCoderProperties, &setCoderProperties);
|
_compressEncoder.QueryInterface(IID_ICompressSetCoderProperties, &setCoderProperties);
|
||||||
if (setCoderProperties)
|
if (setCoderProperties)
|
||||||
{
|
{
|
||||||
RINOK(setCoderProperties->SetCoderProperties(propIDs, properties, sizeof(propIDs) / sizeof(propIDs[0])));
|
RINOK(setCoderProperties->SetCoderProperties(propIDs, props, sizeof(propIDs) / sizeof(propIDs[0])));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ namespace NZip {
|
|||||||
struct CCompressionMethodMode
|
struct CCompressionMethodMode
|
||||||
{
|
{
|
||||||
CRecordVector<Byte> MethodSequence;
|
CRecordVector<Byte> MethodSequence;
|
||||||
// bool MaximizeRatio;
|
UString MatchFinder;
|
||||||
UInt32 Algo;
|
UInt32 Algo;
|
||||||
UInt32 NumPasses;
|
UInt32 NumPasses;
|
||||||
UInt32 NumFastBytes;
|
UInt32 NumFastBytes;
|
||||||
|
|||||||
@@ -16,10 +16,12 @@
|
|||||||
|
|
||||||
#include "../../Common/ProgressUtils.h"
|
#include "../../Common/ProgressUtils.h"
|
||||||
#include "../../Common/StreamObjects.h"
|
#include "../../Common/StreamObjects.h"
|
||||||
|
#include "../../Common/StreamUtils.h"
|
||||||
#include "../../Common/CreateCoder.h"
|
#include "../../Common/CreateCoder.h"
|
||||||
#include "../../Common/FilterCoder.h"
|
#include "../../Common/FilterCoder.h"
|
||||||
|
|
||||||
#include "../../Compress/Copy/CopyCoder.h"
|
#include "../../Compress/Copy/CopyCoder.h"
|
||||||
|
#include "../../Compress/LZMA/LZMADecoder.h"
|
||||||
|
|
||||||
#include "../Common/ItemNameUtils.h"
|
#include "../Common/ItemNameUtils.h"
|
||||||
#include "../Common/OutStreamWithCRC.h"
|
#include "../Common/OutStreamWithCRC.h"
|
||||||
@@ -108,13 +110,13 @@ const wchar_t *kMethods[] =
|
|||||||
L"Tokenizing",
|
L"Tokenizing",
|
||||||
L"Deflate",
|
L"Deflate",
|
||||||
L"Deflate64",
|
L"Deflate64",
|
||||||
L"PKImploding",
|
L"PKImploding"
|
||||||
L"Unknown",
|
|
||||||
L"BZip2"
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const int kNumMethods = sizeof(kMethods) / sizeof(kMethods[0]);
|
const int kNumMethods = sizeof(kMethods) / sizeof(kMethods[0]);
|
||||||
// const wchar_t *kUnknownMethod = L"Unknown";
|
const wchar_t *kBZip2Method = L"BZip2";
|
||||||
|
const wchar_t *kLZMAMethod = L"LZMA";
|
||||||
|
const wchar_t *kJpegMethod = L"Jpeg";
|
||||||
const wchar_t *kWavPackMethod = L"WavPack";
|
const wchar_t *kWavPackMethod = L"WavPack";
|
||||||
const wchar_t *kPPMdMethod = L"PPMd";
|
const wchar_t *kPPMdMethod = L"PPMd";
|
||||||
const wchar_t *kAESMethod = L"AES";
|
const wchar_t *kAESMethod = L"AES";
|
||||||
@@ -294,16 +296,24 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
|
|||||||
}
|
}
|
||||||
if (methodId < kNumMethods)
|
if (methodId < kNumMethods)
|
||||||
method += kMethods[methodId];
|
method += kMethods[methodId];
|
||||||
else if (methodId == NFileHeader::NCompressionMethod::kPPMd)
|
else switch (methodId)
|
||||||
method += kPPMdMethod;
|
{
|
||||||
else if (methodId == NFileHeader::NCompressionMethod::kWavPack)
|
case NFileHeader::NCompressionMethod::kLZMA:
|
||||||
method += kWavPackMethod;
|
method += kLZMAMethod;
|
||||||
else
|
if (item.IsLzmaEOS())
|
||||||
|
method += L":EOS";
|
||||||
|
break;
|
||||||
|
case NFileHeader::NCompressionMethod::kBZip2: method += kBZip2Method; break;
|
||||||
|
case NFileHeader::NCompressionMethod::kJpeg: method += kJpegMethod; break;
|
||||||
|
case NFileHeader::NCompressionMethod::kWavPack: method += kWavPackMethod; break;
|
||||||
|
case NFileHeader::NCompressionMethod::kPPMd: method += kPPMdMethod; break;
|
||||||
|
default:
|
||||||
{
|
{
|
||||||
wchar_t s[32];
|
wchar_t s[32];
|
||||||
ConvertUInt64ToString(methodId, s);
|
ConvertUInt64ToString(methodId, s);
|
||||||
method += s;
|
method += s;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
prop = method;
|
prop = method;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -367,6 +377,37 @@ STDMETHODIMP CHandler::Close()
|
|||||||
//////////////////////////////////////
|
//////////////////////////////////////
|
||||||
// CHandler::DecompressItems
|
// CHandler::DecompressItems
|
||||||
|
|
||||||
|
class CLzmaDecoder:
|
||||||
|
public ICompressCoder,
|
||||||
|
public CMyUnknownImp
|
||||||
|
{
|
||||||
|
NCompress::NLZMA::CDecoder *DecoderSpec;
|
||||||
|
CMyComPtr<ICompressCoder> Decoder;
|
||||||
|
public:
|
||||||
|
CLzmaDecoder();
|
||||||
|
STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,
|
||||||
|
const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
|
||||||
|
|
||||||
|
MY_UNKNOWN_IMP
|
||||||
|
};
|
||||||
|
|
||||||
|
CLzmaDecoder::CLzmaDecoder()
|
||||||
|
{
|
||||||
|
DecoderSpec = new NCompress::NLZMA::CDecoder;
|
||||||
|
Decoder = DecoderSpec;
|
||||||
|
}
|
||||||
|
|
||||||
|
HRESULT CLzmaDecoder::Code(ISequentialInStream *inStream, ISequentialOutStream *outStream,
|
||||||
|
const UInt64 * /* inSize */, const UInt64 *outSize, ICompressProgressInfo *progress)
|
||||||
|
{
|
||||||
|
Byte buf[9];
|
||||||
|
RINOK(ReadStream_FALSE(inStream, buf, 9));
|
||||||
|
if (buf[2] != 5 || buf[3] != 0)
|
||||||
|
return E_NOTIMPL;
|
||||||
|
RINOK(DecoderSpec->SetDecoderProperties2(buf + 4, 5));
|
||||||
|
return Decoder->Code(inStream, outStream, NULL, outSize, progress);
|
||||||
|
}
|
||||||
|
|
||||||
struct CMethodItem
|
struct CMethodItem
|
||||||
{
|
{
|
||||||
UInt16 ZipMethod;
|
UInt16 ZipMethod;
|
||||||
@@ -568,6 +609,8 @@ HRESULT CZipDecoder::Decode(
|
|||||||
mi.Coder = new NCompress::NShrink::CDecoder;
|
mi.Coder = new NCompress::NShrink::CDecoder;
|
||||||
else if (methodId == NFileHeader::NCompressionMethod::kImploded)
|
else if (methodId == NFileHeader::NCompressionMethod::kImploded)
|
||||||
mi.Coder = new NCompress::NImplode::NDecoder::CCoder;
|
mi.Coder = new NCompress::NImplode::NDecoder::CCoder;
|
||||||
|
else if (methodId == NFileHeader::NCompressionMethod::kLZMA)
|
||||||
|
mi.Coder = new CLzmaDecoder;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
CMethodId szMethodID;
|
CMethodId szMethodID;
|
||||||
@@ -656,6 +699,12 @@ HRESULT CZipDecoder::Decode(
|
|||||||
result = coder->Code(inStreamNew, outStream, NULL, &item.UnPackSize, compressProgress);
|
result = coder->Code(inStreamNew, outStream, NULL, &item.UnPackSize, compressProgress);
|
||||||
if (result == S_FALSE)
|
if (result == S_FALSE)
|
||||||
return S_OK;
|
return S_OK;
|
||||||
|
if (result == E_NOTIMPL)
|
||||||
|
{
|
||||||
|
res = NArchive::NExtract::NOperationResult::kUnSupportedMethod;
|
||||||
|
return S_OK;
|
||||||
|
}
|
||||||
|
|
||||||
RINOK(result);
|
RINOK(result);
|
||||||
}
|
}
|
||||||
bool crcOK = true;
|
bool crcOK = true;
|
||||||
|
|||||||
@@ -25,16 +25,28 @@ using namespace NTime;
|
|||||||
namespace NArchive {
|
namespace NArchive {
|
||||||
namespace NZip {
|
namespace NZip {
|
||||||
|
|
||||||
static const UInt32 kDeflateAlgoX1 = 0;
|
static const UInt32 kLzAlgoX1 = 0;
|
||||||
static const UInt32 kDeflateAlgoX5 = 1;
|
static const UInt32 kLzAlgoX5 = 1;
|
||||||
|
|
||||||
static const UInt32 kDeflateNumPassesX1 = 1;
|
static const UInt32 kDeflateNumPassesX1 = 1;
|
||||||
static const UInt32 kDeflateNumPassesX7 = 3;
|
static const UInt32 kDeflateNumPassesX7 = 3;
|
||||||
static const UInt32 kDeflateNumPassesX9 = 10;
|
static const UInt32 kDeflateNumPassesX9 = 10;
|
||||||
|
|
||||||
static const UInt32 kNumFastBytesX1 = 32;
|
static const UInt32 kDeflateNumFastBytesX1 = 32;
|
||||||
static const UInt32 kNumFastBytesX7 = 64;
|
static const UInt32 kDeflateNumFastBytesX7 = 64;
|
||||||
static const UInt32 kNumFastBytesX9 = 128;
|
static const UInt32 kDeflateNumFastBytesX9 = 128;
|
||||||
|
|
||||||
|
static const wchar_t *kLzmaMatchFinderX1 = L"HC4";
|
||||||
|
static const wchar_t *kLzmaMatchFinderX5 = L"BT4";
|
||||||
|
|
||||||
|
static const UInt32 kLzmaNumFastBytesX1 = 32;
|
||||||
|
static const UInt32 kLzmaNumFastBytesX7 = 64;
|
||||||
|
|
||||||
|
static const UInt32 kLzmaDicSizeX1 = 1 << 16;
|
||||||
|
static const UInt32 kLzmaDicSizeX3 = 1 << 20;
|
||||||
|
static const UInt32 kLzmaDicSizeX5 = 1 << 24;
|
||||||
|
static const UInt32 kLzmaDicSizeX7 = 1 << 25;
|
||||||
|
static const UInt32 kLzmaDicSizeX9 = 1 << 26;
|
||||||
|
|
||||||
static const UInt32 kBZip2NumPassesX1 = 1;
|
static const UInt32 kBZip2NumPassesX1 = 1;
|
||||||
static const UInt32 kBZip2NumPassesX7 = 2;
|
static const UInt32 kBZip2NumPassesX7 = 2;
|
||||||
@@ -173,24 +185,20 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numIt
|
|||||||
{
|
{
|
||||||
bool defaultCharWasUsed;
|
bool defaultCharWasUsed;
|
||||||
ui.Name = UnicodeStringToMultiByte(name, CP_OEMCP, '_', defaultCharWasUsed);
|
ui.Name = UnicodeStringToMultiByte(name, CP_OEMCP, '_', defaultCharWasUsed);
|
||||||
tryUtf8 = (!m_ForseLocal && defaultCharWasUsed);
|
tryUtf8 = (!m_ForseLocal && (defaultCharWasUsed ||
|
||||||
|
MultiByteToUnicodeString(ui.Name, CP_OEMCP) != name));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tryUtf8)
|
if (tryUtf8)
|
||||||
{
|
{
|
||||||
bool needUtf = false;
|
int i;
|
||||||
for (int i = 0; i < name.Length(); i++)
|
for (i = 0; i < name.Length() && (unsigned)name[i] < 0x80; i++);
|
||||||
if ((unsigned)name[i] >= 0x80)
|
ui.IsUtf8 = (i != name.Length());
|
||||||
{
|
|
||||||
needUtf = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
ui.IsUtf8 = needUtf;
|
|
||||||
if (!ConvertUnicodeToUTF8(name, ui.Name))
|
if (!ConvertUnicodeToUTF8(name, ui.Name))
|
||||||
return E_INVALIDARG;
|
return E_INVALIDARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ui.Name.Length() > 0xFFFF)
|
if (ui.Name.Length() >= (1 << 16))
|
||||||
return E_INVALIDARG;
|
return E_INVALIDARG;
|
||||||
|
|
||||||
ui.IndexInClient = i;
|
ui.IndexInClient = i;
|
||||||
@@ -272,6 +280,8 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numIt
|
|||||||
options.MethodSequence.Add(NFileHeader::NCompressionMethod::kStored);
|
options.MethodSequence.Add(NFileHeader::NCompressionMethod::kStored);
|
||||||
bool isDeflate = (mainMethod == NFileHeader::NCompressionMethod::kDeflated) ||
|
bool isDeflate = (mainMethod == NFileHeader::NCompressionMethod::kDeflated) ||
|
||||||
(mainMethod == NFileHeader::NCompressionMethod::kDeflated64);
|
(mainMethod == NFileHeader::NCompressionMethod::kDeflated64);
|
||||||
|
bool isLZMA = (mainMethod == NFileHeader::NCompressionMethod::kLZMA);
|
||||||
|
bool isLz = (isLZMA || isDeflate);
|
||||||
bool isBZip2 = (mainMethod == NFileHeader::NCompressionMethod::kBZip2);
|
bool isBZip2 = (mainMethod == NFileHeader::NCompressionMethod::kBZip2);
|
||||||
options.NumPasses = m_NumPasses;
|
options.NumPasses = m_NumPasses;
|
||||||
options.DicSize = m_DicSize;
|
options.DicSize = m_DicSize;
|
||||||
@@ -282,6 +292,8 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numIt
|
|||||||
#ifdef COMPRESS_MT
|
#ifdef COMPRESS_MT
|
||||||
options.NumThreads = _numThreads;
|
options.NumThreads = _numThreads;
|
||||||
#endif
|
#endif
|
||||||
|
if (isLz)
|
||||||
|
{
|
||||||
if (isDeflate)
|
if (isDeflate)
|
||||||
{
|
{
|
||||||
if (options.NumPasses == 0xFFFFFFFF)
|
if (options.NumPasses == 0xFFFFFFFF)
|
||||||
@@ -289,13 +301,32 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numIt
|
|||||||
(level >= 7 ? kDeflateNumPassesX7 :
|
(level >= 7 ? kDeflateNumPassesX7 :
|
||||||
kDeflateNumPassesX1));
|
kDeflateNumPassesX1));
|
||||||
if (options.NumFastBytes == 0xFFFFFFFF)
|
if (options.NumFastBytes == 0xFFFFFFFF)
|
||||||
options.NumFastBytes = (level >= 9 ? kNumFastBytesX9 :
|
options.NumFastBytes = (level >= 9 ? kDeflateNumFastBytesX9 :
|
||||||
(level >= 7 ? kNumFastBytesX7 :
|
(level >= 7 ? kDeflateNumFastBytesX7 :
|
||||||
kNumFastBytesX1));
|
kDeflateNumFastBytesX1));
|
||||||
|
}
|
||||||
|
else if (isLZMA)
|
||||||
|
{
|
||||||
|
if (options.DicSize == 0xFFFFFFFF)
|
||||||
|
options.DicSize =
|
||||||
|
(level >= 9 ? kLzmaDicSizeX9 :
|
||||||
|
(level >= 7 ? kLzmaDicSizeX7 :
|
||||||
|
(level >= 5 ? kLzmaDicSizeX5 :
|
||||||
|
(level >= 3 ? kLzmaDicSizeX3 :
|
||||||
|
kLzmaDicSizeX1))));
|
||||||
|
|
||||||
|
if (options.NumFastBytes == 0xFFFFFFFF)
|
||||||
|
options.NumFastBytes = (level >= 7 ? kLzmaNumFastBytesX7 :
|
||||||
|
kLzmaNumFastBytesX1);
|
||||||
|
|
||||||
|
options.MatchFinder =
|
||||||
|
(level >= 5 ? kLzmaMatchFinderX5 :
|
||||||
|
kLzmaMatchFinderX1);
|
||||||
|
}
|
||||||
|
|
||||||
if (options.Algo == 0xFFFFFFFF)
|
if (options.Algo == 0xFFFFFFFF)
|
||||||
options.Algo =
|
options.Algo = (level >= 5 ? kLzAlgoX5 :
|
||||||
(level >= 5 ? kDeflateAlgoX5 :
|
kLzAlgoX1);
|
||||||
kDeflateAlgoX1);
|
|
||||||
}
|
}
|
||||||
if (isBZip2)
|
if (isBZip2)
|
||||||
{
|
{
|
||||||
@@ -343,18 +374,14 @@ STDMETHODIMP CHandler::SetProperties(const wchar_t **names, const PROPVARIANT *v
|
|||||||
{
|
{
|
||||||
if (prop.vt == VT_BSTR)
|
if (prop.vt == VT_BSTR)
|
||||||
{
|
{
|
||||||
UString valueString = prop.bstrVal;
|
UString m = prop.bstrVal;
|
||||||
valueString.MakeUpper();
|
m.MakeUpper();
|
||||||
if (valueString == L"COPY")
|
if (m == L"COPY") m_MainMethod = NFileHeader::NCompressionMethod::kStored;
|
||||||
m_MainMethod = NFileHeader::NCompressionMethod::kStored;
|
else if (m == L"DEFLATE") m_MainMethod = NFileHeader::NCompressionMethod::kDeflated;
|
||||||
else if (valueString == L"DEFLATE")
|
else if (m == L"DEFLATE64") m_MainMethod = NFileHeader::NCompressionMethod::kDeflated64;
|
||||||
m_MainMethod = NFileHeader::NCompressionMethod::kDeflated;
|
else if (m == L"BZIP2") m_MainMethod = NFileHeader::NCompressionMethod::kBZip2;
|
||||||
else if (valueString == L"DEFLATE64")
|
else if (m == L"LZMA") m_MainMethod = NFileHeader::NCompressionMethod::kLZMA;
|
||||||
m_MainMethod = NFileHeader::NCompressionMethod::kDeflated64;
|
else return E_INVALIDARG;
|
||||||
else if (valueString == L"BZIP2")
|
|
||||||
m_MainMethod = NFileHeader::NCompressionMethod::kBZip2;
|
|
||||||
else
|
|
||||||
return E_INVALIDARG;
|
|
||||||
}
|
}
|
||||||
else if (prop.vt == VT_UI4)
|
else if (prop.vt == VT_UI4)
|
||||||
{
|
{
|
||||||
@@ -364,6 +391,7 @@ STDMETHODIMP CHandler::SetProperties(const wchar_t **names, const PROPVARIANT *v
|
|||||||
case NFileHeader::NCompressionMethod::kDeflated:
|
case NFileHeader::NCompressionMethod::kDeflated:
|
||||||
case NFileHeader::NCompressionMethod::kDeflated64:
|
case NFileHeader::NCompressionMethod::kDeflated64:
|
||||||
case NFileHeader::NCompressionMethod::kBZip2:
|
case NFileHeader::NCompressionMethod::kBZip2:
|
||||||
|
case NFileHeader::NCompressionMethod::kLZMA:
|
||||||
m_MainMethod = (Byte)prop.ulVal;
|
m_MainMethod = (Byte)prop.ulVal;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -414,7 +442,7 @@ STDMETHODIMP CHandler::SetProperties(const wchar_t **names, const PROPVARIANT *v
|
|||||||
}
|
}
|
||||||
else if (name.Left(2) == L"FB")
|
else if (name.Left(2) == L"FB")
|
||||||
{
|
{
|
||||||
UInt32 num = kNumFastBytesX9;
|
UInt32 num = kDeflateNumFastBytesX9;
|
||||||
RINOK(ParsePropValue(name.Mid(2), prop, num));
|
RINOK(ParsePropValue(name.Mid(2), prop, num));
|
||||||
m_NumFastBytes = num;
|
m_NumFastBytes = num;
|
||||||
}
|
}
|
||||||
@@ -433,25 +461,25 @@ STDMETHODIMP CHandler::SetProperties(const wchar_t **names, const PROPVARIANT *v
|
|||||||
}
|
}
|
||||||
else if (name.Left(1) == L"A")
|
else if (name.Left(1) == L"A")
|
||||||
{
|
{
|
||||||
UInt32 num = kDeflateAlgoX5;
|
UInt32 num = kLzAlgoX5;
|
||||||
RINOK(ParsePropValue(name.Mid(1), prop, num));
|
RINOK(ParsePropValue(name.Mid(1), prop, num));
|
||||||
m_Algo = num;
|
m_Algo = num;
|
||||||
}
|
}
|
||||||
else if (name.CompareNoCase(L"TC") == 0)
|
else if (name.CompareNoCase(L"TC") == 0)
|
||||||
return SetBoolProperty(m_WriteNtfsTimeExtra, prop);
|
{
|
||||||
|
RINOK(SetBoolProperty(m_WriteNtfsTimeExtra, prop));
|
||||||
|
}
|
||||||
else if (name.CompareNoCase(L"CL") == 0)
|
else if (name.CompareNoCase(L"CL") == 0)
|
||||||
{
|
{
|
||||||
RINOK(SetBoolProperty(m_ForseLocal, prop));
|
RINOK(SetBoolProperty(m_ForseLocal, prop));
|
||||||
if (m_ForseLocal)
|
if (m_ForseLocal)
|
||||||
m_ForseUtf8 = false;
|
m_ForseUtf8 = false;
|
||||||
return S_OK;
|
|
||||||
}
|
}
|
||||||
else if (name.CompareNoCase(L"CU") == 0)
|
else if (name.CompareNoCase(L"CU") == 0)
|
||||||
{
|
{
|
||||||
RINOK(SetBoolProperty(m_ForseUtf8, prop));
|
RINOK(SetBoolProperty(m_ForseUtf8, prop));
|
||||||
if (m_ForseUtf8)
|
if (m_ForseUtf8)
|
||||||
m_ForseLocal = false;
|
m_ForseLocal = false;
|
||||||
return S_OK;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return E_INVALIDARG;
|
return E_INVALIDARG;
|
||||||
|
|||||||
@@ -69,6 +69,10 @@ namespace NFileHeader
|
|||||||
kPKImploding = 10,
|
kPKImploding = 10,
|
||||||
|
|
||||||
kBZip2 = 12,
|
kBZip2 = 12,
|
||||||
|
kLZMA = 14,
|
||||||
|
kTerse = 18,
|
||||||
|
kLz77 = 19,
|
||||||
|
kJpeg = 0x60,
|
||||||
kWavPack = 0x61,
|
kWavPack = 0x61,
|
||||||
kPPMd = 0x62,
|
kPPMd = 0x62,
|
||||||
kWzAES = 0x63
|
kWzAES = 0x63
|
||||||
@@ -170,6 +174,7 @@ namespace NFileHeader
|
|||||||
namespace NFlags
|
namespace NFlags
|
||||||
{
|
{
|
||||||
const int kEncrypted = 1 << 0;
|
const int kEncrypted = 1 << 0;
|
||||||
|
const int kLzmaEOS = 1 << 1;
|
||||||
const int kDescriptorUsedMask = 1 << 3;
|
const int kDescriptorUsedMask = 1 << 3;
|
||||||
const int kStrongEncrypted = 1 << 6;
|
const int kStrongEncrypted = 1 << 6;
|
||||||
const int kUtf8 = 1 << 11;
|
const int kUtf8 = 1 << 11;
|
||||||
|
|||||||
@@ -51,20 +51,6 @@ bool CExtraSubBlock::ExtractNtfsTime(int index, FILETIME &ft) const
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CLocalItem::IsImplodeBigDictionary() const
|
|
||||||
{
|
|
||||||
if (CompressionMethod != NFileHeader::NCompressionMethod::kImploded)
|
|
||||||
throw 12312212;
|
|
||||||
return (Flags & NFileHeader::NFlags::kImplodeDictionarySizeMask) != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CLocalItem::IsImplodeLiteralsOn() const
|
|
||||||
{
|
|
||||||
if (CompressionMethod != NFileHeader::NCompressionMethod::kImploded)
|
|
||||||
throw 12312213;
|
|
||||||
return (Flags & NFileHeader::NFlags::kImplodeLiteralsOnMask) != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CLocalItem::IsDir() const
|
bool CLocalItem::IsDir() const
|
||||||
{
|
{
|
||||||
return NItemName::HasTailSlash(Name, GetCodePage());
|
return NItemName::HasTailSlash(Name, GetCodePage());
|
||||||
|
|||||||
@@ -188,8 +188,7 @@ public:
|
|||||||
bool IsEncrypted() const { return (Flags & NFileHeader::NFlags::kEncrypted) != 0; }
|
bool IsEncrypted() const { return (Flags & NFileHeader::NFlags::kEncrypted) != 0; }
|
||||||
bool IsStrongEncrypted() const { return IsEncrypted() && (Flags & NFileHeader::NFlags::kStrongEncrypted) != 0; };
|
bool IsStrongEncrypted() const { return IsEncrypted() && (Flags & NFileHeader::NFlags::kStrongEncrypted) != 0; };
|
||||||
|
|
||||||
bool IsImplodeBigDictionary() const;
|
bool IsLzmaEOS() const { return (Flags & NFileHeader::NFlags::kLzmaEOS) != 0; }
|
||||||
bool IsImplodeLiteralsOn() const;
|
|
||||||
|
|
||||||
bool IsDir() const;
|
bool IsDir() const;
|
||||||
bool IgnoreItem() const { return false; }
|
bool IgnoreItem() const { return false; }
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// ZipUpdate.cpp
|
lzma// ZipUpdate.cpp
|
||||||
|
|
||||||
#include "StdAfx.h"
|
#include "StdAfx.h"
|
||||||
|
|
||||||
@@ -568,6 +568,14 @@ static HRESULT Update2(
|
|||||||
if (numThreads <= 1)
|
if (numThreads <= 1)
|
||||||
mtMode = false;
|
mtMode = false;
|
||||||
}
|
}
|
||||||
|
if (method == NFileHeader::NCompressionMethod::kLZMA)
|
||||||
|
{
|
||||||
|
UInt32 numLZMAThreads = (options->Algo > 0 ? 2 : 1);
|
||||||
|
numThreads /= numLZMAThreads;
|
||||||
|
options2.NumThreads = numLZMAThreads;
|
||||||
|
if (numThreads <= 1)
|
||||||
|
mtMode = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mtMode)
|
if (!mtMode)
|
||||||
|
|||||||
@@ -5,27 +5,30 @@
|
|||||||
#include "Common/MyInitGuid.h"
|
#include "Common/MyInitGuid.h"
|
||||||
|
|
||||||
#include "Common/CommandLineParser.h"
|
#include "Common/CommandLineParser.h"
|
||||||
#include "Common/StdOutStream.h"
|
|
||||||
#include "Common/Wildcard.h"
|
|
||||||
#include "Common/StringConvert.h"
|
|
||||||
#include "Common/MyCom.h"
|
#include "Common/MyCom.h"
|
||||||
#include "Common/MyException.h"
|
#include "Common/MyException.h"
|
||||||
|
#include "Common/StdOutStream.h"
|
||||||
|
#include "Common/StringConvert.h"
|
||||||
|
#include "Common/Wildcard.h"
|
||||||
|
|
||||||
#include "Windows/FileDir.h"
|
|
||||||
#include "Windows/FileName.h"
|
|
||||||
#include "Windows/Defs.h"
|
#include "Windows/Defs.h"
|
||||||
|
#include "Windows/FileName.h"
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include "Windows/DLL.h"
|
||||||
|
#include "Windows/FileDir.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "../../IPassword.h"
|
#include "../../IPassword.h"
|
||||||
#include "../../ICoder.h"
|
#include "../../ICoder.h"
|
||||||
|
|
||||||
#include "../../UI/Common/OpenArchive.h"
|
|
||||||
#include "../../UI/Common/DefaultName.h"
|
#include "../../UI/Common/DefaultName.h"
|
||||||
#include "../../UI/Common/ExitCode.h"
|
#include "../../UI/Common/ExitCode.h"
|
||||||
#include "../../UI/Common/Extract.h"
|
#include "../../UI/Common/Extract.h"
|
||||||
|
#include "../../UI/Common/OpenArchive.h"
|
||||||
|
|
||||||
|
#include "../../UI/Console/ExtractCallbackConsole.h"
|
||||||
#include "../../UI/Console/List.h"
|
#include "../../UI/Console/List.h"
|
||||||
#include "../../UI/Console/OpenCallbackConsole.h"
|
#include "../../UI/Console/OpenCallbackConsole.h"
|
||||||
#include "../../UI/Console/ExtractCallbackConsole.h"
|
|
||||||
|
|
||||||
#include "../../MyVersion.h"
|
#include "../../MyVersion.h"
|
||||||
|
|
||||||
@@ -40,11 +43,6 @@ static const char *kCopyrightString =
|
|||||||
|
|
||||||
static const int kNumSwitches = 6;
|
static const int kNumSwitches = 6;
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
static const wchar_t *kDefaultExt = L".exe";
|
|
||||||
static const int kDefaultExtLength = 4;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace NKey {
|
namespace NKey {
|
||||||
enum Enum
|
enum Enum
|
||||||
{
|
{
|
||||||
@@ -271,7 +269,25 @@ int Main2(
|
|||||||
GetArguments(numArguments, arguments, commandStrings);
|
GetArguments(numArguments, arguments, commandStrings);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
UString archiveName = commandStrings.Front();
|
#ifdef _WIN32
|
||||||
|
|
||||||
|
UString arcPath;
|
||||||
|
{
|
||||||
|
UString path;
|
||||||
|
NDLL::MyGetModuleFileName(NULL, path);
|
||||||
|
int fileNamePartStartIndex;
|
||||||
|
if (!NDirectory::MyGetFullPathName(path, arcPath, fileNamePartStartIndex))
|
||||||
|
{
|
||||||
|
g_StdOut << "GetFullPathName Error";
|
||||||
|
return NExitCode::kFatalError;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
UString arcPath = commandStrings.Front();
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
commandStrings.Delete(0);
|
commandStrings.Delete(0);
|
||||||
|
|
||||||
@@ -318,11 +334,6 @@ int Main2(
|
|||||||
|
|
||||||
bool yesToAll = parser[NKey::kYes].ThereIs;
|
bool yesToAll = parser[NKey::kYes].ThereIs;
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
if (archiveName.Right(kDefaultExtLength).CompareNoCase(kDefaultExt) != 0)
|
|
||||||
archiveName += kDefaultExt;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// NExtractMode::EEnum extractMode;
|
// NExtractMode::EEnum extractMode;
|
||||||
// bool isExtractGroupCommand = command.IsFromExtractGroup(extractMode);
|
// bool isExtractGroupCommand = command.IsFromExtractGroup(extractMode);
|
||||||
|
|
||||||
@@ -333,7 +344,7 @@ int Main2(
|
|||||||
password = parser[NKey::kPassword].PostStrings[0];
|
password = parser[NKey::kPassword].PostStrings[0];
|
||||||
|
|
||||||
NFind::CFileInfoW archiveFileInfo;
|
NFind::CFileInfoW archiveFileInfo;
|
||||||
if (!NFind::FindFile(archiveName, archiveFileInfo))
|
if (!NFind::FindFile(arcPath, archiveFileInfo))
|
||||||
throw kCantFindSFX;
|
throw kCantFindSFX;
|
||||||
if (archiveFileInfo.IsDir())
|
if (archiveFileInfo.IsDir())
|
||||||
throw kCantFindSFX;
|
throw kCantFindSFX;
|
||||||
@@ -347,8 +358,8 @@ int Main2(
|
|||||||
|
|
||||||
{
|
{
|
||||||
UStringVector v1, v2;
|
UStringVector v1, v2;
|
||||||
v1.Add(archiveName);
|
v1.Add(arcPath);
|
||||||
v2.Add(archiveName);
|
v2.Add(arcPath);
|
||||||
const NWildcard::CCensorNode &wildcardCensorHead =
|
const NWildcard::CCensorNode &wildcardCensorHead =
|
||||||
wildcardCensor.Pairs.Front().Head;
|
wildcardCensor.Pairs.Front().Head;
|
||||||
|
|
||||||
|
|||||||
@@ -381,6 +381,14 @@ SOURCE=..\..\Crypto\Hash\RotateDefs.h
|
|||||||
# PROP Default_Filter ""
|
# PROP Default_Filter ""
|
||||||
# Begin Source File
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\..\..\Windows\DLL.cpp
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\..\..\Windows\DLL.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
SOURCE=..\..\..\Windows\Error.cpp
|
SOURCE=..\..\..\Windows\Error.cpp
|
||||||
# End Source File
|
# End Source File
|
||||||
# Begin Source File
|
# Begin Source File
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ COMMON_OBJS = \
|
|||||||
$O\Wildcard.obj \
|
$O\Wildcard.obj \
|
||||||
|
|
||||||
WIN_OBJS = \
|
WIN_OBJS = \
|
||||||
|
$O\DLL.obj \
|
||||||
$O\Error.obj \
|
$O\Error.obj \
|
||||||
$O\FileDir.obj \
|
$O\FileDir.obj \
|
||||||
$O\FileFind.obj \
|
$O\FileFind.obj \
|
||||||
|
|||||||
@@ -106,8 +106,6 @@ STDMETHODIMP CExtractCallbackImp::GetStream(UInt32 index,
|
|||||||
}
|
}
|
||||||
_filePath = fullPath;
|
_filePath = fullPath;
|
||||||
|
|
||||||
// m_CurrentFilePath = GetSystemString(fullPath, _codePage);
|
|
||||||
|
|
||||||
if (askExtractMode == NArchive::NExtract::NAskMode::kExtract)
|
if (askExtractMode == NArchive::NExtract::NAskMode::kExtract)
|
||||||
{
|
{
|
||||||
NCOM::CPropVariant prop;
|
NCOM::CPropVariant prop;
|
||||||
@@ -135,14 +133,9 @@ STDMETHODIMP CExtractCallbackImp::GetStream(UInt32 index,
|
|||||||
RINOK(_archiveHandler->GetProperty(index, kpidMTime, &prop));
|
RINOK(_archiveHandler->GetProperty(index, kpidMTime, &prop));
|
||||||
switch(prop.vt)
|
switch(prop.vt)
|
||||||
{
|
{
|
||||||
case VT_EMPTY:
|
case VT_EMPTY: _processedFileInfo.MTime = _defaultMTime; break;
|
||||||
_processedFileInfo.MTime = _defaultMTime;
|
case VT_FILETIME: _processedFileInfo.MTime = prop.filetime; break;
|
||||||
break;
|
default: return E_FAIL;
|
||||||
case VT_FILETIME:
|
|
||||||
_processedFileInfo.MTime = prop.filetime;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return E_FAIL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
UStringVector pathParts;
|
UStringVector pathParts;
|
||||||
@@ -168,6 +161,8 @@ STDMETHODIMP CExtractCallbackImp::GetStream(UInt32 index,
|
|||||||
|
|
||||||
if (isAnti)
|
if (isAnti)
|
||||||
NDirectory::MyRemoveDirectory(_diskFilePath);
|
NDirectory::MyRemoveDirectory(_diskFilePath);
|
||||||
|
else
|
||||||
|
NDirectory::SetDirTime(_diskFilePath, NULL, NULL, &_processedFileInfo.MTime);
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -204,13 +199,7 @@ STDMETHODIMP CExtractCallbackImp::GetStream(UInt32 index,
|
|||||||
|
|
||||||
STDMETHODIMP CExtractCallbackImp::PrepareOperation(Int32 askExtractMode)
|
STDMETHODIMP CExtractCallbackImp::PrepareOperation(Int32 askExtractMode)
|
||||||
{
|
{
|
||||||
_extractMode = false;
|
_extractMode = (askExtractMode == NArchive::NExtract::NAskMode::kExtract);
|
||||||
switch (askExtractMode)
|
|
||||||
{
|
|
||||||
case NArchive::NExtract::NAskMode::kExtract:
|
|
||||||
_extractMode = true;
|
|
||||||
break;
|
|
||||||
};
|
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ static HRESULT SResToHRESULT(SRes res)
|
|||||||
case SZ_OK: return S_OK;
|
case SZ_OK: return S_OK;
|
||||||
case SZ_ERROR_MEM: return E_OUTOFMEMORY;
|
case SZ_ERROR_MEM: return E_OUTOFMEMORY;
|
||||||
case SZ_ERROR_PARAM: return E_INVALIDARG;
|
case SZ_ERROR_PARAM: return E_INVALIDARG;
|
||||||
|
case SZ_ERROR_UNSUPPORTED: return E_NOTIMPL;
|
||||||
// case SZ_ERROR_PROGRESS: return E_ABORT;
|
// case SZ_ERROR_PROGRESS: return E_ABORT;
|
||||||
case SZ_ERROR_DATA: return S_FALSE;
|
case SZ_ERROR_DATA: return S_FALSE;
|
||||||
}
|
}
|
||||||
@@ -29,7 +30,7 @@ namespace NLZMA {
|
|||||||
|
|
||||||
static const UInt32 kInBufSize = 1 << 20;
|
static const UInt32 kInBufSize = 1 << 20;
|
||||||
|
|
||||||
CDecoder::CDecoder(): _inBuf(0), _outSizeDefined(false)
|
CDecoder::CDecoder(): _inBuf(0), _outSizeDefined(false), FinishStream(false)
|
||||||
{
|
{
|
||||||
LzmaDec_Construct(&_state);
|
LzmaDec_Construct(&_state);
|
||||||
}
|
}
|
||||||
@@ -104,10 +105,8 @@ STDMETHODIMP CDecoder::Code(ISequentialInStream *inStream,
|
|||||||
if (rem < curSize)
|
if (rem < curSize)
|
||||||
{
|
{
|
||||||
curSize = (SizeT)rem;
|
curSize = (SizeT)rem;
|
||||||
/*
|
if (FinishStream)
|
||||||
// finishMode = LZMA_FINISH_END;
|
finishMode = LZMA_FINISH_END;
|
||||||
we can't use LZMA_FINISH_END here to allow partial decoding
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -65,6 +65,8 @@ public:
|
|||||||
STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
|
STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
bool FinishStream;
|
||||||
|
|
||||||
CDecoder();
|
CDecoder();
|
||||||
virtual ~CDecoder();
|
virtual ~CDecoder();
|
||||||
|
|
||||||
|
|||||||
@@ -179,42 +179,6 @@ SOURCE=..\LZMA\LZMAEncoder.cpp
|
|||||||
SOURCE=..\LZMA\LZMAEncoder.h
|
SOURCE=..\LZMA\LZMAEncoder.h
|
||||||
# End Source File
|
# End Source File
|
||||||
# End Group
|
# End Group
|
||||||
# Begin Group "RangeCoder"
|
|
||||||
|
|
||||||
# PROP Default_Filter ""
|
|
||||||
# Begin Source File
|
|
||||||
|
|
||||||
SOURCE=..\RangeCoder\RangeCoder.h
|
|
||||||
# End Source File
|
|
||||||
# Begin Source File
|
|
||||||
|
|
||||||
SOURCE=..\RangeCoder\RangeCoderBit.cpp
|
|
||||||
# End Source File
|
|
||||||
# Begin Source File
|
|
||||||
|
|
||||||
SOURCE=..\RangeCoder\RangeCoderBit.h
|
|
||||||
# End Source File
|
|
||||||
# Begin Source File
|
|
||||||
|
|
||||||
SOURCE=..\RangeCoder\RangeCoderBitTree.h
|
|
||||||
# End Source File
|
|
||||||
# Begin Source File
|
|
||||||
|
|
||||||
SOURCE=..\RangeCoder\RangeCoderOpt.h
|
|
||||||
# End Source File
|
|
||||||
# End Group
|
|
||||||
# Begin Group "LZ"
|
|
||||||
|
|
||||||
# PROP Default_Filter ""
|
|
||||||
# Begin Source File
|
|
||||||
|
|
||||||
SOURCE=..\LZ\LZOutWindow.cpp
|
|
||||||
# End Source File
|
|
||||||
# Begin Source File
|
|
||||||
|
|
||||||
SOURCE=..\LZ\LZOutWindow.h
|
|
||||||
# End Source File
|
|
||||||
# End Group
|
|
||||||
# End Group
|
# End Group
|
||||||
# Begin Group "Windows"
|
# Begin Group "Windows"
|
||||||
|
|
||||||
|
|||||||
@@ -31,11 +31,9 @@
|
|||||||
#include "../../../Windows/System.h"
|
#include "../../../Windows/System.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "../../MyVersion.h"
|
|
||||||
|
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
|
#include "../../../../C/7zVersion.h"
|
||||||
#include "../../../../C/Alloc.h"
|
#include "../../../../C/Alloc.h"
|
||||||
#include "../../../../C/LzmaUtil/Lzma86Dec.h"
|
#include "../../../../C/LzmaUtil/Lzma86Dec.h"
|
||||||
#include "../../../../C/LzmaUtil/Lzma86Enc.h"
|
#include "../../../../C/LzmaUtil/Lzma86Enc.h"
|
||||||
@@ -64,13 +62,13 @@ enum Enum
|
|||||||
{
|
{
|
||||||
kHelp1 = 0,
|
kHelp1 = 0,
|
||||||
kHelp2,
|
kHelp2,
|
||||||
kMode,
|
kAlgo,
|
||||||
kDictionary,
|
kDict,
|
||||||
kFastBytes,
|
kFb,
|
||||||
kMatchFinderCycles,
|
kMc,
|
||||||
kLitContext,
|
kLc,
|
||||||
kLitPos,
|
kLp,
|
||||||
kPosBits,
|
kPb,
|
||||||
kMatchFinder,
|
kMatchFinder,
|
||||||
kMultiThread,
|
kMultiThread,
|
||||||
kEOS,
|
kEOS,
|
||||||
@@ -109,7 +107,7 @@ static void PrintHelp()
|
|||||||
" b: Benchmark\n"
|
" b: Benchmark\n"
|
||||||
"<Switches>\n"
|
"<Switches>\n"
|
||||||
" -a{N}: set compression mode - [0, 1], default: 1 (max)\n"
|
" -a{N}: set compression mode - [0, 1], default: 1 (max)\n"
|
||||||
" -d{N}: set dictionary - [12, 30], default: 23 (8MB)\n"
|
" -d{N}: set dictionary size - [12, 30], default: 23 (8MB)\n"
|
||||||
" -fb{N}: set number of fast bytes - [5, 273], default: 128\n"
|
" -fb{N}: set number of fast bytes - [5, 273], default: 128\n"
|
||||||
" -mc{N}: set number of cycles for match finder\n"
|
" -mc{N}: set number of cycles for match finder\n"
|
||||||
" -lc{N}: set number of literal context bits - [0, 8], default: 3\n"
|
" -lc{N}: set number of literal context bits - [0, 8], default: 3\n"
|
||||||
@@ -157,6 +155,13 @@ static bool GetNumber(const wchar_t *s, UInt32 &value)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void ParseUInt32(const CParser &parser, int index, UInt32 &res)
|
||||||
|
{
|
||||||
|
if (parser[index].ThereIs)
|
||||||
|
if (!GetNumber(parser[index].PostStrings[0], res))
|
||||||
|
IncorrectCommand();
|
||||||
|
}
|
||||||
|
|
||||||
int main2(int n, const char *args[])
|
int main2(int n, const char *args[])
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
@@ -202,15 +207,15 @@ int main2(int n, const char *args[])
|
|||||||
IncorrectCommand();
|
IncorrectCommand();
|
||||||
const UString &command = nonSwitchStrings[paramIndex++];
|
const UString &command = nonSwitchStrings[paramIndex++];
|
||||||
|
|
||||||
bool dictionaryIsDefined = false;
|
bool dictDefined = false;
|
||||||
UInt32 dictionary = (UInt32)-1;
|
UInt32 dict = (UInt32)-1;
|
||||||
if(parser[NKey::kDictionary].ThereIs)
|
if(parser[NKey::kDict].ThereIs)
|
||||||
{
|
{
|
||||||
UInt32 dicLog;
|
UInt32 dicLog;
|
||||||
if (!GetNumber(parser[NKey::kDictionary].PostStrings[0], dicLog))
|
if (!GetNumber(parser[NKey::kDict].PostStrings[0], dicLog))
|
||||||
IncorrectCommand();
|
IncorrectCommand();
|
||||||
dictionary = 1 << dicLog;
|
dict = 1 << dicLog;
|
||||||
dictionaryIsDefined = true;
|
dictDefined = true;
|
||||||
}
|
}
|
||||||
UString mf = L"BT4";
|
UString mf = L"BT4";
|
||||||
if (parser[NKey::kMatchFinder].ThereIs)
|
if (parser[NKey::kMatchFinder].ThereIs)
|
||||||
@@ -240,7 +245,7 @@ int main2(int n, const char *args[])
|
|||||||
if (!GetNumber(nonSwitchStrings[paramIndex++], numIterations))
|
if (!GetNumber(nonSwitchStrings[paramIndex++], numIterations))
|
||||||
numIterations = kNumDefaultItereations;
|
numIterations = kNumDefaultItereations;
|
||||||
}
|
}
|
||||||
return LzmaBenchCon(stderr, numIterations, numThreads, dictionary);
|
return LzmaBenchCon(stderr, numIterations, numThreads, dict);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (numThreads == (UInt32)-1)
|
if (numThreads == (UInt32)-1)
|
||||||
@@ -334,10 +339,10 @@ int main2(int n, const char *args[])
|
|||||||
if (outBuffer == 0)
|
if (outBuffer == 0)
|
||||||
throw kCantAllocate;
|
throw kCantAllocate;
|
||||||
}
|
}
|
||||||
if (!dictionaryIsDefined)
|
if (!dictDefined)
|
||||||
dictionary = 1 << 23;
|
dict = 1 << 23;
|
||||||
int res = Lzma86_Encode(outBuffer, &outSize, inBuffer, inSize,
|
int res = Lzma86_Encode(outBuffer, &outSize, inBuffer, inSize,
|
||||||
5, dictionary, parser[NKey::kFilter86].PostCharIndex == 0 ? SZ_FILTER_YES : SZ_FILTER_AUTO);
|
5, dict, parser[NKey::kFilter86].PostCharIndex == 0 ? SZ_FILTER_YES : SZ_FILTER_AUTO);
|
||||||
if (res != 0)
|
if (res != 0)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "\nEncoder error = %d\n", (int)res);
|
fprintf(stderr, "\nEncoder error = %d\n", (int)res);
|
||||||
@@ -378,40 +383,28 @@ int main2(int n, const char *args[])
|
|||||||
NCompress::NLZMA::CEncoder *encoderSpec = new NCompress::NLZMA::CEncoder;
|
NCompress::NLZMA::CEncoder *encoderSpec = new NCompress::NLZMA::CEncoder;
|
||||||
CMyComPtr<ICompressCoder> encoder = encoderSpec;
|
CMyComPtr<ICompressCoder> encoder = encoderSpec;
|
||||||
|
|
||||||
if (!dictionaryIsDefined)
|
if (!dictDefined)
|
||||||
dictionary = 1 << 23;
|
dict = 1 << 23;
|
||||||
|
|
||||||
UInt32 posStateBits = 2;
|
UInt32 pb = 2;
|
||||||
UInt32 litContextBits = 3; // for normal files
|
UInt32 lc = 3; // = 0; for 32-bit data
|
||||||
// UInt32 litContextBits = 0; // for 32-bit data
|
UInt32 lp = 0; // = 2; for 32-bit data
|
||||||
UInt32 litPosBits = 0;
|
UInt32 algo = 1;
|
||||||
// UInt32 litPosBits = 2; // for 32-bit data
|
UInt32 fb = 128;
|
||||||
UInt32 algorithm = 1;
|
UInt32 mc = 16 + fb / 2;
|
||||||
UInt32 numFastBytes = 128;
|
bool mcDefined = false;
|
||||||
UInt32 matchFinderCycles = 16 + numFastBytes / 2;
|
|
||||||
bool matchFinderCyclesDefined = false;
|
|
||||||
|
|
||||||
bool eos = parser[NKey::kEOS].ThereIs || stdInMode;
|
bool eos = parser[NKey::kEOS].ThereIs || stdInMode;
|
||||||
|
|
||||||
if(parser[NKey::kMode].ThereIs)
|
ParseUInt32(parser, NKey::kAlgo, algo);
|
||||||
if (!GetNumber(parser[NKey::kMode].PostStrings[0], algorithm))
|
ParseUInt32(parser, NKey::kFb, fb);
|
||||||
IncorrectCommand();
|
ParseUInt32(parser, NKey::kLc, lc);
|
||||||
|
ParseUInt32(parser, NKey::kLp, lp);
|
||||||
|
ParseUInt32(parser, NKey::kPb, pb);
|
||||||
|
|
||||||
if(parser[NKey::kFastBytes].ThereIs)
|
mcDefined = parser[NKey::kMc].ThereIs;
|
||||||
if (!GetNumber(parser[NKey::kFastBytes].PostStrings[0], numFastBytes))
|
if (mcDefined)
|
||||||
IncorrectCommand();
|
if (!GetNumber(parser[NKey::kMc].PostStrings[0], mc))
|
||||||
matchFinderCyclesDefined = parser[NKey::kMatchFinderCycles].ThereIs;
|
|
||||||
if (matchFinderCyclesDefined)
|
|
||||||
if (!GetNumber(parser[NKey::kMatchFinderCycles].PostStrings[0], matchFinderCycles))
|
|
||||||
IncorrectCommand();
|
|
||||||
if(parser[NKey::kLitContext].ThereIs)
|
|
||||||
if (!GetNumber(parser[NKey::kLitContext].PostStrings[0], litContextBits))
|
|
||||||
IncorrectCommand();
|
|
||||||
if(parser[NKey::kLitPos].ThereIs)
|
|
||||||
if (!GetNumber(parser[NKey::kLitPos].PostStrings[0], litPosBits))
|
|
||||||
IncorrectCommand();
|
|
||||||
if(parser[NKey::kPosBits].ThereIs)
|
|
||||||
if (!GetNumber(parser[NKey::kPosBits].PostStrings[0], posStateBits))
|
|
||||||
IncorrectCommand();
|
IncorrectCommand();
|
||||||
|
|
||||||
PROPID propIDs[] =
|
PROPID propIDs[] =
|
||||||
@@ -429,35 +422,35 @@ int main2(int n, const char *args[])
|
|||||||
};
|
};
|
||||||
const int kNumPropsMax = sizeof(propIDs) / sizeof(propIDs[0]);
|
const int kNumPropsMax = sizeof(propIDs) / sizeof(propIDs[0]);
|
||||||
|
|
||||||
PROPVARIANT properties[kNumPropsMax];
|
PROPVARIANT props[kNumPropsMax];
|
||||||
for (int p = 0; p < 6; p++)
|
for (int p = 0; p < 6; p++)
|
||||||
properties[p].vt = VT_UI4;
|
props[p].vt = VT_UI4;
|
||||||
|
|
||||||
properties[0].ulVal = (UInt32)dictionary;
|
props[0].ulVal = (UInt32)dict;
|
||||||
properties[1].ulVal = (UInt32)posStateBits;
|
props[1].ulVal = (UInt32)pb;
|
||||||
properties[2].ulVal = (UInt32)litContextBits;
|
props[2].ulVal = (UInt32)lc;
|
||||||
properties[3].ulVal = (UInt32)litPosBits;
|
props[3].ulVal = (UInt32)lp;
|
||||||
properties[4].ulVal = (UInt32)algorithm;
|
props[4].ulVal = (UInt32)algo;
|
||||||
properties[5].ulVal = (UInt32)numFastBytes;
|
props[5].ulVal = (UInt32)fb;
|
||||||
|
|
||||||
properties[6].vt = VT_BSTR;
|
props[6].vt = VT_BSTR;
|
||||||
properties[6].bstrVal = (BSTR)(const wchar_t *)mf;
|
props[6].bstrVal = (BSTR)(const wchar_t *)mf;
|
||||||
|
|
||||||
properties[7].vt = VT_BOOL;
|
props[7].vt = VT_BOOL;
|
||||||
properties[7].boolVal = eos ? VARIANT_TRUE : VARIANT_FALSE;
|
props[7].boolVal = eos ? VARIANT_TRUE : VARIANT_FALSE;
|
||||||
|
|
||||||
properties[8].vt = VT_UI4;
|
props[8].vt = VT_UI4;
|
||||||
properties[8].ulVal = (UInt32)numThreads;
|
props[8].ulVal = (UInt32)numThreads;
|
||||||
|
|
||||||
// it must be last in property list
|
// it must be last in property list
|
||||||
properties[9].vt = VT_UI4;
|
props[9].vt = VT_UI4;
|
||||||
properties[9].ulVal = (UInt32)matchFinderCycles;
|
props[9].ulVal = (UInt32)mc;
|
||||||
|
|
||||||
int numProps = kNumPropsMax;
|
int numProps = kNumPropsMax;
|
||||||
if (!matchFinderCyclesDefined)
|
if (!mcDefined)
|
||||||
numProps--;
|
numProps--;
|
||||||
|
|
||||||
if (encoderSpec->SetCoderProperties(propIDs, properties, numProps) != S_OK)
|
if (encoderSpec->SetCoderProperties(propIDs, props, numProps) != S_OK)
|
||||||
IncorrectCommand();
|
IncorrectCommand();
|
||||||
encoderSpec->WriteCoderProperties(outStream);
|
encoderSpec->WriteCoderProperties(outStream);
|
||||||
|
|
||||||
@@ -491,6 +484,7 @@ int main2(int n, const char *args[])
|
|||||||
{
|
{
|
||||||
NCompress::NLZMA::CDecoder *decoderSpec = new NCompress::NLZMA::CDecoder;
|
NCompress::NLZMA::CDecoder *decoderSpec = new NCompress::NLZMA::CDecoder;
|
||||||
CMyComPtr<ICompressCoder> decoder = decoderSpec;
|
CMyComPtr<ICompressCoder> decoder = decoderSpec;
|
||||||
|
decoderSpec->FinishStream = true;
|
||||||
const UInt32 kPropertiesSize = 5;
|
const UInt32 kPropertiesSize = 5;
|
||||||
Byte header[kPropertiesSize + 8];
|
Byte header[kPropertiesSize + 8];
|
||||||
if (ReadStream_FALSE(inStream, header, kPropertiesSize + 8) != S_OK)
|
if (ReadStream_FALSE(inStream, header, kPropertiesSize + 8) != S_OK)
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
#define MY_VER_MAJOR 4
|
#define MY_VER_MAJOR 4
|
||||||
#define MY_VER_MINOR 60
|
#define MY_VER_MINOR 61
|
||||||
#define MY_VER_BUILD 0
|
#define MY_VER_BUILD 0
|
||||||
#define MY_VERSION " 4.60 beta"
|
#define MY_VERSION "4.61 beta"
|
||||||
#define MY_7ZIP_VERSION "7-Zip 4.60 beta"
|
#define MY_7ZIP_VERSION "7-Zip 4.61 beta"
|
||||||
#define MY_DATE "2008-08-19"
|
#define MY_DATE "2008-11-23"
|
||||||
#define MY_COPYRIGHT "Copyright (c) 1999-2008 Igor Pavlov"
|
#define MY_COPYRIGHT "Copyright (c) 1999-2008 Igor Pavlov"
|
||||||
#define MY_VERSION_COPYRIGHT_DATE MY_VERSION " " MY_COPYRIGHT " " MY_DATE
|
#define MY_VERSION_COPYRIGHT_DATE MY_VERSION " " MY_COPYRIGHT " " MY_DATE
|
||||||
|
|||||||
@@ -4,8 +4,6 @@
|
|||||||
|
|
||||||
#include "DefaultName.h"
|
#include "DefaultName.h"
|
||||||
|
|
||||||
static const wchar_t *kEmptyFileAlias = L"[Content]";
|
|
||||||
|
|
||||||
static UString GetDefaultName3(const UString &fileName,
|
static UString GetDefaultName3(const UString &fileName,
|
||||||
const UString &extension, const UString &addSubExtension)
|
const UString &extension, const UString &addSubExtension)
|
||||||
{
|
{
|
||||||
@@ -21,7 +19,11 @@ static UString GetDefaultName3(const UString &fileName,
|
|||||||
int dotPos = fileName.ReverseFind(L'.');
|
int dotPos = fileName.ReverseFind(L'.');
|
||||||
if (dotPos > 0)
|
if (dotPos > 0)
|
||||||
return fileName.Left(dotPos) + addSubExtension;
|
return fileName.Left(dotPos) + addSubExtension;
|
||||||
return kEmptyFileAlias;
|
|
||||||
|
if (addSubExtension.IsEmpty())
|
||||||
|
return fileName + L"~";
|
||||||
|
else
|
||||||
|
return fileName + addSubExtension;
|
||||||
}
|
}
|
||||||
|
|
||||||
UString GetDefaultName2(const UString &fileName,
|
UString GetDefaultName2(const UString &fileName,
|
||||||
|
|||||||
@@ -39,25 +39,23 @@ static int MyCompareTime(NFileTimeType::EEnum fileTimeType, const FILETIME &time
|
|||||||
}
|
}
|
||||||
|
|
||||||
static const wchar_t *kDuplicateFileNameMessage = L"Duplicate filename:";
|
static const wchar_t *kDuplicateFileNameMessage = L"Duplicate filename:";
|
||||||
|
static const wchar_t *kNotCensoredCollisionMessaged = L"Internal file name collision (file on disk, file in archive):";
|
||||||
|
|
||||||
/*
|
static void ThrowError(const UString &message, const UString &s1, const UString &s2)
|
||||||
static const char *kNotCensoredCollisionMessaged = "Internal file name collision:\n";
|
{
|
||||||
static const char *kSameTimeChangedSizeCollisionMessaged =
|
UString m = message;
|
||||||
"Collision between files with same date/time and different sizes:\n";
|
m += L'\n';
|
||||||
*/
|
m += s1;
|
||||||
|
m += L'\n';
|
||||||
|
m += s2;
|
||||||
|
throw m;
|
||||||
|
}
|
||||||
|
|
||||||
static void TestDuplicateString(const UStringVector &strings, const CIntVector &indices)
|
static void TestDuplicateString(const UStringVector &strings, const CIntVector &indices)
|
||||||
{
|
{
|
||||||
for(int i = 0; i + 1 < indices.Size(); i++)
|
for(int i = 0; i + 1 < indices.Size(); i++)
|
||||||
if (CompareFileNames(strings[indices[i]], strings[indices[i + 1]]) == 0)
|
if (CompareFileNames(strings[indices[i]], strings[indices[i + 1]]) == 0)
|
||||||
{
|
ThrowError(kDuplicateFileNameMessage, strings[indices[i]], strings[indices[i + 1]]);
|
||||||
UString message = kDuplicateFileNameMessage;
|
|
||||||
message += L"\n";
|
|
||||||
message += strings[indices[i]];
|
|
||||||
message += L"\n";
|
|
||||||
message += strings[indices[i + 1]];
|
|
||||||
throw message;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GetUpdatePairInfoList(
|
void GetUpdatePairInfoList(
|
||||||
@@ -116,7 +114,7 @@ void GetUpdatePairInfoList(
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!ai.Censored)
|
if (!ai.Censored)
|
||||||
throw 1082022;
|
ThrowError(kNotCensoredCollisionMessaged, dirNames[dirIndex2], ai.Name);
|
||||||
pair.DirIndex = dirIndex2;
|
pair.DirIndex = dirIndex2;
|
||||||
pair.ArcIndex = arcIndex2;
|
pair.ArcIndex = arcIndex2;
|
||||||
switch (MyCompareTime(
|
switch (MyCompareTime(
|
||||||
|
|||||||
@@ -164,6 +164,8 @@ static const wchar_t *kStartExtensions[] =
|
|||||||
L"docx", L"docm", L"dotx", L"dotm", L"xlsx", L"xlsm", L"xltx", L"xltm", L"xlsb",
|
L"docx", L"docm", L"dotx", L"dotm", L"xlsx", L"xlsm", L"xltx", L"xltm", L"xlsb",
|
||||||
L"xlam", L"pptx", L"pptm", L"potx", L"potm", L"ppam", L"ppsx", L"ppsm", L"xsn",
|
L"xlam", L"pptx", L"pptm", L"potx", L"potm", L"ppam", L"ppsx", L"ppsm", L"xsn",
|
||||||
|
|
||||||
|
L"dwf",
|
||||||
|
|
||||||
L"odt", L"ods",
|
L"odt", L"ods",
|
||||||
L"wb3",
|
L"wb3",
|
||||||
L"pdf"
|
L"pdf"
|
||||||
|
|||||||
@@ -81,17 +81,24 @@ STDMETHODIMP CRootFolder::GetProperty(UInt32 itemIndex, PROPID propID, PROPVARIA
|
|||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef BOOL (WINAPI *SHGetSpecialFolderPathWp)(HWND hwnd, LPWSTR pszPath, int csidl, BOOL fCreate);
|
||||||
|
typedef BOOL (WINAPI *SHGetSpecialFolderPathAp)(HWND hwnd, LPSTR pszPath, int csidl, BOOL fCreate);
|
||||||
|
|
||||||
UString GetMyDocsPath()
|
UString GetMyDocsPath()
|
||||||
{
|
{
|
||||||
UString us;
|
UString us;
|
||||||
WCHAR s[MAX_PATH + 1];
|
WCHAR s[MAX_PATH + 1];
|
||||||
if (SHGetSpecialFolderPathW(0, s, CSIDL_PERSONAL, FALSE))
|
SHGetSpecialFolderPathWp getW = (SHGetSpecialFolderPathWp)
|
||||||
|
::GetProcAddress(::GetModuleHandleA("shell32.dll"), "SHGetSpecialFolderPathW");
|
||||||
|
if (getW && getW(0, s, CSIDL_PERSONAL, FALSE))
|
||||||
us = s;
|
us = s;
|
||||||
#ifndef _UNICODE
|
#ifndef _UNICODE
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
SHGetSpecialFolderPathAp getA = (SHGetSpecialFolderPathAp)
|
||||||
|
::GetProcAddress(::GetModuleHandleA("shell32.dll"), "SHGetSpecialFolderPathA");
|
||||||
CHAR s2[MAX_PATH + 1];
|
CHAR s2[MAX_PATH + 1];
|
||||||
if (SHGetSpecialFolderPathA(0, s2, CSIDL_PERSONAL, FALSE))
|
if (getA && getA(0, s2, CSIDL_PERSONAL, FALSE))
|
||||||
us = GetUnicodeString(s2);
|
us = GetUnicodeString(s2);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -146,7 +146,8 @@ static EMethodID g_ZipMethods[] =
|
|||||||
{
|
{
|
||||||
kDeflate,
|
kDeflate,
|
||||||
kDeflate64,
|
kDeflate64,
|
||||||
kBZip2
|
kBZip2,
|
||||||
|
kLZMA
|
||||||
};
|
};
|
||||||
|
|
||||||
static EMethodID g_GZipMethods[] =
|
static EMethodID g_GZipMethods[] =
|
||||||
@@ -173,6 +174,8 @@ struct CFormatInfo
|
|||||||
bool EncryptFileNames;
|
bool EncryptFileNames;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define METHODS_PAIR(x) x, MY_SIZE_OF_ARRAY(x)
|
||||||
|
|
||||||
static const CFormatInfo g_Formats[] =
|
static const CFormatInfo g_Formats[] =
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
@@ -184,26 +187,25 @@ static const CFormatInfo g_Formats[] =
|
|||||||
{
|
{
|
||||||
k7zFormat,
|
k7zFormat,
|
||||||
(1 << 0) | (1 << 1) | (1 << 3) | (1 << 5) | (1 << 7) | (1 << 9),
|
(1 << 0) | (1 << 1) | (1 << 3) | (1 << 5) | (1 << 7) | (1 << 9),
|
||||||
g_7zMethods, MY_SIZE_OF_ARRAY(g_7zMethods),
|
METHODS_PAIR(g_7zMethods),
|
||||||
true, true, true, true, true, true
|
true, true, true, true, true, true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
L"Zip",
|
L"Zip",
|
||||||
(1 << 0) | (1 << 1) | (1 << 3) | (1 << 5) | (1 << 7) | (1 << 9),
|
(1 << 0) | (1 << 1) | (1 << 3) | (1 << 5) | (1 << 7) | (1 << 9),
|
||||||
g_ZipMethods, MY_SIZE_OF_ARRAY(g_ZipMethods) ,
|
METHODS_PAIR(g_ZipMethods),
|
||||||
false, false, true, false, true, false
|
false, false, true, false, true, false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
L"GZip",
|
L"GZip",
|
||||||
(1 << 1) | (1 << 5) | (1 << 7) | (1 << 9),
|
(1 << 1) | (1 << 5) | (1 << 7) | (1 << 9),
|
||||||
g_GZipMethods, MY_SIZE_OF_ARRAY(g_GZipMethods),
|
METHODS_PAIR(g_GZipMethods),
|
||||||
false, false, false, false, false, false
|
false, false, false, false, false, false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
L"BZip2",
|
L"BZip2",
|
||||||
(1 << 1) | (1 << 3) | (1 << 5) | (1 << 7) | (1 << 9),
|
(1 << 1) | (1 << 3) | (1 << 5) | (1 << 7) | (1 << 9),
|
||||||
g_BZip2Methods,
|
METHODS_PAIR(g_BZip2Methods),
|
||||||
MY_SIZE_OF_ARRAY(g_BZip2Methods),
|
|
||||||
false, false, true, false, false
|
false, false, true, false, false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -1289,8 +1291,12 @@ UInt64 CCompressDialog::GetMemoryUsage(UInt32 dictionary, UInt64 &decompressMemo
|
|||||||
UInt32 numThreads = GetNumThreads2();
|
UInt32 numThreads = GetNumThreads2();
|
||||||
if (IsZipFormat())
|
if (IsZipFormat())
|
||||||
{
|
{
|
||||||
if (numThreads > 1)
|
UInt32 numSubThreads = 1;
|
||||||
size += (UInt64)numThreads << 25;
|
if (GetMethodID() == kLZMA && numThreads > 1 && level >= 5)
|
||||||
|
numSubThreads = 2;
|
||||||
|
UInt32 numMainThreads = numThreads / numSubThreads;
|
||||||
|
if (numMainThreads > 1)
|
||||||
|
size += (UInt64)numMainThreads << 25;
|
||||||
}
|
}
|
||||||
switch (GetMethodID())
|
switch (GetMethodID())
|
||||||
{
|
{
|
||||||
@@ -1306,13 +1312,19 @@ UInt64 CCompressDialog::GetMemoryUsage(UInt32 dictionary, UInt64 &decompressMemo
|
|||||||
if (hs > (1 << 24))
|
if (hs > (1 << 24))
|
||||||
hs >>= 1;
|
hs >>= 1;
|
||||||
hs++;
|
hs++;
|
||||||
size += hs * 4;
|
UInt64 size1 = (UInt64)hs * 4;
|
||||||
size += (UInt64)dictionary * 11 / 2;
|
size1 += (UInt64)dictionary * 11 / 2;
|
||||||
if (level >= 5)
|
if (level >= 5)
|
||||||
size += dictionary * 4;
|
size1 += dictionary * 4;
|
||||||
size += (2 << 20);
|
size1 += (2 << 20);
|
||||||
|
|
||||||
|
UInt32 numThreads1 = 1;
|
||||||
if (numThreads > 1 && level >= 5)
|
if (numThreads > 1 && level >= 5)
|
||||||
size += (2 << 20) + (4 << 20);
|
{
|
||||||
|
size1 += (2 << 20) + (4 << 20);
|
||||||
|
numThreads1 = 2;
|
||||||
|
}
|
||||||
|
size += size1 * numThreads / numThreads1;
|
||||||
|
|
||||||
decompressMemory = dictionary + (2 << 20);
|
decompressMemory = dictionary + (2 << 20);
|
||||||
return size;
|
return size;
|
||||||
|
|||||||
@@ -3,7 +3,10 @@
|
|||||||
#ifndef __COMMON_TYPES_H
|
#ifndef __COMMON_TYPES_H
|
||||||
#define __COMMON_TYPES_H
|
#define __COMMON_TYPES_H
|
||||||
|
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
#include "../../C/Types.h"
|
#include "../../C/Types.h"
|
||||||
|
}
|
||||||
|
|
||||||
typedef int HRes;
|
typedef int HRes;
|
||||||
|
|
||||||
|
|||||||
+3
-6
@@ -1,8 +1,6 @@
|
|||||||
7z ANSI-C Decoder 4.58
|
7z ANSI-C Decoder 4.61
|
||||||
----------------------
|
----------------------
|
||||||
|
|
||||||
7z ANSI-C Decoder 4.58 Copyright (C) 1999-2008 Igor Pavlov
|
|
||||||
|
|
||||||
7z ANSI-C provides 7z/LZMA decoding.
|
7z ANSI-C provides 7z/LZMA decoding.
|
||||||
7z ANSI-C version is simplified version ported from C++ code.
|
7z ANSI-C version is simplified version ported from C++ code.
|
||||||
|
|
||||||
@@ -95,7 +93,7 @@ Steps for using 7z decoder
|
|||||||
Use code at 7zMain.c as example.
|
Use code at 7zMain.c as example.
|
||||||
|
|
||||||
1) Declare variables:
|
1) Declare variables:
|
||||||
inStream /* implements ISzInStream interface */
|
inStream /* implements ILookInStream interface */
|
||||||
CSzArEx db; /* 7z archive database structure */
|
CSzArEx db; /* 7z archive database structure */
|
||||||
ISzAlloc allocImp; /* memory functions for main pool */
|
ISzAlloc allocImp; /* memory functions for main pool */
|
||||||
ISzAlloc allocTempImp; /* memory functions for temporary pool */
|
ISzAlloc allocTempImp; /* memory functions for temporary pool */
|
||||||
@@ -128,7 +126,7 @@ SzArEx_Open function allocates and frees temporary structures by "allocTemp" fun
|
|||||||
|
|
||||||
SZ_RESULT SzAr_Extract(
|
SZ_RESULT SzAr_Extract(
|
||||||
CArchiveDatabaseEx *db,
|
CArchiveDatabaseEx *db,
|
||||||
ISzInStream *inStream,
|
ILookInStream *inStream,
|
||||||
UInt32 fileIndex, /* index of file */
|
UInt32 fileIndex, /* index of file */
|
||||||
UInt32 *blockIndex, /* index of solid block */
|
UInt32 *blockIndex, /* index of solid block */
|
||||||
Byte **outBuffer, /* pointer to pointer to output buffer (allocated with allocMain) */
|
Byte **outBuffer, /* pointer to pointer to output buffer (allocated with allocMain) */
|
||||||
@@ -192,4 +190,3 @@ _SZ_ALLOC_DEBUG - define it if you want to debug alloc/free operations to stde
|
|||||||
---
|
---
|
||||||
|
|
||||||
http://www.7-zip.org
|
http://www.7-zip.org
|
||||||
http://www.7-zip.org/support.html
|
|
||||||
|
|||||||
+5
-1
@@ -2,7 +2,7 @@
|
|||||||
;Defines
|
;Defines
|
||||||
|
|
||||||
!define VERSION_MAJOR 4
|
!define VERSION_MAJOR 4
|
||||||
!define VERSION_MINOR 59
|
!define VERSION_MINOR 61
|
||||||
!define VERSION_POSTFIX_FULL " beta"
|
!define VERSION_POSTFIX_FULL " beta"
|
||||||
!ifdef WIN64
|
!ifdef WIN64
|
||||||
!ifdef IA64
|
!ifdef IA64
|
||||||
@@ -240,6 +240,7 @@ Section
|
|||||||
File pt-br.txt
|
File pt-br.txt
|
||||||
File ro.txt
|
File ro.txt
|
||||||
File ru.txt
|
File ru.txt
|
||||||
|
File si.txt
|
||||||
File sk.txt
|
File sk.txt
|
||||||
File sl.txt
|
File sl.txt
|
||||||
File sq.txt
|
File sq.txt
|
||||||
@@ -319,6 +320,8 @@ Section
|
|||||||
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\7-Zip" "NoRepair" 1
|
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\7-Zip" "NoRepair" 1
|
||||||
WriteUninstaller $INSTDIR\Uninstall.exe
|
WriteUninstaller $INSTDIR\Uninstall.exe
|
||||||
|
|
||||||
|
DeleteRegValue HKCR "CLSID\${CLSID_CONTEXT_MENU}\InprocServer32" "InprocServer32"
|
||||||
|
|
||||||
!ifdef WIN64
|
!ifdef WIN64
|
||||||
ExecWait 'regsvr32 /s "$INSTDIR\7-zip.dll"'
|
ExecWait 'regsvr32 /s "$INSTDIR\7-zip.dll"'
|
||||||
!endif
|
!endif
|
||||||
@@ -426,6 +429,7 @@ Section "Uninstall"
|
|||||||
Delete $INSTDIR\Lang\pt-br.txt
|
Delete $INSTDIR\Lang\pt-br.txt
|
||||||
Delete $INSTDIR\Lang\ro.txt
|
Delete $INSTDIR\Lang\ro.txt
|
||||||
Delete $INSTDIR\Lang\ru.txt
|
Delete $INSTDIR\Lang\ru.txt
|
||||||
|
Delete $INSTDIR\Lang\si.txt
|
||||||
Delete $INSTDIR\Lang\sk.txt
|
Delete $INSTDIR\Lang\sk.txt
|
||||||
Delete $INSTDIR\Lang\sl.txt
|
Delete $INSTDIR\Lang\sl.txt
|
||||||
Delete $INSTDIR\Lang\sq.txt
|
Delete $INSTDIR\Lang\sq.txt
|
||||||
|
|||||||
+2
-1
@@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0"?>
|
<?xml version="1.0"?>
|
||||||
|
|
||||||
<?define VerMajor = "4" ?>
|
<?define VerMajor = "4" ?>
|
||||||
<?define VerMinor = "60" ?>
|
<?define VerMinor = "61" ?>
|
||||||
<?define VerBuild = "00" ?>
|
<?define VerBuild = "00" ?>
|
||||||
<?define MmVer = "$(var.VerMajor).$(var.VerMinor)" ?>
|
<?define MmVer = "$(var.VerMajor).$(var.VerMinor)" ?>
|
||||||
<?define MmHex = "0$(var.VerMajor)$(var.VerMinor)" ?>
|
<?define MmHex = "0$(var.VerMajor)$(var.VerMinor)" ?>
|
||||||
@@ -279,6 +279,7 @@
|
|||||||
<File Id="pt_br.txt" Name="pt-br.txt" />
|
<File Id="pt_br.txt" Name="pt-br.txt" />
|
||||||
<File Id="ro.txt" Name="ro.txt" />
|
<File Id="ro.txt" Name="ro.txt" />
|
||||||
<File Id="ru.txt" Name="ru.txt" />
|
<File Id="ru.txt" Name="ru.txt" />
|
||||||
|
<File Id="si.txt" Name="si.txt" />
|
||||||
<File Id="sk.txt" Name="sk.txt" />
|
<File Id="sk.txt" Name="sk.txt" />
|
||||||
<File Id="sl.txt" Name="sl.txt" />
|
<File Id="sl.txt" Name="sl.txt" />
|
||||||
<File Id="sq.txt" Name="sq.txt" />
|
<File Id="sq.txt" Name="sq.txt" />
|
||||||
|
|||||||
+3
-3
@@ -1,4 +1,4 @@
|
|||||||
7-Zip method IDs (4.58)
|
7-Zip method IDs (4.61)
|
||||||
-----------------------
|
-----------------------
|
||||||
|
|
||||||
Each compression or crypto method in 7z has unique binary value (ID).
|
Each compression or crypto method in 7z has unique binary value (ID).
|
||||||
@@ -8,9 +8,9 @@ If you want to add some new ID, you have two ways:
|
|||||||
1) Write request for allocating IDs to 7-zip developers.
|
1) Write request for allocating IDs to 7-zip developers.
|
||||||
2) Generate 8-bytes ID:
|
2) Generate 8-bytes ID:
|
||||||
|
|
||||||
7F ZZ ZZ ZZ ZZ ZZ MM MM
|
3F ZZ ZZ ZZ ZZ ZZ MM MM
|
||||||
|
|
||||||
7F - Prefix for random IDs (1 byte)
|
3F - Prefix for random IDs (1 byte)
|
||||||
ZZ ZZ ZZ ZZ ZZ - Developer ID (5 bytes). Use real random bytes.
|
ZZ ZZ ZZ ZZ ZZ - Developer ID (5 bytes). Use real random bytes.
|
||||||
|
|
||||||
MM MM - Method ID (2 bytes)
|
MM MM - Method ID (2 bytes)
|
||||||
|
|||||||
@@ -1,6 +1,14 @@
|
|||||||
Sources history of the 7-Zip
|
Sources history of the 7-Zip
|
||||||
----------------------------
|
----------------------------
|
||||||
|
|
||||||
|
4.61 2008-11-23
|
||||||
|
-------------------------
|
||||||
|
- Bug in ver. 4.58+ was fixed:
|
||||||
|
7-Zip didn't use any -m* switch after -mtc, -mcl or -mcu for .zip archives.
|
||||||
|
- Bug in .CAB code was fixed. 7-Zip didn't show some empty files,
|
||||||
|
if .CAB archive contains more than one empty file.
|
||||||
|
|
||||||
|
|
||||||
4.59 2008-07-27
|
4.59 2008-07-27
|
||||||
-------------------------
|
-------------------------
|
||||||
- Bug was fixed:
|
- Bug was fixed:
|
||||||
|
|||||||
+2
-62
@@ -1,8 +1,6 @@
|
|||||||
LZMA SDK 4.60 beta
|
LZMA SDK 4.61 beta
|
||||||
------------------
|
------------------
|
||||||
|
|
||||||
LZMA SDK Copyright (C) 1999-2008 Igor Pavlov
|
|
||||||
|
|
||||||
LZMA SDK provides the documentation, samples, header files, libraries,
|
LZMA SDK provides the documentation, samples, header files, libraries,
|
||||||
and tools you need to develop applications that use LZMA compression.
|
and tools you need to develop applications that use LZMA compression.
|
||||||
|
|
||||||
@@ -20,62 +18,7 @@ decompressing.
|
|||||||
LICENSE
|
LICENSE
|
||||||
-------
|
-------
|
||||||
|
|
||||||
LZMA SDK is available under any of the following licenses:
|
LZMA SDK is written and placed in the public domain by Igor Pavlov.
|
||||||
|
|
||||||
1) GNU Lesser General Public License (GNU LGPL)
|
|
||||||
2) Common Public License (CPL)
|
|
||||||
3) Common Development and Distribution License (CDDL) Version 1.0
|
|
||||||
4) Simplified license for unmodified code (read SPECIAL EXCEPTION)
|
|
||||||
|
|
||||||
It means that you can select one of these options and follow rules of that license.
|
|
||||||
|
|
||||||
|
|
||||||
1,2,3) GNU LGPL, CPL and CDDL licenses are classified as
|
|
||||||
- "Free software licenses" at http://www.gnu.org/
|
|
||||||
- "OSI-approved" at http://www.opensource.org/
|
|
||||||
|
|
||||||
4) Simplified license for unmodified code (read SPECIAL EXCEPTION)
|
|
||||||
|
|
||||||
Igor Pavlov, as the author of this code, expressly permits you
|
|
||||||
to statically or dynamically link your code (or bind by name)
|
|
||||||
to the files from LZMA SDK.
|
|
||||||
|
|
||||||
SPECIAL EXCEPTION allows you to use LZMA SDK in applications with closed code,
|
|
||||||
while you keep LZMA SDK code unmodified.
|
|
||||||
|
|
||||||
|
|
||||||
SPECIAL EXCEPTION #2: Igor Pavlov, as the author of this code, expressly permits
|
|
||||||
you to use this code under the same terms and conditions contained in the License
|
|
||||||
Agreement you have for any previous version of LZMA SDK developed by Igor Pavlov.
|
|
||||||
|
|
||||||
SPECIAL EXCEPTION #2 allows owners of proprietary licenses to use latest version
|
|
||||||
of LZMA SDK as update for previous versions.
|
|
||||||
|
|
||||||
Some files in LZMA SDK are placed in public domain.
|
|
||||||
Some of these "public domain" files:
|
|
||||||
C\Types.h,
|
|
||||||
C\LzmaLib.*
|
|
||||||
C\LzmaLibUtil.*
|
|
||||||
LzmaAlone.cpp,
|
|
||||||
LzmaAlone.cs,
|
|
||||||
LzmaAlone.java
|
|
||||||
|
|
||||||
So you can change them as you want and use "SPECIAL EXCEPTION"
|
|
||||||
for other unmodified files. For example, you can edit C\Types.h to solve some
|
|
||||||
compatibility problems with your compiler.
|
|
||||||
|
|
||||||
|
|
||||||
-----
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public
|
|
||||||
License along with this library; if not, write to the Free Software
|
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
|
|
||||||
You should have received a copy of the Common Public License
|
|
||||||
along with this library.
|
|
||||||
|
|
||||||
You should have received a copy of the Common Development and Distribution
|
|
||||||
License Version 1.0 along with this library.
|
|
||||||
|
|
||||||
|
|
||||||
LZMA SDK Contents
|
LZMA SDK Contents
|
||||||
@@ -107,9 +50,6 @@ lzma.txt - LZMA SDK description (this file)
|
|||||||
methods.txt - Compression method IDs for .7z
|
methods.txt - Compression method IDs for .7z
|
||||||
lzma.exe - Compiled file->file LZMA encoder/decoder for Windows
|
lzma.exe - Compiled file->file LZMA encoder/decoder for Windows
|
||||||
history.txt - history of the LZMA SDK
|
history.txt - history of the LZMA SDK
|
||||||
LGPL.txt - GNU Lesser General Public License
|
|
||||||
CPL.html - Common Public License
|
|
||||||
CDDL.html - Common Development and Distribution License (CDDL)
|
|
||||||
|
|
||||||
|
|
||||||
Source code structure
|
Source code structure
|
||||||
|
|||||||
Reference in New Issue
Block a user