Skip to content

Commit

Permalink
mac: Detect proper OS version and codename for logs
Browse files Browse the repository at this point in the history
  • Loading branch information
hbons committed Sep 9, 2017
1 parent 8398954 commit 012631f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
5 changes: 4 additions & 1 deletion SparkleShare/Common/BaseController.cs
Expand Up @@ -213,7 +213,10 @@ public virtual void Initialize ()
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;
Expand Down
26 changes: 26 additions & 0 deletions Sparkles/InstallationInfo.cs
Expand Up @@ -63,6 +63,32 @@ public partial class InstallationInfo {
}


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;
Expand Down

0 comments on commit 012631f

Please sign in to comment.