check inheritFrom in parent descriptors

This commit is contained in:
Timerix 2025-05-21 12:29:35 +05:00
parent 9bcdfd88e6
commit 459b3f09f9

View File

@ -66,23 +66,26 @@ public class InstalledGameVersionProps : IComparable<InstalledGameVersionProps>,
JObject descriptorRaw = JObject.Parse(descriptorText); JObject descriptorRaw = JObject.Parse(descriptorText);
// Descriptors can inherit from other descriptors. // Descriptors can inherit from other descriptors.
// For example, 1.12.2-forge-14.23.5.2860 inherits from 1.12.2 // For example, timerix-anarx-2 inherits from 1.12.2-forge-14.23.5.2860, which inherits from 1.12.2
if (descriptorRaw.TryGetValue("inheritsFrom", out var v)) while (descriptorRaw.TryGetValue("inheritsFrom", out var v))
{ {
string parentDescriptorId = v.Value<string>() string parentDescriptorId = v.Value<string>()
?? throw new Exception("inheritsFrom is null"); ?? throw new Exception("inheritsFrom is null");
LauncherApp.Logger.LogInfo(Id, $"merging descriptor '{parentDescriptorId}' with '{Id}'"); LauncherApp.Logger.LogInfo(Id, $"merging descriptor '{parentDescriptorId}' with '{Id}'");
IOPath parentDescriptorPath = PathHelper.GetVersionDescriptorPath(parentDescriptorId); IOPath parentDescriptorPath = PathHelper.GetVersionDescriptorPath(parentDescriptorId);
if (!File.Exists(parentDescriptorPath)) if (!File.Exists(parentDescriptorPath))
throw new Exception($"Версия '{Id} требует установить версию '{parentDescriptorId}'"); throw new Exception($"Версия '{Id} требует установить версию '{parentDescriptorId}'");
string parentDescriptorText = File.ReadAllText(parentDescriptorPath); JObject parentDescriptorRaw = JObject.Parse(File.ReadAllText(parentDescriptorPath));
JObject parentDescriptorRaw = JObject.Parse(parentDescriptorText);
// Remove `inheritsFrom: parentDescriptor.Id` to prevent overriding of `parentDescriptor.inheritsFrom`
descriptorRaw.Remove("inheritsFrom");
// Merge child descriptor into its parent.
// Child descriptor values override values of parent.
// Array values are merged together.
parentDescriptorRaw.Merge(descriptorRaw, parentDescriptorRaw.Merge(descriptorRaw,
new JsonMergeSettings { MergeArrayHandling = MergeArrayHandling.Concat }); new JsonMergeSettings { MergeArrayHandling = MergeArrayHandling.Concat });
descriptorRaw = parentDescriptorRaw; descriptorRaw = parentDescriptorRaw;
// removing dependency
// descriptorRaw.Remove("inheritsFrom");
// File.WriteAllText(DescriptorPath, descriptorRaw.ToString());
} }
var descriptor = descriptorRaw.ToObject<GameVersionDescriptor>() var descriptor = descriptorRaw.ToObject<GameVersionDescriptor>()