From 56a27f6b9f07e9e133a5493d269ae4d6d2834e96 Mon Sep 17 00:00:00 2001 From: Wroclaw Date: Sat, 12 Nov 2022 00:55:27 +0100 Subject: [PATCH 1/4] add -NoUpdate parameter --- revanced.ps1 | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/revanced.ps1 b/revanced.ps1 index 6e9a5c7..04816f6 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 @@ -299,13 +300,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} From 816ef0abe0b09159f41f1483f8b4ae672f5f6fda Mon Sep 17 00:00:00 2001 From: Wroclaw Date: Sat, 12 Nov 2022 01:05:51 +0100 Subject: [PATCH 2/4] FormItems: add conversion from any list --- revanced.ps1 | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/revanced.ps1 b/revanced.ps1 index 04816f6..e498c8f 100644 --- a/revanced.ps1 +++ b/revanced.ps1 @@ -65,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) { From 07b04f2d8efa2863d0df483cb0ffe69f9d136f08 Mon Sep 17 00:00:00 2001 From: Wroclaw Date: Sat, 12 Nov 2022 01:31:18 +0100 Subject: [PATCH 3/4] filter integration selection with a package name --- revanced.ps1 | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/revanced.ps1 b/revanced.ps1 index e498c8f..83c0399 100644 --- a/revanced.ps1 +++ b/revanced.ps1 @@ -251,6 +251,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#> { @@ -302,6 +310,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 { @@ -348,10 +376,17 @@ 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 } $integrationsForm[$i].selected = $true From d10cee65d58ed71996b48a2bbee89e67f8fdb5c2 Mon Sep 17 00:00:00 2001 From: Wroclaw Date: Sat, 12 Nov 2022 01:59:22 +0100 Subject: [PATCH 4/4] config: save includes per package --- revanced.ps1 | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/revanced.ps1 b/revanced.ps1 index 83c0399..4aa041b 100644 --- a/revanced.ps1 +++ b/revanced.ps1 @@ -142,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 { @@ -153,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 { @@ -388,13 +399,13 @@ function main { $integrationsToInclude = [System.Collections.ArrayList]::new() $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