mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-09-24 16:05:27 +00:00
small refactor
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user