当前位置: 首页>>代码示例>>C#>>正文


C# Ionic类代码示例

本文整理汇总了C#中Ionic的典型用法代码示例。如果您正苦于以下问题:C# Ionic类的具体用法?C# Ionic怎么用?C# Ionic使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Ionic类属于命名空间,在下文中一共展示了Ionic类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddToZip

        public static void AddToZip(BackgroundWorker worker, string zipfile, string FileToAdd, string AsFilename = "", bool showProgress = true, Ionic.Zlib.CompressionLevel complevel = Ionic.Zlib.CompressionLevel.Default)
        {
            if (!File.Exists(zipfile))
                throw new FileNotFoundException("Zipfile " + zipfile + " does not exist");

            bool exists = ExistsInZip(zipfile, AsFilename == "" ? FileToAdd : AsFilename);
            using (ZipFile zip = new ZipFile(zipfile))
            {
                Utility.SetZipTempFolder(zip);
                zip.CompressionLevel = complevel;

                if (exists)
                    zip.RemoveEntry(AsFilename == "" ? FileToAdd : AsFilename);
                ZipEntry ze = zip.AddFile(FileToAdd, "");
                if (!string.IsNullOrEmpty(AsFilename))
                    ze.FileName = AsFilename;

                if (showProgress)
                    zip.SaveProgress += (o, e) =>
                    {
                        if (e.EventType == ZipProgressEventType.Saving_EntryBytesRead && e.CurrentEntry.FileName == (AsFilename == "" ? FileToAdd : AsFilename))
                            worker.ReportProgress((int)((float)e.BytesTransferred / e.TotalBytesToTransfer * 100));
                    };
                zip.Save();
            }
        }
开发者ID:tmeckel,项目名称:PRFCreator,代码行数:26,代码来源:Zipping.cs

示例2: ZipFolder

 public static void ZipFolder(string inputFolder, string outputFile, Ionic.Zlib.CompressionLevel level)
 {
     using (ZipFile zip = new ZipFile())
     {
         zip.CompressionLevel = level;
         zip.AddDirectory(inputFolder, "");
         //zip.AddFiles(GenerateFileList(inputFolder));
         //zip.AddDirectory(inputFolder);
         zip.Save(outputFile);
     }
 }
开发者ID:wdj294,项目名称:tdtk,代码行数:11,代码来源:ZipUtil.cs

示例3: SelectEntries

        /// <summary>
        /// Retrieve the ZipEntry items in the ZipFile that conform to the specified criteria.
        /// </summary>
        /// <remarks>
        ///
        /// <para>
        /// This method applies the criteria set in the FileSelector instance (as described in
        /// the <see cref="FileSelector.SelectionCriteria"/>) to the specified ZipFile.  Using this
        /// method, for example, you can retrieve all entries from the given ZipFile that
        /// have filenames ending in .txt.
        /// </para>
        ///
        /// <para>
        /// Normally, applications would not call this method directly.  This method is used
        /// by the ZipFile class.
        /// </para>
        ///
        /// <para>
        /// Using the appropriate SelectionCriteria, you can retrieve entries based on size,
        /// time, and attributes. See <see cref="FileSelector.SelectionCriteria"/> for a
        /// description of the syntax of the SelectionCriteria string.
        /// </para>
        ///
        /// </remarks>
        ///
        /// <param name="zip">The ZipFile from which to retrieve entries.</param>
        ///
        /// <returns>a collection of ZipEntry objects that conform to the criteria.</returns>
        public ICollection<Ionic.Zip.ZipEntry> SelectEntries(Ionic.Zip.ZipFile zip)
        {
            var list = new List<Ionic.Zip.ZipEntry>();

            foreach (Ionic.Zip.ZipEntry e in zip)
            {
                if (this.Evaluate(e))
                    list.Add(e);
            }

            return list;
        }
开发者ID:pilehave,项目名称:headweb-mp,代码行数:40,代码来源:ZipFile.Selector.cs

示例4: WorkItem

            public WorkItem(int size, Ionic.Zlib.CompressionLevel compressLevel, CompressionStrategy strategy)
            {
                buffer= new byte[size];
                // alloc 5 bytes overhead for every block (margin of safety= 2)
                int n = size + ((size / 32768)+1) * 5 * 2;
                compressed= new byte[n];

                status = (int)Status.None;
                compressor = new ZlibCodec();
                compressor.InitializeDeflate(compressLevel, false);
                compressor.OutputBuffer = compressed;
                compressor.InputBuffer = buffer;
            }
开发者ID:tofurama3000,项目名称:substrate-minecraft,代码行数:13,代码来源:ParallelDeflateOutputStream.cs

示例5: FinishOutputStream

        internal void FinishOutputStream(Stream s,
                                         CountingStream entryCounter,
                                         Stream encryptor,
                                         Stream compressor,
                                         Ionic.Crc.CrcCalculatorStream output)
        {
            if (output == null) return;

            output.Close();

            // by calling Close() on the deflate stream, we write the footer bytes, as necessary.
            if ((compressor as Ionic.Zlib.DeflateStream) != null)
                compressor.Close();
            #if BZIP
            else if ((compressor as Ionic.BZip2.BZip2OutputStream) != null)
                compressor.Close();
            #if !NETCF
            else if ((compressor as Ionic.BZip2.ParallelBZip2OutputStream) != null)
                compressor.Close();
            #endif
            #endif

            #if !NETCF
            else if ((compressor as Ionic.Zlib.ParallelDeflateOutputStream) != null)
                compressor.Close();
            #endif

            encryptor.Flush();
            encryptor.Close();

            _LengthOfTrailer = 0;

            _UncompressedSize = output.TotalBytesSlurped;

            #if AESCRYPTO
            WinZipAesCipherStream wzacs = encryptor as WinZipAesCipherStream;
            if (wzacs != null && _UncompressedSize > 0)
            {
                s.Write(wzacs.FinalAuthentication, 0, 10);
                _LengthOfTrailer += 10;
            }
            #endif
            _CompressedFileDataSize = entryCounter.BytesWritten;
            _CompressedSize = _CompressedFileDataSize;   // may be adjusted
            _Crc32 = output.Crc;

            // Set _RelativeOffsetOfLocalHeader now, to allow for re-streaming
            StoreRelativeOffset();
        }
开发者ID:kidaa,项目名称:DissDlcToolkit,代码行数:49,代码来源:ZipEntry.Write.cs

示例6: WorkItem

 public WorkItem(int size,
                 Ionic.Zlib.CompressionLevel compressLevel,
                 CompressionStrategy strategy,
                 int ix)
 {
     this.buffer= new byte[size];
     // alloc 5 bytes overhead for every block (margin of safety= 2)
     int n = size + ((size / 32768)+1) * 5 * 2;
     this.compressed = new byte[n];
     this.compressor = new ZlibCodec();
     this.compressor.InitializeDeflate(compressLevel, false);
     this.compressor.OutputBuffer = this.compressed;
     this.compressor.InputBuffer = this.buffer;
     this.index = ix;
 }
开发者ID:Eagle-Chan,项目名称:KIS,代码行数:15,代码来源:ParallelDeflateOutputStream.cs

示例7: RecursiveArchivate

 private static void RecursiveArchivate(string path, Ionic.Zip.ZipFile zip, string relPath, ref DateTime dt)
 {
     foreach (var file in Directory.GetFiles(path))
     {
         //if (!CheckFile(file)) continue;
         var fdt = File.GetLastWriteTime(file);
         if (fdt > dt) dt = File.GetLastWriteTime(file);
         zip.AddFile(file, relPath);
     }
     foreach (string directory in Directory.GetDirectories(path))
     {
         var dirName = new DirectoryInfo(directory).Name;
         RecursiveArchivate(directory, zip, string.Format(@"{0}\{1}", relPath, dirName), ref dt);
     }
 }
开发者ID:Ryoko,项目名称:General-Game-Saver,代码行数:15,代码来源:GameSaver.cs

示例8: Evaluate

 internal override bool Evaluate(Ionic.Zip.ZipEntry entry)
 {
     bool result = Left.Evaluate(entry);
     switch (Conjunction)
     {
         case LogicalConjunction.AND:
             if (result)
                 result = Right.Evaluate(entry);
             break;
         case LogicalConjunction.OR:
             if (!result)
                 result = Right.Evaluate(entry);
             break;
         case LogicalConjunction.XOR:
             result ^= Right.Evaluate(entry);
             break;
     }
     return result;
 }
开发者ID:kidaa,项目名称:DissDlcToolkit,代码行数:19,代码来源:ZipFile.Selector.cs

示例9: LNSF_SaveProgress

        void LNSF_SaveProgress(object sender, Ionic.Zip.SaveProgressEventArgs e)
        {
            switch (e.EventType)
            {
                case ZipProgressEventType.Saving_Started:
                    _numEntriesSaved = 0;
                    _txrx.Send("status saving started...");
                    _pb1Set = false;
                    break;

                case ZipProgressEventType.Saving_BeforeWriteEntry:
                    _numEntriesSaved++;
                    if (_numEntriesSaved % 64 == 0)
                        _txrx.Send(String.Format("status Compressing {0}", e.CurrentEntry.FileName));
                    if (!_pb1Set)
                    {
                        _txrx.Send(String.Format("pb 1 max {0}", e.EntriesTotal));
                        _pb1Set = true;
                    }
                    break;

                case ZipProgressEventType.Saving_EntryBytesRead:
                    Assert.IsTrue(e.BytesTransferred <= e.TotalBytesToTransfer);
                    break;

                case ZipProgressEventType.Saving_AfterWriteEntry:
                    _txrx.Send("pb 1 step");
                    break;

                case ZipProgressEventType.Saving_Completed:
                    _txrx.Send("status Save completed");
                    _pb1Set = false;
                    _txrx.Send("pb 1 max 1");
                    _txrx.Send("pb 1 value 1");
                    break;
            }
        }
开发者ID:mattleibow,项目名称:Zip.Portable,代码行数:37,代码来源:LongRunning.cs

示例10: Evaluate

 internal override bool Evaluate(Ionic.Zip.ZipEntry entry)
 {
     DateTime x;
     switch (Which)
     {
         case WhichTime.atime:
             x = entry.AccessedTime;
             break;
         case WhichTime.mtime:
             x = entry.ModifiedTime;
             break;
         case WhichTime.ctime:
             x = entry.CreationTime;
             break;
         default: throw new ArgumentException("??time");
     }
     return _Evaluate(x);
 }
开发者ID:leesanghyun2,项目名称:mp-onlinevideos2,代码行数:18,代码来源:ZipFile.Selector.cs

示例11: _Zip64_Over65534Entries

        void _Zip64_Over65534Entries(Zip64Option z64option,
                                            EncryptionAlgorithm encryption,
                                            Ionic.Zlib.CompressionLevel compression)
        {
            // Emitting a zip file with > 65534 entries requires the use of ZIP64 in
            // the central directory.
            int numTotalEntries = _rnd.Next(4616)+65534;
            //int numTotalEntries = _rnd.Next(461)+6534;
            //int numTotalEntries = _rnd.Next(46)+653;
            string enc = encryption.ToString();
            if (enc.StartsWith("WinZip")) enc = enc.Substring(6);
            else if (enc.StartsWith("Pkzip")) enc = enc.Substring(0,5);
            string zipFileToCreate = String.Format("Zip64.ZF_Over65534.{0}.{1}.{2}.zip",
                                                   z64option.ToString(),
                                                   enc,
                                                   compression.ToString());

            _testTitle = String.Format("ZipFile #{0} 64({1}) E({2}), C({3})",
                                       numTotalEntries,
                                       z64option.ToString(),
                                       enc,
                                       compression.ToString());
            _txrx = TestUtilities.StartProgressMonitor(zipFileToCreate,
                                                       _testTitle,
                                                       "starting up...");

            _txrx.Send("pb 0 max 4"); // 3 stages: AddEntry, Save, Verify
            _txrx.Send("pb 0 value 0");

            string password = Path.GetRandomFileName();

            string statusString = String.Format("status Encrypt:{0} Compress:{1}...",
                                                enc,
                                                compression.ToString());

            int numSaved = 0;
            var saveProgress = new EventHandler<SaveProgressEventArgs>( (sender, e) => {
                    switch (e.EventType)
                    {
                        case ZipProgressEventType.Saving_Started:
                        _txrx.Send("status saving...");
                        _txrx.Send("pb 1 max " + numTotalEntries);
                        numSaved= 0;
                        break;

                        case ZipProgressEventType.Saving_AfterWriteEntry:
                        numSaved++;
                        if ((numSaved % 128) == 0)
                        {
                            _txrx.Send("pb 1 value " + numSaved);
                            _txrx.Send(String.Format("status Saving entry {0}/{1} ({2:N0}%)",
                                                     numSaved, numTotalEntries,
                                                     numSaved / (0.01 * numTotalEntries)
                                                     ));
                        }
                        break;

                        case ZipProgressEventType.Saving_Completed:
                        _txrx.Send("status Save completed");
                        _txrx.Send("pb 1 max 1");
                        _txrx.Send("pb 1 value 1");
                        break;
                    }
                });

            string contentFormatString =
                "This is the content for entry #{0}.\r\n\r\n" +
                "AAAAAAA BBBBBB AAAAA BBBBB AAAAA BBBBB AAAAA\r\n"+
                "AAAAAAA BBBBBB AAAAA BBBBB AAAAA BBBBB AAAAA\r\n";
            _txrx.Send(statusString);
            int dirCount= 0;
            using (var zip = new ZipFile())
            {
                _txrx.Send(String.Format("pb 1 max {0}", numTotalEntries));
                _txrx.Send("pb 1 value 0");

                zip.Password = password;
                zip.Encryption = encryption;
                zip.CompressionLevel = compression;
                zip.SaveProgress += saveProgress;
                zip.UseZip64WhenSaving = z64option;
                // save space when saving the file:
                zip.EmitTimesInWindowsFormatWhenSaving = false;
                zip.EmitTimesInUnixFormatWhenSaving = false;

                // add files:
                for (int m=0; m<numTotalEntries; m++)
                {
                    if (_rnd.Next(7)==0)
                    {
                        string entryName = String.Format("{0:D5}", m);
                        zip.AddDirectoryByName(entryName);
                        dirCount++;
                    }
                    else
                    {
                        string entryName = String.Format("{0:D5}.txt", m);
                        if (_rnd.Next(12)==0)
                        {
                            string contentBuffer = String.Format(contentFormatString, m);
//.........这里部分代码省略.........
开发者ID:mattleibow,项目名称:Zip.Portable,代码行数:101,代码来源:Zip64Tests.cs

示例12: SetZipTempFolder

 public static void SetZipTempFolder(Ionic.Zip.ZipFile zf)
 {
     if (!string.IsNullOrEmpty(Settings.templocation))
         zf.TempFileFolder = Settings.templocation;
 }
开发者ID:joeisgood99,项目名称:PRFCreator,代码行数:5,代码来源:Utility.cs

示例13: PackResources

 public override void PackResources(Ionic.Zip.ZipFile zip, String archiveTargetPath, IPath sourcePath)
 {
     RelativePath path = new RelativePath(this.Source, sourcePath);
     zip.AddFile(path.AbsolutePath, archiveTargetPath);
 }
开发者ID:Pjanssen,项目名称:ScriptCenter,代码行数:5,代码来源:RunMaxscriptAction.cs

示例14: PrepOutputStream

        /// <summary>
        ///   Prepare the given stream for output - wrap it in a CountingStream, and
        ///   then in a CRC stream, and an encryptor and deflator as appropriate.
        /// </summary>
        /// <remarks>
        ///   <para>
        ///     Previously this was used in ZipEntry.Write(), but in an effort to
        ///     introduce some efficiencies in that method I've refactored to put the
        ///     code inline.  This method still gets called by ZipOutputStream.
        ///   </para>
        /// </remarks>
        internal void PrepOutputStream(Stream s,
                                       long streamLength,
                                       out CountingStream outputCounter,
                                       out Stream encryptor,
                                       out Stream compressor,
                                       out Ionic.Crc.CrcCalculatorStream output)
        {
            TraceWriteLine("PrepOutputStream: e({0}) comp({1}) crypto({2}) zf({3})",
                           FileName,
                           CompressionLevel,
                           Encryption,
                           _container.Name);

            // Wrap a counting stream around the raw output stream:
            // This is the last thing that happens before the bits go to the
            // application-provided stream.
            outputCounter = new CountingStream(s);

            // Sometimes the incoming "raw" output stream is already a CountingStream.
            // Doesn't matter. Wrap it with a counter anyway. We need to count at both
            // levels.

            if (streamLength != 0L)
            {
                // Maybe wrap an encrypting stream around that:
                // This will happen BEFORE output counting, and AFTER deflation, if encryption
                // is used.
                encryptor = MaybeApplyEncryption(outputCounter);

                // Maybe wrap a compressing Stream around that.
                // This will happen BEFORE encryption (if any) as we write data out.
                compressor = MaybeApplyCompression(encryptor, streamLength);
            }
            else
            {
                encryptor = compressor = outputCounter;
            }
            // Wrap a CrcCalculatorStream around that.
            // This will happen BEFORE compression (if any) as we write data out.
            output = new Ionic.Crc.CrcCalculatorStream(compressor, true);
        }
开发者ID:puckipedia,项目名称:MagisterAPI,代码行数:52,代码来源:ZipEntry.Write.cs

示例15: Transaction_ProgressChanged

        private void Transaction_ProgressChanged(object sender, Ionic.Zip.SaveProgressEventArgs e)
        {
            try
            {
                if (prbMaster == null || prbSlave == null ||
                    prbMaster.IsDisposed || prbSlave.IsDisposed ||
                    !prbMaster.IsHandleCreated || !prbSlave.IsHandleCreated ||
                    !prbMaster.Created || !prbSlave.Created)
                    return;

                if (e.TotalBytesToTransfer > 0)
                {
                    if (this.prbSlave.InvokeRequired)
                    {
                        this.prbSlave.Invoke(new Action(delegate
                        {
                            this.prbSlave.Value = unchecked((int)(e.BytesTransferred * 100 / e.TotalBytesToTransfer));
                        }));
                    }
                }
                if (e.EntriesSaved > 0 && e.EntriesTotal > 0)
                {
                    if (this.prbMaster.InvokeRequired)
                    {
                        this.prbMaster.Invoke(new Action(delegate
                        {
                            this.prbMaster.Value = unchecked((int)((double)e.EntriesSaved * 100 / (double)e.EntriesTotal));
                        }));
                    }
                }
            }
            catch (Exception ex) { EventReflector.CallReport.Post(new ReportEventArgs("GUI.TransferToDisk_ProgressChanged", ex)); }
        }
开发者ID:Behzadkhosravifar,项目名称:BlackANT,代码行数:33,代码来源:GUI.cs


注:本文中的Ionic类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。