protected KrakenProcess() { UseShellExecute = true; SwallowExceptions = true; CreateNoWindow = false; Verb = ProcessVerb.None; }
public static int Process(Options options, ProcessVerb verb) { _options = options; var pathsToProcess = EnumeratePathsToProcess(_options.Paths.Select(str => new PathNode(str, true)).ToList()).ToList(); if (!_options.Temporary || _options.DryRun) { if (verb == ProcessVerb.Retrack) { SaveRetrackChanges(pathsToProcess); } else { SaveUntrackChanges(pathsToProcess); } } if (_options.Verbose) { Console.WriteLine($"Processing {pathsToProcess.Count} paths"); } var gitExe = GetGitExe(); foreach (var pathToProcess in pathsToProcess) { var toBeTracked = verb == ProcessVerb.Retrack; if (!pathToProcess.IsIncluded) { toBeTracked = !toBeTracked; } var args = toBeTracked ? $"update-index --no-assume-unchanged \"{Path.GetFullPath(pathToProcess.Path).RelativeTo(Environment.CurrentDirectory)}\"" : $"update-index --assume-unchanged \"{Path.GetFullPath(pathToProcess.Path).RelativeTo(Environment.CurrentDirectory)}\""; Console.WriteLine($"git.exe {args}"); if (!_options.DryRun) { var startInfo = new ProcessStartInfo() { Arguments = args, FileName = gitExe, UseShellExecute = false }; var proc = System.Diagnostics.Process.Start(startInfo); proc.WaitForExit(); if (proc.ExitCode != 0) { return(proc.ExitCode); } } } return(0); }
public static int Process(Options options, ProcessVerb verb) { _options = options; var pathsToProcess = EnumeratePathsToProcess(_options.Paths.Select(str => new PathNode(str, true)).ToList()).ToList(); if (!_options.Temporary || _options.DryRun) { if (verb == ProcessVerb.Retrack) { SaveRetrackChanges(pathsToProcess); } else { SaveUntrackChanges(pathsToProcess); } } if (_options.Verbose) Console.WriteLine($"Processing {pathsToProcess.Count} paths"); var gitExe = GetGitExe(); foreach (var pathToProcess in pathsToProcess) { var toBeTracked = verb == ProcessVerb.Retrack; if (!pathToProcess.IsIncluded) toBeTracked = !toBeTracked; var args = toBeTracked ? $"update-index --no-assume-unchanged \"{Path.GetFullPath(pathToProcess.Path).RelativeTo(Environment.CurrentDirectory)}\"" : $"update-index --assume-unchanged \"{Path.GetFullPath(pathToProcess.Path).RelativeTo(Environment.CurrentDirectory)}\""; Console.WriteLine($"git.exe {args}"); if (!_options.DryRun) { var startInfo = new ProcessStartInfo() { Arguments = args, FileName = gitExe, UseShellExecute = false }; var proc = System.Diagnostics.Process.Start(startInfo); proc.WaitForExit(); if (proc.ExitCode != 0) return proc.ExitCode; } } return 0; }
/// <summary> /// Starts an process using the passed parameters. /// </summary> /// <param name="filename">The filename to execute.</param> /// <param name="arguments">The arguments to pass to the process. This parameter is optional.</param> /// <param name="workingDirectory">The workingdirectory of the process. This parameter is optional.</param> /// <param name="operation">The operation to be performed. This parameter is optional. By default, <see cref="ProcessVerb.Open"/> will be used.</param> /// <param name="visibility">A <see cref="ProcessVisibility"/>-value to determine how the new process will be shown. This parameter is optional. By default, <see cref="ProcessVisibility.Normal"/> will be used.</param> /// <param name="suppressErrors">A value determining if exception will be supressed or not.</param> /// <returns><code>true</code> if the operation succeeds, otherwise <code>false</code>.</returns> public static bool ShellExecute(string filename, string arguments = null, string workingDirectory = null, ProcessVerb operation = ProcessVerb.Open, ProcessVisibility visibility = ProcessVisibility.Normal, bool suppressErrors = true) { if (!AutomationFactory.IsAvailable) { throw new Exception("Automation unavailable due to insufficient rights."); } if (filename == null) { throw new ArgumentNullException("commandline"); } if (String.IsNullOrWhiteSpace(filename)) { throw new ArgumentException("Invalid commandline.", "commandline"); } var args = arguments ?? ""; var dir = workingDirectory ?? ""; var verb = operation.ToString().ToLowerInvariant(); int mode = (int)visibility; dynamic shell = null; try { using (shell = AutomationFactory.CreateObject("Shell.Application")) { shell.ShellExecute(filename, args, dir, verb, mode); } } catch (Exception ex) { #if DEBUG Debug.WriteLine(ex.ToString()); #endif if (suppressErrors) { return(false); } throw ex; } finally { shell = null; GC.Collect(); GC.WaitForPendingFinalizers(); } return(true); }
/// <summary> /// Starts an process using the passed parameters. /// </summary> /// <param name="filename">The filename to execute.</param> /// <param name="arguments">The arguments to pass to the process. This parameter is optional.</param> /// <param name="workingDirectory">The workingdirectory of the process. This parameter is optional.</param> /// <param name="operation">The operation to be performed. This parameter is optional. By default, <see cref="ProcessVerb.Open"/> will be used.</param> /// <param name="visibility">A <see cref="ProcessVisibility"/>-value to determine how the new process will be shown. This parameter is optional. By default, <see cref="ProcessVisibility.Normal"/> will be used.</param> /// <param name="suppressErrors">A value determining if exception will be supressed or not.</param> /// <returns><code>true</code> if the operation succeeds, otherwise <code>false</code>.</returns> public static bool ShellExecute(string filename, string arguments = null, string workingDirectory = null, ProcessVerb operation = ProcessVerb.Open, ProcessVisibility visibility = ProcessVisibility.Normal, bool suppressErrors = true) { if (!AutomationFactory.IsAvailable) throw new Exception("Automation unavailable due to insufficient rights."); if (filename == null) throw new ArgumentNullException("commandline"); if (String.IsNullOrWhiteSpace(filename)) throw new ArgumentException("Invalid commandline.", "commandline"); var args = arguments ?? ""; var dir = workingDirectory ?? ""; var verb = operation.ToString().ToLowerInvariant(); int mode = (int)visibility; dynamic shell = null; try { using (shell = AutomationFactory.CreateObject("Shell.Application")) { shell.ShellExecute(filename, args, dir, verb, mode); } } catch (Exception ex) { #if DEBUG Debug.WriteLine(ex.ToString()); #endif if (suppressErrors) return false; throw ex; } finally { shell = null; GC.Collect(); GC.WaitForPendingFinalizers(); } return true; }