From 87ec298263f5fe1d2eb8ca498ecaf78c544a081e Mon Sep 17 00:00:00 2001 From: Howard Wu Date: Mon, 20 Mar 2023 01:23:33 +0800 Subject: [PATCH] Fix resources merge for 2302 (#430) Fix #424 --- installer/Install.ps1 | 10 +++++-- installer/MakePri.ps1 | 65 ++++++++++++++++++++++++++----------------- scripts/build.sh | 2 +- xml/priconfig.xml | 1 + 4 files changed, 49 insertions(+), 29 deletions(-) diff --git a/installer/Install.ps1 b/installer/Install.ps1 index 11a8a5c..65c6b16 100644 --- a/installer/Install.ps1 +++ b/installer/Install.ps1 @@ -1,5 +1,5 @@ # Automated Install script by Midonei -$Host.UI.RawUI.WindowTitle = "Installing MagiskOnWSA..." +$Host.UI.RawUI.WindowTitle = "Installing MagiskOnWSA...." function Test-Administrator { [OutputType([bool])] param() @@ -49,7 +49,11 @@ If (((Test-Path -Path $FileList) -Eq $false).Count) { } If ((Test-Path -Path "MakePri.ps1") -Eq $true) { - Start-Process powershell.exe -Wait -Args "-ExecutionPolicy Bypass -File MakePri.ps1" -WorkingDirectory $PSScriptRoot + $ProcMakePri = Start-Process powershell.exe -PassThru -Args "-ExecutionPolicy Bypass -File MakePri.ps1" -WorkingDirectory $PSScriptRoot + $ProcMakePri.WaitForExit() + If ($ProcMakePri.ExitCode -Ne 0) { + Write-Warning "Failed to merge resources, WSA Seetings will always be in English`r`n" + } } reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock" /t REG_DWORD /f /v "AllowDevelopmentWithoutDevLicense" /d "1" @@ -101,7 +105,7 @@ If (($null -Ne $Installed) -And (-Not ($Installed.IsDevelopmentMode))) { } } Clear-Host -Write-Host "Installing MagiskOnWSA..." +Write-Host "Installing MagiskOnWSA...." Stop-Process -Name "WsaClient" -ErrorAction SilentlyContinue Add-AppxPackage -ForceApplicationShutdown -ForceUpdateFromAnyVersion -Register .\AppxManifest.xml If ($?) { diff --git a/installer/MakePri.ps1 b/installer/MakePri.ps1 index f81b91a..0bcbf1a 100644 --- a/installer/MakePri.ps1 +++ b/installer/MakePri.ps1 @@ -16,34 +16,49 @@ # Copyright (C) 2023 LSPosed Contributors # +$Host.UI.RawUI.WindowTitle = "Merging resources...." If ((Test-Path -Path "pri") -Eq $true -And (Test-Path -Path "xml") -Eq $true) { $AppxManifestFile = ".\AppxManifest.xml" Copy-Item .\resources.pri -Destination ".\pri\resources.pri" - $proc = Start-Process -PassThru makepri.exe -Args "new /pr .\pri /cf .\xml\priconfig.xml /of .\resources.pri /mn $AppxManifestFile /o" - $proc.WaitForExit() - If ($proc.ExitCode -Ne 0) { - Write-Warning "Failed to merge resources`r`n" - exit 1 - } - else { - $ProjectXml = [xml](Get-Content $AppxManifestFile) - $ProjectResources = $ProjectXml.Package.Resources; - $Item = Get-Item .\xml\* -Exclude "priconfig.xml" -Include "*.xml" - $Item | ForEach-Object { - $Xml = [xml](Get-Content $_) - $Resource = $Xml.Package.Resources.Resource - $newNode = $ProjectXml.ImportNode($Resource, $true) - $ProjectResources.AppendChild($newNode) + $ProcNew = Start-Process -PassThru makepri.exe -WindowStyle Hidden -Args "new /pr .\pri /cf .\xml\priconfig.xml /of .\resources.pri /mn $AppxManifestFile /o" + $ProcNew.WaitForExit() + If ($ProcNew.ExitCode -Ne 0) { + Write-Warning "Failed to merge resources from pri`r`nTrying to dump...." + New-Item -Path "." -Name "priinfo" -ItemType "directory" + $Processes = ForEach ($Item in Get-Item ".\pri\*" -Include "*.pri") { + $Name = $Item.Name + Write-Host "Dumping $Name....`r`n" + Start-Process -PassThru -WindowStyle Hidden makepri.exe -Args "dump /if $Item /o /es .\resources.pri /of .\priinfo\$Name.xml /dt detailed" + } + Write-Host "Dumping resources....`r`n" + $Processes | Wait-Process + Write-Host "Creating pri from dumps....`r`n" + $ProcNewFromDump = Start-Process -PassThru -WindowStyle Hidden makepri.exe -Args "new /pr .\priinfo /cf .\xml\priconfig.xml /of .\resources.pri /mn $AppxManifestFile /o" + $ProcNewFromDump.WaitForExit() + Remove-Item 'priinfo' -Recurse + If ($ProcNewFromDump.ExitCode -Ne 0) { + Write-Warning "Failed to merge resources from dump`r`n" + exit 1 } - $ProjectXml.Save($AppxManifestFile) - Remove-Item 'pri' -Recurse - Set-Content -Path "filelist.txt" -Value (Get-Content -Path "filelist.txt" | Select-String -Pattern '^pri$' -NotMatch) - Remove-Item 'xml' -Recurse - Set-Content -Path "filelist.txt" -Value (Get-Content -Path "filelist.txt" | Select-String -Pattern '^xml$' -NotMatch) - Remove-Item 'makepri.exe' - Set-Content -Path "filelist.txt" -Value (Get-Content -Path "filelist.txt" | Select-String -Pattern 'makepri.exe' -NotMatch) - Remove-Item $PSCommandPath -Force - Set-Content -Path "filelist.txt" -Value (Get-Content -Path "filelist.txt" | Select-String -Pattern 'MakePri.ps1' -NotMatch) - exit 0 } + + $ProjectXml = [xml](Get-Content $AppxManifestFile) + $ProjectResources = $ProjectXml.Package.Resources; + $Item = Get-Item .\xml\* -Exclude "priconfig.xml" -Include "*.xml" + $Item | ForEach-Object { + $Xml = [xml](Get-Content $_) + $Resource = $Xml.Package.Resources.Resource + $newNode = $ProjectXml.ImportNode($Resource, $true) + $ProjectResources.AppendChild($newNode) + } + $ProjectXml.Save($AppxManifestFile) + Remove-Item 'pri' -Recurse + Set-Content -Path "filelist.txt" -Value (Get-Content -Path "filelist.txt" | Select-String -Pattern '^pri$' -NotMatch) + Remove-Item 'xml' -Recurse + Set-Content -Path "filelist.txt" -Value (Get-Content -Path "filelist.txt" | Select-String -Pattern '^xml$' -NotMatch) + Remove-Item 'makepri.exe' + Set-Content -Path "filelist.txt" -Value (Get-Content -Path "filelist.txt" | Select-String -Pattern 'makepri.exe' -NotMatch) + Remove-Item $PSCommandPath -Force + Set-Content -Path "filelist.txt" -Value (Get-Content -Path "filelist.txt" | Select-String -Pattern 'MakePri.ps1' -NotMatch) + exit 0 } diff --git a/scripts/build.sh b/scripts/build.sh index b517447..4934eb9 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -898,7 +898,7 @@ if [ "$COMPRESS_OUTPUT" ] || [ -n "$COMPRESS_FORMAT" ]; then elif [ "$COMPRESS_FORMAT" = "xz" ]; then echo "Compressing with tar xz" if ! (tar -cP -I 'xz -9 -T0' -f "$OUTPUT_PATH" "$WORK_DIR/wsa/$artifact_name"); then - echo "Out of memory? Trying again with single threads..." + echo "Out of memory? Trying again with single threads...." tar -cPJvf "$OUTPUT_PATH" "$WORK_DIR/wsa/$artifact_name" || abort fi elif [ "$COMPRESS_FORMAT" = "zip" ]; then diff --git a/xml/priconfig.xml b/xml/priconfig.xml index 181aa69..7587749 100644 --- a/xml/priconfig.xml +++ b/xml/priconfig.xml @@ -7,5 +7,6 @@ + \ No newline at end of file