12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Threading.Tasks;
- using CommandLine;
- using CSharpx;
-
- namespace agbidx
- {
- [Verb("pokemon", HelpText = "Parse a combination of Pokémon front- and backsprite, and output two files respectively.")]
- class PokespriteOptions {
- [Option('i', "input-files", Required = true, HelpText = "Input images to be processed")]
- public IEnumerable<string> Input {get;set;}
-
- [Option('o', "output-directory", Default = ".", Required = false, HelpText = "Output directory for the processed images, defaults to current directory")]
- public string OutputDirectory{get;set;}
-
- [Option('v', "verbose", Default = false, Required = false, HelpText = "Show Verbose information")]
- public bool Verbose{get;set;}
-
- [Option('r', "recursive", Default = false, Required = false, HelpText = "Recursively scan directories for images, by default only one level is scanned, if an input argument is a directory")]
- public bool Recursive{get;set;}
- }
- class Program
- {
- static async Task<int> Main(string[] args)
- {
- return await CommandLine.Parser.Default.ParseArguments<PokespriteOptions>(args)
- .MapResult(
- async (PokespriteOptions opts) => await RunPokespritesAndReturnExitCode(opts),
- async (IEnumerable<Error> errs) => await Task.Run<int>(() => 1));
- }
-
- static async Task<int> RunPokespritesAndReturnExitCode(PokespriteOptions opts)
- {
- try
- {
- if(!Directory.Exists(opts.OutputDirectory))
- Directory.CreateDirectory(opts.OutputDirectory);
- await Task.WhenAll(opts.Input.Select(s => ImageLib.BitmapProcessor.ProcessPokemonImage(opts.OutputDirectory, s, opts.Verbose, true, opts.Recursive)));
- return 0;
- }
- catch(Exception ex)
- {
- Console.WriteLine("An error occured: " + ex.Message);
- return 1;
- }
-
- }
- }
- }
|