/* * Copyright (c) 2000 S.Noda * * Permission to use, copy, modify, and distribute this software * and its documentation for any purpose is hereby granted provided * that the above copyright notice and this permission notice appear * in all copies of the software and related documentation. * * NO WARRANTY * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY WARRANTIES; * WITHOUT EVEN THE IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS * FOR A PARTICULAR PURPOSE. */ #include #include #include #include "unzipdll.h" #ifndef _CRT_WARN #define _CRT_WARN 0 #define _CRT_ERROR 1 #define _CRT_ASSERT 2 #define _CRT_ERRCNT 3 #endif #ifndef _RPTF0 #define _RPTF0(rptno, msg) #define _RPTF1(rptno, msg, arg1) #define _RPTF2(rptno, msg, arg1, arg2) #define _RPTF3(rptno, msg, arg1, arg2, arg3) #define _RPTF4(rptno, msg, arg1, arg2, arg3, arg4) #endif #define UNZ_DLL_NAME "UNZIP32.DLL\0" int WINAPI UzpPrnt(LPSTR buf, unsigned long size) { printf("%s", buf); return (unsigned int)size; } int WINAPI UzpPassword(LPSTR p, int n, LPCSTR m, LPCSTR name) { fprintf(stderr, "%s", m); scanf("%s", p); return 0; } int WINAPI UzpService(LPCSTR filename, unsigned long size) { _RPTF2(_CRT_WARN, "\n", filename, size); return FALSE; } void WINAPI UzpSnd() { _RPTF0(_CRT_WARN, "\n"); } int WINAPI UzpReplace(LPSTR filename) { fprintf(stderr, "This is where you will decide if you want to replace, rename etc existing files. "); scanf("%s", filename); return TRUE; } char *pszCompFactor(unsigned long ucsize, unsigned long csiz, unsigned cfactor) { char CompFactorStr[] = "%c%d%%"; char CompFactor100[] = "100%%"; static char szCompFactor[10]; char sgn; if (csiz > ucsize) sgn = '-'; else sgn = ' '; if (cfactor == 100) lstrcpy(szCompFactor, CompFactor100); else sprintf(szCompFactor, CompFactorStr, sgn, cfactor); return szCompFactor; } void WINAPI UzpMessage(unsigned long ucsize, unsigned long csiz, unsigned cfactor, unsigned mo, unsigned dy, unsigned yr, unsigned hh, unsigned mm, char c, LPSTR filename, LPSTR methbuf, unsigned long crc, char fCrypt) { char psLBEntry[_MAX_PATH]; char LongHdrStats[] = "%7lu %7lu %4s %02u-%02u-%02u %02u:%02u %c%s"; wsprintf(psLBEntry, LongHdrStats, ucsize, csiz, pszCompFactor(ucsize, csiz, cfactor), mo, dy, yr, hh, mm, c, filename); printf("%s\n", psLBEntry); _RPTF4(_CRT_WARN, "methbuf: %s, crc: %x, fCrypt: %c, filename: %s\n", methbuf, crc, fCrypt, filename); } int UzpMain(int ifnc, char **ifnv, int xfnc, char **xfnv, LPDCL lpCL) { HANDLE hUF = GlobalAlloc(GPTR, (DWORD)sizeof(USERFUNCTIONS)); if (!hUF) { return 0; } LPUSERFUNCTIONS lpUserFunc = (LPUSERFUNCTIONS)GlobalLock(hUF); if (!lpUserFunc) { GlobalFree(hUF); return 0; } lpUserFunc->print = UzpPrnt; lpUserFunc->sound = UzpSnd; lpUserFunc->replace = UzpReplace; lpUserFunc->password = UzpPassword; lpUserFunc->SendApplicationMessage = UzpMessage; lpUserFunc->ServCallBk = (lpCL->nZIflag) ? NULL : UzpService; HINSTANCE hUnzipDll = LoadLibrary(UNZ_DLL_NAME); if (!hUnzipDll) { GlobalUnlock(hUF); GlobalFree(hUF); return 0; } UZP_VERSION2 fpUzpVersion2 = (UZP_VERSION2)GetProcAddress(hUnzipDll, "UzpVersion2"); WIZ_SINGLEENTRYUNZIP fpWiz_SingleEntryUnzip = (WIZ_SINGLEENTRYUNZIP)GetProcAddress(hUnzipDll, "Wiz_SingleEntryUnzip"); if (!fpUzpVersion2 || !fpWiz_SingleEntryUnzip) { GlobalUnlock(hUF); GlobalFree(hUF); return 0; } UzpVer2 ver; (*fpUzpVersion2)(&ver); _RPTF1(_CRT_WARN, "\n", ver.date); _RPTF3(_CRT_WARN, "\n", ver.zipinfo.major, ver.zipinfo.minor, ver.zipinfo.patchlevel); _RPTF3(_CRT_WARN, "\n", ver.windll.major, ver.windll.minor, ver.windll.patchlevel); if (ver.windll.major == 5 && ver.windll.minor == 4) { int retcode = (*fpWiz_SingleEntryUnzip)(ifnc, ifnv, xfnc, xfnv, lpCL, lpUserFunc); _RPTF1(_CRT_WARN, "\n", lpUserFunc->TotalSizeComp); _RPTF1(_CRT_WARN, "\n", lpUserFunc->TotalSize); _RPTF1(_CRT_WARN, "\n", pszCompFactor(lpUserFunc->TotalSize, lpUserFunc->TotalSizeComp, lpUserFunc->CompFactor)); _RPTF1(_CRT_WARN, "\n", lpUserFunc->NumMembers); _RPTF1(_CRT_WARN, "\n", lpUserFunc->cchComment); } GlobalUnlock(hUF); GlobalFree(hUF); FreeLibrary(hUnzipDll); return 1; }