@@ -8,14 +8,23 @@ namespace NetDex.Updates;
88
99public partial class UpdateManager : Node
1010{
11+ private enum RuntimeArchitecture
12+ {
13+ Unknown = 0 ,
14+ X86_64 = 1 ,
15+ Arm64 = 2
16+ }
17+
1118 private const string UpdaterConfigPath = "user://updater.cfg" ;
1219 private const string DefaultRepositoryUrl = "https://github.com/NoobNotFound/net-dex" ;
1320 private const string DefaultReleasesUrl = "https://github.com/NoobNotFound/net-dex/releases" ;
1421 private const string DefaultRepoOwner = "NoobNotFound" ;
1522 private const string DefaultRepoName = "net-dex" ;
1623
1724 private const string MacAssetName = "netdex-macos-universal.zip" ;
18- private const string WindowsAssetName = "netdex-windows-x64.zip" ;
25+ private const string WindowsX86_64AssetName = "netdex-windows-x86_64.zip" ;
26+ private const string WindowsX64LegacyAssetName = "netdex-windows-x64.zip" ;
27+ private const string WindowsArm64AssetName = "netdex-windows-arm64.zip" ;
1928 private const string LinuxAssetName = "netdex-linux-x64.zip" ;
2029 private const string AndroidAssetName = "netdex-android-arm64.apk" ;
2130
@@ -33,6 +42,7 @@ public partial class UpdateManager : Node
3342 public string ReleasesUrl { get ; private set ; } = DefaultReleasesUrl ;
3443
3544 public UpdatePlatform RuntimePlatform { get ; private set ; } = UpdatePlatform . Unsupported ;
45+ private RuntimeArchitecture _runtimeArchitecture = RuntimeArchitecture . Unknown ;
3646
3747 private readonly GitHubReleaseProvider _provider = new ( ) ;
3848 private readonly Dictionary < UpdatePlatform , IUpdateInstaller > _installers = new ( ) ;
@@ -68,6 +78,7 @@ public override void _Ready()
6878 Instance = this ;
6979
7080 RuntimePlatform = DetectRuntimePlatform ( ) ;
81+ _runtimeArchitecture = DetectRuntimeArchitecture ( ) ;
7182 CurrentVersion = VersionComparer . NormalizeTagToVersion ( ProjectSettings . GetSetting ( "application/config/version" , "0.0.0" ) . AsString ( ) ) ;
7283
7384 RepositoryUrl = GetProjectSettingString ( "application/config/repository_url" , DefaultRepositoryUrl ) ;
@@ -203,18 +214,19 @@ public async Task PerformUpdateActionAsync()
203214
204215 try
205216 {
217+ var platformAsset = ResolvePlatformAsset ( LatestRelease , RuntimePlatform ) ;
218+
206219 if ( IsDesktopInstaller ( RuntimePlatform ) )
207220 {
208221 SetState ( UpdateState . Downloading , "Downloading update package..." ) ;
209- _downloadPathTemp = $ "user://updates/{ GetDownloadFileName ( RuntimePlatform ) } .download";
222+ var downloadFileName = platformAsset ? . Name ?? GetDownloadFileName ( RuntimePlatform ) ;
223+ _downloadPathTemp = $ "user://updates/{ downloadFileName } .download";
210224 SaveUpdaterConfig ( ) ;
211225 }
212226 else
213227 {
214228 SetState ( UpdateState . Installing , "Opening update destination..." ) ;
215229 }
216-
217- var platformAsset = ResolvePlatformAsset ( LatestRelease , RuntimePlatform ) ;
218230 var result = await installer . ExecuteAsync ( this , LatestRelease , platformAsset ) ;
219231 if ( ! result . Success )
220232 {
@@ -279,7 +291,7 @@ private void SetError(UpdateIssueCode code, string message)
279291 EmitSignal ( SignalName . UpdateIssueRaised , ( int ) code , message ) ;
280292 }
281293
282- private static UpdateAssetInfo ? ResolvePlatformAsset ( UpdateReleaseInfo release , UpdatePlatform platform )
294+ private UpdateAssetInfo ? ResolvePlatformAsset ( UpdateReleaseInfo release , UpdatePlatform platform )
283295 {
284296 if ( platform == UpdatePlatform . MacOS )
285297 {
@@ -288,7 +300,7 @@ private void SetError(UpdateIssueCode code, string message)
288300
289301 if ( platform == UpdatePlatform . Windows )
290302 {
291- return FindAssetByName ( release , WindowsAssetName ) ;
303+ return ResolveWindowsAsset ( release ) ;
292304 }
293305
294306 if ( platform == UpdatePlatform . Linux )
@@ -304,6 +316,30 @@ private void SetError(UpdateIssueCode code, string message)
304316 return null ;
305317 }
306318
319+ private UpdateAssetInfo ? ResolveWindowsAsset ( UpdateReleaseInfo release )
320+ {
321+ return _runtimeArchitecture switch
322+ {
323+ RuntimeArchitecture . Arm64 => FindAssetByNames ( release , WindowsArm64AssetName ) ,
324+ RuntimeArchitecture . X86_64 => FindAssetByNames ( release , WindowsX86_64AssetName , WindowsX64LegacyAssetName ) ,
325+ _ => FindAssetByNames ( release , WindowsX86_64AssetName , WindowsX64LegacyAssetName , WindowsArm64AssetName )
326+ } ;
327+ }
328+
329+ private static UpdateAssetInfo ? FindAssetByNames ( UpdateReleaseInfo release , params string [ ] expectedNames )
330+ {
331+ foreach ( var expectedName in expectedNames )
332+ {
333+ var asset = FindAssetByName ( release , expectedName ) ;
334+ if ( asset != null )
335+ {
336+ return asset ;
337+ }
338+ }
339+
340+ return null ;
341+ }
342+
307343 private static UpdateAssetInfo ? FindAssetByName ( UpdateReleaseInfo release , string expectedName )
308344 {
309345 foreach ( var asset in release . Assets )
@@ -371,6 +407,21 @@ private static UpdatePlatform DetectRuntimePlatform()
371407 return UpdatePlatform . Unsupported ;
372408 }
373409
410+ private static RuntimeArchitecture DetectRuntimeArchitecture ( )
411+ {
412+ if ( OS . HasFeature ( "arm64" ) || OS . HasFeature ( "aarch64" ) )
413+ {
414+ return RuntimeArchitecture . Arm64 ;
415+ }
416+
417+ if ( OS . HasFeature ( "x86_64" ) || OS . HasFeature ( "x64" ) || OS . HasFeature ( "64" ) )
418+ {
419+ return RuntimeArchitecture . X86_64 ;
420+ }
421+
422+ return RuntimeArchitecture . Unknown ;
423+ }
424+
374425 private static bool TryParseOwnerRepoFromUrl ( string repositoryUrl , out string owner , out string repo )
375426 {
376427 owner = string . Empty ;
@@ -418,12 +469,14 @@ private static bool RequiresDigestValidation(UpdatePlatform platform)
418469 return platform is UpdatePlatform . MacOS or UpdatePlatform . Windows or UpdatePlatform . Linux ;
419470 }
420471
421- private static string GetDownloadFileName ( UpdatePlatform platform )
472+ private string GetDownloadFileName ( UpdatePlatform platform )
422473 {
423474 return platform switch
424475 {
425476 UpdatePlatform . MacOS => "netdex-macos-universal.zip" ,
426- UpdatePlatform . Windows => "netdex-windows-x64.zip" ,
477+ UpdatePlatform . Windows => _runtimeArchitecture == RuntimeArchitecture . Arm64
478+ ? WindowsArm64AssetName
479+ : WindowsX86_64AssetName ,
427480 UpdatePlatform . Linux => "netdex-linux-x64.zip" ,
428481 _ => "netdex-update-package"
429482 } ;
0 commit comments