Handle empty cache file case

- Issue MatterHackers/MCCentral#5530
Error loading cached OemProfiles data crashes MatterControl
This commit is contained in:
John Lewin 2019-05-21 08:24:39 -07:00
parent 3a1c68cc8e
commit 0dae638ca0

View file

@ -177,7 +177,12 @@ namespace MatterHackers.MatterControl.SettingsManagement
string cachePath = ApplicationController.CacheablePath("public-profiles", "oemprofiles.json");
// Load data from cache or fall back to stale StaticData content
string json = File.Exists(cachePath) ? File.ReadAllText(cachePath) : AggContext.StaticData.ReadAllText(Path.Combine("Profiles", "oemprofiles.json"));
string json = File.Exists(cachePath) ? File.ReadAllText(cachePath) : null;
if (string.IsNullOrWhiteSpace(json))
{
json = AggContext.StaticData.ReadAllText(Path.Combine("Profiles", "oemprofiles.json"));
}
return JsonConvert.DeserializeObject<OemProfileDictionary>(json);
}