diff --git a/revanced.ps1 b/revanced.ps1 index b32f276..990819b 100644 --- a/revanced.ps1 +++ b/revanced.ps1 @@ -8,7 +8,15 @@ Add-type -AssemblyName System.Drawing $ProgressPreference = 'SilentlyContinue' $ErrorActionPreference = 'Stop' + function execJava { +<# +.Description +execJava was created to additionally allow providing an array of strings to java arguments +if the first argument is a string array, it will launch with arguments in that array +otherwise it will launch with all provided arguments +#> + $SavedErrorActionPreference = $ErrorActionPreference $ErrorActionPreference = 'Continue' if ($args[0].getType().Name -ne "String") { & $Java $args[0] 2>&1 | ForEach-Object{ "$_" } @@ -16,7 +24,7 @@ function execJava { else { & $Java $args 2>&1 | ForEach-Object{ "$_" } } - $ErrorActionPreference = 'Stop' + $ErrorActionPreference = $SavedErrorActionPreference } function renderForm([String[]]$items, [String]$label, [String]$title, [System.Windows.Forms.SelectionMode]$mode, [System.Collections.ArrayList]$selected) { @@ -71,21 +79,6 @@ function renderForm([String[]]$items, [String]$label, [String]$title, [System.Wi 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" @@ -136,6 +129,8 @@ function main { New-Item -type Directory -Path ".\app" -ErrorAction SilentlyContinue | Out-Null + # TODO: use where-object to search for filename + if ($install[0]) { Write-Output "Downloading Patches ($($config.patches) -> $($patchesRelease.tag_name))" Write-Output "changelog: https://github.com/revanced/revanced-patches/compare/$($config.patches)...$($patchesRelease.tag_name)" @@ -174,9 +169,10 @@ function main { elseif ($apks.getType().Name -eq 'String') {$selectedApk = $apks} 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!"} } + if (-not $selectedApk) {throw "No apk selected!"} + # Get available integrations $integrationsList = New-Object System.Collections.ArrayList @@ -229,10 +225,14 @@ function main { [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) + elseif ($devices.Length -eq 1) { + $selectedDevice = ($devices | ForEach-Object {$_.split()[0]})[0] } + else { + $selectedDevice = (renderForm -items ($devices | ForEach-Object {$_.split()[0]}) -label "Select deployment target" -title "Installer for ReVanced - target" -mode One) + } + + if (-not $selectedDevice) {throw "No device selected"} # install to device