Hi all,
i am generating a zip file using sharp zip lib in c# window application. this zip file is password protected. now i want to unzip this file using the mini zip library on ios7 but when i try to extract it using the password it show bad or corrupted file in the ios. however if i normally extract the zip file on ios without any programming it extract fine and all the files extract successfully.
does any one know why this happens.?
C# code to generate zip file
string[] filenames = Directory.GetFiles(sTargetFolderPath);
using (ZipOutputStream s = new ZipOutputStream(File.Create(txtSaveTo.Text + "\\" + "99999_Ravi.Khoda" + ".zip")))
{
s.SetLevel(9);
byte[] buffer = new byte[4096];
foreach (string file in filenames)
{
ZipEntry entry = new ZipEntry(Path.GetFileName(file));
entry.DateTime = DateTime.Now;
s.PutNextEntry(entry);
using (FileStream fs = File.OpenRead(file))
{
int sourceBytes;
do
{
sourceBytes = fs.Read(buffer, 0, buffer.Length);
s.Write(buffer, 0, sourceBytes);
} while (sourceBytes > 0);
}
}
s.Finish();
s.Close();
}
lblUpdate.Visible = false;
System.IO.Directory.Delete(txtSaveTo.Text + "\\TempZipFile\\", true);
MessageBox.Show("Zip file " + txtSaveTo.Text + " created.");
lstFilePaths.Items.Clear();
txtSaveTo.Text = string.Empty;
txtAddFile.Text = string.Empty;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString(), "Zip Operation Error");
}
c code to extract a file using minizip on ios
local unzFile unzOpenInternal (const void *path,
zlib_filefunc64_32_def* pzlib_filefunc64_32_def,
int is64bitOpenFunction)
{
unz64_s us;
unz64_s *s;
ZPOS64_T central_pos;
uLong uL;
uLong number_disk;
uLong number_disk_with_CD;
ZPOS64_T number_entry_CD;
int err=UNZ_OK;
if (unz_copyright[0]!=' ')
return NULL;
us.z_filefunc.zseek32_file = NULL;
us.z_filefunc.ztell32_file = NULL;
if (pzlib_filefunc64_32_def==NULL)
fill_fopen64_filefunc(&us.z_filefunc.zfile_func64);
else
us.z_filefunc = *pzlib_filefunc64_32_def;
us.is64bitOpenFunction = is64bitOpenFunction;
us.filestream = ZOPEN64(us.z_filefunc,
path,
ZLIB_FILEFUNC_MODE_READ |
ZLIB_FILEFUNC_MODE_EXISTING);
if (us.filestream==NULL)
return NULL;
central_pos = unz64local_SearchCentralDir64(&us.z_filefunc,us.filestream);
if (central_pos)
{
uLong uS;
ZPOS64_T uL64;
us.isZip64 = 1;
if (ZSEEK64(us.z_filefunc, us.filestream,
central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0)
err=UNZ_ERRNO;
if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
err=UNZ_ERRNO;
if (unz64local_getLong64(&us.z_filefunc, us.filestream,&uL64)!=UNZ_OK)
err=UNZ_ERRNO;
if (unz64local_getShort(&us.z_filefunc, us.filestream,&uS)!=UNZ_OK)
err=UNZ_ERRNO;
if (unz64local_getShort(&us.z_filefunc, us.filestream,&uS)!=UNZ_OK)
err=UNZ_ERRNO;
if (unz64local_getLong(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK)
err=UNZ_ERRNO;
if (unz64local_getLong(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK)
err=UNZ_ERRNO;
if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.gi.number_entry)!=UNZ_OK)
err=UNZ_ERRNO;
if (unz64local_getLong64(&us.z_filefunc, us.filestream,&number_entry_CD)!=UNZ_OK)
err=UNZ_ERRNO;
if ((number_entry_CD!=us.gi.number_entry) ||
(number_disk_with_CD!=0) ||
(number_disk!=0))
err=UNZ_BADZIPFILE;
if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.size_central_dir)!=UNZ_OK)
err=UNZ_ERRNO;
if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.offset_central_dir)!=UNZ_OK)
err=UNZ_ERRNO;
us.gi.size_comment = 0;
}
else
{
central_pos = unz64local_SearchCentralDir(&us.z_filefunc,us.filestream);
if (central_pos==0)
err=UNZ_ERRNO;
us.isZip64 = 0;
if (ZSEEK64(us.z_filefunc, us.filestream,
central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0)
err=UNZ_ERRNO;
if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
err=UNZ_ERRNO;
if (unz64local_getShort(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK)
err=UNZ_ERRNO;
if (unz64local_getShort(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK)
err=UNZ_ERRNO;
if (unz64local_getShort(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
err=UNZ_ERRNO;
us.gi.number_entry = uL;
if (unz64local_getShort(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
err=UNZ_ERRNO;
number_entry_CD = uL;
if ((number_entry_CD!=us.gi.number_entry) ||
(number_disk_with_CD!=0) ||
(number_disk!=0))
err=UNZ_BADZIPFILE;
if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
err=UNZ_ERRNO;
us.size_central_dir = uL;
if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
err=UNZ_ERRNO;
us.offset_central_dir = uL;
if (unz64local_getShort(&us.z_filefunc, us.filestream,&us.gi.size_comment)!=UNZ_OK)
err=UNZ_ERRNO;
}
if ((central_pos<us.offset_central_dir+us.size_central_dir) &&
(err==UNZ_OK))
err=UNZ_BADZIPFILE;
if (err!=UNZ_OK)
{
ZCLOSE64(us.z_filefunc, us.filestream);
return NULL;
}
us.byte_before_the_zipfile = central_pos -
(us.offset_central_dir+us.size_central_dir);
us.central_pos = central_pos;
us.pfile_in_zip_read = NULL;
us.encrypted = 0;
s=(unz64_s*)ALLOC(sizeof(unz64_s));
if( s != NULL)
{
*s=us;
unzGoToFirstFile((unzFile)s);
}
return (unzFile)s;
}