当前位置: 首页>>代码示例>>C++>>正文


C++ zip_stat_index函数代码示例

本文整理汇总了C++中zip_stat_index函数的典型用法代码示例。如果您正苦于以下问题:C++ zip_stat_index函数的具体用法?C++ zip_stat_index怎么用?C++ zip_stat_index使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了zip_stat_index函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ipsw_get_file_size

int ipsw_get_file_size(const char* ipsw, const char* infile, off_t* size) {
	ipsw_archive* archive = ipsw_open(ipsw);
	if (archive == NULL || archive->zip == NULL) {
		error("ERROR: Invalid archive\n");
		return -1;
	}

	int zindex = zip_name_locate(archive->zip, infile, 0);
	if (zindex < 0) {
		error("ERROR: zip_name_locate: %s\n", infile);
		return -1;
	}

	struct zip_stat zstat;
	zip_stat_init(&zstat);
	if (zip_stat_index(archive->zip, zindex, 0, &zstat) != 0) {
		error("ERROR: zip_stat_index: %s\n", infile);
		return -1;
	}

	*size = zstat.size;

	ipsw_close(archive);
	return 0;
}
开发者ID:Blackmamba0,项目名称:idevicerestore,代码行数:25,代码来源:ipsw.c

示例2: FileNode

FileNode *FileNode::createNodeForZipEntry(struct zip *zip,
        const char *fname, zip_int64_t id) {
    FileNode *n = new FileNode(zip, fname, id);
    if (n == NULL) {
        return NULL;
    }
    n->is_dir = false;
    n->open_count = 0;
    n->state = CLOSED;

    struct zip_stat stat;
    zip_stat_index(zip, id, 0, &stat);
    // check that all used fields are valid
    zip_uint64_t needValid = ZIP_STAT_NAME | ZIP_STAT_INDEX |
        ZIP_STAT_SIZE | ZIP_STAT_MTIME;
    // required fields are always valid for existing items or newly added
    // directories (see zip_stat_index.c from libzip)
    assert((stat.valid & needValid) == needValid);
    n->m_mtime = n->m_atime = n->m_ctime = stat.mtime;
    n->has_cretime = false;
    n->m_size = stat.size;

    n->parse_name();

    n->processExternalAttributes();
    n->processExtraFields();
    return n;
}
开发者ID:dxafn,项目名称:fuse-zip,代码行数:28,代码来源:fileNode.cpp

示例3: r_io_zip_slurp_file

static int r_io_zip_slurp_file(RIOZipFileObj *zfo) {
	struct zip_file *zFile = NULL;
	struct zip *zipArch;
	struct zip_stat sb;
	bool res = false;
	if (!zfo) {
		return res;
	}
	zipArch = r_io_zip_open_archive (
		zfo->archivename, zfo->perm,
		zfo->mode, zfo->rw);

	if (zipArch && zfo && zfo->entry != -1) {
		zFile = zip_fopen_index (zipArch, zfo->entry, 0);
		if (!zfo->b) {
			zfo->b = r_buf_new ();
		}
		zip_stat_init (&sb);
		if (zFile && zfo->b && !zip_stat_index (zipArch, zfo->entry, 0, &sb)) {
			ut8 *buf = malloc (sb.size);
			memset (buf, 0, sb.size);
			if (buf) {
				zip_fread (zFile, buf, sb.size);
				r_buf_set_bytes (zfo->b, buf, sb.size);
				res = true;
				zfo->opened = true;
				free (buf);
			}
		}
		zip_fclose (zFile);
	}
	zip_close (zipArch);
	return res;
}
开发者ID:csarn,项目名称:radare2,代码行数:34,代码来源:io_zip.c

示例4: r_io_zip_get_files

RList * r_io_zip_get_files(char *archivename, ut32 flags, int mode, int rw) {
	ut64 num_entries = 0, i = 0;
	struct zip * zipArch = r_io_zip_open_archive(archivename, flags, mode, rw);
	struct zip_stat sb; 
	RList *files = NULL; 
	//eprintf("Slurping file");
	if (zipArch) {
		files = r_list_new();
		num_entries = zip_get_num_files(zipArch);

		for (i=0; i < num_entries; i++) {
			char *name = NULL;	
			zip_stat_init(&sb );
			zip_stat_index(zipArch, i, 0, &sb );	
			//eprintf("Comparing %s == %s = %d\n", sb.name, filename, strcmp(sb.name, filename));
			name = strdup(sb.name);
			if (name) {
				r_list_append(files, name);
			}

		}
	}
	if (zipArch)
		zip_close(zipArch);

	return files;
}
开发者ID:jdukes,项目名称:radare2,代码行数:27,代码来源:io_zip.c

示例5: zip_enumerate

static int zip_enumerate(arch_enum_t e,struct arch_enum_callbacks *cb,void*arg){
    if (cb->data!=NULL) Abort("cannot enumerate data");
    while(e->next<e->count){
        struct zip_stat sb;
        int res=zip_stat_index(e->archive->archive,e->next,0,&sb);
        if (res<0) {
            Abort("cannot stat zip archive: %s\n",zip_strerror(e->archive->archive));
        }
        if(cb->new_item) {
            res=cb->new_item(arg,e->next,sb.name);
            if (res) {
                e->next++;
                return res;
            }
        }
        if(cb->stat) {
            struct archive_item_s item;
            item.name=sb.name;
            item.code=zip_get_file_comment(e->archive->archive,e->next,NULL,0);
            item.length=sb.size;
            item.compressed=sb.comp_size;
            res=cb->stat(arg,e->next,&item);
            if (res) {
                e->next++;
                return res;
            }
            
        }
        e->next++;
    }
    return 0;
}
开发者ID:graydon,项目名称:ltsmin,代码行数:32,代码来源:hre_zip_io.c

示例6: r_io_zip_alloc_zipfileobj

/* The file can be a file in the archive or ::[num].  */
RIOZipFileObj* r_io_zip_alloc_zipfileobj(const char *archivename, const char *filename, ut32 perm, int mode, int rw) {
	RIOZipFileObj *zfo = NULL;
	ut64 i, num_entries;
	struct zip_stat sb;
	struct zip *zipArch = r_io_zip_open_archive (archivename, perm, mode, rw);
	if (!zipArch) {
		return NULL;
	}
	num_entries = zip_get_num_files (zipArch);

	for (i = 0; i < num_entries; i++) {
		zip_stat_init (&sb);
		zip_stat_index (zipArch, i, 0, &sb);
		if (sb.name != NULL) {
			if (strcmp (sb.name, filename) == 0) {
				zfo = r_io_zip_create_new_file (
					archivename, filename, &sb,
					perm, mode, rw);
				r_io_zip_slurp_file (zfo);
				break;
			}
		}
	}
	if (!zfo) {
		zfo = r_io_zip_create_new_file (archivename,
			filename, NULL, perm, mode, rw);
	}
	zip_close (zipArch);
	return zfo;
}
开发者ID:csarn,项目名称:radare2,代码行数:31,代码来源:io_zip.c

示例7: arch_zip_read

archive_t arch_zip_read(const char* name,int buf){
    archive_t arch=(archive_t)HREmalloc(NULL,sizeof(struct archive_s));
    arch_init(arch);
    int err;
    arch->archive=zip_open(name,ZIP_CHECKCONS,&err);
    if (arch->archive==NULL){
        char errstr[1024];
        zip_error_to_str(errstr, sizeof(errstr), err, errno);
        Abort("cannot open zip archive `%s': %s\n",name , errstr);
    }
    arch->stream_index=SIcreate();
#ifdef LIBZIP_VERSION
    int count=zip_get_num_entries(arch->archive,0);
#else
    int count=zip_get_num_files(arch->archive);
#endif
    for(int i=0;i<count;i++){
        struct zip_stat sb;
        int res=zip_stat_index(arch->archive,i,0,&sb);
        if (res<0) {
            Abort("cannot stat zip archive: %s\n",zip_strerror(arch->archive));
        }
        SIputAt(arch->stream_index,sb.name,i);
        Print(infoShort,"stream %d is %s",i,sb.name);
    }
    arch->procs.contains=zip_contains;
    arch->procs.read=hre_zip_read;
    arch->procs.read_raw=hre_zip_read_raw;
    arch->procs.enumerator=zip_enum;
    arch->procs.close=hre_zip_close;
    arch->buf=buf;
    return arch;
}
开发者ID:graydon,项目名称:ltsmin,代码行数:33,代码来源:hre_zip_io.c

示例8: Unzip

size_t Unzip(const char *dst_path_, const char *archive, const UnzipFileHandler& handler)
{
    struct zip *za;
    struct zip_file *zf;
    struct zip_stat sb;
    char buf[1024];
    size_t ret = 0;
    std::string dst_path = dst_path_;

    int err;
    if ((za = zip_open(archive, 0, &err)) == nullptr) {
        zip_error_to_str(buf, sizeof(buf), err, errno);
        return false;
    }

    for (int i = 0; i < zip_get_num_entries(za, 0); ++i) {
        if (zip_stat_index(za, i, 0, &sb) == 0) {
            std::string dstpath = dst_path + '/' + sb.name;

            if (dstpath.back() == '/') {
                std::experimental::filesystem::create_directories(dstpath.c_str());
            }
            else {
                zf = zip_fopen_index(za, i, 0);
                if (!zf) {
                    goto bail_out;
                }

                FILE *of = fopen(dstpath.c_str(), "wb");
                if (of == nullptr) {
                    goto bail_out;
                }

                size_t sum = 0;
                while (sum != sb.size) {
                    size_t len = (size_t)zip_fread(zf, buf, sizeof(buf));
                    if (len < 0) {
                        fclose(of);
                        goto bail_out;
                    }
                    fwrite(buf, 1, len, of);
                    sum += len;
                }
                fclose(of);
                zip_fclose(zf);
                if (handler) { handler(dstpath.c_str()); }
                ++ret;
            }
        }
    }

    if (zip_close(za) == -1) {
        return false;
    }
    return ret;

bail_out:
    zip_close(za);
    return ret;
}
开发者ID:unity3d-jp,项目名称:FrameCapturer,代码行数:60,代码来源:Compression.cpp

示例9: fzip2buffer

static int fzip2buffer(struct zip *fzip, int index, byte **buffer)
{
    struct zip_stat fstat;
    struct zip_file *file = NULL;

    *buffer = NULL;

    zip_stat_index(fzip, index, 0, &fstat);
    *buffer = malloc(fstat.size);

    // Read zipped file
    if((file = zip_fopen(fzip, fstat.name, ZIP_FL_UNCHANGED))==NULL)
        goto error;
    if(zip_fread(file, *buffer, fstat.size)!=fstat.size)
        goto error;
    zip_fclose(file); file = NULL;

    return fstat.size;

error:
    free(*buffer); *buffer = NULL;
    if(file)
        zip_fclose(file);

    return -1;
}
开发者ID:k5g,项目名称:emulika,代码行数:26,代码来源:rom.c

示例10: r_io_zip_slurp_file

int r_io_zip_slurp_file(RIOZipFileObj *zfo) {
	int res = R_FALSE;
	struct zip_stat sb;
	struct zip_file *zFile = NULL;
	struct zip * zipArch ;

	if (!zfo) return res;
	zipArch = r_io_zip_open_archive (
		zfo->archivename, zfo->flags,
		zfo->mode, zfo->rw);
	//eprintf("Slurping file");

	if (zipArch && zfo && zfo->entry != -1) {
		zFile = zip_fopen_index (zipArch, zfo->entry, 0);
		if (!zfo->b)
			zfo->b = r_buf_new ();
		zip_stat_init (&sb);
		if (zFile && zfo->b && !zip_stat_index(zipArch,
				zfo->entry, 0, &sb) ) {
			ut8 *buf = malloc (sb.size);
			memset (buf, 0, sb.size);
			if (buf) {
				zip_fread (zFile, buf, sb.size);
				r_buf_set_bytes (zfo->b, buf, sb.size);
				res = zfo->opened = R_TRUE;
				free (buf);
			}
		}
		zip_fclose (zFile);
	}
	zip_close (zipArch);
	return res;
}
开发者ID:CodingFree,项目名称:radare2,代码行数:33,代码来源:io_zip.c

示例11: zip_get_num_entries

QStringList KaraokePlayable_ZIP::enumerate()
{
    QStringList filelist;

    // http://www.nih.at/libzip/zip_get_num_entries.html
    int files = zip_get_num_entries( m_zip, ZIP_FL_UNCHANGED );

    if ( files == 0 )
    {
        m_errorMsg = "archive has no files";
        return filelist;
    }

    for ( int i = 0; i < files; i++ )
    {
        // Retrieve the file size
        struct zip_stat fileinfo;

        // http://www.nih.at/libzip/zip_stat_index.html
        if ( zip_stat_index( m_zip, i, 0, &fileinfo) != 0 )
        {
            m_errorMsg = "file info not found";
            return QStringList();
        }

        filelist.push_back( decodeFilename( fileinfo.name ) );
    }

    return filelist;
}
开发者ID:gyunaev,项目名称:spivak,代码行数:30,代码来源:karaokeplayable_zip.cpp

示例12: qDebug

QByteArray zipobject::readData(const QString& inZipPath)const{
    if( NULL == m_zip){
        qDebug()<<"zip unopened";
        return QByteArray();
    }
    int index = zip_name_locate(m_zip,getCharPtr(inZipPath),0);
    if( -1 == index ){
        qDebug()<<"no such file : "<<inZipPath;
        return QByteArray();
    }
    zip_file *pFile = zip_fopen_index(m_zip,index,0);
    if( NULL == pFile){
        qDebug()<<"fopen is NULL"<<zip_strerror(m_zip);
        return QByteArray();
    }
    struct zip_stat stat;
    int rStat = zip_stat_index(m_zip,index, 0, &stat);
    if( -1 == rStat ){
        qDebug()<<"stat failed : "<<zip_strerror(m_zip);
        return QByteArray();
    }
    const int length = stat.size;
    char buffer[length +1 ];
    int rRead = zip_fread(pFile,buffer,sizeof(buffer));
    if( -1 == rRead ){
        qDebug()<<"read failed : "<<zip_strerror(m_zip);
        return QByteArray();
    }
    return QByteArray (buffer,rRead);
}
开发者ID:kubuntu,项目名称:Dlut-Game-Platform,代码行数:30,代码来源:zipobject.cpp

示例13: zip_get_num_files

bool zipobject::extractTo(const QString& dirPath){
    int num_entries = zip_get_num_files(m_zip) ;
    for( int i = 0 ; i < num_entries ; ++i ){
        qDebug()<<zip_get_name(m_zip,i,0);
        zip_file* pFile = zip_fopen_index(m_zip,i,0);
        struct zip_stat stat ;
        zip_stat_index(m_zip,i,0,&stat);
        
        const int length = stat.size ;
        char buffer[length +1 ] ;
        int rRead = zip_fread(pFile,buffer,sizeof(buffer));
        if( -1 == rRead ){
            qDebug()<<"read failed : "<<zip_strerror(m_zip);
            return false;
        }
        
        QFileInfo fileInfo(dirPath + '/' + stat.name);
        QDir dir = fileInfo.absoluteDir() ;
        if(!dir.mkpath(".")){
            return false;
        }
        
        QFile file(dirPath + '/' + stat.name);
        file.open(QIODevice::WriteOnly);
        file.write(QByteArray(buffer,length));
        file.close();
    }
    return true;
}
开发者ID:kubuntu,项目名称:Dlut-Game-Platform,代码行数:29,代码来源:zipobject.cpp

示例14: confirm_replace

static int
confirm_replace(struct zip *za, const char *tname, int it,
		struct zip *zs, const char *sname, int is)
{
    char line[1024];
    struct zip_stat st, ss;

    if (confirm & CONFIRM_ALL_YES)
	return 1;
    else if (confirm & CONFIRM_ALL_NO)
	return 0;

    if (zip_stat_index(za, it, ZIP_FL_UNCHANGED, &st) < 0) {
	fprintf(stderr, "%s: cannot stat file %d in `%s': %s\n",
		prg, it, tname, zip_strerror(za));
	return -1;
    }
    if (zip_stat_index(zs, is, 0, &ss) < 0) {
	fprintf(stderr, "%s: cannot stat file %d in `%s': %s\n",
		prg, is, sname, zip_strerror(zs));
	return -1;
    }

    if (st.size == ss.size && st.crc == ss.crc) {
	if (confirm & CONFIRM_SAME_YES)
	    return 1;
	else if (confirm & CONFIRM_SAME_NO)
	    return 0;
    }

    printf("replace `%s' (%llu / %08x) in `%s'\n"
	   "   with `%s' (%llu / %08x) from `%s'? ",
	   st.name, st.size, st.crc, tname,
	   ss.name, ss.size, ss.crc, sname);
    fflush(stdout);

    if (fgets(line, sizeof(line), stdin) == NULL) {
	fprintf(stderr, "%s: read error from stdin: %s\n",
		prg, strerror(errno));
	return -1;
    }

    if (tolower((unsigned char)line[0]) == 'y')
	return 1;

    return 0;
}
开发者ID:Distrotech,项目名称:libzip,代码行数:47,代码来源:zipmerge.c

示例15: _vdezName

const char* _vdezName(struct VDirEntry* vde) {
	struct VDirEntryZip* vdez = (struct VDirEntryZip*) vde;
	struct zip_stat s;
	if (zip_stat_index(vdez->z, vdez->index, 0, &s) < 0) {
		return 0;
	}
	return s.name;
}
开发者ID:OpenEmu,项目名称:mGBA-Core,代码行数:8,代码来源:vfs-zip.c


注:本文中的zip_stat_index函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。