mac: Detect proper OS version and codename for logs

This commit is contained in:
Hylke Bons 2017-09-09 15:22:49 +01:00
parent cc5e4216a7
commit 653183df6a
2 changed files with 30 additions and 1 deletions

View file

@ -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;

View file

@ -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;