Skip to content

Commit bcbf4e5

Browse files
blowfishproLisias
authored andcommitted
Fix :LAST when mod doesn't exist
Per the original feature design (sarbian#96) it should still run
1 parent 6089fd5 commit bcbf4e5

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

Source/ModuleManager/PatchList.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public ModPassCollection(IEnumerable<string> modList)
7676
private readonly Pass finalPatches = new Pass(":FINAL");
7777

7878
private readonly ModPassCollection modPasses;
79+
private readonly SortedDictionary<string, Pass> lastPasses = new SortedDictionary<string, Pass>(StringComparer.InvariantCultureIgnoreCase);
7980

8081
public PatchList(IEnumerable<string> modList, IEnumerable<IPatch> patches, IPatchProgress progress)
8182
{
@@ -114,8 +115,12 @@ public PatchList(IEnumerable<string> modList, IEnumerable<IPatch> patches, IPatc
114115
}
115116
else if (patch.PassSpecifier is LastPassSpecifier lastPassSpecifier)
116117
{
117-
EnsureMod(lastPassSpecifier.mod);
118-
modPasses[lastPassSpecifier.mod].AddLastPatch(patch);
118+
if (!lastPasses.TryGetValue(lastPassSpecifier.mod, out Pass thisPass))
119+
{
120+
thisPass = new Pass($":LAST[{lastPassSpecifier.mod.ToUpperInvariant()}]");
121+
lastPasses.Add(lastPassSpecifier.mod.ToLowerInvariant(), thisPass);
122+
}
123+
thisPass.Add(patch);
119124
}
120125
else if (patch.PassSpecifier is FinalPassSpecifier)
121126
{
@@ -143,9 +148,9 @@ public IEnumerator<IPass> GetEnumerator()
143148
yield return modPass.afterPass;
144149
}
145150

146-
foreach (ModPass modPass in modPasses)
151+
foreach (Pass lastPass in lastPasses.Values)
147152
{
148-
yield return modPass.lastPass;
153+
yield return lastPass;
149154
}
150155

151156
yield return finalPatches;

Source/ModuleManagerTests/PatchListTest.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ public void Test__Lifecycle()
113113
Substitute.For<IPatch>(),
114114
Substitute.For<IPatch>(),
115115
Substitute.For<IPatch>(),
116+
Substitute.For<IPatch>(),
116117
};
117118

118119
UrlDir.UrlConfig urlConfig = UrlBuilder.CreateConfig("abc/def", new ConfigNode("NODE"));
@@ -139,8 +140,9 @@ public void Test__Lifecycle()
139140
patches[19].PassSpecifier.Returns(new AfterPassSpecifier("MOD2", urlConfig));
140141
patches[20].PassSpecifier.Returns(new LastPassSpecifier("mod2"));
141142
patches[21].PassSpecifier.Returns(new LastPassSpecifier("MOD2"));
142-
patches[22].PassSpecifier.Returns(new FinalPassSpecifier());
143+
patches[22].PassSpecifier.Returns(new LastPassSpecifier("mod3"));
143144
patches[23].PassSpecifier.Returns(new FinalPassSpecifier());
145+
patches[24].PassSpecifier.Returns(new FinalPassSpecifier());
144146

145147
patches[00].CountsAsPatch.Returns(false);
146148
patches[01].CountsAsPatch.Returns(false);
@@ -166,14 +168,15 @@ public void Test__Lifecycle()
166168
patches[21].CountsAsPatch.Returns(true);
167169
patches[22].CountsAsPatch.Returns(true);
168170
patches[23].CountsAsPatch.Returns(true);
171+
patches[24].CountsAsPatch.Returns(true);
169172

170173
IPatchProgress progress = Substitute.For<IPatchProgress>();
171174

172175
PatchList patchList = new PatchList(new[] { "mod1", "mod2" }, patches, progress);
173176

174177
IPass[] passes = patchList.ToArray();
175178

176-
Assert.Equal(12, passes.Length);
179+
Assert.Equal(13, passes.Length);
177180

178181
Assert.Equal(":INSERT (initial)", passes[0].Name);
179182
Assert.Equal(new[] { patches[0], patches[1] }, passes[0]);
@@ -208,10 +211,13 @@ public void Test__Lifecycle()
208211
Assert.Equal(":LAST[MOD2]", passes[10].Name);
209212
Assert.Equal(new[] { patches[20], patches[21] }, passes[10]);
210213

211-
Assert.Equal(":FINAL", passes[11].Name);
212-
Assert.Equal(new[] { patches[22], patches[23] }, passes[11]);
214+
Assert.Equal(":LAST[MOD3]", passes[11].Name);
215+
Assert.Equal(new[] { patches[22] }, passes[11]);
216+
217+
Assert.Equal(":FINAL", passes[12].Name);
218+
Assert.Equal(new[] { patches[23], patches[24] }, passes[12]);
213219

214-
progress.Received(22).PatchAdded();
220+
progress.Received(23).PatchAdded();
215221
}
216222
}
217223
}

0 commit comments

Comments
 (0)