Exemplo n.º 1
0
        private static void Extract(Options.Extract opts)
        {
            WriteHeader();

            if (!File.Exists(opts.ParArchivePath))
            {
                Console.WriteLine($"ERROR: \"{opts.ParArchivePath}\" not found!!!!");
                return;
            }

            if (Directory.Exists(opts.OutputDirectory))
            {
                Console.WriteLine("WARNING: Output directory already exists. Its contents may be overwritten.");
                Console.Write("Continue? (y/N) ");
                string answer = Console.ReadLine();
                if (!string.IsNullOrEmpty(answer) && answer.ToUpperInvariant() != "Y")
                {
                    Console.WriteLine("CANCELLED BY USER.");
                    return;
                }
            }

            Directory.CreateDirectory(opts.OutputDirectory);

            var parameters = new ParArchiveReaderParameters
            {
                Recursive = opts.Recursive,
            };

            using Node par = NodeFactory.FromFile(opts.ParArchivePath);
            par.TransformWith <ParArchiveReader, ParArchiveReaderParameters>(parameters);

            Extract(par, opts.OutputDirectory);
        }
Exemplo n.º 2
0
        private static void Main(string[] args)
        {
            using var parser = new Parser(with => with.HelpWriter = null);
            ParserResult <object> parserResult = parser.ParseArguments <Options.List, Options.Extract, Options.Create, Options.Remove, Options.Add>(args);

            parserResult
            .WithParsed <Options.List>(List)
            .WithParsed <Options.Extract>(Extract)
            .WithParsed <Options.Create>(Create)
            .WithParsed <Options.Remove>(Remove)
            .WithParsed <Options.Add>(Add)
            .WithNotParsed(x =>
            {
                if (args.Length == 1)
                {
                    if (File.Exists(args[0]))
                    {
                        var opts = new Options.Extract
                        {
                            ParArchivePath  = args[0],
                            OutputDirectory = string.Concat(args[0], ".unpack"),
                            Recursive       = false,
                        };

                        Extract(opts);
                        return;
                    }

                    if (Directory.Exists(args[0]))
                    {
                        var opts = new Options.Create
                        {
                            InputDirectory = args[0],
                            ParArchivePath =
                                args[0].EndsWith(".unpack", StringComparison.InvariantCultureIgnoreCase)
                                        ? args[0].Substring(0, args[0].Length - 7)
                                        : string.Concat(args[0], ".par"),
                            AlternativeMode = false,
                            Compression     = 1,
                        };

                        Create(opts);
                        return;
                    }
                }

                var helpText = HelpText.AutoBuild(
                    parserResult,
                    h =>
                {
                    h.AutoHelp    = false;      // hide --help
                    h.AutoVersion = false;      // hide --version
                    return(HelpText.DefaultParsingErrorsHandler(parserResult, h));
                },
                    e => e);

                Console.WriteLine(helpText);
            });
        }