/// <summary>
        /// 픽시브 콘솔 리다이렉트
        /// </summary>
        static bool Redirect(string[] arguments, string contents)
        {
            arguments = CommandLineUtil.InsertWeirdArguments <PixivConsoleOption>(arguments, true, "-user");
            PixivConsoleOption option = CommandLineParser <PixivConsoleOption> .Parse(arguments);

            if (option.Error)
            {
                Console.Instance.WriteLine(option.ErrorMessage);
                if (option.HelpMessage != null)
                {
                    Console.Instance.WriteLine(option.HelpMessage);
                }
                return(false);
            }
            else if (option.Help)
            {
                PrintHelp();
            }
            else if (option.Login != null)
            {
                ProcessLogin(option.Login);
            }
            else if (option.User != null)
            {
                ProcessUser(option.User);
            }
            else if (option.ImageLink != null)
            {
                ProcessImageLink(option.ImageLink);
            }

            return(true);
        }
Example #2
0
        /// <summary>
        /// In 콘솔 리다이렉트
        /// </summary>
        static bool Redirect(string[] arguments, string contents)
        {
            arguments = CommandLineUtil.InsertWeirdArguments <InConsoleOption>(arguments, true, "-i");
            InConsoleOption option = CommandLineParser <InConsoleOption> .Parse(arguments);

            if (option.Error)
            {
                Console.Instance.WriteLine(option.ErrorMessage);
                if (option.HelpMessage != null)
                {
                    Console.Instance.WriteLine(option.HelpMessage);
                }
                return(false);
            }
            else if (option.Help)
            {
                PrintHelp();
            }
            else if (option.Input != null)
            {
                ProcessIn(option.Input);
            }

            return(true);
        }
Example #3
0
        /// <summary>
        /// Out 콘솔 리다이렉트
        /// </summary>
        static bool Redirect(string[] arguments, string contents)
        {
            arguments = CommandLineUtil.InsertWeirdArguments <OutConsoleOption>(arguments, contents != "", "-o");
            OutConsoleOption option = CommandLineParser <OutConsoleOption> .Parse(arguments);

            if (option.Error)
            {
                Console.Instance.WriteLine(option.ErrorMessage);
                if (option.HelpMessage != null)
                {
                    Console.Instance.WriteLine(option.HelpMessage);
                }
                return(false);
            }
            else if (option.Help)
            {
                PrintHelp();
            }
            else if (option.Output != null)
            {
                ProcessOut(option.Output, contents, option.Overwrite);
            }

            return(true);
        }
Example #4
0
        /// <summary>
        /// Internal 콘솔 리다이렉트
        /// </summary>
        static bool Redirect(string[] arguments, string contents)
        {
            arguments = CommandLineUtil.SplitCombinedOptions(arguments);
            if (CommandLineUtil.AnyArgument(arguments, "-e"))
            {
                arguments = CommandLineUtil.DeleteArgument(arguments, "-e");
                if (!CommandLineUtil.AnyStrings(arguments))
                {
                    arguments = CommandLineUtil.PushFront(arguments, "");
                }
            }
            arguments = CommandLineUtil.InsertWeirdArguments <InternalConsoleOption>(arguments, true, "-e");
            InternalConsoleOption option = CommandLineParser <InternalConsoleOption> .Parse(arguments);

            if (option.Error)
            {
                Console.Instance.WriteLine(option.ErrorMessage);
                if (option.HelpMessage != null)
                {
                    Console.Instance.WriteLine(option.HelpMessage);
                }
                return(false);
            }
            else if (option.Help)
            {
                PrintHelp();
            }
            else if (option.Enumerate != null)
            {
                ProcessEnumerate(option.Enumerate, option.EnumerateWithForms, option.EnumerateWithPrivate,
                                 option.EnumerateWithInstances, option.EnumerateWithStatic, option.EnumerateWithMethod);
            }
            else if (option.Get != null)
            {
                ProcessGet(option.Get, option.EnumerateWithForms, option.EnumerateWithInstances, option.EnumerateWithPrivate);
            }
            else if (option.Set != null)
            {
                ProcessSet(option.Set, option.EnumerateWithForms, option.EnumerateWithInstances);
            }
            else if (option.Call != null)
            {
                ProcessCall(option.Call, option.EnumerateWithForms, option.EnumerateWithInstances, option.CallWithReturn, option.CallOnAnotherThread);
            }

            return(true);
        }
Example #5
0
        /// <summary>
        /// Grep 콘솔 리다이렉트
        /// </summary>
        static bool Redirect(string[] arguments, string contents)
        {
            arguments = CommandLineUtil.SplitCombinedOptions(arguments);
            arguments = CommandLineUtil.InsertWeirdArguments <GrepConsoleOption>(arguments, contents != "", "--p");
            GrepConsoleOption option = CommandLineParser <GrepConsoleOption> .Parse(arguments, contents != "", contents);

            if (option.Input == null)
            {
                option.Input = new[] { contents };
            }

            if (option.Error)
            {
                Console.Instance.WriteLine(option.ErrorMessage);
                if (option.HelpMessage != null)
                {
                    Console.Instance.WriteLine(option.HelpMessage);
                }
                return(false);
            }
            else if (option.Help)
            {
                PrintHelp();
            }
            else if (option.Input == null)
            {
                Console.Instance.WriteErrorLine("Input is empty.");
            }
            else if (option.Pattern == null)
            {
                Console.Instance.WriteErrorLine("Pattern is empty.");
            }
            else
            {
                ProcessGrep(option.Input[0], option.Pattern[0], option.UsingRegex, option.ShowNumber, option.IgnoreCase);
            }

            return(true);
        }
Example #6
0
        public static void Start(string[] arguments)
        {
            var origin = arguments;

            arguments = CommandLineUtil.SplitCombinedOptions(arguments);
            arguments = CommandLineUtil.InsertWeirdArguments <Options>(arguments, true, "--url");
            var option = CommandLineParser.Parse <Options>(arguments);

            //
            //  Multi Commands
            //
            if (option.Net)
            {
                NetConsole.Start(origin.Skip(1).ToArray());
            }
            //
            //  Single Commands
            //
            else if (option.Help)
            {
                PrintHelp();
            }
            else if (option.Version)
            {
                PrintVersion();
            }
            else if (option.DialogMode)
            {
                Dialog.StartDialog();
            }
            else if (option.ListExtractor)
            {
                foreach (var extractor in ExtractorManager.Extractors)
                {
                    System.Console.WriteLine($"[{extractor.GetType().Name}]");
                    System.Console.WriteLine($"[HostName] {extractor.HostName}");
                    System.Console.WriteLine($"[Checker] {extractor.ValidUrl}");
                    System.Console.WriteLine($"[Information] {extractor.ExtractorInfo}");
                    var builder = new StringBuilder();
                    CommandLineParser.GetFields(extractor.RecommendOption("").GetType()).ToList().ForEach(
                        x =>
                    {
                        var key = x.Key;
                        if (!key.StartsWith("--"))
                        {
                            return;
                        }
                        if (!string.IsNullOrEmpty(x.Value.Item2.ShortOption))
                        {
                            key = $"{x.Value.Item2.ShortOption}, " + key;
                        }
                        var help = "";
                        if (!string.IsNullOrEmpty(x.Value.Item2.Help))
                        {
                            help = $"[{x.Value.Item2.Help}]";
                        }
                        if (!string.IsNullOrEmpty(x.Value.Item2.Info))
                        {
                            builder.Append($"   {key}".PadRight(30) + $" {x.Value.Item2.Info} {help}\r\n");
                        }
                        else
                        {
                            builder.Append($"   {key}".PadRight(30) + $" {help}\r\n");
                        }
                    });
                    if (builder.ToString() != "")
                    {
                        System.Console.WriteLine($"[Options]");
                        System.Console.Write(builder.ToString());
                    }
                    System.Console.WriteLine($"-------------------------------------------------------------");
                }
            }
            else if (option.Url != null)
            {
                if (!(option.Url[0].StartsWith("https://") || option.Url[0].StartsWith("http://")))
                {
                    System.Console.WriteLine($"'{option.Url[0]}' is not correct url format or not supported scheme.");
                }

                var weird  = CommandLineUtil.GetWeirdArguments <Options>(arguments);
                var n_args = new List <string>();

                weird.ForEach(x => n_args.Add(arguments[x]));

                ProcessExtract(option.Url[0], n_args.ToArray(), option.PathFormat, option.ExtractInformation, option.ExtractLinks, option.PrintProcess, option.DisableDownloadProgress);
            }
            else if (option.Error)
            {
                System.Console.WriteLine(option.ErrorMessage);
                if (option.HelpMessage != null)
                {
                    System.Console.WriteLine(option.HelpMessage);
                }
                return;
            }
            else
            {
                System.Console.WriteLine("Nothing to work on.");
                System.Console.WriteLine("Enter './Koromo_Copy.Console --help' to get more information");
            }

            return;
        }