unalz/main.cpp

144 lines
3.3 KiB
C++
Raw Normal View History

2020-05-05 18:22:29 +00:00
#include <stdio.h>
#include "UnAlz.h"
void Usage()
{
printf("\n");
2020-05-05 18:22:31 +00:00
#ifdef _UNALZ_ICONV
printf("USAGE : unalz [-utf8 | -cp949] sourcefile.alz [dest path] \n");
# 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: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");
printf("unalz v0.23 (2004/10/30) \n");
2020-05-05 18:22:29 +00:00
printf("copyright(C) 2004 http://www.kipple.pe.kr\n");
if(argc<2)
{
Usage();
return 0;
}
2020-05-05 18:22:31 +00:00
CUnAlz unalz;
char* source=NULL;
char* destpath=".";
char* destcodepage=NULL;
int count=1;
// utf8 <20>ɼ<EFBFBD> ó<><C3B3>
#ifdef _UNALZ_ICONV
if(strcmp(argv[count], "-utf8")==0)
{
destcodepage = "UTF-8"; // utf-8 support
count++;
}
else if(strcmp(argv[count], "-cp949")==0)
{
destcodepage = "CP949"; // cp959
count++;
}
2020-05-05 18:22:33 +00:00
else if(strcmp(argv[count], "-euc-kr")==0)
{
destcodepage = "EUC-KR"; // EUC-KR
count++;
}
2020-05-05 18:22:31 +00:00
if(count>=argc) {Usage();return 0;} // <20>ɼǸ<C9BC> <20><><EFBFBD><EFBFBD> <20><>¼<EFBFBD><C2BC><EFBFBD><EFBFBD>..
2020-05-05 18:22:29 +00:00
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: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:31 +00:00
printf("file open error : %s\n", source);
printf("err code(%d) (%s)\n", unalz.GetLastErr(), unalz.GetLastErrStr());
2020-05-05 18:22:29 +00:00
return 0;
}
2020-05-05 18:22:31 +00:00
printf("\nExtract %s to %s\n", source, destpath);
2020-05-05 18:22:29 +00:00
// callback <20>Լ<EFBFBD> <20><><EFBFBD><EFBFBD>
unalz.SetCallback(UnAlzCallback, (void*)NULL);
2020-05-05 18:22:31 +00:00
if(unalz.ExtractAll(destpath)==FALSE)
2020-05-05 18:22:29 +00:00
{
2020-05-05 18:22:31 +00:00
printf("extract %s to %s failed.\n", source, destpath);
printf("err code(%d) (%s)\n", unalz.GetLastErr(), unalz.GetLastErrStr());
2020-05-05 18:22:29 +00:00
}
printf("\ndone..\n");
return 0;
}