Skip to content

Commit

Permalink
Fix a bug with nested :NEEDS when the top node also used a :NEEDS
Browse files Browse the repository at this point in the history
  • Loading branch information
sarbian committed Aug 29, 2015
1 parent cf0717c commit 5aa1ef5
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions moduleManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1086,43 +1086,45 @@ private void CheckNeeds(List<string> excludePaths)
// Check the NEEDS parts first.
foreach (UrlDir.UrlConfig mod in allConfigs)
{
UrlDir.UrlConfig currentMod = mod;
try
{
string name;
if (IsPathInList(mod.url, excludePaths) && (ParseCommand(mod.type, out name) != Command.Insert))
if (IsPathInList(currentMod.url, excludePaths) && (ParseCommand(currentMod.type, out name) != Command.Insert))
{
mod.parent.configs.Remove(mod);
mod.parent.configs.Remove(currentMod);
catEatenCount++;
log("Deleting Node in file " + mod.parent.url + " subnode: " + mod.type +
log("Deleting Node in file " + currentMod.parent.url + " subnode: " + currentMod.type +
" as it is set to be disabled on KSP Win64");
continue;
}

if (mod.type.Contains(":NEEDS["))
if (currentMod.type.Contains(":NEEDS["))
{
mod.parent.configs.Remove(mod);
string type = mod.type;
mod.parent.configs.Remove(currentMod);
string type = currentMod.type;

if (!CheckNeeds(ref type))
{
log("Deleting Node in file " + mod.parent.url + " subnode: " + mod.type +
log("Deleting Node in file " + currentMod.parent.url + " subnode: " + currentMod.type +
" as it can't satisfy its NEEDS");
needsUnsatisfiedCount++;
continue;
}

ConfigNode copy = new ConfigNode(type);
ShallowCopy(mod.config, copy);
mod.parent.configs.Add(new UrlDir.UrlConfig(mod.parent, copy));
ShallowCopy(currentMod.config, copy);
currentMod = new UrlDir.UrlConfig(currentMod.parent, copy);
mod.parent.configs.Add(currentMod);
}

// Recursively check the contents
CheckNeeds(mod.config, mod.parent.url, new List<string> { mod.type });
CheckNeeds(currentMod.config, currentMod.parent.url, new List<string>());
}
catch (Exception ex)
{
log("Exception while checking needs : " + mod.url + " with a type of " + mod.type + "\n" + ex);
log("Node is : " + PrettyConfig(mod));
log("Exception while checking needs : " + currentMod.url + " with a type of " + currentMod.type + "\n" + ex);
log("Node is : " + PrettyConfig(currentMod));
}
}
}
Expand All @@ -1131,9 +1133,9 @@ private void CheckNeeds(ConfigNode subMod, string url, List<string> path)
{
try
{
path.Add(subMod.name + "[" + subMod.GetValue("name") + "]");
path.Add(subMod.name);
bool needsCopy = false;
ConfigNode copy = new ConfigNode();
ConfigNode copy = new ConfigNode(subMod.name);
for (int i = 0; i < subMod.values.Count; ++i)
{
ConfigNode.Value val = subMod.values[i];
Expand Down Expand Up @@ -1168,12 +1170,12 @@ private void CheckNeeds(ConfigNode subMod, string url, List<string> path)
for (int i = 0; i < subMod.nodes.Count; ++i)
{
ConfigNode node = subMod.nodes[i];
string name = node.name;
string nodeName = node.name;
try
{
if (CheckNeeds(ref name))
if (CheckNeeds(ref nodeName))
{
node.name = name;
node.name = nodeName;
CheckNeeds(node, url, path);
copy.AddNode(node);
}
Expand All @@ -1194,7 +1196,6 @@ private void CheckNeeds(ConfigNode subMod, string url, List<string> path)
catch (Exception e)
{
log("General Exception " + e.GetType().Name + " for node \"" + node.name + "\"\n " + e.ToString());

throw;
}
}
Expand Down

0 comments on commit 5aa1ef5

Please sign in to comment.