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


C# ZipFile.SelectEntries方法代码示例

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


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

示例1: UnzipDatabase

 public string UnzipDatabase(string zipFilePath, string sharedFolderPath)
 {
     var tmpDir = PathUtils.PrepareDirectory(sharedFolderPath, PathUtils.GetFileName(Path.GetRandomFileName()));
     _log.InfoFormat("Unzip DB to {0}", tmpDir);
     using (var zipFile = new ZipFile(zipFilePath)) {
         var db = zipFile.SelectEntries("name = *.bak", "db").FirstOrDefault();
         if (db == null) {
             var ex = new ArgumentException("zipFilePath");
             _log.ErrorFormat("Can't find database backup in zip file: {0}", zipFilePath);
             _log.Error(ex);
             throw ex;
         }
         _log.InfoFormat("Extracting database to {0}", tmpDir);
         try {
             db.Extract(tmpDir, ExtractExistingFileAction.OverwriteSilently);
         }
         catch (Exception ex) {
             _log.Error(ex);
             throw;
         }
         var extractedFile = Directory.EnumerateFiles(tmpDir, "*.bak", SearchOption.AllDirectories).FirstOrDefault();
         if (extractedFile == null) {
             var ex = new Exception("zipFilePath");
             _log.ErrorFormat("Can't find extracted database backup in : {0}", tmpDir);
             _log.Error(ex);
             throw ex;
         }
         _log.DebugFormat("Backup found: {0}", extractedFile);
         return extractedFile;
     }
 }
开发者ID:vadimart92,项目名称:TeamCityTools,代码行数:31,代码来源:ZipUtils.cs

示例2: ListZipContent

        public static string[] ListZipContent(string zipfile, string pattern = null)
        {
            try
            {
                using (ZipFile zip = new ZipFile(zipfile))
                {
                    ICollection<ZipEntry> entries;
                    if (string.IsNullOrEmpty(pattern))
                        entries = zip.Entries;
                    else
                        entries = zip.SelectEntries("name = '" + pattern + "'");

                    int i = 0;
                    string[] list = new string[entries.Count];
                    foreach (ZipEntry ze in entries)
                        list[i++] = ze.FileName;

                    return list;
                }
            }
            catch (Ionic.Zip.BadReadException)
            {
                Logger.WriteLog("Error: The zip file " + zipfile + " seems corrupt");
            }
            return null;
        }
开发者ID:tmeckel,项目名称:PRFCreator,代码行数:26,代码来源:Zipping.cs

示例3: ZipGetFullname

 public static string ZipGetFullname(string zipfile, string pattern)
 {
     using (ZipFile zip = new ZipFile(zipfile))
     {
         ICollection<ZipEntry> zes = zip.SelectEntries("name = '" + pattern + "'");
         foreach (ZipEntry ze in zes)
             return ze.FileName;
     }
     return string.Empty;
 }
开发者ID:joeisgood99,项目名称:PRFCreator,代码行数:10,代码来源:Zipping.cs

示例4: FindFileNameInZipLike

        /// <summary>
        /// Uses Ionic.Zip library to search a compressed file for a given pattern
        /// </summary>
        /// <param name="zipFileName"></param>
        /// <param name="pattern"></param>
        /// <returns></returns>
        public static List<string> FindFileNameInZipLike(string zipFileName, string pattern)
        {
            var zipFile = new ZipFile(zipFileName);
            var coll = zipFile.SelectEntries(pattern);

            var results = new List<string>();
            foreach (ZipEntry entry in coll)
            {
                results.Add(entry.FileName);
            }
            return results;
        }
开发者ID:azavea,项目名称:acs-alchemist,代码行数:18,代码来源:FileUtilities.cs

示例5: UnzipPackages

 public string UnzipPackages(string zipFileName, string destinationDirectory)
 {
     InitDestinationDirectoy(destinationDirectory);
     Directory.CreateDirectory(destinationDirectory);
     using (var zipFile = new ZipFile(zipFileName)) {
         foreach (var zipEntry in zipFile.SelectEntries("name = *.gz", PackagesName)) {
             _log.DebugFormat("Extracting entry {0} into {1}", zipEntry.FileName, destinationDirectory);
             try {
                 zipEntry.Extract(destinationDirectory);
             }
             catch (Exception ex) {
                 _log.Error(ex);
                 throw;
             }
         }
     }
     return Path.Combine(destinationDirectory, PackagesName);
 }
开发者ID:vadimart92,项目名称:TeamCityTools,代码行数:18,代码来源:ZipUtils.cs

示例6: RenameInZip

        //Returns true on success and false if there is no entry called oldfile
        public static bool RenameInZip(string zipfile, string oldfile, string newfile)
        {
            using (ZipFile zip = new ZipFile(zipfile))
            {
                Utility.SetZipTempFolder(zip);
                ICollection<ZipEntry> zipEntries = zip.SelectEntries("name = '" + oldfile + "'");
                if (zipEntries.Count == 0)
                    return false;

                foreach (ZipEntry ze in zipEntries)
                {
                    ze.FileName = newfile;
                    break;
                }
                zip.Save();
            }
            return true;
        }
开发者ID:joeisgood99,项目名称:PRFCreator,代码行数:19,代码来源:Zipping.cs

示例7: ExtractBinDirectoryFromZip

        private static string ExtractBinDirectoryFromZip(string zipPath)
        {
            var tmp = Path.GetTempFileName() + ".dir";
            try
            {
                Directory.CreateDirectory(tmp);

                using (var zip = new ZipFile(zipPath))
                {
                    foreach (var entry in zip.SelectEntries("*/Website/bin/*.dll"))
                    {
                        var fileName = Path.GetFileName(entry.FileName);
                        var outputFilePath = Path.Combine(tmp, fileName);
                        Save(entry, outputFilePath);
                    }
                }
            }
            catch(Exception ex)
            {
                Console.WriteLine("Could not extract bin directory from Zip.");
            }

            return tmp + "/";
        }
开发者ID:SaintSkeeta,项目名称:Sitecore-Nuget-Package-Discoverer,代码行数:24,代码来源:Program.cs

示例8: Selector_AddSelectedFiles

        public void Selector_AddSelectedFiles()
        {
            Directory.SetCurrentDirectory(TopLevelDir);

            Trial[] trials = new Trial[]
                {
                    new Trial { Label = "name", C1 = "name = *.txt", C2 = "name = *.bin" },
                    new Trial { Label = "name (shorthand)", C1 = "*.txt", C2 = "*.bin" },
                    new Trial { Label = "attributes (Hidden)", C1 = "attributes = H", C2 = "attributes != H" },
                    new Trial { Label = "attributes (ReadOnly)", C1 = "attributes = R", C2 = "attributes != R" },
                    new Trial { Label = "mtime", C1 = "mtime < 2007-01-01", C2 = "mtime > 2007-01-01" },
                    new Trial { Label = "atime", C1 = "atime < 2007-01-01", C2 = "atime > 2007-01-01" },
                    new Trial { Label = "ctime", C1 = "ctime < 2007-01-01", C2 = "ctime > 2007-01-01" },
                    new Trial { Label = "size", C1 = "size < 7500", C2 = "size >= 7500" },

                    new Trial { Label = "name & size",
                                C1 = "name = *.bin AND size > 7500",
                                C2 = "name != *.bin  OR  size <= 7500",
                    },

                    new Trial { Label = "name, size & attributes",
                                C1 = "name = *.bin AND size > 8kb and attributes = H",
                                C2 = "name != *.bin  OR  size <= 8kb or attributes != H",
                    },

                    new Trial { Label = "name, size, time & attributes.",
                                C1 = "name = *.bin AND size > 7k and mtime < 2007-01-01 and attributes = H",
                                C2 = "name != *.bin  OR  size <= 7k or mtime > 2007-01-01 or attributes != H",
                    },
                };

            _txrx = TestUtilities.StartProgressMonitor("AddSelectedFiles", "AddSelectedFiles", "starting up...");

            string[] zipFileToCreate = {
                Path.Combine(TopLevelDir, "Selector_AddSelectedFiles-1.zip"),
                Path.Combine(TopLevelDir, "Selector_AddSelectedFiles-2.zip")
            };

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

            int count1, count2;

            SetupFiles();
            var topLevelFiles = Directory.GetFiles(fodderDirectory, "*.*", SearchOption.TopDirectoryOnly);

            string currentDir = Directory.GetCurrentDirectory();
            _txrx.Send(String.Format("pb 0 max {0}", 2 * (trials.Length + 1)));

            _txrx.Send("pb 0 step");

            for (int m = 0; m < trials.Length; m++)
            {
                _txrx.Send("test AddSelectedFiles");
                _txrx.Send("pb 1 max 4");
                _txrx.Send(String.Format("status test {0}/{1}: creating zip #1/2",
                                         m + 1, trials.Length));
                TestContext.WriteLine("===============================================");
                TestContext.WriteLine("AddSelectedFiles() [{0}]", trials[m].Label);
                using (ZipFile zip1 = new ZipFile())
                {
                    zip1.AddSelectedFiles(trials[m].C1, fodderDirectory, "");
                    zip1.Save(zipFileToCreate[0]);
                }
                count1 = TestUtilities.CountEntries(zipFileToCreate[0]);
                TestContext.WriteLine("C1({0}) Count({1})", trials[m].C1, count1);
                _txrx.Send("pb 1 step");
                System.Threading.Thread.Sleep(100);
                _txrx.Send("pb 0 step");

                _txrx.Send(String.Format("status test {0}/{1}: creating zip #2/2",
                                         m + 1, trials.Length));
                using (ZipFile zip1 = new ZipFile())
                {
                    zip1.AddSelectedFiles(trials[m].C2, fodderDirectory, "");
                    zip1.Save(zipFileToCreate[1]);
                }
                count2 = TestUtilities.CountEntries(zipFileToCreate[1]);
                TestContext.WriteLine("C2({0}) Count({1})", trials[m].C2, count2);
                Assert.AreEqual<Int32>(topLevelFiles.Length, count1 + count2);
                _txrx.Send("pb 1 step");

                /// =======================================================
                /// Now, select entries from that ZIP
                _txrx.Send(String.Format("status test {0}/{1}: selecting zip #1/2",
                                         m + 1, trials.Length));
                using (ZipFile zip1 = ZipFile.Read(zipFileToCreate[0]))
                {
                    var selected1 = zip1.SelectEntries(trials[m].C1);
                    Assert.AreEqual<Int32>(selected1.Count, count1);
                }
                _txrx.Send("pb 1 step");

                _txrx.Send(String.Format("status test {0}/{1}: selecting zip #2/2",
                                         m + 1, trials.Length));
                using (ZipFile zip1 = ZipFile.Read(zipFileToCreate[1]))
                {
                    var selected2 = zip1.SelectEntries(trials[m].C2);
                    Assert.AreEqual<Int32>(selected2.Count, count2);
                }
//.........这里部分代码省略.........
开发者ID:Belxjander,项目名称:Asuna,代码行数:101,代码来源:Selector.cs

示例9: Selector_SingleQuotesAndSlashes_wi14033

        public void Selector_SingleQuotesAndSlashes_wi14033()
        {
            var zipFileToCreate = "SingleQuotes.zip";
            var parentDir = "DexMik";

            int nFolders = this._rnd.Next(4)+3;
            TestContext.WriteLine("Creating {0} folders:", nFolders);
            Directory.CreateDirectory(parentDir);
            string[] childFolders = new string[nFolders+1];
            childFolders[0] = parentDir;
            for (int i=0; i < nFolders; i++)
            {
                var b1 = "folder" + (i+1);
                int k = (i > 0) ? this._rnd.Next(i+1) : 0;
                var d1 = Path.Combine(childFolders[k], b1);
                TestContext.WriteLine("  {0}", d1);
                Directory.CreateDirectory(d1);
                childFolders[i+1] = d1;

                int nFiles = this._rnd.Next(3)+2;
                TestContext.WriteLine("  Creating {0} files:", nFiles);
                for (int j=0; j < nFiles; j++)
                {
                    var fn1 = Path.GetRandomFileName();
                    var fname = Path.Combine(d1,fn1);
                    TestContext.WriteLine("    {0}", fn1);
                    TestUtilities.CreateAndFillFileText(fname, this._rnd.Next(10000) + 1000);
                }
                TestContext.WriteLine("");
            }

            // create a zip file using those files
            TestContext.WriteLine("");
            TestContext.WriteLine("Zipping:");
            using (var zip = new ZipFile())
            {
                zip.AddDirectory(parentDir, childFolders[0]);
                zip.Save(zipFileToCreate);
            }

            // list all the entries
            TestContext.WriteLine("");
            TestContext.WriteLine("List of entries:");
            using (var zip = new ZipFile(zipFileToCreate))
            {
                foreach (var e in zip)
                {
                    TestContext.WriteLine("  {0}", e.FileName);
                }
            }
            TestContext.WriteLine("");

            // now select some of the entries
            int m = this._rnd.Next(nFolders)+1;
            TestContext.WriteLine("");
            TestContext.WriteLine("Selecting entries from folder {0}:", m);
            using (var zip = new ZipFile(zipFileToCreate))
            {
                string selectCriteria =
                    String.Format("name = '{0}'",
                                  Path.Combine(childFolders[m], "*.*"));
                TestContext.WriteLine("select:  {0}", selectCriteria);
                var selection1 = zip.SelectEntries(selectCriteria);
                Assert.IsTrue(selection1.Count > 0, "first selection failed.");

                foreach (var item in selection1)
                {
                    TestContext.WriteLine("  {0}", item);
                }

                // Try different formats of the selection string - with
                // and without quotes, with fwd slashes and back
                // slashes.
                string[][] replacementPairs = {
                    new string[] { "\\", "/" }, // backslash to fwdslash
                    new string[] { "'", "" },   // remove single quotes
                    new string[] { "/", "\\" }, // fwdslash to backslash
                };

                for (int k=0; k < 3; k++)
                {
                    selectCriteria = selectCriteria.Replace(replacementPairs[k][0],
                                                            replacementPairs[k][1]);

                    TestContext.WriteLine("");
                    TestContext.WriteLine("Try #{0}: {1}", k+2, selectCriteria);
                    var selection2 = zip.SelectEntries(selectCriteria);
                    foreach (var item in selection2)
                    {
                        TestContext.WriteLine("  {0}", item);
                    }

                    Assert.AreEqual<int>(selection1.Count,
                                         selection2.Count,
                                         "selection verification trial {0} failed.", k);
                }
            }

        }
开发者ID:Belxjander,项目名称:Asuna,代码行数:99,代码来源:Selector.cs

示例10: Selector_SelectEntries_Fullpath

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

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

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

            int count1, count2;

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


            TestContext.WriteLine("====================================================");
            TestContext.WriteLine("Creating files...");
            int entries = 0;
            int i = 0;
            int subdirCount = _rnd.Next(17) + 9;
            //int subdirCount = _rnd.Next(3) + 2;
            var FileCount = new Dictionary<string, int>();

            var checksums = new Dictionary<string, string>();
            // I don't actually verify the checksums in this method...


            for (i = 0; i < subdirCount; i++)
            {
                string subDirShort = new System.String(new char[] { (char)(i + 65) });
                string subDir = Path.Combine(fodder, subDirShort);
                Directory.CreateDirectory(subDir);

                int filecount = _rnd.Next(8) + 8;
                //int filecount = _rnd.Next(2) + 2;
                FileCount[subDirShort] = filecount;
                for (int j = 0; j < filecount; j++)
                {
                    string filename = String.Format("file{0:D4}.x", j);
                    string fqFilename = Path.Combine(subDir, filename);
                    TestUtilities.CreateAndFillFile(fqFilename, _rnd.Next(1000) + 1000);

                    var chk = TestUtilities.ComputeChecksum(fqFilename);
                    var s = TestUtilities.CheckSumToString(chk);
                    var t1 = Path.GetFileName(fodder);
                    var t2 = Path.Combine(t1, subDirShort);
                    var key = Path.Combine(t2, filename);
                    key = TestUtilities.TrimVolumeAndSwapSlashes(key);
                    TestContext.WriteLine("chk[{0}]= {1}", key, s);
                    checksums.Add(key, s);
                    entries++;
                }
            }

            Directory.SetCurrentDirectory(TopLevelDir);

            TestContext.WriteLine("====================================================");
            TestContext.WriteLine("Creating zip ({0} entries in {1} subdirs)...", entries, subdirCount);
            // add all the subdirectories into a new zip
            using (ZipFile zip1 = new ZipFile())
            {
                // add all of those subdirectories (A, B, C...) into the root in the zip archive
                zip1.AddDirectory(fodder, "");
                zip1.Save(zipFileToCreate);
            }
            Assert.AreEqual<Int32>(entries, TestUtilities.CountEntries(zipFileToCreate));


            TestContext.WriteLine("====================================================");
            TestContext.WriteLine("Selecting entries by full path...");
            count1 = 0;
            using (ZipFile zip1 = ZipFile.Read(zipFileToCreate))
            {
                for (i = 0; i < subdirCount; i++)
                {
                    string dirInArchive = new System.String(new char[] { (char)(i + 65) });
                    var selected1 = zip1.SelectEntries(Path.Combine(dirInArchive, "*.*"));
                    count1 += selected1.Count;
                    TestContext.WriteLine("--------------\nfiles in dir {0} ({1}):",
                                          dirInArchive, selected1.Count);
                    foreach (ZipEntry e in selected1)
                        TestContext.WriteLine(e.FileName);
                }
                Assert.AreEqual<Int32>(entries, count1);
            }


            TestContext.WriteLine("====================================================");
            TestContext.WriteLine("Selecting entries by directory and size...");
            count1 = 0;
            count2 = 0;
            using (ZipFile zip1 = ZipFile.Read(zipFileToCreate))
            {
                for (i = 0; i < subdirCount; i++)
                {
                    string dirInArchive = new System.String(new char[] { (char)(i + 65) });
                    string pathCriterion = String.Format("name = {0}",
                                                         Path.Combine(dirInArchive, "*.*"));
                    string combinedCriterion = String.Format("size > 1500  AND {0}", pathCriterion);

                    var selected1 = zip1.SelectEntries(combinedCriterion, dirInArchive);
//.........这里部分代码省略.........
开发者ID:Belxjander,项目名称:Asuna,代码行数:101,代码来源:Selector.cs

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

示例12: Selector_SelectEntries_ByName_NamesWithSpaces

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

            string zipFileToCreate = Path.Combine(TopLevelDir, "Selector_SelectEntries_Spaces.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 (ZipFile zip1 = ZipFile.Read(zipFileToCreate))
            {
                var selected1 = zip1.SelectEntries("name = *.txt");
                var selected2 = zip1.SelectEntries("name = *.bin");
                TestContext.WriteLine("Text files:");
                foreach (ZipEntry e in selected1)
                {
                    TestContext.WriteLine(e.FileName);
                }
                Assert.AreEqual<Int32>(entriesAdded, selected1.Count + selected2.Count);
            }


            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'",
            };
            int count = 0;
            using (ZipFile zip1 = ZipFile.Read(zipFileToCreate))
            {
                foreach (string selectionCriteria in selectionStrings)
                {
                    var selected1 = zip1.SelectEntries(selectionCriteria);
                    count += selected1.Count;
                    TestContext.WriteLine("  For criteria ({0}), found {1} files.", selectionCriteria, selected1.Count);
                }
            }
            Assert.AreEqual<Int32>(entriesAdded, count);

        }
开发者ID:Belxjander,项目名称:Asuna,代码行数:82,代码来源:Selector.cs

示例13: LoadLanguageData

 StringLocalizationStorage LoadLanguageData(string mapFilename, ZipFile mapFile)
 {
     var sls = new StringLocalizationStorage();
     if (mapFile.ContainsEntry("strings.resx"))
         using (var s = mapFile["strings.resx"].OpenReader())
             sls.AddLanguage("en", s);
     foreach(var v in mapFile.SelectEntries("strings.*.resx"))
     {
         var lang = v.FileName.Substring("strings.".Length);
         lang = lang.Substring(0, lang.Length - ".resx".Length);
         using (var s = v.OpenReader())
             sls.AddLanguage(lang, s);
     }
     return sls;
 }
开发者ID:ChristianMarchiori,项目名称:DeadMeetsLead,代码行数:15,代码来源:MapPersistence.cs

示例14: Selector_SelectEntries_ByTime

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

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

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

            SetupFiles();

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

            TestContext.WriteLine("====================================================");
            TestContext.WriteLine("Reading zip, SelectEntries() by date...");
            using (ZipFile zip1 = ZipFile.Read(zipFileToCreate))
            {
                var totalEntries = numFodderFiles+numFodderDirs;

                // all of the files should have been modified either
                // after midnight today, or before.
                string crit = String.Format("mtime >= {0}", todayAtMidnight.ToString("yyyy-MM-dd"));
                var selected1 = zip1.SelectEntries(crit);
                TestContext.WriteLine("Case A({0}) count({1})", crit, selected1.Count);
                crit = String.Format("mtime < {0}", todayAtMidnight.ToString("yyyy-MM-dd"));
                var selected2 = zip1.SelectEntries(crit);
                TestContext.WriteLine("Case B({0})  count({1})", crit, selected2.Count);
                Assert.AreEqual<Int32>(totalEntries,
                                       selected1.Count + selected2.Count, "B");


                // some nonzero (high) number of files should have been
                // created in the past twenty days.
                crit = String.Format("ctime >= {0}", twentyDaysAgo.ToString("yyyy-MM-dd"));
                var selected3 = zip1.SelectEntries(crit);
                TestContext.WriteLine("Case C({0}) count({1})", crit, selected3.Count);
                Assert.IsTrue(selected3.Count > 0, "C");


                // a nonzero number should be marked as having been
                // created more than 3 years ago.
                crit = String.Format("ctime < {0}",
                                     threeYearsAgo.ToString("yyyy-MM-dd"));
                var selected4 = zip1.SelectEntries(crit);
                TestContext.WriteLine("Case D({0})  count({1})", crit, selected4.Count);
                Assert.IsTrue(selected4.Count > 0, "D");

                // None of the files should have been created
                // more than 20 years ago
                var twentyYearsAgo = new DateTime(DateTime.Now.Year - 20,
                                                  DateTime.Now.Month,
                                                  DateTime.Now.Day);
                crit = String.Format("ctime < {0}",
                                     twentyYearsAgo.ToString("yyyy-MM-dd"));
                var selected5 = zip1.SelectEntries(crit);
                TestContext.WriteLine("Case F({0})  count({1})", crit, selected5.Count);
                Assert.IsTrue(selected5.Count==0, "F");

                // Some number of the files should have been created
                // more than three days ago
                crit = String.Format("ctime < {0}",
                                     threeDaysAgo.ToString("yyyy-MM-dd"));
                selected5 = zip1.SelectEntries(crit);
                TestContext.WriteLine("Case E({0})  count({1})", crit, selected5.Count);
                Assert.IsTrue(selected5.Count>0, "E");

                // summing all those created more than three days ago,
                // with those created in the last three days, should be all entries.
                crit = String.Format("ctime >= {0}", threeDaysAgo.ToString("yyyy-MM-dd"));
                var selected6 = zip1.SelectEntries(crit);
                TestContext.WriteLine("Case G({0})  count({1})", crit, selected6.Count);
                Assert.IsTrue(selected6.Count>0, "G");
                Assert.AreEqual<Int32>(totalEntries, selected5.Count + selected6.Count, "G");


                // some number should have been accessed in the past 2 days
                crit = String.Format("atime >= {0}  and  atime < {1}",
                                     twoDaysAgo.ToString("yyyy-MM-dd"),
                                     todayAtMidnight.ToString("yyyy-MM-dd"));
                selected5 = zip1.SelectEntries(crit);
                TestContext.WriteLine("Case H({0})  count({1})", crit, selected5.Count);
                Assert.IsTrue(selected5.Count > 0, "H");

                // those accessed *exactly* at midnight yesterday, plus
                // those NOT = all entries
                crit = String.Format("atime = {0}",
                                     yesterdayAtMidnight.ToString("yyyy-MM-dd"));
                selected5 = zip1.SelectEntries(crit);
                TestContext.WriteLine("Case I({0})  count({1})", crit, selected5.Count);

                crit = String.Format("atime != {0}",
                                     yesterdayAtMidnight.ToString("yyyy-MM-dd"));
                selected6 = zip1.SelectEntries(crit);
                TestContext.WriteLine("Case J({0})  count({1})", crit, selected6.Count);
//.........这里部分代码省略.........
开发者ID:Belxjander,项目名称:Asuna,代码行数:101,代码来源:Selector.cs

示例15: UnpackZip

    public virtual void UnpackZip([NotNull] string packagePath, [NotNull] string path, 
      [CanBeNull] string entriesPattern = null, int stepsCount = 1, 
      [CanBeNull] Action incrementProgress = null, bool skipErrors = false)
    {
      Assert.ArgumentNotNull(packagePath, "packagePath");
      Assert.ArgumentNotNull(path, "path");

      // TODO: comment this line when the progress bar is adjusted
      incrementProgress = null;

      bool hasResponse = incrementProgress != null;
      if (System.IO.File.Exists(packagePath))
      {
        try
        {
          if (entriesPattern != null)
          {
            Log.Info("Unzipping the {2} entries of the '{0}' archive to the '{1}' folder", packagePath, path, entriesPattern);
          }
          else 
          {
            Log.Info("Unzipping the '{0}' archive to the '{1}' folder", packagePath, path);
          }

          using (ZipFile zip = new ZipFile(packagePath))
          {
            int q = Math.Max(zip.Entries.Count / stepsCount, 1);

            this.fileSystem.Directory.Ensure(path);
            int i = 0;
            ICollection<ZipEntry> entries = entriesPattern != null ? zip.SelectEntries(entriesPattern) : zip.Entries;
            foreach (ZipEntry entry in entries)
            {
              try
              {
                entry.Extract(path, ExtractExistingFileAction.OverwriteSilently);
              }
              catch (IOException ex)
              {
                if (skipErrors)
                {
                  Log.Error(ex, "Unpacking caused exception");
                  continue;
                }

                bool b = false;
                foreach (string postFix in new[]
                {
                  ".tmp", ".PendingOverwrite"
                })
                {
                  string errorPath = Path.Combine(path, entry.FileName) + postFix;
                  if (System.IO.File.Exists(errorPath))
                  {
                    System.IO.File.Delete(errorPath);
                    b = true;
                  }
                }

                if (!b)
                {
                  throw;
                }

                entry.Extract(path, ExtractExistingFileAction.OverwriteSilently);
              }
              catch (Exception ex)
              {
                if (skipErrors)
                {
                  Log.Error(ex, "Unpacking caused exception");
                  continue;
                }
              }

              if (hasResponse)
              {
                if (++i == q)
                {
                  incrementProgress();
                  i = 0;
                }
              }
            }
          }
        }
        catch (ZipException)
        {
          throw new InvalidOperationException(string.Format("The \"{0}\" package seems to be corrupted.", packagePath));
        }
      }
    }
开发者ID:lennartfranke,项目名称:Sitecore-Instance-Manager,代码行数:92,代码来源:ZipProvider.cs


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