From cf9bf85bb4a3a4a3acbc3c961b7a412b16d34157 Mon Sep 17 00:00:00 2001 From: SPoF Date: Mon, 13 Feb 2017 13:06:54 +0100 Subject: [PATCH 1/2] Add Framework check for non-windows OS GetFrameworkVersion() throws an System.NullReferenceException since there is no Registry on non-windows systems. Fixed by checking the OS under which the program runs. If it's not Windows, check the CLR Version instead of querying the (non-existant) registry. --- PKHeX.WinForms/Program.cs | 47 ++++++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/PKHeX.WinForms/Program.cs b/PKHeX.WinForms/Program.cs index 31ff979bd..139429716 100644 --- a/PKHeX.WinForms/Program.cs +++ b/PKHeX.WinForms/Program.cs @@ -29,16 +29,33 @@ private static void Main() try { - if (GetFrameworkVersion() >= 393295) - { - StartPKHeX(); - } - else - { - // Todo: make this translatable - MessageBox.Show(".NET Framework 4.6 needs to be installed for this version of PKHeX to run.", "PKHeX Error", MessageBoxButtons.OK, MessageBoxIcon.Stop); - Process.Start(@"https://www.microsoft.com/download/details.aspx?id=48130"); - } + if (IsOnWindows()) + { + if (GetFrameworkVersion() >= 393295) + { + StartPKHeX(); + } + else + { + // Todo: make this translatable + MessageBox.Show(".NET Framework 4.6 needs to be installed for this version of PKHeX to run.", "PKHeX Error", MessageBoxButtons.OK, MessageBoxIcon.Stop); + Process.Start(@"https://www.microsoft.com/download/details.aspx?id=48130"); + } + } + else + { + //CLR Version 4.0.30319 is equivalent to .NET Framework version 4.6 + if ((Environment.Version.CompareTo(Version.Parse("4.0.30319.42000"))) >= 0) + { + StartPKHeX(); + } + else + { + MessageBox.Show("Your version of Mono needs to target the .NET Framework 4.6 or higher for this version of PKHeX to run.", + "PKHeX Error", MessageBoxButtons.OK, MessageBoxIcon.Stop); + } + } + } catch (FileNotFoundException ex) { @@ -63,6 +80,16 @@ private static void StartPKHeX() Application.Run(new Main()); } + public static bool IsOnWindows() + { + // 4 -> UNIX, 6 -> Mac OSX, 128 -> UNIX (old) + int p = (int)Environment.OSVersion.Platform; + if ((p == 4) || (p == 6) || (p == 128)) + return false; + return true; + } + + public static int GetFrameworkVersion() { const string subkey = @"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\"; From 19b53e10e98d83e1574cdaa142c33bb43a3163a7 Mon Sep 17 00:00:00 2001 From: Pol Eyschen Date: Mon, 13 Feb 2017 19:55:02 +0100 Subject: [PATCH 2/2] Tabs -> Spaces & Typo --- PKHeX.WinForms/Program.cs | 68 +++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/PKHeX.WinForms/Program.cs b/PKHeX.WinForms/Program.cs index 139429716..9eb439af4 100644 --- a/PKHeX.WinForms/Program.cs +++ b/PKHeX.WinForms/Program.cs @@ -29,32 +29,32 @@ private static void Main() try { - if (IsOnWindows()) - { - if (GetFrameworkVersion() >= 393295) - { - StartPKHeX(); - } - else - { - // Todo: make this translatable - MessageBox.Show(".NET Framework 4.6 needs to be installed for this version of PKHeX to run.", "PKHeX Error", MessageBoxButtons.OK, MessageBoxIcon.Stop); - Process.Start(@"https://www.microsoft.com/download/details.aspx?id=48130"); - } - } - else - { - //CLR Version 4.0.30319 is equivalent to .NET Framework version 4.6 - if ((Environment.Version.CompareTo(Version.Parse("4.0.30319.42000"))) >= 0) - { - StartPKHeX(); - } - else - { - MessageBox.Show("Your version of Mono needs to target the .NET Framework 4.6 or higher for this version of PKHeX to run.", - "PKHeX Error", MessageBoxButtons.OK, MessageBoxIcon.Stop); - } - } + if (IsOnWindows()) + { + if (GetFrameworkVersion() >= 393295) + { + StartPKHeX(); + } + else + { + // Todo: make this translatable + MessageBox.Show(".NET Framework 4.6 needs to be installed for this version of PKHeX to run.", "PKHeX Error", MessageBoxButtons.OK, MessageBoxIcon.Stop); + Process.Start(@"https://www.microsoft.com/download/details.aspx?id=48130"); + } + } + else + { + //CLR Version 4.0.30319.42000 is equivalent to .NET Framework version 4.6 + if ((Environment.Version.CompareTo(Version.Parse("4.0.30319.42000"))) >= 0) + { + StartPKHeX(); + } + else + { + MessageBox.Show("Your version of Mono needs to target the .NET Framework 4.6 or higher for this version of PKHeX to run.", + "PKHeX Error", MessageBoxButtons.OK, MessageBoxIcon.Stop); + } + } } catch (FileNotFoundException ex) @@ -80,14 +80,14 @@ private static void StartPKHeX() Application.Run(new Main()); } - public static bool IsOnWindows() - { - // 4 -> UNIX, 6 -> Mac OSX, 128 -> UNIX (old) - int p = (int)Environment.OSVersion.Platform; - if ((p == 4) || (p == 6) || (p == 128)) - return false; - return true; - } + public static bool IsOnWindows() + { + // 4 -> UNIX, 6 -> Mac OSX, 128 -> UNIX (old) + int p = (int)Environment.OSVersion.Platform; + if ((p == 4) || (p == 6) || (p == 128)) + return false; + return true; + } public static int GetFrameworkVersion()