2022-07-03 01:36:42 +02:00
Param (
[ string ] $Java = 'java'
)
Add-Type -AssemblyName System . Windows . Forms
Add-type -AssemblyName System . Drawing
$ProgressPreference = 'SilentlyContinue'
$ErrorActionPreference = 'Stop'
function execJava {
$ErrorActionPreference = 'Continue'
if ( $args [ 0 ] . getType ( ) . Name -ne " String " ) {
& $Java $args [ 0 ] 2 > & 1 | ForEach-Object { " $_ " }
}
else {
& $Java $args 2 > & 1 | ForEach-Object { " $_ " }
}
$ErrorActionPreference = 'Stop'
}
function renderForm([String[]]$items , [ String ] $label , [ String ] $title , [ System.Windows.Forms.SelectionMode ] $mode , [ System.Collections.ArrayList ] $selected ) {
# https://docs.microsoft.com/en-us/powershell/scripting/samples/multiple-selection-list-boxes?view=powershell-7.2
# https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.anchorstyles
$form = New-Object System . Windows . Forms . Form
$form . Text = $title
$form . Size = New-Object System . Drawing . Size ( 300 , 200 )
$form . StartPosition = 'CenterScreen'
$OKButton = New-Object System . Windows . Forms . Button
$OKButton . Anchor = 2
$OKButton . Location = New-Object System . Drawing . Point ( 102 , 120 )
$OKButton . Size = New-Object System . Drawing . Size ( 75 , 23 )
$OKButton . Text = 'OK'
$OKButton . DialogResult = [ System.Windows.Forms.DialogResult ] :: OK
$form . AcceptButton = $OKButton
$form . Controls . Add ( $OKButton )
$_label = New-Object System . Windows . Forms . Label
$_label . Anchor = 1 + 4 + 8
$_label . Location = New-Object System . Drawing . Point ( 10 , 20 )
$_label . Size = New-Object System . Drawing . Size ( 280 , 20 )
$_label . Text = $label
$form . Controls . Add ( $_label )
$listBox = New-Object System . Windows . Forms . Listbox
$listBox . Anchor = 15
$listBox . Location = New-Object System . Drawing . Point ( 10 , 40 )
$listBox . Size = New-Object System . Drawing . Size ( 260 , 20 )
$listBox . SelectionMode = $mode
foreach ( $entry in $items ) {
[ void ] $listBox . Items . Add ( $entry )
}
if ( $null -ne $selected ) {
for ( $i = 0 ; ( $i -lt $selected . Count ) -and ( $i -lt $items . Length ) ; $i + + ) {
if ( $selected [ $i ] ) { $listBox . SetSelected ( $i , $true ) | Out-Null }
}
}
$listBox . Height = 70
$form . Controls . Add ( $listBox )
$form . Topmost = $true
if ( $form . ShowDialog ( ) -eq [ System.Windows.Forms.DialogResult ] :: OK ) {
return $listbox . selectedItems
}
return $false
}
function splitArray([String[]]$array , $splitter = $null , [ int ] $row = 0 ) {
$returnVal = New-Object System . Collections . ArrayList
if ( $null -eq $splitter ) {
foreach ( $i in $array ) {
$returnVal . Add ( @ ( $i . Split ( ) [ $row ] ) ) | Out-Null
}
}
else {
foreach ( $i in $array ) {
$returnVal . Add ( @ ( $i . Split ( $splitter ) [ $row ] ) ) | Out-Null
}
}
return $returnVal
}
class config {
[ String ] $patches = " none "
[ String ] $integrations = " none "
[ String ] $cli = " none "
[ System.Collections.ArrayList ] $excluded = ( New-Object System . Collections . ArrayList )
[ void ] load ( $Path ) {
$fileContent = ConvertFrom-Json ( ( Get-Content $Path ) -Join ' ' ) . ToString ( )
$this . patches = $fileContent . patches
$this . integrations = $fileContent . integrations
$this . cli = $fileContent . cli
$this . excluded = $fileContent . excluded
}
[ void ] save ( $Path ) {
Out-File $Path -InputObject ( ConvertTo-Json $this )
}
}
function main {
$config = New-Object config
# Get latest releases
try {
$patchesRelease = ConvertFrom-Json ( Invoke-WebRequest https : / / api . github . com / repos / revanced / revanced-patches / releases / latest ) . Content
$integrationsRelease = ConvertFrom-Json ( Invoke-WebRequest https : / / api . github . com / repos / revanced / revanced-integrations / releases / latest ) . Content
$cliRelease = ConvertFrom-Json ( Invoke-WebRequest https : / / api . github . com / repos / revanced / revanced-cli / releases / latest ) . Content
# Check versions
[ Bool[] ] $install = $true , $true , $true
try {
$config . load ( " .\config.json " )
2022-07-04 22:41:42 +02:00
if ( $config . patches -eq $patchesRelease . tag_name ) { $install [ 0 ] = $false }
if ( $config . integrations -eq $integrationsRelease . tag_name ) { $install [ 1 ] = $false }
if ( $config . cli -eq $cliRelease . tag_name ) { $install [ 2 ] = $false }
2022-07-03 01:36:42 +02:00
}
catch [ System.Management.Automation.ItemNotFoundException ] {
Write-Output " currentVersion.json not found, downloading everything "
}
# Download latest releases
New-Item -type Directory -Path " .\app " -ErrorAction SilentlyContinue | Out-Null
if ( $install [ 0 ] ) {
2022-07-04 22:41:42 +02:00
Write-Output " Downloading Patches ( $( $config . patches ) -> $( $patchesRelease . tag_name ) ) changelog: $( $patchesRelease . html_url ) "
2022-07-03 01:36:42 +02:00
Invoke-WebRequest $patchesRelease . assets [ 1 ] . browser_download_url -OutFile " .\app\revanced-patches.jar "
2022-07-04 22:41:42 +02:00
$config . patches = $patchesRelease . tag_name
2022-07-03 01:36:42 +02:00
}
2022-07-04 02:38:26 +02:00
else { Write-Output " Patches up to date $( $config . patches ) " }
2022-07-03 01:36:42 +02:00
if ( $install [ 1 ] ) {
2022-07-04 22:41:42 +02:00
Write-Output " Downloading Integrations ( $( $config . integrations ) -> $( $integrationsRelease . tag_name ) ) changelog: $( $integrationsRelease . html_url ) "
2022-07-03 01:36:42 +02:00
Invoke-WebRequest $integrationsRelease . assets [ 0 ] . browser_download_url -OutFile " .\app\app-release-unsigned.apk "
2022-07-04 22:41:42 +02:00
$config . integrations = $integrationsRelease . tag_name
2022-07-03 01:36:42 +02:00
}
2022-07-04 02:38:26 +02:00
else { Write-Output " Integrations up to date $( $config . integrations ) " }
2022-07-03 01:36:42 +02:00
if ( $install [ 2 ] ) {
2022-07-04 22:41:42 +02:00
Write-Output " Downloading cli ( $( $config . cli ) -> $( $cliRelease . tag_name ) ) changelog: $( $cliRelease . html_url ) "
2022-07-03 01:36:42 +02:00
Invoke-WebRequest $cliRelease . assets [ 0 ] . browser_download_url -OutFile " .\app\revanced-cli.jar "
2022-07-04 22:41:42 +02:00
$config . cli = $cliRelease . tag_name
2022-07-03 01:36:42 +02:00
}
2022-07-04 02:38:26 +02:00
else { Write-Output " cli up to date! $( $config . cli ) " }
2022-07-03 01:36:42 +02:00
$config . save ( " .\config.json " )
}
catch [ System.Net.WebException ] {
Write-Output " Couldn't get newest files, using locals "
}
# Select Youtube app
$apks = ( Get-ChildItem * . apk ) . Name
[ String ] $selectedApk = ''
if ( $apks . Length -eq 0 ) { throw " No YouTube apk files found! " }
2022-07-04 02:37:55 +02:00
elseif ( $apks . getType ( ) . Name -eq 'String' ) { $selectedApk = $apks }
2022-07-03 01:36:42 +02:00
else {
$selectedApk = ( renderForm -items $apks -label " Select apk file to patch " -title " Installer for ReVanced - apk selector " -mode One )
if ( -not $selectedApk ) { throw " No apk selected! " }
}
# Get available integrations
$integrationsList = New-Object System . Collections . ArrayList
2022-07-04 02:37:55 +02:00
class Integration {
[ String ] $id
[ String ] $description
Integration ( [ String ] $_id , [ String ] $_description ) {
$this . id = $_id
$this . description = $_description
}
[ String ] ToString ( ) {
return " $( $this . id ) - $( $this . description ) "
}
}
2022-07-03 01:36:42 +02:00
foreach ( $i in ( execJava -jar . \ app \ revanced-cli . jar -b . \ app \ revanced-patches . jar -l ) ) {
2022-07-04 02:37:55 +02:00
$i = $i . ToString ( ) . substring ( 6 ) . split ( " `t " )
[ void ] $integrationsList . Add ( [ Integration ] :: new ( $i [ 0 ] . TrimStart ( ) , $i [ 1 ] ) )
2022-07-03 01:36:42 +02:00
}
# integrations selector
$excludedIntegrations = New-Object System . Collections . ArrayList
[ System.Collections.ArrayList ] $savedExclusions = New-Object System . Collections . ArrayList
$savedExclusionsNames = $config . excluded
foreach ( $i in $integrationsList ) {
2022-07-04 02:37:55 +02:00
if ( ( $savedExclusionsNames . Count -gt 1 ) -and $savedExclusionsNames . Contains ( $i . id ) ) {
[ void ] $savedExclusions . Add ( $true )
[ void ] $savedExclusionsNames . Remove ( $integrationID )
2022-07-03 01:36:42 +02:00
}
else {
[ void ] $savedExclusions . Add ( $false )
}
}
2022-07-04 02:37:55 +02:00
2022-07-03 01:36:42 +02:00
foreach ( $i in ( renderForm -items $integrationsList -label " Select integrations to exclude " -title " Installer for ReVanced - integrations " -mode MultiExtended -selected $savedExclusions ) ) {
2022-07-04 02:37:55 +02:00
[ void ] $excludedIntegrations . Add ( $i . Split ( ' ' ) [ 0 ] ) #FIXME: hacky way to do this, but it works
2022-07-03 01:36:42 +02:00
}
$config . excluded = $excludedIntegrations
$config . save ( " .\config.json " )
# devices
$devices = adb devices
$devices = $devices [ 1 . . ( $devices . length - 2 ) ]
[ String ] $selectedDevice = ''
if ( $devices . Length -eq 0 ) { throw " No devices found " }
elseif ( $devices . Length -eq 1 ) { $selectedDevice = ( splitArray -array $devices ) [ 0 ] }
else {
$selectedDevice = ( renderForm -items ( splitArray -array $devices ) -label " Select deployment target " -title " Installer for ReVanced - target " -mode One )
}
# install to device
$patcherArgs = " -jar " , " .\app\revanced-cli.jar " , " -a " , " .\ $selectedApk " , " -c " , " -d " , " $selectedDevice " , " -o " , " $env:tmp \revanced.apk " , " -m " , " .\app\app-release-unsigned.apk " , " -b " , " .\app\revanced-patches.jar "
# is microg patch excluded?
if ( $excludedIntegrations . Contains ( " microg-support " ) ) {
$patcherArgs + = " --mount "
}
foreach ( $i in $excludedIntegrations ) {
$patcherArgs + = " -e "
$patcherArgs + = $i
2022-07-04 02:38:26 +02:00
Write-Output " Excluded: $i "
2022-07-03 01:36:42 +02:00
}
2022-07-04 02:38:26 +02:00
Write-Output " Logs below are from the cli "
2022-07-03 01:36:42 +02:00
execJava $patcherArgs
}
main