check inheritFrom in parent descriptors
This commit is contained in:
parent
9bcdfd88e6
commit
459b3f09f9
@ -66,23 +66,26 @@ public class InstalledGameVersionProps : IComparable<InstalledGameVersionProps>,
|
||||
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<string>()
|
||||
?? 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<GameVersionDescriptor>()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user