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


C# ZipFile.ContainsEntry方法代码示例

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


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

示例1: LoadModInfo

 //TODO: Clean this up
 private void LoadModInfo()
 {
     if (this.IsZip == true)
     {
         string entrypath;
         ZipFile zip = new ZipFile(this.Path);
         
         entrypath = "readme.txt";
         if (zip.ContainsEntry(entrypath))
         {
             MemoryStream stream = new MemoryStream();
             zip[entrypath].Extract(stream);
             stream.Position = 0;
             var sr = new StreamReader(stream);
             this.Text = sr.ReadToEnd();
         }
         entrypath = "picture.png";
         if (zip.ContainsEntry(entrypath))
         {
             MemoryStream stream = new MemoryStream();
             zip[entrypath].Extract(stream);
             //stream.Position = 0;
             this.Image = System.Drawing.Image.FromStream(stream);
         }
     }
     else
     {
         string filepath;
         //Look for mod description
         filepath = this.Path + "readme.txt";
         if (File.Exists(filepath))
         {
             this.Text = File.ReadAllText(filepath);
         }
         else
         {
             string[] files = Directory.GetFiles(this.Path, "*.txt");
             foreach (string fpath in files)
             {
                 if (File.Exists(fpath))
                 {
                     this.Text = File.ReadAllText(fpath);
                     break;
                 }
             }
         }
         //Look for mod picture
         //TODO: Look for .jpg and also any picture if 'picture.png' is not found.
         filepath = this.Path + "picture.png";
         if (File.Exists(filepath))
         {
             this.Image = System.Drawing.Image.FromFile(filepath);
         }
     }
 }
开发者ID:Worst-vd-plas,项目名称:Patchlunky,代码行数:56,代码来源:Mods.cs

示例2: GetFileStream

 protected override Stream GetFileStream(string file, string path)
 {
     ZipFile zip = new ZipFile(file + ".mod");
     if (!zip.ContainsEntry(path)) throw new ArgumentException("File " + path.ToString() + " Does not exist in mod!");
     ZipEntry entry = zip[path];
     return entry.OpenReader();
 }
开发者ID:RoyAwesome,项目名称:Watertight-Engine,代码行数:7,代码来源:FileSystemPath.cs

示例3: LoadJPGTextures

 private void LoadJPGTextures(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 .jpg texture that's getting pulled from the pk3 file.
         if (pk3.ContainsEntry(tex.Name + ".jpg"))
         {
             Texture2D readyTex = new Texture2D(4, 4);
             var entry = pk3 [tex.Name + ".jpg"];
             using (var stream = entry.OpenReader())
             {
                 var ms = new MemoryStream();
                 entry.Extract(ms);
                 readyTex.LoadImage(ms.GetBuffer());
             }
             
             readyTex.name = tex.Name;
             readyTex.filterMode = FilterMode.Trilinear;
             readyTex.Compress(true);
             
             if (readyTextures.ContainsKey(tex.Name))
             {
                 Debug.Log("Updating texture with name " + tex.Name);
                 readyTextures [tex.Name] = readyTex;
             } else
                 readyTextures.Add(tex.Name, readyTex);
         }
     }
 }
开发者ID:kungfooman,项目名称:uQuake3,代码行数:29,代码来源:TextureLump.cs

示例4: GetModInfoFromTapiZip

        ModInfo GetModInfoFromTapiZip(ZipFile zf)
        {
            if (zf.ContainsEntry("ModInfo.json"))
            {
                ZipEntry ze = zf["ModInfo.json"];

                using (MemoryStream ms = new MemoryStream())
                {
                    ze.Extract(ms);

                    StreamReader r = new StreamReader(ms);

                    ModInfo mi = new ModInfo(Compiler) { checkCircularRefs = false };

                    var err = mi.CreateAndValidate(new JsonFile(zf.Name, JsonMapper.ToObject(r.ReadToEnd())));

                    if (!Compiler.CreateOutput(err.ToList()).Succeeded)
                        return null;

                    return mi;
                }
            }

            if (zf.ContainsEntry("Mod.tapimod"))
                using (MemoryStream ms = new MemoryStream())
                {
                    return GetModInfoFromTapiMod(ms.ToArray());
                }

            return null;
        }
开发者ID:mugmickey,项目名称:PoroCYon.MCT,代码行数:31,代码来源:ModInfo.cs

示例5: AddPackageContents

 public static void AddPackageContents(string sourcePackage, string additionalPackage, string uniquPackageName1)
 {
     using (var zip = new ZipFile(sourcePackage))
     {
         using (var zip2 = new ZipFile(additionalPackage))
         {
             foreach (var entry in zip2)
             {
                 try
                 {
                     if (! zip.ContainsEntry(entry.FileName))
                     {
                         var entry1 = zip.AddEntry(entry.FileName, entry.OpenReader());
                         if (entry.FileName == "package.config")
                             entry1.FileName = uniquPackageName1 + ".config";
                         zip.Save();
                     }
                 }
                 catch (Exception e)
                 {
                     Console.WriteLine(e);
                 }
             }
             //zip.Save();
         }
     }
 }
开发者ID:CloudMorph,项目名称:CloudMorph,代码行数:27,代码来源:PackageCompressor.cs

示例6: ExistsInPath

 protected override bool ExistsInPath(string file, string path)
 {
     using(ZipFile zip = new ZipFile(file + ".mod"))
     {
         return zip.ContainsEntry(path);
     }
 }
开发者ID:RoyAwesome,项目名称:Watertight-Engine,代码行数:7,代码来源:FileSystemPath.cs

示例7: UnzipFilesWithManifest

        /// <summary>
        /// Given the target folder, it will unzip any zips, and then send folders with imsmanifest.xml into manifest parser.
        /// </summary>
        /// <param name="topDirectory"></param>
        /// <param name="reportFile"></param>
        public static void UnzipFilesWithManifest(string topDirectory)
        {
            string[] zipsList = Directory.GetFiles(topDirectory, "*.zip");
            string extractionDestination;

            // Extract zips --------------------------------------------------------------------------------
            if (zipsList.Length > 0)
            {
                Console.WriteLine("---------- EXTRACTING ZIPS           ----------\n");
                for (int i = 0; i < zipsList.Length; i++)
                {
                    ZipFile zipFolder = new ZipFile(zipsList[i]);
                    // Generate extact folder name
                    extractionDestination = zipFolder.Name.Replace(".zip", "");

                    // If that folder already exists, skip
                    if (!Directory.Exists(extractionDestination))
                    {
                        Console.WriteLine("About to extract  " + zipFolder.Name);
                        // If the zipFile doesn't have the manifest, don't extract. There won't be a manifest to parse
                        if (zipFolder.ContainsEntry("imsmanifest.xml"))
                        {
                            zipFolder.ExtractAll(extractionDestination);
                            Console.WriteLine("\tExtracted " + zipFolder.Name + "\n");
                        }
                        else
                        {
                            Console.WriteLine("\tManifest file was not found\n");
                        }
                    }
                }
                Console.WriteLine("---------- FINISHED EXTRACTING ZIPS  ----------\n\n");
            }
        }
开发者ID:babyworm1,项目名称:CourseAuditorC-,代码行数:39,代码来源:CourseAuditor.cs

示例8: PebbleBundle

        /// <summary>
        /// Create a new PebbleBundle from a .pwb file and parse its metadata.
        /// </summary>
        /// <param name="path">The relative or full path to the file.</param>
        public PebbleBundle(String path)
        {
            Stream jsonstream;
            Stream binstream;

            FullPath = Path.GetFullPath(path);
            Bundle = ZipFile.Read(FullPath);

            if (Bundle.ContainsEntry("manifest.json"))
            {
                jsonstream = Bundle["manifest.json"].OpenReader();
            }
            else
            {
                throw new ArgumentException("manifest.json not found in archive - not a Pebble bundle.");
            }

            var serializer = new DataContractJsonSerializer(typeof(BundleManifest));

            Manifest = serializer.ReadObject(jsonstream) as BundleManifest;
            jsonstream.Close();

            HasResources = (Manifest.Resources.Size != 0);

            if (Manifest.Type == "firmware")
            {
                BundleType = BundleTypes.Firmware;
            }
            else
            {
                BundleType = BundleTypes.Application;
                if (Bundle.ContainsEntry(Manifest.Application.Filename))
                {
                    binstream = Bundle[Manifest.Application.Filename].OpenReader();
                }
                else
                {
                    String format = "App file {0} not found in archive";
                    throw new ArgumentException(String.Format(format, Manifest.Application.Filename));
                }

                Application = Util.ReadStruct<ApplicationMetadata>(binstream);
                binstream.Close();
            }
        }
开发者ID:peterrus,项目名称:flint,代码行数:49,代码来源:PebbleBundle.cs

示例9: GetLayoutSamples

        public virtual IEnumerable<LayoutSample> GetLayoutSamples(string engineName)
        {
            var itemTemplates = this.All(engineName);

            foreach (var item in itemTemplates)
            {
                using (ZipFile zipFile = new ZipFile(item.TemplateFile))
                {
                    var settingEntryName = PathResource.SettingFileName;
                    if (!zipFile.ContainsEntry(settingEntryName))
                    {
                        throw new KoobooException("The layout item template is invalid, setting.config is required.");
                    }
                    Layout layout = null;
                    using (MemoryStream ms = new MemoryStream())
                    {
                        zipFile[settingEntryName].Extract(ms);
                        ms.Position = 0;
                        layout = (Layout)Kooboo.Runtime.Serialization.DataContractSerializationHelper.Deserialize(typeof(Layout), null, ms);
                    }
                    var templateEntryName = layout.TemplateFileName;
                    if (!zipFile.ContainsEntry(templateEntryName))
                    {
                        throw new KoobooException(string.Format("The layout item template is invalid.{0} is requried.", templateEntryName));
                    }
                    LayoutSample sample = new LayoutSample() { Name = item.TemplateName, ThumbnailVirtualPath = item.Thumbnail };
                    using (MemoryStream ms = new MemoryStream())
                    {
                        zipFile[templateEntryName].Extract(ms);
                        ms.Position = 0;
                        using (StreamReader sr = new StreamReader(ms))
                        {
                            sample.Template = sr.ReadToEnd();
                        }
                    }
                    yield return sample;
                }
            }
        }
开发者ID:Godoy,项目名称:CMS,代码行数:39,代码来源:LayoutItemTemplateManager.cs

示例10: ReadFileFromZip

 public static byte[] ReadFileFromZip(ZipFile zip, string filename)
 {
     if (zip.ContainsEntry (filename)) {
         var entry = zip.FirstOrDefault (x => x.FileName == filename);
         if (entry != null) {
             using (var ms = new MemoryStream ()) {
                 entry.Extract (ms);
                 return ms.ToArray ();
             }
         }
     }
     return null;
 }
开发者ID:yudhitech,项目名称:xamarin-android,代码行数:13,代码来源:ZipHelper.cs

示例11: TestZipDirectory

        public void TestZipDirectory()
        {
            //create three directories in our zip dir
            string zipDir = Path.Combine(TestContext.TestDeploymentDir, "zipDir");
            string zipInner1Dir = Path.Combine(zipDir, "testDir1");
            string zipInner2Dir = Path.Combine(zipDir, "testDir2");
            string zipInner3Dir = Path.Combine(zipDir, "testDir3");
            string zipInnerInner3Dir = Path.Combine(zipInner2Dir, "testDir3");
            string zipInnerInner4Dir = Path.Combine(zipInner2Dir, "testDir4");

            Directory.CreateDirectory(zipDir);
            Directory.CreateDirectory(zipInner1Dir);
            Directory.CreateDirectory(zipInner2Dir);
            Directory.CreateDirectory(zipInner3Dir);
            Directory.CreateDirectory(zipInnerInner3Dir);
            Directory.CreateDirectory(zipInnerInner4Dir);

            //zip but exclude some of the dirs
            IZip zip = new DotNetZipAdapter();
            using (MemoryStream ms = zip.ZipDirectory(zipDir, String.Format("{0};{1};{2}", "\\testDir1", "/testDir3", "/testDir2/testDir4")))
            {
                string zipPath = Path.Combine(TestContext.TestDir, "test.zip");
                ms.Position = 0;
                byte[] buff = new byte[ms.Length];
                ms.Read(buff, 0, buff.Length);
                File.WriteAllBytes(zipPath, buff);

                //make sure testDir2 and testDir2//testDir3 are only dir in zip file
                using (ZipFile z = new ZipFile(zipPath))
                {
                    Assert.IsTrue(z.ContainsEntry("testDir2/"));
                    Assert.IsTrue(z.ContainsEntry("testDir2/testDir3/"));
                    Assert.IsTrue(!z.ContainsEntry("testDir1/"));
                    Assert.IsTrue(!z.ContainsEntry("testDir3/"));
                    Assert.IsTrue(!z.ContainsEntry("testDir2/testDir4/"));
                }//end using
            }//end using
        }
开发者ID:dianasp,项目名称:TriggerStandaloneBuild,代码行数:38,代码来源:DotNetZipAdapterTest.cs

示例12: WhenIProduceAPackageAndAskForAZipFile_IShouldRecieveAZipFile

        public void WhenIProduceAPackageAndAskForAZipFile_IShouldRecieveAZipFile()
        {
            ClearFolders(_oldFolderLocation, _newFolderLocation, _patchFolderLocation);
            AddFileToFolder(_newFolderLocation, "addFile.txt");
            Directory.CreateDirectory(_oldFolderLocation);
            var patchFileLocation = _patchFolderLocation + "\\patch.zip";
            KaBlooeyEngine.CreatePatchIntoZip(_oldFolderLocation, _newFolderLocation, patchFileLocation);

            var result = File.Exists(patchFileLocation);
            Assert.AreEqual(true, result);

            using (Ionic.Zip.ZipFile file = new ZipFile(patchFileLocation))
            {
                Assert.IsTrue(file.ContainsEntry("addFile.txt.add"));
            }
        }
开发者ID:bsmithb2,项目名称:KaBlooey,代码行数:16,代码来源:KaBlooeyPackageAndZipTests.cs

示例13: LoadTerrainTextures

 public static void LoadTerrainTextures()
 {
     // TODO: This only works on 1.4.7 and earlier
     Bitmap terrain;
     if (File.Exists("terrain.png"))
         terrain = (Bitmap)Image.FromFile("terrain.png");
     else
     {
         if (File.Exists(Path.Combine(DotMinecraft.GetDotMinecraftPath(), "bin", "minecraft.jar")))
         {
             using (var file = new ZipFile(Path.Combine(DotMinecraft.GetDotMinecraftPath(), "bin", "minecraft.jar")))
             {
                 if (file.ContainsEntry("terrain.png"))
                 {
                     var ms = new MemoryStream();
                     file["terrain.png"].Extract(ms);
                     ms.Seek(0, SeekOrigin.Begin);
                     terrain = (Bitmap)Image.FromStream(ms);
                 }
                 else
                     throw new FileNotFoundException("Missing terrain.png!");
             }
         }
         else
             throw new FileNotFoundException("Missing terrain.png!");
     }
     // Load into OpenGL
     TerrainId = GL.GenTexture();
     GL.BindTexture(TextureTarget.Texture2D, TerrainId);
     var data = terrain.LockBits(new Rectangle(0, 0, terrain.Width, terrain.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
     GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, data.Width, data.Height,
         0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, data.Scan0);
     terrain.UnlockBits(data);
     // Disable mipmaps?
     GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
     GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
 }
开发者ID:Mateus7G,项目名称:Crafty,代码行数:37,代码来源:Textures.cs

示例14: DownloadAllZipped

        private void DownloadAllZipped(int message_id, HttpContext context)
        {
            var mail_box_manager = new MailBoxManager(0);

            var attachments = mail_box_manager.GetMessageAttachments(TenantId, Username, message_id);

            if (attachments.Any())
            {
                using (var zip = new ZipFile())
                {
                    zip.CompressionLevel = CompressionLevel.Level3;
                    zip.AlternateEncodingUsage = ZipOption.AsNecessary;
                    zip.AlternateEncoding = Encoding.GetEncoding(Thread.CurrentThread.CurrentCulture.TextInfo.OEMCodePage);

                    foreach (var attachment in attachments)
                    {
                        using (var file = AttachmentManager.GetAttachmentStream(attachment))
                        {
                            var filename = file.FileName;

                            if (zip.ContainsEntry(filename))
                            {
                                var counter = 1;
                                var temp_name = filename;
                                while (zip.ContainsEntry(temp_name))
                                {
                                    temp_name = filename;
                                    var suffix = " (" + counter + ")";
                                    temp_name = 0 < temp_name.IndexOf('.')
                                                   ? temp_name.Insert(temp_name.LastIndexOf('.'), suffix)
                                                   : temp_name + suffix;

                                    counter++;
                                }
                                filename = temp_name;
                            }

                            zip.AddEntry(filename, file.FileStream.GetCorrectBuffer());
                        }
                    }

                    context.Response.AddHeader("Content-Disposition", ContentDispositionUtil.GetHeaderValue(ArchiveName));

                    zip.Save(context.Response.OutputStream);

                }

            }
        }
开发者ID:haoasqui,项目名称:ONLYOFFICE-Server,代码行数:49,代码来源:DownloadAll.ashx.cs

示例15: HasZipEntry

 private bool HasZipEntry(string filename)
 {
     using (var file = new ZipFile(_zipFile))
       {
     return file.ContainsEntry(filename);
       }
 }
开发者ID:leloulight,项目名称:magicgrove,代码行数:7,代码来源:ResourceFolder.cs


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