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


C# Zip.ZipFile类代码示例

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


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

示例1: ImportActionShouldAddTestsToProblemIfZipFileIsCorrect

        public void ImportActionShouldAddTestsToProblemIfZipFileIsCorrect()
        {
            var zipFile = new ZipFile();

            var inputTest = "input";
            var outputTest = "output";

            zipFile.AddEntry("test.001.in.txt", inputTest);
            zipFile.AddEntry("test.001.out.txt", outputTest);

            var zipStream = new MemoryStream();
            zipFile.Save(zipStream);
            zipStream = new MemoryStream(zipStream.ToArray());

            this.File.Setup(x => x.ContentLength).Returns(1);
            this.File.Setup(x => x.FileName).Returns("file.zip");
            this.File.Setup(x => x.InputStream).Returns(zipStream);

            var redirectResult = this.TestsController.Import("1", this.File.Object, false, false) as RedirectToRouteResult;
            Assert.IsNotNull(redirectResult);

            Assert.AreEqual("Problem", redirectResult.RouteValues["action"]);
            Assert.AreEqual(1, redirectResult.RouteValues["id"]);

            var tests = this.Data.Problems.All().First(pr => pr.Id == 1).Tests.Count;
            Assert.AreEqual(14, tests);

            var tempDataHasKey = this.TestsController.TempData.ContainsKey(GlobalConstants.InfoMessage);
            Assert.IsTrue(tempDataHasKey);

            var tempDataMessage = this.TestsController.TempData[GlobalConstants.InfoMessage];
            Assert.AreEqual("Тестовете са добавени към задачата", tempDataMessage);
        }
开发者ID:yuanlukito-ti,项目名称:OpenJudgeSystem,代码行数:33,代码来源:ImportActionTests.cs

示例2: ResourceLoader

 protected ResourceLoader(string path, int cacheMb)
 {
     Path = path;
     Cache = new ResourceCache(cacheMb);
     Extractor = new ZipFile(path);
     BuildIndex();
 }
开发者ID:makesj,项目名称:vienna,代码行数:7,代码来源:ResourceLoader.cs

示例3: OnTestIonicZip

		void OnTestIonicZip()
		{
			var buffer = new byte[917504];
			foreach (var i in buffer)
			{
				buffer[i] = (byte)'a';
			}

			using (var zippedStream = new MemoryStream())
			{
				using (var zip = new ZipFile(Encoding.UTF8))
				{
					// uncommenting the following line can be used as a work-around
					// zip.ParallelDeflateThreshold = -1;
					zip.AddEntry("entry.txt", buffer);
					zip.Save(zippedStream);
				}
				zippedStream.Position = 0;

				using (var zip = ZipFile.Read(zippedStream))
				{
					using (var ms = new MemoryStream())
					{
						// This line throws a BadReadException
						zip.Entries.First().Extract(ms);
					}
				}
			}
		}
开发者ID:xbadcode,项目名称:Rubezh,代码行数:29,代码来源:DiagnosticsViewModel.cs

示例4: CollectLogFiles

    private static void CollectLogFiles(string dataPath, string outputPath, List<string> products)
    {
      if (!Directory.Exists(outputPath))
        Directory.CreateDirectory(outputPath);

      string targetFile = string.Format("MediaPortal2-Logs-{0}.zip", DateTime.Now.ToString("yyyy-MM-dd-HH.mm.ss"));
      targetFile = Path.Combine(outputPath, targetFile);
      if (File.Exists(targetFile))
        File.Delete(targetFile);

      ZipFile archive = new ZipFile(targetFile);
      foreach (var product in products)
      {
        string sourceFolder = Path.Combine(dataPath, @"Team MediaPortal", product, "Log");
        if (!Directory.Exists(sourceFolder))
        {
          Console.WriteLine("Skipping non-existant folder {0}", sourceFolder);
          continue;
        }
        Console.WriteLine("Adding folder {0}", sourceFolder);
        try
        {
          archive.AddDirectory(sourceFolder, product);
        }
        catch (Exception ex)
        {
          Console.WriteLine("Error adding folder {0}: {1}", sourceFolder, ex);
        }
      }
      archive.Save();
      archive.Dispose();
      Console.WriteLine("Successful created log archive: {0}", targetFile);

      Process.Start(outputPath); // Opens output folder
    }
开发者ID:davinx,项目名称:MediaPortal-2,代码行数:35,代码来源:Program.cs

示例5: Main

        public static int Main(string[] args)
        {
            var options = new Options();

            if (!ParseCommandLineOptions(args, options))
                return 1;

            if (options.OutputDir == null)
                options.OutputDir = options.PackageDir;

            if (!Directory.Exists(options.OutputDir))
                Directory.CreateDirectory(options.OutputDir);

            var packageDllName = options.PackageName + ".dll";
            var packageArchiveName = options.PackageName + ".0.0.0.fld";
            var packageDllPath = Path.Combine(options.PackageDir, packageDllName);
            var packageArchivePath = Path.Combine(options.OutputDir, packageArchiveName);

            //Generate RPC classes
            if (!RemotingGen.Program.Generate(packageDllPath, options.PackageDir, false))
                return 1;

            //Create an archive
            using (var zip = new ZipFile())
            {
                zip.AddDirectory(options.PackageDir, "");
                zip.Save(packageArchivePath);
            }

            return 0;
        }
开发者ID:FloodProject,项目名称:flood,代码行数:31,代码来源:Program.cs

示例6: DoubleZipFileContent

        public static void DoubleZipFileContent(string folderSource, string fileDest, string password)
        {
            using (var zip = new ZipFile())
            {
                zip.AlternateEncoding = Encoding.UTF8;
                zip.AlternateEncodingUsage = ZipOption.Always;

                zip.Password = password;
                zip.Encryption = EncryptionAlgorithm.WinZipAes128;
                zip.AddDirectory(folderSource);
                zip.Save(Path.Combine(folderSource, "content.zip"));
            }

            using (var doubleZip = new ZipFile())
            {
                doubleZip.AlternateEncoding = Encoding.UTF8;
                doubleZip.AlternateEncodingUsage = ZipOption.Always;

                doubleZip.Password = password;
                doubleZip.Encryption = EncryptionAlgorithm.WinZipAes128;
                doubleZip.AddFile(Path.Combine(folderSource, "content.zip"), "");
                doubleZip.Save(fileDest);
            }

            if (File.Exists(Path.Combine(folderSource, "content.zip")))
                File.Delete(Path.Combine(folderSource, "content.zip"));
        }
开发者ID:yetanothervan,项目名称:conspector,代码行数:27,代码来源:ZipHelper.cs

示例7: extractIPA

 public static String extractIPA(IPAInfo info)
 {
     using (ZipFile ipa = ZipFile.Read(info.Location))
     {
         Debug("IPALocation: " + info.Location);
         Debug("Payload location: " + info.BinaryLocation);
         foreach (ZipEntry e in ipa)
         {
             //Debug ("file:" + e.FileName);
             if (e.FileName.Contains(".sinf") || e.FileName.Contains(".supp"))
             {
                 //extract it
                 Debug(GetTemporaryDirectory());
                 e.Extract(GetTemporaryDirectory(), ExtractExistingFileAction.OverwriteSilently);
             }
             else if (e.FileName == info.BinaryLocation)
             {
                 Debug("found binary!!");
                 e.Extract(GetTemporaryDirectory(), ExtractExistingFileAction.OverwriteSilently);
             }
         }
     }
     //zip!
     String AppDirectory = Path.Combine(GetTemporaryDirectory(), "Payload");
     Debug("AppDirectory: " + AppDirectory);
     //return null;
     String ZipPath = Path.Combine(GetTemporaryDirectory(), "upload.ipa");
     using (ZipFile zip = new ZipFile())
     {
         zip.CompressionLevel = Ionic.Zlib.CompressionLevel.None;
         zip.AddDirectory(AppDirectory);
         zip.Save(ZipPath);
     }
     return ZipPath;
 }
开发者ID:koufengwei,项目名称:Brake,代码行数:35,代码来源:AppHelper.cs

示例8: Open

 public override void Open(string file)
 {
     zf = ZipFile.Read (file);
     Pages = zf.Where (entry => (!entry.IsDirectory && IsValidImage (entry.FileName)))
         .OrderBy (e => e.FileName)
         .Select (e => new ZipPage (e)).ToList<Page> ();
 }
开发者ID:adamhathcock,项目名称:comictoolx,代码行数:7,代码来源:ZipComic.cs

示例9: OpenSceneFile

        /// <summary>
        /// Opens a file in preparation for writing a series of image entries
        /// should load the manifest so we can add / remove entries from it
        /// </summary>
        /// <returns></returns>
        public bool OpenSceneFile(string scenefilename) 
        {
            try
            {
                mZip = ZipFile.Read(scenefilename);
                //open the manifest file                
                string xmlname = "manifest.xml";
                ZipEntry manifestentry = mZip[xmlname];
                //get memory stream
                MemoryStream manistream = new MemoryStream();
                //extract the stream
                manifestentry.Extract(manistream);
                //read from stream
                manistream.Seek(0, SeekOrigin.Begin); // rewind the stream for reading
                //create a new XMLHelper to load the stream into
                mManifest = new XmlHelper();
                //load the stream
                mManifest.LoadFromStream(manistream, "manifest");

                return true;
            }
            catch (Exception ex) 
            {
                DebugLogger.Instance().LogError(ex);
            }
            return false;
        }
开发者ID:newtalk,项目名称:UVDLPSlicerController,代码行数:32,代码来源:SceneFile.cs

示例10: CreatePackage

        public bool CreatePackage(string filename, bool includeWalkthrough, out string error)
        {
            error = string.Empty;

            try
            {
                string data = m_worldModel.Save(SaveMode.Package, includeWalkthrough);
                string baseFolder = System.IO.Path.GetDirectoryName(m_worldModel.Filename);

                using (ZipFile zip = new ZipFile(filename))
                {
                    zip.AddEntry("game.aslx", data, Encoding.UTF8);
                    foreach (string file in m_worldModel.GetAvailableExternalFiles("*.jpg;*.jpeg;*.png;*.gif;*.js;*.wav;*.mp3;*.htm;*.html"))
                    {
                        zip.AddFile(System.IO.Path.Combine(baseFolder, file), "");
                    }
                    AddLibraryResources(zip, baseFolder, ElementType.Javascript);
                    AddLibraryResources(zip, baseFolder, ElementType.Resource);
                    zip.Save();
                }
            }
            catch (Exception ex)
            {
                error = ex.Message;
                return false;
            }

            return true;
        }
开发者ID:JatinR,项目名称:quest,代码行数:29,代码来源:Packager.cs

示例11: BuildDlls

 /// <summary>
 /// Builds the DLL with the latest class files to ensure it's up to date.
 /// Adds the 51Degrees and Sitecore interface DLL to the package.
 /// </summary>
 /// <param name="package"></param>
 /// <param name="projectFile"></param>
 private static void BuildDlls(ZipFile package, FileInfo projectFile)
 {
     var outputPath = Path.Combine(
     Path.GetTempPath(),
     "Sitecore.SharedSource.MobileDeviceDetector");
       Directory.CreateDirectory(outputPath);
       var msBuildPath = Path.Combine(RuntimeEnvironment.GetRuntimeDirectory(), "msbuild.exe");
       var startInfo = new ProcessStartInfo(msBuildPath)
       {
     Arguments = string.Format(
       @"""{0}"" /t:rebuild /p:Configuration=Release /p:OutputPath=""{1}""",
       projectFile.FullName,
       outputPath),
     WorkingDirectory = Path.GetDirectoryName(msBuildPath),
     RedirectStandardOutput = true,
     RedirectStandardError = true,
     UseShellExecute = false
       };
       Console.WriteLine("> msbuild " + startInfo.Arguments);
       var process = Process.Start(startInfo);
       Console.Write(process.StandardOutput.ReadToEnd());
       process.WaitForExit();
       AddDll(package,
     outputPath,
     "Sitecore.SharedSource.MobileDeviceDetector.dll");
       AddDll(package,
     outputPath,
     "FiftyOne.Foundation.dll");
       Directory.Delete(outputPath, true);
 }
开发者ID:3chillies,项目名称:Sitecore-Device-Detector,代码行数:36,代码来源:GeneratePackage.cs

示例12: CreateSolution

        public string CreateSolution(IBuildBootstrappedSolutions bootstrapper, SolutionConfiguration configuration)
        {
            configuration.InCodeSubscriptions = true;
            foreach (var endpointConfiguration in configuration.EndpointConfigurations)
            {
                endpointConfiguration.InCodeSubscriptions = configuration.InCodeSubscriptions;
            }

            var solutionData = bootstrapper.BootstrapSolution(configuration);

            var solutionDirectory = SavePath + Guid.NewGuid();

            var solutionFile = SaveSolution(solutionDirectory, solutionData);

            InstallNuGetPackages(solutionDirectory, solutionData, solutionFile, NuGetExe);

            //AddReferencesToNugetPackages(solutionDirectory);

            var zipFilePath = solutionFile.Replace(".sln", ".zip");

            using (var zip = new ZipFile())
            {
                zip.AddDirectory(solutionDirectory, "Solution");
                zip.Save(zipFilePath);
            }

            return zipFilePath;
        }
开发者ID:ParticularLabs,项目名称:NServiceBus.Launchpad,代码行数:28,代码来源:SolutionSaver.cs

示例13: FolderToZip

 public void FolderToZip(string sourceDir, string path)
 {
     using (var surveyBackup = new ZipFile()) {
         surveyBackup.AddDirectory(sourceDir);
         surveyBackup.Save(path);
     }
 }
开发者ID:wurdum,项目名称:deployer,代码行数:7,代码来源:PackageManager.cs

示例14: Write

 // ---------------------------------------------------------------------------
 public void Write(Stream stream)
 {
     // Use old example to create PDF
     MovieTemplates mt = new MovieTemplates();
     byte[] pdf = Utility.PdfBytes(mt);
     using (ZipFile zip = new ZipFile())
     {
         using (MemoryStream ms = new MemoryStream())
         {
             // step 1
             using (Document document = new Document())
             {
                 // step 2
                 PdfWriter writer = PdfWriter.GetInstance(document, ms);
                 // step 3
                 document.Open();
                 // step 4
                 PdfPTable table = new PdfPTable(2);
                 PdfReader reader = new PdfReader(pdf);
                 int n = reader.NumberOfPages;
                 PdfImportedPage page;
                 for (int i = 1; i <= n; i++)
                 {
                     page = writer.GetImportedPage(reader, i);
                     table.AddCell(Image.GetInstance(page));
                 }
                 document.Add(table);
             }
             zip.AddEntry(RESULT, ms.ToArray());
         }
         zip.AddEntry(Utility.ResultFileName(mt.ToString() + ".pdf"), pdf);
         zip.Save(stream);
     }
 }
开发者ID:kuujinbo,项目名称:iTextInAction2Ed,代码行数:35,代码来源:ImportingPages1.cs

示例15: LoadTGATextures

        private void LoadTGATextures(ZipFile pk3)
        {
            foreach (Texture tex in Textures)
            {
                // The size of the new Texture2D object doesn't matter. It will be replaced (including its size) with the data from the texture that's getting pulled from the pk3 file.
                if (pk3.ContainsEntry(tex.Name + ".tga"))
                {
                    Texture2D readyTex = new Texture2D(4, 4);
                    var entry = pk3 [tex.Name + ".tga"];
                    using (var stream = entry.OpenReader())
                    {
                        var ms = new MemoryStream();
                        entry.Extract(ms);
                        readyTex = TGALoader.LoadTGA(ms);
                    }

                    readyTex.name = tex.Name;
                    readyTex.filterMode = FilterMode.Trilinear;
                    readyTex.Compress(true);

                    if (readyTextures.ContainsKey(tex.Name))
                    {
                        Debug.Log("Updating texture with name " + tex.Name + ".tga");
                        readyTextures [tex.Name] = readyTex;
                    } else
                        readyTextures.Add(tex.Name, readyTex);
                }
            }
        }
开发者ID:kungfooman,项目名称:uQuake3,代码行数:29,代码来源:TextureLump.cs


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