|
| 1 | +# |
| 2 | +# This file is part of MagiskOnWSALocal. |
| 3 | +# |
| 4 | +# MagiskOnWSALocal is free software: you can redistribute it and/or modify |
| 5 | +# it under the terms of the GNU Affero General Public License as |
| 6 | +# published by the Free Software Foundation, either version 3 of the |
| 7 | +# License, or (at your option) any later version. |
| 8 | +# |
| 9 | +# MagiskOnWSALocal is distributed in the hope that it will be useful, |
| 10 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | +# GNU Affero General Public License for more details. |
| 13 | +# |
| 14 | +# You should have received a copy of the GNU Affero General Public License |
| 15 | +# along with MagiskOnWSALocal. If not, see <https://www.gnu.org/licenses/>. |
| 16 | +# |
| 17 | +# Copyright (C) 2023 LSPosed Contributors |
| 18 | +# |
| 19 | + |
| 20 | +$Host.UI.RawUI.WindowTitle = "Installing MagiskOnWSA..." |
| 21 | + |
| 22 | +function Finish { |
| 23 | + Clear-Host |
| 24 | + Start-Process "shell:AppsFolder\MicrosoftCorporationII.WindowsSubsystemForAndroid_8wekyb3d8bbwe!SettingsApp" |
| 25 | + Start-Process "wsa://com.topjohnwu.magisk" |
| 26 | + Start-Process "wsa://com.android.vending" |
| 27 | + Start-Process "wsa://com.android.settings" |
| 28 | + |
| 29 | + Write-Output "All Done!`r`nPress any key to exit" |
| 30 | + $null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown') |
| 31 | + exit 0 |
| 32 | +} |
| 33 | + |
| 34 | +$pwsh = "powershell.exe" |
| 35 | + |
| 36 | +if ((New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) -ne $true) { |
| 37 | + Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Bypass -Force |
| 38 | + $Proc = Start-Process -PassThru -Verb RunAs $pwsh -Args "-ExecutionPolicy Bypass -Command Set-Location '$PSScriptRoot'; &'$PSCommandPath' EVAL" |
| 39 | + if ($null -ne $Proc) { |
| 40 | + $Proc.WaitForExit() |
| 41 | + } |
| 42 | + if ($null -eq $Proc -or $Proc.ExitCode -ne 0) { |
| 43 | + Write-Warning "`r`nFailed to launch start as Administrator`r`nPress any key to exit" |
| 44 | + $null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown'); |
| 45 | + } |
| 46 | + exit |
| 47 | +} elseif (($args.Count -eq 1) -and ($args[0] -eq "EVAL")) { |
| 48 | + Start-Process $pwsh -NoNewWindow -Args "-ExecutionPolicy Bypass -Command Set-Location '$PSScriptRoot'; &'$PSCommandPath'" |
| 49 | + exit |
| 50 | +} |
| 51 | + |
| 52 | +$FileList = Get-Content -Path .\filelist.txt |
| 53 | +if (((Test-Path -Path $FileList) -eq $false).Count) { |
| 54 | + Write-Error "`r`nSome files are missing in the folder.`r`nPlease try to build again.`r`n`r`nPress any key to exit" |
| 55 | + $null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown') |
| 56 | + exit 1 |
| 57 | +} |
| 58 | + |
| 59 | +reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock" /t REG_DWORD /f /v "AllowDevelopmentWithoutDevLicense" /d "1" |
| 60 | + |
| 61 | +if ($(Get-WindowsOptionalFeature -Online -FeatureName 'VirtualMachinePlatform').State -ne "Enabled") { |
| 62 | + Enable-WindowsOptionalFeature -Online -NoRestart -FeatureName 'VirtualMachinePlatform' |
| 63 | + Write-Warning "`r`nNeed restart to enable virtual machine platform`r`nPress y to restart or press any key to exit" |
| 64 | + $Key = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown') |
| 65 | + if ("y" -eq $Key.Character) { |
| 66 | + Restart-Computer -Confirm |
| 67 | + } else { |
| 68 | + exit 1 |
| 69 | + } |
| 70 | +} |
| 71 | + |
| 72 | +if (((Test-Path -Path "MakePri.ps1") -and (Test-Path -Path "makepri.exe")) -eq $true) { |
| 73 | + $ProcMakePri = Start-Process $pwsh -PassThru -NoNewWindow -Args "-ExecutionPolicy Bypass -File MakePri.ps1" -WorkingDirectory $PSScriptRoot |
| 74 | + $null = $ProcMakePri.Handle |
| 75 | + $ProcMakePri.WaitForExit() |
| 76 | + if ($ProcMakePri.ExitCode -ne 0) { |
| 77 | + Write-Warning "`r`nFailed to merge resources, WSA Seetings will always be in English`r`nPress any key to continue" |
| 78 | + $null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown') |
| 79 | + } |
| 80 | + $Host.UI.RawUI.WindowTitle = "Installing MagiskOnWSA...." |
| 81 | +} |
| 82 | + |
| 83 | +if ((Test-Path -Path 'uwp') -eq $true) { |
| 84 | + [xml]$Xml = Get-Content ".\AppxManifest.xml"; |
| 85 | + $Name = $Xml.Package.Identity.Name; |
| 86 | + Write-Output "Installing $Name version: $($Xml.Package.Identity.Version)" |
| 87 | + $ProcessorArchitecture = $Xml.Package.Identity.ProcessorArchitecture; |
| 88 | + $Dependencies = $Xml.Package.Dependencies.PackageDependency; |
| 89 | + $Dependencies | ForEach-Object { |
| 90 | + $InstalledVersion = Get-AppxPackage -Name $_.Name | ForEach-Object { if ($_.Architecture -eq $ProcessorArchitecture) { $_ } } | Sort-Object -Property Version | Select-Object -ExpandProperty Version -Last 1 |
| 91 | + if ( $InstalledVersion -lt $_.MinVersion ) { |
| 92 | + if ($env:WT_SESSION) { |
| 93 | + $env:WT_SESSION = $null |
| 94 | + Write-Output "`r`nDependency should be installed but Windows Terminal is in use. Restarting to conhost.exe" |
| 95 | + Start-Process conhost.exe -Args "powershell.exe -ExecutionPolicy Bypass -Command Set-Location '$PSScriptRoot'; &'$PSCommandPath'" |
| 96 | + exit 1 |
| 97 | + } |
| 98 | + Write-Output "Dependency package $($_.Name) $ProcessorArchitecture required minimum version: $($_.MinVersion). Installing..." |
| 99 | + Add-AppxPackage -ForceApplicationShutdown -ForceUpdateFromAnyVersion -Path "uwp\$($_.Name)_$ProcessorArchitecture.appx" |
| 100 | + } else { |
| 101 | + Write-Output "Dependency package $($_.Name) $ProcessorArchitecture current version: $InstalledVersion.`r`nNothing to do." |
| 102 | + } |
| 103 | + } |
| 104 | +} else { |
| 105 | + Write-Warning "`r`nIgnored install WSA dependencies." |
| 106 | +} |
| 107 | + |
| 108 | +$Installed = $null |
| 109 | +$Installed = Get-AppxPackage -Name $Name |
| 110 | + |
| 111 | +if (($null -ne $Installed) -and (-not ($Installed.IsDevelopmentMode))) { |
| 112 | + Write-Warning "`r`nThere is already one installed WSA.`r`nPlease uninstall it first.`r`n`r`nPress y to uninstall existing WSA or press any key to exit" |
| 113 | + $key = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown') |
| 114 | + if ("y" -eq $key.Character) { |
| 115 | + Clear-Host |
| 116 | + Remove-AppxPackage -Package $Installed.PackageFullName |
| 117 | + } else { |
| 118 | + exit 1 |
| 119 | + } |
| 120 | +} |
| 121 | + |
| 122 | +if ($Installed) { |
| 123 | + Write-Output "`r`nShutting down WSA..." |
| 124 | + Start-Process WsaClient -Wait -Args "/shutdown" |
| 125 | +} |
| 126 | +Stop-Process -Name "WsaClient" -ErrorAction SilentlyContinue |
| 127 | + |
| 128 | +Write-Output "`r`nInstalling MagiskOnWSA..." |
| 129 | + |
| 130 | +Add-AppxPackage -ForceApplicationShutdown -ForceUpdateFromAnyVersion -Register .\AppxManifest.xml |
| 131 | +if ($?) { |
| 132 | + Finish |
| 133 | +} elseif ($null -ne $Installed) { |
| 134 | + Write-Error "`r`nFailed to update.`r`nPress any key to uninstall existing installation while preserving user data.`r`nTake in mind that this will remove the Android apps' icon from the start menu.`r`nIf you want to cancel, close this window now." |
| 135 | + $null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown') |
| 136 | + Clear-Host |
| 137 | + Remove-AppxPackage -PreserveApplicationData -Package $Installed.PackageFullName |
| 138 | + Add-AppxPackage -ForceApplicationShutdown -ForceUpdateFromAnyVersion -Register .\AppxManifest.xml |
| 139 | + if ($?) { |
| 140 | + Finish |
| 141 | + } |
| 142 | +} |
0 commit comments