small refactor

This commit is contained in:
Adam Hathcock
2017-05-19 16:47:32 +01:00
parent 723f4dc83f
commit e7720ccc4e
2 changed files with 43 additions and 43 deletions

View File

@@ -1,5 +1,8 @@
using System;
using System.Collections.Generic;
using System.IO;
using CommandLine;
using SharpCompress.Archives;
namespace SharpCompress
{
@@ -11,5 +14,44 @@ namespace SharpCompress
[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;
}
}
}

View File

@@ -1,7 +1,4 @@
using System;
using System.IO;
using CommandLine;
using SharpCompress.Archives;
namespace SharpCompress
{
@@ -11,49 +8,10 @@ namespace SharpCompress
{
return Parser.Default.ParseArguments<InfoOptions, ExtractOptions>(args)
.MapResult(
(InfoOptions opts) => Info(opts),
(InfoOptions opts) => opts.Process(),
(ExtractOptions opts) => Extract(opts),
errs => 1);
}
public static int Info(InfoOptions options)
{
foreach (var s in options.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 (options.ShowEntries)
{
foreach (var archiveEntry in archive.Entries)
{
Console.WriteLine($"\tEntry: {archiveEntry.Key}");
}
}
}
}
catch (Exception e)
{
Console.WriteLine("Archive Type is unknown.");
}
}
else
{
Console.WriteLine($"{s} does not exist");
return 1;
}
}
return 0;
}
public static int Extract(ExtractOptions options)
{