Add batch script (#116)

Co-authored-by: Howard Wu <40033067+Howard20181@users.noreply.github.com>
This commit is contained in:
Syuugo 2022-09-17 21:38:33 +09:00 committed by GitHub
parent 823f1895d0
commit 08fbb8d9dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 18 deletions

View File

@ -54,7 +54,7 @@
1. Select the root solution (none means no root)
1. Wait for the script to complete and the artifact will be in the `output` folder
1. Move the artifact to a place you like
1. Right-click `Install.ps1` and select `Run with PowerShell`
1. Double-click `Run.bat`
- If you previously have a MagiskOnWSA installation, it will automatically uninstall the previous one while **preserving all user data** and install the new one, so don't worry about your data.
- If you have an official WSA installation, you should uninstall it first. (In case you want to preserve your data, you can backup `%LOCALAPPDATA%\Packages\MicrosoftCorporationII.WindowsSubsystemForAndroid_8wekyb3d8bbwe\LocalCache\userdata.vhdx` before uninstallation and restore it after installation.) (If you want to restore the icons to the start menu, please install and use [WSAHelper](https://github.com/LSPosed/WSAHelper/releases/latest).)
- If the popup windows disappear **without asking administrative permission** and WSA is not installed successfully, you should manually run `Install.ps1` as administrator:

View File

@ -658,7 +658,7 @@ sudo rm -rf "${WORK_DIR:?}"/wsa/"$ARCH"/\[Content_Types\].xml "$WORK_DIR"/wsa/"$
cp "$vclibs_PATH" "$xaml_PATH" "$WORK_DIR"/wsa/"$ARCH" || abort
tee "$WORK_DIR"/wsa/"$ARCH"/Install.ps1 <<EOF
# Automated Install script by Midonei
# http://github.com/doneibcn
\$Host.UI.RawUI.WindowTitle = "Installing MagiskOnWSA..."
function Test-Administrator {
[OutputType([bool])]
param()
@ -674,23 +674,23 @@ function Finish {
Start-Process "wsa://com.android.vending"
}
if (-not (Test-Administrator)) {
If (-Not (Test-Administrator)) {
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Bypass -Force
\$proc = Start-Process -PassThru -WindowStyle Hidden -Verb RunAs powershell.exe -Args "-executionpolicy bypass -command Set-Location '\$PSScriptRoot'; &'\$PSCommandPath' EVAL"
\$proc = Start-Process -PassThru -WindowStyle Hidden -Verb RunAs powershell.exe -Args "-ExecutionPolicy Bypass -Command Set-Location '\$PSScriptRoot'; &'\$PSCommandPath' EVAL"
\$proc.WaitForExit()
if (\$proc.ExitCode -ne 0) {
If (\$proc.ExitCode -Ne 0) {
Clear-Host
Write-Warning "Failed to launch start as Administrator\`r\`nPress any key to exit"
\$null = \$Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');
}
exit
}
elseif ((\$args.Count -eq 1) -and (\$args[0] -eq "EVAL")) {
Start-Process powershell.exe -Args "-executionpolicy bypass -command Set-Location '\$PSScriptRoot'; &'\$PSCommandPath'"
ElseIf ((\$args.Count -Eq 1) -And (\$args[0] -Eq "EVAL")) {
Start-Process powershell.exe -Args "-ExecutionPolicy Bypass -Command Set-Location '\$PSScriptRoot'; &'\$PSCommandPath'"
exit
}
if (((Test-Path -Path $(find "$WORK_DIR"/wsa/"$ARCH" -maxdepth 1 -mindepth 1 -printf "\"%P\"\n" | paste -sd "," -)) -eq \$false).Count) {
If (((Test-Path -Path $(find "$WORK_DIR"/wsa/"$ARCH" -maxdepth 1 -mindepth 1 -printf "\"%P\"\n" | paste -sd "," -)) -Eq \$false).Count) {
Write-Error "Some files are missing in the folder. Please try to build again. Press any key to exist"
\$null = \$Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown')
exit 1
@ -698,13 +698,12 @@ if (((Test-Path -Path $(find "$WORK_DIR"/wsa/"$ARCH" -maxdepth 1 -mindepth 1 -pr
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock" /t REG_DWORD /f /v "AllowDevelopmentWithoutDevLicense" /d "1"
\$VMP = Get-WindowsOptionalFeature -Online -FeatureName 'VirtualMachinePlatform'
if (\$VMP.State -ne "Enabled") {
If (\$(Get-WindowsOptionalFeature -Online -FeatureName 'VirtualMachinePlatform').State -Ne "Enabled") {
Enable-WindowsOptionalFeature -Online -NoRestart -FeatureName 'VirtualMachinePlatform'
Clear-Host
Write-Warning "Need restart to enable virtual machine platform\`r\`nPress y to restart or press any key to exit"
\$key = \$Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown')
If ("y" -eq \$key.Character) {
If ("y" -Eq \$key.Character) {
Restart-Computer -Confirm
}
Else {
@ -718,11 +717,11 @@ Add-AppxPackage -ForceApplicationShutdown -ForceUpdateFromAnyVersion -Path xaml-
\$Installed = \$null
\$Installed = Get-AppxPackage -Name 'MicrosoftCorporationII.WindowsSubsystemForAndroid'
If ((\$null -ne \$Installed) -and (-not (\$Installed.IsDevelopmentMode))) {
If ((\$null -Ne \$Installed) -And (-Not (\$Installed.IsDevelopmentMode))) {
Clear-Host
Write-Warning "There is already one installed WSA. Please uninstall it first.\`r\`nPress y to uninstall existing WSA or press any key to exit"
\$key = \$Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown')
If ("y" -eq \$key.Character) {
If ("y" -Eq \$key.Character) {
Remove-AppxPackage -Package \$Installed.PackageFullName
}
Else {
@ -731,23 +730,37 @@ If ((\$null -ne \$Installed) -and (-not (\$Installed.IsDevelopmentMode))) {
}
Clear-Host
Write-Host "Installing MagiskOnWSA..."
Stop-Process -Name "wsaclient" -ErrorAction "silentlycontinue"
Stop-Process -Name "WsaClient" -ErrorAction SilentlyContinue
Add-AppxPackage -ForceApplicationShutdown -ForceUpdateFromAnyVersion -Register .\AppxManifest.xml
if (\$?) {
If (\$?) {
Finish
}
Elseif (\$null -ne \$Installed) {
ElseIf (\$null -Ne \$Installed) {
Clear-Host
Write-Host "Failed to update, try to uninstall existing installation while preserving userdata..."
Remove-AppxPackage -PreserveApplicationData -Package \$Installed.PackageFullName
Add-AppxPackage -ForceApplicationShutdown -ForceUpdateFromAnyVersion -Register .\AppxManifest.xml
if (\$?) {
If (\$?) {
Finish
}
}
Write-Host "All Done\`r\`nPress any key to exit"
Write-Host "All Done!\`r\`nPress any key to exit"
\$null = \$Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown')
EOF
tee "$WORK_DIR"/wsa/"$ARCH"/Run.bat <<EOF
:: Automated Install batch script by Syuugo
@echo off
if not exist Install.ps1 (
echo "Install.ps1" is not found.
echo Press any key to exit
pause>nul
exit 1
) else (
start powershell.exe -File .\Install.ps1 -ExecutionPolicy Bypass
exit
)
EOF
echo -e "Remove signature and add scripts done\n"
echo "Generate info"