From ef9d9aaeebd50f1209c6c608c3f21531597c6ef3 Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Tue, 5 May 2020 20:22:44 +0200 Subject: [PATCH] v0.51 --- UnAlz.cpp | 58 ++++++++++++++++++++++++++--------- UnAlz.h | 15 +++++++-- UnAlzUtils.cpp | 13 ++++---- main.cpp | 83 ++++++++++++++++++++++++++++++++++++++------------ 4 files changed, 126 insertions(+), 43 deletions(-) diff --git a/UnAlz.cpp b/UnAlz.cpp index fa67e5c..73da4de 100755 --- a/UnAlz.cpp +++ b/UnAlz.cpp @@ -109,7 +109,9 @@ static time_t dosTime2TimeT(UINT32 dostime) // from INFO-ZIP src static const char* errorstrtable[]= { "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 "not alz file", // ERR_NOT_ALZ_FILE "can't read signature", // ERR_CANT_READ_SIG @@ -161,6 +163,7 @@ CUnAlz::CUnAlz() m_bIsEOF = FALSE; m_bIsEncrypted = FALSE; m_bIsDataDescr = FALSE; + m_bPipeMode = FALSE; #ifdef _UNALZ_ICONV @@ -663,7 +666,7 @@ BOOL CUnAlz::ExtractCurrentFile(const char* szDestPathName, const char* szDestFi BOOL ret=FALSE; SExtractDest dest; - char szDestPathFileName[MAX_PATH]; + char szDestPathFileName[MAX_PATH]; if(chkValidPassword() == FALSE) { @@ -692,27 +695,46 @@ BOOL CUnAlz::ExtractCurrentFile(const char* szDestPathName, const char* szDestFi // ¾ÐÃàÇ® ´ë»ó ( ÆÄÀÏ ) 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) { - DigPath(szDestPathFileName); // °æ·Î¸í¿¡ / °¡ ÀÖÀ» °æ¿ì.. + DigPath(szDestPathFileName); dest.fp = fopen(szDestPathFileName, "wb"); } -#ifdef _WIN32 + // ±×·¡µµ ÆÄÀÏ¿­±â ½ÇÆнÃ. if(dest.fp==NULL) { - ASSERT(0); + // ´ë»ó ÆÄÀÏ ¿­±â ½ÇÆÐ + m_nErr = ERR_CANT_OPEN_DEST_FILE; +//printf("dest pathfilename:%s\n",szDestPathFileName); if(m_pFuncCallBack) { - CHAR buf[1024]; - sprintf(buf, "ÆÄÀÏ ¿­±â ½ÇÆÐ : %s", szDestPathFileName); - m_pFuncCallBack(buf, 0,0,m_pCallbackParam, NULL); +// CHAR buf[1024]; +// sprintf(buf, "ÆÄÀÏ ¿­±â ½ÇÆÐ : %s", szDestPathFileName); +// m_pFuncCallBack(buf, 0,0,m_pCallbackParam, NULL); } return FALSE; } -#endif +//#endif + // CALLBACK ¼¼Æà 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) { - char* dup = strdup(szPathName); - char seps[] = "/\\"; - char *token; + char* dup = strdup(szPathName); + char seps[] = "/\\"; + char* token; char path[MAX_PATH] = {0}; char* last; @@ -882,11 +904,16 @@ BOOL CUnAlz::DigPath(const char* szPathName) last --; } + token = strtok( dup, seps ); while( token != NULL ) { - if(strlen(path)==0) - strcpy(path, token); + if(strlen(path)==0) + { + if(szPathName[0]=='/') // is absolute path ? + strcpy(path,"/"); + strcat(path, token); + } else { strcat(path, PATHSEP); @@ -899,6 +926,7 @@ BOOL CUnAlz::DigPath(const char* szPathName) #else mkdir(path, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); #endif +//printf("path:%s\n", path); token = strtok( NULL, seps ); } diff --git a/UnAlz.h b/UnAlz.h index 0b4cbd0..9fa8548 100755 --- a/UnAlz.h +++ b/UnAlz.h @@ -63,9 +63,14 @@ 2005/07/02 - unalz Ä¿¸Çµå ¶óÀÎ ¹æ½Ä º¯°æ, ¾ÐÃàÇ® ´ë»ó ÆÄÀÏ ÁöÁ¤ ±â´É Ãß°¡.. - ¾ÐÃà ÇØÁ¦µÈ ÆÄÀϽð£À» ¿ø·¡ ½Ã°£À¸·Î ¼¼ÆÃÇÏ´Â ÄÚµå Ãß°¡ - from unalz_wcx_01i.zip 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.. ) - ´Ù¾çÇÑ Ç÷¡Æû Áö¿ø (Win32/POSIX(BSD/LINUX/DARWIN)) - ¾ÏÈ£°É¸° ÆÄÀÏÀÇ ¾ÐÃà ÇØÁ¦ @@ -169,7 +174,7 @@ namespace UNALZ # pragma pack(1) #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 ) "; enum {ENCR_HEADER_LEN=12}; // xf86 @@ -363,6 +368,7 @@ public: BOOL ExtractCurrentFileToBuf(BYTE* pDestBuf, int nBufSize); // pDestBuf=NULL ÀÏ °æ¿ì Å×½ºÆ®¸¸ ¼öÇàÇÑ´Ù. BOOL ExtractAll(const char* szDestPathName); 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 BOOL chkValidPassword(); // xf86 @@ -395,7 +401,9 @@ public : enum ERR ///< ¿¡·¯ ÄÚµå - Á¤¸® ÇÊ¿ä.. { ERR_NOERR, - ERR_CANT_OPEN_FILE, ///< ÆÄÀÏ ¿­±â ½ÇÆÐ + ERR_CANT_OPEN_FILE, ///< ¼Ò½º ÆÄÀÏ ¿­±â ½ÇÆÐ + ERR_CANT_OPEN_DEST_FILE, ///< ´ë»ó ÆÄÀÏ ¿­±â ½ÇÆÐ +// ERR_CANT_CREATE_DEST_PATH, ///< ´ë»ó °æ·Î ¸¸µé±â ½ÇÆÐ ERR_CORRUPTED_FILE, ///< ±úÁø ÆÄÀÏ? ERR_NOT_ALZ_FILE, ///< ALZ ÆÄÀÏÀÌ ¾Æ´Ï´Ù. ERR_CANT_READ_SIG, ///< signature Àб⠽ÇÆÐ @@ -519,6 +527,7 @@ private : // BOOL m_bIsEncrypted; // xf86 BOOL m_bIsDataDescr; char m_szPasswd[512]; + BOOL m_bPipeMode; ///< pipemode - ¸Þ½ÃÁö Ãâ·Â¾øÀÌ stdout À¸·Î¸¸ Ãâ·Â private : /* from CZipArchive diff --git a/UnAlzUtils.cpp b/UnAlzUtils.cpp index 08d72d0..a425bc1 100755 --- a/UnAlzUtils.cpp +++ b/UnAlzUtils.cpp @@ -66,11 +66,11 @@ int ListAlz(CUnAlz* pUnAlz, const char* src) list = pUnAlz->GetFileList(); printf("\nListing archive: %s\n" - "\n Date Time Attr Size Compressed Name\n", + "\n Date & Time Attr Size Compressed Name\n", src); printf("------------------- ----- ------------ ------------ ------------\n"); - char szDate[64]; +// char szDate[64]; char szTime[64]; char szAttr[6]; UINT64 totalUnCompressedSize = 0; @@ -83,13 +83,14 @@ int ListAlz(CUnAlz* pUnAlz, const char* src) // time time = dosTime2TimeT(i->head.fileTimeDate); filetm = localtime(&time); - strftime(szTime, 64, "%H:%M:%S", filetm); - strftime(szDate, 64, "%Y:%m:%d", filetm); +// strftime(szTime, 64, "%H:%M:%S", filetm); +// strftime(szDate, 64, "%Y-%m-%d", filetm); + strftime(szTime, 64, "%x %X", filetm); // use system locale // attributes FileAttr2Str(szAttr, i->head.fileAttribute); - printf("%s %s %s " I64FORM(12) " " I64FORM(12) " %s%s\n", - szDate, szTime, szAttr, i->uncompressedSize, + printf("%19s %s " I64FORM(12) " " I64FORM(12) " %s%s\n", + szTime, szAttr, i->uncompressedSize, i->compressedSize, i->fileName, i->head.fileDescriptor & ALZ_FILE_DESCRIPTOR_ENCRYPTED ? "*" : "" ); diff --git a/main.cpp b/main.cpp index 2689b5f..64583f4 100755 --- a/main.cpp +++ b/main.cpp @@ -10,9 +10,28 @@ #include "UnAlz.h" #include "UnAlzUtils.h" +#include + + +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() { + Copyright(); + printf("\n"); /* #ifdef _UNALZ_ICONV @@ -48,6 +67,8 @@ void Usage() #endif // _UNALZ_ICONV printf(" -l : list contents of archive\n"); printf(" -d directory : set output directory\n"); + printf(" -p : extract files to pipe, no messages\n"); + printf(" -pwd : set password\n"); } @@ -57,6 +78,8 @@ void Usage() void UnAlzCallback(const char* szMessage, INT64 nCurrent, INT64 nRange, void* param, BOOL* bHalt) { + if(g_bPipeMode) return; // slient + // progress static char szFileName[1024]={0}; INT64 percent; @@ -101,14 +124,6 @@ void UnAlzCallback(const char* szMessage, INT64 nCurrent, INT64 nRange, void* pa 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) { Usage(); @@ -119,6 +134,7 @@ int main(int argc, char* argv[]) char* source=NULL; char* destpath="."; char* destcodepage=NULL; + char* password=NULL; int count; BOOL listMode = FALSE; vector filelist; @@ -187,12 +203,22 @@ int main(int argc, char* argv[]) { listMode = TRUE; } + else if(strcmp(argv[count], "-p")==0) + { + g_bPipeMode = TRUE; + } else if(strcmp(argv[count], "-d")==0) // dest dir { count++; if(count>=argc) {Usage();return 0;} // dest dir ÀÌ Á¤»ó ÁöÁ¤µÇÁö ¾Ê¾Ò´Ù.. destpath = argv[count]; } + else if(strcmp(argv[count], "-pwd")==0) // pwd + { + count++; + if(count>=argc) {Usage();return 0;} // dest dir ÀÌ Á¤»ó ÁöÁ¤µÇÁö ¾Ê¾Ò´Ù.. + password = argv[count]; + } else // ¿É¼ÇÀÌ ¾Æ´Ñ °æ¿ì { if(source==NULL) // ¼Ò½º ÆÄÀÏ °æ·Î @@ -213,6 +239,12 @@ int main(int argc, char* argv[]) #endif + if(g_bPipeMode==FALSE) + Copyright(); // copyright Ç¥½Ã + + // pipe mode setting + unalz.SetPipeMode(g_bPipeMode); + // ÆÄÀÏ ¿­±â if(unalz.Open(source)==FALSE) { @@ -236,13 +268,21 @@ int main(int argc, char* argv[]) { if(unalz.IsEncrypted()) { - char pwd[256]; - printf("Enter Password : "); - fgets(pwd,256,stdin); - unalz.setPassword(pwd); + if(password) // command line À¸·Î ¾ÏÈ£°¡ ÁöÁ¤µÇ¾úÀ» °æ¿ì. + { + unalz.setPassword(password); + } + 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 ÇÔ¼ö ¼¼Æà unalz.SetCallback(UnAlzCallback, (void*)NULL); @@ -254,7 +294,8 @@ int main(int argc, char* argv[]) { 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 unalz.ExtractCurrentFile(destpath); @@ -264,13 +305,17 @@ int main(int argc, char* argv[]) { if(unalz.ExtractAll(destpath)==FALSE) { - printf("\n"); - printf("extract %s to %s failed.\n", source, destpath); - printf("err code(%d) (%s)\n", unalz.GetLastErr(), - unalz.GetLastErrStr()); + if(g_bPipeMode==FALSE) + { + printf("\n"); + 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;