Esempio n. 1
0
        private long ExtractFromZip(string fName, string entryName, string destPath)
        {
            ZipFile zf = null;

            System.IO.Stream zp  = null;
            FileStream       fs  = null;
            ZipEntry         ze  = null;
            long             ret = -1;

            try
            {
                zf = new ZipFile(fName);
                ze = zf.GetEntry(entryName);
                zp = zf.GetInputStream(ze);

                string pt = destPath;
                pt += "\\" + entryName;
                if (CIO.FileExists(pt))
                {
                    CIO.blRemoveFile(pt);
                }
                fs = new FileStream(pt, FileMode.CreateNew);
                int bt;
                while (true)
                {
                    bt = zp.ReadByte();
                    if (bt < 0)
                    {
                        break;
                    }
                    fs.WriteByte(CConvert.ToByte(bt));
                }
                ret = ze.Size;
            }
            catch (Exception ex)
            {
                CLog.stLogException(new Exception("ExtractFromZip:", ex));
                ret = -1;
            }
            finally
            {
                if (zf != null)
                {
                    zf.Close();
                }
                if (zp != null)
                {
                    zp.Close();
                }
                if (fs != null)
                {
                    fs.Close();
                }
                CIO.blRemoveFile(fName);
            }
            return(ret);
        }