// ____ _ ___ // / ___| _ __ ___ __ _ _ __| |_|_ _|_ __ ___ __ _ __ _ ___ // \___ \| '_ ` _ \ / _` | '__| __|| || '_ ` _ \ / _` |/ _` |/ _ \ // ___) | | | | | | (_| | | | |_ | || | | | | | (_| | (_| | __/ // |____/|_| |_| |_|\__,_|_| \__|___|_| |_| |_|\__,_|\__, |\___| // |___/ /* * 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(); } }
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(); } } }
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 client = new SearchClient(UserSearchConfig.Config); client.Start(); // Show results var i = new NConsoleInterface(client.Results) { SelectMultiple = false, Prompt = InterfacePrompt }; var v = i.Run(); //todo // refine search if (v.Any() && (bool)v.First()) { Debug.WriteLine($"Re-search"); var yandex = client.Results.Find(r => r.Name == "Yandex"); var configImageInput = MediaTypes.IsDirect(yandex.Url, MimeType.Image) ? yandex.Url : yandex.ExtendedResults.First(e => MediaTypes.IsDirect(e.Url, MimeType.Image))?.Url; //var configImageInput = SearchClient.Client.Results.FirstOrDefault(r=>MediaTypes.IsDirect(r.Url))?.Url; Debug.WriteLine($">>>> {configImageInput}"); Console.Clear(); UserSearchConfig.Config.ImageInput = configImageInput; goto SEARCH; } } 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(); } } }
// ____ _ ___ // / ___| _ __ ___ __ _ _ __| |_|_ _|_ __ ___ __ _ __ _ ___ // \___ \| '_ ` _ \ / _` | '__| __|| || '_ ` _ \ / _` |/ _` |/ _ \ // ___) | | | | | | (_| | | | |_ | || | | | | | (_| | (_| | __/ // |____/|_| |_| |_|\__,_|_| \__|___|_| |_| |_|\__,_|\__, |\___| // |___/ /* * todo: refactor access modifiers * todo: maybe create a separate unit testing project */ /* * Entry point */ private static void Main(string[] args) { /* * Set up console */ Console.Title = RuntimeInfo.NAME; Console.SetWindowSize(120, 50); Console.OutputEncoding = Encoding.Unicode; Console.Clear(); NConsole.Init(); NConsoleUI.DefaultName = RuntimeInfo.NAME_BANNER; /* * Run search */ try { // Setup SearchConfig.Config.Setup(); Integration.Setup(); // Run UI if not using command line arguments if (SearchConfig.Config.NoArguments) { MainMenu.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 (String.IsNullOrWhiteSpace(SearchConfig.Config.Image)) { return; } // Run search SearchClient.Client.Start(); // Show results NConsoleIO.HandleOptions(SearchClient.Client.Interface); } 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); NConsoleIO.WaitForInput(); #else Console.WriteLine(exception); #endif } finally { // Exit SearchConfig.Config.UpdateFile(); } }