-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
57 lines (56 loc) · 2.1 KB
/
Program.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
53
54
55
56
57
using CommandLine;
using SharpCompress.Archives;
using SharpCompress.Common;
using SharpCompress.IO;
using System;
using System.IO;
using System.Linq;
namespace Zippy
{
class Program
{
static void Main(string[] args)
{
Parser.Default.ParseArguments<CommandLineOptions>(args).WithParsed(options =>
{
bool unzip = options.Operation == 'e';
using var stream = new NonDisposingStream(File.OpenRead(options.InputFile), true);
using var reader = ArchiveFactory.Open(stream);
try
{
foreach (var entry in reader.Entries.Where(entry => !entry.IsDirectory))
{
if (unzip)
{
if (options.SkipExistingFiles && File.Exists(Path.Combine(options.OutputDirectory, entry.Key)))
{
Console.WriteLine($"Skipping {entry.Key}");
continue;
}
if (options.Verbose)
{
Console.WriteLine($"Processing {entry.Key}");
}
entry.WriteToDirectory(options.OutputDirectory,
new ExtractionOptions()
{
ExtractFullPath = true,
Overwrite = true
});
} else
{
Console.WriteLine(entry.ToString());
}
}
}
catch (IndexOutOfRangeException)
{
//SevenZipArchive_BZip2_Split test needs this
stream.ThrowOnDispose = false;
throw;
}
stream.ThrowOnDispose = false;
});
}
}
}