[Project64] Cleanup 3rdParty/7zip.cpp
This commit is contained in:
parent
ec6ab39137
commit
fd5941fa35
|
@ -6,22 +6,22 @@ typedef const char * LPCSTR;
|
|||
#include <memory.h>
|
||||
#include "7zip.h"
|
||||
|
||||
C7zip::C7zip (LPCSTR FileName) :
|
||||
m_FileSize(0),
|
||||
m_CurrentFile(-1),
|
||||
m_blockIndex(0xFFFFFFFF),
|
||||
m_outBuffer(0),
|
||||
m_outBufferSize(0),
|
||||
m_NotfyCallback(NotfyCallbackDefault),
|
||||
m_NotfyCallbackInfo(NULL),
|
||||
m_db(NULL),
|
||||
m_Opened(false)
|
||||
C7zip::C7zip(LPCSTR FileName) :
|
||||
m_FileSize(0),
|
||||
m_CurrentFile(-1),
|
||||
m_blockIndex(0xFFFFFFFF),
|
||||
m_outBuffer(0),
|
||||
m_outBufferSize(0),
|
||||
m_NotfyCallback(NotfyCallbackDefault),
|
||||
m_NotfyCallbackInfo(NULL),
|
||||
m_db(NULL),
|
||||
m_Opened(false)
|
||||
{
|
||||
memset(&m_FileName,0,sizeof(m_FileName));
|
||||
memset(&m_archiveLookStream,0,sizeof(m_archiveLookStream));
|
||||
memset(&m_FileName, 0, sizeof(m_FileName));
|
||||
memset(&m_archiveLookStream, 0, sizeof(m_archiveLookStream));
|
||||
|
||||
m_db = new CSzArEx;
|
||||
memset(m_db,0,sizeof(CSzArEx));
|
||||
memset(m_db, 0, sizeof(CSzArEx));
|
||||
|
||||
m_archiveStream.s.Read = SzFileReadImp;
|
||||
m_archiveStream.s.Seek = SzFileSeekImp;
|
||||
|
@ -32,16 +32,16 @@ C7zip::C7zip (LPCSTR FileName) :
|
|||
m_allocTempImp.Alloc = AllocAllocImp;
|
||||
m_allocTempImp.Free = AllocFreeImp;
|
||||
|
||||
InFile_Open(&m_archiveStream.file,FileName);
|
||||
InFile_Open(&m_archiveStream.file, FileName);
|
||||
if (m_archiveStream.file.handle == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
//PrintError("can not open input file");
|
||||
return;
|
||||
}
|
||||
m_FileSize = GetFileSize(m_archiveStream.file.handle,NULL);
|
||||
m_FileSize = GetFileSize(m_archiveStream.file.handle, NULL);
|
||||
|
||||
char drive[_MAX_DRIVE] ,dir[_MAX_DIR], ext[_MAX_EXT];
|
||||
_splitpath( FileName, drive, dir, m_FileName, ext );
|
||||
char drive[_MAX_DRIVE], dir[_MAX_DIR], ext[_MAX_EXT];
|
||||
_splitpath(FileName, drive, dir, m_FileName, ext);
|
||||
|
||||
CrcGenerateTable();
|
||||
SzArEx_Init(m_db);
|
||||
|
@ -62,7 +62,7 @@ C7zip::C7zip (LPCSTR FileName) :
|
|||
}
|
||||
}
|
||||
|
||||
C7zip::~C7zip (void)
|
||||
C7zip::~C7zip(void)
|
||||
{
|
||||
if (m_db)
|
||||
{
|
||||
|
@ -84,7 +84,7 @@ C7zip::~C7zip (void)
|
|||
#endif
|
||||
}
|
||||
|
||||
void C7zip::SetNotificationCallback (LP7ZNOTIFICATION NotfyFnc, void * CBInfo)
|
||||
void C7zip::SetNotificationCallback(LP7ZNOTIFICATION NotfyFnc, void * CBInfo)
|
||||
{
|
||||
m_NotfyCallback = NotfyFnc ? NotfyFnc : NotfyCallbackDefault;
|
||||
m_NotfyCallbackInfo = CBInfo;
|
||||
|
@ -110,7 +110,7 @@ void C7zip::StatusUpdate(_7Z_STATUS status, int Value1, int Value2, C7zip * _thi
|
|||
}
|
||||
#endif
|
||||
|
||||
bool C7zip::GetFile(int index, Byte * Data, size_t DataLen )
|
||||
bool C7zip::GetFile(int index, Byte * Data, size_t DataLen)
|
||||
{
|
||||
m_CurrentFile = -1;
|
||||
if (Data == NULL || DataLen == 0)
|
||||
|
@ -129,7 +129,7 @@ bool C7zip::GetFile(int index, Byte * Data, size_t DataLen )
|
|||
wchar_t Msg[200];
|
||||
std::wstring FileName = FileNameIndex(index);
|
||||
_snwprintf(Msg, sizeof(Msg) / sizeof(Msg[0]), L"extracting %s", FileName.c_str());
|
||||
m_NotfyCallback(Msg,m_NotfyCallbackInfo);
|
||||
m_NotfyCallback(Msg, m_NotfyCallbackInfo);
|
||||
|
||||
SRes res = SzArEx_Extract(m_db, &m_archiveLookStream.s, index,
|
||||
&m_blockIndex, &m_outBuffer, &m_outBufferSize,
|
||||
|
@ -145,19 +145,19 @@ bool C7zip::GetFile(int index, Byte * Data, size_t DataLen )
|
|||
{
|
||||
outSizeProcessed = DataLen;
|
||||
}
|
||||
memcpy(Data,m_outBuffer + offset,outSizeProcessed);
|
||||
m_NotfyCallback(L"",m_NotfyCallbackInfo);
|
||||
memcpy(Data, m_outBuffer + offset, outSizeProcessed);
|
||||
m_NotfyCallback(L"", m_NotfyCallbackInfo);
|
||||
m_CurrentFile = -1;
|
||||
return true;
|
||||
}
|
||||
|
||||
void * C7zip::AllocAllocImp (void * /*p*/, size_t size)
|
||||
void * C7zip::AllocAllocImp(void * /*p*/, size_t size)
|
||||
{
|
||||
return malloc(size);
|
||||
//return new BYTE[size];
|
||||
}
|
||||
|
||||
void C7zip::AllocFreeImp (void * /*p*/, void *address)
|
||||
void C7zip::AllocFreeImp(void * /*p*/, void *address)
|
||||
{
|
||||
if (address != NULL)
|
||||
{
|
||||
|
@ -169,7 +169,7 @@ SRes C7zip::SzFileReadImp(void *object, void *buffer, size_t *processedSize)
|
|||
{
|
||||
CFileInStream *p = (CFileInStream *)object;
|
||||
DWORD dwRead;
|
||||
if (!ReadFile(p->file.handle,buffer,*processedSize,&dwRead,NULL))
|
||||
if (!ReadFile(p->file.handle, buffer, *processedSize, &dwRead, NULL))
|
||||
{
|
||||
return SZ_ERROR_FAIL;
|
||||
}
|
||||
|
@ -196,9 +196,8 @@ SRes C7zip::SzFileSeekImp(void *p, Int64 *pos, ESzSeek origin)
|
|||
break;
|
||||
default:
|
||||
return SZ_ERROR_FAIL;
|
||||
|
||||
}
|
||||
*pos = SetFilePointer(s->file.handle,(LONG)*pos, NULL, dwMoveMethod);
|
||||
*pos = SetFilePointer(s->file.handle, (LONG)*pos, NULL, dwMoveMethod);
|
||||
if (*pos == INVALID_SET_FILE_POINTER)
|
||||
{
|
||||
return SZ_ERROR_FAIL;
|
||||
|
@ -206,7 +205,7 @@ SRes C7zip::SzFileSeekImp(void *p, Int64 *pos, ESzSeek origin)
|
|||
return SZ_OK;
|
||||
}
|
||||
|
||||
const char * C7zip::FileName ( char * FileName, int SizeOfFileName ) const
|
||||
const char * C7zip::FileName(char * FileName, int SizeOfFileName) const
|
||||
{
|
||||
if (FileName == NULL)
|
||||
{
|
||||
|
@ -217,12 +216,12 @@ const char * C7zip::FileName ( char * FileName, int SizeOfFileName ) const
|
|||
{
|
||||
Len = (SizeOfFileName - 1);
|
||||
}
|
||||
strncpy(FileName,m_FileName,Len);
|
||||
strncpy(FileName, m_FileName, Len);
|
||||
FileName[Len] = 0;
|
||||
return FileName;
|
||||
}
|
||||
|
||||
std::wstring C7zip::FileNameIndex (int index)
|
||||
std::wstring C7zip::FileNameIndex(int index)
|
||||
{
|
||||
std::wstring filename;
|
||||
if (m_db == NULL || m_db->FileNameOffsets == 0)
|
||||
|
|
|
@ -14,26 +14,25 @@ extern "C" {
|
|||
}
|
||||
#endif
|
||||
|
||||
|
||||
class C7zip
|
||||
{
|
||||
public:
|
||||
|
||||
C7zip (LPCSTR FileName);
|
||||
~C7zip ();
|
||||
C7zip(LPCSTR FileName);
|
||||
~C7zip();
|
||||
|
||||
typedef void (__stdcall *LP7ZNOTIFICATION)( LPCWSTR Status, void * CBInfo );
|
||||
typedef void(__stdcall *LP7ZNOTIFICATION)(LPCWSTR Status, void * CBInfo);
|
||||
|
||||
inline int NumFiles ( void ) const { return m_db ? m_db->db.NumFiles : 0; }
|
||||
inline CSzFileItem * FileItem ( int index ) const { return m_db ? &m_db->db.Files[index] : NULL; }
|
||||
inline int FileSize ( void ) const { return m_FileSize; }
|
||||
inline bool OpenSuccess ( void) const { return m_Opened; }
|
||||
inline int NumFiles(void) const { return m_db ? m_db->db.NumFiles : 0; }
|
||||
inline CSzFileItem * FileItem(int index) const { return m_db ? &m_db->db.Files[index] : NULL; }
|
||||
inline int FileSize(void) const { return m_FileSize; }
|
||||
inline bool OpenSuccess(void) const { return m_Opened; }
|
||||
|
||||
bool GetFile ( int index, Byte * Data, size_t DataLen );
|
||||
const char * FileName ( char * FileName, int SizeOfFileName ) const;
|
||||
std::wstring FileNameIndex (int index);
|
||||
bool GetFile(int index, Byte * Data, size_t DataLen);
|
||||
const char * FileName(char * FileName, int SizeOfFileName) const;
|
||||
std::wstring FileNameIndex(int index);
|
||||
|
||||
void SetNotificationCallback (LP7ZNOTIFICATION NotfyFnc, void * CBInfo);
|
||||
void SetNotificationCallback(LP7ZNOTIFICATION NotfyFnc, void * CBInfo);
|
||||
|
||||
private:
|
||||
C7zip(void); // Disable default constructor
|
||||
|
@ -45,7 +44,7 @@ private:
|
|||
ISzInStream InStream;
|
||||
FILE *File;
|
||||
} CFileInStream;
|
||||
*/
|
||||
*/
|
||||
CSzArEx * m_db;
|
||||
CFileInStream m_archiveStream;
|
||||
CLookToRead m_archiveLookStream;
|
||||
|
@ -57,19 +56,19 @@ private:
|
|||
bool m_Opened;
|
||||
|
||||
//Used for extraction
|
||||
UInt32 m_blockIndex ; // it can have any value before first call (if outBuffer = 0)
|
||||
UInt32 m_blockIndex; // it can have any value before first call (if outBuffer = 0)
|
||||
Byte * m_outBuffer; // it must be 0 before first call for each new archive.
|
||||
size_t m_outBufferSize; // it can have any value before first call (if outBuffer = 0)
|
||||
|
||||
static void * AllocAllocImp (void *p, size_t size);
|
||||
static void AllocFreeImp (void *p, void *address); /* address can be 0 */
|
||||
static void * AllocAllocImp(void *p, size_t size);
|
||||
static void AllocFreeImp(void *p, void *address); /* address can be 0 */
|
||||
|
||||
static SRes SzFileReadImp(void *object, void *buffer, size_t *processedSize);
|
||||
static SRes SzFileSeekImp(void *p, Int64 *pos, ESzSeek origin);
|
||||
|
||||
//static void __stdcall StatusUpdate(_7Z_STATUS status, int Value1, int Value2, C7zip * _this);
|
||||
|
||||
static void __stdcall NotfyCallbackDefault ( LPCWSTR /*Status*/, void * /*CBInfo*/ ) { }
|
||||
static void __stdcall NotfyCallbackDefault(LPCWSTR /*Status*/, void * /*CBInfo*/) { }
|
||||
|
||||
LP7ZNOTIFICATION m_NotfyCallback;
|
||||
void * m_NotfyCallbackInfo;
|
||||
|
|
Loading…
Reference in New Issue