Skip to content

Commit

Permalink
Implementing (fatal) Sanity Check for issue #34
Browse files Browse the repository at this point in the history
  • Loading branch information
Lisias committed Jun 8, 2019
1 parent 24477c6 commit d7d9aec
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
8 changes: 8 additions & 0 deletions Source/Scale/GlobalSuppressions.cs
@@ -0,0 +1,8 @@

// This file is used by Code Analysis to maintain SuppressMessage
// attributes that are applied to this project.
// Project-level suppressions either have no target or are given
// a specific target and scoped to a namespace, type, member, etc.

[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage ("Potential Code Quality Issues", "RECS0082:Parameter has the same name as a member and hides it", Justification = "<Pending>", Scope = "member", Target = "~M:TweakScale.GUI.AlertBox.Init(System.String,System.String,System.Action)")]

40 changes: 37 additions & 3 deletions Source/Scale/PrefabDryCostWriter.cs
Expand Up @@ -49,6 +49,7 @@ private IEnumerator WriteDryCost()
}

int sanity_failures = 0;
int showstoppers_failures = 0;
foreach (AvailablePart p in PartLoader.LoadedPartsList)
{
for (int i = WAIT_ROUNDS; i >= 0 && null == p.partPrefab && null == p.partPrefab.Modules && p.partPrefab.Modules.Count < 1; --i)
Expand Down Expand Up @@ -106,8 +107,9 @@ private IEnumerator WriteDryCost()
}
#endif
{
string r = this.checkForSanity(prefab);
if (null != r)
string r = null;
// We check for fixable problems first, in the hope to prevent by luck a ShowStopper below.
if (null != (r = this.checkForSanity(prefab)))
{ // There are some known situations where TweakScale is capsizing. If such situations are detected, we just
// refuse to scale it. Sorry.
Debug.LogWarningFormat("[TweakScale] Removing TweakScale support for {0}.", p.name);
Expand All @@ -116,6 +118,16 @@ private IEnumerator WriteDryCost()
++sanity_failures;
continue;
}

if (null != (r = this.checkForShowStoppers(prefab)))
{ // This are situations that we should not allow the KSP to run to prevent serious corruption.
// This is **FAR** from a good measure, but it's the only viable.
Debug.LogWarningFormat("[TweakScale] **FATAL** Found a showstopper problem on {0}.", p.name);
prefab.Modules.Remove(prefab.Modules["TweakScale"]);
Debug.LogErrorFormat("[TweakScale] **FATAL** Part {0} has a fatal problem due {1}.", p.name, r);
++showstoppers_failures;
continue;
}
}

try
Expand All @@ -140,7 +152,11 @@ private IEnumerator WriteDryCost()
}
Debug.Log("TweakScale::WriteDryCost: Concluded");
PrefabDryCostWriter.isConcluded = true;
if (sanity_failures > 0)
if (showstoppers_failures > 0)
{
//todo MessageBox!
}
else if (sanity_failures > 0)
{
//todo MessageBox!
}
Expand Down Expand Up @@ -184,5 +200,23 @@ private string checkForSanity(Part p)

return null;
}

private string checkForShowStoppers(Part p)
{
{
ConfigNode part = GameDatabase.Instance.GetConfigNode(p.partInfo.partUrl);
foreach (ConfigNode basket in part.GetNodes("MODULE"))
{
if ("TweakScale" != basket.GetValue("name")) continue;
foreach (ConfigNode.Value property in basket.values)
{
if (1 != basket.GetValues(property.name).Length)
return "having duplicated properties - see issue #34 - https://github.com/net-lisias-ksp/TweakScale/issues/34";
}
}
}

return null;
}
}
}

0 comments on commit d7d9aec

Please sign in to comment.