From 4c6c2c4552e488372daf1d479e8a6dcdf32bc280 Mon Sep 17 00:00:00 2001 From: Bryan Wolf Date: Mon, 15 Sep 2014 15:07:33 -0500 Subject: [PATCH 1/3] Changed environment variable to no longer use ~ AppData isn't necessarily a directory underneath $Home in some environments. Changed to use the DirectoryInfo.DirectoryName instead and reverse the slashes. --- Program.cs | 15 ++++++++------- Properties/AssemblyInfo.cs | 4 ++-- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Program.cs b/Program.cs index 843da6f..53d97a0 100644 --- a/Program.cs +++ b/Program.cs @@ -27,13 +27,13 @@ public static int Main(string[] args) if (IsProcessElevated()) { MessageBox.Show("Run this application as a normal user (not as Elevated Administrator)", - "App is Elevated", MessageBoxButtons.OK, MessageBoxIcon.Error ); + "App is Elevated", MessageBoxButtons.OK, MessageBoxIcon.Error); return -1; } if (MessageBox.Show( - "Do you want to use your default text editor as your commit editor?", - "Installing GitPad", MessageBoxButtons.YesNo) + "Do you want to use your default text editor as your commit editor?", + "Installing GitPad", MessageBoxButtons.YesNo) != DialogResult.Yes) { return -1; @@ -48,11 +48,12 @@ public static int Main(string[] args) var dest = new FileInfo(Environment.ExpandEnvironmentVariables(@"%AppData%\GitPad\GitPad.exe")); File.Copy(Assembly.GetExecutingAssembly().Location, dest.FullName, true); - Environment.SetEnvironmentVariable("EDITOR", "~/AppData/Roaming/GitPad/GitPad.exe", EnvironmentVariableTarget.User); + Environment.SetEnvironmentVariable("EDITOR", dest.FullName.Replace('\\', '/'), EnvironmentVariableTarget.User); return 0; } int ret = 0; + string fileData = null; string path = null; try @@ -131,7 +132,7 @@ public static int Main(string[] args) static void WriteStringToFile(string path, string fileData, LineEndingType lineType, bool emitUTF8Preamble) { - using(var of = File.Open(path, FileMode.Create)) + using (var of = File.Open(path, FileMode.Create)) { var buf = Encoding.UTF8.GetBytes(ForceLineEndings(fileData, lineType)); if (emitUTF8Preamble) @@ -145,7 +146,7 @@ public static string ForceLineEndings(string fileData, LineEndingType type) var ret = new StringBuilder(fileData.Length); string ending; - switch(type) + switch (type) { case LineEndingType.Windows: ending = "\r\n"; @@ -174,7 +175,7 @@ public static string ForceLineEndings(string fileData, LineEndingType type) public static unsafe bool IsProcessElevated() { - if (Environment.OSVersion.Version < new Version(6,0,0,0)) + if (Environment.OSVersion.Version < new Version(6, 0, 0, 0)) { // Elevation is not a thing. return false; diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index 13103a1..a8b3253 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.4.0.0")] -[assembly: AssemblyFileVersion("1.4.0.0")] +[assembly: AssemblyVersion("1.4.1.0")] +[assembly: AssemblyFileVersion("1.4.1.0")] From 22c4b9881d6df525a3ed11b3e945192199c2c243 Mon Sep 17 00:00:00 2001 From: Bryan Date: Mon, 15 Sep 2014 23:21:02 -0500 Subject: [PATCH 2/3] Revert "Changed environment variable to no longer use ~" This reverts commit 4c6c2c4552e488372daf1d479e8a6dcdf32bc280. --- Program.cs | 15 +++++++-------- Properties/AssemblyInfo.cs | 4 ++-- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/Program.cs b/Program.cs index 53d97a0..843da6f 100644 --- a/Program.cs +++ b/Program.cs @@ -27,13 +27,13 @@ public static int Main(string[] args) if (IsProcessElevated()) { MessageBox.Show("Run this application as a normal user (not as Elevated Administrator)", - "App is Elevated", MessageBoxButtons.OK, MessageBoxIcon.Error); + "App is Elevated", MessageBoxButtons.OK, MessageBoxIcon.Error ); return -1; } if (MessageBox.Show( - "Do you want to use your default text editor as your commit editor?", - "Installing GitPad", MessageBoxButtons.YesNo) + "Do you want to use your default text editor as your commit editor?", + "Installing GitPad", MessageBoxButtons.YesNo) != DialogResult.Yes) { return -1; @@ -48,12 +48,11 @@ public static int Main(string[] args) var dest = new FileInfo(Environment.ExpandEnvironmentVariables(@"%AppData%\GitPad\GitPad.exe")); File.Copy(Assembly.GetExecutingAssembly().Location, dest.FullName, true); - Environment.SetEnvironmentVariable("EDITOR", dest.FullName.Replace('\\', '/'), EnvironmentVariableTarget.User); + Environment.SetEnvironmentVariable("EDITOR", "~/AppData/Roaming/GitPad/GitPad.exe", EnvironmentVariableTarget.User); return 0; } int ret = 0; - string fileData = null; string path = null; try @@ -132,7 +131,7 @@ public static int Main(string[] args) static void WriteStringToFile(string path, string fileData, LineEndingType lineType, bool emitUTF8Preamble) { - using (var of = File.Open(path, FileMode.Create)) + using(var of = File.Open(path, FileMode.Create)) { var buf = Encoding.UTF8.GetBytes(ForceLineEndings(fileData, lineType)); if (emitUTF8Preamble) @@ -146,7 +145,7 @@ public static string ForceLineEndings(string fileData, LineEndingType type) var ret = new StringBuilder(fileData.Length); string ending; - switch (type) + switch(type) { case LineEndingType.Windows: ending = "\r\n"; @@ -175,7 +174,7 @@ public static string ForceLineEndings(string fileData, LineEndingType type) public static unsafe bool IsProcessElevated() { - if (Environment.OSVersion.Version < new Version(6, 0, 0, 0)) + if (Environment.OSVersion.Version < new Version(6,0,0,0)) { // Elevation is not a thing. return false; diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index a8b3253..13103a1 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.4.1.0")] -[assembly: AssemblyFileVersion("1.4.1.0")] +[assembly: AssemblyVersion("1.4.0.0")] +[assembly: AssemblyFileVersion("1.4.0.0")] From 514fda3f28e0ea00f6a3261aa65147751c5a1837 Mon Sep 17 00:00:00 2001 From: Bryan Date: Mon, 15 Sep 2014 23:22:20 -0500 Subject: [PATCH 3/3] Changed environment variable to no longer use ~ AppData isn't necessarily a directory underneath $Home in some environments. Changed to use DirectoryInfo.DirectoryName instead and reverse the slashes. Also fixed extraneous formatting caused by Visual Studio :-) --- Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Program.cs b/Program.cs index 843da6f..920eb95 100644 --- a/Program.cs +++ b/Program.cs @@ -48,7 +48,7 @@ public static int Main(string[] args) var dest = new FileInfo(Environment.ExpandEnvironmentVariables(@"%AppData%\GitPad\GitPad.exe")); File.Copy(Assembly.GetExecutingAssembly().Location, dest.FullName, true); - Environment.SetEnvironmentVariable("EDITOR", "~/AppData/Roaming/GitPad/GitPad.exe", EnvironmentVariableTarget.User); + Environment.SetEnvironmentVariable("EDITOR", dest.FullName.Replace('\\', '/'), EnvironmentVariableTarget.User); return 0; }