2020-05-05 18:22:42 +00:00
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
# pragma warning( disable : 4786 ) // stl warning <20><><EFBFBD>ֱ<EFBFBD>
|
|
|
|
|
#endif
|
|
|
|
|
|
2020-05-05 18:22:29 +00:00
|
|
|
|
#include <stdio.h>
|
2020-05-05 18:22:35 +00:00
|
|
|
|
#include <iostream>
|
2020-05-05 18:22:42 +00:00
|
|
|
|
#include <time.h>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
2020-05-05 18:22:29 +00:00
|
|
|
|
#include "UnAlz.h"
|
2020-05-05 18:22:42 +00:00
|
|
|
|
#include "UnAlzUtils.h"
|
2020-05-05 18:22:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Usage()
|
|
|
|
|
{
|
|
|
|
|
printf("\n");
|
2020-05-05 18:22:42 +00:00
|
|
|
|
/*
|
2020-05-05 18:22:31 +00:00
|
|
|
|
#ifdef _UNALZ_ICONV
|
2020-05-05 18:22:38 +00:00
|
|
|
|
printf("USAGE : unalz [ -utf8 | -cp949 | -euc-kr ] sourcefile.alz [dest path] \n");
|
2020-05-05 18:22:31 +00:00
|
|
|
|
# ifdef _UNALZ_UTF8
|
|
|
|
|
printf(" -utf8 : convert filename's codepage to UTF-8 (default)\n");
|
|
|
|
|
printf(" -cp949 : convert filename's codepage to CP949\n");
|
2020-05-05 18:22:33 +00:00
|
|
|
|
printf(" -euc-kr: convert filename's codepage to EUC-KR\n");
|
2020-05-05 18:22:31 +00:00
|
|
|
|
# else
|
|
|
|
|
printf(" -utf8 : convert filename's codepage to UTF-8\n");
|
|
|
|
|
printf(" -cp949 : convert filename's codepage to CP949 (default)\n");
|
2020-05-05 18:22:33 +00:00
|
|
|
|
printf(" -euc-kr: convert filename's codepage to EUC-KR\n");
|
2020-05-05 18:22:31 +00:00
|
|
|
|
# endif // _UNALZ_UTF8
|
|
|
|
|
#else // no iconv
|
2020-05-05 18:22:29 +00:00
|
|
|
|
printf("USAGE : unalz sourcefile.alz [dest path] \n");
|
2020-05-05 18:22:31 +00:00
|
|
|
|
#endif // _UNALZ_ICONV
|
2020-05-05 18:22:42 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
printf("Usage : unalz [<switches>...] archive.alz [<file names to extract>...]\n");
|
|
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
|
printf("<switches>\n");
|
|
|
|
|
#ifdef _UNALZ_ICONV
|
|
|
|
|
# ifdef _UNALZ_UTF8
|
|
|
|
|
printf(" -utf8 : convert filename's codepage to UTF-8 (default)\n");
|
|
|
|
|
printf(" -cp949 : convert filename's codepage to CP949\n");
|
|
|
|
|
printf(" -euc-kr : convert filename's codepage to EUC-KR\n");
|
|
|
|
|
# else
|
|
|
|
|
printf(" -utf8 : convert filename's codepage to UTF-8\n");
|
|
|
|
|
printf(" -cp949 : convert filename's codepage to CP949 (default)\n");
|
|
|
|
|
printf(" -euc-kr : convert filename's codepage to EUC-KR\n");
|
|
|
|
|
# endif // _UNALZ_UTF8
|
|
|
|
|
#endif // _UNALZ_ICONV
|
|
|
|
|
printf(" -l : list contents of archive\n");
|
|
|
|
|
printf(" -d directory : set output directory\n");
|
|
|
|
|
|
2020-05-05 18:22:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-05 18:22:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-05-05 18:22:29 +00:00
|
|
|
|
void UnAlzCallback(const char* szMessage, INT64 nCurrent, INT64 nRange, void* param, BOOL* bHalt)
|
|
|
|
|
{
|
|
|
|
|
// progress
|
2020-05-05 18:22:33 +00:00
|
|
|
|
static char szFileName[1024]={0};
|
2020-05-05 18:22:29 +00:00
|
|
|
|
INT64 percent;
|
|
|
|
|
static INT64 nPrevPercent = -1;
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD>ϸ<EFBFBD> <20><><EFBFBD><EFBFBD>..
|
|
|
|
|
if(szMessage)
|
|
|
|
|
{
|
2020-05-05 18:22:33 +00:00
|
|
|
|
printf("\n");
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
sprintf(szFileName, "unalziiiing : %s (%I64dbytes) ", szMessage, nRange);
|
|
|
|
|
#else
|
|
|
|
|
sprintf(szFileName, "unalziiiing : %s (%lldbytes) ", szMessage, nRange);
|
|
|
|
|
#endif
|
|
|
|
|
printf("%s", szFileName);
|
|
|
|
|
fflush(stdout);
|
2020-05-05 18:22:29 +00:00
|
|
|
|
nPrevPercent = -1;
|
2020-05-05 18:22:33 +00:00
|
|
|
|
return;
|
2020-05-05 18:22:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
percent = nCurrent*100/nRange;
|
|
|
|
|
|
2020-05-05 18:22:33 +00:00
|
|
|
|
if(nPrevPercent/10==percent/10) return; // <20>ʹ<EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʈ <20><><EFBFBD><EFBFBD>..
|
2020-05-05 18:22:29 +00:00
|
|
|
|
nPrevPercent = percent;
|
2020-05-05 18:22:33 +00:00
|
|
|
|
|
|
|
|
|
printf(".");
|
|
|
|
|
fflush(stdout);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
char buf[1024];
|
2020-05-05 18:22:29 +00:00
|
|
|
|
#ifdef _WIN32
|
2020-05-05 18:22:33 +00:00
|
|
|
|
sprintf(buf, "\r%s %I64d/%I64d (%I64d%%)", szFileName, nCurrent, nRange, percent);
|
2020-05-05 18:22:29 +00:00
|
|
|
|
#else
|
2020-05-05 18:22:33 +00:00
|
|
|
|
// sprintf(buf, "\r%s %d/%d (%d%%)", szMessage, (int)nCurrent, (int)nRange, (int)percent); // int64 <20><> <20><><EFBFBD><EFBFBD><EFBFBD>Ҷ<EFBFBD><D2B6><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ؾ<EFBFBD> <20>Ǵ<EFBFBD><C7B4><EFBFBD>?
|
|
|
|
|
sprintf(buf, "\r%s %lld/%lld (%lld%%)", szFileName, nCurrent, Range, percent);
|
2020-05-05 18:22:29 +00:00
|
|
|
|
#endif
|
2020-05-05 18:22:31 +00:00
|
|
|
|
puts(buf);
|
2020-05-05 18:22:29 +00:00
|
|
|
|
fflush(stdout);
|
2020-05-05 18:22:33 +00:00
|
|
|
|
*/
|
2020-05-05 18:22:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-05 18:22:31 +00:00
|
|
|
|
|
2020-05-05 18:22:29 +00:00
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
|
{
|
2020-05-05 18:22:31 +00:00
|
|
|
|
// printf("unalz v0.20 (2004/10/22) \n");
|
2020-05-05 18:22:33 +00:00
|
|
|
|
// printf("unalz v0.22 (2004/10/27) \n");
|
2020-05-05 18:22:35 +00:00
|
|
|
|
// printf("unalz v0.23 (2004/10/30) \n");
|
2020-05-05 18:22:39 +00:00
|
|
|
|
// printf("unalz v0.31 (2004/11/27) \n");
|
2020-05-05 18:22:42 +00:00
|
|
|
|
// printf("unalz v0.4 (2005/06/18) \n");
|
|
|
|
|
printf("unalz v0.5 (2005/07/09) \n");
|
2020-05-05 18:22:39 +00:00
|
|
|
|
printf("Copyright(C) 2004-2005 by hardkoder (http://www.kipple.pe.kr) \n");
|
2020-05-05 18:22:29 +00:00
|
|
|
|
|
|
|
|
|
if(argc<2)
|
|
|
|
|
{
|
|
|
|
|
Usage();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-05 18:22:31 +00:00
|
|
|
|
CUnAlz unalz;
|
|
|
|
|
char* source=NULL;
|
|
|
|
|
char* destpath=".";
|
|
|
|
|
char* destcodepage=NULL;
|
2020-05-05 18:22:42 +00:00
|
|
|
|
int count;
|
|
|
|
|
BOOL listMode = FALSE;
|
|
|
|
|
vector<string> filelist;
|
2020-05-05 18:22:31 +00:00
|
|
|
|
|
2020-05-05 18:22:42 +00:00
|
|
|
|
/* old method
|
|
|
|
|
for (count=1 ; count < argc && argv[count][0] == '-'; ++count)
|
2020-05-05 18:22:31 +00:00
|
|
|
|
{
|
2020-05-05 18:22:42 +00:00
|
|
|
|
#ifdef _UNALZ_ICONV
|
|
|
|
|
// utf8 <20>ɼ<EFBFBD> ó<><C3B3>
|
|
|
|
|
if(strcmp(argv[count], "-utf8")==0)
|
|
|
|
|
{
|
|
|
|
|
destcodepage = "UTF-8"; // utf-8 support
|
|
|
|
|
}
|
|
|
|
|
else if(strcmp(argv[count], "-cp949")==0)
|
|
|
|
|
{
|
|
|
|
|
destcodepage = "CP949"; // cp949
|
|
|
|
|
}
|
|
|
|
|
else if(strcmp(argv[count], "-euc-kr")==0)
|
|
|
|
|
{
|
|
|
|
|
destcodepage = "EUC-KR"; // EUC-KR
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
#endif
|
|
|
|
|
if(strcmp(argv[count], "-l")==0 || strcmp(argv[count], "-list")==0)
|
|
|
|
|
{
|
|
|
|
|
listMode = TRUE;
|
|
|
|
|
}
|
2020-05-05 18:22:33 +00:00
|
|
|
|
}
|
2020-05-05 18:22:29 +00:00
|
|
|
|
|
2020-05-05 18:22:42 +00:00
|
|
|
|
#ifdef _UNALZ_ICONV
|
|
|
|
|
if(count>=argc) {Usage();return 0;} // <20>ɼǸ<C9BC> <20><><EFBFBD><EFBFBD> <20><>¼<EFBFBD><C2BC><EFBFBD><EFBFBD>..
|
2020-05-05 18:22:31 +00:00
|
|
|
|
if(destcodepage) unalz.SetDestCodepage(destcodepage);
|
|
|
|
|
#endif
|
2020-05-05 18:22:29 +00:00
|
|
|
|
|
2020-05-05 18:22:31 +00:00
|
|
|
|
// <20>ҽ<EFBFBD> <20><><EFBFBD><EFBFBD>
|
|
|
|
|
source=argv[count];
|
|
|
|
|
count++;
|
2020-05-05 18:22:29 +00:00
|
|
|
|
|
2020-05-05 18:22:31 +00:00
|
|
|
|
// <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
|
|
|
|
if(count<argc)
|
|
|
|
|
{
|
|
|
|
|
destpath = argv[count];
|
|
|
|
|
count++;
|
|
|
|
|
}
|
2020-05-05 18:22:42 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
for (count=1 ; count < argc; count++)
|
|
|
|
|
{
|
|
|
|
|
#ifdef _UNALZ_ICONV
|
|
|
|
|
// utf8 <20>ɼ<EFBFBD> ó<><C3B3>
|
|
|
|
|
if(strcmp(argv[count], "-utf8")==0)
|
|
|
|
|
{
|
|
|
|
|
destcodepage = "UTF-8"; // utf-8 support
|
|
|
|
|
}
|
|
|
|
|
else if(strcmp(argv[count], "-cp949")==0)
|
|
|
|
|
{
|
|
|
|
|
destcodepage = "CP949"; // cp949
|
|
|
|
|
}
|
|
|
|
|
else if(strcmp(argv[count], "-euc-kr")==0)
|
|
|
|
|
{
|
|
|
|
|
destcodepage = "EUC-KR"; // EUC-KR
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
#endif
|
|
|
|
|
if(strcmp(argv[count], "-l")==0 || strcmp(argv[count], "-list")==0)
|
|
|
|
|
{
|
|
|
|
|
listMode = TRUE;
|
|
|
|
|
}
|
|
|
|
|
else if(strcmp(argv[count], "-d")==0) // dest dir
|
|
|
|
|
{
|
|
|
|
|
count++;
|
|
|
|
|
if(count>=argc) {Usage();return 0;} // dest dir <20><> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ʾҴ<CABE>..
|
|
|
|
|
destpath = argv[count];
|
|
|
|
|
}
|
|
|
|
|
else // <20>ɼ<EFBFBD><C9BC><EFBFBD> <20>ƴ<EFBFBD> <20><><EFBFBD><EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
if(source==NULL) // <20>ҽ<EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
source=argv[count];
|
|
|
|
|
}
|
|
|
|
|
else // <20><><EFBFBD><EFBFBD>Ǯ <20><><EFBFBD><EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
filelist.push_back(argv[count]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(source==NULL) {Usage();return 0;} // <20>ɼǸ<C9BC> <20><><EFBFBD><EFBFBD> <20><>¼<EFBFBD><C2BC><EFBFBD><EFBFBD>..
|
|
|
|
|
|
|
|
|
|
#ifdef _UNALZ_ICONV
|
|
|
|
|
if(destcodepage) unalz.SetDestCodepage(destcodepage);
|
|
|
|
|
#endif
|
2020-05-05 18:22:29 +00:00
|
|
|
|
|
|
|
|
|
|
2020-05-05 18:22:31 +00:00
|
|
|
|
// <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
2020-05-05 18:22:29 +00:00
|
|
|
|
if(unalz.Open(source)==FALSE)
|
|
|
|
|
{
|
2020-05-05 18:22:38 +00:00
|
|
|
|
if(unalz.GetLastErr()==CUnAlz::ERR_CORRUPTED_FILE)
|
|
|
|
|
{
|
2020-05-05 18:22:42 +00:00
|
|
|
|
printf("It's corrupted file.\n"); // <20>׳<EFBFBD> <20><><EFBFBD><EFBFBD> Ǯ<><C7AE>..
|
2020-05-05 18:22:38 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
printf("file open error : %s\n", source);
|
|
|
|
|
printf("err code(%d) (%s)\n", unalz.GetLastErr(), unalz.GetLastErrStr());
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2020-05-05 18:22:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-05 18:22:42 +00:00
|
|
|
|
if (listMode)
|
|
|
|
|
{
|
|
|
|
|
return ListAlz(&unalz, source);
|
2020-05-05 18:22:35 +00:00
|
|
|
|
}
|
2020-05-05 18:22:42 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if(unalz.IsEncrypted())
|
|
|
|
|
{
|
|
|
|
|
char pwd[256];
|
|
|
|
|
printf("Enter Password : ");
|
|
|
|
|
fgets(pwd,256,stdin);
|
|
|
|
|
unalz.setPassword(pwd);
|
|
|
|
|
}
|
2020-05-05 18:22:35 +00:00
|
|
|
|
|
2020-05-05 18:22:42 +00:00
|
|
|
|
printf("\nExtract %s to %s\n", source, destpath);
|
2020-05-05 18:22:29 +00:00
|
|
|
|
|
2020-05-05 18:22:42 +00:00
|
|
|
|
// callback <20>Լ<EFBFBD> <20><><EFBFBD><EFBFBD>
|
|
|
|
|
unalz.SetCallback(UnAlzCallback, (void*)NULL);
|
2020-05-05 18:22:29 +00:00
|
|
|
|
|
2020-05-05 18:22:42 +00:00
|
|
|
|
if (filelist.empty()==false) // <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ϱ<EFBFBD>.
|
|
|
|
|
{
|
|
|
|
|
vector<string>::iterator i;
|
|
|
|
|
for(i=filelist.begin();i<filelist.end();i++)
|
|
|
|
|
{
|
|
|
|
|
if(unalz.SetCurrentFile(i->c_str())==FALSE)
|
|
|
|
|
{
|
|
|
|
|
printf("filename not matched : %s\n", i->c_str());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
unalz.ExtractCurrentFile(destpath);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else // <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><>Ǯ<EFBFBD><C7AE>.
|
|
|
|
|
{
|
|
|
|
|
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());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
printf("\ndone..\n");
|
|
|
|
|
}
|
2020-05-05 18:22:38 +00:00
|
|
|
|
|
2020-05-05 18:22:29 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|