Skip to content

Commit

Permalink
Allow warnings
Browse files Browse the repository at this point in the history
Cache generation can proceed but the user will be alerted.
  • Loading branch information
blowfishpro committed Oct 22, 2018
1 parent c912580 commit 7b23097
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 0 deletions.
8 changes: 8 additions & 0 deletions ModuleManager/MMPatchLoader.cs
Expand Up @@ -258,6 +258,11 @@ float updateTimeRemaining()

#region Saving Cache

foreach (KeyValuePair<string, int> item in progress.Counter.warningFiles)
{
logger.Warning(item.Value + " warning" + (item.Value > 1 ? "s" : "") + " related to GameData/" + item.Key);
}

if (progress.Counter.errors > 0 || progress.Counter.exceptions > 0)
{
foreach (KeyValuePair<string, int> item in progress.Counter.errorFiles)
Expand Down Expand Up @@ -693,6 +698,9 @@ private void StatusUpdate(IPatchProgress progress)

status = "ModuleManager: " + progress.Counter.patchedNodes + " patch" + (progress.Counter.patchedNodes != 1 ? "es" : "") + " applied";

if (progress.Counter.warnings > 0)
status += ", found <color=yellow>" + progress.Counter.warnings + " warning" + (progress.Counter.warnings != 1 ? "s" : "") + "</yellow>";

if (progress.Counter.errors > 0)
status += ", found <color=orange>" + progress.Counter.errors + " error" + (progress.Counter.errors != 1 ? "s" : "") + "</color>";

Expand Down
1 change: 1 addition & 0 deletions ModuleManager/Progress/IPatchProgress.cs
Expand Up @@ -9,6 +9,7 @@ public interface IPatchProgress

float ProgressFraction { get; }

void Warning(UrlDir.UrlConfig url, string message);
void Error(UrlDir.UrlConfig url, string message);
void Exception(string message, Exception exception);
void Exception(UrlDir.UrlConfig url, string message, Exception exception);
Expand Down
19 changes: 19 additions & 0 deletions ModuleManager/Progress/PatchProgress.cs
Expand Up @@ -95,6 +95,13 @@ public void NeedsUnsatisfiedAfter(UrlDir.UrlConfig url)
Counter.needsUnsatisfied.Increment();
}

public void Warning(UrlDir.UrlConfig url, string message)
{
Counter.warnings.Increment();
logger.Warning(message);
RecordWarningFile(url);
}

public void Error(UrlDir.UrlConfig url, string message)
{
Counter.errors.Increment();
Expand All @@ -114,6 +121,18 @@ public void Exception(UrlDir.UrlConfig url, string message, Exception exception)
RecordErrorFile(url);
}

private void RecordWarningFile(UrlDir.UrlConfig url)
{
string key = url.parent.url + "." + url.parent.fileExtension;
if (key[0] == '/')
key = key.Substring(1);

if (Counter.warningFiles.ContainsKey(key))
Counter.warningFiles[key] += 1;
else
Counter.warningFiles[key] = 1;
}

private void RecordErrorFile(UrlDir.UrlConfig url)
{
string key = url.parent.url + "." + url.parent.fileExtension;
Expand Down
2 changes: 2 additions & 0 deletions ModuleManager/Progress/ProgressCounter.cs
Expand Up @@ -9,10 +9,12 @@ public class ProgressCounter
public readonly Counter totalPatches = new Counter();
public readonly Counter appliedPatches = new Counter();
public readonly Counter patchedNodes = new Counter();
public readonly Counter warnings = new Counter();
public readonly Counter errors = new Counter();
public readonly Counter exceptions = new Counter();
public readonly Counter needsUnsatisfied = new Counter();

public readonly Dictionary<String, int> warningFiles = new Dictionary<string, int>();
public readonly Dictionary<String, int> errorFiles = new Dictionary<string, int>();
}
}
19 changes: 19 additions & 0 deletions ModuleManagerTests/Progress/PatchProgressTest.cs
Expand Up @@ -219,6 +219,25 @@ public void TestNeedsUnsatisfiedAfter()
logger.Received().Log(LogType.Log, "Deleting root node in file ghi/jkl node: SOME_OTHER_NODE as it can't satisfy its AFTER");
}

[Fact]
public void TestWarning()
{
UrlDir.UrlConfig config1 = UrlBuilder.CreateConfig("abc/def", new ConfigNode("SOME_NODE"));
UrlDir.UrlConfig config2 = UrlBuilder.CreateConfig("abc/def", new ConfigNode("SOME_OTHER_NODE"));

Assert.Equal(0, progress.Counter.warnings);

progress.Warning(config1, "I'm warning you");
Assert.Equal(1, progress.Counter.warnings);
Assert.Equal(1, progress.Counter.warningFiles["abc/def.cfg"]);
logger.Received().Log(LogType.Warning, "I'm warning you");

progress.Warning(config2, "You should probably pay attention to this");
Assert.Equal(2, progress.Counter.warnings);
Assert.Equal(2, progress.Counter.warningFiles["abc/def.cfg"]);
logger.Received().Log(LogType.Warning, "You should probably pay attention to this");
}

[Fact]
public void TestError()
{
Expand Down

0 comments on commit 7b23097

Please sign in to comment.