Improve guards for theme loading

This commit is contained in:
John Lewin 2018-10-22 12:22:18 -07:00
parent 367c3b67eb
commit 819d7ef453
2 changed files with 13 additions and 3 deletions

View file

@ -159,7 +159,7 @@ namespace MatterHackers.MatterControl
if (themeset == null)
{
var themeProvider = ThemeProviders.Values.First();
themeset = themeProvider.GetTheme("Dark", themeProvider.DefaultColor);
themeset = themeProvider.GetTheme(themeProvider.ThemeNames.First(), themeProvider.DefaultColor);
}
DefaultThumbView.ThumbColor = new Color(themeset.Theme.Colors.PrimaryTextColor, 30);

View file

@ -79,8 +79,18 @@ namespace MatterHackers.MatterControl
public ThemeSet GetTheme(string themeName, Color accentColor)
{
var themeset = JsonConvert.DeserializeObject<ThemeSet>(
AggContext.StaticData.ReadAllText(Path.Combine(path, themeName + ".json")));
ThemeSet themeset = null;
try
{
themeset = JsonConvert.DeserializeObject<ThemeSet>(
AggContext.StaticData.ReadAllText(Path.Combine(path, themeName + ".json")));
}
catch
{
themeset = JsonConvert.DeserializeObject<ThemeSet>(
AggContext.StaticData.ReadAllText(Path.Combine(path, this.ThemeNames.First() + ".json")));
}
themeset.ThemeID = themeName;
themeset.SetAccentColor(accentColor);