diff --git a/revanced.ps1 b/revanced.ps1 index 6e9a5c7..4aa041b 100644 --- a/revanced.ps1 +++ b/revanced.ps1 @@ -1,6 +1,7 @@ Param( [string]$Java = 'java', - [switch]$NoDeploy + [switch]$NoDeploy, + [switch]$NoUpdate ) Add-Type -AssemblyName System.Windows.Forms @@ -64,6 +65,22 @@ 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) { @@ -125,8 +142,8 @@ function renderForm([FormItems]$items, [String]$label, [String]$title, [System.W } class config { - [hashtable]$version = @{} - [System.Collections.ArrayList]$included = [System.Collections.ArrayList]::new() + [System.Collections.SortedList]$version + [System.Collections.SortedList]$included } class configFile { @@ -136,19 +153,30 @@ class configFile { [void] load() { $fileContent = ConvertFrom-Json ((Get-Content $this.path) -Join ' ').ToString() - $version = @{} + $version = [System.Collections.SortedList]::new() foreach ($prop in $fileContent.version.PsObject.Properties) { $version.Add($prop.Name, $prop.Value) } - $fileContent.version = $null - - $this.config = $fileContent $this.config.version = $version + + $included = [System.Collections.SortedList]::new() + foreach ($prop in $fileContent.included.PsObject.Properties) { + $included.Add($prop.Name, $prop.Value) + } + $this.config.included = $included } [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 { @@ -234,6 +262,14 @@ 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#> { @@ -285,6 +321,26 @@ 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 { @@ -299,13 +355,15 @@ function main { # Update - $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" - } + 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 + 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} @@ -329,18 +387,25 @@ 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() + $integrationsForm = $integrations.getForm($packageName) for ($i = 0; $i -lt $integrationsForm.Count; $i++) { - if (-not $config.config.included.Contains($integrationsForm[$i].value)) { continue } + if (-not $config.getIncludesForPackage($packageName).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.config.included = $integrationsToInclude + $config.setIncludeForPackage($packageName, $integrationsToInclude) $config.save() # We save only what user selected, but we still need to include integrations that depends on selected