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


C# ZipFile.UpdateDirectory方法代码示例

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


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

示例1: _CreateHugeZipfiles


//.........这里部分代码省略.........
                // do this because creating such large files from nothing would take
                // a very very long time.
                if (CreateLinksToLargeFiles(dirToZip))
                    return null;

                Directory.SetCurrentDirectory(testDir); // again

                if (found == null || !found.Contains(0))
                {
                    // create a zip file, using WinZip
                    // This will take 50 minutes or so, no progress updates possible.
                    System.Threading.Thread.Sleep(220);
                    _txrx.Send("title Zip64 Create Huge Zip files"); // in case it was missed
                    System.Threading.Thread.Sleep(220);
                    _txrx.Send("pb 2 value 0");
                    zipFileToCreate = zipsToCreate[0];
                    zipsToCreate[0] = Path.Combine(testDir, zipsToCreate[0]);

                    // wzzip.exe will create a zip64 file automatically, as necessary.
                    // There is no explicit switch required.
                    // switches:
                    //   -a   add
                    //   -r   recurse
                    //   -p   store folder names
                    //   -yx  store extended timestamps
                    var sb1 = new System.Text.StringBuilder();
                    sb1.Append("-a -p -r -yx \"")
                        .Append(zipFileToCreate)
                        .Append("\" \"")
                        .Append(dirToZip)
                        .Append("\" ");

                    string args = sb1.ToString();
                    System.Threading.Thread.Sleep(220);
                    _txrx.Send("status wzzip.exe " + args);
                    TestContext.WriteLine("Exec: wzzip {0}", args);
                    string wzzipOut = this.Exec(wzzip, args);
                    TestContext.WriteLine("Done with wzzip.exe");
                    _txrx.Send("status wzzip.exe: Done");
                }

                if (found == null || !found.Contains(1))
                {
                    // Create a zip file using DotNetZip
                    // This will take 50 minutes or so.
                    // pb1 and pb2 will be set in the {Add,Save}Progress handlers
                    _txrx.Send("pb 0 step");
                    System.Threading.Thread.Sleep(120);
                    _txrx.Send("status Saving the zip...");
                    System.Threading.Thread.Sleep(120);
                    _txrx.Send(String.Format("pb 1 max {0}", numFilesToAdd + Directory.GetFiles(dirToZip).Length));
                    _testTitle = "Zip64 Create Huge Zip files"; // used in Zip64_SaveProgress
                    _pb1Set = false;
                    zipFileToCreate = Path.Combine(testDir, zipsToCreate[1]);
                    zipsToCreate[1] = zipFileToCreate;
                    using (ZipFile zip = new ZipFile())
                    {
                        zip.SaveProgress += Zip64SaveProgress;
                        zip.AddProgress += Zip64AddProgress;
                        zip.UpdateDirectory(dirToZip, "");
                        foreach (var e in zip)
                        {
                            if (e.FileName.EndsWith(".pst") ||
                                e.FileName.EndsWith(".ost") ||
                                e.FileName.EndsWith(".zip"))
                                e.CompressionMethod = CompressionMethod.None;
                        }

                        zip.UseZip64WhenSaving = Zip64Option.Always;
                        // use large buffer to speed up save for large files:
                        zip.BufferSize = 1024 * 756;
                        zip.CodecBufferSize = 1024 * 128;
                        zip.Save(zipFileToCreate);
                    }
                }

                _txrx.Send("pb 0 step");
                System.Threading.Thread.Sleep(120);

                // Delete the fodder dir only if we have both zips.
                // This is helpful when modifying or editing this method.
                // With repeated runs you don't have to re-create all the data
                // each time.
                if (File.Exists(zipsToCreate[0]) && File.Exists(zipsToCreate[1]))
                    Directory.Delete(dirToZip, true);

                _txrx.Send("pb 0 step");
                System.Threading.Thread.Sleep(120);

                _txrx.Send("stop");

                // restore the cwd:
                Directory.SetCurrentDirectory(originalDir);

                TestContext.WriteLine("All done - " +
                                  DateTime.Now.ToString("G"));

                return zipsToCreate;
            }
        }
开发者ID:mattleibow,项目名称:Zip.Portable,代码行数:101,代码来源:Zip64Tests.cs

示例2: Update_FromRoot_wi11988

        public void Update_FromRoot_wi11988()
        {
            string zipFileToCreate = "FromRoot.zip";
            string dirToZip = "Fodder";
            var files = TestUtilities.GenerateFilesFlat(dirToZip);
            string windir = System.Environment.GetEnvironmentVariable("Windir");
            string substExe = Path.Combine(Path.Combine(windir, "system32"), "subst.exe");
            Assert.IsTrue(File.Exists(substExe), "subst.exe does not exist ({0})",
                          substExe);

            try
            {
                // create a subst drive
                this.Exec(substExe, "G: " + dirToZip);

                using (var zip = new ZipFile())
                {
                    zip.UpdateDirectory("G:\\", "");
                    zip.Save(zipFileToCreate);
                }

                Assert.AreEqual<int>(TestUtilities.CountEntries(zipFileToCreate),
                                     files.Length);
                Assert.IsTrue(files.Length > 3);
                BasicVerifyZip(zipFileToCreate);
            }
            finally
            {
                // remove the virt drive
                this.Exec(substExe, "/D G:");
            }
        }
开发者ID:mattleibow,项目名称:Zip.Portable,代码行数:32,代码来源:UpdateTests.cs


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