⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 makezip.c

📁 有关zip的一个开发实例。主要包括图片和程序源代码。
💻 C
📖 第 1 页 / 共 2 页
字号:
/* Copyright (C) 1996 Mike White Permission is granted to any individual or institution to use, copy, or redistribute this software so long as all of the original files are included, that it is not sold for profit, and that this copyright notice is retained.*/#ifdef __BORLANDC__#include <dir.h>#endif#include <direct.h>#include <string.h>#include <io.h>#include <stdio.h>#include <ctype.h>#include <dos.h>#include <fcntl.h>#include <io.h>#include "wiz.h"#include "helpids.h"#ifndef WIN32#include <lzexpand.h>#endif/* Define size of read/write buffer for copying files */#define READ_WRITE_BUF 4096extern char **pszIndex;extern char *sz;extern LPSTR szFileList;extern HANDLE hFileList;extern int ZipRetCode;BOOL fMakeDosSFX;BOOL fMakeSFX;char szTempFileName[PATH_MAX];char szTargetName[PATH_MAX];static char szTargetFileName[PATH_MAX] = "";char __based(__segname("STRINGS_TEXT")) szTargetZipDir[PATH_MAX];char __based(__segname("STRINGS_TEXT")) szTargetZipFile[PATH_MAX] = "";char __based(__segname("STRINGS_TEXT")) szCantMakeZip[] =   "Internal error: Cannot make zip file. Common dialog error code is 0x%lX.";void MakeArchive(HWND hWnd){char tempFileName[PATH_MAX], tempPath[PATH_MAX];/* temporary zip options flags */BOOL fVerbose,fForce,fSystem,fVolume,fNoDirEntries,fJunkDir,fCRLF_LF,     fLF_CRLF,fEncrypt,fRecurse,fMove,fLatestTime,fUpdate,fFreshen,     fQuiet,fComment,fmakesfx,fOffsets, fExtra;#ifdef WIN32BOOL fPrivilege, fdossfx;#endifchar fLevel;int fRepair;#ifndef WIN32   FARPROC lpfnGetFilesProc;#endif/* Save zip options flags */fRepair       = ZpOpt.fRepair;#ifdef WIN32fPrivilege    = ZpOpt.fPrivilege;#endiffExtra        = ZpOpt.fExtra;fVerbose      = ZpOpt.fVerbose;fForce        = ZpOpt.fForce;fSystem       = ZpOpt.fSystem;fVolume       = ZpOpt.fVolume;fNoDirEntries = ZpOpt.fNoDirEntries;fJunkDir      = ZpOpt.fJunkDir;fCRLF_LF      = ZpOpt.fCRLF_LF;fLF_CRLF      = ZpOpt.fLF_CRLF;fEncrypt      = ZpOpt.fEncrypt;fRecurse      = ZpOpt.fRecurse;fMove         = ZpOpt.fMove;fLatestTime   = ZpOpt.fLatestTime;fUpdate       = ZpOpt.fUpdate;fFreshen      = ZpOpt.fFreshen;fQuiet        = ZpOpt.fQuiet;fComment      = ZpOpt.fComment;fLevel        = ZpOpt.fLevel;fmakesfx      = fMakeSFX;fOffsets      = ZpOpt.fOffsets;#ifdef WIN32fdossfx       = fMakeDosSFX;#endif#ifndef WIN32_fmemset(&lpumb->ofn, '\0', sizeof(OPENFILENAME)); /* initialize struct */#elsememset(&lpumb->ofn, '\0', sizeof(OPENFILENAME)); /* initialize struct */#endifWinAssert(hWnd);lpumb->szUnzipToDirNameTmp[0] = '\0';lpumb->ofn.lStructSize = sizeof(OPENFILENAME);lpumb->ofn.hwndOwner = hWnd;lpumb->ofn.hInstance = hInst;lpumb->ofn.lpstrFilter = "Zip Files (*.zip)\0*.zip\0Self-extracting Files (*.exe)\0*.exe\0All Files (*.*)\0*.*\0\0";lpumb->ofn.nFilterIndex = 1;lpumb->ofn.lpstrFile = lpumb->szUnzipToDirNameTmp; /* result goes here! */lpumb->ofn.nMaxFile = PATH_MAX;lpumb->ofn.lpstrFileTitle = NULL; /* NULL causes nMaxFileTitle to be ignored */lpumb->ofn.nMaxFileTitle = PATH_MAX; /* ignored ! */lpumb->ofn.lpstrTitle = (LPSTR)"Archive Name";lpumb->ofn.lpstrInitialDir =   (LPSTR)(!szTargetZipDir[0] ? NULL : szTargetZipDir);lpumb->ofn.Flags = OFN_SHOWHELP | OFN_HIDEREADONLY;uf.fTrailingSlash = FALSE; /* set trailing slash to FALSE */lpumb->szZipFileName[0] = '\0';dwCommDlgHelpId = HELPID_ZIP_GET_ARCHIVE_NAME;if (GetOpenFileName(&lpumb->ofn)) /* successfully got archive name ? */   {   if (lstrcmpi(lpumb->szUnzipToDirNameTmp, lpumb->szZipFileName)!=0)      {      lstrcpy(tempPath, lpumb->szUnzipToDirNameTmp);      if (!uf.fTrailingSlash) /* Do we have a trailing slash? */         { /* No - strip file name off and save it */         StripDirectory(tempPath);         lstrcpy(tempFileName, tempPath);         /* Strip file name off, we've just saved it */         GetDirectory(lpumb->szUnzipToDirNameTmp);         }      uf.fTrailingSlash = FALSE;      /* Okay, make the directory, if necessary */      lstrcpy(szTargetZipDir, lpumb->szUnzipToDirNameTmp);      if (MakeDirectory(lpumb->szUnzipToDirNameTmp, FALSE))         {         if (lpumb->szUnzipToDirNameTmp[0] != '\0')            lstrcat(lpumb->szUnzipToDirNameTmp, "\\");         lstrcat(lpumb->szUnzipToDirNameTmp, tempFileName);         /* lpumb->szUnzipToDirNameTmp now contains the fully qualified            zip file name.         */         if (strrchr(lpumb->szUnzipToDirNameTmp, '.') == NULL)            {            if (!fMakeSFX)               lstrcat(lpumb->szUnzipToDirNameTmp, ".zip");            else               lstrcat(lpumb->szUnzipToDirNameTmp, ".exe");            }         lstrcpy(szTargetFileName, lpumb->szUnzipToDirNameTmp);         lstrcpy(lpumb->szZipFileName, lpumb->szUnzipToDirNameTmp);         ZpZCL.lpszZipFN = szTargetFileName;         }      if (fSaveZipToDir)         {         getcwd(szTargetZipDir, PATH_MAX);         WriteZipOptionsProfile();         }   /* NOTE: Here is where we must actually call to get the files      to go into the archive. All we've done so far is get the      archive name.   */      {      dwCommDlgHelpId = HELPID_ZIP_SELECT_FILES;#ifndef WIN32      _fmemset(&lpumb->ofn, '\0', sizeof(OPENFILENAME)); /* initialize struct */#else      memset(&lpumb->ofn, '\0', sizeof(OPENFILENAME)); /* initialize struct */#endif      WinAssert(hWnd);      szTargetZipFile[0] = '\0';      lpumb->ofn.lStructSize = sizeof(OPENFILENAME);      lpumb->ofn.hwndOwner = hWnd;      lpumb->ofn.hInstance = hInst;      lpumb->ofn.lpstrFilter = "All Files (*.*)\0*.*\0\0";      lpumb->ofn.nFilterIndex = 1;      lpumb->ofn.lpstrFile = szTargetZipFile;      lpumb->ofn.nMaxFile = PATH_MAX;      lpumb->ofn.lpstrFileTitle = NULL;      lpumb->ofn.nMaxFileTitle = PATH_MAX; /* ignored ! */      wsprintf(lpumb->szBuffer, "Archive %s", lpumb->szZipFileName);      lpumb->ofn.lpstrTitle = (LPSTR) lpumb->szBuffer;      lpumb->ofn.lpstrInitialDir =         (LPSTR)(!szTargetZipDir[0] ? NULL : szTargetZipDir);      lpumb->ofn.Flags = OFN_SHOWHELP | OFN_ENABLEHOOK | OFN_CREATEPROMPT |         OFN_HIDEREADONLY|OFN_ENABLETEMPLATE;#ifndef WIN32      lpfnGetFilesProc = MakeProcInstance((FARPROC)GetFilesProc, hInst);#   ifndef MSC      (UINT CALLBACK *)lpumb->ofn.lpfnHook = (UINT CALLBACK *)lpfnGetFilesProc;#   else      lpumb->ofn.lpfnHook = lpfnGetFilesProc;#   endif#else      lpumb->ofn.lpfnHook = (LPOFNHOOKPROC)GetFilesProc;#endif      lpumb->ofn.lpTemplateName = "GETFILES";   /* see getfiles.dlg   */      if (GetOpenFileName(&lpumb->ofn) && (hFileList &&             (ZpZCL.lpszZipFN[0] != '\0')) ||             (ZpOpt.fRepair && (ZpZCL.lpszZipFN[0] != '\0')))         {         char *ptr;         UpdateWindow(hWndMain);         if (fMakeSFX)            {            ptr = strrchr(lpumb->szZipFileName, '.') + 1;            *ptr = '\0';            lstrcat(lpumb->szZipFileName, "exe");            lstrcpy(ZpZCL.lpszZipFN, lpumb->szZipFileName);            }         ZpZCL.FNV = (char **)szFileList;         if (!ZpOpt.fRepair)            BufferOut( "Creating/Updating Archive: %s\n",               lpumb->szZipFileName);         else            if (ZpZCL.argc != 0)               BufferOut( "Repairing/Updating Archive: %s\n",                  lpumb->szZipFileName);            else               BufferOut( "Repairing Archive: %s\n",                  lpumb->szZipFileName);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -