/
InfoOptions.cs
57 lines (52 loc) · 1.79 KB
/
InfoOptions.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 System;
using System.Collections.Generic;
using System.IO;
using CommandLine;
using SharpCompress.Archives;
namespace SharpCompress
{
[Verb("i", HelpText = "Information about an archive")]
public class InfoOptions
{
[Value(0, Min = 1)]
public IEnumerable<string> Path { get; set; }
[Option('e', HelpText = "Show Archive Entry Information")]
public bool ShowEntries { get; set; }
public int Process()
{
foreach (var s in Path)
{
if (File.Exists(s))
{
Console.WriteLine($"=== Archive: {s}");
try
{
using (var archive = ArchiveFactory.Open(File.OpenRead(s)))
{
Console.WriteLine($"Archive Type: {archive.Type}");
Console.WriteLine($"Size: {archive.TotalSize}");
Console.WriteLine($"Uncompressed Size: {archive.TotalUncompressSize}");
if (ShowEntries)
{
foreach (var archiveEntry in archive.Entries)
{
Console.WriteLine($"\tEntry: {archiveEntry.Key}");
}
}
}
}
catch (Exception)
{
Console.WriteLine("Archive Type is unknown.");
}
}
else
{
Console.WriteLine($"{s} does not exist");
return 1;
}
}
return 0;
}
}
}