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[]=
{
"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 );
}

15
UnAlz.h
View file

@ -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

View file

@ -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 ? "*" : "" );

View file

@ -10,9 +10,28 @@
#include "UnAlz.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()
{
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 <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<string> 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;