Skip to content

Commit 7b23097

Browse files
committed
Allow warnings
Cache generation can proceed but the user will be alerted.
1 parent c912580 commit 7b23097

5 files changed

Lines changed: 49 additions & 0 deletions

File tree

ModuleManager/MMPatchLoader.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,11 @@ float updateTimeRemaining()
258258

259259
#region Saving Cache
260260

261+
foreach (KeyValuePair<string, int> item in progress.Counter.warningFiles)
262+
{
263+
logger.Warning(item.Value + " warning" + (item.Value > 1 ? "s" : "") + " related to GameData/" + item.Key);
264+
}
265+
261266
if (progress.Counter.errors > 0 || progress.Counter.exceptions > 0)
262267
{
263268
foreach (KeyValuePair<string, int> item in progress.Counter.errorFiles)
@@ -693,6 +698,9 @@ private void StatusUpdate(IPatchProgress progress)
693698

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

701+
if (progress.Counter.warnings > 0)
702+
status += ", found <color=yellow>" + progress.Counter.warnings + " warning" + (progress.Counter.warnings != 1 ? "s" : "") + "</yellow>";
703+
696704
if (progress.Counter.errors > 0)
697705
status += ", found <color=orange>" + progress.Counter.errors + " error" + (progress.Counter.errors != 1 ? "s" : "") + "</color>";
698706

ModuleManager/Progress/IPatchProgress.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public interface IPatchProgress
99

1010
float ProgressFraction { get; }
1111

12+
void Warning(UrlDir.UrlConfig url, string message);
1213
void Error(UrlDir.UrlConfig url, string message);
1314
void Exception(string message, Exception exception);
1415
void Exception(UrlDir.UrlConfig url, string message, Exception exception);

ModuleManager/Progress/PatchProgress.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,13 @@ public void NeedsUnsatisfiedAfter(UrlDir.UrlConfig url)
9595
Counter.needsUnsatisfied.Increment();
9696
}
9797

98+
public void Warning(UrlDir.UrlConfig url, string message)
99+
{
100+
Counter.warnings.Increment();
101+
logger.Warning(message);
102+
RecordWarningFile(url);
103+
}
104+
98105
public void Error(UrlDir.UrlConfig url, string message)
99106
{
100107
Counter.errors.Increment();
@@ -114,6 +121,18 @@ public void Exception(UrlDir.UrlConfig url, string message, Exception exception)
114121
RecordErrorFile(url);
115122
}
116123

124+
private void RecordWarningFile(UrlDir.UrlConfig url)
125+
{
126+
string key = url.parent.url + "." + url.parent.fileExtension;
127+
if (key[0] == '/')
128+
key = key.Substring(1);
129+
130+
if (Counter.warningFiles.ContainsKey(key))
131+
Counter.warningFiles[key] += 1;
132+
else
133+
Counter.warningFiles[key] = 1;
134+
}
135+
117136
private void RecordErrorFile(UrlDir.UrlConfig url)
118137
{
119138
string key = url.parent.url + "." + url.parent.fileExtension;

ModuleManager/Progress/ProgressCounter.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ public class ProgressCounter
99
public readonly Counter totalPatches = new Counter();
1010
public readonly Counter appliedPatches = new Counter();
1111
public readonly Counter patchedNodes = new Counter();
12+
public readonly Counter warnings = new Counter();
1213
public readonly Counter errors = new Counter();
1314
public readonly Counter exceptions = new Counter();
1415
public readonly Counter needsUnsatisfied = new Counter();
1516

17+
public readonly Dictionary<String, int> warningFiles = new Dictionary<string, int>();
1618
public readonly Dictionary<String, int> errorFiles = new Dictionary<string, int>();
1719
}
1820
}

ModuleManagerTests/Progress/PatchProgressTest.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,25 @@ public void TestNeedsUnsatisfiedAfter()
219219
logger.Received().Log(LogType.Log, "Deleting root node in file ghi/jkl node: SOME_OTHER_NODE as it can't satisfy its AFTER");
220220
}
221221

222+
[Fact]
223+
public void TestWarning()
224+
{
225+
UrlDir.UrlConfig config1 = UrlBuilder.CreateConfig("abc/def", new ConfigNode("SOME_NODE"));
226+
UrlDir.UrlConfig config2 = UrlBuilder.CreateConfig("abc/def", new ConfigNode("SOME_OTHER_NODE"));
227+
228+
Assert.Equal(0, progress.Counter.warnings);
229+
230+
progress.Warning(config1, "I'm warning you");
231+
Assert.Equal(1, progress.Counter.warnings);
232+
Assert.Equal(1, progress.Counter.warningFiles["abc/def.cfg"]);
233+
logger.Received().Log(LogType.Warning, "I'm warning you");
234+
235+
progress.Warning(config2, "You should probably pay attention to this");
236+
Assert.Equal(2, progress.Counter.warnings);
237+
Assert.Equal(2, progress.Counter.warningFiles["abc/def.cfg"]);
238+
logger.Received().Log(LogType.Warning, "You should probably pay attention to this");
239+
}
240+
222241
[Fact]
223242
public void TestError()
224243
{

0 commit comments

Comments
 (0)