From 0296ebbca065c9b97038c6a7b945a60715080de8 Mon Sep 17 00:00:00 2001 From: Brandon Olin Date: Mon, 22 Nov 2021 21:03:42 -0800 Subject: [PATCH] Set default preferences if prefs.xml cannot be parsed --- CHANGELOG.md | 6 ++++++ Terminal-Icons/Private/Import-Preferences.ps1 | 19 ++++++++++++++----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a72a5a..5a797b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [0.7.1] Unreleased + +### Fixed + +- Set default preferences if the preferences XML file cannot be parsed for any reason. + ## [0.7.0] 2021-11-10 ### Added diff --git a/Terminal-Icons/Private/Import-Preferences.ps1 b/Terminal-Icons/Private/Import-Preferences.ps1 index 054ef80..dbfb6e3 100644 --- a/Terminal-Icons/Private/Import-Preferences.ps1 +++ b/Terminal-Icons/Private/Import-Preferences.ps1 @@ -9,14 +9,23 @@ function Import-Preferences { [string]$DefaultThemeName = $script:defaultTheme ) + begin { + $defaultPrefs = @{ + CurrentColorTheme = $DefaultThemeName + CurrentIconTheme = $DefaultThemeName + } + } + process { if (Test-Path $Path) { - Import-Clixml -Path $Path - } else { - @{ - CurrentColorTheme = $DefaultThemeName - CurrentIconTheme = $DefaultThemeName + try { + Import-Clixml -Path $Path -ErrorAction Stop + } catch { + Write-Warning "Unable to parse [$Path]. Setting default preferences." + $defaultPrefs } + } else { + $defaultPrefs } } }