This commit is contained in:
King_DuckZ 2020-05-05 20:22:31 +02:00
parent 0f9dddcc52
commit 35c0b24c92
12 changed files with 654 additions and 360 deletions

View file

@ -5,8 +5,8 @@ CPP = g++.exe
CC = gcc.exe
WINDRES = windres.exe
RES =
OBJ = main.o UnAlz.o UnAlzBz2decompress.o UnAlzBzip2.o UnAlzbzlib.o zlib/adler32.o zlib/crc32.o zlib/infblock.o zlib/infcodes.o zlib/inffast.o zlib/inflate.o zlib/inftrees.o zlib/infutil.o zlib/uncompr.o zlib/zutil.o bzip2/blocksort.o bzip2/compress.o bzip2/crctable.o bzip2/huffman.o bzip2/randtable.o $(RES)
LINKOBJ = main.o UnAlz.o UnAlzBz2decompress.o UnAlzBzip2.o UnAlzbzlib.o zlib/adler32.o zlib/crc32.o zlib/infblock.o zlib/infcodes.o zlib/inffast.o zlib/inflate.o zlib/inftrees.o zlib/infutil.o zlib/uncompr.o zlib/zutil.o bzip2/blocksort.o bzip2/compress.o bzip2/crctable.o bzip2/huffman.o bzip2/randtable.o $(RES)
OBJ = main.o UnAlz.o UnAlzBz2decompress.o UnAlzBzip2.o UnAlzbzlib.o zlib/adler32.o zlib/crc32.o zlib/infblock.o zlib/infcodes.o zlib/inffast.o zlib/inflate.o zlib/inftrees.o zlib/infutil.o zlib/zutil.o bzip2/blocksort.o bzip2/compress.o bzip2/crctable.o bzip2/huffman.o bzip2/randtable.o $(RES)
LINKOBJ = main.o UnAlz.o UnAlzBz2decompress.o UnAlzBzip2.o UnAlzbzlib.o zlib/adler32.o zlib/crc32.o zlib/infblock.o zlib/infcodes.o zlib/inffast.o zlib/inflate.o zlib/inftrees.o zlib/infutil.o zlib/zutil.o bzip2/blocksort.o bzip2/compress.o bzip2/crctable.o bzip2/huffman.o bzip2/randtable.o $(RES)
LIBS = -L"C:/Dev-Cpp/lib" -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -luuid -lodbc32 -lodbccp32 -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -luuid -lodbc32 -lodbccp32
INCS = -I"C:/Dev-Cpp/include"
CXXINCS = -I"C:/Dev-Cpp/include/c++/3.3.1" -I"C:/Dev-Cpp/include/c++/3.3.1/mingw32" -I"C:/Dev-Cpp/include/c++/3.3.1/backward" -I"C:/Dev-Cpp/lib/gcc-lib/mingw32/3.3.1/include" -I"C:/Dev-Cpp/include"
@ -64,9 +64,6 @@ zlib/inftrees.o: zlib/inftrees.c
zlib/infutil.o: zlib/infutil.c
$(CC) -c zlib/infutil.c -o zlib/infutil.o $(CFLAGS)
zlib/uncompr.o: zlib/uncompr.c
$(CC) -c zlib/uncompr.c -o zlib/uncompr.o $(CFLAGS)
zlib/zutil.o: zlib/zutil.c
$(CC) -c zlib/zutil.c -o zlib/zutil.o $(CFLAGS)

291
UnAlz.cpp
View file

@ -2,24 +2,108 @@
#include "zlib/zlib.h"
#include "bzip2/bzlib.h"
#include "UnAlz.h"
// mkdir
#ifdef _WIN32
#include <direct.h> // mkdir
# include <direct.h>
#else
#include <sys/stat.h>
# include <sys/stat.h>
#endif
// le16toh 등등..
#if (defined(__FreeBSD__) || defined(__DARWIN__))
# include <sys/endian.h>
#endif
#ifdef __linux__ // __BYTE_ORDER 가져오기
# include <endian.h>
#endif
#ifdef _UNALZ_ICONV // code page support
# include <iconv.h>
#endif
#ifdef __linux__ // iconv.h 때문에 필요
# include <errno.h>
#endif
#ifndef _WIN32 // WIN32 는 무조건 LITTLE 이니까 필요없다.
# define swapint64(Data) (INT64) ( (((Data)&0x00000000000000FFLL) << 56) | (((Data)&0x000000000000FF00LL) << 40) | (((Data)&0x0000000000FF0000LL) << 24) | (((Data)&0x00000000FF000000LL) << 8) | (((Data)&0x000000FF00000000LL) >> 8) | (((Data)&0x0000FF0000000000LL) >> 24) | (((Data)&0x00FF000000000000LL) >> 40) | (((Data)&0xFF00000000000000LL) >> 56) )
# define swapint32(a) ((((a)&0xff)<<24)+(((a>>8)&0xff)<<16)+(((a>>16)&0xff)<<8)+(((a>>24)&0xff)))
# define swapint16(a) (((a)&0xff)<<8)+(((a>>8)&0xff))
#endif
//// byte-order : little to host ////
#ifdef _WIN32 // little to little
inline UINT16 unalz_le16toh(UINT16 a){return a;}
inline UINT32 unalz_le32toh(UINT32 a){return a;}
inline UINT64 unalz_le64toh(UINT64 a){return a;}
#endif
#if (defined(__FreeBSD__) || defined(__DARWIN__))
inline UINT16 unalz_le16toh(UINT16 a){return le16toh(a);}
inline UINT32 unalz_le32toh(UINT32 a){return le32toh(a);}
inline UINT64 unalz_le64toh(UINT64 a){return le64toh(a);}
#endif
#ifdef __linux__ // 리눅스에서 little 을 host 로 바꾸는 함수를 모르겠다.. 그래서 그냥 define 된걸로 판단한다.
# if __BYTE_ORDER == __BIG_ENDIAN
inline UINT16 unalz_le16toh(UINT16 a){return swapint16(a);}
inline UINT32 unalz_le32toh(UINT32 a){return swapint32(a);}
inline UINT64 unalz_le64toh(UINT64 a){return swapint64(a);}
# else // __LITTLE_ENDIAN
inline UINT16 unalz_le16toh(UINT16 a){return (a);}
inline UINT32 unalz_le32toh(UINT32 a){return (a);}
inline UINT64 unalz_le64toh(UINT64 a){return (a);}
# endif
#endif
#ifndef MAX_PATH
#define MAX_PATH 260
# define MAX_PATH 260
#endif
#ifdef _WIN32
#define PATHSEP "\\"
#define PATHSEPC '\\'
# define PATHSEP "\\"
# define PATHSEPC '\\'
#else
#define PATHSEP "/"
#define PATHSEPC '/'
# define PATHSEP "/"
# define PATHSEPC '/'
#endif
// error string table <- CUnAlz::ERR 의 번역
static const char* errorstrtable[]=
{
"no error", // ERR_NOERR
"can't open file", // ERR_CANT_OPEN_FILE
"can't read signature", // ERR_CANT_READ_SIG
"can't read file", // ERR_CANT_READ_FILE
"error at read header", // ERR_AT_READ_HEADER
"invalid filename length", // ERR_INVALID_FILENAME_LENGTH
"invalid extrafield length", // ERR_INVALID_EXTRAFIELD_LENGTH,
"can't read central directory structure head", // ERR_CANT_READ_CENTRAL_DIRECTORY_STRUCTURE_HEAD,
"invalid filename size", // ERR_INVALID_FILENAME_SIZE,
"invalid extrafield size", // ERR_INVALID_EXTRAFIELD_SIZE,
"invalid filecomment size", // ERR_INVALID_FILECOMMENT_SIZE,
"cant' read header", // ERR_CANT_READ_HEADER,
"memory allocation failed", // ERR_MEM_ALLOC_FAILED,
"file read eror", // ERR_FILE_READ_ERROR,
"inflate failed", // ERR_INFLATE_FAILED,
"iconv-can't open iconv", // ERR_ICONV_CANT_OPEN,
"iconv-invalid multisequence of characters", // ERR_ICONV_INVALID_MULTISEQUENCE_OF_CHARACTERS,
"iconv-incomplete multibyte sequence", // ERR_ICONV_INCOMPLETE_MULTIBYTE_SEQUENCE,
"iconv-not enough space of buffer to convert", // ERR_ICONV_NOT_ENOUGH_SPACE_OF_BUFFER_TO_CONVERT,
"iconv-etc", // ERR_ICONV_ETC,
};
////////////////////////////////////////////////////////////////////////////////////////////////////
/// ctor
/// @date 2004-03-06 오후 11:19:49
@ -37,6 +121,17 @@ CUnAlz::CUnAlz()
m_nVirtualFilePos = 0;
m_nCurFilePos = 0;
m_bIsEOF = FALSE;
#ifdef _UNALZ_ICONV
#ifdef _UNALZ_UTF8
strcpy(m_szToCodepage, "UTF-8") ; // 기본적으로 utf-8
#else
strcpy(m_szToCodepage, "CP949") ; // 기본적으로 CP949
#endif // _UNALZ_UTF8
strcpy(m_szFromCodepage, "CP949"); // alz 는 949 만 지원
#endif // _UNALZ_ICONV
}
////////////////////////////////////////////////////////////////////////////////////////////////////
@ -58,20 +153,41 @@ void CUnAlz::SetCallback(_UnAlzCallback* pFunc, void* param)
m_pCallbackParam = param;
}
#ifdef _WIN32
#ifndef __GNUWIN32__
////////////////////////////////////////////////////////////////////////////////////////////////////
/// 파일 열기
/// @param szPathName
/// @return
/// @date 2004-03-06 오후 11:03:59
////////////////////////////////////////////////////////////////////////////////////////////////////
#ifdef _WIN32
/*
#include <atlbase.h>
#include <atlconv.h>
BOOL CUnAlz::Open(LPCWSTR szPathName)
{
USES_CONVERSION;
return Open(W2A(szPathName));
}
*/
////////////////////////////////////////////////////////////////////////////////////////////////////
/// 대상 파일 세팅하기.
/// @param szFileName
/// @return
/// @date 2004-03-06 오후 11:06:20
////////////////////////////////////////////////////////////////////////////////////////////////////
BOOL CUnAlz::SetCurrentFile(LPCWSTR szFileName)
{
USES_CONVERSION;
return SetCurrentFile(W2A(szFileName));
}
BOOL CUnAlz::IsFolder(LPCWSTR szPathName)
{
UINT32 dwRet;
dwRet = GetFileAttributesW(szPathName);
if(dwRet==0xffffffff) return FALSE;
if(dwRet & FILE_ATTRIBUTE_DIRECTORY) return TRUE;
return FALSE;
}
#endif // __GNUWIN32__
#endif // _WIN32
BOOL CUnAlz::Open(const char* szPathName)
@ -95,7 +211,7 @@ BOOL CUnAlz::Open(const char* szPathName)
{
break;
}
if(sig==SIG_ERR)
if(sig==SIG_ERROR)
{
return FALSE; // 깨진 파일..
}
@ -149,17 +265,17 @@ void CUnAlz::Close()
////////////////////////////////////////////////////////////////////////////////////////////////////
CUnAlz::SIGNATURE CUnAlz::ReadSignature()
{
DWORD dwSig;
UINT32 dwSig;
if(FRead(&dwSig, sizeof(dwSig))==FALSE)
{
//int pos = ftell(m_fp);
if(FEof())
return SIG_EOF;
m_nErr = ERR_CANT_READ_SIG;
return SIG_ERR;
return SIG_ERROR;
}
return (SIGNATURE)dwSig;
return (SIGNATURE)unalz_le32toh(dwSig); // little to host;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
@ -210,6 +326,10 @@ BOOL CUnAlz::ReadLocalFileheader()
FRead(&(zipHeader.uncompressedSize), byteLen); // 압축 사이즈가 없다.
}
// little to system
zipHeader.head.fileNameLength = unalz_le16toh(zipHeader.head.fileNameLength);
zipHeader.compressedSize = unalz_le64toh(zipHeader.compressedSize);
zipHeader.uncompressedSize = unalz_le64toh(zipHeader.uncompressedSize);
// FILE NAME
zipHeader.fileName = (char*)malloc(zipHeader.head.fileNameLength+1);
@ -221,6 +341,68 @@ BOOL CUnAlz::ReadLocalFileheader()
FRead(zipHeader.fileName, zipHeader.head.fileNameLength);
zipHeader.fileName[zipHeader.head.fileNameLength] = (CHAR)NULL;
#ifdef _UNALZ_ICONV // codepage convert
if(strlen(m_szToCodepage))
{
#define ICONV_BUF_SIZE (260*6) // utf8 은 최대 6byte
size_t ileft, oleft;
iconv_t cd;
size_t iconv_result;
size_t size;
char inbuf[ICONV_BUF_SIZE];
char outbuf[ICONV_BUF_SIZE];
#ifdef __FreeBSD__
const char *inptr = inbuf;
#else
char *inptr = inbuf;
#endif
char *outptr = outbuf;
size = strlen(zipHeader.fileName)+1;
strncpy(inbuf, zipHeader.fileName, size);
ileft = size;
oleft = sizeof(outbuf);
cd = iconv_open(m_szToCodepage, m_szFromCodepage); // 보통 "CP949" 에서 "UTF-8" 로
iconv(cd, NULL, NULL, NULL, NULL);
if( cd == (iconv_t)(-1))
{
m_nErr = ERR_ICONV_CANT_OPEN; // printf("Converting Error : Cannot open iconv");
return FALSE;
}
else
{
iconv_result = iconv(cd, &inptr, &ileft, &outptr, &oleft);
if(iconv_result== (size_t)(-1)) // iconv 실패..
{
if (errno == EILSEQ)
m_nErr = ERR_ICONV_INVALID_MULTISEQUENCE_OF_CHARACTERS; // printf("Invalid Multibyte Sequence of Characters");
else if (errno == EINVAL)
m_nErr = ERR_ICONV_INCOMPLETE_MULTIBYTE_SEQUENCE; //printf("Incomplete multibyte sequence");
else if (errno != E2BIG)
m_nErr = ERR_ICONV_NOT_ENOUGH_SPACE_OF_BUFFER_TO_CONVERT; // printf("Not enough space of buffer to convert");
else
m_nErr = ERR_ICONV_ETC;
iconv_close(cd);
return FALSE;
}
else
{
outbuf[ICONV_BUF_SIZE-oleft] = 0;
strcpy(zipHeader.fileName, outbuf);
// printf("\n Converted File Name : %s", outbuf);
}
iconv_close(cd);
}
}
#endif
/*
// EXTRA FIELD LENGTH
if(zipHeader.head.extraFieldLength)
@ -345,21 +527,6 @@ BOOL CUnAlz::ReadEndofCentralDirectoryRecord()
return TRUE;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
/// ´ë»ó ÆÄÀÏ ¼¼ÆÃÇϱâ.
/// @param szFileName
/// @return
/// @date 2004-03-06 ¿ÀÈÄ 11:06:20
////////////////////////////////////////////////////////////////////////////////////////////////////
#ifdef _WIN32
/*
BOOL CUnAlz::SetCurrentFile(LPCWSTR szFileName)
{
USES_CONVERSION;
return SetCurrentFile(W2A(szFileName));
}
*/
#endif // _WIN32
BOOL CUnAlz::SetCurrentFile(const char* szFileName)
{
@ -431,6 +598,17 @@ BOOL CUnAlz::ExtractCurrentFile(const char* szDestPathName, const char* szDestFi
if(szDestFileName) strcat(szDestPathFileName, szDestFileName);
else strcat(szDestPathFileName, m_posCur->fileName);
#ifndef _WIN32
{
char* p = szDestPathFileName; // 경로 delimiter 바꾸기
while(*p)
{
if(*p=='\\') *p='/';
p++;
}
}
#endif
// 압축풀 대상 ( 파일 )
dest.nType = ET_FILE;
dest.fp = fopen(szDestPathFileName, "wb");
@ -441,6 +619,7 @@ BOOL CUnAlz::ExtractCurrentFile(const char* szDestPathName, const char* szDestFi
dest.fp = fopen(szDestPathFileName, "wb");
}
#ifdef _WIN32
if(dest.fp==NULL)
{
ASSERT(0);
@ -452,12 +631,12 @@ BOOL CUnAlz::ExtractCurrentFile(const char* szDestPathName, const char* szDestFi
}
return FALSE;
}
#endif
// CALLBACK 세팅
if(m_pFuncCallBack) m_pFuncCallBack(m_posCur->fileName, 0,0,m_pCallbackParam, NULL);
ret = ExtractTo(&dest);
fclose(dest.fp);
if(dest.fp!=NULL)fclose(dest.fp);
return ret;
}
@ -625,10 +804,8 @@ BOOL CUnAlz::DigPath(const char* szPathName)
#ifdef _WIN32
_mkdir(path);
#else
//printf("mkdir:%s\n", path);
mkdir(path, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
#endif
token = strtok( NULL, seps );
}
@ -646,7 +823,7 @@ BOOL CUnAlz::DigPath(const char* szPathName)
BOOL CUnAlz::IsFolder(LPCSTR szPathName)
{
#ifdef _WIN32
DWORD dwRet;
UINT32 dwRet;
dwRet = GetFileAttributesA(szPathName);
if(dwRet==0xffffffff) return FALSE;
if(dwRet & FILE_ATTRIBUTE_DIRECTORY) return TRUE;
@ -663,19 +840,6 @@ BOOL CUnAlz::IsFolder(LPCSTR szPathName)
return FALSE;
#endif
}
#ifdef _WIN32
/*
BOOL CUnAlz::IsFolder(LPCWSTR szPathName)
{
DWORD dwRet;
dwRet = GetFileAttributesW(szPathName);
if(dwRet==0xffffffff) return FALSE;
if(dwRet & FILE_ATTRIBUTE_DIRECTORY) return TRUE;
return FALSE;
}
*/
#endif // _WIN32
////////////////////////////////////////////////////////////////////////////////////////////////////
/// 압축을 풀 대상에 압축을 푼다.
@ -727,7 +891,7 @@ BOOL CUnAlz::ExtractBzip2_bak(FILE* fp, SLocalFileHeader& file)
//int err;
int flush=Z_SYNC_FLUSH;
BOOL ret = FALSE;
DWORD crc = 0xffffffff;
UINT32 crc = 0xffffffff;
//BYTE temp[100];
@ -968,7 +1132,7 @@ BOOL CUnAlz::ExtractDeflate2(SExtractDest* dest, SLocalFileHeader& file)
int flush=Z_SYNC_FLUSH;
BOOL ret = FALSE;
INT64 nRestReadCompressed;
DWORD dwCRC32= 0;
UINT32 dwCRC32= 0;
INT64 rest_read_uncompressed;
UINT iRead = 0;
INT64 nWritten = 0;
@ -1075,7 +1239,7 @@ BOOL CUnAlz::FOpen(const char* szPathName)
char* temp = strdup(szPathName); // 파일명 복사..
int i;
int nLen = strlen(szPathName);
DWORD dwFileSizeLow,dwFileSizeHigh;
UINT32 dwFileSizeLow,dwFileSizeHigh;
m_nFileCount = 0;
m_nCurFile = 0;
m_nVirtualFilePos = 0;
@ -1087,13 +1251,13 @@ BOOL CUnAlz::FOpen(const char* szPathName)
#ifdef _WIN32
m_files[i].fp = CreateFileA(temp, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL);
if(m_files[i].fp==INVALID_HANDLE_VALUE) break;
dwFileSizeLow = GetFileSize(m_files[i].fp, &dwFileSizeHigh);
dwFileSizeLow = GetFileSize(m_files[i].fp, (DWORD*)&dwFileSizeHigh);
#else
m_files[i].fp = fopen(temp, "rb");
if(m_files[i].fp==NULL) break;
dwFileSizeHigh=0;
fseek(m_files[i].fp,0,SEEK_END);
dwFileSizeLow=ftell(m_files[i].fp);
dwFileSizeLow=ftell(m_files[i].fp); // _LARGEFILE64_SOURCE 호환성 문제 발생.. T.T
fseek(m_files[i].fp,0,SEEK_SET);
#endif
m_nFileCount++;
@ -1201,13 +1365,13 @@ BOOL CUnAlz::FSeek(INT64 offset)
/// @return
/// @date 2004-10-02 오후 11:44:05
////////////////////////////////////////////////////////////////////////////////////////////////////
BOOL CUnAlz::FRead(void* buffer, DWORD nBytesToRead, int* pTotRead )
BOOL CUnAlz::FRead(void* buffer, UINT32 nBytesToRead, int* pTotRead )
{
BOOL ret;
DWORD nNumOfBytesRead;
UINT32 nNumOfBytesRead;
INT64 dwRemain;
DWORD dwRead;
DWORD dwTotRead;
UINT32 dwRead;
UINT32 dwTotRead;
dwRemain = nBytesToRead;
dwTotRead = 0;
@ -1215,12 +1379,12 @@ BOOL CUnAlz::FRead(void* buffer, DWORD nBytesToRead, int* pTotRead )
while(dwRemain)
{
dwRead = (DWORD)min(dwRemain, (m_files[m_nCurFile].nFileSize-m_nCurFilePos-m_files[m_nCurFile].nMultivolTailSize));
dwRead = (UINT32)min(dwRemain, (m_files[m_nCurFile].nFileSize-m_nCurFilePos-m_files[m_nCurFile].nMultivolTailSize));
if(dwRead==0) {
m_bIsEOF = TRUE;return FALSE;
}
#ifdef _WIN32
ret = ReadFile(m_files[m_nCurFile].fp, ((BYTE*)buffer)+dwTotRead, dwRead, &nNumOfBytesRead, NULL);
ret = ReadFile(m_files[m_nCurFile].fp, ((BYTE*)buffer)+dwTotRead, dwRead, (DWORD*)&nNumOfBytesRead, NULL);
if(ret==FALSE && GetLastError()==ERROR_HANDLE_EOF)
{
m_bIsEOF = TRUE;return FALSE;
@ -1274,3 +1438,14 @@ BOOL CUnAlz::FRead(void* buffer, DWORD nBytesToRead, int* pTotRead )
return ret;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
/// error code 를 스트링으로 바꿔 준다.
/// @param nERR
/// @return
/// @date 2004-10-24 오후 3:28:39
////////////////////////////////////////////////////////////////////////////////////////////////////
const char* CUnAlz::LastErrToStr(ERR nERR)
{
if(nERR>= sizeof(errorstrtable)/sizeof(errorstrtable[0])) {ASSERT(0); return NULL; }
return errorstrtable[nERR];
}

140
UnAlz.h
View file

@ -1,6 +1,7 @@
/*
COPYRIGHT(C) 2004 hardkoder@gmail.com / http://www.kipple.pe.kr
:
- // .
- , .
@ -17,11 +18,6 @@
bzip2 . )
- 4 .
:
- stdio
2GB WINDOWS I/O .
- , .
:
2004/02/06 - http://www.wotsit.org/ 에서 ZIP File Format Specification version 4.5 [PKWARE Inc.] 를
.
@ -34,21 +30,29 @@
- callback ..
2004/03/07 - ( ExtractCurrentFileToBuf() )
2004/10/03 - ( FILE I/O )
- 2GB
- 2GB (WINDOWS ONLY)
2004/10/22 - (BSD/LINUX)
( BSD/LINUX 2GB )
2004/10/23 - by xxfree86 : DARWIN , "\\"
2004/10/24 - by aqua0125 : , 64bit
- ,
2004/10/25 - by yongari : __LP64__ , (le64toh/le132oh/le16toh)
2004/10/26 - BSD/LINUX : byte-order, libiconv
:
- bzip2
- UI ( PROGRESS, , )
-
: ( * )
- bzip2 *
- UI ( PROGRESS, , ) *
- *
-
-
- CRC
:
- bzip2
- UI ( PROGRESS, , )
-
( -DXXXX )
- _WIN32 : WIN32
- _UNALZ_ICONV : iconv code
- _UNALZ_UTF8 : _UNALZ_ICONV "UTF-8"
*/
@ -68,9 +72,22 @@ using namespace std;
#endif
#endif
#ifndef DWORD
typedef unsigned long DWORD;
#endif // DWORD
#ifndef UINT64
#ifdef _WIN32
# define UINT64 unsigned __int64
#else
# define UINT64 unsigned long long
#endif
#endif
#ifndef UINT32
typedef unsigned int UINT32;
#endif
#ifndef UINT16
typedef unsigned short UINT16;
#endif
#ifndef SHORT
typedef short SHORT;
#endif
@ -116,9 +133,6 @@ using namespace std;
namespace UNALZ
{
@ -128,14 +142,14 @@ namespace UNALZ
# pragma pack(1)
#endif
static const char UNALZ_VERSION[] = "CUnAlz0.2";
static const char UNALZ_VERSION[] = "CUnAlz0.21";
static const char UNALZ_COPYRIGHT[] = "Copyright(C) 2004 hardkoder@gmail.com";
// 맨 파일 앞..
struct SAlzHeader
{
DWORD unknown; // ??
UINT32 unknown; // ??
};
/*
@ -174,9 +188,9 @@ struct _SLocalFileHeaderHead ///<
SHORT compressionMethod;
SHORT lastModFileTime;
SHORT lastModFileDate;
DWORD crc32;
DWORD compressedSize;
DWORD uncompressedSize;
UINT32 crc32;
UINT32 compressedSize;
UINT32 uncompressedSize;
SHORT fileNameLength;
SHORT extraFieldLength;
*/
@ -184,9 +198,9 @@ struct _SLocalFileHeaderHead ///<
struct _SDataDescriptor
{
DWORD crc32;
DWORD compressed;
DWORD uncompressed;
UINT32 crc32;
UINT32 compressed;
UINT32 uncompressed;
};
struct SLocalFileHeader
@ -198,7 +212,7 @@ struct SLocalFileHeader
BYTE compressionMethod; ///< 압축 방법 : 2 - deflate, 1 - bzip2(?), 0 - 압축 안함.
BYTE unknown3[1]; ///< ???
DWORD maybeCRC; ///< 아마도 crc
UINT32 maybeCRC; ///< 아마도 crc
INT64 compressedSize;
INT64 uncompressedSize;
@ -211,9 +225,9 @@ struct SLocalFileHeader
struct _SCentralDirectoryStructureHead
{
DWORD dwUnknown; ///< 항상 NULL 이던데..
DWORD dwMaybeCRC; ///< 아마도 crc
DWORD dwCLZ03; ///< "CLZ0x03" - 0x035a4c43 끝을 표시하는듯.
UINT32 dwUnknown; ///< 항상 NULL 이던데..
UINT32 dwMaybeCRC; ///< 아마도 crc
UINT32 dwCLZ03; ///< "CLZ0x03" - 0x035a4c43 끝을 표시하는듯.
/*
SHORT versionMadeBy;
SHORT versionNeededToExtract;
@ -221,16 +235,16 @@ struct _SCentralDirectoryStructureHead
SHORT compressionMethod;
SHORT lastModFileTime;
SHORT lastModFileDate;
DWORD crc32;
DWORD compressedSize;
DWORD uncompressedSize;
UINT32 crc32;
UINT32 compressedSize;
UINT32 uncompressedSize;
SHORT fileNameLength;
SHORT extraFieldLength;
SHORT fileCommentLength;
SHORT diskNumberStart;
SHORT internalFileAttributes;
DWORD externalFileAttributes;
DWORD relativeOffsetOfLocalHeader;
UINT32 externalFileAttributes;
UINT32 relativeOffsetOfLocalHeader;
*/
};
@ -254,8 +268,8 @@ struct _SEndOfCentralDirectoryRecordHead
SHORT numberOfTheDiskWithTheStartOfTheCentralDirectory;
SHORT centralDirectoryOnThisDisk;
SHORT totalNumberOfEntriesInTheCentralDirectoryOnThisDisk;
DWORD sizeOfTheCentralDirectory;
DWORD offsetOfStartOfCentralDirectoryWithREspectoTotheStartingDiskNumber;
UINT32 sizeOfTheCentralDirectory;
UINT32 offsetOfStartOfCentralDirectoryWithREspectoTotheStartingDiskNumber;
SHORT zipFileCommentLength;
};
*/
@ -271,9 +285,13 @@ struct SEndOfCentralDirectoryRecord
*/
#ifdef _WIN32
#pragma pack(pop, UNALZ) ///< PACKING 원상 복구
# pragma pack(pop, UNALZ) ///< PACKING 원상 복구
#else
#pragma pack(4)
# ifdef __LP64__ // 63bit 는 8byte 맞나 ? 잘모르겠다..
# pragma pack(8)
# else
# pragma pack(4)
# endif
#endif
@ -294,20 +312,28 @@ public:
BOOL ExtractAll(const char* szDestPathName);
void SetCallback(_UnAlzCallback* pFunc, void* param=NULL);
#ifdef _UNALZ_ICONV
void SetDestCodepage(const char* szToCodepage) { strcpy(m_szToCodepage, szToCodepage); }
#endif
public : ///< WIN32 전용 ( UNICODE 처리용 )
/*
#ifdef _WIN32
#ifndef __GNUWIN32__
#ifndef LPCWSTR
typedef const wchar_t* LPCWSTR;
#endif
BOOL Open(LPCWSTR szPathName);
BOOL SetCurrentFile(LPCWSTR szFileName);
static BOOL IsFolder(LPCWSTR szPathName);
#endif
*/
#endif // __GNUWIN32__
#endif // _WIN32
public :
typedef vector<SLocalFileHeader> FileList; ///< 파일 목록.
const FileList& GetFileList() { return m_fileList; }; ///< file 목록 리턴
FileList::iterator GetCurFileHeader() { return m_posCur; }; ///< 현재 (SetCurrentFile() 로 세팅된) 파일 정보
// const SLocalFileHeader* GetCurFileHeader() { return _posCur; }; ///< 현재 (SetCurrentFile() 로 세팅된) 파일 정보
// const SLocalFileHeader* GetCurFileHeader() { return m_posCur; }; ///< 현재 (SetCurrentFile() 로 세팅된) 파일 정보
public :
enum ERR ///< 에러 코드 - 정리 필요..
@ -328,12 +354,21 @@ public :
ERR_MEM_ALLOC_FAILED,
ERR_FILE_READ_ERROR,
ERR_INFLATE_FAILED,
ERR_ICONV_CANT_OPEN,
ERR_ICONV_INVALID_MULTISEQUENCE_OF_CHARACTERS,
ERR_ICONV_INCOMPLETE_MULTIBYTE_SEQUENCE,
ERR_ICONV_NOT_ENOUGH_SPACE_OF_BUFFER_TO_CONVERT,
ERR_ICONV_ETC,
};
ERR GetLastErr(){return m_nErr;}
const char* GetLastErrStr(){return LastErrToStr(m_nErr);}
const char* LastErrToStr(ERR nERR);
enum SIGNATURE ///< zip file signature
enum SIGNATURE ///< zip file signature - little endian
{
SIG_ERR = 0x00,
SIG_ERROR = 0x00,
SIG_EOF = 0x01,
SIG_ALZ_FILE_HEADER = 0x015a4c41, ///< ALZ 0x01
SIG_LOCAL_FILE_HEADER = 0x015a4c42, ///< BLZ 0x01
@ -366,8 +401,8 @@ private :
EXTRACT_TYPE nType; ///< 대상이 파일인가 메모리 인가..
FILE* fp; ///< ET_FILE 일 경우 대상 FILE*
BYTE* buf; ///< ET_MEM 일 경우 대상 포인터
DWORD bufsize; ///< ET_MEM 일 경우 대상 버퍼의 크기
DWORD bufpos; ///< ET_MEM 일 경우 대상 버퍼에 쓰고 있는 위치
UINT32 bufsize; ///< ET_MEM 일 경우 대상 버퍼의 크기
UINT32 bufpos; ///< ET_MEM 일 경우 대상 버퍼에 쓰고 있는 위치
};
int WriteToDest(SExtractDest* dest, BYTE* buf, int nSize);
@ -393,7 +428,7 @@ private : //
INT64 FTell();
BOOL FEof();
BOOL FSeek(INT64 offset);
BOOL FRead(void* buffer, DWORD nBytesToRead, int* pTotRead=NULL);
BOOL FRead(void* buffer, UINT32 nBytesToRead, int* pTotRead=NULL);
enum {MAX_FILES=1000}; ///< 처리 가능한 분할 압축 파일 수.
enum {MULTIVOL_TAIL_SIZE=16,MULTIVOL_HEAD_SIZE=8}; ///< 분할 압축시 꼴랑지, 헤더 크기
@ -420,6 +455,11 @@ private :
_UnAlzCallback* m_pFuncCallBack;
void* m_pCallbackParam;
BOOL m_bHalt;
#ifdef _UNALZ_ICONV
char m_szToCodepage[256]; ///< codepage
char m_szFromCodepage[256]; ///< "CP949"
#endif
};
}

View file

@ -27,11 +27,7 @@ typedef struct {
}
MybzFile;
#define BZ_SETERR(eee) \
{ \
if (bzerror != NULL) *bzerror = eee; \
if (bzf != NULL) bzf->lastErr = eee; \
}
#define BZ_SETERR(eee){if (bzerror != NULL) *bzerror = eee;if (bzf != NULL) bzf->lastErr = eee;}

BIN
bzip2/vssver.scc Normal file

Binary file not shown.

View file

@ -5,7 +5,18 @@
void Usage()
{
printf("\n");
#ifdef _UNALZ_ICONV
printf("USAGE : unalz [-utf8 | -cp949] sourcefile.alz [dest path] \n");
# ifdef _UNALZ_UTF8
printf(" -utf8 : convert filename's codepage to UTF-8 (default)\n");
printf(" -cp949 : convert filename's codepage to CP949\n");
# else
printf(" -utf8 : convert filename's codepage to UTF-8\n");
printf(" -cp949 : convert filename's codepage to CP949 (default)\n");
# endif // _UNALZ_UTF8
#else // no iconv
printf("USAGE : unalz sourcefile.alz [dest path] \n");
#endif // _UNALZ_ICONV
}
void UnAlzCallback(const char* szMessage, INT64 nCurrent, INT64 nRange, void* param, BOOL* bHalt)
@ -20,13 +31,12 @@ void UnAlzCallback(const char* szMessage, INT64 nCurrent, INT64 nRange, void* pa
// 파일명 출력..
if(szMessage)
{
printf("\n");
printf("Extracting : %s ", szMessage);
//printf("\n");
printf("unalziiiing : %s ", szMessage);
nPrevPercent = -1;
return ;
}
percent = nCurrent*100/nRange;
if(nPrevPercent==percent) return; // 너무 잦은 업데이트 방지..
@ -34,53 +44,80 @@ void UnAlzCallback(const char* szMessage, INT64 nCurrent, INT64 nRange, void* pa
#ifdef _WIN32
sprintf(buf, "%I64d/%I64d (%I64d%%)", nCurrent, nRange, percent);
#else
sprintf(buf, "%d/%d (%d%%)", (int)nCurrent, (int)nRange, (int)percent);
sprintf(buf, "%d/%d (%d%%)", (int)nCurrent, (int)nRange, (int)percent); // int64 를 출력할라면 어찌해야 되는지?
#endif
printf("%s", buf);
puts(buf);
buflen = strlen(buf);
fflush(stdout);
for(i=0;i<buflen;i++)
printf("\b");
for(i=0;i<buflen;i++) printf("\b");
}
int main(int argc, char* argv[])
{
printf("unalz v0.20 (2004/10/22) \n");
// printf("unalz v0.20 (2004/10/22) \n");
printf("unalz v0.22 (2004/10/28) \n");
printf("copyright(C) 2004 http://www.kipple.pe.kr\n");
if(argc<2)
{
Usage();
return 0;
}
char* source = argv[1];
char* dest = argv[2];
if(argc<3) dest="."; // current dir
else dest = argv[2];
CUnAlz unalz;
char* source=NULL;
char* destpath=".";
char* destcodepage=NULL;
int count=1;
// utf8 옵션 처리
#ifdef _UNALZ_ICONV
if(strcmp(argv[count], "-utf8")==0)
{
destcodepage = "UTF-8"; // utf-8 support
count++;
}
else if(strcmp(argv[count], "-cp949")==0)
{
destcodepage = "CP949"; // cp959
count++;
}
if(count>=argc) {Usage();return 0;} // 옵션만 쓰면 어쩌라고..
if(destcodepage) unalz.SetDestCodepage(destcodepage);
#endif
// 소스 파일
source=argv[count];
count++;
// 대상 경로
if(count<argc)
{
destpath = argv[count];
count++;
}
// 파일 열기
if(unalz.Open(source)==FALSE)
{
printf("file open error : %s\nerr code(%d)\n", source,unalz.GetLastErr());
printf("file open error : %s\n", source);
printf("err code(%d) (%s)\n", unalz.GetLastErr(), unalz.GetLastErrStr());
return 0;
}
printf("\nExtract %s to %s\n", source, dest);
printf("\nExtract %s to %s\n", source, destpath);
// callback 함수 세팅
unalz.SetCallback(UnAlzCallback, (void*)NULL);
if(unalz.ExtractAll(dest)==FALSE)
if(unalz.ExtractAll(destpath)==FALSE)
{
printf("extract %s to %s failed.\n", source, dest);
printf("extract %s to %s failed.\n", source, destpath);
printf("err code(%d) (%s)\n", unalz.GetLastErr(), unalz.GetLastErrStr());
}
printf("\ndone..\n");

View file

@ -1,29 +1,65 @@
CPP = g++
CC = gcc
OBJ = main.o UnAlz.o UnAlzBz2decompress.o UnAlzBzip2.o UnAlzbzlib.o zlib/adler32.o zlib/crc32.o zlib/infblock.o zlib/infcodes.o zlib/inffast.o zlib/inflate.o zlib/inftrees.o zlib/infutil.o zlib/zutil.o bzip2/blocksort.o bzip2/compress.o bzip2/crctable.o bzip2/huffman.o bzip2/randtable.o
OBJ = UnAlzBz2decompress.o UnAlzBzip2.o UnAlzbzlib.o zlib/adler32.o zlib/crc32.o zlib/infblock.o zlib/infcodes.o zlib/inffast.o zlib/inflate.o zlib/inftrees.o zlib/infutil.o zlib/zutil.o bzip2/blocksort.o bzip2/compress.o bzip2/crctable.o bzip2/huffman.o bzip2/randtable.o
LINKOBJ = main.o UnAlz.o UnAlzBz2decompress.o UnAlzBzip2.o UnAlzbzlib.o zlib/adler32.o zlib/crc32.o zlib/infblock.o zlib/infcodes.o zlib/inffast.o zlib/inflate.o zlib/inftrees.o zlib/infutil.o zlib/zutil.o bzip2/blocksort.o bzip2/compress.o bzip2/crctable.o bzip2/huffman.o bzip2/randtable.o
BIN = unalz
CFLAGS =
CFLAGS = -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
LDFLAGS=
#CFLAGS = -DDARWIN
#LDFLAGS=-liconv
SRCS=main.cpp UnAlz.cpp UnAlzBz2decompress.c UnAlzBzip2.cpp UnAlzbzlib.c
#nothing:
all:
@echo ""
@echo "USAGE : make TARGET_SYSTEM"
@echo ""
@echo ""
@echo "TARGET_SYSTEM is one of"
@echo ""
@echo " posix : POSIX system (FreeBSD/linux/OSX/sparc)"
@echo " posix-utf8 : POSIX with utf8 filesystem(OSX)"
@echo " posix-noiconv : POSIX without libiconv (CP949 only)"
@echo ""
@echo " and 'clean' for clean"
@echo ""
posix: unalz
$(CPP) -c UnAlz.cpp -c main.cpp $(CFLAGS) -D_UNALZ_ICONV
$(CPP) $(LINKOBJ) $(LDFLAGS) -liconv -o $(BIN)
posix-utf8: unalz
$(CPP) -c UnAlz.cpp -c main.cpp $(CFLAGS) -D_UNALZ_ICONV -D_UNALZ_UTF8
$(CPP) $(LINKOBJ) $(LDFLAGS) -liconv -o $(BIN)
posix-noiconv: unalz
$(CPP) -c UnAlz.cpp -c main.cpp $(CFLAGS)
$(CPP) $(LINKOBJ) $(LDFLAGS) -o $(BIN)
all: unalz
clean:
rm -f $(OBJ) $(BIN)
rm -f $(OBJ) $(BIN) main.o UnAlz.o
$(BIN): $(OBJ)
$(CPP) $(LINKOBJ) -o "unalz"
# $(CPP) $(LINKOBJ) $(LDFLAGS) -o $(BIN)
main.o: main.cpp
$(CPP) -c main.cpp -o main.o
#UnAlz.o: UnAlz.cpp
# $(CPP) -c UnAlz.cpp -o UnAlz.o $(CFLAGS)
UnAlz.o: UnAlz.cpp
$(CPP) -c UnAlz.cpp -o UnAlz.o
#main.o: main.cpp
# $(CPP) -c main.cpp -o main.o $(CFLAGS)
UnAlzBz2decompress.o: UnAlzBz2decompress.c
$(CC) -c UnAlzBz2decompress.c -o UnAlzBz2decompress.o $(CFLAGS)
UnAlzBzip2.o: UnAlzBzip2.cpp
$(CPP) -c UnAlzBzip2.cpp -o UnAlzBzip2.o
$(CPP) -c UnAlzBzip2.cpp -o UnAlzBzip2.o $(CFLAGS)
UnAlzbzlib.o: UnAlzbzlib.c
$(CC) -c UnAlzbzlib.c -o UnAlzbzlib.o $(CFLAGS)

10
makefile.freebsd Normal file
View file

@ -0,0 +1,10 @@
# $FreeBSD$
PROG= unalz
NOMAN=
SRCS= main.cpp UnAlz.cpp UnAlzBz2decompress.c UnAlzBzip2.cpp \
UnAlzbzlib.c
LDADD+= -lz -lbz2 -liconv -lstdc++
.include <bsd.prog.mk>

View file

@ -1,18 +1,21 @@
unalz v0.2
unalz v0.22
copyright(C) 2004 http://www.kipple.pe.kr
- 최종 갱신일 : 2004/10/22
- 최초 작성일 : v0.20 - 2004/10/22
- 최종 갱신일 : v0.22 - 2004/10/28
- 기능
. alz 파일 압축 해제 프로그램
. deflate/변형 bzip2/raw 포맷 지원
. 분할 압축 파일 지원
. WIN32(VC60/VC70/DEV-C++) , Free-BSD/LINUX(gcc/g++) 지원
. 0.22 - SIG_ERR 관련 문제점 수정,
- 빅엔디안 시스템(OSX) 지원
- UTF-8 파일 시스템을 위한 코드 페이지 옵션 기능 지원
- 라이선스
. 자유로이 변형/배포 가능 (BSD-license)

View file

@ -9,7 +9,7 @@ CppCompiler=-D__GNUWIN32__ -W -DWIN32 -DNDEBUG -D_CONSOLE -D_MBCS_@@_
Includes=
Linker=-lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -luuid -lodbc32 -lodbccp32 -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -luuid -lodbc32 -lodbccp32_@@_
Libs=
UnitCount=32
UnitCount=31
Folders=bzip2,main,unalz,zlib
ObjFiles=
PrivateResource=
@ -230,16 +230,6 @@ OverrideBuildCmd=0
BuildCmd=
[Unit21]
FileName=zlib\uncompr.c
Folder=zlib
Compile=1
CompileCpp=0
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=
[Unit22]
FileName=zlib\ZCONF.H
Folder=zlib
Compile=1
@ -249,7 +239,7 @@ Priority=1000
OverrideBuildCmd=0
BuildCmd=
[Unit23]
[Unit22]
FileName=zlib\ZLIB.H
Folder=zlib
Compile=1
@ -259,7 +249,7 @@ Priority=1000
OverrideBuildCmd=0
BuildCmd=
[Unit24]
[Unit23]
FileName=zlib\zutil.c
Folder=zlib
Compile=1
@ -269,7 +259,7 @@ Priority=1000
OverrideBuildCmd=0
BuildCmd=
[Unit25]
[Unit24]
FileName=zlib\ZUTIL.H
Folder=zlib
Compile=1
@ -279,7 +269,7 @@ Priority=1000
OverrideBuildCmd=0
BuildCmd=
[Unit26]
[Unit25]
FileName=bzip2\blocksort.c
Folder=bzip2
Compile=1
@ -289,7 +279,7 @@ Priority=1000
OverrideBuildCmd=0
BuildCmd=
[Unit27]
[Unit26]
FileName=bzip2\bzlib.h
Folder=bzip2
Compile=1
@ -299,7 +289,7 @@ Priority=1000
OverrideBuildCmd=0
BuildCmd=
[Unit28]
[Unit27]
FileName=bzip2\bzlib_private.h
Folder=bzip2
Compile=1
@ -309,7 +299,7 @@ Priority=1000
OverrideBuildCmd=0
BuildCmd=
[Unit29]
[Unit28]
FileName=bzip2\compress.c
Folder=bzip2
Compile=1
@ -319,7 +309,7 @@ Priority=1000
OverrideBuildCmd=0
BuildCmd=
[Unit30]
[Unit29]
FileName=bzip2\crctable.c
Folder=bzip2
Compile=1
@ -329,7 +319,7 @@ Priority=1000
OverrideBuildCmd=0
BuildCmd=
[Unit31]
[Unit30]
FileName=bzip2\huffman.c
Folder=bzip2
Compile=1
@ -339,6 +329,16 @@ Priority=1000
OverrideBuildCmd=0
BuildCmd=
[Unit31]
FileName=bzip2\randtable.c
Folder=bzip2
Compile=1
CompileCpp=0
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=
[Unit32]
FileName=bzip2\randtable.c
Folder=bzip2

View file

@ -66,7 +66,7 @@ LINK32=link.exe
# PROP Ignore_Export_Lib 0
# 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 CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FR /YX /FD /GZ /c
# ADD BASE RSC /l 0x412 /d "_DEBUG"
# ADD RSC /l 0x412 /d "_DEBUG"
BSC32=bscmake.exe

BIN
zlib/vssver.scc Normal file

Binary file not shown.