forked from KSP-ModularManagement/ModuleManager
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPatchApplier.cs
More file actions
57 lines (51 loc) · 1.89 KB
/
Copy pathPatchApplier.cs
File metadata and controls
57 lines (51 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System;
using System.Collections.Generic;
using System.Linq;
using ModuleManager.Logging;
using ModuleManager.Extensions;
using ModuleManager.Patches;
using ModuleManager.Progress;
namespace ModuleManager
{
public class PatchApplier
{
private readonly IBasicLogger logger;
private readonly IPatchProgress progress;
public string Activity { get; private set; }
public PatchApplier(IPatchProgress progress, IBasicLogger logger)
{
this.progress = progress ?? throw new ArgumentNullException(nameof(progress));
this.logger = logger ?? throw new ArgumentNullException(nameof(logger));
}
public void ApplyPatches(IEnumerable<UrlDir.UrlFile> configFiles, IEnumerable<IPass> patches)
{
if (configFiles == null) throw new ArgumentNullException(nameof(configFiles));
if (patches == null) throw new ArgumentNullException(nameof(patches));
foreach (IPass pass in patches)
{
ApplyPatches(configFiles, pass);
}
}
private void ApplyPatches(IEnumerable<UrlDir.UrlFile> configFiles, IPass pass)
{
logger.Info(pass.Name + " pass");
Activity = "ModuleManager " + pass.Name;
foreach (IPatch patch in pass)
{
try
{
foreach (UrlDir.UrlFile file in configFiles)
{
patch.Apply(file, progress, logger);
}
progress.PatchApplied();
}
catch (Exception e)
{
progress.Exception(patch.UrlConfig, "Exception while processing node : " + patch.UrlConfig.SafeUrl(), e);
logger.Error("Processed node was\n" + patch.UrlConfig.PrettyPrint());
}
}
}
}
}