From 1cc4cdb2e845b155a60819f46f5ef1fc3f61a25b Mon Sep 17 00:00:00 2001 From: James Upjohn Date: Thu, 15 Jul 2021 21:44:07 +1200 Subject: [PATCH] feat(installer-pwsh): check Firefox installation directories --- Install.ps1 | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/Install.ps1 b/Install.ps1 index a7eb91f..bf9a958 100644 --- a/Install.ps1 +++ b/Install.ps1 @@ -60,6 +60,7 @@ param( # Constants $PSMinSupportedVersion = 2 +$DefaultFirefoxProfilePaths = @("~/AppData/Roaming/Mozilla/Firefox/") function Check-Help { # Cheap and dirty way of getting the same output as '-?' for '-h' and '-Help' @@ -163,6 +164,38 @@ function Select-LeptonDistribution { } } +function Get-TestedPaths { + param ([string[]]$Paths) + + $FoundPaths = @() + foreach ($pathItem in $Paths) { + if ($Test-Path -Path $pathItem) { + $FoundPaths += $pathItem + } + } + + return $FoundPaths +} + +function Check-FirefoxProfileDirectories { + param ([string]$CustomProfilePath) + + Write-Host -Nonewline "Checking Firefox profile directories... " + + $FirefoxProfilePaths = $DefaultFirefoxProfilePaths + $FirefoxProfilePaths += $CustomProfilePath + + $FirefoxInstalls = Get-TestedPaths -Paths $FirefoxProfilePaths + if ($FirefoxInstalls.Length -eq 0) { + Write-Host "[not found]" + Write-Error "Unable to find Firefox installations" + exit -1 + } + + Write-Host "[found]" + return $FirefoxInstalls +} + function Check-FirefoxProfileDirectories { param ([string]$CustomProfilePath) # TODO: stub @@ -190,7 +223,7 @@ function Install-Lepton { $SelectedDistribution = Select-LeptonDistribution # TODO: check profile director{y,ies} (including custom) - #$InstallationDirectories = Check-FirefoxProfileDirectories $ProfilePath + $InstallationDirectories = Check-FirefoxProfileDirectories $ProfilePath # TODO: check profile ini files exists #Check-FirefoxProfileConfigurations $InstallationDirectories