コード例 #1
0
ファイル: CZipLoader.cpp プロジェクト: argarak/vcmi
std::unordered_map<ResourceID, unz64_file_pos> CZipLoader::listFiles(const std::string & mountPoint, const boost::filesystem::path & archive)
{
	std::unordered_map<ResourceID, unz64_file_pos> ret;

	unzFile file = unzOpen2_64(archive.c_str(), &zlibApi);

	if(file == nullptr)
		logGlobal->errorStream() << archive << " failed to open";

	if (unzGoToFirstFile(file) == UNZ_OK)
	{
		do
		{
			unz_file_info64 info;
			std::vector<char> filename;
			// Fill unz_file_info structure with current file info
			unzGetCurrentFileInfo64 (file, &info, nullptr, 0, nullptr, 0, nullptr, 0);

			filename.resize(info.size_filename);
			// Get name of current file. Contrary to docs "info" parameter can't be null
			unzGetCurrentFileInfo64 (file, &info, filename.data(), filename.size(), nullptr, 0, nullptr, 0);

			std::string filenameString(filename.data(), filename.size());
			unzGetFilePos64(file, &ret[ResourceID(mountPoint + filenameString)]);
		}
		while (unzGoToNextFile(file) == UNZ_OK);
	}
	unzClose(file);

	return ret;
}
コード例 #2
0
ファイル: zip.c プロジェクト: armornick/duktape-misc
static duk_ret_t dukzip_unz_listfiles(duk_context *ctx) {
	unzFile archive = dukzip_unz_from_this(ctx);

	unzGoToFirstFile(archive);
	int i = 0, res;
	duk_idx_t arr_idx = duk_push_array(ctx);

	do {
		// unz_file_info fileInfo;
		// unzGetCurrentFileInfo(archive, &fileInfo, NULL, 0, NULL, 0, NULL, 0);
		unz_file_info64 fileInfo;
		unzGetCurrentFileInfo64(archive, &fileInfo, NULL, 0, NULL, 0, NULL, 0);

#if defined(__GNUC__) && !defined(DUK_NO_VLA)
		char fileName[fileInfo.size_filename];
#else
		char *fileName = malloc(fileInfo.size_filename);
#endif

		// unzGetCurrentFileInfo(archive, &fileInfo, fileName, fileInfo.size_filename, NULL, 0, NULL, 0);
		unzGetCurrentFileInfo64(archive, &fileInfo, fileName, fileInfo.size_filename, NULL, 0, NULL, 0);

		duk_push_lstring(ctx, fileName, fileInfo.size_filename);
		duk_put_prop_index(ctx, arr_idx, i++);

#if !defined(__GNUC__) || defined(DUK_NO_VLA)
		free(fileName);
#endif

		res = unzGoToNextFile(archive);

	} while (res != UNZ_END_OF_LIST_OF_FILE || res == UNZ_OK);

	return 1;
}
コード例 #3
0
ファイル: zip.c プロジェクト: armornick/duktape-misc
static duk_ret_t dukzip_unz_getfilename(duk_context *ctx) {
	// unz_file_info fileInfo;
	unz_file_info64 fileInfo;
	unzFile archive = dukzip_unz_from_this(ctx);

	// unzGetCurrentFileInfo(archive, &fileInfo, NULL, 0, NULL, 0, NULL, 0);
	unzGetCurrentFileInfo64(archive, &fileInfo, NULL, 0, NULL, 0, NULL, 0);

#if defined(__GNUC__) && !defined(DUK_NO_VLA)
	char fileName[fileInfo.size_filename];
#else
	char *fileName = malloc(fileInfo.size_filename);
#endif

	// unzGetCurrentFileInfo(archive, &fileInfo, fileName, fileInfo.size_filename, NULL, 0, NULL, 0);
	unzGetCurrentFileInfo64(archive, &fileInfo, fileName, fileInfo.size_filename, NULL, 0, NULL, 0);

	duk_push_lstring(ctx, fileName, fileInfo.size_filename);

#if !defined(__GNUC__) || defined(DUK_NO_VLA)
	free(fileName);
#endif

	return 1;
}
コード例 #4
0
ファイル: CZipLoader.cpp プロジェクト: argarak/vcmi
std::vector<std::string> ZipArchive::listFiles(boost::filesystem::path filename)
{
	std::vector<std::string> ret;

	unzFile file = unzOpen2_64(filename.c_str(), FileStream::GetMinizipFilefunc());

	if (unzGoToFirstFile(file) == UNZ_OK)
	{
		do
		{
			unz_file_info64 info;
			std::vector<char> filename;

			unzGetCurrentFileInfo64 (file, &info, nullptr, 0, nullptr, 0, nullptr, 0);

			filename.resize(info.size_filename);
			// Get name of current file. Contrary to docs "info" parameter can't be null
			unzGetCurrentFileInfo64 (file, &info, filename.data(), filename.size(), nullptr, 0, nullptr, 0);

			ret.push_back(std::string(filename.data(), filename.size()));
		}
		while (unzGoToNextFile(file) == UNZ_OK);
	}
	unzClose(file);

	return ret;
}
コード例 #5
0
bool MinizipUtils::get_info(unzFile uf,
                            unz_file_info64 *fi,
                            std::string *filename)
{
    unz_file_info64 info;
    memset(&info, 0, sizeof(info));

    // First query to get filename size
    int ret = unzGetCurrentFileInfo64(
        uf,                     // file
        &info,                  // pfile_info
        nullptr,                // filename
        0,                      // filename_size
        nullptr,                // extrafield
        0,                      // extrafield_size
        nullptr,                // comment
        0                       // comment_size
    );

    if (ret != UNZ_OK) {
        LOGE("miniunz: Failed to get inner file metadata: %s",
             unz_error_string(ret).c_str());
        return false;
    }

    if (filename) {
        std::vector<char> buf(static_cast<size_t>(info.size_filename + 1));

        ret = unzGetCurrentFileInfo64(
            uf,                                 // file
            &info,                              // pfile_info
            buf.data(),                         // filename
            static_cast<uint16_t>(buf.size()),  // filename_size
            nullptr,                            // extrafield
            0,                                  // extrafield_size
            nullptr,                            // comment
            0                                   // comment_size
        );

        if (ret != UNZ_OK) {
            LOGE("miniunz: Failed to get inner filename: %s",
                 unz_error_string(ret).c_str());
            return false;
        }

        *filename = buf.data();
    }

    if (fi) {
        *fi = info;
    }

    return true;
}
コード例 #6
0
ファイル: zip.c プロジェクト: armornick/duktape-misc
static duk_ret_t dukzip_unz_getfileinfo(duk_context *ctx) {
	duk_idx_t info_obj;
	// unz_file_info fileInfo;
	unz_file_info64 fileInfo;
	unzFile archive = dukzip_unz_from_this(ctx);

	// unzGetCurrentFileInfo(archive, &fileInfo, NULL, 0, NULL, 0, NULL, 0);
	unzGetCurrentFileInfo64(archive, &fileInfo, NULL, 0, NULL, 0, NULL, 0);

#if defined(__GNUC__) && !defined(DUK_NO_VLA)
	char fileName[fileInfo.size_filename],
		extraField[fileInfo.size_file_extra],
		commentString[fileInfo.size_file_comment];
#else
	char *fileName = malloc(fileInfo.size_filename); 
	char *extraField = malloc(fileInfo.size_file_extra); 
	char *commentString = malloc(fileInfo.size_file_comment);
#endif

	// unzGetCurrentFileInfo(archive, &fileInfo, 
	// 	fileName, fileInfo.size_filename,
	// 	extraField, fileInfo.size_file_extra,
	// 	commentString, fileInfo.size_file_comment);
	unzGetCurrentFileInfo64(archive, &fileInfo, 
		fileName, fileInfo.size_filename,
		extraField, fileInfo.size_file_extra,
		commentString, fileInfo.size_file_comment);

	info_obj = duk_push_object(ctx);

	duk_push_int(ctx, fileInfo.compressed_size);
	duk_put_prop_string(ctx, info_obj, "compressed");

	duk_push_int(ctx, fileInfo.uncompressed_size);
	duk_put_prop_string(ctx, info_obj, "uncompressed");

	duk_push_lstring(ctx, fileName, fileInfo.size_filename);
	duk_put_prop_string(ctx, info_obj, "filename");

	duk_push_lstring(ctx, extraField, fileInfo.size_file_extra);
	duk_put_prop_string(ctx, info_obj, "extra");

	duk_push_lstring(ctx, commentString, fileInfo.size_file_comment);
	duk_put_prop_string(ctx, info_obj, "comment");

#if !defined(__GNUC__) || defined(DUK_NO_VLA)
	free(fileName);
	free(extraField);
	free(commentString);
#endif

	return 1;
}
コード例 #7
0
ファイル: FolderZip.cpp プロジェクト: AtomikPunk/rombox
int FolderZip::Populate()
{
	std::string filename(m_path.begin(), m_path.end());
	unzFile f = unzOpen64(filename.c_str());
	// Support for unicode filename is not yet implemented in unzip(?)
	//unzFile f = unzOpen64(m_path.c_str());
	if (!f)
		return -1;

	unz_global_info64 globalInfo;
	int getGlobalInfoResult = unzGetGlobalInfo64(f, &globalInfo);
	if (getGlobalInfoResult != UNZ_OK)
	{
		unzClose(f);
		return -2;
	}

	int firstFileResult = unzGoToFirstFile(f);
	if (firstFileResult != UNZ_OK)
	{
		unzClose(f);
		return -3;
	}

	int nextFileResult = firstFileResult;
	do
	{
		unz_file_info64 fileInfo;
		int getInfoResult = unzGetCurrentFileInfo64(f, &fileInfo, NULL, 0, NULL, 0, NULL, 0);
		if (getInfoResult != UNZ_OK)
		{
			unzClose(f);
			continue;
		}

		char *filename = new char[fileInfo.size_filename+1];
		unzGetCurrentFileInfo64(f, &fileInfo, filename, fileInfo.size_filename, NULL, 0, NULL, 0);
		filename[fileInfo.size_filename] = '\0';

		File *newFile = new File();
		newFile->m_path = std::wstring(filename, filename+fileInfo.size_filename);
		newFile->m_crc = fileInfo.crc;
		mFileList.insert(std::pair<std::wstring,File*>(newFile->m_path, newFile));

		nextFileResult = unzGoToNextFile(f);
	} while (nextFileResult == UNZ_OK);

	unzClose(f);

	return 0;
}
コード例 #8
0
ファイル: fileutils.cpp プロジェクト: iebie/DualBootPatcher
bool FileUtils::mzGetInfo(unzFile uf,
                          unz_file_info64 *fi,
                          std::string *filename)
{
    unz_file_info64 info;
    memset(&info, 0, sizeof(info));

    // First query to get filename size
    int ret = unzGetCurrentFileInfo64(
        uf,                     // file
        &info,                  // pfile_info
        nullptr,                // filename
        0,                      // filename_size
        nullptr,                // extrafield
        0,                      // extrafield_size
        nullptr,                // comment
        0                       // comment_size
    );

    if (ret != UNZ_OK) {
        return false;
    }

    if (filename) {
        std::vector<char> buf(info.size_filename + 1);

        ret = unzGetCurrentFileInfo64(
            uf,             // file
            &info,          // pfile_info
            buf.data(),     // filename
            buf.size(),     // filename_size
            nullptr,        // extrafield
            0,              // extrafield_size
            nullptr,        // comment
            0               // comment_size
        );

        if (ret != UNZ_OK) {
            return false;
        }

        *filename = buf.data();
    }

    if (fi) {
        *fi = info;
    }

    return true;
}
コード例 #9
0
int minizip_getfilenameinzip(const char * lpszzipfilename, char *lpszfilenameinzip, int nmaxlen)
{
  int nret = -1;
  // Open zip file
  unzFile uf = NULL;
  if (lpszzipfilename != NULL)
  {
    uf = unzOpen64(lpszzipfilename);
  }

  if (uf == NULL)
  {
    return nret;
  }

  // Get filename in zip
  unz_file_info64 file_info = { 0 };

  int status = unzGetCurrentFileInfo64(uf, &file_info, lpszfilenameinzip, nmaxlen, NULL, 0, NULL, 0);
  if (status != UNZ_OK)
  {
    return nret;
  }
  nret = 0;
  return nret;
}
コード例 #10
0
ファイル: file_access_zip.cpp プロジェクト: baekdahl/godot
bool ZipArchive::try_open_pack(const String& p_name) {

	//printf("opening zip pack %ls, %i, %i\n", p_name.c_str(), p_name.extension().nocasecmp_to("zip"), p_name.extension().nocasecmp_to("pcz"));
	if (p_name.get_extension().nocasecmp_to("zip") != 0 && p_name.get_extension().nocasecmp_to("pcz") != 0)
		return false;

	zlib_filefunc_def io;

	FileAccess* f = FileAccess::open(p_name, FileAccess::READ);
	if (!f)
		return false;
	io.opaque = f;
	io.zopen_file = godot_open;
	io.zread_file = godot_read;
	io.zwrite_file = godot_write;

	io.ztell_file = godot_tell;
	io.zseek_file = godot_seek;
	io.zclose_file = godot_close;
	io.zerror_file = godot_testerror;

	unzFile zfile = unzOpen2(p_name.utf8().get_data(), &io);
	ERR_FAIL_COND_V(!zfile, false);

	unz_global_info64 gi;
	int err = unzGetGlobalInfo64(zfile, &gi);
	ERR_FAIL_COND_V(err!=UNZ_OK, false);

	Package pkg;
	pkg.filename = p_name;
	pkg.zfile = zfile;
	packages.push_back(pkg);
	int pkg_num = packages.size()-1;

	for (unsigned int i=0;i<gi.number_entry;i++) {

		char filename_inzip[256];

		unz_file_info64 file_info;
		err = unzGetCurrentFileInfo64(zfile,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0);
		ERR_CONTINUE(err != UNZ_OK);

		File f;
		f.package = pkg_num;
		unzGetFilePos(zfile, &f.file_pos);

		String fname = String("res://") + filename_inzip;
		files[fname] = f;

		uint8_t md5[16]={0,0,0,0,0,0,0,0 , 0,0,0,0,0,0,0,0};
		PackedData::get_singleton()->add_path(p_name, fname, 1, 0, md5, this);
		//printf("packed data add path %ls, %ls\n", p_name.c_str(), fname.c_str());

		if ((i+1)<gi.number_entry) {
			unzGoToNextFile(zfile);
		};
	};

	return true;
};
コード例 #11
0
ファイル: zip.cpp プロジェクト: h2so5/PaintField
bool UnzipFile::open()
{
	if (d->filepath.isEmpty())
	{
		PAINTFIELD_WARNING << "file path not specified";
		return false;
	}
	
	if (d->archive->d->currentUnzipFile)
	{
		PAINTFIELD_WARNING << "another unzip file is open";
		return false;
	}
	
	auto unzip = d->archive->d->unzip;
	
	if (unzLocateFile(unzip, d->filepath.toUtf8(), 1) != UNZ_OK)
	{
		PAINTFIELD_WARNING << "file not found";
		return false;
	}
	
	unz_file_info64 fileInfo;
	unzGetCurrentFileInfo64(unzip, &fileInfo, 0, 0, 0, 0, 0, 0);
	d->size = fileInfo.uncompressed_size;
	
	if (unzOpenCurrentFile(unzip) != UNZ_OK)
	{
		PAINTFIELD_WARNING << "failed to open current file";
		return false;
	}
	
	setOpenMode(ReadOnly);
	return true;
}
コード例 #12
0
ファイル: ZipUtil.cpp プロジェクト: kindleStudy/sumatrapdf
void ZipFile::ExtractFilenames(ZipMethod method)
{
    if (!uf)
        return;

    unz_global_info64 ginfo;
    int err = unzGetGlobalInfo64(uf, &ginfo);
    if (err != UNZ_OK)
        return;
    unzGoToFirstFile(uf);

    for (int i = 0; i < ginfo.number_entry && UNZ_OK == err; i++) {
        unz_file_info64 finfo;
        char fileName[MAX_PATH];
        err = unzGetCurrentFileInfo64(uf, &finfo, fileName, dimof(fileName), NULL, 0, NULL, 0);
        // some file format specifications only allow Deflate as compression method (e.g. XPS and EPUB)
        bool isSupported = Zip_Any == method || Zip_None == finfo.compression_method ||
                                                method == finfo.compression_method;
        if (err == UNZ_OK && isSupported) {
            WCHAR fileNameW[MAX_PATH];
            UINT cp = (finfo.flag & (1 << 11)) ? CP_UTF8 : CP_ZIP;
            str::conv::FromCodePageBuf(fileNameW, dimof(fileNameW), fileName, cp);
            filenames.Append(Allocator::StrDup(allocator, fileNameW));
            fileinfo.Append(finfo);

            unz64_file_pos fpos;
            err = unzGetFilePos64(uf, &fpos);
            if (err != UNZ_OK)
                fpos.num_of_file = INVALID_ZIP_FILE_POS;
            filepos.Append(fpos);
        }
        err = unzGoToNextFile(uf);
    }
    commentLen = ginfo.size_comment;
}
コード例 #13
0
int extractCurrentFile(unzFile uf, const char *password)
{
  unz_file_info64 file_info = { 0 };
  char filename_inzip[MAX_FILENAME_LEN] = { 0 };

  int status = unzGetCurrentFileInfo64(uf, &file_info, filename_inzip, sizeof(filename_inzip), NULL, 0, NULL, 0);
  if (status != UNZ_OK)
  {
    return status;
  }

  uInt size_buf = WRITE_BUFFER_SIZE;
  void* buf = (void*) malloc(size_buf);
  if (buf == NULL) return UNZ_INTERNALERROR;
	
	if (password &&(password[0]==0))
	{
  	password = NULL;
  }
  status = unzOpenCurrentFilePassword(uf, password);
  const char* write_filename = filename_inzip;

  // Create the file on disk so we can unzip to it
  FILE* fout = NULL;
  if (status == UNZ_OK)
  {
    fout = fopen64(write_filename, "wb");
  }

  // Read from the zip, unzip to buffer, and write to disk
  if (fout != NULL)
  {
    do
    {
      status = unzReadCurrentFile(uf, buf, size_buf);
      if (status <= 0) break;
      if (fwrite(buf, status, 1, fout) != 1)
      {
        status = UNZ_ERRNO;
        break;
      }
    }
    while (status > 0);

    if (fout) fclose(fout);

    // Set the time of the file that has been unzipped
    if (status == 0)
    {
      setFileTime(write_filename, file_info.dosDate, file_info.tmu_date);
    }
  }

  unzCloseCurrentFile(uf);

  free(buf);
  return status;
}
コード例 #14
0
ファイル: zipfile.cpp プロジェクト: xaphier/Eternal-Lands
	void ZipFile::init()
	{
		zlib_filefunc64_def file_functions;
		unz_file_info64 info;
		unz64_file_pos position;
		boost::scoped_array<char> file_name;
		String index;
		Uint32 size;
		Sint32 ok;

		file_functions.zopen64_file = open_ifstream_func;
		file_functions.zread_file = read_istream_func;
		file_functions.zwrite_file = write_istream_func;
		file_functions.ztell64_file = tell_istream_func;
		file_functions.zseek64_file = seek_istream_func;
		file_functions.zclose_file = close_istream_func;
		file_functions.zerror_file = error_istream_func;

		m_file = unzOpen2_64(utf8_to_string(get_name()).c_str(),
			&file_functions);

		ok = unzGoToFirstFile(m_file);

		while (ok == UNZ_OK)
		{
			unzGetFilePos64(m_file, &position);

			unzGetCurrentFileInfo64(m_file, &info, 0, 0, 0, 0, 0,
				0);

			size = info.size_filename;

			file_name.reset(new char[size + 1]);

			unzGetCurrentFileInfo64(m_file, 0, file_name.get(),
				size, 0, 0, 0, 0);

			index = String(string_to_utf8(std::string(
				file_name.get(), size)));

			m_files[index] = ZipFileEntry(position);

			ok = unzGoToNextFile(m_file);
		}
	}
コード例 #15
0
ファイル: miniunzip.cpp プロジェクト: WildGenie/Scarab
bool zip::ZipArchiveInput::Index()
{
	static const int UNZ_MAXFILENAMEINZIP = 256;

	int err = unzGoToFirstFile(uf);
	if( err != UNZ_OK )
	{
		m_errorMessage << "Can't go to first file" << std::endl;
		return false;
	}

	while (err == UNZ_OK)
	{
		char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1];
		err = unzGetCurrentFileInfo64(uf, NULL,	szCurrentFileName, sizeof(szCurrentFileName)-1,NULL,0,NULL,0);
		if(err == UNZ_OK)
		{
#ifdef SCARAB_WCHAR_MODE
			String_t fileNameKey = utf_convert::as_wide( szCurrentFileName );
#else
			String_t fileNameKey = szCurrentFileName;
#endif
			if( !m_caseSensitive )
				for (size_t i = 0; i < fileNameKey.size(); ++i )
					fileNameKey[i] = _ttolower( fileNameKey[i] );

			unz_file_pos pos;
			err = unzGetFilePos( uf, &pos );
			if( err != UNZ_OK )
			{
				m_errorMessage << "Can't get file position for " << fileNameKey << std::endl;
				return false;
			}

			ZipEntry zipEntry;
			zipEntry.pos_in_zip_directory = pos.pos_in_zip_directory;
			zipEntry.num_of_file = pos.num_of_file;
			m_nameToEntry.insert( std::make_pair( fileNameKey, zipEntry ) );

			err = unzGoToNextFile(uf);
			if( err != UNZ_OK && err != UNZ_END_OF_LIST_OF_FILE )
			{
				m_errorMessage << "Can't go to next file" << std::endl;
				return false;
			}
		}
		else
		{
			m_errorMessage << "Can't get file info" << std::endl;
			return false;
		}
	}

	return err == UNZ_END_OF_LIST_OF_FILE;
}
コード例 #16
0
ファイル: GameScene.cpp プロジェクト: chaosren/mySample2
void readInZipFileName()
{
    
     //FileUtils::getInstance()->getWritablePath();
     //●●● filePath=/data/data/com.superman.plane/files/ ●●●
    
    std::string filePath = "/storage/sdcard0/Android/obb/com.superman.plane/";
    std::string zipFile = "main.2.com.superman.plane.obb";
    std::string imgFile = "assets/img_bg_1.jpg";

    std::string path = filePath + zipFile;
    
    // zipファイルをopenし、ファイル数を取得します。
    unzFile zipfile = unzOpen(path.c_str());
    log( "--- path = %s ---" ,path.c_str());
    
    unz_global_info global_info;
    if ( unzGetGlobalInfo( zipfile, &global_info ) != UNZ_OK )
    {
        log( "could not read file global infon" );
        unzClose( zipfile );
        return;
    }
    
    // ファイルの先頭にカーソルを合わせます
    unzGoToFirstFile(zipfile);
    uLong i;
    for ( i = 0; i < global_info.number_entry; ++i )
    {
        // Get info about current file.
        char filename[ 100 ];
        if ( unzGetCurrentFileInfo64(zipfile,
                                     NULL,
                                     filename,
                                     100,
                                     NULL, 0, NULL, 0)
            
            != UNZ_OK )
        {
            log( "could not read file" );
            unzClose( zipfile );
            return;
        }
        std::string str(filename);
        
        log("file[%lu] name == %s" , i , str.c_str());
        // ここでstd::vectorにでも詰めればOK
        
        // 次にカーソルを進める
        unzGoToNextFile(zipfile);
    }
    // 終わったらcloseを忘れずに。
    unzClose(zipfile);
}
コード例 #17
0
ファイル: qzipfile.cpp プロジェクト: gonzoua/qompress
QZipFileEntry QZipFile::currentEntry()
{
    int err;
    char filename_inzip[256];
    unz_file_info64 file_info;
    err = unzGetCurrentFileInfo64(m_unzFile, &file_info, filename_inzip, 
            sizeof(filename_inzip), NULL, 0, NULL, 0);
    if (err) {
        setErrorString("Failed to current get entry info");
        return QZipFileEntry();
    }
    else 
        return QZipFileEntry(filename_inzip, file_info);

}
コード例 #18
0
ファイル: file_access_zip.cpp プロジェクト: baekdahl/godot
Error FileAccessZip::_open(const String& p_path, int p_mode_flags) {

	close();

	ERR_FAIL_COND_V(p_mode_flags & FileAccess::WRITE, FAILED);
	ZipArchive* arch = ZipArchive::get_singleton();
	ERR_FAIL_COND_V(!arch, FAILED);
	zfile = arch->get_file_handle(p_path);
	ERR_FAIL_COND_V(!zfile, FAILED);

	int err = unzGetCurrentFileInfo64(zfile,&file_info,NULL,0,NULL,0,NULL,0);
	ERR_FAIL_COND_V(err != UNZ_OK, FAILED);

	return OK;
};
コード例 #19
0
ファイル: corel_thumbnail.cpp プロジェクト: hongwenjun/srgb
bool zip_extract_currentfile(unzFile uf, LPCTSTR save_filename)
{
    char szFilePathA[MAX_PATH];

    // 对于每个内部文件,可用 unzGetCurrentFileInfo64 来查内部文件名
    unz_file_info64 FileInfo;
    if (unzGetCurrentFileInfo64(uf, &FileInfo, szFilePathA, sizeof(szFilePathA), NULL, 0, NULL, 0) != UNZ_OK) {
        return false;
    }

//    printf("%s", szFilePathA);  // 在压缩文件中的 文件名

    // 对于非目录的内部文件,用 unzOpenCurrentFile打开
    if (unzOpenCurrentFile(uf) != UNZ_OK) {
        return false;
    }

    HANDLE hFile = CreateFile(save_filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);

    if (hFile == INVALID_HANDLE_VALUE) {
        return false;
    }


    // 然后 unzReadCurrentFile 读取文件内容,写入到真实文件中。
    // unzReadCurrentFile 返回 0 表示文件读取结束然后 unzReadCurrentFile 读取文件内容,写入到真实文件中。
    // unzReadCurrentFile 返回 0 表示文件读取结束

    char byBuffer[WRITEBUFFERSIZE];
    while (true) {
        int err = unzReadCurrentFile(uf, byBuffer, WRITEBUFFERSIZE);

        if (err < 0) {
            return false;
        } else if (err == 0) {
            break;
        } else {
            DWORD dwWritten = 0;

            if (!WriteFile(hFile, byBuffer, (DWORD)err, &dwWritten, NULL) || dwWritten != (DWORD)err) {
                return false;
            }
        }
    }

    CloseHandle(hFile);
    return true;
}
コード例 #20
0
ファイル: vfs-zip.c プロジェクト: nagitsu/mgba
struct VDirEntry* _vdzListNext(struct VDir* vd) {
	struct VDirZip* vdz = (struct VDirZip*) vd;
	if (!vdz->hasNextFile) {
		return 0;
	}
	unz_file_info64 info;
	int status = unzGetCurrentFileInfo64(vdz->z, &info, vdz->dirent.name, sizeof(vdz->dirent.name), 0, 0, 0, 0);
	if (status < 0) {
		return 0;
	}
	vdz->dirent.fileSize = info.uncompressed_size;
	if (unzGoToNextFile(vdz->z) == UNZ_END_OF_LIST_OF_FILE) {
		vdz->hasNextFile = false;
	}
	return &vdz->dirent.d;
}
コード例 #21
0
ファイル: Unzipper.cpp プロジェクト: afrozm/projects
BOOL CUnzipper::GetFileInfo(UZ_FileInfo& info)
{
	if (!m_uzFile)
		return FALSE;

	unz_file_info64 uzfi;

	ZeroMemory(&info, sizeof(info));
	ZeroMemory(&uzfi, sizeof(uzfi));
	char szFileName[MAX_PATH+1];
	char szComment[MAX_COMMENT+1];
	if (UNZ_OK != unzGetCurrentFileInfo64(m_uzFile, &uzfi, szFileName, MAX_PATH, NULL, 0, szComment, MAX_COMMENT))
		return FALSE;
    UTF8ToUniCodeString(szFileName, info.szFileName,
		sizeof(info.szFileName)/sizeof(TCHAR));
    UTF8ToUniCodeString(szComment, info.szComment,
		sizeof(info.szComment)/sizeof(TCHAR));

	// copy across
	info.dwVersion = uzfi.version;	
	info.dwVersionNeeded = uzfi.version_needed;
	info.dwFlags = uzfi.flag;	
	info.dwCompressionMethod = uzfi.compression_method; 
	info.dwDosDate = uzfi.dosDate;  
	info.dwCRC = uzfi.crc;	 
	info.dwCompressedSize = uzfi.compressed_size; 
	info.dwUncompressedSize = uzfi.uncompressed_size;
	info.dwInternalAttrib = uzfi.internal_fa; 
	info.dwExternalAttrib = uzfi.external_fa; 

	// replace filename forward slashes with backslashes
	int nLen = (int) lstrlen(info.szFileName);
	const int sLen = nLen;

	while (nLen--)
	{
		if (info.szFileName[nLen] == '/')
			info.szFileName[nLen] = '\\';
	}

	// is it a folder?
	info.bFolder = (info.szFileName[sLen - 1] == '\\');
	if (info.bFolder)
		info.szFileName[sLen - 1] = 0;

	return TRUE;
}
コード例 #22
0
ファイル: apk.cpp プロジェクト: Ricky310711/DualBootPatcher
static bool read_to_memory(unzFile uf, std::vector<unsigned char> *out)
{
    unz_file_info64 fi;
    memset(&fi, 0, sizeof(fi));

    int ret = unzGetCurrentFileInfo64(
        uf,         // file
        &fi,        // pfile_info
        nullptr,    // filename
        0,          // filename_size
        nullptr,    // extrafield
        0,          // extrafield_size
        nullptr,    // comment
        0           // comment_size
    );

    if (ret != UNZ_OK) {
        return false;
    }

    std::vector<unsigned char> data;
    data.reserve(fi.uncompressed_size);

    ret = unzOpenCurrentFile(uf);
    if (ret != UNZ_OK) {
        return false;
    }

    char buf[50 * 1024]; // 50 KiB
    int bytes_read;

    while ((bytes_read = unzReadCurrentFile(uf, buf, sizeof(buf))) > 0) {
        data.insert(data.end(), buf, buf + bytes_read);
    }

    unzCloseCurrentFile(uf);

    if (bytes_read != 0) {
        return false;
    }

    data.swap(*out);
    return true;
}
コード例 #23
0
bool ArchiveReader::Enumerate_ZIP()
{
	clPtr<iIStream> TheSource = FSourceFile;
	FSourceFile->Seek( 0 );

	zlib_filefunc64_def ffunc;
	fill_functions( TheSource.GetInternalPtr(), &ffunc );

	unzFile uf = unzOpen2_64( "", &ffunc );

	unz_global_info64 gi;
	int err = unzGetGlobalInfo64( uf, &gi );

	for ( uLong i = 0; i < gi.number_entry; i++ )
	{
		char filename_inzip[256];
		unz_file_info64 file_info;
		err = unzGetCurrentFileInfo64( uf, &file_info, filename_inzip, sizeof( filename_inzip ), NULL, 0, NULL, 0 );

		if ( err != UNZ_OK ) { break; }

		if ( ( i + 1 ) < gi.number_entry )
		{
			err = unzGoToNextFile( uf );

			// WARNING: "error %d with zipfile in unzGoToNextFile\n", err
			if ( err != UNZ_OK ) { break; }
		}

		sFileInfo Info;
		Info.FOffset = 0;
		Info.FCompressedSize = file_info.compressed_size;
		Info.FSize = file_info.uncompressed_size;
		FFileInfos.push_back( Info );

		std::string TheName = Arch_FixFileName( filename_inzip );
		FFileInfoIdx[TheName] = ( int )FFileNames.size();
		FFileNames.push_back( TheName );
		FRealFileNames.push_back( std::string( filename_inzip ) );
	}

	unzClose( uf );
	return true;
}
コード例 #24
0
ファイル: DKZipUnarchiver.cpp プロジェクト: hhg128/DKGL
			static DKObject<UnZipFile> Create(const DKString& zipFile, const DKString& file, const char* password)
			{
				if (zipFile.Length() == 0 || file.Length() == 0)
					return NULL;

				DKString filename = zipFile.FilePathString();

				unzFile uf = NULL;
#ifdef _WIN32
				{
					zlib_filefunc64_def ffunc;
					fill_win32_filefunc64W(&ffunc);
					uf = unzOpen2_64((const wchar_t*)filename, &ffunc); // UTF16LE
				}
#else
				{
					DKStringU8 filenameUTF8(filename);
					if (filenameUTF8.Bytes() > 0)
						uf = unzOpen64((const char*)filenameUTF8); // UTF8
				}
#endif
				if (uf)
				{
					unz_file_info64 file_info;
					DKStringU8 fileUTF8(file);
					if (fileUTF8.Bytes() > 0 &&
						unzLocateFile(uf, (const char*)fileUTF8, 0) == UNZ_OK &&
						unzGetCurrentFileInfo64(uf, &file_info, NULL, 0, NULL, 0, NULL, 0) == UNZ_OK &&
						file_info.uncompressed_size > 0)
					{
						if (unzOpenCurrentFilePassword(uf, password) == UNZ_OK)
						{
							DKObject<UnZipFile> p = DKOBJECT_NEW UnZipFile(uf, file_info, password);
							return p;
						}
						else
						{
							DKLog("[%s] failed to open file: %ls.\n", DKLIB_FUNCTION_NAME, (const wchar_t*)file);
						}
					}
				}
				return NULL;
			}
コード例 #25
0
ファイル: vfs-zip.c プロジェクト: OpenEmu/mGBA-Core
struct VFile* _vdzOpenFile(struct VDir* vd, const char* path, int mode) {
	UNUSED(mode);
	struct VDirZip* vdz = (struct VDirZip*) vd;

	if ((mode & O_ACCMODE) != O_RDONLY) {
		// minizip implementation only supports read
		return 0;
	}

	if (unzLocateFile(vdz->z, path, 0) != UNZ_OK) {
		return 0;
	}

	if (unzOpenCurrentFile(vdz->z) < 0) {
		return 0;
	}

	unz_file_info64 info;
	int status = unzGetCurrentFileInfo64(vdz->z, &info, 0, 0, 0, 0, 0, 0);
	if (status < 0) {
		return 0;
	}

	struct VFileZip* vfz = malloc(sizeof(struct VFileZip));
	vfz->z = vdz->z;
	vfz->buffer = 0;
	vfz->bufferSize = 0;
	vfz->fileSize = info.uncompressed_size;

	vfz->d.close = _vfzClose;
	vfz->d.seek = _vfzSeek;
	vfz->d.read = _vfzRead;
	vfz->d.readline = VFileReadline;
	vfz->d.write = _vfzWrite;
	vfz->d.map = _vfzMap;
	vfz->d.unmap = _vfzUnmap;
	vfz->d.truncate = _vfzTruncate;
	vfz->d.size = _vfzSize;
	vfz->d.sync = _vfzSync;

	return &vfz->d;
}
コード例 #26
0
/// Internal routine to extract a single file from ZIP archive
int ExtractCurrentFile_ZIP( unzFile uf, const char* password, int* abort_flag, float* progress, const clPtr<iOStream>& fout )
{
	char filename_inzip[256];
	int err = UNZ_OK;
	void* buf;
	uInt size_buf;
	unz_file_info64 file_info;

	err = unzGetCurrentFileInfo64( uf, &file_info, filename_inzip, sizeof( filename_inzip ), NULL, 0, NULL, 0 );

	if ( err != UNZ_OK ) { return err; }

	uint64 file_size = ( uint64 )file_info.uncompressed_size;
	uint64 total_bytes = 0;

	unsigned char _buf[WRITEBUFFERSIZE];
	size_buf = WRITEBUFFERSIZE;
	buf = ( void* )_buf;

	err = unzOpenCurrentFilePassword( uf, password );

	if ( err != UNZ_OK ) { return err; }

	do
	{
		err = unzReadCurrentFile( uf, buf, size_buf );

		if ( err < 0 ) { break; }

		if ( err > 0 ) { total_bytes += err; fout->Write( buf, err ); }
	}
	while ( err > 0 );

	int close_err = unzCloseCurrentFile ( uf );

	if ( close_err != UNZ_OK ) { return close_err; }

	return err;
}
コード例 #27
0
ファイル: decompress_wrap.cpp プロジェクト: AlexWMF/Carberp
int InternalEnumFiles(HZIP hZip)
{
    int r=-1;
    unz_global_info64 gi;
    ZIPDECOMPRESSION *p=(ZIPDECOMPRESSION*)hZip;
    int err=unzGetGlobalInfo64(p->hZip,&gi);
    if (err == UNZ_OK)
    {
        for (uLong i=0; i<gi.number_entry; i++)
        {
            char filename_inzip[256];
            unz_file_info64 file_info;
            err=unzGetCurrentFileInfo64(p->hZip,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0);
            if (err == UNZ_OK)
            {
                LPWSTR sourceFile=OemToUnicodeEx(filename_inzip,-1);

                if (p->bOnlyEnum)
                {
                    if (!p->bEnumAnsi)
                        r=(p->lpEnumProc(sourceFile)) ? 0 : -1;
                    else
                    {
                        char ansi_filename_inzip[256];
                        OemToAnsi(filename_inzip,ansi_filename_inzip);
                        r=(p->lpEnumProc((LPWSTR)ansi_filename_inzip)) ? 0 : -1;
                    }
                }
                else
                    r=ExtractCurrentFile(hZip,false);

                MemFree(sourceFile);
            }
            unzGoToNextFile(p->hZip);
        }
    }
    return r;
}
コード例 #28
0
ファイル: sq_zlib.cpp プロジェクト: The-Mad-Pirate/squilu
static SQRESULT sq_minizip_unzip_get_file_info(HSQUIRRELVM v)
{
    SQ_FUNC_VARS_NO_TOP(v);
    GET_minizip_unzip_INSTANCE();
    char filename_inzip[LZ_MAX_ZIP_NAME_SIZE];
    unz_file_info64 file_info;
    int err = unzGetCurrentFileInfo64(self,&file_info,filename_inzip,LZ_MAX_ZIP_NAME_SIZE,NULL,0,NULL,0);
    if (err!=UNZ_OK)
    {
        return sq_throwerror(v, _SC("error %d with zipfile in unzGetCurrentFileInfo\n"),err);
    }
    sq_newtable(v);
    sq_pushliteral(v, "name");
    sq_pushstring(v, filename_inzip, -1);
    sq_rawset(v, -3);
    sq_pushliteral(v, "size");
    sq_pushinteger(v, file_info.uncompressed_size);
    sq_rawset(v, -3);
    sq_pushliteral(v, "is_dir");
    sq_pushbool(v, file_info.external_fa & ZIP_DOS_DIR_ATTRIBUTE_BITFLAG);
    sq_rawset(v, -3);

	return 1;
}
コード例 #29
0
ファイル: miniunzip.cpp プロジェクト: WildGenie/Scarab
bool zip::ZipArchiveInput::ReadCurrentFile( String_t const& fileName, Byte_t*& pMemoryBlock, size_t& size )
{
	int err = UNZ_OK;

#ifdef SCARAB_WCHAR_MODE
	std::string filename_inzip = utf_convert::as_utf8( fileName );
#else
	std::string filename_inzip = fileName;
#endif

	unz_file_info64 file_info;
	uLong ratio=0;
	err = unzGetCurrentFileInfo64(uf,&file_info,(char*)filename_inzip.c_str(),filename_inzip.size()+1,NULL,0,NULL,0);
	if ( err != UNZ_OK )
	{
		m_errorMessage << "unzGetCurrentFileInfo error in file " << fileName << " error code: " << err << std::endl;
		return false;
	}

	size_t size_buf = (size_t)file_info.uncompressed_size;
	void* buf = malloc(size_buf);
	if (buf == NULL)
	{
		m_errorMessage << "Error allocating memory for file " << fileName << " requested: " << size_buf << std::endl;
		return false;
	}

	err = unzOpenCurrentFilePassword(uf,password);
	if (err != UNZ_OK)
	{
		m_errorMessage << "unzOpenCurrentFilePassword error in file " << fileName << " error code: " << err << std::endl;
		return false;
	}

	int numRead = unzReadCurrentFile(uf,buf,size_buf);
	if( numRead < 0 )
	{
		m_errorMessage << "unzReadCurrentFile error in file " << fileName << " error code: " << err << std::endl;
		err = numRead;
	}
	else
		err = UNZ_OK;

	if (err==UNZ_OK)
	{
		err = unzCloseCurrentFile (uf);
		if (err!=UNZ_OK)
			m_errorMessage << "unzCloseCurrentFile error in file " << fileName << " error code: " << err << std::endl;
	}
	else
		unzCloseCurrentFile(uf); /* don't lose the error */

	if( err != UNZ_OK )
	{
		free(buf);
		return false;
	}

	pMemoryBlock = (Byte_t*)buf;
	size = size_buf;
	return true;
}
コード例 #30
0
ファイル: tri-zip.c プロジェクト: aboleab/ArangoDB
static int ExtractCurrentFile (unzFile uf,
                               void* buffer,
                               const size_t bufferSize,
                               const char* outPath,
                               const bool skipPaths,
                               const bool overwrite,
                               const char* password) {
  char filenameInZip[256];
  char* filenameWithoutPath;
  char* fullPath;
  char* p;
  FILE *fout;
  unz_file_info64 fileInfo;

  if (unzGetCurrentFileInfo64(uf, &fileInfo, filenameInZip, sizeof(filenameInZip), NULL, 0, NULL, 0) != UNZ_OK) {
    return TRI_ERROR_INTERNAL;
  }

  p = filenameWithoutPath = filenameInZip;

  // get the file name without any path prefix
  while (*p != '\0') {
    if (*p == '/' || *p == '\\') {
      filenameWithoutPath = p + 1;
    }

    p++;
  }
  
  // found a directory
  if (*filenameWithoutPath == '\0') {
    if (! skipPaths) {
      fullPath = TRI_Concatenate2File(outPath, filenameInZip);
      TRI_CreateRecursiveDirectory(fullPath);
      TRI_Free(TRI_CORE_MEM_ZONE, fullPath);
    }
  }

  // found a file
  else {
    const char* writeFilename;

    if (! skipPaths) {
      writeFilename = filenameInZip;
    }
    else {
      writeFilename = filenameWithoutPath;
    }

    if (unzOpenCurrentFilePassword(uf, password) != UNZ_OK) {
      return TRI_ERROR_INTERNAL;
    }

    // prefix the name from the zip file with the path specified
    fullPath = TRI_Concatenate2File(outPath, writeFilename);
    
    if (! overwrite && TRI_ExistsFile(fullPath)) {
      return TRI_ERROR_INTERNAL;
    }

    // try to write the outfile
    fout = fopen(fullPath, "wb");

    // cannot write to outfile. this may be due to the target directory missing
    if (fout == NULL && ! skipPaths && filenameWithoutPath != (char*) filenameInZip) {
      char* d;

      char c = *(filenameWithoutPath - 1);
      *(filenameWithoutPath - 1) = '\0';

      // create target directory recursively
      d = TRI_Concatenate2File(outPath, filenameInZip);
      TRI_CreateRecursiveDirectory(d);
      TRI_Free(TRI_CORE_MEM_ZONE, d);

      *(filenameWithoutPath - 1) = c;

      // try again
      fout = fopen(fullPath, "wb");
    }
    
    TRI_Free(TRI_CORE_MEM_ZONE, fullPath);

    if (fout == NULL) {
      return TRI_ERROR_CANNOT_WRITE_FILE;
    }

    while (true) {
      int result = unzReadCurrentFile(uf, buffer, bufferSize);

      if (result < 0) {
        fclose(fout);

        return TRI_ERROR_INTERNAL;
      }

      if (result > 0) {
        if (fwrite(buffer, result, 1, fout) != 1) {
          fclose(fout);

          return TRI_set_errno(TRI_ERROR_SYS_ERROR);
        }
      }
      else {
        assert(result == 0);
        break;
      }
    }

    fclose(fout);
  }

  unzCloseCurrentFile(uf);
  
  return TRI_ERROR_NO_ERROR;
}