I have added code from assest Manager class for Unzip Zip File
I am using unzGetGlobalInfo
if (unzGetGlobalInfo(zipfile, &global_info) != UNZ_OK)
in this method error is
Error expression preceding parentheses of apparent call must have (pointer-to-) function type
I got this Error with each method . unzClose , unzOpenCurrentFile , unzCloseCurrentFile
Here Some Piece of Code .
unzFile *zipfile = unzOpen(pathName.c_str());
if (!zipfile)
{
CCLOG("can not open downloaded zip file %s", pathName.c_str());
return;
}
unz_global_info global_info;
if (unzGetGlobalInfo(zipfile, &global_info) != UNZ_OK)
{
CCLOG("can not read file global info of %s", pathName.c_str());
unzClose(zipfile);
return;
}
unzGetCurrentFileInfo(zipfile, &global_info);
//Loop to extract all files
long i;
for (i = 0; i < global_info.number_entry; ++i)
{
unz_file_info file_info;
char filename[100];
if (unzGetCurrentFileInfo(
zipfile,
&file_info,
filename,
100,
NULL, 0, NULL, 0) != UNZ_OK)
{
CCLog("could not read file infon");
unzClose(zipfile);
return;
}
// Buffer to hold data read from the zip file.
char read_buffer[8192];
string str(filename);
if (str.find(".png") != string::npos || str.find(".gif") != string::npos){
CCLog("debug extracting file %s", filename);
// Check if this entry is a directory or file.
const size_t filename_length = strlen(filename);
if (filename[filename_length - 1] == '/')
{
// Entry is a directory, so create it.
printf("dir:%sn", filename);
}
else
{
//Entry is a file, so extract it.
CCLog("file:%sn", filename);
if (unzOpenCurrentFile(zipfile) != UNZ_OK)
{
CCLog("could not open filen");
unzClose(zipfile);
return;
}
// Open a file to write out the data.
string filepath = CCFileUtils::sharedFileUtils()->getWritablePath() + packageID + "_" + filename;
CCLog("%s", filepath.c_str());
FILE *out = fopen(filepath.c_str(), "wb");
if (out == NULL)
{
CCLog("could not open destination filen");
unzCloseCurrentFile(zipfile);
unzClose(zipfile);
return;
}
else
{
int error = UNZ_OK;
do
{
error = unzReadCurrentFile(zipfile, read_buffer, READ_SIZE);
if (error < 0)
{
printf("error %dn", error);
unzCloseCurrentFile(zipfile);
unzClose(zipfile);
return;
}
// Write data to file.
if (error > 0)
{
int dbuf = fwrite(read_buffer, error, 1, out); // You should check return of fwrite...
CCLog("debug bytes written %d %s", dbuf, filename);
}
} while (error > 0);
fclose(out);
}
}
unzCloseCurrentFile(zipfile);
// Go the the next entry listed in the zip file.
if ((i + 1) < global_info.number_entry)
{
if (unzGoToNextFile(zipfile) != UNZ_OK)
{
printf("cound not read next filen");
unzClose(zipfile);
return;
}
}
}
unzClose(zipfile);
Plz help
