-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathUsageExample.cs
52 lines (43 loc) · 1.24 KB
/
UsageExample.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Unzip class usage example
// Written by Alexey Yakovlev <[email protected]>
// https://github.com/yallie/unzip
using System;
using System.Linq;
namespace Internals
{
internal struct Program
{
private static void Main(string[] args)
{
if (args.Length < 2)
{
Console.WriteLine("Syntax: unzip Archive.zip TargetDirectory");
return;
}
var archiveName = args.First();
var outputDirectory = args.Last();
using (var unzip = new Unzip(archiveName))
{
Console.WriteLine("Listing files in the archive:");
ListFiles(unzip);
Console.WriteLine("Extracting files from the archive:");
unzip.ExtractProgress += (s, e) => Console.WriteLine("{0} of {1}: {2}", e.CurrentFile, e.TotalFiles, e.FileName);
unzip.ExtractToDirectory(outputDirectory);
}
}
private static void ListFiles(Unzip unzip)
{
var tab = unzip.Entries.Any(e => e.IsDirectory) ? "\t" : string.Empty;
foreach (var entry in unzip.Entries.OrderBy(e => e.Name))
{
if (entry.IsFile)
{
Console.WriteLine(tab + "{0}: {1} -> {2}", entry.Name, entry.CompressedSize, entry.OriginalSize);
continue;
}
Console.WriteLine(entry.Name);
}
Console.WriteLine();
}
}
}