本文整理汇总了C#中Ionic.Zip.ZipFile.ExtractSelectedEntries方法的典型用法代码示例。如果您正苦于以下问题:C# ZipFile.ExtractSelectedEntries方法的具体用法?C# ZipFile.ExtractSelectedEntries怎么用?C# ZipFile.ExtractSelectedEntries使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ionic.Zip.ZipFile
的用法示例。
在下文中一共展示了ZipFile.ExtractSelectedEntries方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Selector_ExtractSelectedEntries
public void Selector_ExtractSelectedEntries()
{
//Directory.SetCurrentDirectory(TopLevelDir);
string zipFileToCreate = Path.Combine(TopLevelDir, "Selector_ExtractSelectedEntries.zip");
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));
string extractDir = "extract";
TestContext.WriteLine("====================================================");
TestContext.WriteLine("Reading zip, ExtractSelectedEntries() by date...");
using (ZipFile zip1 = ZipFile.Read(zipFileToCreate))
{
string crit = String.Format("mtime >= {0}", todayAtMidnight.ToString("yyyy-MM-dd"));
TestContext.WriteLine("Criteria({0})", crit);
zip1.ExtractSelectedEntries(crit, null, extractDir);
}
TestContext.WriteLine("====================================================");
TestContext.WriteLine("Reading zip, ExtractSelectedEntries() by date, with overwrite...");
using (ZipFile zip1 = ZipFile.Read(zipFileToCreate))
{
string crit = String.Format("mtime >= {0}", todayAtMidnight.ToString("yyyy-MM-dd"));
TestContext.WriteLine("Criteria({0})", crit);
zip1.ExtractSelectedEntries(crit, null, extractDir, ExtractExistingFileAction.OverwriteSilently);
}
// workitem 9174: test ExtractSelectedEntries using a directoryPathInArchive
List<String> dirs = new List<String>();
// first, get the list of directories used by all entries
TestContext.WriteLine("Reading zip, ...");
using (ZipFile zip1 = ZipFile.Read(zipFileToCreate))
{
foreach (var e in zip1)
{
TestContext.WriteLine("entry {0}", e.FileName);
string p = Path.GetDirectoryName(e.FileName.Replace("/", "\\"));
if (!dirs.Contains(p)) dirs.Add(p);
}
}
// with or without trailing slash
for (int i = 0; i < 2; i++)
{
int grandTotal = 0;
extractDir = String.Format("extract.{0}", i);
for (int j = 0; j < dirs.Count; j++)
{
string d = dirs[j];
if (i == 1) d += "\\";
TestContext.WriteLine("====================================================");
TestContext.WriteLine("Reading zip, ExtractSelectedEntries() by name, with directoryInArchive({0})...", d);
using (ZipFile zip1 = ZipFile.Read(zipFileToCreate))
{
string crit = "name = *.bin";
TestContext.WriteLine("Criteria({0})", crit);
var s = zip1.SelectEntries(crit, d);
TestContext.WriteLine(" {0} entries", s.Count);
grandTotal += s.Count;
zip1.ExtractSelectedEntries(crit, d, extractDir, ExtractExistingFileAction.OverwriteSilently);
}
}
TestContext.WriteLine("====================================================");
TestContext.WriteLine("Total for all dirs: {0} entries", grandTotal);
var extracted = Directory.GetFiles(extractDir, "*.bin", SearchOption.AllDirectories);
Assert.AreEqual<Int32>(grandTotal, extracted.Length);
}
}
示例2: Update
private static void Update()
{
var req = (HttpWebRequest)WebRequest.Create(Upfile);
var res = (HttpWebResponse)req.GetResponse();
using (var instream = res.GetResponseStream())
{
using (var outstream = File.Create("OSUplayer.zip"))
{
byte[] buffer = new byte[1024];
int count;
do
{
count = instream.Read(buffer, 0, buffer.Length);
if (count > 0)
outstream.Write(buffer, 0, count);
}
while (count > 0);
}
}
string filename = Assembly.GetExecutingAssembly().Location;
if (File.Exists(filename + ".detele")) File.Delete(filename + ".delete");
File.Move(filename, filename + ".delete");
using (var sourceFile = new ZipFile("OSUplayer.zip"))
{
sourceFile.ExtractSelectedEntries("OSUplayer.exe", ExtractExistingFileAction.OverwriteSilently);
}
File.Move("OSUplayer.exe", filename);
File.Delete("OSUplayer.zip");
File.Delete("list.db");
MessageBox.Show(LanguageManager.Get("Update_Restart_Text"), LanguageManager.Get("Tip_Text"), MessageBoxButtons.OK, MessageBoxIcon.Information);
var proc = Process.GetProcessesByName(Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().Location));
var p = new Process { StartInfo = { FileName = filename } };
p.Start();
foreach (var pr in proc)
{
pr.Kill();
}
}