diff --git a/Mlaumcherb.Client.Avalonia/классы/Пролетариат/InstalledGameVersionProps.cs b/Mlaumcherb.Client.Avalonia/классы/Пролетариат/InstalledGameVersionProps.cs index 06b7302..001a41f 100644 --- a/Mlaumcherb.Client.Avalonia/классы/Пролетариат/InstalledGameVersionProps.cs +++ b/Mlaumcherb.Client.Avalonia/классы/Пролетариат/InstalledGameVersionProps.cs @@ -66,23 +66,26 @@ public class InstalledGameVersionProps : IComparable, JObject descriptorRaw = JObject.Parse(descriptorText); // Descriptors can inherit from other descriptors. - // For example, 1.12.2-forge-14.23.5.2860 inherits from 1.12.2 - if (descriptorRaw.TryGetValue("inheritsFrom", out var v)) + // For example, timerix-anarx-2 inherits from 1.12.2-forge-14.23.5.2860, which inherits from 1.12.2 + while (descriptorRaw.TryGetValue("inheritsFrom", out var v)) { string parentDescriptorId = v.Value() - ?? throw new Exception("inheritsFrom is null"); + ?? throw new Exception("inheritsFrom is null"); LauncherApp.Logger.LogInfo(Id, $"merging descriptor '{parentDescriptorId}' with '{Id}'"); + IOPath parentDescriptorPath = PathHelper.GetVersionDescriptorPath(parentDescriptorId); if (!File.Exists(parentDescriptorPath)) throw new Exception($"Версия '{Id} требует установить версию '{parentDescriptorId}'"); - string parentDescriptorText = File.ReadAllText(parentDescriptorPath); - JObject parentDescriptorRaw = JObject.Parse(parentDescriptorText); + JObject parentDescriptorRaw = JObject.Parse(File.ReadAllText(parentDescriptorPath)); + + // 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, new JsonMergeSettings { MergeArrayHandling = MergeArrayHandling.Concat }); descriptorRaw = parentDescriptorRaw; - // removing dependency - // descriptorRaw.Remove("inheritsFrom"); - // File.WriteAllText(DescriptorPath, descriptorRaw.ToString()); } var descriptor = descriptorRaw.ToObject()