From 35c0b24c920b5eebea2a5594b0dbe8a7fa81c2c2 Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Tue, 5 May 2020 20:22:31 +0200 Subject: [PATCH] v0.22 --- Makefile.win | 7 +- UnAlz.cpp | 295 +++++++++++++++++++++++++++++++-------- UnAlz.h | 158 +++++++++++++-------- UnAlzBzip2.cpp | 356 +++++++++++++++++++++++------------------------ bzip2/vssver.scc | Bin 0 -> 144 bytes main.cpp | 81 ++++++++--- makefile | 56 ++++++-- makefile.freebsd | 10 ++ readme.txt | 9 +- unalz.dev | 40 +++--- unalz.dsp | 2 +- zlib/vssver.scc | Bin 0 -> 320 bytes 12 files changed, 654 insertions(+), 360 deletions(-) create mode 100644 bzip2/vssver.scc create mode 100644 makefile.freebsd create mode 100644 zlib/vssver.scc diff --git a/Makefile.win b/Makefile.win index 7f97f6b..b21f12f 100644 --- a/Makefile.win +++ b/Makefile.win @@ -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) diff --git a/UnAlz.cpp b/UnAlz.cpp index 35c150c..71928e1 100644 --- a/UnAlz.cpp +++ b/UnAlz.cpp @@ -2,24 +2,108 @@ #include "zlib/zlib.h" #include "bzip2/bzlib.h" #include "UnAlz.h" -#ifdef _WIN32 -#include // mkdir + +// mkdir +#ifdef _WIN32 +# include #else -#include +# include #endif +// le16toh µîµî.. +#if (defined(__FreeBSD__) || defined(__DARWIN__)) +# include +#endif + +#ifdef __linux__ // __BYTE_ORDER °¡Á®¿À±â +# include +#endif + +#ifdef _UNALZ_ICONV // code page support +# include +#endif + +#ifdef __linux__ // iconv.h ¶§¹®¿¡ ÇÊ¿ä +# include +#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 +#include 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); + fseek(m_files[i].fp,0,SEEK_END); + 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]; +} diff --git a/UnAlz.h b/UnAlz.h index ec1af8f..e554d35 100644 --- a/UnAlz.h +++ b/UnAlz.h @@ -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 ÀÌ»óÀÇ ÆÄÀÏ Ã³¸® Áö¿ø - - ÇÒÀÏ : - - bzip2 ·Î ¾ÐÃàµÈ ÆÄÀÏÀÇ ¾ÐÃà ÇØÁ¦ - - UI °³¼± ( PROGRESS, ¿¡·¯ ¸Þ½ÃÁö Ãâ·Â, ¾ÐÃà ÇØÁ¦ °á°ú ) - - ºÐÇÒ ¾ÐÃà ÆÄÀÏ Áö¿ø + - 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, ¿¡·¯ ¸Þ½ÃÁö Ãâ·Â, ¾ÐÃà ÇØÁ¦ °á°ú ) * + - ºÐÇÒ ¾ÐÃà ÆÄÀÏ Áö¿ø * - ¾ÏÈ£ °É¸° ÆÄÀÏ Áö¿ø - ¼Õ»óµÈ ÆÄÀÏ¿¡¼­ÀÇ Á»´õ ¸¹Àº Å×½ºÆ® - ÆÄÀÏ 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 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}; ///< ºÐÇÒ ¾ÐÃà½Ã ²Ã¶ûÁö, Çì´õ Å©±â @@ -405,21 +440,26 @@ private : // int nMultivolTailSize; }; - SFile m_files[MAX_FILES]; ///< ºÐÇÒ ÆÄÀÏ ÀúÀå array - ¹«½ÄÇÑ°¡? - int m_nCurFile; ///< m_files ¿¡¼­ ÇöÀç ó¸®ÁßÀÎ ÆÄÀÏÀÇ À§Ä¡. - int m_nFileCount; ///< ºÐÇÒ ÆÄÀÏ °¹¼ö.. - INT64 m_nVirtualFilePos; ///< ¸ÖƼº¼·ý¿¡¼­ÀÇ °¡»óÀÇ À§Ä¡ - INT64 m_nCurFilePos; ///< ÇöÀç ÆÄÀÏÀÇ ¹°¸®Àû À§Ä¡. - BOOL m_bIsEOF; ///< ÆÄÀÏÀÇ ³¡±îÁö (ºÐÇÒ ÆÄÀÏ Æ÷ÇÔÇؼ­) ¿Ô³ª? + SFile m_files[MAX_FILES]; ///< ºÐÇÒ ÆÄÀÏ ÀúÀå array - ¹«½ÄÇÑ°¡? + int m_nCurFile; ///< m_files ¿¡¼­ ÇöÀç ó¸®ÁßÀÎ ÆÄÀÏÀÇ À§Ä¡. + int m_nFileCount; ///< ºÐÇÒ ÆÄÀÏ °¹¼ö.. + INT64 m_nVirtualFilePos; ///< ¸ÖƼº¼·ý¿¡¼­ÀÇ °¡»óÀÇ À§Ä¡ + INT64 m_nCurFilePos; ///< ÇöÀç ÆÄÀÏÀÇ ¹°¸®Àû À§Ä¡. + BOOL m_bIsEOF; ///< ÆÄÀÏÀÇ ³¡±îÁö (ºÐÇÒ ÆÄÀÏ Æ÷ÇÔÇؼ­) ¿Ô³ª? private : - FileList m_fileList; ///< ¾ÐÃàÆÄÀÏ ³»ÀÇ ÆÄÀÏ ¸ñ·Ï + FileList m_fileList; ///< ¾ÐÃàÆÄÀÏ ³»ÀÇ ÆÄÀÏ ¸ñ·Ï ERR m_nErr; - FileList::iterator m_posCur; ///< ÇöÀç ÆÄÀÏ + FileList::iterator m_posCur; ///< ÇöÀç ÆÄÀÏ _UnAlzCallback* m_pFuncCallBack; void* m_pCallbackParam; BOOL m_bHalt; + +#ifdef _UNALZ_ICONV + char m_szToCodepage[256]; ///< codepage + char m_szFromCodepage[256]; ///< "CP949" +#endif }; } diff --git a/UnAlzBzip2.cpp b/UnAlzBzip2.cpp index 0f81958..d519d19 100644 --- a/UnAlzBzip2.cpp +++ b/UnAlzBzip2.cpp @@ -1,180 +1,176 @@ -//////////////////////////////////////////////////////////////////////////////////////////////////// -/// -/// bzip2 °ü·Ã file i/o ÇÔ¼öµé - ¿ø·¡ UnAlzbzlib.c (bzlib.c) ¿¡ ÀÖ´ø ÇÔ¼öµéÀº ºÐÇÒ ¾ÐÃà 󸮸¦ À§Çؼ­ -/// ¾à°£ÀÇ ¼öÁ¤À» °¡ÇÑ ¼Ò½ºµéÀÌ´Ù.. -/// FILE* handle °ü·Ã ºÎºÐµéÀÌ ¼öÁ¤µÇ¾ú´Ù. -/// -/// @author hardkoder@gmail.com -/// @date 2004-10-03 ¿ÀÈÄ 3:09:11 -/// -//////////////////////////////////////////////////////////////////////////////////////////////////// - -//#include "stdafx.h" -#include "zlib/zlib.h" -#include "bzip2/bzlib.h" -#include "bzip2/bzlib_private.h" -#include "UnAlz.h" - - -typedef struct { - CUnAlz* handle; - Char buf[BZ_MAX_UNUSED]; - Int32 bufN; - Bool writing; - bz_stream strm; - Int32 lastErr; - Bool initialisedOk; -} -MybzFile; - -#define BZ_SETERR(eee) \ -{ \ - if (bzerror != NULL) *bzerror = eee; \ - if (bzf != NULL) bzf->lastErr = eee; \ -} - - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -/// BZIP2 ÆÄÀÏ Ã³¸® ÇÔ¼ö -/// @param bzerror -/// @param f -/// @param verbosity -/// @param _small -/// @param unused -/// @param nUnused -/// @return -/// @date 2004-10-03 ¿ÀÀü 3:16:45 -//////////////////////////////////////////////////////////////////////////////////////////////////// -CUnAlz::MYBZFILE* CUnAlz::BZ2_bzReadOpen(int* bzerror, CUnAlz* f, int verbosity, int _small,void* unused, int nUnused) -{ - MybzFile* bzf = NULL; - int ret; - - BZ_SETERR(BZ_OK); - - if (f == NULL || - (_small != 0 && _small != 1) || - (verbosity < 0 || verbosity > 4) || - (unused == NULL && nUnused != 0) || - (unused != NULL && (nUnused < 0 || nUnused > BZ_MAX_UNUSED))) - { BZ_SETERR(BZ_PARAM_ERROR); return NULL; }; - -// if (f->FEof()) -// { BZ_SETERR(BZ_IO_ERROR); return NULL; }; - - bzf = (MybzFile*)malloc ( sizeof(MybzFile) ); - if (bzf == NULL) - { BZ_SETERR(BZ_MEM_ERROR); return NULL; }; - - BZ_SETERR(BZ_OK); - - bzf->initialisedOk = False; - bzf->handle = f; - bzf->bufN = 0; - bzf->writing = False; - bzf->strm.bzalloc = NULL; - bzf->strm.bzfree = NULL; - bzf->strm.opaque = NULL; - - while (nUnused > 0) { - bzf->buf[bzf->bufN] = *((UChar*)(unused)); bzf->bufN++; - unused = ((void*)( 1 + ((UChar*)(unused)) )); - nUnused--; - } - - ret = BZ2_bzDecompressInit ( &(bzf->strm), verbosity, _small ); - if (ret != BZ_OK) - { BZ_SETERR(ret); free(bzf); return NULL; }; - - bzf->strm.avail_in = bzf->bufN; - bzf->strm.next_in = bzf->buf; - - bzf->initialisedOk = True; - return bzf; -} - - -int CUnAlz::BZ2_bzread(MYBZFILE* b, void* buf, int len ) -{ - int bzerr, nread; - if (((MybzFile*)b)->lastErr == BZ_STREAM_END) return 0; - nread = BZ2_bzRead(&bzerr,b,buf,len); - if (bzerr == BZ_OK || bzerr == BZ_STREAM_END) { - return nread; - } else { - return -1; - } -} - - -int CUnAlz::BZ2_bzRead(int* bzerror, MYBZFILE* b, void* buf, int len) -{ - Int32 n, ret; - MybzFile* bzf = (MybzFile*)b; - - BZ_SETERR(BZ_OK); - - if (bzf == NULL || buf == NULL || len < 0) - { BZ_SETERR(BZ_PARAM_ERROR); return 0; }; - - if (bzf->writing) - { BZ_SETERR(BZ_SEQUENCE_ERROR); return 0; }; - - if (len == 0) - { BZ_SETERR(BZ_OK); return 0; }; - - bzf->strm.avail_out = len; - bzf->strm.next_out = (char*)buf; - - while (True) { - -// if (ferror(bzf->handle)) -// { BZ_SETERR(BZ_IO_ERROR); return 0; }; - - if (bzf->strm.avail_in == 0 && !bzf->handle->FEof()) { - bzf->handle->FRead(bzf->buf, sizeof(UChar)*BZ_MAX_UNUSED, &n); - - if(n==0) - { BZ_SETERR(BZ_IO_ERROR); return 0; }; - bzf->bufN = n; - bzf->strm.avail_in = bzf->bufN; - bzf->strm.next_in = bzf->buf; - } - - ret = BZ2_bzDecompress ( &(bzf->strm) ); - - if (ret != BZ_OK && ret != BZ_STREAM_END) - { BZ_SETERR(ret); return 0; }; - - if (ret == BZ_OK && bzf->handle->FEof() && - bzf->strm.avail_in == 0 && bzf->strm.avail_out > 0) - { BZ_SETERR(BZ_UNEXPECTED_EOF); return 0; }; - - if (ret == BZ_STREAM_END) - { BZ_SETERR(BZ_STREAM_END); - return len - bzf->strm.avail_out; }; - if (bzf->strm.avail_out == 0) - { BZ_SETERR(BZ_OK); return len; }; - - } - - return 0; /*not reached*/ -} - -void CUnAlz::BZ2_bzReadClose( int *bzerror, MYBZFILE *b ) -{ - MybzFile* bzf = (MybzFile*)b; - - BZ_SETERR(BZ_OK); - if (bzf == NULL) - { BZ_SETERR(BZ_OK); return; }; - - if (bzf->writing) - { BZ_SETERR(BZ_SEQUENCE_ERROR); return; }; - - if (bzf->initialisedOk) - (void)BZ2_bzDecompressEnd ( &(bzf->strm) ); - free ( bzf ); -} - +//////////////////////////////////////////////////////////////////////////////////////////////////// +/// +/// bzip2 °ü·Ã file i/o ÇÔ¼öµé - ¿ø·¡ UnAlzbzlib.c (bzlib.c) ¿¡ ÀÖ´ø ÇÔ¼öµéÀº ºÐÇÒ ¾ÐÃà 󸮸¦ À§Çؼ­ +/// ¾à°£ÀÇ ¼öÁ¤À» °¡ÇÑ ¼Ò½ºµéÀÌ´Ù.. +/// FILE* handle °ü·Ã ºÎºÐµéÀÌ ¼öÁ¤µÇ¾ú´Ù. +/// +/// @author hardkoder@gmail.com +/// @date 2004-10-03 ¿ÀÈÄ 3:09:11 +/// +//////////////////////////////////////////////////////////////////////////////////////////////////// + +//#include "stdafx.h" +#include "zlib/zlib.h" +#include "bzip2/bzlib.h" +#include "bzip2/bzlib_private.h" +#include "UnAlz.h" + + +typedef struct { + CUnAlz* handle; + Char buf[BZ_MAX_UNUSED]; + Int32 bufN; + Bool writing; + bz_stream strm; + Int32 lastErr; + Bool initialisedOk; +} +MybzFile; + +#define BZ_SETERR(eee){if (bzerror != NULL) *bzerror = eee;if (bzf != NULL) bzf->lastErr = eee;} + + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +/// BZIP2 ÆÄÀÏ Ã³¸® ÇÔ¼ö +/// @param bzerror +/// @param f +/// @param verbosity +/// @param _small +/// @param unused +/// @param nUnused +/// @return +/// @date 2004-10-03 ¿ÀÀü 3:16:45 +//////////////////////////////////////////////////////////////////////////////////////////////////// +CUnAlz::MYBZFILE* CUnAlz::BZ2_bzReadOpen(int* bzerror, CUnAlz* f, int verbosity, int _small,void* unused, int nUnused) +{ + MybzFile* bzf = NULL; + int ret; + + BZ_SETERR(BZ_OK); + + if (f == NULL || + (_small != 0 && _small != 1) || + (verbosity < 0 || verbosity > 4) || + (unused == NULL && nUnused != 0) || + (unused != NULL && (nUnused < 0 || nUnused > BZ_MAX_UNUSED))) + { BZ_SETERR(BZ_PARAM_ERROR); return NULL; }; + +// if (f->FEof()) +// { BZ_SETERR(BZ_IO_ERROR); return NULL; }; + + bzf = (MybzFile*)malloc ( sizeof(MybzFile) ); + if (bzf == NULL) + { BZ_SETERR(BZ_MEM_ERROR); return NULL; }; + + BZ_SETERR(BZ_OK); + + bzf->initialisedOk = False; + bzf->handle = f; + bzf->bufN = 0; + bzf->writing = False; + bzf->strm.bzalloc = NULL; + bzf->strm.bzfree = NULL; + bzf->strm.opaque = NULL; + + while (nUnused > 0) { + bzf->buf[bzf->bufN] = *((UChar*)(unused)); bzf->bufN++; + unused = ((void*)( 1 + ((UChar*)(unused)) )); + nUnused--; + } + + ret = BZ2_bzDecompressInit ( &(bzf->strm), verbosity, _small ); + if (ret != BZ_OK) + { BZ_SETERR(ret); free(bzf); return NULL; }; + + bzf->strm.avail_in = bzf->bufN; + bzf->strm.next_in = bzf->buf; + + bzf->initialisedOk = True; + return bzf; +} + + +int CUnAlz::BZ2_bzread(MYBZFILE* b, void* buf, int len ) +{ + int bzerr, nread; + if (((MybzFile*)b)->lastErr == BZ_STREAM_END) return 0; + nread = BZ2_bzRead(&bzerr,b,buf,len); + if (bzerr == BZ_OK || bzerr == BZ_STREAM_END) { + return nread; + } else { + return -1; + } +} + + +int CUnAlz::BZ2_bzRead(int* bzerror, MYBZFILE* b, void* buf, int len) +{ + Int32 n, ret; + MybzFile* bzf = (MybzFile*)b; + + BZ_SETERR(BZ_OK); + + if (bzf == NULL || buf == NULL || len < 0) + { BZ_SETERR(BZ_PARAM_ERROR); return 0; }; + + if (bzf->writing) + { BZ_SETERR(BZ_SEQUENCE_ERROR); return 0; }; + + if (len == 0) + { BZ_SETERR(BZ_OK); return 0; }; + + bzf->strm.avail_out = len; + bzf->strm.next_out = (char*)buf; + + while (True) { + +// if (ferror(bzf->handle)) +// { BZ_SETERR(BZ_IO_ERROR); return 0; }; + + if (bzf->strm.avail_in == 0 && !bzf->handle->FEof()) { + bzf->handle->FRead(bzf->buf, sizeof(UChar)*BZ_MAX_UNUSED, &n); + + if(n==0) + { BZ_SETERR(BZ_IO_ERROR); return 0; }; + bzf->bufN = n; + bzf->strm.avail_in = bzf->bufN; + bzf->strm.next_in = bzf->buf; + } + + ret = BZ2_bzDecompress ( &(bzf->strm) ); + + if (ret != BZ_OK && ret != BZ_STREAM_END) + { BZ_SETERR(ret); return 0; }; + + if (ret == BZ_OK && bzf->handle->FEof() && + bzf->strm.avail_in == 0 && bzf->strm.avail_out > 0) + { BZ_SETERR(BZ_UNEXPECTED_EOF); return 0; }; + + if (ret == BZ_STREAM_END) + { BZ_SETERR(BZ_STREAM_END); + return len - bzf->strm.avail_out; }; + if (bzf->strm.avail_out == 0) + { BZ_SETERR(BZ_OK); return len; }; + + } + + return 0; /*not reached*/ +} + +void CUnAlz::BZ2_bzReadClose( int *bzerror, MYBZFILE *b ) +{ + MybzFile* bzf = (MybzFile*)b; + + BZ_SETERR(BZ_OK); + if (bzf == NULL) + { BZ_SETERR(BZ_OK); return; }; + + if (bzf->writing) + { BZ_SETERR(BZ_SEQUENCE_ERROR); return; }; + + if (bzf->initialisedOk) + (void)BZ2_bzDecompressEnd ( &(bzf->strm) ); + free ( bzf ); +} + diff --git a/bzip2/vssver.scc b/bzip2/vssver.scc new file mode 100644 index 0000000000000000000000000000000000000000..d8a26a34b417a66e27b2cf04a6574f2548d8d9cd GIT binary patch literal 144 zcmXpJVq}o$H#QZpXL9PlTX*Jb%`f%sJGY+|WMu$@w@eHSy19ZsI(d;s#F zhy`$UPN=argc) {Usage();return 0;} // ¿É¼Ç¸¸ ¾²¸é ¾î¼¶ó°í.. + + if(destcodepage) unalz.SetDestCodepage(destcodepage); +#endif + + // ¼Ò½º ÆÄÀÏ + source=argv[count]; + count++; + + // ´ë»ó °æ·Î + if(count + diff --git a/readme.txt b/readme.txt index 01c0a83..ff8ffaa 100644 --- a/readme.txt +++ b/readme.txt @@ -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) diff --git a/unalz.dev b/unalz.dev index ede1956..6617fe3 100644 --- a/unalz.dev +++ b/unalz.dev @@ -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 diff --git a/unalz.dsp b/unalz.dsp index 2b9855a..c643ee9 100644 --- a/unalz.dsp +++ b/unalz.dsp @@ -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 diff --git a/zlib/vssver.scc b/zlib/vssver.scc new file mode 100644 index 0000000000000000000000000000000000000000..2116ac560415b268bc51a294648333e72286f9ec GIT binary patch literal 320 zcmXpJVq}o$H#QZpXL9PlTX*Jb%`f%ON>2PjtPEgqgo%OS@UJC0U8mlOU(=qi%!1MzPI`D-Oy?sU1Hn*ie90rH(^er1O7?*jRnbA{x)<|eNJ$pZk@ C|8GM8 literal 0 HcmV?d00001