RemoveEntries() public method

This method removes a collection of entries from the ZipFile, by name.
public RemoveEntries ( System entriesToRemove ) : void
entriesToRemove System /// A collection of strings that refer to names of entries to be removed /// from the ZipFile. For example, you can pass in an array or a /// List of Strings that provide the names of entries to be removed. ///
return void
コード例 #1
1
ファイル: Modder.cs プロジェクト: ShaRose/MultiMC
        /// <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();
        }
コード例 #2
0
        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();
        }
コード例 #3
0
ファイル: BackupHandler.cs プロジェクト: fandrei/AppMetrics
        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);
        }
コード例 #4
0
ファイル: EpubFile.cs プロジェクト: sashaMilka/MultiReader
        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());
        }
コード例 #5
0
ファイル: LevelManager.cs プロジェクト: ArtSin/Mine2D-Old
        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;
        }
コード例 #6
0
ファイル: Modder.cs プロジェクト: Glought/MultiMC
        /// <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();
        }
コード例 #7
0
ファイル: Selector.cs プロジェクト: Belxjander/Asuna
        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));
        }