From 5cdf75b463cdae632ee441da312b763c899e9e72 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Wed, 1 Mar 2017 19:32:14 -0500 Subject: [PATCH] show OS caption (like "Windows 10") instead of internal version when available --- release-notes.md | 3 ++- src/StardewModdingAPI/Program.cs | 19 ++++++++++++++++++- .../StardewModdingAPI.csproj | 1 + 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/release-notes.md b/release-notes.md index 3dfa42ad..029246b0 100644 --- a/release-notes.md +++ b/release-notes.md @@ -23,7 +23,8 @@ For mod developers: * Added a simpler API for console commands (see `helper.ConsoleCommands`). * Added `GetPrivateProperty` reflection helper. * SMAPI now writes XNA input enums (`Buttons` and `Keys`) to JSON as strings, so mods no longer need to add a `StringEnumConverter` themselves for those. -* Log files now always use `\r\n` to simplify crossplatform viewing. +* Logs now show the OS caption (like "Windows 10") instead of its internal version when available. +* Logs now always use `\r\n` to simplify crossplatform viewing. * Several obsolete APIs have been removed (see [deprecation guide](http://canimod.com/guides/updating-a-smapi-mod)), and all _notice_-level deprecations have been increased to _info_. diff --git a/src/StardewModdingAPI/Program.cs b/src/StardewModdingAPI/Program.cs index ebeefe96..360f75f0 100644 --- a/src/StardewModdingAPI/Program.cs +++ b/src/StardewModdingAPI/Program.cs @@ -4,6 +4,7 @@ using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.IO; using System.Linq; +using System.Management; using System.Reflection; using System.Threading; #if SMAPI_FOR_WINDOWS @@ -87,7 +88,7 @@ namespace StardewModdingAPI { // initialise logging Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-GB"); // for consistent log formatting - this.Monitor.Log($"SMAPI {Constants.ApiVersion} with Stardew Valley {Constants.GameVersion} on {Environment.OSVersion}", LogLevel.Info); + this.Monitor.Log($"SMAPI {Constants.ApiVersion} with Stardew Valley {Constants.GameVersion} on {this.GetFriendlyPlatformName()}", LogLevel.Info); Console.Title = $"SMAPI {Constants.ApiVersion} - running Stardew Valley {Constants.GameVersion}"; // inject compatibility shims @@ -582,5 +583,21 @@ namespace StardewModdingAPI { return new Monitor(name, this.ConsoleManager, this.LogFile, this.ExitGameImmediately) { WriteToConsole = this.Monitor.WriteToConsole, ShowTraceInConsole = this.Settings.DeveloperMode }; } + + /// Get a human-readable name for the current platform. + private string GetFriendlyPlatformName() + { + try + { + return ( + from entry in new ManagementObjectSearcher("SELECT Caption FROM Win32_OperatingSystem").Get().Cast() + select entry.GetPropertyValue("Caption").ToString() + ).FirstOrDefault(); + } + catch + { + return Environment.OSVersion.ToString(); + } + } } } diff --git a/src/StardewModdingAPI/StardewModdingAPI.csproj b/src/StardewModdingAPI/StardewModdingAPI.csproj index 9b86adac..2340a431 100644 --- a/src/StardewModdingAPI/StardewModdingAPI.csproj +++ b/src/StardewModdingAPI/StardewModdingAPI.csproj @@ -97,6 +97,7 @@ + True