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

📄 kaeziparchiveimplement.cpp

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

            break;
            
            /*              
            //if (rsize)                          // q. use up input stream?
            //    quit_with(data_error);          // a. no .. quit w/err message
                  
            crc ^= 0xffffffffL;                 // finalize crc value
                    
            ASSERT(crc == lfp->lf_crc);         //seawind modified //exit
                      
            //if (crc != lfp->lf_crc)             // q. crc match?
            //    quit_with(crc_error);           // a. no .. quit w/err message
                        
            //if (sw_test)                        // q. testing files?
            //    printf(test_ok);                // a. yes .. give confirmation
            //else
            //    printf(" \n");                  // else .. just goto next line
            */
        }
        
    case 2:                                 // completion call
        //if (total_files)                    // q. anything done?
        //    printf(extract_done, sw_test ?  // a. yes .. print "extract" or
        //        extract_tc : extract_ec,    // .."test" complete message
        //        total_files);               // ..and total file count
        //else
        //    printf(extract_none);           // else .. say nothing happened
        //if (sb)
        //{
        //    free(sb);                           // free memory for output buffer
        //    sb_size = 0;                        // clean dictionary size
        //    sb = NULL;      
        //    sbe = NULL;
        //}
        
        
        break;                              // then return to caller
    }

    return;
}


/* ******************************************************************** *
 *
 *  extract_open() -- open the destination file for output
 *
 *  Returns: 1 = output file opened
 *           0 = skip file expansion
 *
 * ******************************************************************** */
int KAEZipArchive::extract_open(LF *lfp)
{
    char fname[MAX_PATH];

    /*
    if(LAST(output_path) != '\\')
        StrCat(output_path,"\\");

    StrCpy(fname,output_path);
    StrCat(fname,wf.fname);
    StrCat(fname,wf.ext);
    */

    //int nTempPathNameSize = StrLen(output_path) + 1;
    int nRetTempFileNameSize;

    piKSProvidePath->GetTmpFileName(
        0,//nTempPathNameSize,
        NULL,//output_path,
        MAX_PATH,
        fname,
        &nRetTempFileNameSize
        );

    ASSERT(nRetTempFileNameSize > 1);

    //seawind added
    StrCpy(m_szPathNameInTemp, fname);

    //seawind added
    int len = StrLen(m_szFullNameInArchive) + 1;
    ASSERT(len > 1);

    /*
    int nRetVal = 0;    // default is ok
    
    if (m_pfnPreProcessFile)
    {
        nRetVal = m_pfnPreProcessFile(
            len, m_szFullNameInArchive, 
            m_pvPreProcessContext
        );
    }
    */

    KSCOMRESULT krResult = KSCOM_E_FAIL;

    ASSERT(m_piArchiveCallBack != NULL);
    krResult = m_piArchiveCallBack->KAEArchivePreProcess(
        len, m_szFullNameInArchive
    );
    
    if (FAILED(krResult))   // include KSCOM_E_USER_BREAK and all error value
    {
        m_nActionCancel = 1;//cancel the action
        return 0;   //don't open it
    }


    switch(krResult)
    {
    case KSCOM_S_SKIP:      //no,don't open it and I want to see next one
        return 0;           //don't open it

    default:                // KSCOM_S_OK and other SUCCESSFUL value
        ofile = fopen(fname, "wb");
        if (!ofile)
            return 0;       //don't open it
    }

    return 1;               // open it

    /*
    char    fname[13];                          // filename string
    struct  find_t dde;                         // DOS directory entry

    if (sw_test)                                // q. test integrity?
    {                                           // a. yes .. open NUL for output
        if ((ofile = fopen("NUL", "w+")) == NULL)   // q. open nothing ok?
            quit_with(open_error);                  // a. no .. quit w/error

        return(0);                                  // else .. return ok
    }

    StrCpy(fname, wf.fname);                    // copy filename to work..
    StrCat(fname, wf.ext);                      // ..and extension

    if (*wf.dir && chdir(wf.dir))               // q. destination dir ok?
    {                                       // a. no .. not available
        if (sw_dirs)                            // q. make new directory?
        {                                   // a. yes .. create new one
            if (make_path(wf.dir))              // q. dir create ok?
                quit_with(invalid_dir);         // a. no .. quit w/err msg
        }
    }

    if (NOT _dos_findfirst(fname,               // q. find requested file
                FILE_ATTR, &dde))               // ..in target directory?
    {                                       // a. yes .. handle error
        if (sw_freshen || sw_new)               // q. freshen old or new files?
                                               // a. check dates and times
        {
            if ((((long) dde.wr_date << 16) + dde.wr_time) >=   // q. existing
              (((long) lfp->lf_date << 16) + lfp->lf_time)) // file newer?
            {
                change_dir(output_path);            // a. yes .. change back
                return(1);                          // ..and bypass this one
            }
        }
        else 
            if (NOT sw_overwrite)             // q. overwrite enabled?
            {                                   // a. no .. give user info
                printf(old_file, wf.path,           // give info on old file..
                        dde.size,                   // ..including file size
                        file_date(dde.wr_date,      // ..file date
                        dde.wr_time));          // ..and time

                printf(new_file,                    // then give info on new file..
                        lfp->lf_size,               // ..including file size
                        file_date(lfp->lf_date,     // ..file date
                            lfp->lf_time));         // ..and time

                if (overwrite_prompt())             // q. bypass this file?
                {
                    change_dir(output_path);        // a. yes .. change back
                    return(1);                      // ..and skip this file
                }
            }

        delete_file(fname);                     // delete/unlink/remove file

    }
    else
    {
        if (sw_freshen)                         // q. only freshening files?
        {
            change_dir(output_path);            // a. yes .. change back
            return(1);                          // ..and bypass this one
        }
    }

    if ((ofile = fopen(fname, "w+")) == NULL)   // q. create work this time?
        quit_with(open_error);                  // a. no .. quit w/error

    if (*wf.dir)                                // q. destination dir used?
        chdir(output_path);                     // a. yes .. chg back to base path

    return(0);                                  // ..and process this file
    */
}

/* ******************************************************************** *
 *
 *  extract_stored() -- extract a stored file
 *
 * ******************************************************************** */
void KAEZipArchive::extract_stored()
{
    extract_copy(rsize);                        // copy stored data to file
}

/* ******************************************************************** *
 *
 *  extract_copy() -- copy stored data to output stream
 *
 * ******************************************************************** */
void KAEZipArchive::extract_copy(ULONG len)
{
    char   *b,                                  // work buffer pointer
           *p;                                  // work pointer
    UINT    csize = 0;                          // current read size


    b = (char *) malloc_chk((UINT) COPY_BUFFER);// get an file buffer
    ASSERT(b != NULL);                          //seawind added
    if (!b)
    {
        m_nZipFileCracked = 1;
        return;
    }


    while (len)                                 // loop copying file to output
    {
        //seawind added for stop
        if(m_nActionCancel || m_nZipFileCracked)
            break;

        csize = (len <= COPY_BUFFER) ?          // determine next read size
                (int) len : (UINT) COPY_BUFFER;

        //if (fread(b, 1, csize, ifile) != csize) // q. read ok?
        //  quit_with(read_error);              // a. no .. quit w/error msg
        
        if(fread(b, 1, csize, ifile) != (int)csize)  //seawind modified
        {
            m_nZipFileCracked = 1;
            goto Exit0;
        }

        rsize -= csize;                         // decrement remaining length
        len -= csize;                           // ..and loop control length

        for (p = b; csize--;)                   // for the whole block
            store_char(*p++);                   // ..write output data
    }

Exit0:

    free(b);                                    // ..and release file buffer

}

/* ******************************************************************** *
 *
 *  extract_shrunk() -- extract a LZW shrunk file
 *
 * ******************************************************************** */
void KAEZipArchive::extract_shrunk()
{
    int     b_c,                                // base code
            p_c,                                // previous code
            s_c,                                // saved code
            c;                                  // current code
    UINT    cnt;                                // decode stack counter
    char    cs = 9;                             // code size
    
    /*
    SD      huge *dict,                         // main dictionary
            huge *d,                            // dictionary entry pointer
            huge *fd,                           // next free pointer
            huge *ld;                           // last entry
    char    huge *decode_stack;                 // decode stack
    */

    //seawind added
    SD      *dict,                         // main dictionary
            *d,                            // dictionary entry pointer
            *fd,                           // next free pointer
            *ld;                           // last entry
    char    *decode_stack;                 // decode stack

    /*
    dict = (SD huge *) huge_malloc(sizeof(SD) * TABLE_SIZE);    // allocate dictionary trees
    decode_stack = (char huge *) huge_malloc(TABLE_SIZE);       // ..and allocate decode stack
    */

    //seawind added
    dict = (SD *) malloc_chk(sizeof(SD) * TABLE_SIZE);          // allocate dictionary trees
    decode_stack = (char *) malloc_chk(TABLE_SIZE);             // ..and allocate decode stack

    ld = &dict[TABLE_SIZE];                 // get address of last entry

    for (fd = d = &dict[257]; d < ld; d++)  // loop thru dictionary
        d->parent_c = FREE;                 // ..and make each one free

    store_char(p_c = b_c = get_code(cs));   // get and store a code

    for (;;)                                // inner loop
    {
        //seawind added for stop
        if(m_nActionCancel || m_nZipFileCracked)
            break;

        cnt = 0;                            // reset decode stack

        if ((s_c = c = get_code(cs)) == -1) // q. end of data?
            break;                          // a. yes .. exit loop

        if (c == 256)                       // q. special code?
        {                                   // a. yes .. get next code
            //if ((c = get_code(cs)) == -1)     // q. get next code ok?
            //  quit_with(data_error);          // a. no .. quit w/error msg

            //seawind added
            c = get_code(cs);

            if(c == -1)
            {
                //seawind added
                m_nZipFileCracked = 1;
                break;
            }

⌨️ 快捷键说明

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