设为首页 加入收藏

TOP

C++获取zip文件列表(十一)
2012-12-06 13:36:09 来源: 作者: 【 】 浏览:2517
Tags:获取 zip 文件

 

    int CZipFile::ReadFileHeader(BYTE * data, FileHeader * hdr)

    {

    /*Name:    int CZipFile::ReadFileHeader(BYTE * data, CString* stData)

    /*It read the file header in the Central Directory Structure

    Return the number of bytes read; if the stream does not contain

    a valid local_file_header 0 is returned and the stream pointer (f)

    is not modified

    st is filled with all the data;

    */

    BYTE * origdata=data;

    // FileHeader hdr;

    //fill the values into the file_header structure

    hdr->signature            = (ui32) ReadValue(data   ,32);

    if(hdr->signature!=0x02014b50)

    return 0; //no further file

    hdr->version_made_by      = (ui16) ReadValue(data+4 ,16);

    hdr->version_needed       = (ui16) ReadValue(data+6 ,16);

    hdr->bitflags             = (ui16) ReadValue(data+8 ,16);

    hdr->comp_method          = (ui16) ReadValue(data+10,16);

    hdr->lastModFileTime      = (ui16) ReadValue(data+12,16);

    hdr->lastModFileDate      = (ui16) ReadValue(data+14,16);

    hdr->crc_32               = (ui32) ReadValue(data+16,32);

    hdr->comp_size            = (ui32) ReadValue(data+20,32);

    hdr->uncompr_size         = (ui32) ReadValue(data+24,32);

    hdr->fname_len            = (ui16) ReadValue(data+28,16);

    hdr->extra_field_len      = (ui16) ReadValue(data+30,16);

    hdr->fcomment_len         = (ui16) ReadValue(data+32,16);

    hdr->disk_num_start       = (ui16) ReadValue(data+34,16);

    hdr->internal_fattribute  = (ui16) ReadValue(data+36,16);

    hdr->external_fattribute  = (ui32) ReadValue(data+38,32);

    hdr->relative_offset      = (ui32) ReadValue(data+42,32);

    data+=46;

    if(hdr->fname_len>0)

    {

    char *fn;

    fn=new (char[hdr->fname_len+1]);

    strncpy(fn,(char*)data,hdr->fname_len);

    fn[hdr->fname_len]='\0';

    hdr->file_name = fn;

    data+=hdr->fname_len;

    }

    if(hdr->extra_field_len>0)

    {

    char *fn;

    fn=new (char[hdr->extra_field_len+1]);

    strncpy(fn,(char*)data,hdr->extra_field_len);

    fn[hdr->extra_field_len]='\0';

    hdr->extra_field = fn;

    data += hdr->extra_field_len;

    }

    //file comment

    if(hdr->fcomment_len>0)

    {

    char *fn;

    fn=new (char[hdr->fcomment_len+1]);

    strncpy(fn,(char*)data,hdr->fcomment_len);

    fn[hdr->fcomment_len]='\0';

    hdr->file_comment = fn;

    data += hdr->extra_field_len;

    }

    return (data-origdata);

    }

    ui32 CZipFile::ReadValue(unsigned char * buf, int nbits)

    {

    /*Name:    void ReadValue(char*buf, int nbits)

    /*Return the value read from the buffer of size nbits;

    */

    ui32 value = 0;

    switch (nbits)

    {

    case (8):

    value = (ui32)*(buf);

    break;

    case(16):

    value = (((ui32)*(buf+1))<<8)+(ui32)*(buf);

    break;

    case(24):

    value = (((ui32)*(buf+2))<<16)+(((ui32)*(buf+1))<<8)+((ui32)*(buf));

    break;

    case(32):

    value = (((ui32)*(buf+3))<<24)+(((ui32)*(buf+2))<<16)+(((ui32)*(buf+1))<<8)+((ui32)*(buf));

          

首页 上一页 8 9 10 11 12 下一页 尾页 11/12/12
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇i2c 驱动编程接口 下一篇C++中类型转换运算符的使用方法

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: