Refactor logic for setting default applications

This commit is contained in:
Manuel Thalmann 2023-07-26 17:10:57 +02:00
parent 9b1be73a7a
commit 41696d2078
2 changed files with 8 additions and 64 deletions

View file

@ -1,38 +1,8 @@
#!/bin/pwsh #!/bin/pwsh
param($context) . "$PSScriptRoot/../../Scripts/AppAssociations.ps1";
$applicationName = "Thunderbird";
. "$PSScriptRoot/../../Scripts/Context.ps1";
[Context] $context = $context;
$tempDir = $context.GetTempDirectory();
Push-Location $tempDir;
$configFile = "$tempDir/DefaultAssociations.xml";
Write-Host "Configuring Thunderbird";
Write-Information "Making Thunderbird the default Mail program"; Write-Information "Making Thunderbird the default Mail program";
DISM /Online "/Export-DefaultAppAssociations:$configFile"; Set-DefaultAppAssociation "mailto" "Thunderbird.Url.mailto" $applicationName;
Set-DefaultAppAssociation ".eml" "ThunderbirdEML" $applicationName;
[xml]$defaultAssociations = [xml]::new();
$defaultAssociations.PreserveWhitespace = $true;
$reader = [System.Xml.XmlReader]::Create("$configFile", $readerSettings);
$defaultAssociations.Load($reader);
$reader.Dispose();
foreach ($association in $defaultAssociations.SelectNodes("/DefaultAssociations/Association")) {
switch ($association.Identifier) {
"mailto" {
$association.ApplicationName = "Thunderbird";
$association.ProgId = "Thunderbird.Url.mailto";
};
".eml" {
$association.ApplicationName = "Thunderbird";
$association.ProgId = "ThunderbirdEML";
};
}
}
$defaultAssociations.Save($configFile);
DISM /Online "/Import-DefaultAppAssociations:$configFile";
Pop-Location;
Remove-Item -Recurse $tempDir;

View file

@ -1,32 +1,6 @@
#!/bin/pwsh #!/bin/pwsh
param($context) . "$PSScriptRoot/../../Scripts/AppAssociations.ps1";
. "$PSScriptRoot/../../Scripts/Context.ps1";
[Context] $context = $context;
$tempDir = $context.GetTempDirectory();
Push-Location $tempDir;
$configFile = "$tempDir/DefaultAssociations.xml";
Write-Host "Configuring WinSCP";
Write-Information "Making WinSCP the default FTP program"; Write-Information "Making WinSCP the default FTP program";
DISM /Online "/Export-DefaultAppAssociations:$configFile"; Set-DefaultAppAssociation "ftp" "WinSCP.Url" "WinSCP: SFTP, FTP, WebDAV, S3 and SCP client";
[xml]$defaultAssociations = [xml]::new();
$defaultAssociations.PreserveWhitespace = $true;
$reader = [System.Xml.XmlReader]::Create("$configFile", $readerSettings);
$defaultAssociations.Load($reader);
$reader.Dispose();
foreach ($association in $defaultAssociations.SelectNodes("/DefaultAssociations/Association")) {
if ($association.Identifier -eq "ftp") {
$association.ProgId = "WinSCP.Url";
$association.ApplicationName = "WinSCP: SFTP, FTP, WebDAV, S3 and SCP client";
}
}
$defaultAssociations.Save($configFile);
DISM /Online "/Import-DefaultAppAssociations:$configFile";
Pop-Location;
Remove-Item -Recurse $tempDir;