From dd15b5743715a606ae4060892735923158c3cab8 Mon Sep 17 00:00:00 2001 From: Wroclaw Date: Sat, 12 Nov 2022 01:59:22 +0100 Subject: [PATCH] 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..0e2468a 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] setIncludesForPackage([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.setIncludesForPackage($packageName, $integrationsToInclude) $config.save() # We save only what user selected, but we still need to include integrations that depends on selected