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


C# FastZip.CreateZip方法代码示例

本文整理汇总了C#中ICSharpCode.SharpZipLib.Zip.FastZip.CreateZip方法的典型用法代码示例。如果您正苦于以下问题:C# FastZip.CreateZip方法的具体用法?C# FastZip.CreateZip怎么用?C# FastZip.CreateZip使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ICSharpCode.SharpZipLib.Zip.FastZip的用法示例。


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

示例1: buttonCreateBackup_Click

        private void buttonCreateBackup_Click(object sender, EventArgs e)
        {
            if (Directory.Exists("_backup")) Directory.Delete("_backup", true);
            Directory.CreateDirectory("_backup");

            // prompt user for backup filename
            SaveFileDialog saveBackup = new SaveFileDialog();
            saveBackup.Filter = "SnakeBite Backup|*.sbb";
            DialogResult saveResult = saveBackup.ShowDialog();
            if (saveResult != DialogResult.OK) return;

            // copy current settings
            objSettings.SaveSettings();
            File.Copy(ModManager.GameDir + "\\sbmods.xml", "_backup\\sbmods.xml");

            // copy current 01.dat
            File.Copy(ModManager.GameArchivePath, "_backup\\01.dat");

            // compress to backup
            FastZip zipper = new FastZip();
            zipper.CreateZip(saveBackup.FileName, "_backup", true, "(.*?)");

            Directory.Delete("_backup", true);

            MessageBox.Show("Backup complete.", "SnakeBite", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
开发者ID:MrRSPEED9845,项目名称:SnakeBite,代码行数:26,代码来源:formMain.cs

示例2: PackFiles

    /// <summary>压缩文件</summary>
    /// <param name="filename">filename生成的文件的名称,如:C:\RAR\075_20110820153200001-1.rar</param>
    /// <param name="directory">directory要压缩的文件夹路径,如:C:\OA</param>
    /// <returns></returns>
    public static bool PackFiles(string filename, string directory)
    {
        try
        {

            directory = directory.Replace("/", "\\");

            if (!directory.EndsWith("\\"))
                directory += "\\";
            if (!System.IO.Directory.Exists(directory))
            {
                System.IO.Directory.CreateDirectory(directory);
            }
            if (System.IO.File.Exists(filename))
            {
                System.IO.File.Delete(filename);
            }
            FastZip fz = new FastZip();
            fz.CreateEmptyDirectories = true;
            fz.CreateZip(filename, directory, true, "");
            return true;
        }
        catch (Exception)
        {
            return false;
        }
    }
开发者ID:wjszxli,项目名称:hyoav10_gdcrm,代码行数:31,代码来源:list_bak.aspx.cs

示例3: Basics

        public void Basics()
        {
            const string tempName1 = "a(1).dat";

            MemoryStream target = new MemoryStream();

            string tempFilePath = GetTempFilePath();
            Assert.IsNotNull(tempFilePath, "No permission to execute this test?");

            string addFile = Path.Combine(tempFilePath, tempName1);
            MakeTempFile(addFile, 1);

            try {
                FastZip fastZip = new FastZip();
                fastZip.CreateZip(target, tempFilePath, false, @"a\(1\)\.dat", null);

                MemoryStream archive = new MemoryStream(target.ToArray());
                using (ZipFile zf = new ZipFile(archive)) {
                    Assert.AreEqual(1, zf.Count);
                    ZipEntry entry = zf[0];
                    Assert.AreEqual(tempName1, entry.Name);
                    Assert.AreEqual(1, entry.Size);
                    Assert.IsTrue(zf.TestArchive(true));

                    zf.Close();
                }
            }
            finally {
                File.Delete(tempName1);
            }
        }
开发者ID:firestrand,项目名称:SharpZipLib,代码行数:31,代码来源:ZipTests.cs

示例4: CreateDeltaPackage

        public ReleasePackage CreateDeltaPackage(ReleasePackage basePackage, ReleasePackage newPackage, string outputFile)
        {
            Contract.Requires(basePackage != null);
            Contract.Requires(!String.IsNullOrEmpty(outputFile) && !File.Exists(outputFile));

            if (basePackage.Version > newPackage.Version) {
                var message = String.Format(
                    "You cannot create a delta package based on version {0} as it is a later version than {1}",
                    basePackage.Version,
                    newPackage.Version);
                throw new InvalidOperationException(message);
            }

            if (basePackage.ReleasePackageFile == null) {
                throw new ArgumentException("The base package's release file is null", "basePackage");
            }

            if (!File.Exists(basePackage.ReleasePackageFile)) {
                throw new FileNotFoundException("The base package release does not exist", basePackage.ReleasePackageFile);
            }

            if (!File.Exists(newPackage.ReleasePackageFile)) {
                throw new FileNotFoundException("The new package release does not exist", newPackage.ReleasePackageFile);
            }

            string baseTempPath = null;
            string tempPath = null;

            using (Utility.WithTempDirectory(out baseTempPath, null))
            using (Utility.WithTempDirectory(out tempPath, null)) {
                var baseTempInfo = new DirectoryInfo(baseTempPath);
                var tempInfo = new DirectoryInfo(tempPath);

                this.Log().Info("Extracting {0} and {1} into {2}", 
                    basePackage.ReleasePackageFile, newPackage.ReleasePackageFile, tempPath);

                var fz = new FastZip();
                fz.ExtractZip(basePackage.ReleasePackageFile, baseTempInfo.FullName, null);
                fz.ExtractZip(newPackage.ReleasePackageFile, tempInfo.FullName, null);

                // Collect a list of relative paths under 'lib' and map them
                // to their full name. We'll use this later to determine in
                // the new version of the package whether the file exists or
                // not.
                var baseLibFiles = baseTempInfo.GetAllFilesRecursively()
                    .Where(x => x.FullName.ToLowerInvariant().Contains("lib" + Path.DirectorySeparatorChar))
                    .ToDictionary(k => k.FullName.Replace(baseTempInfo.FullName, ""), v => v.FullName);

                var newLibDir = tempInfo.GetDirectories().First(x => x.Name.ToLowerInvariant() == "lib");

                foreach (var libFile in newLibDir.GetAllFilesRecursively()) {
                    createDeltaForSingleFile(libFile, tempInfo, baseLibFiles);
                }

                ReleasePackage.addDeltaFilesToContentTypes(tempInfo.FullName);
                fz.CreateZip(outputFile, tempInfo.FullName, true, null);
            }

            return new ReleasePackage(outputFile);
        }
开发者ID:RxSmart,项目名称:Squirrel.Windows,代码行数:60,代码来源:DeltaPackage.cs

示例5: Zip

 /// <summary>
 /// Writes the specified directory to a new zip file.
 /// </summary>
 /// <param name="sourceDirectory">Directory with files to add.</param>
 /// <param name="zipFileName">Output file name.</param>
 public static void Zip(string sourceDirectory, string zipFileName)
 {
     FastZip fastZip = new FastZip();
     fastZip.RestoreAttributesOnExtract = true;
     fastZip.RestoreDateTimeOnExtract = true;
     fastZip.CreateZip(zipFileName, sourceDirectory, true, null);
 }
开发者ID:MarcStan,项目名称:NArrange,代码行数:12,代码来源:ZipUtilities.cs

示例6: ZipDir

 public static  void ZipDir(string strDir, string strZipFile)
 {
     FastZip fz = new FastZip();
     fz.CreateEmptyDirectories = true;
     fz.CreateZip(strZipFile, strDir, true, "");
     fz = null;
 }
开发者ID:powerhai,项目名称:Jinchen,代码行数:7,代码来源:ZipHelper.cs

示例7: BackupNow

        public static void BackupNow(MCServer s, string strAppendName = "")
        {
            Database.AddLog("Backing up " + s.ServerTitle, "backup");

            //Check for a backup dir and create if not
            if (!Directory.Exists(s.ServerDirectory + @"\backups\")) Directory.CreateDirectory(s.ServerDirectory + @"\backups\");

            //Force a save
            s.Save();
            s.DisableSaving();

            //Find all the directories that start with "world"
            if (Directory.Exists(Core.StoragePath + s.ServerID.ToString() + @"\backups\temp\")) Directory.Delete(Core.StoragePath + s.ServerID.ToString() + @"\backups\temp\", true);
            if (!Directory.Exists(Core.StoragePath + s.ServerID.ToString() + @"\backups\temp\")) Directory.CreateDirectory(Core.StoragePath + s.ServerID.ToString() + @"\backups\temp\");

            string[] dirs = Directory.GetDirectories(s.ServerDirectory, "world*");
            foreach (string dir in dirs)
            {
                //Copy world to a temp Dir
                DirectoryInfo thisDir = new DirectoryInfo(dir);
                Util.Copy(dir, s.ServerDirectory + @"\backups\temp\" + thisDir.Name);
            }

            //Re-enable saving then force another save
            s.EnableSaving();
            s.Save();

            //Now zip up temp dir and move to backups
            FastZip z = new FastZip();
            z.CreateEmptyDirectories = true;
            z.CreateZip(s.ServerDirectory + @"\backups\" + DateTime.Now.Year + "-" + DateTime.Now.Month.ToString("D2") + "-" + DateTime.Now.Day.ToString("D2") + "-" + DateTime.Now.Hour.ToString("D2") + "-" + DateTime.Now.Minute.ToString("D2") + strAppendName + ".zip", s.ServerDirectory + @"\backups\temp\", true, "");

            //If the server is empty, reset the HasChanged
            if (s.Players.Count == 0) s.HasChanged = false;
        }
开发者ID:rusnewman,项目名称:YAMS,代码行数:35,代码来源:Backup.cs

示例8: btnExport_Click

    protected void btnExport_Click(object sender, EventArgs e)
    {
        //try
        //{
        string zipFileName = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + @"\OSAE\OSA_Logs.zip";

            FastZip fastZip = new FastZip();
            if (File.Exists(zipFileName))
                File.Delete(zipFileName);

            fastZip.CreateZip(zipFileName, Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + @"\OSAE\Logs", true, "");

            Response.Clear();
            Response.ClearHeaders();
            Response.ClearContent();
            Response.AddHeader("Content-Disposition", "attachment; filename=OSA_Logs.zip");
            Response.AddHeader("Content-Length", new FileInfo(zipFileName).Length.ToString());
            Response.ContentType = "application/octet-stream";
            Response.Flush();
            Response.TransmitFile(zipFileName);
            Response.End();
        ///}
        //catch (Exception ex)
        //{
            // not going to do anything as the file may be in use so just carry on
        //}
    }
开发者ID:roboticowl,项目名称:Open-Source-Automation,代码行数:27,代码来源:logs.aspx.cs

示例9: MergeFile

 private static async Task MergeFile( MergeParams p ) {
     var zf = new FastZip();
     using ( var s = File.OpenWrite( p.DestImg ) ) {
         s.Seek( 0, SeekOrigin.End );
         zf.CreateZip( s, Path.GetDirectoryName( p.DataSource ), false, Path.GetFileName( p.DataSource ), "" );
     }
 }
开发者ID:EpicMorg,项目名称:EMRJT,代码行数:7,代码来源:Merger.cs

示例10: Program

        public Program()
        {
            string[] dirs=Directory.GetDirectories(".");
            foreach (string dir in dirs)
            {

                DataBase.AnimatedBitmap an = new DataBase.AnimatedBitmap();
                an._Name =Path.GetFileName(dir);
                foreach (string file in Directory.GetFiles(dir))
                    if (Regex.IsMatch(Path.GetExtension(file), "jpg|png", RegexOptions.IgnoreCase))
                        an._Bitmaps.Add(file.Replace(@"\", "/","./",""));

                if (an._Bitmaps.Count > 0)
                {
                    Image img = Bitmap.FromFile(an._Bitmaps.First());
                    an._Width = img.Width;
                    an._Height = img.Height;
                    _DataBase._AnimatedBitmaps.Add(an);

                }
            }
            Common._XmlSerializer.Serialize("./db.xml", _DataBase);

            FastZip _FastZip = new FastZip();
            _FastZip.CreateZip("content.zip","./",true,@"\.jpg|\.png|.\xml");
        }
开发者ID:vonhacker,项目名称:counterstrike,代码行数:26,代码来源:Program.cs

示例11: BackupNow

        public static void BackupNow(MCServer s)
        {
            Database.AddLog("Backing up " + s.ServerTitle, "backup");

            //Check for a backup dir and create if not
            if (!Directory.Exists(s.ServerDirectory + @"\backups\")) Directory.CreateDirectory(s.ServerDirectory + @"\backups\");

            //Force a save
            s.Save();
            s.DisableSaving();

            //Copy world to a temp Dir
            if (Directory.Exists(Core.StoragePath + s.ServerID.ToString() + @"\backups\temp\")) Directory.Delete(Core.StoragePath + s.ServerID.ToString() + @"\backups\temp\", true);
            if (!Directory.Exists(Core.StoragePath + s.ServerID.ToString() + @"\backups\temp\")) Directory.CreateDirectory(Core.StoragePath + s.ServerID.ToString() + @"\backups\temp\");
            Util.Copy(s.ServerDirectory + @"\world\", s.ServerDirectory + @"\backups\temp\");

            //Re-enable saving then force another save
            s.EnableSaving();
            s.Save();

            //Now zip up temp dir and move to backups
            FastZip z = new FastZip();
            z.CreateEmptyDirectories = true;
            z.CreateZip(s.ServerDirectory + @"\backups\" + DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + DateTime.Now.Day + "-" + DateTime.Now.Hour + "-" + DateTime.Now.Minute + ".zip", s.ServerDirectory + @"\backups\temp\", true, "");

            //If the server is empty, reset the HasChanged
            if (s.Players.Count == 0) s.HasChanged = false;
        }
开发者ID:Rawwar13,项目名称:YAMS,代码行数:28,代码来源:Backup.cs

示例12: gerarZipDiretorio

 public void gerarZipDiretorio(string sDiretorioOrigem, string sDiretorioDestino)
 {
     FastZip sz = new FastZip();
     try
     {
         string sArquivoZip = string.Empty;
         //Aqui vou criar um nome do arquivo.
         DateTime newDate = DateTime.Now;
         sArquivoZip = "MeuZip_" + Convert.ToString(newDate).Replace("/", "_").Replace(":", "") + ".zip";
         //Só um tratamento para garantir mais estabilidade
         if (sDiretorioOrigem.Substring(sDiretorioOrigem.Length - 2) != "\\" || sDiretorioDestino.Substring(sDiretorioDestino.Length - 2) != "\\")
         {
             sDiretorioOrigem = sDiretorioOrigem + "\\";
         }
         sz.Password = txtDiretorioZipSenha.Text;
         //Gera o ZIP
         sz.CreateZip(sDiretorioDestino + sArquivoZip, sDiretorioOrigem + "" + "\\", true, "", "");
     }
     catch (Exception ex)
     {
         MessageBox.Show("Ocorreu um erro durante o processo de compactação : " + ex);
     }
     finally
     {
         //Limpa o Objeto
         sz = null;
     }
 }
开发者ID:danygolden,项目名称:gianfratti,代码行数:28,代码来源:Form1.cs

示例13: ZipFolder

 /// <summary>
 /// 压缩文件夹
 /// </summary>
 /// <param name="_fileForlder">文件夹路径</param>
 /// <param name="_outZip">zip文件路径+名字</param>
 public void ZipFolder(string _fileFolder, string _outZip)
 {
     string directory = _outZip.Substring(0, _outZip.LastIndexOf('/'));
     if (!Directory.Exists(directory))
         Directory.CreateDirectory(directory);
     if (File.Exists(_outZip))
         File.Delete(_outZip);
     progress = progressOverall = 0;
     Thread thread = new Thread(delegate ()
     {
         int fileCount = FileCount(_fileFolder);
         int fileCompleted = 0;
         FastZipEvents events = new FastZipEvents();
         events.Progress = new ProgressHandler((object sender, ProgressEventArgs e) =>
         {
             progress = e.PercentComplete;
             if (progress == 100) { fileCompleted++; progressOverall = 100 * fileCompleted / fileCount; }
         });
         events.ProgressInterval = TimeSpan.FromSeconds(progressUpdateTime);
         events.ProcessFile = new ProcessFileHandler(
             (object sender, ScanEventArgs e) => { });
         FastZip fastZip = new FastZip(events);
         fastZip.CreateZip(_outZip, _fileFolder, true, "");
     });
     thread.IsBackground = true;
     thread.Start();
 }
开发者ID:hiramtan,项目名称:HiZip_unity,代码行数:32,代码来源:MyZip.cs

示例14: ZipFileDictory

        /// <summary>
        /// 压缩目录
        /// </summary>
        /// <param name="args">数组(数组[0]: 要压缩的目录; 数组[1]: 压缩的文件名)</param>
        public static void ZipFileDictory(string[] args)
        {
            try
            {
                FastZip fastZip = new FastZip();

                bool recurse = true;

                //压缩后的文件名,压缩目录 ,是否递归          

                //BZip2.Compress(File.OpenRead(args[0]),File.Create(args[1]),4096);     


                fastZip.CreateZip(args[1], args[0], recurse, "");

            }
            catch (Exception ex)
            {
                throw ex;
            }



            //string[] filenames = Directory.GetFiles(args[0]);

            //Crc32 crc = new Crc32();
            //ZipOutputStream s = new ZipOutputStream(File.Create(args[1]));
            //s.SetLevel(6);

            //foreach (string file in filenames)
            //{
            //    //打开压缩文件
            //    FileStream fs = File.OpenRead(file);

            //    byte[] buffer = new byte[fs.Length];
            //    fs.Read(buffer, 0, buffer.Length);
            //    ZipEntry entry = new ZipEntry(file);

            //    entry.DateTime = DateTime.Now;

            //    entry.Size = fs.Length;
            //    fs.Close();

            //    crc.Reset();
            //    crc.Update(buffer);

            //    entry.Crc = crc.Value;

            //    s.PutNextEntry(entry);

            //    s.Write(buffer, 0, buffer.Length);

            //}

            //s.Finish();
            //s.Close();
        }
开发者ID:XiaoQiJun,项目名称:BPS,代码行数:61,代码来源:ZipClass.cs

示例15: MergeDirectory

 private static async Task MergeDirectory( MergeParams p ) {
     using ( var s = File.OpenWrite( p.DestImg ) ) {
         s.Seek( 0, SeekOrigin.End );
         var zf = new FastZip {
             CreateEmptyDirectories = true
         };
         zf.CreateZip( s, Path.GetDirectoryName( p.DataSource ), true, "*", Path.GetFileName( p.DataSource ) );
     }
 }
开发者ID:EpicMorg,项目名称:EMRJT,代码行数:9,代码来源:Merger.cs


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