Skip to content

Commit 0296ebb

Browse files
committed
Set default preferences if prefs.xml cannot be parsed
1 parent 668cecd commit 0296ebb

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

8+
## [0.7.1] Unreleased
9+
10+
### Fixed
11+
12+
- Set default preferences if the preferences XML file cannot be parsed for any reason.
13+
814
## [0.7.0] 2021-11-10
915

1016
### Added

Terminal-Icons/Private/Import-Preferences.ps1

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,23 @@ function Import-Preferences {
99
[string]$DefaultThemeName = $script:defaultTheme
1010
)
1111

12+
begin {
13+
$defaultPrefs = @{
14+
CurrentColorTheme = $DefaultThemeName
15+
CurrentIconTheme = $DefaultThemeName
16+
}
17+
}
18+
1219
process {
1320
if (Test-Path $Path) {
14-
Import-Clixml -Path $Path
15-
} else {
16-
@{
17-
CurrentColorTheme = $DefaultThemeName
18-
CurrentIconTheme = $DefaultThemeName
21+
try {
22+
Import-Clixml -Path $Path -ErrorAction Stop
23+
} catch {
24+
Write-Warning "Unable to parse [$Path]. Setting default preferences."
25+
$defaultPrefs
1926
}
27+
} else {
28+
$defaultPrefs
2029
}
2130
}
2231
}

0 commit comments

Comments
 (0)