Skip to content

Commit

Permalink
Extract interface for PatchList, modify PatchExtractor
Browse files Browse the repository at this point in the history
PatchExtractor did too much at once, it shouldn't enumerate and extract
at the same time (still some work to be done there...).  PatchList now
has a clearer interface and obscures more of the details - iterating
through patches is now handled by it rater than PatchApplier
  • Loading branch information
blowfishpro committed Apr 12, 2018
1 parent f96c333 commit 83288b5
Show file tree
Hide file tree
Showing 12 changed files with 1,419 additions and 624 deletions.
2 changes: 1 addition & 1 deletion ModuleManager/Collections/ArrayEnumerator.cs
Expand Up @@ -9,7 +9,7 @@ public struct ArrayEnumerator<T> : IEnumerator<T>
private readonly T[] array;
private int index;

public ArrayEnumerator(T[] array)
public ArrayEnumerator(params T[] array)
{
this.array = array;
index = -1;
Expand Down
11 changes: 10 additions & 1 deletion ModuleManager/MMPatchLoader.cs
Expand Up @@ -175,7 +175,16 @@ private IEnumerator ProcessPatch()

yield return null;

PatchList patchList = PatchExtractor.SortAndExtractPatches(GameDatabase.Instance.root, mods, progress);
// PatchList patchList = PatchExtractor.SortAndExtractPatches(GameDatabase.Instance.root, mods, progress);

PatchList patchList = new PatchList(mods);
PatchExtractor extractor = new PatchExtractor(patchList, progress, logger);

// Have to convert to an array because we will be removing patches
foreach (UrlDir.UrlConfig urlConfig in GameDatabase.Instance.root.AllConfigs.ToArray())
{
extractor.ExtractPatch(urlConfig);
}

#endregion

Expand Down
4 changes: 1 addition & 3 deletions ModuleManager/ModuleManager.csproj
Expand Up @@ -57,12 +57,10 @@
<Compile Include="ModuleManager.cs" />
<Compile Include="ModListGenerator.cs" />
<Compile Include="NeedsChecker.cs" />
<<<<<<< HEAD
<Compile Include="Operator.cs" />
<Compile Include="OperatorParser.cs" />
=======
<Compile Include="Pass.cs" />
<Compile Include="Patch.cs" />
>>>>>>> Make Patch an object
<Compile Include="PatchApplier.cs" />
<Compile Include="PatchContext.cs" />
<Compile Include="PatchExtractor.cs" />
Expand Down
31 changes: 31 additions & 0 deletions ModuleManager/Pass.cs
@@ -0,0 +1,31 @@
using System;
using System.Collections;
using System.Collections.Generic;

namespace ModuleManager
{
public interface IPass : IEnumerable<Patch>
{
string Name { get; }
}

public class Pass : IPass
{
private readonly string name;
private readonly List<Patch> patches = new List<Patch>(0);

public Pass(string name)
{
this.name = name ?? throw new ArgumentNullException(nameof(name));
if (name == string.Empty) throw new ArgumentException("can't be empty", nameof(name));
}

public string Name => name;

public void Add(Patch patch) => patches.Add(patch);

public List<Patch>.Enumerator GetEnumerator() => patches.GetEnumerator();
IEnumerator<Patch> IEnumerable<Patch>.GetEnumerator() => GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
}
28 changes: 8 additions & 20 deletions ModuleManager/PatchApplier.cs
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using ModuleManager.Logging;
using ModuleManager.Extensions;
Expand All @@ -14,13 +13,13 @@ public class PatchApplier
private readonly IPatchProgress progress;

private readonly UrlDir databaseRoot;
private readonly PatchList patchList;
private readonly IPatchList patchList;

private readonly UrlDir.UrlFile[] allConfigFiles;

public string Activity { get; private set; }

public PatchApplier(PatchList patchList, UrlDir databaseRoot, IPatchProgress progress, IBasicLogger logger)
public PatchApplier(IPatchList patchList, UrlDir databaseRoot, IPatchProgress progress, IBasicLogger logger)
{
this.patchList = patchList;
this.databaseRoot = databaseRoot;
Expand All @@ -32,29 +31,18 @@ public PatchApplier(PatchList patchList, UrlDir databaseRoot, IPatchProgress pro

public void ApplyPatches()
{
ApplyPatches(":FIRST", patchList.firstPatches);

// any node without a :pass
ApplyPatches(":LEGACY (default)", patchList.legacyPatches);

foreach (PatchList.ModPass pass in patchList.modPasses)
foreach (IPass pass in patchList)
{
string upperModName = pass.name.ToUpper();
ApplyPatches($":BEFORE[{upperModName}]", pass.beforePatches);
ApplyPatches($":FOR[{upperModName}]", pass.forPatches);
ApplyPatches($":AFTER[{upperModName}]", pass.afterPatches);
ApplyPatches(pass);
}

// :Final node
ApplyPatches(":FINAL", patchList.finalPatches);
}

private void ApplyPatches(string stage, IEnumerable<Patch> patches)
private void ApplyPatches(IPass pass)
{
logger.Info(stage + " pass");
Activity = "ModuleManager " + stage;
logger.Info(pass.Name + " pass");
Activity = "ModuleManager " + pass.Name;

foreach (Patch patch in patches)
foreach (Patch patch in pass)
{
try
{
Expand Down

0 comments on commit 83288b5

Please sign in to comment.