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


C# ZipFile.RemoveEntries方法代码示例

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


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

示例1: PackIt

        public static void PackIt(string sourceDirectory, string targetDirectory)
        {
            string directoryName = new DirectoryInfo(sourceDirectory).Name;

            targetDirectory = targetDirectory ?? sourceDirectory;
            string targetZipPathFilename = Path.Combine(targetDirectory, directoryName + ".zip");

            if (File.Exists(targetZipPathFilename)) File.Delete(targetZipPathFilename);

            ZipFile zipFile = new ZipFile(targetZipPathFilename);
            zipFile.AddDirectory(sourceDirectory);

            ZipEntry[] tempEntries = zipFile.Entries.Where(IsTempFile).ToArray();

            zipFile.RemoveEntries(tempEntries);
            zipFile.Save();
        }
开发者ID:howardchn,项目名称:VSProjectCleaner,代码行数:17,代码来源:ProjectCleaner.cs

示例2: ArchiveFile

        public static void ArchiveFile(string fileName)
        {
            var zipFileName = Path.ChangeExtension(fileName, ".zip");
            using (var zipFile = new ZipFile(zipFileName))
            {
                zipFile.TempFileFolder = Path.GetTempPath();

                zipFile.RemoveEntries(zipFile.Entries.ToArray());

                zipFile.CompressionMethod = CompressionMethod.Deflate;
                zipFile.CompressionLevel = CompressionLevel.BestCompression;
                zipFile.AddFile(fileName, ".");

                zipFile.Save();
            }

            File.Delete(fileName);
        }
开发者ID:fandrei,项目名称:AppMetrics,代码行数:18,代码来源:BackupHandler.cs

示例3: EpubFile

        public EpubFile(string filePath, Encoding encoding)
        {
            // Załaduj archiwum
            _file = new ZipFile(filePath, encoding);

            // Zapamiętaj referencje do plików, które mogą ulec zmianie
            ZipEntry _ncxEntry = _file.Entries.FirstOrDefault(f => Normalize(f.FileName) == ncxFileName);
            ZipEntry _opfEntry = _file.Entries.FirstOrDefault(f => Normalize(f.FileName) == opfFileName);
            IEnumerable<ZipEntry> sections = _file.Entries.Where(f => Path.GetExtension(f.FileName) == ".html");

            // Rozpakuj i rozczytaj pliki metadanych (content.opf) i spisu treści (toc.ncx)
            _ncxMetadata = new OpfMetadataFile(_ncxEntry);
            _opfMetadata = new OpfMetadataFile(_opfEntry);

            // Znajdź i wczytaj wszystkie rozdziały dokumentu
            _sections = sections.Select(e => new ContentSection(e)).ToList();

            // Usuń te pliki z archiwum - zostaną ponownie zapakowane przy zapisie pliku
            _file.RemoveEntries(sections.Union(new ZipEntry[] { _ncxEntry }).Union(new ZipEntry[] { _opfEntry }).ToArray());
        }
开发者ID:sashaMilka,项目名称:MultiReader,代码行数:20,代码来源:EpubFile.cs

示例4: SaveLevel

        public static void SaveLevel(Mine2D game, string filePath)
        {
            string tempFolder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"/Mine2D";
            Directory.CreateDirectory(tempFolder);
            ZipFile zip = new ZipFile(filePath);
            BinaryFormatter formatter = new BinaryFormatter();

            try
            {
                zip.RemoveEntries(new string[] { "world.dat", "player.dat", "smallInventory.dat", "normalInventory.dat" });
            }
            catch (ArgumentException) { }

            FileStream worldFile = new FileStream(tempFolder + @"/world.dat", FileMode.Create);
            formatter.Serialize(worldFile, game.world);
            worldFile.Close();
            zip.AddFile(tempFolder + @"/world.dat", "/");

            FileStream playerFile = new FileStream(tempFolder + @"/player.dat", FileMode.Create);
            formatter.Serialize(playerFile, game.player);
            playerFile.Close();
            zip.AddFile(tempFolder + @"/player.dat", "/");

            FileStream smallInventoryFile = new FileStream(tempFolder + @"/smallInventory.dat", FileMode.Create);
            formatter.Serialize(smallInventoryFile, game.smallInventory);
            smallInventoryFile.Close();
            zip.AddFile(tempFolder + @"/smallInventory.dat", "/");

            FileStream normalInventoryFile = new FileStream(tempFolder + @"/normalInventory.dat", FileMode.Create);
            formatter.Serialize(normalInventoryFile, game.normalInventory);
            normalInventoryFile.Close();
            zip.AddFile(tempFolder + @"/normalInventory.dat", "/");

            zip.Save();
            RecreateLevel(game);
            game.gameState = GameState.MainMenu;
        }
开发者ID:ArtSin,项目名称:Mine2D-Old,代码行数:37,代码来源:LevelManager.cs

示例5: InstallMods

        /// <summary>
        /// Installs mods from instMods into minecraft.jar
        /// </summary>
        private void InstallMods()
        {
            OnStart();
            modFileIndices = new Dictionary<string, int>();
            foreach (Mod mod in Target.InstMods)
            {
                modFileIndices[mod.FileName] = Target.InstMods[mod];
            }

            string mcBin = Target.BinDir;
            string mcJar = Path.Combine(mcBin, "minecraft.jar");
            string mcBackup = Path.Combine(mcBin, "mcbackup.jar");

            Status = "Installing mods - Backing up minecraft.jar...";
            if (!File.Exists(mcBackup))
            {
                File.Copy(mcJar, mcBackup);
            }

            TaskStep++; // STEP
            Status = "Installing mods - Adding class files...";
            try
            {
                File.Delete(mcJar);
            } catch (IOException e)
            {
                if (e.Message.Contains("being used"))
                {
                    OnErrorMessage("Can't install mods because minecraft.jar is being used " +
                        "by another process. If you have minecraft.jar open in 7-zip, WinRAR " +
                        "or any other program, please close it and then try again.");
                    Cancel();
                }
            }
            File.Copy(mcBackup, mcJar);
            using (ZipFile jarFile = new ZipFile(mcJar))
            {
                if (!Directory.Exists(Target.InstModsDir))
                    Directory.CreateDirectory(Target.InstModsDir);

                AddToJar(Target.InstModsDir, jarFile);

                TaskStep++; // STEP
                Status = "Installing mods - Removing META-INF...";
                /*
                 * HACK: This is a weird, custom regex. Not a filesystem path. At all. Never treat it as one.
                 */
                string metaInfRegex = "META-INF\\*";
                if (jarFile.SelectEntries(metaInfRegex) != null)
                {
                    DebugUtils.Print("Removing META-INF");
                    ICollection <Ionic.Zip.ZipEntry> coll = jarFile.SelectEntries(metaInfRegex);
                    jarFile.RemoveEntries(coll);
                }

                TaskStep++; // STEP
                Status = "Installing mods - Saving minecraft.jar...";
                jarFile.Save(mcJar);
            }

            TaskStep++; // STEP
            Status = "Installing mods - Removing temporary files...";
            if (Directory.Exists(Path.Combine(Target.RootDir, MODTEMP_DIR_NAME)))
            {
                Directory.Delete(Path.Combine(Target.RootDir, MODTEMP_DIR_NAME), true);
            }

            TaskStep++; // STEP
            Status = "Installing mods - Done.";
            //running = false;
            OnComplete();
        }
开发者ID:Glought,项目名称:MultiMC,代码行数:75,代码来源:Modder.cs

示例6: InstallMods

        /// <summary>
        /// Installs mods from instMods into minecraft.jar
        /// </summary>
        private void InstallMods()
        {
            OnStart();
            //running = true;

            //ArrayList cFiles = new ArrayList();

            string mcBin = Target.BinDir;
            string mcJar = Path.Combine(mcBin, "minecraft.jar");
            string mcBackup = Path.Combine(mcBin, "mcbackup.jar");

            Status = "Installing mods - Backing up minecraft.jar...";
            if (!File.Exists(mcBackup))
            {
                File.Copy(mcJar, mcBackup);
            }

            TaskStep++; // STEP
            Status = "Installing mods - Adding class files...";
            try
            {
                File.Delete(mcJar);
            } catch (IOException e)
            {
                if (e.Message.Contains("being used"))
                {
                    OnErrorMessage("Can't install mods because minecraft.jar is being used " +
                        "by another process. If you have minecraft.jar open in 7-zip, WinRAR " +
                        "or any other program, please close it and then try again.");
                    Cancel();
                }
            }
            File.Copy(mcBackup, mcJar);
            ZipFile jarFile = new ZipFile(mcJar);

            if (!Directory.Exists(Target.InstModsDir))
                Directory.CreateDirectory(Target.InstModsDir);

            AddToJar(Target.InstModsDir, jarFile);

            TaskStep++; // STEP
            Status = "Installing mods - Removing META-INF...";
            string metaInfRegex = Path.Combine("META-INF", "*");
            if (jarFile.SelectEntries(metaInfRegex) != null)
            {
                Console.WriteLine("Removing META-INF");
                jarFile.RemoveEntries(jarFile.SelectEntries(metaInfRegex));
            }

            TaskStep++; // STEP
            Status = "Installing mods - Saving minecraft.jar...";
            jarFile.Save(mcJar);

            TaskStep++; // STEP
            Status = "Installing mods - Removing temporary files...";
            if (Directory.Exists(Path.Combine(Target.RootDir, MODTEMP_DIR_NAME)))
            {
                Directory.Delete(Path.Combine(Target.RootDir, MODTEMP_DIR_NAME), true);
            }

            TaskStep++; // STEP
            Status = "Installing mods - Done.";
            //running = false;
            OnComplete();
        }
开发者ID:ShaRose,项目名称:MultiMC,代码行数:68,代码来源:Modder.cs

示例7: Selector_RemoveSelectedEntries2

        public void Selector_RemoveSelectedEntries2()
        {
            //Directory.SetCurrentDirectory(TopLevelDir);

            string zipFileToCreate = Path.Combine(TopLevelDir, "Selector_RemoveSelectedEntries2.zip");

            Assert.IsFalse(File.Exists(zipFileToCreate), "The zip file '{0}' already exists.", zipFileToCreate);

            //int count1, count2;
            int entriesAdded = 0;
            String filename = null;

            string subDir = Path.Combine(TopLevelDir, "A");
            Directory.CreateDirectory(subDir);

            int fileCount = _rnd.Next(44) + 44;
            TestContext.WriteLine("====================================================");
            TestContext.WriteLine("Files being added to the zip:");
            for (int j = 0; j < fileCount; j++)
            {
                string space = (_rnd.Next(2) == 0) ? " " : "";
                if (_rnd.Next(2) == 0)
                {
                    filename = Path.Combine(subDir, String.Format("file{1}{0:D3}.txt", j, space));
                    TestUtilities.CreateAndFillFileText(filename, _rnd.Next(5000) + 5000);
                }
                else
                {
                    filename = Path.Combine(subDir, String.Format("file{1}{0:D3}.bin", j, space));
                    TestUtilities.CreateAndFillFileBinary(filename, _rnd.Next(5000) + 5000);
                }
                TestContext.WriteLine(Path.GetFileName(filename));
                entriesAdded++;
            }


            TestContext.WriteLine("====================================================");
            TestContext.WriteLine("Creating zip...");
            using (ZipFile zip1 = new ZipFile())
            {
                zip1.AddDirectory(subDir, "");
                zip1.Save(zipFileToCreate);
            }
            Assert.AreEqual<Int32>(entriesAdded, TestUtilities.CountEntries(zipFileToCreate));


            TestContext.WriteLine("====================================================");
            TestContext.WriteLine("Reading zip, using name patterns that contain spaces...");
            string[] selectionStrings = { "name = '* *.txt'",
                                          "name = '* *.bin'",
                                          "name = *.txt and name != '* *.txt'",
                                          "name = *.bin and name != '* *.bin'",
            };
            foreach (string selectionCriteria in selectionStrings)
            {
                using (ZipFile zip1 = ZipFile.Read(zipFileToCreate))
                {
                    var selected1 = zip1.SelectEntries(selectionCriteria);
                    ZipEntry[] entries = new ZipEntry[selected1.Count];
                    selected1.CopyTo(entries, 0);
                    string[] names = Array.ConvertAll(entries, x => x.FileName);
                    zip1.RemoveEntries(names);
                    TestContext.WriteLine("for pattern {0}, Removed {1} entries", selectionCriteria, selected1.Count);
                    zip1.Save();
                }

            }

            Assert.AreEqual<Int32>(0, TestUtilities.CountEntries(zipFileToCreate));
        }
开发者ID:Belxjander,项目名称:Asuna,代码行数:70,代码来源:Selector.cs


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