本文整理汇总了C++中ZipFile类的典型用法代码示例。如果您正苦于以下问题:C++ ZipFile类的具体用法?C++ ZipFile怎么用?C++ ZipFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ZipFile类的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: processJarFiles
ssize_t processJarFiles(Bundle* bundle, ZipFile* zip)
{
status_t err;
ssize_t count = 0;
const android::Vector<const char*>& jars = bundle->getJarFiles();
size_t N = jars.size();
for (size_t i=0; i<N; i++) {
ZipFile jar;
err = jar.open(jars[i], ZipFile::kOpenReadOnly);
if (err != 0) {
fprintf(stderr, "ERROR: unable to open '%s' as a zip file: %d\n",
jars[i], err);
return err;
}
err += processJarFile(&jar, zip);
if (err < 0) {
fprintf(stderr, "ERROR: unable to process '%s'\n", jars[i]);
return err;
}
count += err;
}
return count;
}
开发者ID:AOSP-Jaguar,项目名称:frameworks_base,代码行数:25,代码来源:Package.cpp
示例2: ThrowException
Handle<Value> ZipFile::New(const Arguments& args)
{
if (!args.IsConstructCall())
return ThrowException(String::New("Cannot call constructor as function, you need to use 'new' keyword"));
if (args.Length() != 1 || !args[0]->IsString())
return ThrowException(Exception::TypeError(
String::New("first argument must be a path to a zipfile")));
std::string input_file = TOSTR(args[0]);
struct zip *za;
int err;
char errstr[1024];
if ((za=zip_open(input_file.c_str(), ZIP_CREATE, &err)) == NULL) {
zip_error_to_str(errstr, sizeof(errstr), err, errno);
std::stringstream s;
s << "cannot open file: " << input_file << " error: " << errstr << "\n";
return ThrowException(Exception::Error(
String::New(s.str().c_str())));
}
ZipFile* zf = new ZipFile(input_file);
zf->archive = za;
zf->GetNames();
zf->Wrap(args.This());
return args.This();
}
开发者ID:toots,项目名称:node-zipfile,代码行数:29,代码来源:node_zipfile.cpp
示例3: getFileDataFromZip
unsigned char* getFileDataFromZip(const char* zipFile, const char* fileName, ssize_t* size)
{
if (nullptr == zipFile || nullptr == fileName || nullptr == size)
return nullptr;
Data zipData = FileUtils::getInstance()->getDataFromFile(zipFile);
if (zipData.isNull())
return nullptr;
ZipFile * zip = ZipFile::createWithBuffer(zipData.getBytes(), zipData.getSize());
if (nullptr == zip)
return nullptr;
*size = 0;
unsigned char * data = zip->getFileData(fileName, size);
delete zip;
if (nullptr == data || size <= 0)
{
*size = 0;
free(data);
return nullptr;
}
return data;
}
开发者ID:Danewalker,项目名称:DotaSkeletonAnim,代码行数:25,代码来源:Utils.cpp
示例4: ZipFile
// Creates new zip file object for given zip file name, then opens zip file
ZipFile* ZipFile::Open(String* FileName)
{
ZipFile* zipFile = new ZipFile();
zipFile->FileName = FileName;
zipFile->Open();
return zipFile;
}
开发者ID:avs009,项目名称:gsf,代码行数:10,代码来源:ZipFile.cpp
示例5: OpenFileForUnzip
// Updates specified files in zip
void ZipFile::Update(String* FileSpec, UpdateOption UpdateWhen, Boolean AddNewFiles, Boolean RecurseSubdirectories, PathInclusion AddPathMethod)
{
// If destination zip file doesn't exist, we just perform an Add
if (!File::Exists(fileName))
{
if (AddNewFiles) Add(FileSpec, RecurseSubdirectories, AddPathMethod);
return;
}
char* pszPassword = NULL;
ZipFile* tempZipFile;
OpenFileForUnzip();
// Just wrapping in a try/catch/finally to make sure unmanaged code allocations always get released and temp zip file gets removed
try
{
// Create temporary zip file to hold update results
tempZipFile = CreateTempZipFile();
// Get ANSI password, if one was provided
if (password)
if (password->get_Length())
pszPassword = StringToCharBuffer(password);
String* fileSpec = Path::GetFileName(FileSpec);
String* rootPath = JustPath(FileSpec, fileSpec);
UpdateFilesInZip(tempZipFile, fileSpec, rootPath, rootPath->get_Length(), UpdateWhen, AddNewFiles, RecurseSubdirectories, AddPathMethod, pszPassword);
// Now make the temp file the new zip file
Close();
tempZipFile->Close();
File::Delete(fileName);
File::Move(tempZipFile->fileName, fileName);
}
catch (CompressionException* ex)
{
// We just rethrow any errors back to user
throw ex;
}
catch (Exception* ex)
{
throw ex;
}
__finally
{
if (pszPassword)
free(pszPassword);
// If everything went well, temp zip will no longer exist, but just in case we tidy up and delete the temp file...
DeleteTempZipFile(tempZipFile);
}
// We'll reload the file list after update if requested...
if (autoRefresh) Refresh();
}
开发者ID:avs009,项目名称:gsf,代码行数:57,代码来源:ZipFile.cpp
示例6: unzip
Result unzip (const MemoryBlock& data)
{
setStatusMessage ("Installing...");
File unzipTarget;
bool isUsingTempFolder = false;
{
MemoryInputStream input (data, false);
ZipFile zip (input);
if (zip.getNumEntries() == 0)
return Result::fail ("The downloaded file wasn't a valid JUCE file!");
unzipTarget = targetFolder;
if (unzipTarget.exists())
{
isUsingTempFolder = true;
unzipTarget = targetFolder.getNonexistentSibling();
if (! unzipTarget.createDirectory())
return Result::fail ("Couldn't create a folder to unzip the new version!");
}
Result r (zip.uncompressTo (unzipTarget));
if (r.failed())
{
if (isUsingTempFolder)
unzipTarget.deleteRecursively();
return r;
}
}
if (isUsingTempFolder)
{
File oldFolder (targetFolder.getSiblingFile (targetFolder.getFileNameWithoutExtension() + "_old")
.getNonexistentSibling());
if (! targetFolder.moveFileTo (oldFolder))
{
unzipTarget.deleteRecursively();
return Result::fail ("Could not remove the existing folder!");
}
if (! unzipTarget.moveFileTo (targetFolder))
{
unzipTarget.deleteRecursively();
return Result::fail ("Could not overwrite the existing folder!");
}
}
return Result::ok();
}
开发者ID:jkent,项目名称:JUCE,代码行数:56,代码来源:jucer_AutoUpdater.cpp
示例7: writeAPK
/*
* The directory hierarchy looks like this:
* "outputDir" and "assetRoot" are existing directories.
*
* On success, "bundle->numPackages" will be the number of Zip packages
* we created.
*/
status_t writeAPK(Bundle* bundle, int fd, const sp<OutputSet>& outputSet, bool isOverlay)
{
#if BENCHMARK
fprintf(stdout, "BENCHMARK: Starting APK Bundling \n");
long startAPKTime = clock();
#endif /* BENCHMARK */
status_t result = NO_ERROR;
ZipFile* zip = NULL;
status_t status;
zip = new ZipFile;
status = zip->openfd(fd, ZipFile::kOpenReadWrite);
if (status != NO_ERROR) {
fprintf(stderr, "ERROR: unable to open file as Zip file for writing\n");
result = PERMISSION_DENIED;
goto bail;
}
result = writeAPK(bundle, zip, "file_descriptor", outputSet, isOverlay);
if (result != NO_ERROR) {
fprintf(stderr, "ERROR: Writing apk failed\n");
goto bail;
}
/* anything here? */
if (zip->getNumEntries() == 0) {
if (bundle->getVerbose()) {
printf("Archive is empty -- removing\n");
}
delete zip; // close the file so we can remove it in Win32
zip = NULL;
close(fd);
}
assert(result == NO_ERROR);
bail:
delete zip; // must close before remove in Win32
close(fd);
if (result != NO_ERROR) {
if (bundle->getVerbose()) {
printf("Removing archive due to earlier failures\n");
}
}
if (result == NO_ERROR && bundle->getVerbose())
printf("Done!\n");
#if BENCHMARK
fprintf(stdout, "BENCHMARK: End APK Bundling. Time Elapsed: %f ms \n",(clock() - startAPKTime)/1000.0);
#endif /* BENCHMARK */
return result;
}
开发者ID:entony80,项目名称:frameworks_base-2,代码行数:62,代码来源:Package.cpp
示例8: fopen
bool TextureHandler::Load (const char *zip)
{
FILE *f = fopen (zip, "rb");
if (f) {
ZipFile *zf = new ZipFile;
if (zf->Init (f) == RET_FAIL) {
logger.Trace (NL_Error, "Failed to load zip archive %s\n", zip);
fclose (f);
return false;
}
const char *imgExt[]={ "bmp", "jpg", "tga", "png", "dds", "pcx", "pic", "gif", "ico", 0 };
// Add the zip entries to the texture set
for (int a=0;a<zf->GetNumFiles ();a++)
{
char tempFile[64];
zf->GetFilename (a, tempFile, sizeof(tempFile));
char *ext=FixTextureName (tempFile);
if (ext)
{
int x=0;
for (x=0;imgExt[x];x++)
if (!strcmp(imgExt[x],ext)) break;
if (!imgExt[x])
continue;
if (textures.find(tempFile) != textures.end())
continue;
TexRef ref;
ref.zip = zips.size();
ref.index = a;
ref.texture = LoadTexture (zf,a, tempFile);
if(textures.find(tempFile)!=textures.end())
logger.Trace(NL_Debug,"Texture %s already loaded\n", tempFile);
TexRef &tr = textures[tempFile];
tr.texture = ref.texture;
tr.index = a;;
tr.zip = zips.size();
}
}
fclose (f);
zips.push_back (zf);
}
return false;
}
开发者ID:SpliFF,项目名称:upspring,代码行数:55,代码来源:Texture.cpp
示例9: main
int main(int argc, char** argv) {
ZipFile *zipfile;
zipfile=new ZipFile("啊.zip");
zipfile->open();
qDebug()<<zipfile->readFileList();
qDebug()<<zipfile->readFile(zipfile->readFileList().at(0))<<"a";
qDebug()<<zipfile->readFile(zipfile->readFileList().at(3))<<"b";
qDebug()<<"C";
return 0;
}
开发者ID:Michael-Z,项目名称:mangaviewer,代码行数:11,代码来源:main.cpp
示例10: unzip
Result unzip (const ModuleList::Module& m, const MemoryBlock& data)
{
setStatusMessage ("Installing " + m.uid + "...");
MemoryInputStream input (data, false);
ZipFile zip (input);
if (zip.getNumEntries() == 0)
return Result::fail ("The downloaded file wasn't a valid module file!");
return zip.uncompressTo (targetList.getModulesFolder(), true);
}
开发者ID:HsienYu,项目名称:JUCE,代码行数:12,代码来源:jucer_JuceUpdater.cpp
示例11: ThrowException
Handle<Value> ZipFile::readFile(const Arguments& args) {
HandleScope scope;
if (args.Length() < 2)
return ThrowException(Exception::TypeError(
String::New("requires two arguments, the name of a file and a callback")));
// first arg must be name
if (!args[0]->IsString())
return ThrowException(Exception::TypeError(
String::New("first argument must be a file name inside the zip")));
// last arg must be function callback
if (!args[args.Length()-1]->IsFunction())
return ThrowException(Exception::TypeError(
String::New("last argument must be a callback function")));
std::string name = TOSTR(args[0]);
ZipFile* zf = ObjectWrap::Unwrap<ZipFile>(args.This());
closure_t *closure = new closure_t();
closure->request.data = closure;
// libzip is not threadsafe so we cannot use the zf->archive_
// instead we open a new zip archive for each thread
struct zip *za;
int err;
char errstr[1024];
if ((za = zip_open(zf->file_name_.c_str() , 0, &err)) == NULL) {
zip_error_to_str(errstr, sizeof(errstr), err, errno);
std::stringstream s;
s << "cannot open file: " << zf->file_name_ << " error: " << errstr << "\n";
zip_close(za);
return ThrowException(Exception::Error(
String::New(s.str().c_str())));
}
closure->zf = zf;
closure->za = za;
closure->error = false;
closure->name = name;
closure->cb = Persistent<Function>::New(Handle<Function>::Cast(args[args.Length()-1]));
uv_queue_work(uv_default_loop(), &closure->request, Work_ReadFile, Work_AfterReadFile);
uv_ref(uv_default_loop());
zf->Ref();
return Undefined();
}
开发者ID:anoopsinha,项目名称:maui-epub,代码行数:48,代码来源:node_zipfile.cpp
示例12: createSVGDrawable
void createSVGDrawable()
{
lastSVGLoadTime = Time::getCurrentTime();
MemoryInputStream iconsFileStream (BinaryData::icons_zip, BinaryData::icons_zipSize, false);
ZipFile icons (&iconsFileStream, false);
// Load a random SVG file from our embedded icons.zip file.
const ScopedPointer<InputStream> svgFileStream (icons.createStreamForEntry (Random::getSystemRandom().nextInt (icons.getNumEntries())));
if (svgFileStream != nullptr)
{
svgDrawable = dynamic_cast <DrawableComposite*> (Drawable::createFromImageDataStream (*svgFileStream));
if (svgDrawable != nullptr)
{
// to make our icon the right size, we'll set its bounding box to the size and position that we want.
svgDrawable->setBoundingBox (RelativeParallelogram (Point<float> (-100, -100),
Point<float> (100, -100),
Point<float> (-100, 100)));
}
}
}
开发者ID:AydinSakar,项目名称:JUCE,代码行数:23,代码来源:GraphicsDemo.cpp
示例13: main
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-//
int main ( int argc , char **argv)
{
if(argc != 2)
{
cout << "Usage: " << argv[0] << " <file name>" << endl;
return 0;
}
ZipFile zfile(argv[1]);
/// Zip a file
cout << "Original File Size: " << zfile.size() << " Bytes" << endl;
/// Compress file
ZipFile czf = zfile.compress(zfile.getPath() + ".gz");
cout << "Compressed File Size: " << czf.size() << " Bytes" << endl;
/// Decompress file
ZipFile dzf = czf.decompress(czf.getPath() + ".decom");
cout << "Decompressed File Size: " << dzf.size() << " Bytes" << endl;
cout << "Ratio: " << (1.f - (float)czf.size() / (float)dzf.size()) * 100.f << "%" << endl;
/// Zip a buffer
ZipMemory<GraVitoN::guchar> buff(256);
buff.zero();
for(size_t i=0; i<buff.size(); ++i)
buff[i] = (i % ('z' - 'a' + 1)) + 'a';
cout << endl;
cout << "Original buff: '" << buff << "'" << endl;
/// Compress buffer
ZipMemory<unsigned char> izbuff, ozbuff;
ozbuff = buff.compress();
cout << "Compressed buffer size: " << ozbuff.size() << " Bytes" << endl;
/// Decompress buffer
// cout << "Compressed Buffer: '" << GraVitoN::Utils::OptParser::hexToStr(izbuff, ib_size) << "'" << endl;
izbuff = ozbuff.decompress();
cout << "Decompressed Buffer Size: " << izbuff.size() << " Bytes" << endl;
cout << "Decompressed Buffer: '" << izbuff << "'" << endl;
cout << "Ratio: " << (1.f - (float)ozbuff.size() / (float)izbuff.size()) * 100.f << "%" << endl;
cout << "Result: " << ( (buff.toString() == izbuff.toString()) ? ("Matched") : ("UNMATCHED") ) << endl;
return 0;
}
开发者ID:jizhongqing,项目名称:graviton,代码行数:48,代码来源:zip_test.cpp
示例14: Write
void FFMS_Track::Write(ZipFile &stream) const {
stream.Write<uint8_t>(TT);
stream.Write(TB.Num);
stream.Write(TB.Den);
stream.Write<int32_t>(MaxBFrames);
stream.Write<uint8_t>(UseDTS);
stream.Write<uint8_t>(HasTS);
stream.Write<uint64_t>(size());
if (empty()) return;
FrameInfo temp{};
for (size_t i = 0; i < size(); ++i)
WriteFrame(stream, Frames[i], i == 0 ? temp : Frames[i - 1], TT);
}
开发者ID:KonDiter42,项目名称:ffms2,代码行数:15,代码来源:track.cpp
示例15: initObjectIconMap
Drawable* ResourceLoader::createSVGDrawable(const String& filename)
{
initObjectIconMap();
if (iconsFromZipFile.size() == 0)
{
// If we've not already done so, load all the images from the zip file..
MemoryInputStream iconsFileStream (BinaryData::icons_zip, BinaryData::icons_zipSize, false);
ZipFile icons (&iconsFileStream, false);
for (int i = 0; i < icons.getNumEntries(); ++i)
{
ScopedPointer<InputStream> svgFileStream (icons.createStreamForEntry (i));
if (svgFileStream != 0)
{
iconNames.add (icons.getEntry(i)->filename);
iconsFromZipFile.add (Drawable::createFromImageDataStream (*svgFileStream));
}
}
}
return iconsFromZipFile [iconNames.indexOf (filename)];//->createCopy();
}
开发者ID:imclab,项目名称:SaM-Designer,代码行数:24,代码来源:ResourceLoader.cpp
示例16: fopen
void Tools::LoadImages()
{
FILE *f = fopen("data/data.ups", "rb");
if (!f) {
fltk::message("Failed to load data.ups");
}
else
{
ZipFile zf;
zf.Init(f);
for(unsigned int a=0;a<tools.size();a++) {
if (!tools[a]->imageFile)
continue;
std::string fn = tools[a]->imageFile;
int zipIndex=-1;
for (int fi=0;fi<zf.GetNumFiles();fi++) {
char zfn [64];
zf.GetFilename(fi, zfn, sizeof(zfn));
if (!STRCASECMP(zfn, fn.c_str())) {
zipIndex = fi;
break;
}
}
if (zipIndex>=0) {
int len = zf.GetFileLen(zipIndex);
char *buf = new char[len];
zf.ReadFile(zipIndex, buf);
tools[a]->image = FltkImage::Load(buf, len);
if (!tools[a]->image) {
fltk::message("Failed to load texture %s\n", fn.c_str());
delete[] buf;
continue;
}
delete[] buf;
tools[a]->button->image(tools[a]->image->img);
tools[a]->button->label("");
} else
fltk::message("Couldn't find %s", fn.c_str());
}
fclose(f);
}
}
开发者ID:Neoniet,项目名称:upspring,代码行数:48,代码来源:Tools.cpp
示例17: writeAPK
/*
* The directory hierarchy looks like this:
* "outputDir" and "assetRoot" are existing directories.
*
* On success, "bundle->numPackages" will be the number of Zip packages
* we created.
*/
status_t writeAPK(Bundle* bundle, const String8& outputFile, const sp<OutputSet>& outputSet)
{
#if BENCHMARK
fprintf(stdout, "BENCHMARK: Starting APK Bundling \n");
long startAPKTime = clock();
#endif /* BENCHMARK */
status_t result = NO_ERROR;
ZipFile* zip = NULL;
int count;
//bundle->setPackageCount(0);
/*
* Prep the Zip archive.
*
* If the file already exists, fail unless "update" or "force" is set.
* If "update" is set, update the contents of the existing archive.
* Else, if "force" is set, remove the existing archive.
*/
FileType fileType = getFileType(outputFile.string());
if (fileType == kFileTypeNonexistent) {
// okay, create it below
} else if (fileType == kFileTypeRegular) {
if (bundle->getUpdate()) {
// okay, open it below
} else if (bundle->getForce()) {
if (unlink(outputFile.string()) != 0) {
fprintf(stderr, "ERROR: unable to remove '%s': %s\n", outputFile.string(),
strerror(errno));
goto bail;
}
} else {
fprintf(stderr, "ERROR: '%s' exists (use '-f' to force overwrite)\n",
outputFile.string());
goto bail;
}
} else {
fprintf(stderr, "ERROR: '%s' exists and is not a regular file\n", outputFile.string());
goto bail;
}
if (bundle->getVerbose()) {
printf("%s '%s'\n", (fileType == kFileTypeNonexistent) ? "Creating" : "Opening",
outputFile.string());
}
status_t status;
zip = new ZipFile;
status = zip->open(outputFile.string(), ZipFile::kOpenReadWrite | ZipFile::kOpenCreate);
if (status != NO_ERROR) {
fprintf(stderr, "ERROR: unable to open '%s' as Zip file for writing\n",
outputFile.string());
goto bail;
}
if (bundle->getVerbose()) {
printf("Writing all files...\n");
}
count = processAssets(bundle, zip, outputSet);
if (count < 0) {
fprintf(stderr, "ERROR: unable to process assets while packaging '%s'\n",
outputFile.string());
result = count;
goto bail;
}
if (bundle->getVerbose()) {
printf("Generated %d file%s\n", count, (count==1) ? "" : "s");
}
count = processJarFiles(bundle, zip);
if (count < 0) {
fprintf(stderr, "ERROR: unable to process jar files while packaging '%s'\n",
outputFile.string());
result = count;
goto bail;
}
if (bundle->getVerbose())
printf("Included %d file%s from jar/zip files.\n", count, (count==1) ? "" : "s");
result = NO_ERROR;
/*
* Check for cruft. We set the "marked" flag on all entries we created
* or decided not to update. If the entry isn't already slated for
* deletion, remove it now.
*/
{
if (bundle->getVerbose())
printf("Checking for deleted files\n");
//.........这里部分代码省略.........
开发者ID:AOSP-Jaguar,项目名称:frameworks_base,代码行数:101,代码来源:Package.cpp
示例18: FinishLoadingCbz
bool CbxEngineImpl::FinishLoadingCbz()
{
fileExt = L".cbz";
Vec<const WCHAR *> allFileNames;
for (size_t idx = 0; idx < cbzFile->GetFileCount(); idx++) {
const WCHAR *fileName = cbzFile->GetFileName(idx);
// bail, if we accidentally try to load an XPS file
if (fileName && str::StartsWith(fileName, L"_rels/.rels"))
return false;
if (fileName && ImageEngine::IsSupportedFile(fileName) &&
// OS X occasionally leaves metadata with image extensions
!str::StartsWith(path::GetBaseName(fileName), L".")) {
allFileNames.Append(fileName);
}
else {
allFileNames.Append(NULL);
}
}
assert(allFileNames.Count() == cbzFile->GetFileCount());
ScopedMem<char> metadata(cbzFile->GetFileData(L"ComicInfo.xml"));
if (metadata)
ParseComicInfoXml(metadata);
metadata.Set(cbzFile->GetComment());
if (metadata)
json::Parse(metadata, this);
Vec<const WCHAR *> pageFileNames;
for (const WCHAR **fn = allFileNames.IterStart(); fn; fn = allFileNames.IterNext()) {
if (*fn)
pageFileNames.Append(*fn);
}
pageFileNames.Sort(cmpAscii);
for (const WCHAR **fn = pageFileNames.IterStart(); fn; fn = pageFileNames.IterNext()) {
fileIdxs.Append(allFileNames.Find(*fn));
}
assert(pageFileNames.Count() == fileIdxs.Count());
if (fileIdxs.Count() == 0)
return false;
pages.AppendBlanks(fileIdxs.Count());
mediaboxes.AppendBlanks(fileIdxs.Count());
return true;
}
开发者ID:Livit,项目名称:moonpdf,代码行数:47,代码来源:ImagesEngine.cpp
示例19: scope
char *CbxEngineImpl::GetImageData(int pageNo, size_t& len)
{
if (cbzFile) {
ScopedCritSec scope(&fileAccess);
return cbzFile->GetFileData(fileIdxs.At(pageNo - 1), &len);
}
return NULL;
}
开发者ID:Livit,项目名称:moonpdf,代码行数:8,代码来源:ImagesEngine.cpp
注:本文中的ZipFile类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论