From 07422a3ab3b2c95d75d0b1976c59773f97c9b3bf Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Mon, 24 Jul 2023 23:08:12 +0200 Subject: [PATCH] Add a separate file for configuring Firefox --- scripts/Windows/Config/Firefox/Install.ps1 | 54 ++++++++++++++++++++ scripts/Windows/Software/Firefox/Install.ps1 | 50 +----------------- 2 files changed, 55 insertions(+), 49 deletions(-) create mode 100644 scripts/Windows/Config/Firefox/Install.ps1 diff --git a/scripts/Windows/Config/Firefox/Install.ps1 b/scripts/Windows/Config/Firefox/Install.ps1 new file mode 100644 index 00000000..c4a17983 --- /dev/null +++ b/scripts/Windows/Config/Firefox/Install.ps1 @@ -0,0 +1,54 @@ +#!/bin/pwsh +param($context) + +. "$PSScriptRoot/../../Scripts/Context.ps1"; + +[Context] $context = $context; +$tempDir = $context.GetTempDirectory(); + +Push-Location $tempDir; +$configFile = "$tempDir/DefaultAssociations.xml"; + +Write-Information "Making Firefox the default browser"; +DISM /Online "/Export-DefaultAppAssociations:$configFile"; + +[xml]$defaultAssociations = [xml]::new(); +$defaultAssociations.PreserveWhitespace = $true; +$reader = [System.Xml.XmlReader]::Create("$configFile", $readerSettings); +$defaultAssociations.Load($reader); +$reader.Dispose(); + +$extensions = @( + ".htm", + ".html", + ".svg", + ".xht", + ".xhtml" +); + +$schemes = @( + "http", + "https" +); + +foreach ($association in $defaultAssociations.SelectNodes("/DefaultAssociations/Association")) { + [string] $className = $null; + + if (($extensions + $schemes) -contains $association.Identifier) { + $association.ApplicationName = "Firefox"; + + if ($extensions -contains $association.Identifier) { + $className = "FirefoxHTML"; + } else { + $className = "FirefoxURL"; + } + + $association.ProgId = "$className-308046B0AF4A39CB" + } +} + +$defaultAssociations.Save($configFile); +DISM /Online "/Import-DefaultAppAssociations:$configFile"; + +Pop-Location; +Remove-Item -Recurse $tempDir; diff --git a/scripts/Windows/Software/Firefox/Install.ps1 b/scripts/Windows/Software/Firefox/Install.ps1 index 79098845..7a6160f9 100644 --- a/scripts/Windows/Software/Firefox/Install.ps1 +++ b/scripts/Windows/Software/Firefox/Install.ps1 @@ -3,55 +3,7 @@ function Install-Firefox { param([Context] $context) - - $tempDir = $context.GetTempDirectory(); - Push-Location $tempDir; - $configFile = "$tempDir/DefaultAssociations.xml"; - Write-Host "Installing Firefox"; choco install -y firefox; - - Write-Information "Making Firefox the default browser"; - DISM /Online "/Export-DefaultAppAssociations:$configFile"; - - [xml]$defaultAssociations = [xml]::new(); - $defaultAssociations.PreserveWhitespace = $true; - $reader = [System.Xml.XmlReader]::Create("$configFile", $readerSettings); - $defaultAssociations.Load($reader); - $reader.Dispose(); - - $extensions = @( - ".htm", - ".html", - ".svg", - ".xht", - ".xhtml" - ); - - $schemes = @( - "http", - "https" - ); - - foreach ($association in $defaultAssociations.SelectNodes("/DefaultAssociations/Association")) { - [string] $className = $null; - - if (($extensions + $schemes) -contains $association.Identifier) { - $association.ApplicationName = "Firefox"; - - if ($extensions -contains $association.Identifier) { - $className = "FirefoxHTML"; - } else { - $className = "FirefoxURL"; - } - - $association.ProgId = "$className-308046B0AF4A39CB" - } - } - - $defaultAssociations.Save($configFile); - DISM /Online "/Import-DefaultAppAssociations:$configFile"; - - Pop-Location; - Remove-Item -Recurse $tempDir; + . "$PSScriptRoot/../../Config/Firefox/Install.ps1" $context; }