This commit is contained in:
King_DuckZ 2020-05-05 20:22:44 +02:00
parent e5cd2e91e8
commit ef9d9aaeeb
4 changed files with 126 additions and 43 deletions

View file

@ -109,7 +109,9 @@ static time_t dosTime2TimeT(UINT32 dostime) // from INFO-ZIP src
static const char* errorstrtable[]= static const char* errorstrtable[]=
{ {
"no error", // ERR_NOERR "no error", // ERR_NOERR
"can't open file", // ERR_CANT_OPEN_FILE "can't open archive file", // ERR_CANT_OPEN_FILE
"can't open dest file or path", // ERR_CANT_OPEN_DEST_FILE
// "can't create dest path", // ERR_CANT_CREATE_DEST_PATH
"corrupted file", // ERR_CORRUPTED_FILE "corrupted file", // ERR_CORRUPTED_FILE
"not alz file", // ERR_NOT_ALZ_FILE "not alz file", // ERR_NOT_ALZ_FILE
"can't read signature", // ERR_CANT_READ_SIG "can't read signature", // ERR_CANT_READ_SIG
@ -161,6 +163,7 @@ CUnAlz::CUnAlz()
m_bIsEOF = FALSE; m_bIsEOF = FALSE;
m_bIsEncrypted = FALSE; m_bIsEncrypted = FALSE;
m_bIsDataDescr = FALSE; m_bIsDataDescr = FALSE;
m_bPipeMode = FALSE;
#ifdef _UNALZ_ICONV #ifdef _UNALZ_ICONV
@ -663,7 +666,7 @@ BOOL CUnAlz::ExtractCurrentFile(const char* szDestPathName, const char* szDestFi
BOOL ret=FALSE; BOOL ret=FALSE;
SExtractDest dest; SExtractDest dest;
char szDestPathFileName[MAX_PATH]; char szDestPathFileName[MAX_PATH];
if(chkValidPassword() == FALSE) if(chkValidPassword() == FALSE)
{ {
@ -692,27 +695,46 @@ BOOL CUnAlz::ExtractCurrentFile(const char* szDestPathName, const char* szDestFi
// ¾ÐÃàÇ® ´ë»ó ( ÆÄÀÏ ) // ¾ÐÃàÇ® ´ë»ó ( ÆÄÀÏ )
dest.nType = ET_FILE; dest.nType = ET_FILE;
dest.fp = fopen(szDestPathFileName, "wb");
if(m_bPipeMode)
dest.fp = stdout; // pipe mode 일 경우 stdout 출력
else
dest.fp = fopen(szDestPathFileName, "wb");
// 타입이 폴더일 경우..
if(m_bPipeMode==FALSE && (m_posCur->head.fileAttribute) & ALZ_FILEATTR_DIRECTORY )
{
//printf("digpath:%s\n", szDestPathFileName);
// 경로파기
DigPath(szDestPathFileName);
return TRUE;
// m_nErr = ERR_CANT_CREATE_DEST_PATH;
// return FALSE;
}
// 파일 열기 실패시 - 경로를 파본다
if(dest.fp==NULL) if(dest.fp==NULL)
{ {
DigPath(szDestPathFileName); // 경로명에 / 가 있을 경우.. DigPath(szDestPathFileName);
dest.fp = fopen(szDestPathFileName, "wb"); dest.fp = fopen(szDestPathFileName, "wb");
} }
#ifdef _WIN32 // 그래도 파일열기 실패시.
if(dest.fp==NULL) if(dest.fp==NULL)
{ {
ASSERT(0); // 대상 파일 열기 실패
m_nErr = ERR_CANT_OPEN_DEST_FILE;
//printf("dest pathfilename:%s\n",szDestPathFileName);
if(m_pFuncCallBack) if(m_pFuncCallBack)
{ {
CHAR buf[1024]; // CHAR buf[1024];
sprintf(buf, "파일 열기 실패 : %s", szDestPathFileName); // sprintf(buf, "파일 열기 실패 : %s", szDestPathFileName);
m_pFuncCallBack(buf, 0,0,m_pCallbackParam, NULL); // m_pFuncCallBack(buf, 0,0,m_pCallbackParam, NULL);
} }
return FALSE; return FALSE;
} }
#endif //#endif
// CALLBACK ¼¼Æà // CALLBACK ¼¼ÆÃ
if(m_pFuncCallBack) m_pFuncCallBack(m_posCur->fileName, 0,m_posCur->uncompressedSize,m_pCallbackParam, NULL); if(m_pFuncCallBack) m_pFuncCallBack(m_posCur->fileName, 0,m_posCur->uncompressedSize,m_pCallbackParam, NULL);
@ -864,9 +886,9 @@ BOOL CUnAlz::ExtractAll(const char* szDestPathName)
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
BOOL CUnAlz::DigPath(const char* szPathName) BOOL CUnAlz::DigPath(const char* szPathName)
{ {
char* dup = strdup(szPathName); char* dup = strdup(szPathName);
char seps[] = "/\\"; char seps[] = "/\\";
char *token; char* token;
char path[MAX_PATH] = {0}; char path[MAX_PATH] = {0};
char* last; char* last;
@ -882,11 +904,16 @@ BOOL CUnAlz::DigPath(const char* szPathName)
last --; last --;
} }
token = strtok( dup, seps ); token = strtok( dup, seps );
while( token != NULL ) while( token != NULL )
{ {
if(strlen(path)==0) if(strlen(path)==0)
strcpy(path, token); {
if(szPathName[0]=='/') // is absolute path ?
strcpy(path,"/");
strcat(path, token);
}
else else
{ {
strcat(path, PATHSEP); strcat(path, PATHSEP);
@ -899,6 +926,7 @@ BOOL CUnAlz::DigPath(const char* szPathName)
#else #else
mkdir(path, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); mkdir(path, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
#endif #endif
//printf("path:%s\n", path);
token = strtok( NULL, seps ); token = strtok( NULL, seps );
} }

15
UnAlz.h
View file

@ -63,9 +63,14 @@
2005/07/02 - unalz , .. 2005/07/02 - unalz , ..
- - from unalz_wcx_01i.zip - - from unalz_wcx_01i.zip
2005/07/09 - unalz 0.5 2005/07/09 - unalz 0.5
2005/07/25 - -d "/" (Pavel Roskin)
- pipemode - (Pavel Roskin)
- / (Pavel Roskin)
- -pwd
- unalz 0.51
: :
- alz ( deflate/ bzip2/raw ) - alz (deflate/ bzip2/raw)
- (alz, a00, a01.. ) - (alz, a00, a01.. )
- (Win32/POSIX(BSD/LINUX/DARWIN)) - (Win32/POSIX(BSD/LINUX/DARWIN))
- -
@ -169,7 +174,7 @@ namespace UNALZ
# pragma pack(1) # pragma pack(1)
#endif #endif
static const char UNALZ_VERSION[] = "CUnAlz0.5"; static const char UNALZ_VERSION[] = "CUnAlz0.51";
static const char UNALZ_COPYRIGHT[] = "Copyright(C) 2004-2005 by hardkoder ( http://www.kipple.pe.kr ) "; static const char UNALZ_COPYRIGHT[] = "Copyright(C) 2004-2005 by hardkoder ( http://www.kipple.pe.kr ) ";
enum {ENCR_HEADER_LEN=12}; // xf86 enum {ENCR_HEADER_LEN=12}; // xf86
@ -363,6 +368,7 @@ public:
BOOL ExtractCurrentFileToBuf(BYTE* pDestBuf, int nBufSize); // pDestBuf=NULL 일 경우 테스트만 수행한다. BOOL ExtractCurrentFileToBuf(BYTE* pDestBuf, int nBufSize); // pDestBuf=NULL 일 경우 테스트만 수행한다.
BOOL ExtractAll(const char* szDestPathName); BOOL ExtractAll(const char* szDestPathName);
void SetCallback(_UnAlzCallback* pFunc, void* param=NULL); void SetCallback(_UnAlzCallback* pFunc, void* param=NULL);
void SetPipeMode(BOOL bPipeMode) {m_bPipeMode=bPipeMode;}
void setPassword(char *passwd) { if(strlen(passwd) == 0) return; strcpy(m_szPasswd, passwd); }; // xf86 void setPassword(char *passwd) { if(strlen(passwd) == 0) return; strcpy(m_szPasswd, passwd); }; // xf86
BOOL chkValidPassword(); // xf86 BOOL chkValidPassword(); // xf86
@ -395,7 +401,9 @@ public :
enum ERR ///< 에러 코드 - 정리 필요.. enum ERR ///< 에러 코드 - 정리 필요..
{ {
ERR_NOERR, ERR_NOERR,
ERR_CANT_OPEN_FILE, ///< 파일 열기 실패 ERR_CANT_OPEN_FILE, ///< 소스 파일 열기 실패
ERR_CANT_OPEN_DEST_FILE, ///< 대상 파일 열기 실패
// ERR_CANT_CREATE_DEST_PATH, ///< 대상 경로 만들기 실패
ERR_CORRUPTED_FILE, ///< 깨진 파일? ERR_CORRUPTED_FILE, ///< 깨진 파일?
ERR_NOT_ALZ_FILE, ///< ALZ 파일이 아니다. ERR_NOT_ALZ_FILE, ///< ALZ 파일이 아니다.
ERR_CANT_READ_SIG, ///< signature 읽기 실패 ERR_CANT_READ_SIG, ///< signature 읽기 실패
@ -519,6 +527,7 @@ private : //
BOOL m_bIsEncrypted; // xf86 BOOL m_bIsEncrypted; // xf86
BOOL m_bIsDataDescr; BOOL m_bIsDataDescr;
char m_szPasswd[512]; char m_szPasswd[512];
BOOL m_bPipeMode; ///< pipemode - 메시지 출력없이 stdout 으로만 출력
private : private :
/* from CZipArchive /* from CZipArchive

View file

@ -66,11 +66,11 @@ int ListAlz(CUnAlz* pUnAlz, const char* src)
list = pUnAlz->GetFileList(); list = pUnAlz->GetFileList();
printf("\nListing archive: %s\n" printf("\nListing archive: %s\n"
"\n Date Time Attr Size Compressed Name\n", "\n Date & Time Attr Size Compressed Name\n",
src); src);
printf("------------------- ----- ------------ ------------ ------------\n"); printf("------------------- ----- ------------ ------------ ------------\n");
char szDate[64]; // char szDate[64];
char szTime[64]; char szTime[64];
char szAttr[6]; char szAttr[6];
UINT64 totalUnCompressedSize = 0; UINT64 totalUnCompressedSize = 0;
@ -83,13 +83,14 @@ int ListAlz(CUnAlz* pUnAlz, const char* src)
// time // time
time = dosTime2TimeT(i->head.fileTimeDate); time = dosTime2TimeT(i->head.fileTimeDate);
filetm = localtime(&time); filetm = localtime(&time);
strftime(szTime, 64, "%H:%M:%S", filetm); // strftime(szTime, 64, "%H:%M:%S", filetm);
strftime(szDate, 64, "%Y:%m:%d", filetm); // strftime(szDate, 64, "%Y-%m-%d", filetm);
strftime(szTime, 64, "%x %X", filetm); // use system locale
// attributes // attributes
FileAttr2Str(szAttr, i->head.fileAttribute); FileAttr2Str(szAttr, i->head.fileAttribute);
printf("%s %s %s " I64FORM(12) " " I64FORM(12) " %s%s\n", printf("%19s %s " I64FORM(12) " " I64FORM(12) " %s%s\n",
szDate, szTime, szAttr, i->uncompressedSize, szTime, szAttr, i->uncompressedSize,
i->compressedSize, i->fileName, i->compressedSize, i->fileName,
i->head.fileDescriptor & ALZ_FILE_DESCRIPTOR_ENCRYPTED ? "*" : "" ); i->head.fileDescriptor & ALZ_FILE_DESCRIPTOR_ENCRYPTED ? "*" : "" );

View file

@ -10,9 +10,28 @@
#include "UnAlz.h" #include "UnAlz.h"
#include "UnAlzUtils.h" #include "UnAlzUtils.h"
#include <sys/timeb.h>
BOOL g_bPipeMode=FALSE;
void Copyright()
{
// printf("unalz v0.20 (2004/10/22) \n");
// printf("unalz v0.22 (2004/10/27) \n");
// printf("unalz v0.23 (2004/10/30) \n");
// printf("unalz v0.31 (2004/11/27) \n");
// printf("unalz v0.4 (2005/06/18) \n");
// printf("unalz v0.5 (2005/07/09) \n");
printf("unalz v0.51 (2005/07/24) \n");
printf("Copyright(C) 2004-2005 by hardkoder (http://www.kipple.pe.kr) \n");
}
void Usage() void Usage()
{ {
Copyright();
printf("\n"); printf("\n");
/* /*
#ifdef _UNALZ_ICONV #ifdef _UNALZ_ICONV
@ -48,6 +67,8 @@ void Usage()
#endif // _UNALZ_ICONV #endif // _UNALZ_ICONV
printf(" -l : list contents of archive\n"); printf(" -l : list contents of archive\n");
printf(" -d directory : set output directory\n"); printf(" -d directory : set output directory\n");
printf(" -p : extract files to pipe, no messages\n");
printf(" -pwd <pwd> : set password\n");
} }
@ -57,6 +78,8 @@ void Usage()
void UnAlzCallback(const char* szMessage, INT64 nCurrent, INT64 nRange, void* param, BOOL* bHalt) void UnAlzCallback(const char* szMessage, INT64 nCurrent, INT64 nRange, void* param, BOOL* bHalt)
{ {
if(g_bPipeMode) return; // slient
// progress // progress
static char szFileName[1024]={0}; static char szFileName[1024]={0};
INT64 percent; INT64 percent;
@ -101,14 +124,6 @@ void UnAlzCallback(const char* szMessage, INT64 nCurrent, INT64 nRange, void* pa
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
// printf("unalz v0.20 (2004/10/22) \n");
// printf("unalz v0.22 (2004/10/27) \n");
// printf("unalz v0.23 (2004/10/30) \n");
// printf("unalz v0.31 (2004/11/27) \n");
// printf("unalz v0.4 (2005/06/18) \n");
printf("unalz v0.5 (2005/07/09) \n");
printf("Copyright(C) 2004-2005 by hardkoder (http://www.kipple.pe.kr) \n");
if(argc<2) if(argc<2)
{ {
Usage(); Usage();
@ -119,6 +134,7 @@ int main(int argc, char* argv[])
char* source=NULL; char* source=NULL;
char* destpath="."; char* destpath=".";
char* destcodepage=NULL; char* destcodepage=NULL;
char* password=NULL;
int count; int count;
BOOL listMode = FALSE; BOOL listMode = FALSE;
vector<string> filelist; vector<string> filelist;
@ -187,12 +203,22 @@ int main(int argc, char* argv[])
{ {
listMode = TRUE; listMode = TRUE;
} }
else if(strcmp(argv[count], "-p")==0)
{
g_bPipeMode = TRUE;
}
else if(strcmp(argv[count], "-d")==0) // dest dir else if(strcmp(argv[count], "-d")==0) // dest dir
{ {
count++; count++;
if(count>=argc) {Usage();return 0;} // dest dir 이 정상 지정되지 않았다.. if(count>=argc) {Usage();return 0;} // dest dir 이 정상 지정되지 않았다..
destpath = argv[count]; destpath = argv[count];
} }
else if(strcmp(argv[count], "-pwd")==0) // pwd
{
count++;
if(count>=argc) {Usage();return 0;} // dest dir 이 정상 지정되지 않았다..
password = argv[count];
}
else // 옵션이 아닌 경우 else // 옵션이 아닌 경우
{ {
if(source==NULL) // 소스 파일 경로 if(source==NULL) // 소스 파일 경로
@ -213,6 +239,12 @@ int main(int argc, char* argv[])
#endif #endif
if(g_bPipeMode==FALSE)
Copyright(); // copyright 표시
// pipe mode setting
unalz.SetPipeMode(g_bPipeMode);
// 파일 열기 // 파일 열기
if(unalz.Open(source)==FALSE) if(unalz.Open(source)==FALSE)
{ {
@ -236,13 +268,21 @@ int main(int argc, char* argv[])
{ {
if(unalz.IsEncrypted()) if(unalz.IsEncrypted())
{ {
char pwd[256]; if(password) // command line 으로 암호가 지정되었을 경우.
printf("Enter Password : "); {
fgets(pwd,256,stdin); unalz.setPassword(password);
unalz.setPassword(pwd); }
else
{
char pwd[256];
printf("Enter Password : ");
fgets(pwd,256,stdin);
unalz.setPassword(pwd);
}
} }
printf("\nExtract %s to %s\n", source, destpath); if(g_bPipeMode==FALSE)
printf("\nExtract %s to %s\n", source, destpath);
// callback 함수 세팅 // callback 함수 세팅
unalz.SetCallback(UnAlzCallback, (void*)NULL); unalz.SetCallback(UnAlzCallback, (void*)NULL);
@ -254,7 +294,8 @@ int main(int argc, char* argv[])
{ {
if(unalz.SetCurrentFile(i->c_str())==FALSE) if(unalz.SetCurrentFile(i->c_str())==FALSE)
{ {
printf("filename not matched : %s\n", i->c_str()); if(g_bPipeMode==FALSE)
printf("filename not matched : %s\n", i->c_str());
} }
else else
unalz.ExtractCurrentFile(destpath); unalz.ExtractCurrentFile(destpath);
@ -264,13 +305,17 @@ int main(int argc, char* argv[])
{ {
if(unalz.ExtractAll(destpath)==FALSE) if(unalz.ExtractAll(destpath)==FALSE)
{ {
printf("\n"); if(g_bPipeMode==FALSE)
printf("extract %s to %s failed.\n", source, destpath); {
printf("err code(%d) (%s)\n", unalz.GetLastErr(), printf("\n");
unalz.GetLastErrStr()); printf("extract %s to %s failed.\n", source, destpath);
printf("err code(%d) (%s)\n", unalz.GetLastErr(),
unalz.GetLastErrStr());
}
} }
} }
printf("\ndone..\n"); if(g_bPipeMode==FALSE)
printf("\ndone..\n");
} }
return 0; return 0;