Return proper sysinfo OS names for Linux/macOS.

This commit is contained in:
Paul Chote
2023-06-11 11:03:26 +01:00
committed by Matthias Mailänder
parent d955efff14
commit 1f37728ecf
2 changed files with 63 additions and 5 deletions

View File

@@ -79,6 +79,65 @@ namespace OpenRA
}
}
public static string OperatingSystem
{
get
{
if (CurrentPlatform == PlatformType.Linux)
{
var sessionType = Environment.GetEnvironmentVariable("XDG_SESSION_TYPE");
if (!string.IsNullOrEmpty(sessionType))
sessionType = $" ({sessionType})";
else
sessionType = "";
try
{
var psi = new ProcessStartInfo("hostnamectl", "status")
{
UseShellExecute = false,
RedirectStandardOutput = true
};
var p = Process.Start(psi);
string line;
while ((line = p.StandardOutput.ReadLine()) != null)
if (line.StartsWith("Operating System: "))
return line[18..] + sessionType;
}
catch { }
if (File.Exists("/etc/os-release"))
foreach (var line in File.ReadLines("/etc/os-release"))
if (line.StartsWith("PRETTY_NAME="))
return line[13..^1] + sessionType;
}
else if (CurrentPlatform == PlatformType.OSX)
{
try
{
var psi = new ProcessStartInfo("system_profiler", "SPSoftwareDataType")
{
UseShellExecute = false,
RedirectStandardOutput = true
};
var p = Process.Start(psi);
string line;
while ((line = p.StandardOutput.ReadLine()) != null)
{
line = line.Trim();
if (line.StartsWith("System Version: "))
return line[16..];
}
}
catch { }
}
return Environment.OSVersion.ToString();
}
}
/// <summary>
/// Directory containing user-specific support files (settings, maps, replays, game data, etc).
/// </summary>

View File

@@ -20,17 +20,16 @@ namespace OpenRA.Mods.Common.Widgets.Logic
public class SystemInfoPromptLogic : ChromeLogic
{
// Increment the version number when adding new stats
const int SystemInformationVersion = 5;
const int SystemInformationVersion = 6;
static Dictionary<string, (string Label, string Value)> GetSystemInformation()
{
var lang = CultureInfo.InstalledUICulture.TwoLetterISOLanguageName;
return new Dictionary<string, (string, string)>()
return new Dictionary<string, (string, string)>
{
{ "id", ("Anonymous ID", Game.Settings.Debug.UUID) },
{ "platform", ("OS Type", Platform.CurrentPlatform.ToString()) },
{ "os", ("OS Version", Platform.OperatingSystem) },
{ "arch", ("Architecture", Platform.CurrentArchitecture.ToString()) },
{ "os", ("OS Version", Environment.OSVersion.ToString()) },
{ "x64", ("OS is 64 bit", Environment.Is64BitOperatingSystem.ToString()) },
{ "x64process", ("Process is 64 bit", Environment.Is64BitProcess.ToString()) },
{ "runtime", (".NET Runtime", Platform.RuntimeVersion) },
@@ -38,7 +37,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{ "windowsize", ("Window Size", $"{Game.Renderer.NativeResolution.Width}x{Game.Renderer.NativeResolution.Height}") },
{ "windowscale", ("Window Scale", Game.Renderer.NativeWindowScale.ToString("F2", CultureInfo.InvariantCulture)) },
{ "uiscale", ("UI Scale", Game.Settings.Graphics.UIScale.ToString("F2", CultureInfo.InvariantCulture)) },
{ "lang", ("System Language", lang) }
{ "lang", ("System Language", CultureInfo.InstalledUICulture.TwoLetterISOLanguageName) }
};
}