Refactor the format of saved app associations

This commit is contained in:
Manuel Thalmann 2023-07-26 17:21:19 +02:00
parent 41696d2078
commit a6d438d9c2

View file

@ -28,10 +28,17 @@ $null = New-Module {
$association.ProgId = $progId;
$association.ApplicationName = $applicationName;
[AppAssociations]::SaveAssociations($associations);
}
static SaveAssociations([xml] $associations) {
$defaultAssociations = $associations.SelectNodes([AppAssociations]::associationSelector);
$defaultAssociations | ForEach-Object { $associations.RemoveChild($_); } | Sort-Object -Property "Identifier" | ForEach-Object { $associations.AppendChild($_); };
$configFile = New-TemporaryFile;
$writerSettings = [System.Xml.XmlWriterSettings]::new();
$writerSettings.Indent = $true;
$writerSettings.IndentChars = " ";
$writerSettings.Encoding = [System.Text.UTF8Encoding]::new();
$writer = [System.Xml.XmlWriter]::Create($configFile.FullName, $writerSettings);
$associations.Save($writer);