From b06470989bf67fc2d799beadeb3c9fda0244cc81 Mon Sep 17 00:00:00 2001 From: Anna Clemens Date: Thu, 17 Aug 2023 14:26:35 -0400 Subject: [PATCH] fix: handle broken heliosphere.json files --- Model/HeliosphereMeta.cs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Model/HeliosphereMeta.cs b/Model/HeliosphereMeta.cs index 22505a0..8138b13 100644 --- a/Model/HeliosphereMeta.cs +++ b/Model/HeliosphereMeta.cs @@ -40,7 +40,11 @@ internal class HeliosphereMeta { internal static async Task Load(string path) { var text = await File.ReadAllTextAsync(path); - var obj = JsonConvert.DeserializeObject(text)!; + var obj = JsonConvert.DeserializeObject(text); + if (obj == null) { + return null; + } + var (meta, changed) = await Convert(obj); if (changed) { var json = JsonConvert.SerializeObject(meta, Formatting.Indented); @@ -90,6 +94,17 @@ uint GetVersion() { } private static async Task MigrateV1(JObject config) { + if (!config.ContainsKey(nameof(MetaVersion)) && !config.ContainsKey("AuthorUuid")) { + // this is an invalid heliosphere.json created by the website pmp + // download (only existed for a few days) + + config[nameof(MetaVersion)] = 2u; + config[nameof(FullInstall)] = true; + config[nameof(IncludeTags)] = true; + config[nameof(SelectedOptions)] = new JObject(); + return; + } + // rename AuthorUuid to AuthorId config[nameof(AuthorId)] = config["AuthorUuid"]; config.Remove("AuthorUuid");