diff --git a/revanced.ps1 b/revanced.ps1 index 4aa041b..6e9a5c7 100644 --- a/revanced.ps1 +++ b/revanced.ps1 @@ -1,7 +1,6 @@ Param( [string]$Java = 'java', - [switch]$NoDeploy, - [switch]$NoUpdate + [switch]$NoDeploy ) Add-Type -AssemblyName System.Windows.Forms @@ -65,22 +64,6 @@ class FormItems : System.Collections.ArrayList<#FormItem#> { } return $rvalue } - - FormItems() {} - - FormItems([System.Collections.IEnumerable] $list) { - <# - .Description - Creates FormItems list with all items in list - where values are those items - and displaytext as string representation of them - - TLDR it converts any list to FormItems - #> - foreach ($i in $list) { - [void] $this.Add([FormItem]::new($i, $i.ToString())) - } - } } function renderForm([FormItems]$items, [String]$label, [String]$title, [System.Windows.Forms.SelectionMode]$mode) { @@ -142,8 +125,8 @@ function renderForm([FormItems]$items, [String]$label, [String]$title, [System.W } class config { - [System.Collections.SortedList]$version - [System.Collections.SortedList]$included + [hashtable]$version = @{} + [System.Collections.ArrayList]$included = [System.Collections.ArrayList]::new() } class configFile { @@ -153,30 +136,19 @@ class configFile { [void] load() { $fileContent = ConvertFrom-Json ((Get-Content $this.path) -Join ' ').ToString() - $version = [System.Collections.SortedList]::new() + $version = @{} foreach ($prop in $fileContent.version.PsObject.Properties) { $version.Add($prop.Name, $prop.Value) } - $this.config.version = $version + $fileContent.version = $null - $included = [System.Collections.SortedList]::new() - foreach ($prop in $fileContent.included.PsObject.Properties) { - $included.Add($prop.Name, $prop.Value) - } - $this.config.included = $included + $this.config = $fileContent + $this.config.version = $version } [void] save() { Out-File $this.path -InputObject (ConvertTo-Json $this.config) } - - [void] setIncludeForPackage([String] $packageName, [System.Collections.IEnumerable] $integrationNames) { - $this.config.included[$packageName] = $integrationNames.Clone() - } - - [System.Collections.ArrayList] getIncludesForPackage([String] $packageName) { - return $this.config.included[$packageName].Clone() - } } function UpdateFromGithub { @@ -262,14 +234,6 @@ class Integration { if ($compatiblePackage.length -eq 0 ) { return $false } return $compatiblePackage.Contains($version) } - - [System.Collections.ArrayList] compatiblePackageNames() { - $rvalue =[System.Collections.ArrayList]::new($this.compatiblePackages.Count) - foreach ($i in $this.compatiblePackages) { - [void] $rvalue.Add($i.name) - } - return $rvalue - } } class IntegrationList : System.Collections.ArrayList<#Integration#> { @@ -321,26 +285,6 @@ class IntegrationList : System.Collections.ArrayList<#Integration#> { } return $rvalue } - - [FormItems] getForm([String] $packageName) { - $rvalue = [FormItems]::new() - foreach ($i in $this) { - if (-not $i.compatiblePackageNames().Contains($packageName)) { continue } - [void] $rvalue.Add([FormItem]::new($i.name, "$($i.name) - $($i.description)")) - } - return $rvalue - } - - [System.Collections.ArrayList] getAllCompatiblePackagesNames() { - $rvalue = [System.Collections.ArrayList]::new() - foreach ($i in $this) { - foreach ($j in $i.compatiblePackages) { - if ($rvalue.Contains($j.name)) { continue } - [void] $rvalue.Add($j.name) - } - } - return $rvalue - } } function main { @@ -355,16 +299,14 @@ function main { # Update - if (-not $NoUpdate) { - $updatedPatches = UpdateFromGithub -Repository "revanced/revanced-patches" -Config $config -AssetsFilter {$_.content_type -like "application/java-archive"} -OutFile ".\app\revanced-patches.jar" - if ($updatedPatches) { - Invoke-WebRequest "https://raw.githubusercontent.com/revanced/revanced-patches/main/patches.json" -OutFile ".\app\revanced-patches.json" - } - - UpdateFromGithub -Repository "revanced/revanced-integrations" -Config $config -AssetsFilter {$_.content_type -like "application/*"} -OutFile ".\app\app-release-unsigned.apk" | Out-Null - UpdateFromGithub -Repository "revanced/revanced-cli" -Config $config -AssetsFilter {$_.content_type -like "application/*"} -OutFile ".\app\revanced-cli.jar" | Out-Null + $updatedPatches = UpdateFromGithub -Repository "revanced/revanced-patches" -Config $config -AssetsFilter {$_.content_type -like "application/java-archive"} -OutFile ".\app\revanced-patches.jar" + if ($updatedPatches) { + Invoke-WebRequest "https://raw.githubusercontent.com/revanced/revanced-patches/main/patches.json" -OutFile ".\app\revanced-patches.json" } + UpdateFromGithub -Repository "revanced/revanced-integrations" -Config $config -AssetsFilter {$_.content_type -like "application/*"} -OutFile ".\app\app-release-unsigned.apk" | Out-Null + UpdateFromGithub -Repository "revanced/revanced-cli" -Config $config -AssetsFilter {$_.content_type -like "application/*"} -OutFile ".\app\revanced-cli.jar" | Out-Null + if ($NoDeploy) {return} # Select apk to patch @@ -387,25 +329,18 @@ function main { $integrations = [IntegrationList]::new(".\app\revanced-patches.json") - # get package name - # FIXME: How to extract package name from its apk file? - - $packageNamesForm = [FormItems]::new($integrations.getAllCompatiblePackagesNames()) - - $packageName = renderForm -items $packageNamesForm -label "Which package is it?" -title "Installer for ReVanced - package name" -mode One - # integrations selector $integrationsToInclude = [System.Collections.ArrayList]::new() - $integrationsForm = $integrations.getForm($packageName) + $integrationsForm = $integrations.getForm() for ($i = 0; $i -lt $integrationsForm.Count; $i++) { - if (-not $config.getIncludesForPackage($packageName).Contains(($integrationsForm[$i].value))) { continue } + if (-not $config.config.included.Contains($integrationsForm[$i].value)) { continue } $integrationsForm[$i].selected = $true } $integrationsToInclude = renderForm -items $integrationsForm -label "Select integrations to include" -title "Installer for ReVanced - integrations" -mode MultiExtended - $config.setIncludeForPackage($packageName, $integrationsToInclude) + $config.config.included = $integrationsToInclude $config.save() # We save only what user selected, but we still need to include integrations that depends on selected