Browse Source

UI: Updater: Add support for eventual Windows on ARM updates

Evan Husted 1 year ago
parent
commit
332bcdfaf1
2 changed files with 52 additions and 12 deletions
  1. 21 2
      src/Ryujinx.Common/Helpers/RunningPlatform.cs
  2. 31 10
      src/Ryujinx/Updater.cs

+ 21 - 2
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;

+ 31 - 10
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}";
+        }
     }
 }