Skip to content

Commit

Permalink
Set default preferences if prefs.xml cannot be parsed
Browse files Browse the repository at this point in the history
  • Loading branch information
devblackops committed Nov 23, 2021
1 parent 668cecd commit 0296ebb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 14 additions & 5 deletions Terminal-Icons/Private/Import-Preferences.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}

0 comments on commit 0296ebb

Please sign in to comment.