config: save includes per package

This commit is contained in:
Wroclaw 2022-11-12 01:59:22 +01:00
parent 07b04f2d8e
commit 53f70624a4

View file

@ -142,8 +142,8 @@ function renderForm([FormItems]$items, [String]$label, [String]$title, [System.W
} }
class config { class config {
[hashtable]$version = @{} [System.Collections.SortedList]$version
[System.Collections.ArrayList]$included = [System.Collections.ArrayList]::new() [System.Collections.SortedList]$included
} }
class configFile { class configFile {
@ -153,19 +153,30 @@ class configFile {
[void] load() { [void] load() {
$fileContent = ConvertFrom-Json ((Get-Content $this.path) -Join ' ').ToString() $fileContent = ConvertFrom-Json ((Get-Content $this.path) -Join ' ').ToString()
$version = @{} $version = [System.Collections.SortedList]::new()
foreach ($prop in $fileContent.version.PsObject.Properties) { foreach ($prop in $fileContent.version.PsObject.Properties) {
$version.Add($prop.Name, $prop.Value) $version.Add($prop.Name, $prop.Value)
} }
$fileContent.version = $null
$this.config = $fileContent
$this.config.version = $version $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() { [void] save() {
Out-File $this.path -InputObject (ConvertTo-Json $this.config) 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 { function UpdateFromGithub {
@ -388,13 +399,13 @@ function main {
$integrationsToInclude = [System.Collections.ArrayList]::new() $integrationsToInclude = [System.Collections.ArrayList]::new()
$integrationsForm = $integrations.getForm($packageName) $integrationsForm = $integrations.getForm($packageName)
for ($i = 0; $i -lt $integrationsForm.Count; $i++) { 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 $integrationsForm[$i].selected = $true
} }
$integrationsToInclude = renderForm -items $integrationsForm -label "Select integrations to include" -title "Installer for ReVanced - integrations" -mode MultiExtended $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() $config.save()
# We save only what user selected, but we still need to include integrations that depends on selected # We save only what user selected, but we still need to include integrations that depends on selected