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

📄 kaeziparchiveimplement.cpp

📁 zip解压源码.
💻 CPP
📖 第 1 页 / 共 5 页
字号:

        sf = (SFS *) malloc_chk(                // get enough memory
            sizeof(SFS) * pos_count - j);       // ..for each selected file

        for (i = 0; j < pos_count; j++)         // for each positional parm
        {
            touppers(pos_parms[j]);             // uppercase the string
            StrCpy(sf[i].path, pos_parms[j]);   // ..copy to structure
            SPLIT(sf[i]);                       // ..and split into components
            i++;                                // ..bump index
        }

        sf_count = i;                           // save select file count
    }

    if (sw_exclude)                             // q. exclude mask given?
    {                                       // a. yes .. set up structure
        touppers(sw_exclude);                   // ..uppercase the string
        StrCpy(ef.path, sw_exclude);            // ..copy to structure
        SPLIT(ef);                              // ..and split into components
    }

    StrCpy(zfn, pos_parms[0]);                  // copy zipfile to global area
    touppers(zfn);                              // ..and put into uppercase

    if (NOT extension_given(zfn))               // q. file extension given?
        StrCat(zfn, ".ZIP");                    // a. no .. append one

    if ((ifile = fopen(zfn, "rb")) == NULL)     // q. requested zip file avail?
        quit_with(no_zip_found, zfn);           // a. no .. quit w/error msg

    if (*output_path && change_dir(output_path))// q. output directory available?
    {                                       // a. no .. handle error
        if (sw_dirs)                            // q. make directories?
        {                                   // a. yes .. try creating dir
            if (make_path(output_path))         // q. create directory ok?
                quit_with(dir_error);           // a. no .. quit w/err message
        }
        else
            quit_with(invalid_dir);             // else .. quit w/err message
    }

    getcwd(output_path, MAX_PATH);              // get fully qualified output path
    */
}

/* ******************************************************************** *
 *
 *  initialization2() -- initialization for IKSFile
 *
 * ******************************************************************** */
int KAEZipArchive::initialization2(IKSFile *piFile)
{
    total_files = 0;
    total_size = 0;
    total_csize = 0;

    crc = 0;                               // running crc 32 value
    bhold = 0;                             // bits hold area
    
    rsize = 0;                             // remaining size to process
    last_kpal = 0;                         // keep alive message time
    total_size = 0;                        // uncompressed sum
    total_csize = 0;                       // compressed sum
    
    //int     rc /*= 1*/,                         // errorlevel return code
    pos_count = 0;                         // positional parms count
    sf_count = 0;                          // select file parms count
    e_count = 0;                           // end of data counter/flag
    total_files = 0;                       // files processed
    
    // because init in KAEZipArchive::KAEZipArchive
    //sb_size = 0;                         // sliding buffer size
    
    bsize = 0;                             // bits left to process

    m_nActionCancel = 0;
    m_nZipFileCracked = 0;

    //StrCpy(zfn,szZipPathName);
    //ifile = fopen(zfn, "rb");

    ifile = _fopen(piFile, true);

    if(ifile == NULL)   //seawind added
        return 0;

    StrCpy(output_path,"");
    
    /*
    StrCpy(output_path, m_szTempPath);
    
    if(LAST(output_path) == '\\')            
        LAST(output_path) = '\0';
    */

    return 1;
}

/* ******************************************************************** *
 *
 *  extract_zip() -- extract files from a ZIP file
 *
 *  This routine is a sub-function of the scan_zip() routine.  The
 *  extract_zip() routine is call with the following function calls.
 *                                        
 *      0 = initialization call
 *      1 = current file number
 *      2 = completion call
 *
 * ******************************************************************** */
void KAEZipArchive::extract_zip(int fnc, LF *lfp)
{   
    switch (fnc)                                // based on function number
    {
    case 0:                                     // initialization call
        
        //printf(extract_hdr, sw_test ?       // print header information
        //    extract_test : extract_msg,     // ..giving "extract" or "test"
        //    zfn);                           // ..and filename
        
        
        // because sb is include in class
        //sb_size = (UINT) BUFFER_SIZE;       // set up the dictionary size
        //sb = (BYTE *) malloc_chk(sb_size);  // get memory for output buffer
        //sbe = &sb[sb_size];                 // set up end of buffer address
        break;                                // ..and return to caller
        
    case 1:                                 // process file call
        {
            m_nTempFileCreated = 0;         //added by seawind
            
            if (lfp->lf_flag & LH_FLAG_ENCRYPT) // q. encrypted file?
            {
                //printf(extract_encr,            // a. yes .. give message
                //        wf.path);               // ..and filename
                
                // ..seek past the compressed data
                if(fseek(ifile, lfp->lf_csize,SEEK_CUR) != 0)
                    m_nZipFileCracked = 1;
                
                return;                          // ..and skip this one
            }
            
            if (LAST(wf.path) == '\\')          // q. directory entry?
            {                                   // a. yes .. process it
                //if (sw_dirs && NOT sw_test &&   // q. build dirs but not testing?
                //         zip_select_file())     // ..and pass selection test?
                //{
                //   make_path(wf.path);         // a. yes .. build directory
                //    change_dir(output_path);    // ..and change back
                //}
                
                // finally, seek past compressed data
                if(fseek(ifile,lfp->lf_csize,SEEK_CUR) != 0)
                    m_nZipFileCracked = 1;
                
                return;                          // ..then skip this one
            }
            
            //if ((NOT zip_select_file()) ||      // q. bypass this file?
            //        extract_open(lfp))          // ..or output problems?
            
            if(! extract_open(lfp))             //seawind modified
            {
                if(fseek(ifile,lfp->lf_csize,SEEK_CUR) != 0)
                    m_nZipFileCracked = 1;
                
                return;
            }

            //temp file has been created
            m_nTempFileCreated = 1;             //added by seawind

            //seawind
            long curpos = ftell(ifile);
            long ifilesize = _fsize(ifile);
                
            if(curpos + (long)lfp->lf_csize - 1 > ifilesize)
                m_nZipFileCracked = 1;

            if(m_nActionCancel || m_nZipFileCracked)
            {
                ASSERT(m_nTempFileCreated);
                
                fclose(ofile);
                
                piKSFileMgr->DeleteFile(
                    StrLen(m_szPathNameInTemp) + 1,
                    m_szPathNameInTemp
                    );
                
                //m_nTempFileCreated = 0;
                                
                return;                                 
            }
            
            //printf(extract_line,                // print detail line
            //    decompr[lfp->lf_cm < 9 ?        // ..compression method
            //            lfp->lf_cm + 1 : 0],    // ..or unknown if unsupported
            //    wf.path);
            
            total_files++;                      // tally processed files
            total_size += lfp->lf_size;         // summarize uncompressed
            total_csize += lfp->lf_csize;       // ..and compressed sizes
            
            rsize = lfp->lf_csize;              // remaining filesize to process
            bsize = 0;                          // ..bits in byte to process
            e_count = 2;                        // end of data counter/flag
            crc = -1;                           // clear current crc
            sbp = sb;                           // reset next output pointer
            //last_kpal = 0;                      // clear keep alive timer
            //spin = 0;                           // ..next kpal character index
            memset(sb, 0, sb_size);             // ..and dictionary/output buffer
            
            switch (lfp->lf_cm)                 // based on compression method
            {
            case LF_CM_STORED:              // stored file
                extract_stored();           // process stored file
                break;                      // ..then do next file
                
            case LF_CM_SHRUNK:              // LZW shrunk file
                extract_shrunk();           // process shrunk file
                break;                      // ..then do next file
                
            case LF_CM_REDUCED1:            // reduced file #1
            case LF_CM_REDUCED2:            // reduced file #2
            case LF_CM_REDUCED3:            // reduced file #3
            case LF_CM_REDUCED4:            // reduced file #4
                extract_expand(lfp);        // process reduced file
                break;                      // ..then do next file
                
            case LF_CM_IMPLODED:            // imploded file
                extract_explode(lfp);       // process imploded file
                break;                      // ..then do next file
                
            case LF_CM_DEFLATED:            // deflated file
                
                //seawind modified
                if(lfp->lf_flag & LF_FLAG_DDREC)         // q. need data descriptor rec?
                {
                    ASSERT(m_nTempFileCreated);

                    fclose(ofile);

                    piKSFileMgr->DeleteFile(
                        StrLen(m_szPathNameInTemp) + 1,
                        m_szPathNameInTemp
                    );

                    //m_nTempFileCreated = 0;

                    if(fseek(ifile, lfp->lf_csize,SEEK_CUR) != 0)
                        m_nZipFileCracked = 1;
                        
                    return;
                }
                else
                    extract_inflate(lfp);   // process deflated file
                
                break;                      // ..then do next file
                
            case LF_CM_TOKENIZED:           // tokenized file
            default:
                
                //printf(extract_skip);     // bypass unknown file types

                ASSERT(m_nTempFileCreated);

                fclose(ofile);

                piKSFileMgr->DeleteFile(
                    StrLen(m_szPathNameInTemp) + 1,
                    m_szPathNameInTemp
                );

                //m_nTempFileCreated = 0;

                if(fseek(ifile, lfp->lf_csize,SEEK_CUR) != 0)
                    m_nZipFileCracked = 1;
                
                return;
            
            }//switch (lfp->lf_cm)
            
            extract_flush();                    // else .. flush our output buffer
            
            // not need to do this, because fclose do the same thing
            //fflush(ofile);                    // flush file system's buffers
            
            //_dos_setftime(fileno(ofile),      // set file's date and time
            //        lfp->lf_date, lfp->lf_time);
            
            fclose(ofile);                      // close output file

            if (!m_nZipFileCracked)
            {
                int len1 = StrLen(m_szFullNameInArchive) + 1;
                int len2 = StrLen(m_szPathNameInTemp) + 1;          
                KAEARCHIVESTATUS enumKAEArchiveStatus;
            
                crc ^= 0xffffffffL;                 // finalize crc value
            
                if(rsize == 0 && crc == lfp->lf_crc)
                    enumKAEArchiveStatus = enumKAEARCHIVE_OK;
                else
                    enumKAEArchiveStatus = enumKAEARCHIVE_FAIL;
            
                if(enumKAEArchiveStatus == enumKAEARCHIVE_OK && !(m_nActionCancel || m_nZipFileCracked))
                {
                    ASSERT(m_piArchiveCallBack);
                
                    KSCOMRESULT krResult = KSCOM_E_FAIL;
                
                    krResult = m_piArchiveCallBack->KAEArchiveProcess(
                        enumKAEArchiveStatus,
                        len1, m_szFullNameInArchive,
                        len2, m_szPathNameInTemp,
                        m_uUnCompressedSize, 0
                        );
                
                
                    if (krResult == KSCOM_E_USER_BREAK)
                        Stop(NULL);
                    else if (FAILED(krResult))
                        ASSERT(false);
                }
            }

            ASSERT(m_nTempFileCreated);

            piKSFileMgr->DeleteFile(
                StrLen(m_szPathNameInTemp) + 1,
                m_szPathNameInTemp
            );

⌨️ 快捷键说明

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