Skip to content

Commit f4b2eb2

Browse files
committed
2.0.6 : display info and errors on loading screen
1 parent 575406f commit f4b2eb2

2 files changed

Lines changed: 83 additions & 15 deletions

File tree

Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
1818
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
1919

20-
[assembly: AssemblyVersion("2.0.5")]
20+
[assembly: AssemblyVersion("2.0.6")]
2121

2222
// The following attributes are used to specify the signing key for the assembly,
2323
// if desired. See the Mono documentation for more information about signing.

moduleManager.cs

Lines changed: 82 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public static ConfigNode ModifyNode(ConfigNode original, ConfigNode mod)
167167
}
168168

169169
}
170-
print(vals);
170+
//print(vals);
171171

172172
foreach (ConfigNode subMod in mod.nodes)
173173
{
@@ -305,7 +305,7 @@ public static ConfigNode ModifyNode(ConfigNode original, ConfigNode mod)
305305
newNode.nodes.Add(newSubNode);
306306
}
307307
}
308-
print(msg);
308+
//print(msg);
309309
}
310310
}
311311
return newNode;
@@ -327,9 +327,10 @@ public static ConfigNode ModifyNode(ConfigNode original, ConfigNode mod)
327327

328328
static int patchCount = 0;
329329
static int errorCount = 0;
330+
static Dictionary<String,int> errorFiles;
330331
List<AssemblyName> mods;
331332

332-
public void OnGUI()
333+
public void Update()
333334
{
334335
/*
335336
* It should be a code to reload when the Reload Database debug button is used.
@@ -347,8 +348,6 @@ public void OnGUI()
347348
}
348349
*/
349350

350-
351-
352351
if (!GameDatabase.Instance.IsReady() && ((HighLogic.LoadedScene == GameScenes.MAINMENU) || (HighLogic.LoadedScene == GameScenes.SPACECENTER)))
353352
{
354353
return;
@@ -359,6 +358,7 @@ public void OnGUI()
359358

360359
patchCount = 0;
361360
errorCount = 0;
361+
errorFiles = new Dictionary<string, int>();
362362

363363
// Check for old version and MMSarbianExt
364364
var oldMM = AssemblyLoader.loadedAssemblies.Where(a => a.assembly.GetName().Name == Assembly.GetExecutingAssembly().GetName().Name).Where(a => a.assembly.GetName().Version.CompareTo(new System.Version(1, 6)) == -1);
@@ -466,22 +466,57 @@ public void OnGUI()
466466
// :Final node
467467
ApplyPatch(excludePaths, ":FINAL");
468468

469-
print("[ModuleManager] Applied " + patchCount + " patches and found " + errorCount + " errors");
469+
if (errorCount > 0)
470+
foreach (String file in errorFiles.Keys)
471+
errors += errorFiles[file] + " error"+ (errorFiles[file]>1?"s":"") +" in GameData/" + file + "\n";
472+
473+
474+
status = "ModuleManager applied " + patchCount + " patches and found " + errorCount + " error" + (errorCount > 1 ? "s" : "");
475+
476+
print("[ModuleManager] " + status + "\n" + errors);
477+
470478
loaded = true;
479+
}
480+
481+
static string status = "Processing Module Manager patch\nPlease Wait...";
482+
static string errors = "";
483+
484+
public void OnGUI()
485+
{
486+
if (HighLogic.LoadedScene != GameScenes.LOADING)
487+
return;
488+
489+
var centeredStyle = GUI.skin.GetStyle("Label");
490+
centeredStyle.alignment = TextAnchor.UpperCenter;
491+
centeredStyle.fontSize = 16;
492+
Vector2 sizeOfLabel = centeredStyle.CalcSize(new GUIContent(status));
493+
GUI.Label(new Rect(Screen.width / 2 - (sizeOfLabel.x / 2), Mathf.FloorToInt(0.8f * Screen.height), sizeOfLabel.x, sizeOfLabel.y), status, centeredStyle);
494+
495+
if (errorCount > 0)
496+
{
497+
var errorStyle = GUI.skin.GetStyle("Label");
498+
errorStyle.alignment = TextAnchor.UpperLeft;
499+
errorStyle.fontSize = 16;
500+
Vector2 sizeOfError = errorStyle.CalcSize(new GUIContent(errors));
501+
GUI.Label(new Rect(Screen.width / 2 - (sizeOfLabel.x / 2), Mathf.FloorToInt(0.8f * Screen.height) + sizeOfLabel.y, sizeOfError.x, sizeOfError.y), errors, errorStyle);
502+
503+
}
471504

472505
}
506+
473507
// Apply patch to all relevent nodes
474508
public void ApplyPatch(List<String> excludePaths, string Stage)
475509
{
476510
print("[ModuleManager] " + Stage + (Stage == ":FIRST" ? " (default) pass" : " pass"));
477511
foreach (UrlDir.UrlConfig mod in GameDatabase.Instance.root.AllConfigs)
478512
{
479-
if (mod.type[0] == '@' || (mod.type[0] == '$'))
513+
if (mod.type[0] == '@' || (mod.type[0] == '$') || (mod.type[0] == '!'))
480514
{
481515
try
482516
{
483-
string name = RemoveWS(mod.name);
517+
int lastErrorCount = errorCount;
484518

519+
string name = RemoveWS(mod.name);
485520

486521
string dependencies = "";
487522
if (name.Contains(":NEEDS["))
@@ -545,6 +580,7 @@ public void ApplyPatch(List<String> excludePaths, string Stage)
545580
if (!IsBraquetBalanced(mod.name))
546581
{
547582
print("[ModuleManager] Skipping a patch with unbalanced square brackets or a space (replace them with a '?') :\n" + mod.name + "\n");
583+
addErrorFiles(mod.parent);
548584
errorCount++;
549585
continue;
550586
}
@@ -563,25 +599,57 @@ public void ApplyPatch(List<String> excludePaths, string Stage)
563599
patchCount++;
564600
url.config = ConfigManager.ModifyNode(url.config, mod.config);
565601
}
566-
else
567-
{ // type = $
568-
// Here we would duplicate an Node if we had the mean to do it
569-
//ConfigNode newNode = ConfigManager.ModifyNode(url.config, mod.config);
570-
//UrlDir.UrlConfig newurl = new UrlDir.UrlConfig(mod.parent, newNode);
571-
//print("[ModuleManager] Copying Node " + newurl.url + " " + newurl.name);
602+
else if (mod.type[0] == '$')
603+
{
604+
// Here we would duplicate an Node if it did not create an exception since we modfiy an enum while it is used
605+
606+
//ConfigNode clone = ConfigManager.ModifyNode(url.config, mod.config);
607+
//if (url.config.name != mod.name)
608+
//{
609+
// print("[ModuleManager] Copying Node " + url.config.name + " into " + clone.name);
610+
// url.parent.configs.Add(new UrlDir.UrlConfig(url.parent, clone));
611+
//}
612+
//else
613+
//{
614+
// errorCount++;
615+
// print("[ModuleManager] Error while processing " + mod.config.name + " the copy need to have a different name than the parent (use @name = xxx)");
616+
//}
617+
}
618+
else if (mod.type[0] == '!')
619+
{
620+
// Same problem
621+
//print("[ModuleManager] Deleting Node " + url.config.name);
622+
//url.parent.configs.Remove(url);
572623
}
573624
}
574625
}
575626
}
627+
628+
if (lastErrorCount < errorCount)
629+
addErrorFiles(mod.parent, errorCount - lastErrorCount);
630+
576631
}
577632
catch (Exception e)
578633
{
579634
print("[ModuleManager] Exception while processing node : " + mod.url + "\n" + e.ToString());
635+
addErrorFiles(mod.parent);
580636
}
581637
}
582638
}
583639
}
584640

641+
public void addErrorFiles(UrlDir.UrlFile file, int n=1)
642+
{
643+
string key = file.url + "." + file.fileExtension;
644+
if (key[0] == '/')
645+
key = key.Substring(1);
646+
if (!errorFiles.ContainsKey(key))
647+
errorFiles.Add(key, n);
648+
else
649+
errorFiles[key] = errorFiles[key] + n;
650+
651+
}
652+
585653
public bool IsPathInList(string modPath, List<String> pathList)
586654
{
587655
return pathList.Any(modPath.StartsWith);

0 commit comments

Comments
 (0)