Ejemplo n.º 1
0
    public static void SynchroUnzip(string zipPath, string destPath)
    {
        ZipInputStream zip = new ZipInputStream(File.OpenRead(zipPath));
        ZipEntry       theEntry;
        int            curUnzipCount = 0;

        while ((theEntry = zip.GetNextEntry()) != null)
        {
            curUnzipCount++;
            string theEntryName = theEntry.Name.Replace("\\", "/");
            if (theEntry.IsFile)
            {
                byte[] bytesBuffer = new byte[theEntry.Size];
                int    i           = zip.Read(bytesBuffer, 0, bytesBuffer.Length);
                string entryPath   = Path.Combine(destPath, theEntryName);
                GetFilePath(entryPath);
                FileStream fs = File.Create(entryPath);
                fs.Write(bytesBuffer, 0, i);
                fs.Close();
                fs.Dispose();
            }
            else if (theEntry.IsDirectory)
            {
                string dirPath = Path.Combine(destPath, theEntryName);
                GetFilePath(dirPath);
            }
        }
        zip.Close();
        zip.Dispose();
    }
Ejemplo n.º 2
0
        // Constructor
        public PK3Reader(DataLocation dl) : base(dl)
        {
            General.WriteLogLine("Opening PK3 resource '" + location.location + "'");

            // Open the zip file
            ZipInputStream zipstream = OpenPK3File();

            // Make list of all files
            List <DirectoryFileEntry> fileentries = new List <DirectoryFileEntry>();
            ZipEntry entry = zipstream.GetNextEntry();

            while (entry != null)
            {
                if (entry.IsFile)
                {
                    fileentries.Add(new DirectoryFileEntry(entry.Name));
                }

                // Next
                entry = zipstream.GetNextEntry();
            }

            // Make files list
            files = new DirectoryFilesList(fileentries);

            // Done with the zip file
            zipstream.Close();
            zipstream.Dispose();

            // Initialize without path (because we use paths relative to the PK3 file)
            Initialize();

            // We have no destructor
            GC.SuppressFinalize(this);
        }
Ejemplo n.º 3
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         _zipStream.Dispose();
     }
 }
Ejemplo n.º 4
0
        private static bool InitializeIcuData()
        {
            var            icuDir = CustomIcu.DefaultDataDirectory;
            ZipInputStream zipIn  = null;

            try
            {
                try
                {
                    var baseDir = FwDirectoryFinder.DataDirectory;
                    zipIn = new ZipInputStream(File.OpenRead(Path.Combine(baseDir, string.Format("Icu{0}.zip", CustomIcu.Version))));
                }
                catch (Exception e1)
                {
                    Assert.Fail("Something is wrong with the file you chose." + Environment
                                .NewLine +
                                " The file could not be opened. " + Environment.NewLine + Environment.NewLine +
                                "   The error message was: '" + e1.Message);
                }
                if (zipIn == null)
                {
                    return(false);
                }
                Wrapper.Cleanup();
                foreach (string dir in Directory.GetDirectories(icuDir))
                {
                    string subdir = Path.GetFileName(dir);
                    if (subdir.Equals(string.Format("icudt{0}l", CustomIcu.Version),
                                      StringComparison.OrdinalIgnoreCase))
                    {
                        Directory.Delete(dir, true);
                    }
                }
                ZipEntry entry;
                while ((entry = zipIn.GetNextEntry()) != null)
                {
                    string dirName = Path.GetDirectoryName(entry.Name);
                    Match  match   = Regex.Match(dirName, @"^ICU\d\d[\\/]?(.*)$", RegexOptions.IgnoreCase);
                    if (match.Success)                     // Zip file was built in a way that includes the root directory name.
                    {
                        dirName = match.Groups[1].Value;   // Strip it off. May leave empty string.
                    }
                    string fileName = Path.GetFileName(entry.Name);
                    bool   fOk      = UnzipFile(zipIn, fileName, entry.Size, Path.Combine(icuDir, dirName));
                    if (!fOk)
                    {
                        return(false);
                    }
                }
                return(true);
            }
            finally
            {
                if (zipIn != null)
                {
                    zipIn.Dispose();
                }
            }
        }
Ejemplo n.º 5
0
    /// <summary>
    /// 解压文件
    /// </summary>
    /// <param name="file">要解压的文件</param>
    /// <param name="outPath">解压后输出路径</param>
    public static void UnZip(string file, string outPath)
    {
        if (!Directory.Exists(outPath))
        {
            Directory.CreateDirectory(outPath);
        }
        ZipInputStream s     = new ZipInputStream(File.OpenRead(file));
        ZipEntry       entry = null;

        while ((entry = s.GetNextEntry()) != null)
        {
            #region   照压缩前的文件夹解压
            //string fileName = Path.GetFileName(entry.Name);
            //string filePath = Path.Combine(outPath, entry.Name);
            // string directoryName = Path.GetDirectoryName(filePath);
            //if (!string.IsNullOrEmpty(directoryName))
            //{
            //    Directory.CreateDirectory(directoryName);
            //}
            #endregion

            //统一解压到一个文件夹下
            string fileName = Path.GetFileName(entry.Name);
            string filePath = Path.Combine(outPath, fileName);

            if (!string.IsNullOrEmpty(fileName))
            {
                try
                {
                    if (File.Exists(filePath))
                    {
                        File.Delete(filePath);
                    }
                    FileStream streamWriter = File.Create(filePath);
                    int        size         = 2048;
                    byte[]     data         = new byte[size];
                    while (size > 0)
                    {
                        size = s.Read(data, 0, data.Length);
                        if (size > 0)
                        {
                            streamWriter.Write(data, 0, size);
                        }
                    }
                    streamWriter.Close();
                    streamWriter.Dispose();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
        File.Delete(file);
        s.Close();
        s.Dispose();
        s     = null;
        entry = null;
    }
Ejemplo n.º 6
0
        public string ExtractZipFiles(string zipFilePath, string destinationFolderPath)
        {
            var    s          = new ZipInputStream(File.OpenRead(zipFilePath));
            string returnpath = "";

            try
            {
                ZipEntry theEntry;
                int      i = 0;
                while ((theEntry = s.GetNextEntry()) != null)
                {
                    string directoryName = Path.GetDirectoryName(theEntry.Name);
                    string fileName      = Path.GetFileName(theEntry.Name);
                    Directory.CreateDirectory(destinationFolderPath + "\\" + directoryName);
                    if (i == 0)
                    {
                        i++;
                        returnpath = Directory.GetParent(destinationFolderPath + "\\" + directoryName).FullName;
                    }

                    if (fileName != String.Empty)
                    {
                        FileStream streamWriter = File.Create(destinationFolderPath + "\\" + theEntry.Name);
                        try
                        {
                            long   collectiveSize = 0;
                            int    size           = 2048;
                            byte[] data           = new byte[2048];
                            while (true)
                            {
                                size            = s.Read(data, 0, data.Length);
                                collectiveSize += size;
                                if (size > 0 && collectiveSize <= theEntry.Size)
                                {
                                    streamWriter.Write(data, 0, size);
                                }
                                else
                                {
                                    break;
                                }
                            }
                        }
                        finally
                        {
                            streamWriter.Close();
                            streamWriter.Dispose();
                        }
                    }
                }
            }
            finally
            {
                s.Close();
                s.Dispose();
            }

            return(returnpath);
        }
Ejemplo n.º 7
0
        private static bool InitializeIcuData()
        {
            var            icuDir = Icu.DefaultDirectory;
            ZipInputStream zipIn  = null;

            try
            {
                try
                {
                    var baseDir = DirectoryFinder.FWDataDirectory;
                    zipIn = new ZipInputStream(File.OpenRead(Path.Combine(baseDir, "Icu50.zip")));
                }
                catch (Exception e1)
                {
                    MessageBoxUtils.Show("Something is wrong with the file you chose." + Environment.NewLine +
                                         " The file could not be opened. " + Environment.NewLine + Environment.NewLine +
                                         "   The error message was: '" + e1.Message);
                }
                if (zipIn == null)
                {
                    return(false);
                }
                Icu.Cleanup();
                foreach (var dir in Directory.GetDirectories(icuDir))
                {
                    var subdir = Path.GetFileName(dir).ToLowerInvariant();
                    if (subdir == "data" ||
                        (subdir.StartsWith("icudt") && subdir.EndsWith("l")))
                    {
                        Directory.Delete(dir, true);
                    }
                }
                ZipEntry entry;
                while ((entry = zipIn.GetNextEntry()) != null)
                {
                    var dirName = Path.GetDirectoryName(entry.Name);
                    var match   = new Regex(@"^ICU\d\d[\\/]?(.*)$").Match(dirName);
                    if (match.Success)                     // Zip file was built in a way that includes the root directory name.
                    {
                        dirName = match.Groups[1].Value;   // Strip it off. May leave empty string.
                    }
                    var fileName = Path.GetFileName(entry.Name);
                    var fOk      = UnzipFile(zipIn, fileName, entry.Size, Path.Combine(icuDir, dirName));
                    if (!fOk)
                    {
                        return(false);
                    }
                }
                return(true);
            }
            finally
            {
                if (zipIn != null)
                {
                    zipIn.Dispose();
                }
            }
        }
Ejemplo n.º 8
0
 /// <summary>
 ///
 /// </summary>
 public override void Unload()
 {
     if (_zipStream != null)
     {
         _zipStream.Close();
         _zipStream.Dispose();
         _zipStream = null;
     }
 }
Ejemplo n.º 9
0
 protected override void Dispose(bool disposing)
 {
     if (_zipStream != null)
     {
         _zipStream.Close();
         _zipStream.Dispose();
         _zipStream = null;
     }
 }
Ejemplo n.º 10
0
        /// <summary>
        /// zip解压文件
        /// </summary>
        /// <param name="unPackToPath">解压到哪个绝对路径下</param>
        /// <param name="packFilePath">要解压的文件的路径</param>
        /// <param name="packFileName">要解压的文件名</param>
        /// <returns></returns>
        public static bool UnZip(string unPackToPath, string packFilePath, string packFileName)
        {
            try
            {
                if (!Directory.Exists(unPackToPath))
                {
                    Directory.CreateDirectory(unPackToPath);
                }
                string         filePath = Path.Combine(packFilePath, packFileName);
                ZipInputStream zstream  = new ZipInputStream(File.OpenRead(filePath));
                ZipEntry       entry;
                while ((entry = zstream.GetNextEntry()) != null)
                {
                    if (!string.IsNullOrEmpty(entry.Name))
                    {
                        string upath = Path.Combine(unPackToPath, entry.Name);
                        if (entry.IsDirectory && !Directory.Exists(upath))
                        {
                            Directory.CreateDirectory(upath);
                        }
                        else if (entry.Name.Contains("\\"))
                        {
                            string   tmp_path = unPackToPath;
                            string[] sss      = entry.Name.Split('\\');

                            int count = sss.Length;
                            for (int i = 0; i < count - 1; i++)
                            {
                                tmp_path = Path.Combine(tmp_path, sss[i]);
                                if (!Directory.Exists(tmp_path))
                                {
                                    Directory.CreateDirectory(tmp_path);
                                }
                            }
                            if (entry.CompressedSize > 0)
                            {
                                GenerateFile(zstream, upath);
                            }
                        }
                        else if (entry.CompressedSize > 0)
                        {
                            GenerateFile(zstream, upath);
                        }
                    }
                }
                zstream.Dispose();
                zstream.Close();
                return(true);
            }
            catch
            {
                throw;
            }
        }
Ejemplo n.º 11
0
        ///
        /// 解壓縮檔案
        ///
        ///解壓縮檔案目錄路徑
        ///密碼
        public void UnZipFiles(string path, string password)
        {
            ZipInputStream zis = null;

            try
            {
                string unZipPath = path.Replace(".zip", "");
                CreateDirectory(unZipPath);
                zis = new ZipInputStream(File.OpenRead(path));
                if (password != null && password != string.Empty)
                {
                    zis.Password = password;
                }
                ZipEntry entry;

                while ((entry = zis.GetNextEntry()) != null)
                {
                    string filePath = unZipPath + @"\" + entry.Name;

                    if (entry.Name != "")
                    {
                        FileStream fs     = File.Create(filePath);
                        int        size   = 2048;
                        byte[]     buffer = new byte[2048];
                        while (true)
                        {
                            size = zis.Read(buffer, 0, buffer.Length);
                            if (size > 0)
                            {
                                fs.Write(buffer, 0, size);
                            }
                            else
                            {
                                break;
                            }
                        }

                        fs.Close();
                        fs.Dispose();
                    }
                }
            }

            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            finally
            {
                zis.Close();
                zis.Dispose();
            }
        }
Ejemplo n.º 12
0
 public static void UnZipFile(Stream ms, string unZipDir, string password, bool overWrite)
 {
     if (ms == null)
     {
         Debug.LogError("解压流为null");
         return;
     }
     using (ZipInputStream zipInputStream = new ZipInputStream(ms))
     {
         zipInputStream.set_Password(password);
         ZipEntry nextEntry;
         while ((nextEntry = zipInputStream.GetNextEntry()) != null)
         {
             string text          = nextEntry.get_Name().Replace("\\", "/");
             string directoryName = Path.GetDirectoryName(text);
             if (directoryName != null)
             {
                 string text2 = Path.Combine(unZipDir, directoryName);
                 if (!Directory.Exists(text2))
                 {
                     Directory.CreateDirectory(text2);
                 }
             }
             if (text != null)
             {
                 string text3 = Path.Combine(unZipDir, text).Replace("\\", "/");
                 if (!File.Exists(text3) || overWrite)
                 {
                     using (FileStream fileStream = File.Create(text3))
                     {
                         int    num   = 1048576;
                         byte[] array = new byte[num];
                         while (true)
                         {
                             num = zipInputStream.Read(array, 0, array.Length);
                             if (num <= 0)
                             {
                                 break;
                             }
                             fileStream.Write(array, 0, num);
                         }
                         fileStream.Close();
                         fileStream.Dispose();
                     }
                 }
             }
         }
         zipInputStream.Close();
         zipInputStream.Dispose();
     }
     ms.Close();
     ms.Dispose();
     ms = null;
 }
Ejemplo n.º 13
0
        // This loads an entire file in memory and returns the stream
        // NOTE: Callers are responsible for disposing the stream!
        protected override MemoryStream LoadFile(string filename)
        {
            MemoryStream filedata = null;

            byte[] copybuffer = new byte[4096];

            // Open the zip file
            ZipInputStream zipstream = OpenPK3File();

            ZipEntry entry = zipstream.GetNextEntry();

            while (entry != null)
            {
                if (entry.IsFile)
                {
                    string entryname = entry.Name.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);

                    // Is this the entry we are looking for?
                    if (string.Compare(entryname, filename, true) == 0)
                    {
                        int expectedsize = (int)entry.Size;
                        if (expectedsize < 1)
                        {
                            expectedsize = 1024;
                        }
                        filedata = new MemoryStream(expectedsize);
                        int readsize = zipstream.Read(copybuffer, 0, copybuffer.Length);
                        while (readsize > 0)
                        {
                            filedata.Write(copybuffer, 0, readsize);
                            readsize = zipstream.Read(copybuffer, 0, copybuffer.Length);
                        }
                        break;
                    }
                }

                // Next
                entry = zipstream.GetNextEntry();
            }

            // Done with the zip file
            zipstream.Close();
            zipstream.Dispose();

            // Nothing found?
            if (filedata == null)
            {
                throw new FileNotFoundException("Cannot find the file \"" + filename + "\" in ZIP file " + location.location + ".");
            }
            else
            {
                return(filedata);
            }
        }
Ejemplo n.º 14
0
        //在zip中加载AssetBundle
        private async Task <MemoryStream> LoadAssetBundleToMemoryInZipAsync()
        {
            ZipInputStream zip = ZipUtils.OpenZipFile(FilePath);
            ZipEntry       theEntry;

            while ((theEntry = zip.GetNextEntry()) != null)
            {
                if (theEntry.Name == "Level.assetbundle" ||
                    theEntry.Name == "/Level.assetbundle")
                {
                    MemoryStream ms = await ZipUtils.ReadZipFileToMemoryAsync(zip);

                    zip.Close();
                    zip.Dispose();
                    return(ms);
                }
            }
            zip.Close();
            zip.Dispose();
            return(null);
        }
Ejemplo n.º 15
0
        private long GetZipBytes(byte[] ZipByte)
        {
            long           num            = 0;
            ZipInputStream zipInputStream = new ZipInputStream((Stream) new MemoryStream(ZipByte));

            while ((this.ent = zipInputStream.GetNextEntry()) != null)
            {
                num += this.ent.Size;
            }
            zipInputStream.Close();
            zipInputStream.Dispose();
            return(num);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Releases the unmanaged resources used by the <see cref="T:System.IO.Stream"/> and optionally releases the managed resources.
        /// </summary>
        /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (_zipStream != null)
                {
                    _zipStream.Dispose();
                }

                _zipStream = null;
            }

            base.Dispose(disposing);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// 解压功能(解压压缩文件到指定目录)
        /// </summary>
        /// <param name="fileToUnZip">待解压的文件</param>
        /// <param name="zipedFolder">指定解压目标目录</param>
        /// <param name="password">密码</param>
        /// <returns>解压结果</returns>
        public static bool UnZipGetFirstText(Stream inputZipStream, out string content)
        {
            bool result = true;

            content = string.Empty;
            ZipInputStream zipStream = null;
            ZipEntry       ent       = null;

            try
            {
                inputZipStream.Seek(0, SeekOrigin.Begin);
                zipStream = new ZipInputStream(inputZipStream);
                if ((ent = zipStream.GetNextEntry()) != null)
                {
                    using (StreamReader sr = new StreamReader(zipStream))
                    {
                        content = sr.ReadToEnd();
                    }
                    //int size = 2048;
                    //byte[] data = new byte[size];
                    //while (true)
                    //{
                    //    size = zipStream.Read(data, 0, data.Length);
                    //    if (size > 0)
                    //        fs.Write(data, 0, data.Length);
                    //    else
                    //        break;
                    //}
                }
            }
            catch
            {
                result = false;
            }
            finally
            {
                if (zipStream != null)
                {
                    zipStream.Close();
                    zipStream.Dispose();
                }
                if (ent != null)
                {
                    ent = null;
                }
                GC.Collect();
                GC.Collect(1);
            }
            return(result);
        }
Ejemplo n.º 18
0
        private long GetZipBytes(byte[] ZipByte)
        {
            long           zipSize   = 0;
            Stream         lenStream = new MemoryStream(ZipByte);
            ZipInputStream lenzip    = new ZipInputStream(lenStream);

            while ((ent = lenzip.GetNextEntry()) != null)
            {
                zipSize += ent.Size;
            }
            lenzip.Close();
            lenzip.Dispose();
            return(zipSize);
        }
Ejemplo n.º 19
0
        private static void UnZip(string fileFromUnZip, string fileToUnZip)
        {
            ZipInputStream inputStream = new
                                         ZipInputStream(File.OpenRead(fileFromUnZip));

            try
            {
                ZipEntry theEntry;
                while ((theEntry = inputStream.GetNextEntry()) != null)
                {
                    fileToUnZip += "/";
                    string fileName = Path.GetFileName(theEntry.Name);
                    string path     = Path.GetDirectoryName(fileToUnZip) + "/";
                    //if (File.Exists(path + fileName))
                    //{
                    //    File.Delete(path + fileName);
                    //}
                    // Directory.CreateDirectory(path);//生成解压目录                 if (fileName != String.Empty)                 { 
                    FileStream streamWriter = File.Create(path + fileName); //解压文件到指定的目录  
                    try
                    {
                        int    size = 2048;
                        byte[] data = new byte[size];
                        while (true)
                        {
                            size = inputStream.Read(data, 0, data.Length);
                            if (size > 0)
                            {
                                streamWriter.Write(data, 0, size);
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                    finally
                    {
                        streamWriter.Close();
                        streamWriter.Dispose();
                    }
                }
            }
            finally
            {
                inputStream.Close();
                inputStream.Dispose();
            }
        }
Ejemplo n.º 20
0
        //加载基础信息
        private bool LoadBaseInfo()
        {
            bool hasDefFile = false;

            //在zip中加载LevelDef
            ZipInputStream zip = ZipUtils.OpenZipFile(FilePath);
            ZipEntry       theEntry;

            while ((theEntry = zip.GetNextEntry()) != null)
            {
                if (theEntry.Name == "/LevelDef.xml" || theEntry.Name == "LevelDef.xml")
                {
                    hasDefFile = true;
                    LoadLevelDefInZip(zip, theEntry);
                }
                else if (theEntry.Name == "/" + Logo || theEntry.Name == Logo)
                {
                    LoadLogoInZip(zip, theEntry);
                }
            }
            zip.Close();
            zip.Dispose();

            if (!hasDefFile)
            {
                GameLogger.Error(TAG, "加载模组包失败,未找到 LevelDef.xml");
                GameErrorManager.LastError = GameError.InitializationFailed;

                LoadStatus = GameModStatus.InitializeFailed;
                LoadError  = "未找到 ModDef.xml";

                return(false);
            }

            //检查兼容性
            if (LevelCompatibilityInfo.MinVersion > GameConst.GameBulidVersion)
            {
                GameLogger.Error(TAG, "加载模组包失败,关卡与游戏版本不兼容");
                GameErrorManager.LastError = GameError.BadMod;

                LoadStatus = GameModStatus.BadMod;
                LoadError  = "关卡与游戏版本不兼";

                return(false);
            }

            return(true);
        }
Ejemplo n.º 21
0
    public void ExcuteUnzip(string zipPath, string destPath)
    {
        int    UpdateRegisterClassStr = AutherFile.GetStringHash("UpdateUI/UpdateRegisterClass.txt");
        int    UpdateConfigStr        = AutherFile.GetStringHash("Utils/UpdateConfig.txt");
        int    UpdateControllerStr    = AutherFile.GetStringHash("Utils/UpdateController.txt");
        Thread thread = new Thread(delegate()
        {
            try
            {
                unZipIng        = true;
                ZipFile z       = new ZipFile(zipPath);
                long unZipCount = z.Count;
                z.Close();
                ZipInputStream zip = new ZipInputStream(File.OpenRead(zipPath));
                ZipEntry theEntry;
                int curUnzipCount = 0;
                while ((theEntry = zip.GetNextEntry()) != null)
                {
                    int theEntryName = int.Parse(theEntry.Name);
                    if (theEntry.IsFile)
                    {
                        byte[] bytesBuffer = new byte[theEntry.Size];
                        int i = zip.Read(bytesBuffer, 0, bytesBuffer.Length);
                        AutherFile.PutData(theEntryName, bytesBuffer);
                        if (theEntryName.Equals(UpdateRegisterClassStr) || theEntryName.Equals(UpdateConfigStr) ||
                            theEntryName.Equals(UpdateControllerStr))
                        {
                            existsUpdateLua = true;
                        }
                        Debug.Log("PutData " + theEntryName);
                    }
                    curUnzipCount++;
                    progress = (float)curUnzipCount / unZipCount;
                }
                zip.Close();
                zip.Dispose();
                unZipSuccess = true;
                unZipIng     = false;
            }
            catch (Exception e)
            {
                isError = true;
                Debug.Log(e.Message);
            }
        });

        thread.Start();
    }
Ejemplo n.º 22
0
        private static ExcelCotnent GetTempletContent()
        {
            ExcelCotnent   content   = new ExcelCotnent();
            MemoryStream   stream    = new MemoryStream(Properties.Resources.ExportTemplet);
            ZipInputStream zipstream = new ZipInputStream(stream);

            try
            {
                Heren.Common.ZipLib.Zip.ZipEntry entry = zipstream.GetNextEntry();
                while (entry != null)
                {
                    if (entry.Name == "xl/workbook.xml")
                    {
                        content.WorkbookContent = GlobalMethods.Xml.GetXmlDocument(zipstream);
                    }
                    else if (entry.Name == "xl/sharedStrings.xml")
                    {
                        content.SharedStringsContent = GlobalMethods.Xml.GetXmlDocument(zipstream);
                    }
                    else if (entry.Name == "xl/worksheets/sheet1.xml")
                    {
                        content.WorksheetsContent = GlobalMethods.Xml.GetXmlDocument(zipstream);
                    }
                    entry = zipstream.GetNextEntry();
                }

                XmlNode columnsNode = GetColumnsNode(content);
                columnsNode.RemoveAll();

                XmlNode rowsNode = GetRowsNode(content);
                rowsNode.RemoveAll();

                content.SharedStringsContent.DocumentElement.RemoveAll();
                return(content);
            }
            catch (Exception ex)
            {
                LogManager.Instance.WriteLog("GlobalMethods.ExportExcelFile", ex);
                return(null);
            }
            finally
            {
                zipstream.Close();
                zipstream.Dispose();
                stream.Close();
                stream.Dispose();
            }
        }
Ejemplo n.º 23
0
        private static Stream OpenFirstZipEntry(Stream rawStream)
        {
            var zipStream = new ZipInputStream(rawStream);

            try
            {
                zipStream = new ZipInputStream(rawStream);
                zipStream.GetNextEntry();
                return(zipStream);
            }
            catch
            {
                zipStream.Dispose();
                throw;
            }
        }
Ejemplo n.º 24
0
 private void AllDispose()
 {
     if (fs != null)
     {
         fs.Close();
         fs.Dispose();
     }
     if (zipStream != null)
     {
         zipStream.Close();
         zipStream.Dispose();
     }
     if (ent != null)
     {
         ent = null;
     }
     GC.Collect();
     GC.Collect(1);
 }
Ejemplo n.º 25
0
        private static void ResetUnCompress()
        {
            ResetUnCompressThread();

            if (m_ZipInputStream != null)
            {
                m_ZipInputStream.Close();
                m_ZipInputStream.Dispose();
                m_ZipInputStream = null;
            }

            if (m_inputStream != null)
            {
                m_inputStream.Close();
                m_inputStream.Dispose();
                m_inputStream = null;
            }

            ResetLocalFile();
        }
        public void ReadCompressedZip(string filepath)
        {
            while (BackgroundWriting)
            {
                ;
            }

            ZipInputStream  instream  = new ZipInputStream(filepath);
            BinaryFormatter formatter = new BinaryFormatter();

            instream.GetNextEntry();
            searchDump = new TCPTCPGecko.Dump((uint)formatter.Deserialize(instream), (uint)formatter.Deserialize(instream));
            instream.Read(searchDump.mem, 0, (int)(searchDump.EndAddress - searchDump.StartAddress));

            instream.GetNextEntry();
            resultsList = (System.Collections.Generic.List <UInt32>)formatter.Deserialize(instream);

            instream.Close();
            instream.Dispose();
        }
        public Dump LoadSearchDump(string filepath)
        {
            while (BackgroundWriting)
            {
                ;
            }

            ZipInputStream  instream  = new ZipInputStream(filepath);
            BinaryFormatter formatter = new BinaryFormatter();

            instream.GetNextEntry();
            Dump searchDump = new Dump((uint)formatter.Deserialize(instream), (uint)formatter.Deserialize(instream));

            instream.Read(searchDump.mem, 0, (int)(searchDump.EndAddress - searchDump.StartAddress));

            instream.Close();
            instream.Dispose();

            return(searchDump);
        }
        public List <uint> LoadSearchList(string filepath)
        {
            while (BackgroundWriting)
            {
                ;
            }

            ZipInputStream  instream  = new ZipInputStream(filepath);
            BinaryFormatter formatter = new BinaryFormatter();

            instream.GetNextEntry();

            instream.GetNextEntry();

            List <uint> searchList = (List <uint>)formatter.Deserialize(instream);

            instream.Close();
            instream.Dispose();

            return(searchList);
        }
Ejemplo n.º 29
0
        static public string UnZip(string target, string to, string password)
        {
            var filename = target.Split(':').ToArray();

            FileStream fileStreamIn = new FileStream(filename[0], FileMode.Open, FileAccess.Read);

            ZipInputStream zipInStream = new ZipInputStream(fileStreamIn)
            {
                Password = password
            };
            ZipEntry entry = zipInStream.GetNextEntry();

            do
            {
                if (entry.IsDirectory)
                {
                    CreateIfNotExist(to + entry.Name);
                }
                if (entry.Name != filename[1])
                {
                    continue;
                }
                if (File.Exists(to + filename[1]))
                {
                    return(to + filename[1]);
                }
                using FileStream fileStreamOut = new FileStream(to + filename[1], FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
                int    size   = 2048;
                byte[] buffer = new byte[2048];
                do
                {
                    size = zipInStream.Read(buffer, 0, buffer.Length);
                    fileStreamOut.Write(buffer, 0, size);
                } while (size > 0);
                return(to + filename[1]);
            } while ((entry = zipInStream.GetNextEntry()) != null);

            zipInStream.Dispose();
            return(null);
        }
Ejemplo n.º 30
0
 public static byte[] UnZipFiles(byte[] Data, string password)
 {
     try
     {
         byte[]       bufferArray = new byte[4096];
         MemoryStream inStream    = new MemoryStream(Data);
         using (var unzip = new ZipInputStream(inStream))
         {
             if (password != null && password != string.Empty)
             {
                 unzip.Password = password;
             }
             ZipEntry entry = unzip.GetNextEntry();
             using (var output = new MemoryStream())
             {
                 var readLength = 0;
                 while (true)
                 {
                     readLength = unzip.Read(bufferArray, 0, bufferArray.Length);
                     if (readLength > 0)
                     {
                         output.Write(bufferArray, 0, readLength);
                     }
                     else
                     {
                         break;
                     }
                 }
                 unzip.Close();
                 unzip.Dispose();
                 return(output.ToArray());
             }
         }
     }
     catch (Exception ex)
     {
         //Console.WriteLine(ex.Message);
         throw ex;
     }
 }