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 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'src/StardewModdingAPI.Installer/InteractiveInstaller.cs') 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) -- cgit