forked from KSP-ModularManagement/ModuleManager
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMMPatchRunner.cs
More file actions
70 lines (55 loc) · 2.28 KB
/
Copy pathMMPatchRunner.cs
File metadata and controls
70 lines (55 loc) · 2.28 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
58
59
60
61
62
63
64
65
66
67
68
69
70
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using ModuleManager.Extensions;
using ModuleManager.Logging;
using ModuleManager.Threading;
using static ModuleManager.FilePathRepository;
namespace ModuleManager
{
public class MMPatchRunner
{
private readonly IBasicLogger kspLogger;
public string Status { get; private set; } = "";
public string Errors { get; private set; } = "";
public MMPatchRunner(IBasicLogger kspLogger)
{
this.kspLogger = kspLogger ?? throw new ArgumentNullException(nameof(kspLogger));
}
public IEnumerator Run()
{
PostPatchLoader.Instance.databaseConfigs = null;
// Wait for game database to be initialized for the 2nd time and wait for any plugins to initialize
yield return null;
yield return null;
IEnumerable<ModListGenerator.ModAddedByAssembly> modsAddedByAssemblies = ModListGenerator.GetAdditionalModsFromStaticMethods(ModLogger.Instance);
IEnumerable<IProtoUrlConfig> databaseConfigs = null;
MMPatchLoader patchLoader = new MMPatchLoader(modsAddedByAssemblies, ModLogger.Instance);
ITaskStatus patchingThreadStatus = BackgroundTask.Start(delegate
{
databaseConfigs = patchLoader.Run();
});
while(true)
{
yield return null;
Status = patchLoader.status;
Errors = patchLoader.errors;
if (!patchingThreadStatus.IsRunning) break;
}
if (patchingThreadStatus.IsExitedWithError)
{
kspLogger.Exception("The patching thread threw an exception", patchingThreadStatus.Exception);
FatalErrorHandler.HandleFatalError("The patching thread threw an exception");
yield break;
}
if (databaseConfigs == null)
{
kspLogger.Error("The patcher returned a null collection of configs");
FatalErrorHandler.HandleFatalError("The patcher returned a null collection of configs");
yield break;
}
PostPatchLoader.Instance.databaseConfigs = databaseConfigs;
}
}
}