44using System . Diagnostics ;
55using System . IO ;
66using System . Linq ;
7- using System . Runtime . InteropServices ;
87using System . Security . Principal ;
98using System . Threading ;
109using System . Threading . Tasks ;
1110
11+ using static sttz . InstallUnity . UnityReleaseAPIClient ;
12+
1213namespace sttz . InstallUnity
1314{
1415
@@ -35,8 +36,8 @@ public class WindowsPlatform : IInstallerPlatform
3536 /// Path to the program files directory.
3637 /// </summary>
3738 static string ProgramFilesPath { get {
38- if ( RuntimeInformation . OSArchitecture != Architecture . X86
39- && RuntimeInformation . ProcessArchitecture == Architecture . X86 ) {
39+ if ( System . Runtime . InteropServices . RuntimeInformation . OSArchitecture != System . Runtime . InteropServices . Architecture . X86
40+ && System . Runtime . InteropServices . RuntimeInformation . ProcessArchitecture == System . Runtime . InteropServices . Architecture . X86 ) {
4041 // The unity editor since 2017.1 is 64bit
4142 // If install-unity is run as X86 on a non-X86 system, GetFolderPath will return
4243 // the "Program Files (x86)" directory instead of the main one where the editor
@@ -57,14 +58,19 @@ public void SetConfiguration(Configuration configuration)
5758 this . configuration = configuration ;
5859 }
5960
60- public Task < CachePlatform > GetCurrentPlatform ( )
61+ public async Task < Architecture > GetInstallableArchitectures ( )
6162 {
62- return Task . FromResult ( CachePlatform . Windows ) ;
63+ var ( _, arch ) = await GetCurrentPlatform ( ) ;
64+ if ( arch == Architecture . X86_64 ) {
65+ return Architecture . X86_64 ;
66+ } else {
67+ return Architecture . ARM64 | Architecture . X86_64 ;
68+ }
6369 }
6470
65- public Task < IEnumerable < CachePlatform > > GetInstallablePlatforms ( )
71+ public Task < IEnumerable < Platform > > GetInstallablePlatforms ( )
6672 {
67- IEnumerable < CachePlatform > platforms = new CachePlatform [ ] { CachePlatform . Windows } ;
73+ IEnumerable < Platform > platforms = new Platform [ ] { Platform . Windows } ;
6874 return Task . FromResult ( platforms ) ;
6975 }
7076
@@ -73,6 +79,11 @@ public string GetCacheDirectory()
7379 return GetLocalApplicationDataDirectory ( ) ;
7480 }
7581
82+ public Task < ( Platform , Architecture ) > GetCurrentPlatform ( )
83+ {
84+ return Task . FromResult ( ( Platform . Windows , Architecture . X86_64 ) ) ;
85+ }
86+
7687 public string GetConfigurationDirectory ( )
7788 {
7889 return GetLocalApplicationDataDirectory ( ) ;
@@ -92,7 +103,7 @@ public Task<bool> IsAdmin(CancellationToken cancellation = default)
92103
93104 public Task < Installation > CompleteInstall ( bool aborted , CancellationToken cancellation = default )
94105 {
95- if ( ! installing . version . IsValid )
106+ if ( ! installing . Version . IsValid )
96107 throw new InvalidOperationException ( "Not installing any version to complete" ) ;
97108
98109 if ( ! aborted )
@@ -103,7 +114,7 @@ public Task<Installation> CompleteInstall(bool aborted, CancellationToken cancel
103114
104115 var installation = new Installation ( )
105116 {
106- version = installing . version ,
117+ version = installing . Version ,
107118 executable = executable ,
108119 path = installPath
109120 } ;
@@ -164,7 +175,7 @@ public async Task<IEnumerable<Installation>> FindInstallations(CancellationToken
164175
165176 public async Task Install ( UnityInstaller . Queue queue , UnityInstaller . QueueItem item , CancellationToken cancellation = default )
166177 {
167- if ( item . package . name != PackageMetadata . EDITOR_PACKAGE_NAME && ! installedEditor )
178+ if ( item . package is not EditorDownload && ! installedEditor && upgradeOriginalPath == null )
168179 {
169180 throw new InvalidOperationException ( "Cannot install package without installing editor first." ) ;
170181 }
@@ -175,7 +186,7 @@ public async Task Install(UnityInstaller.Queue queue, UnityInstaller.QueueItem i
175186 throw new Exception ( $ "Failed to install { item . filePath } output: { result . output } / { result . error } ") ;
176187 }
177188
178- if ( item . package . name == PackageMetadata . EDITOR_PACKAGE_NAME )
189+ if ( item . package is EditorDownload )
179190 {
180191 installedEditor = true ;
181192 }
@@ -189,26 +200,26 @@ public Task MoveInstallation(Installation installation, string newPath, Cancella
189200
190201 public async Task PrepareInstall ( UnityInstaller . Queue queue , string installationPaths , CancellationToken cancellation = default )
191202 {
192- if ( installing . version . IsValid )
193- throw new InvalidOperationException ( $ "Already installing another version: { installing . version } ") ;
203+ if ( installing . Version . IsValid )
204+ throw new InvalidOperationException ( $ "Already installing another version: { installing . Version } ") ;
194205
195206 installing = queue . metadata ;
196207 installedEditor = false ;
197208
198209 // Check for upgrading installation
199- if ( ! queue . items . Any ( i => i . package . name == PackageMetadata . EDITOR_PACKAGE_NAME ) )
210+ if ( ! queue . items . Any ( i => i . package is EditorDownload ) )
200211 {
201212 var installs = await FindInstallations ( cancellation ) ;
202- var existingInstall = installs . Where ( i => i . version == queue . metadata . version ) . FirstOrDefault ( ) ;
213+ var existingInstall = installs . Where ( i => i . version == queue . metadata . Version ) . FirstOrDefault ( ) ;
203214 if ( existingInstall == null )
204215 {
205- throw new InvalidOperationException ( $ "Not installing editor but version { queue . metadata . version } not already installed.") ;
216+ throw new InvalidOperationException ( $ "Not installing editor but version { queue . metadata . Version } not already installed.") ;
206217 }
207218
208219 installedEditor = true ;
209220 }
210-
211- installPath = GetInstallationPath ( installing . version , installationPaths ) ;
221+
222+ installPath = GetInstallationPath ( installing . Version , installationPaths ) ;
212223 }
213224
214225 public Task < bool > PromptForPasswordIfNecessary ( CancellationToken cancellation = default )
@@ -279,10 +290,14 @@ public async Task Uninstall(Installation installation, CancellationToken cancell
279290
280291 Configuration configuration ;
281292
293+ bool ? isRoot ;
294+ string pwd ;
282295 VersionMetadata installing ;
283296 string installPath ;
297+ string upgradeOriginalPath ;
298+ bool movedExisting ;
284299 bool installedEditor ;
285-
300+
286301 async Task < ( int exitCode , string output , string error ) > RunAsAdmin ( string filename , string arguments )
287302 {
288303 var startInfo = new ProcessStartInfo ( ) ;
0 commit comments