private void FindItWithMatching(string inputPath, string matchingFileName) { if (!inputPath.EndsWith(@"\")) { inputPath += @"\"; } string[] files = Directory.GetFiles(inputPath, matchingFileName + ".exe", SearchOption.AllDirectories); if (files.Length > 0) { if (ApplicationContext.CacheFuzzyMatches) { CommandPairManager.AddCommand(new CommandPair { Command = matchingFileName, Path = files[0] }); } //the matches for fuzzy searching are not cached RunProcess(files); } }
private void FindIt(string inputPath, string exeFileName, bool hasExtension) { if (launched) { return; } if (!inputPath.EndsWith(@"\")) { inputPath += @"\"; } if (hasFixedDepth) { //check depth int length = inputPath.Split(new[] { Path.DirectorySeparatorChar }, StringSplitOptions.None).Length; int current = length - currentRootDepth; if (current > depth) { if (hasRunInDebugMode) { Console.WriteLine("Bailing out of {0} due to depth restriction", inputPath); } return; } } string[] files; if (hasExtension) { //user is looking for specific file files = Directory.GetFiles(inputPath, exeFileName); if (files.Length > 0) { RunProcess(files); CommandPairManager.AddCommand(new CommandPair { Command = exeFileName, Path = files[0] }); return; } } else { //search with all extensions foreach (string ext in ApplicationContext.Extensions) { files = Directory.GetFiles(inputPath, exeFileName + "." + ext); if (files.Length > 0) { RunProcess(files); CommandPairManager.AddCommand(new CommandPair { Command = exeFileName, Path = files[0] }); return; } } } string[] directories = Directory.GetDirectories(inputPath); foreach (string d in directories) { FindIt(d, exeFileName, hasExtension); } }
private static void Main(string[] args) { Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); Thread.CurrentThread.Priority = ThreadPriority.Highest; Console.WriteLine("ExeLauncher"); Console.WriteLine("(c) 2012-2014 Marius Gheorghe"); Console.WriteLine(""); try { if (ParseConfig() == false) { return; } } catch (Exception ex) { Console.WriteLine("Error {0}", ex.Message); return; } //any paths if (ApplicationContext.Paths.Count == 0) { Console.WriteLine("No valid input paths found. Modify the config file and enter the paths."); return; } //is it help ? if (args.Length == 1 && args[0] == "?") { Console.WriteLine("Sample: el starcraft.exe"); return; } List <string> listArguments = new List <string>(); for (int i = 1; i < args.Length; i++) { listArguments.Add(args[i]); } //load previously cached commands CommandPairManager.LoadCommands(); //look it up string command = args[0]; //look it in the cache CommandPair commandPair = CommandPairManager.GetCommand(command); if (commandPair != null) { if (File.Exists(commandPair.Path)) { Console.WriteLine("found it in cache"); (new Launcher(listArguments)).RunProcess(new[] { commandPair.Path }); return; } } bool result = (new Launcher(listArguments)).Launch(command); if (result == false) { Console.WriteLine("No luck....Make sure you typed the exe filename correctly"); } CommandPairManager.Persist(); }