diff --git a/ModuleManager/PatchApplier.cs b/ModuleManager/PatchApplier.cs index 94d16e03..adaade88 100644 --- a/ModuleManager/PatchApplier.cs +++ b/ModuleManager/PatchApplier.cs @@ -41,7 +41,7 @@ private void ApplyPatches(LinkedList databaseConfigs, IPass pas try { patch.Apply(databaseConfigs, progress, logger); - progress.PatchApplied(); + if (patch.CountsAsPatch) progress.PatchApplied(); } catch (Exception e) { diff --git a/ModuleManager/PatchList.cs b/ModuleManager/PatchList.cs index 892b6843..9716de22 100644 --- a/ModuleManager/PatchList.cs +++ b/ModuleManager/PatchList.cs @@ -126,7 +126,7 @@ public PatchList(IEnumerable modList, IEnumerable patches, IPatc throw new NotImplementedException("Don't know what to do with pass specifier: " + patch.PassSpecifier.Descriptor); } - progress.PatchAdded(); + if (patch.CountsAsPatch) progress.PatchAdded(); } } diff --git a/ModuleManager/Patches/CopyPatch.cs b/ModuleManager/Patches/CopyPatch.cs index 05241973..45ee09fe 100644 --- a/ModuleManager/Patches/CopyPatch.cs +++ b/ModuleManager/Patches/CopyPatch.cs @@ -13,6 +13,7 @@ public class CopyPatch : IPatch public UrlDir.UrlConfig UrlConfig { get; } public INodeMatcher NodeMatcher { get; } public IPassSpecifier PassSpecifier { get; } + public bool CountsAsPatch => true; public CopyPatch(UrlDir.UrlConfig urlConfig, INodeMatcher nodeMatcher, IPassSpecifier passSpecifier) { diff --git a/ModuleManager/Patches/DeletePatch.cs b/ModuleManager/Patches/DeletePatch.cs index fd465c9a..46d46a94 100644 --- a/ModuleManager/Patches/DeletePatch.cs +++ b/ModuleManager/Patches/DeletePatch.cs @@ -12,6 +12,7 @@ public class DeletePatch : IPatch public UrlDir.UrlConfig UrlConfig { get; } public INodeMatcher NodeMatcher { get; } public IPassSpecifier PassSpecifier { get; } + public bool CountsAsPatch => true; public DeletePatch(UrlDir.UrlConfig urlConfig, INodeMatcher nodeMatcher, IPassSpecifier passSpecifier) { diff --git a/ModuleManager/Patches/EditPatch.cs b/ModuleManager/Patches/EditPatch.cs index 501144e9..91613879 100644 --- a/ModuleManager/Patches/EditPatch.cs +++ b/ModuleManager/Patches/EditPatch.cs @@ -15,6 +15,7 @@ public class EditPatch : IPatch public UrlDir.UrlConfig UrlConfig { get; } public INodeMatcher NodeMatcher { get; } public IPassSpecifier PassSpecifier { get; } + public bool CountsAsPatch => true; public EditPatch(UrlDir.UrlConfig urlConfig, INodeMatcher nodeMatcher, IPassSpecifier passSpecifier) { diff --git a/ModuleManager/Patches/IPatch.cs b/ModuleManager/Patches/IPatch.cs index 032ce6e1..a877ea80 100644 --- a/ModuleManager/Patches/IPatch.cs +++ b/ModuleManager/Patches/IPatch.cs @@ -10,6 +10,7 @@ public interface IPatch { UrlDir.UrlConfig UrlConfig { get; } IPassSpecifier PassSpecifier { get; } + bool CountsAsPatch { get; } void Apply(LinkedList configs, IPatchProgress progress, IBasicLogger logger); } } diff --git a/ModuleManager/Patches/InsertPatch.cs b/ModuleManager/Patches/InsertPatch.cs index 9f3c8a50..c5f2c17f 100644 --- a/ModuleManager/Patches/InsertPatch.cs +++ b/ModuleManager/Patches/InsertPatch.cs @@ -12,6 +12,7 @@ public class InsertPatch : IPatch public UrlDir.UrlConfig UrlConfig { get; } public string NodeType { get; } public IPassSpecifier PassSpecifier { get; } + public bool CountsAsPatch => false; public InsertPatch(UrlDir.UrlConfig urlConfig, string nodeType, IPassSpecifier passSpecifier) { diff --git a/ModuleManagerTests/PatchApplierTest.cs b/ModuleManagerTests/PatchApplierTest.cs index 7cd8f7c9..d7fb0eb1 100644 --- a/ModuleManagerTests/PatchApplierTest.cs +++ b/ModuleManagerTests/PatchApplierTest.cs @@ -67,6 +67,16 @@ public void TestApplyPatches() patches[i] = Substitute.For(); } + patches[0].CountsAsPatch.Returns(false); + patches[1].CountsAsPatch.Returns(false); + patches[2].CountsAsPatch.Returns(false); + patches[3].CountsAsPatch.Returns(true); + patches[4].CountsAsPatch.Returns(true); + patches[5].CountsAsPatch.Returns(true); + patches[6].CountsAsPatch.Returns(true); + patches[7].CountsAsPatch.Returns(true); + patches[8].CountsAsPatch.Returns(true); + pass1.GetEnumerator().Returns(new ArrayEnumerator(patches[0], patches[1], patches[2])); pass2.GetEnumerator().Returns(new ArrayEnumerator(patches[3], patches[4], patches[5])); pass3.GetEnumerator().Returns(new ArrayEnumerator(patches[6], patches[7], patches[8])); @@ -87,11 +97,8 @@ public void TestApplyPatches() { progress.PassStarted(pass1); patches[0].Apply(databaseConfigs, progress, logger); - progress.PatchApplied(); patches[1].Apply(databaseConfigs, progress, logger); - progress.PatchApplied(); patches[2].Apply(databaseConfigs, progress, logger); - progress.PatchApplied(); progress.PassStarted(pass2); patches[3].Apply(databaseConfigs, progress, logger); progress.PatchApplied(); diff --git a/ModuleManagerTests/PatchListTest.cs b/ModuleManagerTests/PatchListTest.cs index 8e66f0b3..09b1c1dc 100644 --- a/ModuleManagerTests/PatchListTest.cs +++ b/ModuleManagerTests/PatchListTest.cs @@ -142,6 +142,31 @@ public void Test__Lifecycle() patches[22].PassSpecifier.Returns(new FinalPassSpecifier()); patches[23].PassSpecifier.Returns(new FinalPassSpecifier()); + patches[00].CountsAsPatch.Returns(false); + patches[01].CountsAsPatch.Returns(false); + patches[02].CountsAsPatch.Returns(true); + patches[03].CountsAsPatch.Returns(true); + patches[04].CountsAsPatch.Returns(true); + patches[05].CountsAsPatch.Returns(true); + patches[06].CountsAsPatch.Returns(true); + patches[07].CountsAsPatch.Returns(true); + patches[08].CountsAsPatch.Returns(true); + patches[09].CountsAsPatch.Returns(true); + patches[10].CountsAsPatch.Returns(true); + patches[11].CountsAsPatch.Returns(true); + patches[12].CountsAsPatch.Returns(true); + patches[13].CountsAsPatch.Returns(true); + patches[14].CountsAsPatch.Returns(true); + patches[15].CountsAsPatch.Returns(true); + patches[16].CountsAsPatch.Returns(true); + patches[17].CountsAsPatch.Returns(true); + patches[18].CountsAsPatch.Returns(true); + patches[19].CountsAsPatch.Returns(true); + patches[20].CountsAsPatch.Returns(true); + patches[21].CountsAsPatch.Returns(true); + patches[22].CountsAsPatch.Returns(true); + patches[23].CountsAsPatch.Returns(true); + IPatchProgress progress = Substitute.For(); PatchList patchList = new PatchList(new[] { "mod1", "mod2" }, patches, progress); @@ -186,7 +211,7 @@ public void Test__Lifecycle() Assert.Equal(":FINAL", passes[11].Name); Assert.Equal(new[] { patches[22], patches[23] }, passes[11]); - progress.Received(patches.Length).PatchAdded(); + progress.Received(22).PatchAdded(); } } } diff --git a/ModuleManagerTests/Patches/CopyPatchTest.cs b/ModuleManagerTests/Patches/CopyPatchTest.cs index c0e8e14a..ee6443dd 100644 --- a/ModuleManagerTests/Patches/CopyPatchTest.cs +++ b/ModuleManagerTests/Patches/CopyPatchTest.cs @@ -74,6 +74,13 @@ public void TestPassSpecifier() Assert.Same(passSpecifier, patch.PassSpecifier); } + [Fact] + public void TestCountsAsPatch() + { + CopyPatch patch = new CopyPatch(UrlBuilder.CreateConfig("abc/def", new ConfigNode()), Substitute.For(), Substitute.For()); + Assert.True(patch.CountsAsPatch); + } + [Fact] public void TestApply() { diff --git a/ModuleManagerTests/Patches/DeletePatchTest.cs b/ModuleManagerTests/Patches/DeletePatchTest.cs index 1cfa950d..f45916fa 100644 --- a/ModuleManagerTests/Patches/DeletePatchTest.cs +++ b/ModuleManagerTests/Patches/DeletePatchTest.cs @@ -73,6 +73,13 @@ public void TestPassSpecifier() Assert.Same(passSpecifier, patch.PassSpecifier); } + [Fact] + public void TestCountsAsPatch() + { + DeletePatch patch = new DeletePatch(UrlBuilder.CreateConfig("abc/def", new ConfigNode()), Substitute.For(), Substitute.For()); + Assert.True(patch.CountsAsPatch); + } + [Fact] public void TestApply() { diff --git a/ModuleManagerTests/Patches/EditPatchTest.cs b/ModuleManagerTests/Patches/EditPatchTest.cs index 7ce5f6a9..50efd3b1 100644 --- a/ModuleManagerTests/Patches/EditPatchTest.cs +++ b/ModuleManagerTests/Patches/EditPatchTest.cs @@ -75,6 +75,13 @@ public void TestPassSpecifier() Assert.Same(passSpecifier, patch.PassSpecifier); } + [Fact] + public void TestCountsAsPatch() + { + EditPatch patch = new EditPatch(UrlBuilder.CreateConfig("abc/def", new ConfigNode()), Substitute.For(), Substitute.For()); + Assert.True(patch.CountsAsPatch); + } + [Fact] public void TestApply() { diff --git a/ModuleManagerTests/Patches/InsertPatchTest.cs b/ModuleManagerTests/Patches/InsertPatchTest.cs index b9944a9d..f1e134a4 100644 --- a/ModuleManagerTests/Patches/InsertPatchTest.cs +++ b/ModuleManagerTests/Patches/InsertPatchTest.cs @@ -73,6 +73,13 @@ public void TestPassSpecifier() Assert.Same(passSpecifier, patch.PassSpecifier); } + + [Fact] + public void TestCountsAsPatch() + { + InsertPatch patch = new InsertPatch(UrlBuilder.CreateConfig("abc/def", new ConfigNode()), "A_NODE", Substitute.For()); + Assert.False(patch.CountsAsPatch); + } [Fact] public void TestApply()