From 79e63fde9a54717378bb29ea97d7b90e6bf56091 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Tue, 14 Mar 2017 19:36:18 -0400 Subject: validate .NET Framework 4.5+ is installed on Windows in SMAPI installer --- .../InteractiveInstaller.cs | 34 ++++++++++++++++++++++ src/StardewModdingAPI.sln | 4 +-- 2 files changed, 36 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/StardewModdingAPI.Installer/InteractiveInstaller.cs b/src/StardewModdingAPI.Installer/InteractiveInstaller.cs index 7dcd88fd..52d0642a 100644 --- a/src/StardewModdingAPI.Installer/InteractiveInstaller.cs +++ b/src/StardewModdingAPI.Installer/InteractiveInstaller.cs @@ -15,6 +15,9 @@ namespace StardewModdingApi.Installer /********* ** Properties *********/ + /// The value that represents Windows 7. + private readonly Version Windows7Version = new Version(6, 1); + /// The default file paths where Stardew Valley can be installed. /// The target platform. /// Derived from the crossplatform mod config: https://github.com/Pathoschild/Stardew.ModBuildConfig. @@ -152,6 +155,21 @@ namespace StardewModdingApi.Installer Console.ReadLine(); return; } + + /**** + ** validate .NET Framework version + ****/ + if (platform == Platform.Windows && !this.HasNetFramework45(platform)) + { + this.PrintError(Environment.OSVersion.Version >= this.Windows7Version + ? "Please install the latest version of .NET Framework before installing SMAPI." // Windows 7+ + : "Please install .NET Framework 4.5 before installing SMAPI." // Windows Vista or earlier + ); + this.PrintError("See the download page at https://www.microsoft.com/net/download/framework for details."); + Console.ReadLine(); + return; + } + Console.WriteLine(); /**** @@ -360,6 +378,22 @@ namespace StardewModdingApi.Installer Console.WriteLine(text); } + /// Get whether the current system has .NET Framework 4.5 or later installed. + /// The current platform. + /// The current platform is not Windows. + private bool HasNetFramework45(Platform platform) + { + switch (platform) + { + case Platform.Windows: + using (RegistryKey versionKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey(@"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full")) + return versionKey?.GetValue("Release") != null; // .NET Framework 4.5+ + + default: + throw new NotSupportedException("The installed .NET Framework version can only be checked on Windows."); + } + } + /// Interactively delete a file or folder path, and block until deletion completes. /// The file or folder path. private void InteractivelyDelete(string path) diff --git a/src/StardewModdingAPI.sln b/src/StardewModdingAPI.sln index 8ab297ed..441b51a9 100644 --- a/src/StardewModdingAPI.sln +++ b/src/StardewModdingAPI.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 14 -VisualStudioVersion = 14.0.25420.1 +# Visual Studio 15 +VisualStudioVersion = 15.0.26228.4 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TrainerMod", "TrainerMod\TrainerMod.csproj", "{28480467-1A48-46A7-99F8-236D95225359}" EndProject -- cgit