Skip to content
This repository was archived by the owner on Jun 23, 2022. It is now read-only.

Commit ccc4fee

Browse files
committed
BSA -> BsaInstaller
BSA prompts moved to Prompts/IPrompts Split out ErrorPromptResult from BSA.BsaBuildResult Split out BuildBsasStep from Installer Moved some more constants to resources Fixed runtime issues from faulty DI setup
1 parent ab1c553 commit ccc4fee

19 files changed

+797
-695
lines changed

Installer/DependencyRegistry.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Threading;
66
using System.Windows.Forms;
77
using StructureMap;
8+
using TaleOfTwoWastelands.Patching;
89
using TaleOfTwoWastelands.UI;
910

1011
namespace TaleOfTwoWastelands
@@ -25,7 +26,8 @@ private static Container defaultContainer()
2526
{
2627
x.ForSingletonOf<ILog>().Use<Log>();
2728
x.ForSingletonOf<IInstaller>().Use<Installer>();
28-
x.For<IPrompts>().Use<Prompts>();
29+
x.ForSingletonOf<IPrompts>().Use<Prompts>();
30+
x.For<IBsaDiff>().Use<BsaDiff>();
2931
});
3032
}
3133
}

Installer/IInstaller.cs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,25 @@
33

44
namespace TaleOfTwoWastelands
55
{
6-
public interface IInstaller
7-
{
8-
/// <summary>
9-
/// Provides progress updates for minor operations
10-
/// </summary>
11-
IProgress<InstallStatus> ProgressMinorOperation { get; set; }
6+
public interface IInstaller
7+
{
8+
string DirFO3Data { get; }
9+
string DirFNVData { get; }
10+
string DirTTWMain { get; }
11+
string DirTTWOptional { get; }
1212

13-
/// <summary>
14-
/// Provides progress updates for major operations
15-
/// </summary>
16-
IProgress<InstallStatus> ProgressMajorOperation { get; set; }
13+
/// <summary>
14+
/// Provides progress updates for minor operations
15+
/// </summary>
16+
IProgress<InstallStatus> ProgressMinorOperation { get; set; }
1717

18-
void Install(CancellationToken inToken);
19-
}
18+
/// <summary>
19+
/// Provides progress updates for major operations
20+
/// </summary>
21+
IProgress<InstallStatus> ProgressMajorOperation { get; set; }
22+
23+
CancellationToken Token { get; }
24+
25+
void Install(CancellationToken inToken);
26+
}
2027
}
Lines changed: 11 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,12 @@
77
using BSAsharp;
88
using TaleOfTwoWastelands.Patching;
99
using TaleOfTwoWastelands.Properties;
10+
using TaleOfTwoWastelands.UI;
1011

1112
namespace TaleOfTwoWastelands.Install
1213
{
13-
public class BSA
14+
public class BsaInstaller
1415
{
15-
public enum BuildResult
16-
{
17-
Continue,
18-
Retry,
19-
Abort
20-
}
21-
2216
const CompressionStrategy
2317
FastStrategy = CompressionStrategy.Unsafe | CompressionStrategy.Speed,
2418
GoodStrategy = CompressionStrategy.Unsafe | CompressionStrategy.Size;
@@ -40,58 +34,14 @@ const CompressionStrategy
4034
};
4135

4236
private readonly ILog Log;
37+
private readonly IPrompts Prompts;
38+
private readonly IBsaDiff _bsaDiff;
4339

44-
public BSA(ILog log)
40+
public BsaInstaller(ILog log, IPrompts prompts, IBsaDiff bsaDiff)
4541
{
4642
Log = log;
47-
}
48-
49-
private bool OverwritePrompt(string bsaName, string bsaPath)
50-
{
51-
if (!File.Exists(bsaPath))
52-
return true;
53-
54-
Log.File("BSA \"{0}\" does not exist", bsaPath);
55-
56-
var promptResult = MessageBox.Show(String.Format(Localization.RebuildPrompt, bsaName), Localization.FileAlreadyExists, MessageBoxButtons.YesNo);
57-
switch (promptResult)
58-
{
59-
case DialogResult.Yes:
60-
File.Delete(bsaPath);
61-
Log.File("Rebuilding {0}", bsaName);
62-
return true;
63-
case DialogResult.No:
64-
Log.Dual("{0} has already been built. Skipping.", bsaName);
65-
break;
66-
}
67-
68-
return false;
69-
}
70-
71-
public bool BuildPrompt(string bsaName, string bsaPath)
72-
{
73-
if (!OverwritePrompt(bsaName, bsaPath))
74-
return false;
75-
76-
Log.Dual("Building {0}", bsaName);
77-
return true;
78-
}
79-
80-
private BuildResult ErrorPrompt(string bsaFile)
81-
{
82-
var promptResult = MessageBox.Show(String.Format(Localization.ErrorWhilePatching, bsaFile), Localization.Error, MessageBoxButtons.AbortRetryIgnore);
83-
switch (promptResult)
84-
{
85-
//case DialogResult.Abort: //Quit install
86-
case DialogResult.Retry: //Start over from scratch
87-
Log.Dual("Retrying build.");
88-
return BuildResult.Retry;
89-
case DialogResult.Ignore: //Ignore errors and move on
90-
Log.Dual("Ignoring errors.");
91-
return BuildResult.Continue;
92-
}
93-
94-
return BuildResult.Abort;
43+
Prompts = prompts;
44+
_bsaDiff = bsaDiff;
9545
}
9646

9747
public CompressionOptions GetOptionsOrDefault(string inBsa)
@@ -108,7 +58,7 @@ public CompressionOptions GetOptionsOrDefault(string inBsa)
10858
return bsaOptions ?? DefaultBSAOptions;
10959
}
11060

111-
public BuildResult Patch(BSADiff diff, CompressionOptions options, string inBsaFile, string inBsaPath, string outBsaPath)
61+
public ErrorPromptResult Patch(CompressionOptions options, string inBsaFile, string inBsaPath, string outBsaPath)
11262
{
11363
bool patchSuccess;
11464

@@ -118,7 +68,7 @@ public BuildResult Patch(BSADiff diff, CompressionOptions options, string inBsaF
11868
{
11969
watch.Start();
12070
#endif
121-
patchSuccess = diff.PatchBSA(options, inBsaPath, outBsaPath);
71+
patchSuccess = _bsaDiff.PatchBsa(options, inBsaPath, outBsaPath);
12272
if (!patchSuccess)
12373
Log.Dual("Patching BSA {0} failed", inBsaFile);
12474
#if DEBUG
@@ -133,10 +83,10 @@ public BuildResult Patch(BSADiff diff, CompressionOptions options, string inBsaF
13383
if (patchSuccess)
13484
{
13585
Log.Dual("Build successful.");
136-
return BuildResult.Continue;
86+
return ErrorPromptResult.Continue;
13787
}
13888

139-
return ErrorPrompt(inBsaFile);
89+
return Prompts.PatchingErrorPrompt(inBsaFile);
14090
}
14191

14292
public void Extract(CancellationToken token, IEnumerable<BSAFolder> folders, string outBsa, string outBsaPath, bool skipExisting)

Installer/Install/BuildBsasStep.cs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using System.IO;
2+
using System.Threading;
3+
using TaleOfTwoWastelands.Progress;
4+
using TaleOfTwoWastelands.Properties;
5+
using TaleOfTwoWastelands.UI;
6+
7+
namespace TaleOfTwoWastelands.Install
8+
{
9+
class BuildBsasStep : IInstallStep
10+
{
11+
private readonly IInstaller _installer;
12+
private readonly IPrompts _prompts;
13+
14+
public BuildBsasStep(IInstaller installer, IPrompts prompts)
15+
{
16+
_installer = installer;
17+
_prompts = prompts;
18+
}
19+
20+
public bool? Run(InstallStatus status, CancellationToken token)
21+
{
22+
foreach (var kvp in Game.BuildableBSAs)
23+
{
24+
if (token.IsCancellationRequested)
25+
return false;
26+
27+
//inBSA - KVP.Key
28+
//outBSA - KVP.Value
29+
var outBSA = kvp.Value;
30+
string outBSAFile = Path.ChangeExtension(kvp.Value, ".bsa");
31+
string outBSAPath = Path.Combine(_installer.DirTTWMain, outBSAFile);
32+
33+
var inBSA = kvp.Key;
34+
string inBSAFile = Path.ChangeExtension(kvp.Key, ".bsa");
35+
string inBSAPath = Path.Combine(_installer.DirFO3Data, inBSAFile);
36+
37+
ErrorPromptResult buildResult;
38+
try
39+
{
40+
status.CurrentOperation = string.Format("Building {0}", outBSA);
41+
42+
if (!_prompts.BuildPrompt(outBSA, outBSAPath))
43+
continue;
44+
45+
var bsaInstaller = DependencyRegistry.Container.GetInstance<BsaInstaller>();
46+
do
47+
{
48+
buildResult = bsaInstaller.Patch(bsaInstaller.GetOptionsOrDefault(inBSA), inBSAFile, inBSAPath, outBSAPath);
49+
} while (!token.IsCancellationRequested && buildResult == ErrorPromptResult.Retry);
50+
}
51+
finally
52+
{
53+
status.Step();
54+
}
55+
56+
if (buildResult == ErrorPromptResult.Abort)
57+
return null;
58+
}
59+
60+
return true;
61+
}
62+
}
63+
}

Installer/Install/FOMOD.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ internal class FOMOD
1010
{
1111
private readonly ILog Log;
1212

13-
internal FOMOD(ILog log)
13+
public FOMOD(ILog log)
1414
{
1515
Log = log;
1616
SevenZipCompressor.SetLibraryPath(Path.Combine(Paths.AssetsDir, Paths.SevenZipBinaries, Environment.Is64BitProcess ? Paths.SevenZipX64 : Paths.SevenZipX32));

Installer/Install/IInstallStep.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System.Threading;
2+
using TaleOfTwoWastelands.Progress;
3+
4+
namespace TaleOfTwoWastelands.Install
5+
{
6+
interface IInstallStep
7+
{
8+
bool? Run(InstallStatus status, CancellationToken token);
9+
}
10+
}

0 commit comments

Comments
 (0)