mirror of
https://github.com/Xevion/easy7zip.git
synced 2026-01-31 04:24:11 -06:00
4.45 beta
This commit is contained in:
committed by
Kornel Lesiński
parent
d9666cf046
commit
a145bfc7cf
@@ -1,133 +0,0 @@
|
||||
// Common/Alloc.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "MyWindows.h"
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#include "Alloc.h"
|
||||
|
||||
/* #define _SZ_ALLOC_DEBUG */
|
||||
/* use _SZ_ALLOC_DEBUG to debug alloc/free operations */
|
||||
#ifdef _SZ_ALLOC_DEBUG
|
||||
#include <stdio.h>
|
||||
int g_allocCount = 0;
|
||||
int g_allocCountMid = 0;
|
||||
int g_allocCountBig = 0;
|
||||
#endif
|
||||
|
||||
void *MyAlloc(size_t size) throw()
|
||||
{
|
||||
if (size == 0)
|
||||
return 0;
|
||||
#ifdef _SZ_ALLOC_DEBUG
|
||||
fprintf(stderr, "\nAlloc %10d bytes; count = %10d", size, g_allocCount++);
|
||||
#endif
|
||||
return ::malloc(size);
|
||||
}
|
||||
|
||||
void MyFree(void *address) throw()
|
||||
{
|
||||
#ifdef _SZ_ALLOC_DEBUG
|
||||
if (address != 0)
|
||||
fprintf(stderr, "\nFree; count = %10d", --g_allocCount);
|
||||
#endif
|
||||
|
||||
::free(address);
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
void *MidAlloc(size_t size) throw()
|
||||
{
|
||||
if (size == 0)
|
||||
return 0;
|
||||
#ifdef _SZ_ALLOC_DEBUG
|
||||
fprintf(stderr, "\nAlloc_Mid %10d bytes; count = %10d", size, g_allocCountMid++);
|
||||
#endif
|
||||
return ::VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE);
|
||||
}
|
||||
|
||||
void MidFree(void *address) throw()
|
||||
{
|
||||
#ifdef _SZ_ALLOC_DEBUG
|
||||
if (address != 0)
|
||||
fprintf(stderr, "\nFree_Mid; count = %10d", --g_allocCountMid);
|
||||
#endif
|
||||
if (address == 0)
|
||||
return;
|
||||
::VirtualFree(address, 0, MEM_RELEASE);
|
||||
}
|
||||
|
||||
|
||||
#ifndef MEM_LARGE_PAGES
|
||||
#define _7ZIP_NO_LARGE_PAGES
|
||||
#endif
|
||||
|
||||
// define _7ZIP_NO_LARGE_PAGES if you don't need LARGE_PAGES support
|
||||
// #define _7ZIP_NO_LARGE_PAGES
|
||||
|
||||
|
||||
#ifndef _7ZIP_NO_LARGE_PAGES
|
||||
static SIZE_T g_LargePageSize =
|
||||
#ifdef _WIN64
|
||||
(1 << 21);
|
||||
#else
|
||||
(1 << 22);
|
||||
#endif
|
||||
|
||||
typedef SIZE_T (WINAPI *GetLargePageMinimumP)();
|
||||
#endif
|
||||
|
||||
bool SetLargePageSize()
|
||||
{
|
||||
#ifndef _7ZIP_NO_LARGE_PAGES
|
||||
GetLargePageMinimumP largePageMinimum = (GetLargePageMinimumP)
|
||||
::GetProcAddress(::GetModuleHandle(TEXT("kernel32.dll")), "GetLargePageMinimum");
|
||||
if (largePageMinimum == 0)
|
||||
return false;
|
||||
SIZE_T size = largePageMinimum();
|
||||
if (size == 0 || (size & (size - 1)) != 0)
|
||||
return false;
|
||||
g_LargePageSize = size;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void *BigAlloc(size_t size) throw()
|
||||
{
|
||||
if (size == 0)
|
||||
return 0;
|
||||
#ifdef _SZ_ALLOC_DEBUG
|
||||
fprintf(stderr, "\nAlloc_Big %10d bytes; count = %10d", size, g_allocCountBig++);
|
||||
#endif
|
||||
|
||||
#ifndef _7ZIP_NO_LARGE_PAGES
|
||||
if (size >= (1 << 18))
|
||||
{
|
||||
void *res = ::VirtualAlloc(0, (size + g_LargePageSize - 1) & (~(g_LargePageSize - 1)),
|
||||
MEM_COMMIT | MEM_LARGE_PAGES, PAGE_READWRITE);
|
||||
if (res != 0)
|
||||
return res;
|
||||
}
|
||||
#endif
|
||||
return ::VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE);
|
||||
}
|
||||
|
||||
void BigFree(void *address) throw()
|
||||
{
|
||||
#ifdef _SZ_ALLOC_DEBUG
|
||||
if (address != 0)
|
||||
fprintf(stderr, "\nFree_Big; count = %10d", --g_allocCountBig);
|
||||
#endif
|
||||
|
||||
if (address == 0)
|
||||
return;
|
||||
::VirtualFree(address, 0, MEM_RELEASE);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,29 +0,0 @@
|
||||
// Common/Alloc.h
|
||||
|
||||
#ifndef __COMMON_ALLOC_H
|
||||
#define __COMMON_ALLOC_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
void *MyAlloc(size_t size) throw();
|
||||
void MyFree(void *address) throw();
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
bool SetLargePageSize();
|
||||
|
||||
void *MidAlloc(size_t size) throw();
|
||||
void MidFree(void *address) throw();
|
||||
void *BigAlloc(size_t size) throw();
|
||||
void BigFree(void *address) throw();
|
||||
|
||||
#else
|
||||
|
||||
#define MidAlloc(size) MyAlloc(size)
|
||||
#define MidFree(address) MyFree(address)
|
||||
#define BigAlloc(size) MyAlloc(size)
|
||||
#define BigFree(address) MyFree(address)
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
+4
-51
@@ -2,60 +2,13 @@
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "CRC.h"
|
||||
|
||||
static const UInt32 kCRCPoly = 0xEDB88320;
|
||||
|
||||
UInt32 CCRC::Table[256];
|
||||
|
||||
void CCRC::InitTable()
|
||||
{
|
||||
for (UInt32 i = 0; i < 256; i++)
|
||||
{
|
||||
UInt32 r = i;
|
||||
for (int j = 0; j < 8; j++)
|
||||
if (r & 1)
|
||||
r = (r >> 1) ^ kCRCPoly;
|
||||
else
|
||||
r >>= 1;
|
||||
CCRC::Table[i] = r;
|
||||
}
|
||||
extern "C"
|
||||
{
|
||||
#include "../../C/7zCrc.h"
|
||||
}
|
||||
|
||||
class CCRCTableInit
|
||||
{
|
||||
public:
|
||||
CCRCTableInit() { CCRC::InitTable(); }
|
||||
CCRCTableInit() { CrcGenerateTable(); }
|
||||
} g_CRCTableInit;
|
||||
|
||||
void CCRC::UpdateByte(Byte b)
|
||||
{
|
||||
_value = Table[((Byte)(_value)) ^ b] ^ (_value >> 8);
|
||||
}
|
||||
|
||||
void CCRC::UpdateUInt16(UInt16 v)
|
||||
{
|
||||
UpdateByte(Byte(v));
|
||||
UpdateByte(Byte(v >> 8));
|
||||
}
|
||||
|
||||
void CCRC::UpdateUInt32(UInt32 v)
|
||||
{
|
||||
for (int i = 0; i < 4; i++)
|
||||
UpdateByte((Byte)(v >> (8 * i)));
|
||||
}
|
||||
|
||||
void CCRC::UpdateUInt64(UInt64 v)
|
||||
{
|
||||
for (int i = 0; i < 8; i++)
|
||||
UpdateByte((Byte)(v >> (8 * i)));
|
||||
}
|
||||
|
||||
void CCRC::Update(const void *data, size_t size)
|
||||
{
|
||||
UInt32 v = _value;
|
||||
const Byte *p = (const Byte *)data;
|
||||
for (; size > 0 ; size--, p++)
|
||||
v = Table[((Byte)(v)) ^ *p] ^ (v >> 8);
|
||||
_value = v;
|
||||
}
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
// Common/CRC.h
|
||||
|
||||
#ifndef __COMMON_CRC_H
|
||||
#define __COMMON_CRC_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include "Types.h"
|
||||
|
||||
class CCRC
|
||||
{
|
||||
UInt32 _value;
|
||||
public:
|
||||
static UInt32 Table[256];
|
||||
static void InitTable();
|
||||
|
||||
CCRC(): _value(0xFFFFFFFF){};
|
||||
void Init() { _value = 0xFFFFFFFF; }
|
||||
void UpdateByte(Byte v);
|
||||
void UpdateUInt16(UInt16 v);
|
||||
void UpdateUInt32(UInt32 v);
|
||||
void UpdateUInt64(UInt64 v);
|
||||
void Update(const void *data, size_t size);
|
||||
UInt32 GetDigest() const { return _value ^ 0xFFFFFFFF; }
|
||||
static UInt32 CalculateDigest(const void *data, size_t size)
|
||||
{
|
||||
CCRC crc;
|
||||
crc.Update(data, size);
|
||||
return crc.GetDigest();
|
||||
}
|
||||
static bool VerifyDigest(UInt32 digest, const void *data, size_t size)
|
||||
{
|
||||
return (CalculateDigest(data, size) == digest);
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -5,7 +5,9 @@
|
||||
|
||||
#include "MyWindows.h"
|
||||
|
||||
#ifndef RINOK
|
||||
#define RINOK(x) { HRESULT __result_ = (x); if(__result_ != S_OK) return __result_; }
|
||||
#endif
|
||||
|
||||
template <class T>
|
||||
class CMyComPtr
|
||||
|
||||
@@ -22,14 +22,14 @@ typedef struct {
|
||||
#define REFIID REFGUID
|
||||
|
||||
#ifdef __cplusplus
|
||||
inline bool operator==(REFGUID g1, REFGUID g2)
|
||||
inline int operator==(REFGUID g1, REFGUID g2)
|
||||
{
|
||||
for (int i = 0; i < (int)sizeof(g1); i++)
|
||||
if (((unsigned char *)&g1)[i] != ((unsigned char *)&g2)[i])
|
||||
return false;
|
||||
return true;
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
inline bool operator!=(REFGUID g1, REFGUID g2) { return !(g1 == g2); }
|
||||
inline int operator!=(REFGUID g1, REFGUID g2) { return !(g1 == g2); }
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -15,10 +15,10 @@ public:
|
||||
CStdOutStream (): _streamIsOpen(false), _stream(0) {};
|
||||
CStdOutStream (FILE *stream): _streamIsOpen(false), _stream(stream) {};
|
||||
~CStdOutStream ();
|
||||
operator FILE *() { return _stream; }
|
||||
bool Open(const char *fileName);
|
||||
bool Close();
|
||||
bool Flush();
|
||||
|
||||
CStdOutStream & operator<<(CStdOutStream & (* aFunction)(CStdOutStream &));
|
||||
CStdOutStream & operator<<(const char *string);
|
||||
CStdOutStream & operator<<(const wchar_t *string);
|
||||
|
||||
+5
-7
@@ -12,8 +12,6 @@
|
||||
#include "MyWindows.h"
|
||||
#endif
|
||||
|
||||
static const char *kTrimDefaultCharSet = " \n\t";
|
||||
|
||||
template <class T>
|
||||
inline int MyStringLen(const T *s)
|
||||
{
|
||||
@@ -55,7 +53,7 @@ inline char MyCharUpper(char c)
|
||||
{ return (char)(unsigned int)(UINT_PTR)CharUpperA((LPSTR)(UINT_PTR)(unsigned int)(unsigned char)c); }
|
||||
#ifdef _UNICODE
|
||||
inline wchar_t MyCharUpper(wchar_t c)
|
||||
{ return (wchar_t)CharUpperW((LPWSTR)c); }
|
||||
{ return (wchar_t)(unsigned int)(UINT_PTR)CharUpperW((LPWSTR)(UINT_PTR)(unsigned int)c); }
|
||||
#else
|
||||
wchar_t MyCharUpper(wchar_t c);
|
||||
#endif
|
||||
@@ -64,7 +62,7 @@ inline char MyCharLower(char c)
|
||||
{ return (char)(unsigned int)(UINT_PTR)CharLowerA((LPSTR)(UINT_PTR)(unsigned int)(unsigned char)c); }
|
||||
#ifdef _UNICODE
|
||||
inline wchar_t MyCharLower(wchar_t c)
|
||||
{ return (wchar_t)CharLowerW((LPWSTR)c); }
|
||||
{ return (wchar_t)(unsigned int)(UINT_PTR)CharLowerW((LPWSTR)(UINT_PTR)(unsigned int)c); }
|
||||
#else
|
||||
wchar_t MyCharLower(wchar_t c);
|
||||
#endif
|
||||
@@ -431,9 +429,9 @@ public:
|
||||
CStringBase GetTrimDefaultCharSet()
|
||||
{
|
||||
CStringBase<T> charSet;
|
||||
for(int i = 0; i < (int)(sizeof(kTrimDefaultCharSet) /
|
||||
sizeof(kTrimDefaultCharSet[0])); i++)
|
||||
charSet += (T)kTrimDefaultCharSet[i];
|
||||
charSet += (T)' ';
|
||||
charSet += (T)'\n';
|
||||
charSet += (T)'\t';
|
||||
return charSet;
|
||||
}
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user