コード例 #1
0
        public ArquivoPdf[] DescomprimirBase64(byte[] ArquivosZip)
        {
            MemoryStream baseInputStream = new MemoryStream(ArquivosZip);

            ICSharpCode.SharpZipLib.Zip.ZipInputStream zipInputStream = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(baseInputStream);
            IList <ArquivoPdf> list = new List <ArquivoPdf>();

            ICSharpCode.SharpZipLib.Zip.ZipEntry nextEntry;
            while ((nextEntry = zipInputStream.GetNextEntry()) != null)
            {
                MemoryStream memoryStream = new MemoryStream();
                ArquivoPdf   arquivoPdf   = new ArquivoPdf();
                long         num          = nextEntry.Size;
                arquivoPdf.Nome = nextEntry.Name;
                byte[] array = new byte[1024];
                while (true)
                {
                    num = (long)zipInputStream.Read(array, 0, array.Length);
                    if (num <= 0L)
                    {
                        break;
                    }
                    memoryStream.Write(array, 0, (int)num);
                }
                memoryStream.Close();
                arquivoPdf.Dados = memoryStream.ToArray();
                list.Add(arquivoPdf);
            }
            return(list.ToArray <ArquivoPdf>());
        }
コード例 #2
0
        /// <summary>
        /// Unzip a local file and return its contents via streamreader:
        /// </summary>
        public static StreamReader UnzipStreamToStreamReader(Stream zipstream)
        {
            StreamReader reader = null;

            try
            {
                //Initialise:
                MemoryStream file;

                //If file exists, open a zip stream for it.
                using (var zipStream = new ZipInputStream(zipstream))
                {
                    //Read the file entry into buffer:
                    var entry  = zipStream.GetNextEntry();
                    var buffer = new byte[entry.Size];
                    zipStream.Read(buffer, 0, (int)entry.Size);

                    //Load the buffer into a memory stream.
                    file = new MemoryStream(buffer);
                }

                //Open the memory stream with a stream reader.
                reader = new StreamReader(file);
            }
            catch (Exception err)
            {
                Log.Error(err);
            }

            return(reader);
        } // End UnZip
コード例 #3
0
        /* Unzips dirName + ".zip" --> dirName, removing dirName
         * first */
        public virtual void  Unzip(System.String zipName, System.String destDirName)
        {
#if SHARP_ZIP_LIB
            // get zip input stream
            ICSharpCode.SharpZipLib.Zip.ZipInputStream zipFile;
            zipFile = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(System.IO.File.OpenRead(zipName + ".zip"));

            // get dest directory name
            System.String      dirName = FullDir(destDirName);
            System.IO.FileInfo fileDir = new System.IO.FileInfo(dirName);

            // clean up old directory (if there) and create new directory
            RmDir(fileDir.FullName);
            System.IO.Directory.CreateDirectory(fileDir.FullName);

            // copy file entries from zip stream to directory
            ICSharpCode.SharpZipLib.Zip.ZipEntry entry;
            while ((entry = zipFile.GetNextEntry()) != null)
            {
                System.IO.Stream streamout = new System.IO.BufferedStream(new System.IO.FileStream(new System.IO.FileInfo(System.IO.Path.Combine(fileDir.FullName, entry.Name)).FullName, System.IO.FileMode.Create));
                byte[]           buffer    = new byte[8192];
                int len;
                while ((len = zipFile.Read(buffer, 0, buffer.Length)) > 0)
                {
                    streamout.Write(buffer, 0, len);
                }

                streamout.Close();
            }

            zipFile.Close();
#else
            Assert.Fail("Needs integration with SharpZipLib");
#endif
        }
コード例 #4
0
        /// <summary>
        /// Decompresses the given data stream from its source ZIP or GZIP format.
        /// </summary>
        /// <param name="dataBytes"></param>
        /// <returns></returns>
        private static byte[] Inflate(byte[] dataBytes)
        {
            byte[] outputBytes    = null;
            var    zipInputStream =
                new ICSharpCode.SharpZipLib.Zip.ZipInputStream(new MemoryStream(dataBytes));

            if (zipInputStream.CanDecompressEntry)
            {
                MemoryStream zipoutStream = new MemoryStream();
#if XBOX
                byte[] buf = new byte[4096];
                int    amt = -1;
                while (true)
                {
                    amt = zipInputStream.Read(buf, 0, buf.Length);
                    if (amt == -1)
                    {
                        break;
                    }
                    zipoutStream.Write(buf, 0, amt);
                }
#else
                zipInputStream.CopyTo(zipoutStream);
#endif
                outputBytes = zipoutStream.ToArray();
            }
            else
            {
                try {
                    var gzipInputStream =
                        new ICSharpCode.SharpZipLib.GZip.GZipInputStream(new MemoryStream(dataBytes));


                    MemoryStream zipoutStream = new MemoryStream();

#if XBOX
                    byte[] buf = new byte[4096];
                    int    amt = -1;
                    while (true)
                    {
                        amt = gzipInputStream.Read(buf, 0, buf.Length);
                        if (amt == -1)
                        {
                            break;
                        }
                        zipoutStream.Write(buf, 0, amt);
                    }
#else
                    gzipInputStream.CopyTo(zipoutStream);
#endif
                    outputBytes = zipoutStream.ToArray();
                }
                catch (Exception exc)
                {
                    CCLog.Log("Error decompressing image data: " + exc.Message);
                }
            }

            return(outputBytes);
        }
コード例 #5
0
        public void UnZIP(string SourceFile, string DestPath, bool PreservePath, string[] ZipEntry)
        {
            FileStream fs = File.OpenRead(SourceFile);

            ICSharpCode.SharpZipLib.Zip.ZipInputStream s = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(fs);
            ICSharpCode.SharpZipLib.Zip.ZipEntry       theEntry;
            while ((theEntry = s.GetNextEntry()) != null)
            {
                if (theEntry.IsDirectory)
                {
                    continue;
                }

                if (null != ZipEntry && ZipEntry.Length > 0 && Array.BinarySearch(ZipEntry, Path.GetFileName(theEntry.Name), System.Collections.CaseInsensitiveComparer.Default) < 0)
                {
                    continue;
                }

                int    size = 2048;
                byte[] data = new byte[2048];

                string outputFileName = null;
                if (PreservePath)
                {
                    outputFileName = Path.Combine(DestPath, theEntry.Name);
                }
                else
                {
                    outputFileName = Path.Combine(DestPath, Path.GetFileName(theEntry.Name));
                }
                if (!Directory.Exists(Path.GetDirectoryName(outputFileName)))
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(outputFileName));
                }

                FileStream destFS = new FileStream(outputFileName, FileMode.Create);

                while (s.Available > 0)
                {
                    int readLen = s.Read(data, 0, size);
                    destFS.Write(data, 0, readLen);
                }
                destFS.Flush();
                destFS.Close();
            }
            s.Close();
        }
コード例 #6
0
ファイル: ZipUtils.cs プロジェクト: ahuinan/MyCode
 /// <summary>
 /// 解压缩(将压缩的文件解压到指定的文件夹下面)—解压到指定文件夹下面
 /// </summary>
 /// <param name="zipFilePath">源压缩的文件路径</param>
 /// <param name="savePath">解压后保存文件到指定的文件夹</param>
 public static void ZipUnFileInfo(string zipFilePath, string savePath)
 {
     try
     {
         using (var zipInputStream = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(File.OpenRead(zipFilePath)))
         {
             ICSharpCode.SharpZipLib.Zip.ZipEntry zipEntry;
             while ((zipEntry = zipInputStream.GetNextEntry()) != null)
             {
                 string directoryName = Path.GetDirectoryName(zipEntry.Name);
                 string fileName      = Path.GetFileName(zipEntry.Name);
                 string serverFolder  = savePath;
                 //创建一个文件目录信息
                 Directory.CreateDirectory(serverFolder + "/" + directoryName);
                 //如果解压的文件不等于空,则执行以下步骤
                 if (fileName != string.Empty)
                 {
                     using (FileStream fileStream = File.Create((serverFolder + "/" + zipEntry.Name)))
                     {
                         int    size = 2048;
                         byte[] data = new byte[2048]; //初始化字节数为2兆,后面根据需要解压的内容扩展字节数
                         while (true)
                         {
                             size = zipInputStream.Read(data, 0, data.Length);
                             if (size > 0)
                             {
                                 fileStream.Write(data, 0, size);
                             }
                             else
                             {
                                 break;
                             }
                         }
                         fileStream.Close();
                     }
                 }
             }
             zipInputStream.Close();
         }
     }
     catch (Exception exception)
     {
         throw new Exception("出现错误了,不能解压缩,错误原因:" + exception.Message);
     }
 }
コード例 #7
0
ファイル: UnZipUtil.cs プロジェクト: go886/LuaGame
        public static byte[] ReadEntry(string zipFileName, string entryname, string password = null)
        {
            try
            {
                SharpZipLib.Zip.ZipInputStream s = new SharpZipLib.Zip.ZipInputStream(File.OpenRead(zipFileName));
                s.Password = password;

                SharpZipLib.Zip.ZipEntry theEntry;
                if (!FindEntry(s, entryname, out theEntry))
                {
                    s.Close();
                    return(null);
                }
                byte[] buffer = null;
                using (MemoryStream mm = new MemoryStream())
                {
                    int    size = 2048;
                    byte[] data = new byte[2048];
                    while (true)
                    {
                        size = s.Read(data, 0, data.Length);
                        if (size > 0)
                        {
                            mm.Write(data, 0, size);
                        }
                        else
                        {
                            break;
                        }
                    }

                    buffer = mm.ToArray();
                    mm.Close();
                }

                s.Close();
                return(buffer);
            }
            catch (Exception e)
            {
                LogUtil.LogError(e.Message);
                return(null);
            }
        }
コード例 #8
0
        /// <summary>
        /// Разжатие
        /// </summary>
        /// <param name="ms"></param>
        /// <returns></returns>
        public static MemoryStream Decompress(MemoryStream ms)
        {
            ms.Seek(0, System.IO.SeekOrigin.Begin);

            ICSharpCode.SharpZipLib.Zip.ZipInputStream zs = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(ms);

            ICSharpCode.SharpZipLib.Zip.ZipEntry theEntry;

            try
            {
                theEntry = zs.GetNextEntry();
            }
            catch (Exception e)
            {
                return(ms);
            }


            MemoryStream resstream = new MemoryStream();


            //****
            byte[] data = new byte[4096];
            int    size;

            do
            {
                size = zs.Read(data, 0, data.Length);
                resstream.Write(data, 0, size);
            } while (size > 0);

            //*****

            //b = new byte[zs.Length];

            //zs.Read(b,0,b.Length);

            //resstream.Write(b,0,b.Length);

            resstream.Seek(0, SeekOrigin.Begin);
            zs.Close();
            return(resstream);
        }
コード例 #9
0
ファイル: clsCompactacao.cs プロジェクト: silvath/siscobras
        public void descompacta(string strNomeArquivoZip)
        {
            try
            {
                ICSharpCode.SharpZipLib.Zip.ZipInputStream clsZipInStream = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(System.IO.File.OpenRead(strNomeArquivoZip));

                ICSharpCode.SharpZipLib.Zip.ZipEntry theEntry;
                while ((theEntry = clsZipInStream.GetNextEntry()) != null)
                {
                    if (theEntry.Size > 0)
                    {
                        byte[] conteudoArquivo = new byte[theEntry.Size];
                        int    bytesReaded, posInFile = 0;
                        long   fileSize = theEntry.Size;

                        do
                        {
                            bytesReaded = clsZipInStream.Read(conteudoArquivo, posInFile, (int)fileSize);
                            posInFile  += bytesReaded;
                            fileSize   -= bytesReaded;
                        } while (fileSize > 0 || bytesReaded == 0);

                        if (bytesReaded > 0)
                        {
                            System.IO.FileStream   fsOutFile = new System.IO.FileStream(theEntry.Name, System.IO.FileMode.Create, System.IO.FileAccess.Write);
                            System.IO.BinaryWriter bwOutFile = new System.IO.BinaryWriter(fsOutFile);
                            bwOutFile.Write(conteudoArquivo);
                            bwOutFile.Flush();
                            bwOutFile.Close();
                            fsOutFile.Close();
                        }

                        conteudoArquivo = null;
                    }
                }
                clsZipInStream.Close();
            }
            catch (Exception err)
            {
                Object erro = err;
                m_cls_ter_tratadorErro.trataErro(ref erro);
            }
        }
コード例 #10
0
        private static string GetContentXml(System.IO.Stream fileStream)
        {
            string contentXml = "";

            using (ICSharpCode.SharpZipLib.Zip.ZipInputStream zipInputStream =
                       new ICSharpCode.SharpZipLib.Zip.ZipInputStream(fileStream))
            {
                ICSharpCode.SharpZipLib.Zip.ZipEntry contentEntry = null;
                while ((contentEntry = zipInputStream.GetNextEntry()) != null)
                {
                    if (!contentEntry.IsFile)
                    {
                        continue;
                    }

                    if (contentEntry.Name.ToLower() == "content.xml")
                    {
                        break;
                    }
                }

                if (contentEntry.Name.ToLower() != "content.xml")
                {
                    throw new System.Exception("Cannot find content.xml");
                }

                byte[] bytesResult = new byte[] { };
                byte[] bytes       = new byte[2000];
                int    i           = 0;

                while ((i = zipInputStream.Read(bytes, 0, bytes.Length)) != 0)
                {
                    int arrayLength = bytesResult.Length;
                    System.Array.Resize <byte>(ref bytesResult, arrayLength + i);
                    System.Array.Copy(bytes, 0, bytesResult, arrayLength, i);
                }

                contentXml = System.Text.Encoding.UTF8.GetString(bytesResult);
            }

            return(contentXml);
        }
コード例 #11
0
ファイル: Compression.cs プロジェクト: Capnode/Algoloop
        /// <summary>
        /// Uncompress zip data byte array into a dictionary string array of filename-contents.
        /// </summary>
        /// <param name="zipData">Byte data array of zip compressed information</param>
        /// <param name="encoding">Specifies the encoding used to read the bytes. If not specified, defaults to ASCII</param>
        /// <returns>Uncompressed dictionary string-sting of files in the zip</returns>
        public static Dictionary <string, string> UnzipData(byte[] zipData, Encoding encoding = null)
        {
            // Initialize:
            var data = new Dictionary <string, string>();

            try
            {
                using (var ms = new MemoryStream(zipData))
                {
                    //Read out the zipped data into a string, save in array:
                    using (var zipStream = new ZipInputStream(ms))
                    {
                        while (true)
                        {
                            //Get the next file
                            var entry = zipStream.GetNextEntry();

                            if (entry != null)
                            {
                                //Read the file into buffer:
                                var buffer = new byte[entry.Size];
                                zipStream.Read(buffer, 0, (int)entry.Size);

                                //Save into array:
                                var str = (encoding ?? Encoding.ASCII).GetString(buffer);
                                data.Add(entry.Name, str);
                            }
                            else
                            {
                                break;
                            }
                        }
                    } // End Zip Stream.
                }     // End Using Memory Stream
            }
            catch (Exception err)
            {
                Log.Error(err);
            }
            return(data);
        }
コード例 #12
0
ファイル: ZipUtils.cs プロジェクト: ahuinan/MyCode
 /// <summary>
 /// 解压缩—结果不包含文件夹
 /// </summary>
 /// <param name="zipFilePath">源压缩的文件路径</param>
 /// <param name="savePath">解压后的文件保存路径</param>
 public static void ZipUnFileWithOutFolderInfo(string zipFilePath, string savePath)
 {
     try
     {
         using (var zipInputStream = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(File.OpenRead(zipFilePath)))
         {
             ICSharpCode.SharpZipLib.Zip.ZipEntry zipEntry;
             while ((zipEntry = zipInputStream.GetNextEntry()) != null)
             {
                 string fileName = Path.GetFileName(zipEntry.Name);
                 if (fileName != string.Empty)
                 {
                     using (var fileStream = File.Create(savePath))
                     {
                         int    size = 2084; //初始化字节数为2兆,后面根据需要解压的内容扩展字节数
                         byte[] data = new byte[2048];
                         while (true)
                         {
                             size = zipInputStream.Read(data, 0, data.Length);
                             if (size > 0)
                             {
                                 fileStream.Write(data, 0, size);
                             }
                             else
                             {
                                 break;
                             }
                         }
                         fileStream.Close();
                     }
                 }
             }
             zipInputStream.Close();
         }
     }
     catch (Exception exception)
     {
         throw new Exception("解压缩出现错误了,错误原因:" + exception.Message);
     }
 }
コード例 #13
0
		// Uncomment these cases & run in a pre-lockless checkout
		// to create indices:
		
		/*
		public void testCreatePreLocklessCFS() throws IOException {
		CreateIndex("src/test/org/apache/lucene/index/index.prelockless.cfs", true);
		}
		
		public void testCreatePreLocklessNoCFS() throws IOException {
		CreateIndex("src/test/org/apache/lucene/index/index.prelockless.nocfs", false);
		}
		*/
		
		/* Unzips dirName + ".zip" --> dirName, removing dirName
		first */
		public virtual void  Unzip(System.String zipName, System.String destDirName)
		{
#if SHARP_ZIP_LIB
			// get zip input stream
			ICSharpCode.SharpZipLib.Zip.ZipInputStream zipFile;
			zipFile = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(System.IO.File.OpenRead(zipName + ".zip"));

			// get dest directory name
			System.String dirName = FullDir(destDirName);
			System.IO.FileInfo fileDir = new System.IO.FileInfo(dirName);

			// clean up old directory (if there) and create new directory
			RmDir(fileDir.FullName);
			System.IO.Directory.CreateDirectory(fileDir.FullName);

			// copy file entries from zip stream to directory
			ICSharpCode.SharpZipLib.Zip.ZipEntry entry;
			while ((entry = zipFile.GetNextEntry()) != null)
			{
				System.IO.Stream streamout = new System.IO.BufferedStream(new System.IO.FileStream(new System.IO.FileInfo(System.IO.Path.Combine(fileDir.FullName, entry.Name)).FullName, System.IO.FileMode.Create));
				
				byte[] buffer = new byte[8192];
				int len;
				while ((len = zipFile.Read(buffer, 0, buffer.Length)) > 0)
				{
					streamout.Write(buffer, 0, len);
				}
				
				streamout.Close();
			}
			
			zipFile.Close();
#else
			Assert.Fail("Needs integration with SharpZipLib");
#endif
		}
コード例 #14
0
        /// <summary> 解压数据 </summary>
        public static byte[] Decompress(Stream source)
        {
#if false//SCORPIO_UWP && !UNITY_EDITOR
            using (MemoryStream stream = new MemoryStream()) {
                System.IO.Compression.ZipArchive      zipStream = new System.IO.Compression.ZipArchive(source, System.IO.Compression.ZipArchiveMode.Read);
                System.IO.Compression.ZipArchiveEntry zipEntry  = zipStream.Entries[0];
                Stream entryStream = zipEntry.Open();
                int    count       = 0;
                byte[] data        = new byte[4096];
                while ((count = entryStream.Read(data, 0, data.Length)) != 0)
                {
                    stream.Write(data, 0, count);
                }
                zipStream.Dispose();
                byte[] ret = stream.ToArray();
                stream.Dispose();
                return(ret);
            }
#else
            using (MemoryStream stream = new MemoryStream()) {
                ICSharpCode.SharpZipLib.Zip.ZipInputStream zipStream = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(source);
                zipStream.GetNextEntry();
                int    count = 0;
                byte[] data  = new byte[4096];
                while ((count = zipStream.Read(data, 0, data.Length)) != 0)
                {
                    stream.Write(data, 0, count);
                }
                zipStream.Flush();
                byte[] ret = stream.ToArray();
                zipStream.Dispose();
                stream.Dispose();
                return(ret);
            }
#endif
        }
コード例 #15
0
ファイル: Compression.cs プロジェクト: nooperpudd/Lean
        /// <summary>
        /// Uncompress zip data byte array into a dictionary string array of filename-contents.
        /// </summary>
        /// <param name="zipData">Byte data array of zip compressed information</param>
        /// <returns>Uncompressed dictionary string-sting of files in the zip</returns>
        public static Dictionary<string, string> UnzipData(byte[] zipData)
        {
            // Initialize:
            var data = new Dictionary<string, string>();

            try
            {
                using (var ms = new MemoryStream(zipData))
                {
                    //Read out the zipped data into a string, save in array:
                    using (var zipStream = new ZipInputStream(ms))
                    {
                        while (true)
                        {
                            //Get the next file
                            var entry = zipStream.GetNextEntry();

                            if (entry != null)
                            {
                                //Read the file into buffer:
                                var buffer = new byte[entry.Size];
                                zipStream.Read(buffer, 0, (int)entry.Size);

                                //Save into array:
                                data.Add(entry.Name, buffer.GetString());
                            }
                            else
                            {
                                break;
                            }
                        }
                    } // End Zip Stream.
                } // End Using Memory Stream

            }
            catch (Exception err)
            {
                Log.Error("Data.UnzipData(): " + err.Message);
            }
            return data;
        }
コード例 #16
0
ファイル: Compression.cs プロジェクト: nooperpudd/Lean
        /// <summary>
        /// Unzip a local file and return its contents via streamreader:
        /// </summary>
        public static StreamReader UnzipStream(Stream zipstream)
        {
            StreamReader reader = null;
            try
            {
                //Initialise:
                MemoryStream file;

                //If file exists, open a zip stream for it.
                using (var zipStream = new ZipInputStream(zipstream))
                {
                    //Read the file entry into buffer:
                    var entry = zipStream.GetNextEntry();
                    var buffer = new byte[entry.Size];
                    zipStream.Read(buffer, 0, (int)entry.Size);

                    //Load the buffer into a memory stream.
                    file = new MemoryStream(buffer);
                }

                //Open the memory stream with a stream reader.
                reader = new StreamReader(file);
            }
            catch (Exception err)
            {
                Log.Error(err, "Data.UnZip(): Stream >> " + err.Message);
            }

            return reader;
        }
コード例 #17
0
ファイル: UnZipUtil.cs プロジェクト: go886/LuaGame
        //directory : end of "/" or "\\"
        public static bool UnZipDirectory(string zipFileName, string directory, string password = null, Action <string, float, long, long> cb = null)
        {
            try
            {
                /*if (!Directory.Exists(directory))
                 *  Directory.CreateDirectory(directory);
                 * directory = directory.Replace('\\', '/');
                 * if (directory.EndsWith("/"))
                 *  directory = directory.Substring(0, directory.Length - 1);
                 * SharpZipLib.Zip.FastZipEvents events = new SharpZipLib.Zip.FastZipEvents();
                 * events.Progress += (object sender, SharpZipLib.Core.ProgressEventArgs e) =>
                 * {
                 *  if(cb != null)
                 *  {
                 *      cb(e.Name, e.PercentComplete, e.Processed, e.Target);
                 *  }
                 *  else
                 *  {
                 *      LogUtil.Log("UnZip {0} {1}/{2}--{3}",e.Name, e.Processed, e.Target,e.PercentComplete);
                 *  }
                 * };
                 * SharpZipLib.Zip.FastZip fz = new SharpZipLib.Zip.FastZip(events);
                 * fz.Password = password;
                 * fz.ExtractZip(zipFileName,directory, SharpZipLib.Zip.FastZip.Overwrite.Always,null,null,null,true);
                 */
                if (!Directory.Exists(directory))
                {
                    Directory.CreateDirectory(directory);
                }

                SharpZipLib.Zip.ZipFile szip = new SharpZipLib.Zip.ZipFile(zipFileName);
                szip.Password = password;
                long count = szip.Count;
                szip.Close();

                SharpZipLib.Zip.ZipInputStream s = new SharpZipLib.Zip.ZipInputStream(File.OpenRead(zipFileName));
                s.Password = password;
                SharpZipLib.Zip.ZipEntry theEntry;
                int n = 0;
                while ((theEntry = s.GetNextEntry()) != null)
                {
                    string directoryName = Path.GetDirectoryName(theEntry.Name);
                    string fileName      = Path.GetFileName(theEntry.Name);

                    if (directoryName != string.Empty)
                    {
                        Directory.CreateDirectory(Path.Combine(directory, directoryName));
                    }

                    if (fileName != string.Empty)
                    {
                        FileStream streamWriter = File.Create(Path.Combine(directory, theEntry.Name));
                        LogUtil.Log("-------------->Begin UnZip {0},Size:{1}", theEntry.Name, theEntry.Size);
                        int    size = 2048;
                        byte[] data = new byte[2048];
                        while (true)
                        {
                            size = s.Read(data, 0, data.Length);
                            if (size > 0)
                            {
                                streamWriter.Write(data, 0, size);
                            }
                            else
                            {
                                break;
                            }

                            if (cb != null)
                            {
                                cb(theEntry.Name, theEntry.Size > 0 ? 100 * streamWriter.Length * 1.0f / theEntry.Size : 100, streamWriter.Length, theEntry.Size);
                            }
                            // else
                            // {
                            //     LogUtil.Log("UnZip {0} {1}/{2}--{3}", theEntry.Name, streamWriter.Length, theEntry.Size, theEntry.Size > 0 ? 100*streamWriter.Length*1.0f / theEntry.Size : 100);
                            // }
                        }

                        streamWriter.Close();
                        n++;
                        LogUtil.Log("-------------->End UnZip {0}, {1}/{2}", theEntry.Name, n, count);
                    }
                }
                s.Close();
                return(true);
            }
            catch (Exception e)
            {
                LogUtil.LogError(e.Message);
                return(false);
            }
        }
コード例 #18
0
        /// <summary>
        /// Decompresses the given data stream from its source ZIP or GZIP format.
        /// </summary>
        /// <param name="dataBytes"></param>
        /// <returns></returns>
        private static byte[] Inflate(byte[] dataBytes)
        {
            byte[] outputBytes = null;
            var zipInputStream =
                new ICSharpCode.SharpZipLib.Zip.ZipInputStream(new MemoryStream(dataBytes));

            if (zipInputStream.CanDecompressEntry) {

                MemoryStream zipoutStream = new MemoryStream();
            #if XBOX
                byte[] buf = new byte[4096];
                int amt = -1;
                while (true)
                {
                    amt = zipInputStream.Read(buf, 0, buf.Length);
                    if (amt == -1)
                    {
                        break;
                    }
                    zipoutStream.Write(buf, 0, amt);
                }
            #else
                zipInputStream.CopyTo(zipoutStream);
            #endif
                outputBytes = zipoutStream.ToArray();
            }
            else {

                try {
                var gzipInputStream =
                    new ICSharpCode.SharpZipLib.GZip.GZipInputStream(new MemoryStream(dataBytes));

                MemoryStream zipoutStream = new MemoryStream();

            #if XBOX
                byte[] buf = new byte[4096];
                int amt = -1;
                while (true)
                {
                    amt = gzipInputStream.Read(buf, 0, buf.Length);
                    if (amt == -1)
                    {
                        break;
                    }
                    zipoutStream.Write(buf, 0, amt);
                }
            #else
                gzipInputStream.CopyTo(zipoutStream);
            #endif
                outputBytes = zipoutStream.ToArray();
                }
                catch (Exception exc)
                {
                    CCLog.Log("Error decompressing image data: " + exc.Message);
                }

            }

            return outputBytes;
        }
コード例 #19
0
ファイル: MainForm.cs プロジェクト: faze79/rmo-rugbymania
 private void menuImportTeamData_Click(object sender, EventArgs e)
 {
     OpenFileDialog d = new OpenFileDialog();
     d.CheckFileExists = true;
     d.CheckPathExists = true;
     d.Filter = T("Tutti i file ZIP (*.zip)")+"|*.zip";
     d.InitialDirectory = My.Dir.Desktop;
     d.Multiselect = false;
     d.Title = T("Importa dati precedentemente importati");
     if (d.ShowDialog() == DialogResult.OK)
     {
         string file = d.FileName;
         try
         {
             if (!System.IO.Directory.Exists(PATH_HISTORY)) System.IO.Directory.CreateDirectory(PATH_HISTORY);
             using (ICSharpCode.SharpZipLib.Zip.ZipInputStream s = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(System.IO.File.OpenRead(file)))
             {
                 ICSharpCode.SharpZipLib.Zip.ZipEntry theEntry;
                 while ((theEntry = s.GetNextEntry()) != null)
                 {
                     lStatus.Text = string.Format(T("Importazione di {0}"), theEntry.Name);
                     string fileName = System.IO.Path.GetFileName(theEntry.Name);
                     if (fileName != String.Empty)
                     {
                         string new_path = PATH_HISTORY + "\\" + fileName;
                         using (System.IO.FileStream streamWriter = System.IO.File.Create(new_path))
                         {
                             int size = 2048;
                             byte[] data = new byte[2048];
                             while (true)
                             {
                                 size = s.Read(data, 0, data.Length);
                                 if (size > 0) streamWriter.Write(data, 0, size);
                                 else break;
                             }
                         }
                     }
                 }
                 lStatus.Text = T("Import ultimato correttamente");
             }
         }
         catch (Exception ex) { My.Box.Errore(T("Errore durante l'importazione del backup")+"\r\n" + ex.Message); }
     }
 }
コード例 #20
0
        /*
         *              if (provider.Name.EndsWith (".vssettings", StringComparison.Ordinal)) {
         *              styles [name] = OldFormat.ImportVsSetting (provider.Name, stream);
         *      } else if (provider.Name.EndsWith (".json", StringComparison.Ordinal)) {
         *              styles [name] = OldFormat.ImportColorScheme (stream);
         *      } else {
         *              styles [name] = TextMateFormat.LoadEditorTheme (stream);
         *      }
         *      styles [name].FileName = provider.Name;
         *
         * */

        static object LoadFile(LanguageBundle bundle, string file, Func <Stream> openStream, Func <IStreamProvider> getStreamProvider)
        {
            if (file.EndsWith(".json", StringComparison.OrdinalIgnoreCase))
            {
                using (var stream = openStream()) {
                    string     styleName;
                    JSonFormat format;
                    if (TryScanJSonStyle(stream, out styleName, out format))
                    {
                        switch (format)
                        {
                        case JSonFormat.OldSyntaxTheme:
                            var theme = OldFormat.ImportColorScheme(getStreamProvider().Open());
                            if (theme != null)
                            {
                                bundle.Add(theme);
                            }
                            return(theme);

                        case JSonFormat.TextMateJsonSyntax:
                            SyntaxHighlightingDefinition highlighting = TextMateFormat.ReadHighlightingFromJson(getStreamProvider().Open());
                            if (highlighting != null)
                            {
                                bundle.Add(highlighting);
                            }
                            return(highlighting);
                        }
                    }
                }
            }
            else if (file.EndsWith(".tmTheme", StringComparison.OrdinalIgnoreCase))
            {
                using (var stream = openStream()) {
                    string styleName = ScanTextMateStyle(stream);
                    if (!string.IsNullOrEmpty(styleName))
                    {
                        var theme = TextMateFormat.LoadEditorTheme(getStreamProvider().Open());
                        if (theme != null)
                        {
                            bundle.Add(theme);
                        }
                        return(theme);
                    }
                    else
                    {
                        LoggingService.LogError("Invalid .tmTheme theme file : " + file);
                    }
                }
            }
            else if (file.EndsWith(".vssettings", StringComparison.OrdinalIgnoreCase))
            {
                using (var stream = openStream()) {
                    string      styleName = Path.GetFileNameWithoutExtension(file);
                    EditorTheme theme;
                    try {
                        theme = OldFormat.ImportVsSetting(styleName, getStreamProvider().Open());
                    } catch (StyleImportException e) {
                        switch (e.Reason)
                        {
                        case StyleImportException.ImportFailReason.Unknown:
                            LoggingService.LogWarning("Unknown error in theme file : " + file, e);
                            break;

                        case StyleImportException.ImportFailReason.NoValidColorsFound:
                            LoggingService.LogWarning("No colors defined in vssettings : " + file, e);
                            break;
                        }
                        return(null);
                    } catch (Exception e) {
                        LoggingService.LogWarning("Invalid theme : " + file, e);
                        return(null);
                    }
                    if (theme != null)
                    {
                        bundle.Add(theme);
                    }
                    return(theme);
                }
            }
            else if (file.EndsWith(".tmLanguage", StringComparison.OrdinalIgnoreCase))
            {
                using (var stream = openStream()) {
                    var highlighting = TextMateFormat.ReadHighlighting(stream);
                    if (highlighting != null)
                    {
                        bundle.Add(highlighting);
                    }
                    return(highlighting);
                }
            }
            else if (file.EndsWith(".sublime-syntax", StringComparison.OrdinalIgnoreCase))
            {
                using (var stream = new StreamReader(openStream())) {
                    var highlighting = Sublime3Format.ReadHighlighting(stream);
                    if (highlighting != null)
                    {
                        bundle.Add(highlighting);
                    }
                    return(highlighting);
                }
            }
            else if (file.EndsWith(".sublime-package", StringComparison.OrdinalIgnoreCase) || file.EndsWith(".tmbundle", StringComparison.OrdinalIgnoreCase))
            {
                try {
                    using (var stream = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(openStream())) {
                        var entry     = stream.GetNextEntry();
                        var newBundle = new LanguageBundle(Path.GetFileNameWithoutExtension(file), file);
                        while (entry != null)
                        {
                            if (entry.IsFile && !entry.IsCrypted)
                            {
                                if (stream.CanDecompressEntry)
                                {
                                    byte [] data = new byte [entry.Size];
                                    stream.Read(data, 0, (int)entry.Size);
                                    LoadFile(newBundle, entry.Name, () => new MemoryStream(data), () => new MemoryStreamProvider(data, entry.Name));
                                }
                            }
                            entry = stream.GetNextEntry();
                        }
                        languageBundles.Add(newBundle);
                        return(newBundle);
                    }
                } catch (Exception e) {
                    LoggingService.LogError("Error while reading : " + file, e);
                }
            }
            else if (file.EndsWith(".tmPreferences", StringComparison.OrdinalIgnoreCase))
            {
                using (var stream = openStream()) {
                    var preference = TextMateFormat.ReadPreferences(stream);
                    if (preference != null)
                    {
                        bundle.Add(preference);
                    }
                    return(preference);
                }
            }
            else if (file.EndsWith(".tmSnippet", StringComparison.OrdinalIgnoreCase))
            {
                using (var stream = openStream()) {
                    var snippet = TextMateFormat.ReadSnippet(stream);
                    if (snippet != null)
                    {
                        bundle.Add(snippet);
                    }
                    return(snippet);
                }
            }
            else if (file.EndsWith(".sublime-snippet", StringComparison.OrdinalIgnoreCase))
            {
                using (var stream = openStream()) {
                    var snippet = Sublime3Format.ReadSnippet(stream);
                    if (snippet != null)
                    {
                        bundle.Add(snippet);
                    }
                    return(snippet);
                }
            }
            return(null);
        }
コード例 #21
0
ファイル: FTPClient.cs プロジェクト: SDRC-India/sdrcdevinfo
        /// <summary>
        /// Extractor function 
        /// </summary>
        /// <param name="zipFilename">zipFilename</param>
        /// <param name="ExtractDir">ExtractDir</param>
        /// <param name="deleteZippedfile">if true, zipped file will be deleted after extraction.</param>
        public void ExtractArchive(string zipFilename, string ExtractDir, bool deleteZippedfile)
        {
            //			int Redo = 1;
            ICSharpCode.SharpZipLib.Zip.ZipInputStream MyZipInputStream;
            FileStream MyFileStream;

            MyZipInputStream = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(new FileStream(zipFilename, FileMode.Open, FileAccess.Read));
            ICSharpCode.SharpZipLib.Zip.ZipEntry MyZipEntry = MyZipInputStream.GetNextEntry();
            Directory.CreateDirectory(ExtractDir);

            while (!(MyZipEntry == null))
            {
                if (MyZipEntry.IsDirectory)
                {
                    Directory.CreateDirectory(ExtractDir + "\\" + MyZipEntry.Name);
                }
                else
                {
                    if (!Directory.Exists(ExtractDir + "\\" + Path.GetDirectoryName(MyZipEntry.Name)))
                    {
                        Directory.CreateDirectory(ExtractDir + "\\" + Path.GetDirectoryName(MyZipEntry.Name));
                    }

                    MyFileStream = new FileStream(ExtractDir + "\\" + MyZipEntry.Name, FileMode.OpenOrCreate, FileAccess.Write);
                    int count;
                    byte[] buffer = new byte[4096];
                    count = MyZipInputStream.Read(buffer, 0, 4096);
                    while (count > 0)
                    {
                        MyFileStream.Write(buffer, 0, count);
                        count = MyZipInputStream.Read(buffer, 0, 4096);
                    }
                    MyFileStream.Close();
                }

                try
                {
                    MyZipEntry = MyZipInputStream.GetNextEntry();
                }
                catch (Exception ex)
                {
                    MyZipEntry = null;
                }
            }

            //dispose active objects
            try
            {
                if (!(MyZipInputStream == null))
                    MyZipInputStream.Close();
            }
            catch (Exception ex)
            { }
            finally
            {
                if (deleteZippedfile)
                {
                    //delete the zip file
                    if (System.IO.File.Exists(zipFilename))
                        System.IO.File.Delete(zipFilename);
                }
            }
        }
コード例 #22
0
        public static bool UnZipFile(string inputPathOfZipFile, out string returnMsg)
        {
            returnMsg = string.Empty;

            bool ret = true;

            try
            {
                if (File.Exists(inputPathOfZipFile))
                {
                    string baseDirectory = Path.GetDirectoryName(inputPathOfZipFile);

                    using (ICSharpCode.SharpZipLib.Zip.ZipInputStream zipStream = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(File.OpenRead(inputPathOfZipFile)))
                    {
                        ICSharpCode.SharpZipLib.Zip.ZipEntry theEntry;
                        while ((theEntry = zipStream.GetNextEntry()) != null)
                        {
                            if (theEntry.IsFile)
                            {
                                if (theEntry.Name != "")
                                {
                                    string strNewFile = @"" + baseDirectory + @"\" + theEntry.Name;
                                    //Check thư mục chứa nó, Nếu không có thì tạo mới
                                    string folder = Path.GetDirectoryName(strNewFile);
                                    if (folder != null && !Directory.Exists(folder))
                                    {
                                        Directory.CreateDirectory(folder);
                                    }
                                    ////////End

                                    using (FileStream streamWriter = File.Create(strNewFile))
                                    {
                                        byte[] data = new byte[2048];
                                        while (true)
                                        {
                                            int size = zipStream.Read(data, 0, data.Length);
                                            if (size > 0)
                                            {
                                                streamWriter.Write(data, 0, size);
                                            }
                                            else
                                            {
                                                break;
                                            }
                                        }
                                        streamWriter.Close();
                                    }
                                }
                            }
                            else if (theEntry.IsDirectory)
                            {
                                string strNewDirectory = @"" + baseDirectory + @"\" + theEntry.Name;
                                if (!Directory.Exists(strNewDirectory))
                                {
                                    Directory.CreateDirectory(strNewDirectory);
                                }
                            }
                        }
                        zipStream.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                ret       = false;
                returnMsg = ex.Message + "\r\n\r\n" + ex.StackTrace;
            }
            return(ret);
        }
コード例 #23
0
        /// <summary>
        /// 解压功能(解压压缩文件到指定目录)
        /// </summary>
        /// <param name="FileToUpZip">待解压的文件</param>
        /// <param name="ZipedFolder">指定解压目标目录</param>
        public static void UnZip(string FileToUpZip, string ZipedFolder)
        {
            if (!File.Exists(FileToUpZip))
            {
                return;
            }

            if (!Directory.Exists(ZipedFolder))
            {
                Directory.CreateDirectory(ZipedFolder);
            }

            ICSharpCode.SharpZipLib.Zip.ZipInputStream s        = null;
            ICSharpCode.SharpZipLib.Zip.ZipEntry       theEntry = null;

            string     fileName;
            FileStream streamWriter = null;

            try
            {
                s = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(File.OpenRead(FileToUpZip));
                while ((theEntry = s.GetNextEntry()) != null)
                {
                    if (theEntry.Name != String.Empty)
                    {
                        fileName = Path.Combine(ZipedFolder, theEntry.Name);
                        ///判断文件路径是否是文件夹

                        if (fileName.EndsWith("/") || fileName.EndsWith("\\"))
                        {
                            Directory.CreateDirectory(fileName);
                            continue;
                        }

                        streamWriter = File.Create(fileName);
                        int    size = 2048;
                        byte[] data = new byte[2048];
                        while (true)
                        {
                            size = s.Read(data, 0, data.Length);
                            if (size > 0)
                            {
                                streamWriter.Write(data, 0, size);
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }
            }
            finally
            {
                if (streamWriter != null)
                {
                    streamWriter.Close();
                    streamWriter = null;
                }
                if (theEntry != null)
                {
                    theEntry = null;
                }
                if (s != null)
                {
                    s.Close();
                    s = null;
                }
                GC.Collect();
                GC.Collect(1);
            }
        }