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


C# ZipFile.RemoveEntry方法代码示例

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


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

示例1: Handle

        protected override OperationResult Handle(ZipEntry entry, ZipFile zip)
        {
            string orig = entry.FileName;
            string stripped = GetStripped(entry.FileName);
            if (stripped == null)
            {
                if (entry.IsDirectory)
                {
                    zip.RemoveEntry(entry);
                    return OperationResult.Removed;
                }

                stripped = orig;
            }

            try
            {
                entry.FileName = stripped;
                return OperationResult.Changed;
            }
            catch (Exception ex)
            {
                string type = entry.IsDirectory ? "directory" : "file";
                throw new Exception(string.Format("Could not rename {0} '{1}' to '{2}'", type, orig, stripped), ex);
            }
        }
开发者ID:tgmayfield,项目名称:zip-dir-strip,代码行数:26,代码来源:DirStripOperation.cs

示例2: 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

示例3: Delete

 public override void Delete(Guid id)
 {
     using(var zip = new ZipFile(Path))
     {
         zip.RemoveEntry(id + ".xml");
         zip.Save();
     }
 }
开发者ID:stevenbey,项目名称:elfar,代码行数:8,代码来源:ZipErrorLogProvider.cs

示例4: Handle

        protected override OperationResult Handle(ZipEntry entry, ZipFile zip)
        {
            if (_regex.IsMatch(entry.FileName))
            {
                zip.RemoveEntry(entry);
                return OperationResult.Removed;
            }

            return OperationResult.NoChange;
        }
开发者ID:tgmayfield,项目名称:zip-dir-strip,代码行数:10,代码来源:RemoveOperation.cs

示例5: AddConfigurationToZip

		static void AddConfigurationToZip(ZipFile zipFile, VersionedConfiguration versionedConfiguration, string fileName)
		{
			var configuarationMemoryStream = ZipSerializeHelper.Serialize(versionedConfiguration);
			if (zipFile.Entries.Any(x => x.FileName == fileName))
			{
				zipFile.RemoveEntry(fileName);
			}
			configuarationMemoryStream.Position = 0;
			zipFile.AddEntry(fileName, configuarationMemoryStream);
		}
开发者ID:saeednazari,项目名称:Rubezh,代码行数:10,代码来源:XDeviceLibraryConfigurationPatchHelper.cs

示例6: IntoZip

		public static void IntoZip(string fileName, MemoryStream stream)
		{
			var path = ".\\Configuration\\";
			var zipName = "config.fscp";
			var filePath = path + fileName;
			var zipPath = path + zipName;
			var zip = new ZipFile(zipPath);
			if (zip.Entries.FirstOrDefault(x => x.FileName == fileName) != null)
				zip.RemoveEntry(fileName);
			stream.Position = 0;
			zip.AddEntry(fileName, stream);
			zip.Save(zipPath);
		}
开发者ID:saeednazari,项目名称:Rubezh,代码行数:13,代码来源:ZipConfigHelper.cs

示例7: ExecuteTransformationOnArchive

        private static void ExecuteTransformationOnArchive(
            ZipFile zippedXapFile, 
            string targetEnvironment,                                                           
            string silverlightEnvironmentTransformFile)
        {
            zippedXapFile[SILVERLIGHT_CONFIG_FILE].Extract(_platformTempFilePath);
            zippedXapFile[silverlightEnvironmentTransformFile].Extract(_platformTempFilePath);

            new MsBuildConfigTransform().ExecuteTransformation(targetEnvironment, _platformTempFilePath);

            zippedXapFile.RemoveEntry(SILVERLIGHT_CONFIG_FILE);
            zippedXapFile.AddFile(Path.Combine(_platformTempFilePath, SILVERLIGHT_CONFIG_FILE), "");
            zippedXapFile.Save();
        }
开发者ID:splant,项目名称:XAPConfigTransformer,代码行数:14,代码来源:Program.cs

示例8: MakeModpack

        public void MakeModpack()
        {
            String[] fileList = Directory.GetFiles(tmp, "*", SearchOption.AllDirectories);

            using (Ionic.Zip.ZipFile zip = new Ionic.Zip.ZipFile(mcFile)) {
                foreach (String file in fileList) {
                    String newFile = file.Substring(tmp.Length);
                    Console.WriteLine(newFile);
                    if (zip.ContainsEntry(newFile))
                        zip.RemoveEntry(newFile);
                    zip.AddFile(file, Path.GetDirectoryName(newFile));
                }
                zip.Save();
                MessageBox.Show("Done...");
            }
               /* using (ZipArchive zip = System.IO.Compression.ZipFile.Open(mcFile, ZipArchiveMode.Update)) {
                foreach (String file in fileList) {
                    var fileInZip = (from f in zip.Entries
                                     where f.Name == Path.GetFileName(file)
                                     select f).FirstOrDefault();
                    if (fileInZip != null)
                        fileInZip.Delete();
                    zip.CreateEntryFromFile(file, file.Remove(0, tmp.Length), CompressionLevel.Optimal);
                }
            }*/

            //ZipFile zip = new ZipFile(Path.Combine(path, ".minecraft" + Path.DirectorySeparatorChar, "bin" + Path.DirectorySeparatorChar, "minecraft.jar"));
            //zip.AddDirectory(tmp);
            //zip.Save(Path.Combine(path, ".minecraft" + Path.DirectorySeparatorChar, "bin" + Path.DirectorySeparatorChar, "minecraft.jar"));
        }
开发者ID:SinZ163,项目名称:SinZationalMinecraftLauncher,代码行数:30,代码来源:InstallJar.cs

示例9: SaveContentXml

        private void SaveContentXml(ZipFile templateFile, XmlDocument contentXml)
        {
            templateFile.RemoveEntry("content.xml");

            MemoryStream memStream = new MemoryStream();
            contentXml.Save(memStream);
            memStream.Seek(0, SeekOrigin.Begin);

            templateFile.AddEntry("content.xml", memStream);
        }
开发者ID:shaunus84,项目名称:through-shadows,代码行数:10,代码来源:OdsReadWrite.cs

示例10: downloadForgeButton_Click

        private void downloadForgeButton_Click(object sender, EventArgs e)
        {
            string forge_ver = (int)Forge1NumericUpDown.Value + "." + (int)Forge2NumericUpDown.Value + "." + (int)Forge3NumericUpDown.Value + "." + (int)Forge4NumericUpDown.Value;
            string forge_url = "http://files.minecraftforge.net/minecraftforge-universal-" + forge_ver + ".zip";
            WebClient client = new WebClient();
            try
            {
                client.DownloadFile(forge_url, AppData + @"minecraftforge-universal-" + forge_ver + ".zip");
            }
            catch (WebException exc)
            {
                MessageBox.Show("Ошибка при загрузке minecraftforge-universal-" + forge_ver + ".zip: " + exc.Message, "Лаунчер", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            ZipFile forge_zip = new ZipFile("minecraftforge-universal-" + forge_ver + ".zip");
            ZipFile mc_jar = new ZipFile(AppData + @"/.minecraft/bin/minecraft.jar");

            forge_zip.RemoveEntry("META-INF");
            mc_jar.RemoveEntry("META-INF");

            Directory.CreateDirectory("Forge-TEMP");
            forge_zip.ExtractAll("Forge-TEMP");

            string[] files = Directory.GetFiles("Forge-TEMP");
            foreach (string file in files)
            {
                mc_jar.AddFile("Forge-TEMP/" + file);
            }
            Directory.Delete("Forge-TEMP", true);

            forge_zip.Save();
            mc_jar.Save();
        }
开发者ID:ArtSin,项目名称:CSharpLauncher,代码行数:33,代码来源:Options.cs

示例11: Init


//.........这里部分代码省略.........
            if ((int)worldJson["hardmodeOres"][2] == -1)
                worldJson["hardmodeOres"][2] = 111;

            buttons.Add(oreButtons[0] = new MenuButton(0, "Cobalt", "", "", () =>
            {
                if ((int)worldJson["hardmodeOres"][0] == 107)
                {
                    worldJson["hardmodeOres"][0] = 221;
                    oreButtons[0].displayText = "Palladium";
                }
                else
                {
                    worldJson["hardmodeOres"][0] = 107;
                    oreButtons[0].displayText = "Cobalt";
                }

                Main.PlaySound(12);
            }).Where(mb =>
            {
                if ((int)worldJson["hardmodeOres"][0] == 221)
                    mb.displayText = "Palladium";

                mb.SetAutomaticPosition(aLeft, lid++);
            }));
            buttons.Add(oreButtons[1] = new MenuButton(0, "Mithril", "", "", () =>
            {
                if ((int)worldJson["hardmodeOres"][1] == 108)
                {
                    worldJson["hardmodeOres"][1] = 222;
                    oreButtons[1].displayText = "Orchialcum";
                }
                else
                {
                    worldJson["hardmodeOres"][1] = 108;
                    oreButtons[1].displayText = "Mithril";
                }

                Main.PlaySound(12);
            }).Where(mb =>
            {
                if ((int)worldJson["hardmodeOres"][1] == 222)
                    mb.displayText = "Orchialcum";

                mb.SetAutomaticPosition(aCentre, cid++);
            }));
            buttons.Add(oreButtons[2] = new MenuButton(0, "Adamantite", "", "", () =>
            {
                if ((int)worldJson["hardmodeOres"][2] == 111)
                {
                    worldJson["hardmodeOres"][2] = 223;
                    oreButtons[2].displayText = "Titanium";
                }
                else
                {
                    worldJson["hardmodeOres"][2] = 111;
                    oreButtons[2].displayText = "Adamantite";
                }

                Main.PlaySound(12);
            }).Where(mb =>
            {
                if ((int)worldJson["hardmodeOres"][2] == 223)
                    mb.displayText = "Titanium";

                mb.SetAutomaticPosition(aRight, rid++);
            }));

            lid++;
            cid++;
            rid++;

            buttons.Add(new MenuButton(0, "Save & go back", "World Select").Where(mb =>
            {
                mb.Click += () =>
                {
                    using (ZipFile zf = new ZipFile(selectedWorldPath))
                    {
                        zf.RemoveEntry("Info.json");
                        zf.AddEntry("Info.json", JsonMapper.ToJson(worldJson));

                        zf.Save();

                        Main.LoadWorlds();
                    }
                };

                mb.SetAutomaticPosition(new MenuAnchor()
                {
                    anchor = new Vector2(0.5f, 0f),
                    offset = new Vector2(-105f, 200f),
                    offset_button = new Vector2(0f, 50f)
                }, lid++);
            }));
            buttons.Add(new MenuButton(0, "Go back without saving", "World Select").Where(mb => mb.SetAutomaticPosition(new MenuAnchor()
            {
                anchor = new Vector2(0.5f, 0f),
                offset = new Vector2(105f, 200f),
                offset_button = new Vector2(0f, 50f)
            }, rid++)));
        }
开发者ID:mugmickey,项目名称:Ingame-Cheat-Menu,代码行数:101,代码来源:EditWorldPage.cs

示例12: Create_RenameRemoveAndRenameAgain_wi8047

        public void Create_RenameRemoveAndRenameAgain_wi8047()
        {
            string filename = "file.test";
            string dirToZip = Path.GetFileNameWithoutExtension(Path.GetRandomFileName());
            var files = TestUtilities.GenerateFilesFlat(dirToZip);

            for (int m = 0; m < 2; m++)
            {
                string zipFileToCreate = Path.Combine(TopLevelDir, String.Format("Create_RenameRemoveAndRenameAgain_wi8047-{0}.zip", m));

                using (var zip = new ZipFile())
                {
                    // select a single file from the list
                    int n = _rnd.Next(files.Length);

                    // insert the selected file into the zip, and also rename it
                    zip.UpdateFile(files[n]).FileName = filename;

                    // conditionally save
                    if (m > 0) zip.Save(zipFileToCreate);

                    // remove the original file
                    zip.RemoveEntry(zip[filename]);

                    // select another file from the list, making sure it is not the same file
                    int n2 = 0;
                    while ((n2 = _rnd.Next(files.Length)) == n) ;

                    // insert that other file and rename it
                    zip.UpdateFile(files[n2]).FileName = filename;
                    zip.Save(zipFileToCreate);
                }

                Assert.AreEqual<int>(1, TestUtilities.CountEntries(zipFileToCreate), "Trial {0}: The Zip file has the wrong number of entries.", m);
            }
        }
开发者ID:mattleibow,项目名称:Zip.Portable,代码行数:36,代码来源:ExtendedTests.cs

示例13: RebaseFiles

        /// <summary>
        /// this is used to rebase the paths in the .zip file if the skin folders are not directly in the root of the zip
        /// for example the extra-skins.zip we ship is structured like this: extra-skins/artisteer-30alphamotors/ 
        /// so skin folders are inside the extra-skins folder and we want to extract them directly without including the extra-skins folder
        /// so we have to remove that base folder by renaming the files and removing that part.
        /// </summary>
        /// <param name="zip"></param>
        /// <param name="baseToRemove"></param>
        private void RebaseFiles(ZipFile zip, string baseToRemove)
        {
            if (string.IsNullOrEmpty(baseToRemove)) { return; }

            // we cannot edit the file names while enumerating them so we first get a list of filenames
            List<string> fileNames = new List<string>();
            foreach (ZipEntry e in zip)
            {
                fileNames.Add(e.FileName);
            }

            foreach (string s in fileNames)
            {
                ZipEntry e = zip[s];
                if (e != null)
                {
                    if ((e.FileName.StartsWith(baseToRemove)) && (e.FileName.Length > baseToRemove.Length))
                    {
                        e.FileName = e.FileName.Replace(baseToRemove, string.Empty);
                    }
                }
            }

            // get rid of the outer folder
            zip.RemoveEntry(baseToRemove);

            zip.Save();
        }
开发者ID:saiesh86,项目名称:TravelBlog,代码行数:36,代码来源:SkinHelper.cs

示例14: btnOk_Click

        private void btnOk_Click(object sender, EventArgs e)
        {

            //Validate plugin folder
            if (!Directory.Exists(PluginFolder))
            {
                MessageBox.Show(@"Please select a valid folder to create the plugin from.");
                return;
            }

            //Prompt for save path
            if(sfdPlugin.ShowDialog() != DialogResult.OK)
            {
                return;   
            }

            if (File.Exists(sfdPlugin.FileName))
            {
                FileHelper.DeleteFile(sfdPlugin.FileName);
            }
            //Create plugin file
            using(var zip = new ZipFile())
            {
                var directory = new DirectoryInfo(PluginFolder);

                //Add files in directory
                foreach (var fileToAdd in Directory.GetFiles(PluginFolder, "*.*", SearchOption.AllDirectories))
                {
                    if (this.AllFilesRadioButton.Checked || mWhatIsConsideredCode.Contains(FileManager.GetExtension(fileToAdd).ToLower()))
                    {
                        string relativeDirectory = null;

                        relativeDirectory = FileManager.MakeRelative(FileManager.GetDirectory(fileToAdd), directory.Parent.FullName);

                        if (relativeDirectory.EndsWith("/"))
                        {
                            relativeDirectory = relativeDirectory.Substring(0, relativeDirectory.Length - 1);
                        }
                        zip.AddFile(fileToAdd, relativeDirectory);
                    }
                }

                //Add compatibility file
                var time = new FileInfo(Assembly.GetExecutingAssembly().Location).LastWriteTime;


                if (zip.Entries.Any(item => item.FileName == directory.Name + "/" + "Compatibility.txt"))
                {
                    zip.RemoveEntry(directory.Name + "/" + "Compatibility.txt");
                }

                try
                {

                    zip.AddFileFromString("Compatibility.txt", directory.Name, time.ToString());
                }
                catch (Exception)
                {
                    MessageBox.Show("The directory already contains a Compatibility.txt file name.  The plugin will still be created but it may not properly include compatibility information.  Consider removing this file and re-creating the plugin.");
                }
                zip.Save(sfdPlugin.FileName);
            }

            MessageBox.Show(@"Successfully created.");

            System.Diagnostics.Process.Start(FileManager.GetDirectory(sfdPlugin.FileName));

            Close();
        }
开发者ID:vchelaru,项目名称:FlatRedBall,代码行数:69,代码来源:CreatePluginWindow.cs

示例15: SaveContentPackage

        private void SaveContentPackage(bool forceLocationSelection)
        {
            if (!ValidateResourceEntries()) return;

            if (forceLocationSelection || String.IsNullOrWhiteSpace(Model.FilePath))
            {
                SaveFilePrompt.Filter = ExtensionFactory.BuildContentPackageFileFilter();
                if ((bool)SaveFilePrompt.ShowDialog())
                {
                    Model.FilePath = SaveFilePrompt.FileName;
                }
            }

            if (!String.IsNullOrWhiteSpace(Model.FilePath))
            {
                try
                {
                    Model.Description = txtDescription.Text;
                    Model.Name = txtName.Text;

                    XmlSerializer serializer = new XmlSerializer(typeof(ContentPackageXML));
                    StringWriter stringWriter = new StringWriter();
                    XmlWriterSettings settings = new XmlWriterSettings { Indent = true, Encoding = Encoding.ASCII};
                    XmlWriter writer = XmlWriter.Create(stringWriter, settings);
                    serializer.Serialize(writer, Model);
                    string manifestXML = stringWriter.ToString();

                    File.WriteAllText("./Manifest.xml", manifestXML);

                    using (ZipFile zipFile = new ZipFile(Model.FilePath))
                    {
                        zipFile.CompressionLevel = CompressionLevel.None;

                        // Update the Manifest.xml file.
                        if (zipFile["Manifest.xml"] != null)
                        {
                            zipFile.RemoveEntry("Manifest.xml");
                        }
                        zipFile.AddFile("./Manifest.xml", "");

                        List<ContentPackageResourceXML> resourceList = lstAddedResources.Items.Cast<ContentPackageResourceXML>().ToList();

                        // Remove files which are no longer used.
                        for(int index = zipFile.Entries.Count; index > 0; index--)
                        {
                            ZipEntry entry = zipFile[index-1];
                            if (entry.FileName != "Manifest.xml")
                            {
                                if (!resourceList.Exists(x => x.FileName == entry.FileName))
                                {
                                    zipFile.RemoveEntry(entry);
                                }
                            }
                        }

                        // Upsert new/modified files
                        foreach (ContentPackageResourceXML resource in resourceList)
                        {
                            ZipEntry entry = zipFile[resource.FileName];

                            if(entry == null)
                            {
                                zipFile.AddFile(resource.FilePath, "");
                            }
                            else
                            {
                                // Modified file isn't in the package. Remove existing and replace with new version.
                                if (!resource.IsInPackage && File.Exists(resource.FilePath))
                                {
                                    zipFile.RemoveEntry(entry);
                                    zipFile.AddFile(resource.FilePath, "");
                                }
                            }
                        }

                        zipFile.Save();

                        // Mark all as "unmodified"
                        resourceList.ForEach(a => a.IsInPackage = true);

                        // Clean up
                        File.Delete("./Manifest.xml");
                        Model.IsModified = false;
                    }
                }
                catch
                {
                    throw;
                }
            }
        }
开发者ID:zunath,项目名称:WinterEngine,代码行数:91,代码来源:MainWindow.xaml.cs


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