Skip to content

Commit

Permalink
Bullet proof PrettyPrint
Browse files Browse the repository at this point in the history
  • Loading branch information
sarbian committed Mar 24, 2015
1 parent 124895b commit 045d874
Showing 1 changed file with 62 additions and 23 deletions.
85 changes: 62 additions & 23 deletions moduleManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1229,6 +1229,7 @@ public IEnumerator ApplyPatch(List<String> excludePaths, string Stage)
catch (Exception e)
{
log("Exception while processing node : " + mod.url + "\n" + e);
log(PrettyConfig(mod));
mod.parent.configs.Remove(mod);
}
finally
Expand Down Expand Up @@ -2167,46 +2168,84 @@ private string PrettyConfig(UrlDir.UrlConfig config)
{
StringBuilder sb = new StringBuilder();
sb.AppendFormat("{0}[{1}]\n",config.type ?? "NULL", config.name ?? "NULL");

if (config.config !=null)
try
{
PrettyConfig(config.config, ref sb, " ");
if (config.config != null)
{
PrettyConfig(config.config, ref sb, " ");
}
else
{
sb.Append("NULL\n");
}
sb.Append("\n");
}
else
catch( Exception e )
{
sb.Append("NULL\n");
log("PrettyConfig Exception " +e);
}
sb.Append("\n");
return sb.ToString();
}

private void PrettyConfig(ConfigNode node, ref StringBuilder sb, string indent)
{
sb.AppendFormat("{0}{1}\n{2}{{\n", indent, node.name ?? "NULL", indent);
string newindent = indent + " ";
if (node.values != null)
try
{
foreach (ConfigNode.Value value in node.values)
sb.AppendFormat("{0}{1}\n{2}{{\n", indent, node.name ?? "NULL", indent);
string newindent = indent + " ";
if (node.values != null)
{
foreach (ConfigNode.Value value in node.values)
{
if (value != null)
{
try
{
sb.AppendFormat("{0}{1} = {2}\n", newindent, value.name ?? "null", value.value ?? "null");
}
catch (Exception e)
{
log("value.name.Length=" + value.name.Length);
log("value.name.IsNullOrEmpty=" + string.IsNullOrEmpty(value.name));
log("n " +value.name ?? "null");
log("v " + value.value ?? "null");
throw e;
}
}
else
{
sb.AppendFormat("{0} Null value\n", newindent);
}
}
}
else
{
sb.AppendFormat("{0}{1} = {2}\n", newindent, value.name ?? "null", value.value ?? "null");
sb.AppendFormat("{0} Null values\n", newindent);
}
}
else
{
sb.AppendFormat("{0} Null values\n", newindent);
}
if (node.nodes != null)
{
foreach (ConfigNode subnode in node.nodes)
if (node.nodes != null)
{
PrettyConfig(subnode, ref sb, newindent);
foreach (ConfigNode subnode in node.nodes)
{
if (subnode != null)
{
PrettyConfig(subnode, ref sb, newindent);
}
else
{
sb.AppendFormat("{0} Null Subnode\n", newindent);
}
}
}
else
{
sb.AppendFormat("{0} Null nodes\n", newindent);
}
sb.AppendFormat("{0}}}\n", indent);
}
else
catch (Exception e)
{
sb.AppendFormat("{0} Null nodes\n", newindent);
throw e;
}
sb.AppendFormat("{0}}}\n", indent);
}

//FindConfigNodeIn finds and returns a ConfigNode in src of type nodeType.
Expand Down

0 comments on commit 045d874

Please sign in to comment.