Ejemplo n.º 1
0
        //  ____                       _   ___
        // / ___| _ __ ___   __ _ _ __| |_|_ _|_ __ ___   __ _  __ _  ___
        // \___ \| '_ ` _ \ / _` | '__| __|| || '_ ` _ \ / _` |/ _` |/ _ \
        //  ___) | | | | | | (_| | |  | |_ | || | | | | | (_| | (_| |  __/
        // |____/|_| |_| |_|\__,_|_|   \__|___|_| |_| |_|\__,_|\__, |\___|
        //                                                     |___/

        // todo: further improve UI

        // todo: remove SmartImage nuget package stuff

        // todo: fix access modifiers


        /**
         * Entry point
         */
        private static void Main(string[] args)
        {
            Console.Title = RuntimeInfo.NAME;
            Console.SetWindowSize(120, 35);
            Console.Clear();

            RuntimeInfo.Setup();
            SearchConfig.ReadSearchConfigArguments(args);

            if (SearchConfig.Config.NoArguments)
            {
                Commands.RunCommandMenu();
                Console.Clear();
            }

            var img = SearchConfig.Config.Image;

            bool run = !String.IsNullOrWhiteSpace(img);

            if (!run)
            {
                return;
            }

            var results = new SearchResult[(int)SearchEngines.All];
            var ok      = Search.RunSearch(img, ref results);

            if (!ok)
            {
                CliOutput.WriteError("Search failed");
                return;
            }

            Commands.HandleConsoleOptions(results);

            // Exit
            SearchConfig.Cleanup();
        }
Ejemplo n.º 2
0
        /**
         * Entry point
         */
        private static void Main(string[] args)
        {
            if (args == null || args.Length == 0)
            {
                return;
            }

            RuntimeInfo.Setup();

            CliParse.ReadArguments(args);

            var img = RuntimeInfo.Config.Image;

            bool run = img != null;

            if (run)
            {
                var sr      = new SearchResults();
                var ok      = Search.RunSearch(img, ref sr);
                var results = sr.Results;

                // Console.WriteLine("Elapsed: {0:F} sec", result.Duration.TotalSeconds);

                ConsoleKeyInfo cki;

                do
                {
                    Console.Clear();

                    for (int i = 0; i < sr.Results.Length; i++)
                    {
                        var r = sr.Results[i];

                        var tag = (i + 1).ToString();
                        if (r != null)
                        {
                            string str = r.Format(tag);

                            Console.Write(str);
                        }
                        else
                        {
                            Console.WriteLine("{0} - ...", tag);
                        }
                    }

                    Console.WriteLine();

                    // Exit
                    if (RuntimeInfo.Config.AutoExit)
                    {
                        SearchConfig.Cleanup();
                        return;
                    }

                    CliOutput.WriteSuccess("Enter the result number to open or escape to quit.");


                    while (!Console.KeyAvailable)
                    {
                        // Block until input is entered.
                    }


                    // Key was read

                    cki = Console.ReadKey(true);
                    char keyChar = cki.KeyChar;

                    if (Char.IsNumber(keyChar))
                    {
                        int idx = (int)Char.GetNumericValue(cki.KeyChar) - 1;

                        if (idx < results.Length && idx >= 0)
                        {
                            var res = results[idx];
                            WebAgent.OpenUrl(res.Url);
                        }
                    }
                } while (cki.Key != ConsoleKey.Escape);

                // Exit
                SearchConfig.Cleanup();
            }
            else
            {
                //CliOutput.WriteInfo("Exited");
            }
        }
Ejemplo n.º 3
0
        //  ____                       _   ___
        // / ___| _ __ ___   __ _ _ __| |_|_ _|_ __ ___   __ _  __ _  ___
        // \___ \| '_ ` _ \ / _` | '__| __|| || '_ ` _ \ / _` |/ _` |/ _ \
        //  ___) | | | | | | (_| | |  | |_ | || | | | | | (_| | (_| |  __/
        // |____/|_| |_| |_|\__,_|_|   \__|___|_| |_| |_|\__,_|\__, |\___|
        //                                                     |___/

        /*
         * todo: refactor access modifiers
         */

        /*
         * Entry point
         */
        private static void Main(string[] args)
        {
            /*
             * Set up console
             */

            Console.Title = RuntimeInfo.NAME;
            Console.SetWindowSize(120, 45);
            Console.OutputEncoding = Encoding.Unicode;
            Console.Clear();

            NConsoleUI.DefaultName = RuntimeInfo.NAME_BANNER;


            /*
             * Run search
             */

            try {
                Integration.Setup();
                SearchConfig.ReadSearchConfigArguments(args);

                if (SearchConfig.Config.NoArguments)
                {
                    ConsoleMainMenu.Run();
                    Console.Clear();
                }

                string img = SearchConfig.Config.Image;

                // Run checks
                if (!SearchClient.IsFileValid(img))
                {
                    return;
                }

                // Run search

                using var searchClient = new SearchClient(img);
                searchClient.Start();

                // Show results

                NConsole.IO.HandleOptions(searchClient.Results);
            }
            catch (Exception exception) {
#if !DEBUG
                var cr = new CrashReport(exception);

                Console.WriteLine(cr);

                var src = cr.WriteToFile();

                Console.WriteLine("Crash log written to {0}", src);

                Console.WriteLine("Please file an issue and attach the crash log.");

                Network.OpenUrl(RuntimeInfo.Issue);

                NConsole.IO.WaitForInput();
#else
                Console.WriteLine(exception);
#endif
            }
            finally {
                // Exit
                SearchConfig.UpdateFile();
            }
        }
Ejemplo n.º 4
0
        private static void Main(string[] args)
        {
            /*
             * Setup
             * Check compatibility
             */
            Info.Setup();


            /*
             * Set up console
             */

            Console.Title = Info.NAME;

            NConsole.AutoResizeHeight = false;
            NConsole.Resize(Interface.MainWindowWidth, Interface.MainWindowHeight);

            Console.CancelKeyPress += (sender, eventArgs) => { };

            Console.Clear();

            Console.WriteLine(Info.NAME_BANNER);
            NConsole.WriteInfo("Setting up...");


            /*
             * Set up NConsole
             */
            NConsole.Init();
            NConsoleInterface.DefaultName = Info.NAME_BANNER;

            /*
             * Check for any legacy integrations that need to be migrated
             */
            bool cleanupOk = LegacyIntegration.LegacyCleanup();

            if (!cleanupOk)
            {
                NConsole.WriteError("Could not migrate legacy features");
            }

            /*
             * Run search
             */

            try {
                // Setup
                UserSearchConfig.Config.EnsureConfig();
                Integration.Setup();

                // Run UI if not using command line arguments
                if (UserSearchConfig.Config.NoArguments)
                {
                    Interface.Run();
                    Console.Clear();
                }

                // Image is automatically read from command line arguments,
                // or it is input through the main menu


                // Exit if no image is given
                if (!UserSearchConfig.Config.HasImageInput)
                {
                    return;
                }

SEARCH:

                // Run search

                var cfg2 = new SearchConfig()
                {
                    SearchEngines   = UserSearchConfig.Config.SearchEngines,
                    PriorityEngines = UserSearchConfig.Config.PriorityEngines,
                    Query           = UserSearchConfig.Config.ImageInput
                };

                var client = new SearchClient(cfg2);
                client.RunSearchAsync();

                var res = client.Results;


                // Show results
                var i = new NConsoleInterface(client.Results)
                {
                    SelectMultiple = false,
                    Prompt         = InterfacePrompt
                };

                var v = i.Run();
            }
            catch (Exception exception) {
#if !DEBUG
                var cr = new CrashReport(exception);

                Console.WriteLine(cr);


                var src = cr.WriteToFile();
                Console.WriteLine(exception.InnerException?.StackTrace);
                Console.WriteLine(exception.InnerException?.Message);
                Console.WriteLine("Crash log written to {0}", src);

                Console.WriteLine("Please file an issue and attach the crash log.");

                //Network.OpenUrl(Info.Issue);

                NConsole.WaitForInput();
#else
                Console.WriteLine(exception);
#endif
            }
            finally {
                // Exit

                if (UserSearchConfig.Config.UpdateConfig)
                {
                    UserSearchConfig.Config.SaveFile();
                }
            }
        }