JobManager/Archiver/Program.cs

57 lines
2.1 KiB
C#
Raw Permalink Normal View History

2024-06-01 20:41:42 +09:00
using Archiver.Lib;
namespace Archiver;
public class Program
{
public static void Main(string[] args)
{
try
{
Options options = CommandLine.Parser.Default.ParseArguments<Options>(args).Value;
if (options is null || options.InputFiles is null || string.IsNullOrEmpty(options.OutputPath))
{
Console.WriteLine("[Archiver] Usage: archiver -i <input files> -o <output file>");
return;
}
int c = options.InputFiles.Count();
if (c == 0)
{
Console.WriteLine("[Archiver] Empty input files.");
return;
}
if (c > 1)
{
Console.WriteLine($"[Archiver] Encode");
Console.WriteLine($"[Archiver] Input : {string.Join(", ", options.InputFiles)}");
Console.WriteLine($"[Archiver] Output: {options.OutputPath}");
ArchiveEncoder.Encode(options.InputFiles, options.OutputPath).ConfigureAwait(false).GetAwaiter().GetResult();
}
else
{
string inputFile = options.InputFiles.ToArray()[0];
if (ArchiveEncoder.IsArchiveFile(inputFile))
{
Console.WriteLine($"[Archiver] Decode");
Console.WriteLine($"[Archiver] Input : {inputFile}");
Console.WriteLine($"[Archiver] Output: {options.OutputPath}");
ArchiveDecoder.Decode(inputFile, options.OutputPath).ConfigureAwait(false).GetAwaiter().GetResult();
}
else
{
Console.WriteLine($"[Archiver] Encode");
Console.WriteLine($"[Archiver] Input : {string.Join(',', options.InputFiles)}");
Console.WriteLine($"[Archiver] Output: {options.OutputPath}");
ArchiveEncoder.Encode(inputFile, options.OutputPath).ConfigureAwait(false).GetAwaiter().GetResult();
}
}
}
catch (Exception ex)
{
Console.WriteLine($"[Archiver] Error: {ex.Message}");
}
}
}