Skip to content
This repository has been archived by the owner on Apr 11, 2023. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #15 from github/editor-hardening
Gracefully handle missing associations and editors
  • Loading branch information
Paul Betts committed Feb 15, 2013
2 parents 4849938 + 3cda05e commit 99f093d
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion Program.cs
Expand Up @@ -72,14 +72,30 @@ public static int Main(string[] args)
UseShellExecute = true,
};

var proc = Process.Start(psi);
Process proc;

try
{
proc = Process.Start(psi);
}
catch
{
Console.Error.WriteLine("Could not launch the default text editor, falling back to notepad.");

psi.FileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "notepad.exe");
psi.Arguments = path;

proc = Process.Start(psi);
}

// See http://stackoverflow.com/questions/3456383/process-start-returns-null
// In case of editor reuse (think VS) we can't block on the process so we only have two options. Either try
// to be clever and monitor the file for changes but it's quite possible that users save their file before
// being done with them so we'll go with the semi-sucky method of showing a message on the console
if (proc == null)
{
Console.CancelKeyPress += (s, e) => File.Delete(path);

Console.WriteLine("Press enter when you're done editing your commit message, or CTRL+C to abort");
Console.ReadLine();
}
Expand Down

0 comments on commit 99f093d

Please sign in to comment.