Skip to content

Commit

Permalink
fix: handle broken heliosphere.json files
Browse files Browse the repository at this point in the history
  • Loading branch information
anna-is-cute committed Aug 17, 2023
1 parent 514be96 commit b064709
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion Model/HeliosphereMeta.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ internal class HeliosphereMeta {

internal static async Task<HeliosphereMeta?> Load(string path) {
var text = await File.ReadAllTextAsync(path);
var obj = JsonConvert.DeserializeObject<JObject>(text)!;
var obj = JsonConvert.DeserializeObject<JObject>(text);
if (obj == null) {
return null;
}

var (meta, changed) = await Convert(obj);
if (changed) {
var json = JsonConvert.SerializeObject(meta, Formatting.Indented);
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit b064709

Please sign in to comment.