diff --git a/src/Ryujinx.Common/Helpers/RunningPlatform.cs b/src/Ryujinx.Common/Helpers/RunningPlatform.cs index 8d85c4a3c..7ec2f18df 100644 --- a/src/Ryujinx.Common/Helpers/RunningPlatform.cs +++ b/src/Ryujinx.Common/Helpers/RunningPlatform.cs @@ -5,15 +5,34 @@ using System.Runtime.InteropServices; namespace Ryujinx.Common.Helper { + public enum OperatingSystemType + { + MacOS, + Linux, + Windows + } + public static class RunningPlatform { + public static readonly OperatingSystemType CurrentOS + = IsMacOS + ? OperatingSystemType.MacOS + : IsWindows + ? OperatingSystemType.Windows + : IsLinux + ? OperatingSystemType.Linux + : throw new PlatformNotSupportedException(); + + public static Architecture Architecture => RuntimeInformation.OSArchitecture; + public static Architecture CurrentProcessArchitecture => RuntimeInformation.ProcessArchitecture; + public static bool IsMacOS => OperatingSystem.IsMacOS(); public static bool IsWindows => OperatingSystem.IsWindows(); public static bool IsLinux => OperatingSystem.IsLinux(); - public static bool IsArm => RuntimeInformation.OSArchitecture is Architecture.Arm64; + public static bool IsArm => Architecture is Architecture.Arm64; - public static bool IsX64 => RuntimeInformation.OSArchitecture is Architecture.X64; + public static bool IsX64 => Architecture is Architecture.X64; public static bool IsIntelMac => IsMacOS && IsX64; public static bool IsArmMac => IsMacOS && IsArm; diff --git a/src/Ryujinx/Updater.cs b/src/Ryujinx/Updater.cs index 338e9de43..7ca5e885a 100644 --- a/src/Ryujinx/Updater.cs +++ b/src/Ryujinx/Updater.cs @@ -43,17 +43,9 @@ namespace Ryujinx.Ava private const int ConnectionCount = 4; private static string _buildVer; + - private static readonly string _platformExt = - RunningPlatform.IsMacOS - ? "macos_universal.app.tar.gz" - : RunningPlatform.IsWindows - ? "win_x64.zip" - : RunningPlatform.IsX64Linux - ? "linux_x64.tar.gz" - : RunningPlatform.IsArmLinux - ? "linux_arm64.tar.gz" - : throw new PlatformNotSupportedException(); + private static readonly string _platformExt = BuildPlatformExtension(); private static string _buildUrl; private static long _buildSize; @@ -780,5 +772,34 @@ namespace Ryujinx.Ava public static void CleanupUpdate() => Directory.GetFiles(_homeDir, "*.ryuold", SearchOption.AllDirectories) .ForEach(File.Delete); + + private static string BuildPlatformExtension() + { + if (RunningPlatform.IsMacOS) + return "macos_universal.app.tar.gz"; + +#pragma warning disable CS8509 // It is exhaustive for any values this can contain. + string osPrefix = RunningPlatform.CurrentOS switch + { + OperatingSystemType.Linux => "linux", + OperatingSystemType.Windows => "win" + }; + + string archSuffix = RunningPlatform.Architecture switch + { + Architecture.Arm64 => "arm64", + Architecture.X64 => "x64", + _ => throw new PlatformNotSupportedException($"Unknown architecture {Enum.GetName(RunningPlatform.Architecture)}."), + }; + + string fileExtension = RunningPlatform.CurrentOS switch +#pragma warning restore CS8509 + { + OperatingSystemType.Linux => "tar.gz", + OperatingSystemType.Windows => "zip" + }; + + return $"{osPrefix}_{archSuffix}.{fileExtension}"; + } } }