public static void RunContextMenuIntegration(string option) { switch (option) { case OPT_ADD: string fullPath = RuntimeInfo.ExeLocation; if (!RuntimeInfo.IsExeInAppFolder) { bool v = CliOutput.ReadConfirm("Could not find exe in system path. Add now?"); if (v) { RuntimeInfo.Setup(); return; } } // Add command string[] commandCode = { "@echo off", String.Format("reg.exe add {0} /ve /d \"{1} \"\"%%1\"\"\" /f >nul", RuntimeInfo.REG_SHELL_CMD, fullPath) }; Cli.CreateRunBatchFile("add_to_menu.bat", commandCode); // Add icon string[] iconCode = { "@echo off", String.Format("reg.exe add {0} /v Icon /d \"{1}\" /f >nul",RuntimeInfo.REG_SHELL, fullPath) }; Cli.CreateRunBatchFile("add_icon_to_menu.bat", iconCode); break; case OPT_REM: // reg delete HKEY_CLASSES_ROOT\*\shell\SmartImage // const string DEL = @"reg delete HKEY_CLASSES_ROOT\*\shell\SmartImage"; string[] code = { "@echo off", String.Format(@"reg.exe delete {0} /f >nul", RuntimeInfo.REG_SHELL) }; Cli.CreateRunBatchFile("rem_from_menu.bat", code); break; } }
// ____ _ ___ // / ___| _ __ ___ __ _ _ __| |_|_ _|_ __ ___ __ _ __ _ ___ // \___ \| '_ ` _ \ / _` | '__| __|| || '_ ` _ \ / _` |/ _` |/ _ \ // ___) | | | | | | (_| | | | |_ | || | | | | | (_| | (_| | __/ // |____/|_| |_| |_|\__,_|_| \__|___|_| |_| |_|\__,_|\__, |\___| // |___/ // 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(); }
/** * 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"); } }