From 653183df6af40f6464aaa058087d92c35a4f5d28 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Sat, 9 Sep 2017 15:22:49 +0100 Subject: [PATCH] mac: Detect proper OS version and codename for logs --- SparkleShare/Common/BaseController.cs | 5 ++++- Sparkles/InstallationInfo.cs | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/SparkleShare/Common/BaseController.cs b/SparkleShare/Common/BaseController.cs index 2580a43d..d089baff 100644 --- a/SparkleShare/Common/BaseController.cs +++ b/SparkleShare/Common/BaseController.cs @@ -213,7 +213,10 @@ namespace SparkleShare { Logger.LogInfo ("Environment", "Git " + Sparkles.Git.GitCommand.GitVersion); // TODO: ToString() with nice OS version names (Mac OS X Yosemite, Fedora 24, Ubuntu 16.04, etc.) - Logger.LogInfo ("Environment", InstallationInfo.OperatingSystem + " (" + Environment.OSVersion + ")"); + if (InstallationInfo.OperatingSystem == OS.Mac) + Logger.LogInfo ("Environment", InstallationInfo.MacOSVersion ()); + else + Logger.LogInfo ("Environment", InstallationInfo.OperatingSystem + " (" + Environment.OSVersion + ")"); UserAuthenticationInfo = new SSHAuthenticationInfo (); SSHAuthenticationInfo.DefaultAuthenticationInfo = UserAuthenticationInfo; diff --git a/Sparkles/InstallationInfo.cs b/Sparkles/InstallationInfo.cs index 787e784d..ff34ffe5 100644 --- a/Sparkles/InstallationInfo.cs +++ b/Sparkles/InstallationInfo.cs @@ -63,6 +63,32 @@ namespace Sparkles { } + public static string MacOSVersion () + { + var uname = new Command ("sw_vers", "-productVersion", false); + string output = uname.StartAndReadStandardOutput (); + string version = output; + + // Parse the version number between the periods (e.g. "10.12.1" -> 12) + output = output.Substring (output.IndexOf (".") + 1); + output = output.Substring (0, output.LastIndexOf (".")); + + string release = "Unreleased Version"; + + switch (int.Parse (output)) { + case 7: release = "Lion"; break; + case 8: release = "Mountain Lion"; break; + case 9: release = "Mavericks"; break; + case 10: release = "Yosemite"; break; + case 11: release = "El Capitan"; break; + case 12: release = "Sierra"; break; + case 13: release = "High Sierra"; break; + } + + return string.Format ("macOS {0} ({1})", version, release); + } + + public static string Version { get { string version = "" + Assembly.GetExecutingAssembly ().GetName ().Version;