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

📄 extract.c

📁 完整的解压zip文件的源码。包含密码功能
💻 C
📖 第 1 页 / 共 5 页
字号:
        } else {            if (num_dirs == 1)                sorted_dirlist[0] = dirlist;            else {                for (i = 0;  i < num_dirs;  ++i) {                    sorted_dirlist[i] = dirlist;                    dirlist = dirlist->next;                }                qsort((char *)sorted_dirlist, num_dirs, sizeof(dirtime *),                  dircomp);            }            Trace((stderr, "setting directory times/perms/attributes\n"));            for (i = 0;  i < num_dirs;  ++i) {                dirtime *d = sorted_dirlist[i];                Trace((stderr, "dir = %s\n", d->fn));                if ((error = set_direc_attribs(__G__ d)) != PK_OK) {                    Info(slide, 0x201, ((char *)slide,                      LoadFarString(DirlistSetAttrFailed), d->fn));                    if (!error_in_archive)                        error_in_archive = error;                }                free(d->fn);                free(d);            }            free(sorted_dirlist);        }    }#endif /* SET_DIR_ATTRIB */#if (defined(WIN32) && defined(NTSD_EAS))    process_defer_NT(__G);  /* process any deferred items for this .zip file */#endif/*---------------------------------------------------------------------------    Check for unmatched filespecs on command line and print warning if any    found.  Free allocated memory.  ---------------------------------------------------------------------------*/    if (fn_matched) {        for (i = 0;  i < G.filespecs;  ++i)            if (!fn_matched[i]) {#ifdef DLL                if (!G.redirect_data && !G.redirect_text)                    Info(slide, 0x401, ((char *)slide,                      LoadFarString(FilenameNotMatched), G.pfnames[i]));                else                    setFileNotFound(__G);#else                Info(slide, 1, ((char *)slide,                  LoadFarString(FilenameNotMatched), G.pfnames[i]));#endif                if (error_in_archive <= PK_WARN)                    error_in_archive = PK_FIND;   /* some files not found */            }        free((zvoid *)fn_matched);    }    if (xn_matched) {        for (i = 0;  i < G.xfilespecs;  ++i)            if (!xn_matched[i])                Info(slide, 0x401, ((char *)slide,                  LoadFarString(ExclFilenameNotMatched), G.pxnames[i]));        free((zvoid *)xn_matched);    }/*---------------------------------------------------------------------------    Double-check that we're back at the end-of-central-directory record, and    print quick summary of results, if we were just testing the archive.  We    send the summary to stdout so that people doing the testing in the back-    ground and redirecting to a file can just do a "tail" on the output file.  ---------------------------------------------------------------------------*/#ifndef SFX    if (readbuf(__G__ G.sig, 4) == 0)        error_in_archive = PK_EOF;    if (strncmp(G.sig, end_central_sig, 4)) {   /* just to make sure */        Info(slide, 0x401, ((char *)slide, LoadFarString(EndSigMsg)));        Info(slide, 0x401, ((char *)slide, LoadFarString(ReportMsg)));        if (!error_in_archive)       /* don't overwrite stronger error */            error_in_archive = PK_WARN;    }#endif /* !SFX */    if (uO.tflag) {        unsigned num = filnum - num_bad_pwd;        if (uO.qflag < 2) {        /* GRR 930710:  was (uO.qflag == 1) */            if (error_in_archive)                Info(slide, 0, ((char *)slide, LoadFarString(ErrorInArchive),                  (error_in_archive == 1)? "warning-" : "", G.zipfn));            else if (num == 0)                Info(slide, 0, ((char *)slide, LoadFarString(ZeroFilesTested),                  G.zipfn));            else if (G.process_all_files && (num_skipped+num_bad_pwd == 0))                Info(slide, 0, ((char *)slide, LoadFarString(NoErrInCompData),                  G.zipfn));            else                Info(slide, 0, ((char *)slide, LoadFarString(NoErrInTestedFiles)                  , G.zipfn, num, (num==1)? "":"s"));            if (num_skipped > 0)                Info(slide, 0, ((char *)slide, LoadFarString(FilesSkipped),                  num_skipped, (num_skipped==1)? "":"s"));#if CRYPT            if (num_bad_pwd > 0)                Info(slide, 0, ((char *)slide, LoadFarString(FilesSkipBadPasswd)                  , num_bad_pwd, (num_bad_pwd==1)? "":"s"));#endif /* CRYPT */        } else if ((uO.qflag == 0) && !error_in_archive && (num == 0))            Info(slide, 0, ((char *)slide, LoadFarString(ZeroFilesTested),              G.zipfn));    }    /* give warning if files not tested or extracted (first condition can still     * happen if zipfile is empty and no files specified on command line) */    if ((filnum == 0) && error_in_archive <= PK_WARN) {        if (num_skipped > 0)            error_in_archive = IZ_UNSUP; /* unsupport. compression/encryption */        else            error_in_archive = PK_FIND;  /* no files found at all */    }#if CRYPT    else if ((filnum == num_bad_pwd) && error_in_archive <= PK_WARN)        error_in_archive = IZ_BADPWD;    /* bad passwd => all files skipped */#endif    else if ((num_skipped > 0) && error_in_archive <= PK_WARN)        error_in_archive = IZ_UNSUP;     /* was PK_WARN; Jean-loup complained */#if CRYPT    else if ((num_bad_pwd > 0) && !error_in_archive)        error_in_archive = PK_WARN;#endif    return error_in_archive;} /* end function extract_or_test_files() *//***************************//*  Function store_info()  *//***************************/static int store_info(__G)   /* return 0 if skipping, 1 if OK */    __GDEF{#ifdef SFX#  define UNKN_COMPR \   (G.crec.compression_method!=STORED && G.crec.compression_method!=DEFLATED)#else#  ifdef COPYRIGHT_CLEAN  /* no reduced files */#    define UNKN_RED (G.crec.compression_method >= REDUCED1 && \                      G.crec.compression_method <= REDUCED4)#  else#    define UNKN_RED  FALSE  /* reducing not unknown */#  endif#  ifdef LZW_CLEAN  /* no shrunk files */#    define UNKN_SHR (G.crec.compression_method == SHRUNK)#  else#    define UNKN_SHR  FALSE  /* unshrinking not unknown */#  endif#  define UNKN_COMPR (UNKN_RED || UNKN_SHR || \   G.crec.compression_method==TOKENIZED || G.crec.compression_method>DEFLATED)#endif/*---------------------------------------------------------------------------    Check central directory info for version/compatibility requirements.  ---------------------------------------------------------------------------*/    G.pInfo->encrypted = G.crec.general_purpose_bit_flag & 1;   /* bit field */    G.pInfo->ExtLocHdr = (G.crec.general_purpose_bit_flag & 8) == 8;  /* bit */    G.pInfo->textfile = G.crec.internal_file_attributes & 1;    /* bit field */    G.pInfo->crc = G.crec.crc32;    G.pInfo->compr_size = G.crec.csize;    G.pInfo->uncompr_size = G.crec.ucsize;    switch (uO.aflag) {        case 0:            G.pInfo->textmode = FALSE;   /* bit field */            break;        case 1:            G.pInfo->textmode = G.pInfo->textfile;   /* auto-convert mode */            break;        default:  /* case 2: */            G.pInfo->textmode = TRUE;            break;    }    if (G.crec.version_needed_to_extract[1] == VMS_) {        if (G.crec.version_needed_to_extract[0] > VMS_UNZIP_VERSION) {            if (!((uO.tflag && uO.qflag) || (!uO.tflag && !QCOND2)))                Info(slide, 0x401, ((char *)slide, LoadFarString(VersionMsg),                  FnFilter1(G.filename), "VMS",                  G.crec.version_needed_to_extract[0] / 10,                  G.crec.version_needed_to_extract[0] % 10,                  VMS_UNZIP_VERSION / 10, VMS_UNZIP_VERSION % 10));            return 0;        }#ifndef VMS   /* won't be able to use extra field, but still have data */        else if (!uO.tflag && !uO.overwrite_all) { /* if -o, extract anyway */            Info(slide, 0x481, ((char *)slide, LoadFarString(VMSFormatQuery),              FnFilter1(G.filename)));            fgets(G.answerbuf, 9, stdin);            if ((*G.answerbuf != 'y') && (*G.answerbuf != 'Y'))                return 0;        }#endif /* !VMS */    /* usual file type:  don't need VMS to extract */    } else if (G.crec.version_needed_to_extract[0] > UNZIP_VERSION) {        if (!((uO.tflag && uO.qflag) || (!uO.tflag && !QCOND2)))            Info(slide, 0x401, ((char *)slide, LoadFarString(VersionMsg),              FnFilter1(G.filename), "PK",              G.crec.version_needed_to_extract[0] / 10,              G.crec.version_needed_to_extract[0] % 10,              UNZIP_VERSION / 10, UNZIP_VERSION % 10));        return 0;    }    if UNKN_COMPR {        if (!((uO.tflag && uO.qflag) || (!uO.tflag && !QCOND2))) {#ifndef SFX            if (G.crec.compression_method < NUM_METHODS)                Info(slide, 0x401, ((char *)slide, LoadFarString(ComprMsgName),                  FnFilter1(G.filename),                  LoadFarStringSmall(ComprNames[G.crec.compression_method])));            else#endif                Info(slide, 0x401, ((char *)slide, LoadFarString(ComprMsgNum),                  FnFilter1(G.filename),                  G.crec.compression_method));        }        return 0;    }#if (!CRYPT)    if (G.pInfo->encrypted) {        if (!((uO.tflag && uO.qflag) || (!uO.tflag && !QCOND2)))            Info(slide, 0x401, ((char *)slide, LoadFarString(SkipEncrypted),              FnFilter1(G.filename)));        return 0;    }#endif /* !CRYPT */    /* map whatever file attributes we have into the local format */    mapattr(__G);   /* GRR:  worry about return value later */    G.pInfo->offset = (long)G.crec.relative_offset_local_header;    return 1;} /* end function store_info() *//***************************************//*  Function extract_or_test_member()  *//***************************************/static int extract_or_test_member(__G)    /* return PK-type error code */     __GDEF{    char *nul="[empty] ", *txt="[text]  ", *bin="[binary]";#ifdef CMS_MVS    char *ebc="[ebcdic]";#endif    register int b;    int r, error=PK_COOL;#if (defined(DLL) && !defined(NO_SLIDE_REDIR))    ulg wsize;#else#   define wsize WSIZE#endif/*---------------------------------------------------------------------------    Initialize variables, buffers, etc.  ---------------------------------------------------------------------------*/    G.bits_left = 0;    G.bitbuf = 0L;       /* unreduce and unshrink only */    G.zipeof = 0;    G.newfile = TRUE;    G.crc32val = CRCVAL_INITIAL;#ifdef SYMLINKS    /* if file came from Unix and is a symbolic link and we are extracting     * to disk, prepare to restore the link */    if (S_ISLNK(G.pInfo->file_attr) &&        (G.pInfo->hostnum == UNIX_ || G.pInfo->hostnum == ATARI_ ||         G.pInfo->hostnum == BEOS_) &&        !uO.tflag && !uO.cflag && (G.lrec.ucsize > 0))        G.symlnk = TRUE;    else        G.symlnk = FALSE;#endif /* SYMLINKS */    if (uO.tflag) {        if (!uO.qflag)            Info(slide, 0, ((char *)slide, LoadFarString(ExtractMsg), "test",              FnFilter1(G.filename), "", ""));    } else {#ifdef DLL        if (uO.cflag && !G.redirect_data)#else        if (uO.cflag)#endif        {#if (defined(OS2) && defined(__IBMC__) && (__IBMC__ >= 200))            G.outfile = freopen("", "wb", stdout);   /* VAC++ ignores setmode */#else            G.outfile = stdout;#endif#ifdef DOS_FLX_H68_OS2_W32#if (defined(__HIGHC__) && !defined(FLEXOS))            setmode(G.outfile, _BINARY);#else /* !(defined(__HIGHC__) && !defined(FLEXOS)) */            setmode(fileno(G.outfile), O_BINARY);#endif /* ?(defined(__HIGHC__) && !defined(FLEXOS)) */#           define NEWLINE "\r\n"#else /* !DOS_FLX_H68_OS2_W32 */#           define NEWLINE "\n"#endif /* ?DOS_FLX_H68_OS2_W32 */#ifdef VMS

⌨️ 快捷键说明

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