config: save includes per package

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

View file

@ -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