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

Commit 6302f09

Browse files
committed
Added IPathStore and converted RegistryHelper to an implementation
1 parent ccc4fee commit 6302f09

File tree

7 files changed

+49
-13
lines changed

7 files changed

+49
-13
lines changed

Installer/DependencyRegistry.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ private static Container defaultContainer()
2828
x.ForSingletonOf<IInstaller>().Use<Installer>();
2929
x.ForSingletonOf<IPrompts>().Use<Prompts>();
3030
x.For<IBsaDiff>().Use<BsaDiff>();
31+
x.For<IPathStore>().Use<RegistryPathStore>();
3132
});
3233
}
3334
}

Installer/IPathStore.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using Microsoft.Win32;
2+
3+
namespace TaleOfTwoWastelands
4+
{
5+
public interface IPathStore
6+
{
7+
string GetPathFromKey(string keyName);
8+
void SetPathFromKey(string keyName, string path);
9+
}
10+
}
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
namespace TaleOfTwoWastelands
66
{
7-
public static class RegistryHelper
8-
{
9-
public static RegistryKey GetBethKey()
7+
public class RegistryPathStore : IPathStore
8+
{
9+
public RegistryKey GetBethKey()
1010
{
1111
using (var bethKey =
1212
Registry.LocalMachine.OpenSubKey(
@@ -19,7 +19,7 @@ public static RegistryKey GetBethKey()
1919
}
2020
}
2121

22-
public static string GetPathFromKey(string keyName)
22+
public string GetPathFromKey(string keyName)
2323
{
2424
using (var bethKey = GetBethKey())
2525
using (var subKey = bethKey.CreateSubKey(keyName))
@@ -29,7 +29,7 @@ public static string GetPathFromKey(string keyName)
2929
}
3030
}
3131

32-
public static void SetPathFromKey(string keyName, string path)
32+
public void SetPathFromKey(string keyName, string path)
3333
{
3434
using (var bethKey = GetBethKey())
3535
using (var subKey = bethKey.CreateSubKey(keyName))

Installer/SettingsPathStore.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
using System.Diagnostics;
3+
using Microsoft.Win32;
4+
5+
namespace TaleOfTwoWastelands
6+
{
7+
public class SettingsPathStore : IPathStore
8+
{
9+
public string GetPathFromKey(string keyName)
10+
{
11+
throw new NotImplementedException();
12+
}
13+
14+
public void SetPathFromKey(string keyName, string path)
15+
{
16+
throw new NotImplementedException();
17+
}
18+
}
19+
}

Installer/Tale Of Two Wastelands Installer.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
<Compile Include="Install\FOMOD.cs" />
9898
<Compile Include="Install\IInstallStep.cs" />
9999
<Compile Include="Install\NVSE.cs" />
100+
<Compile Include="IPathStore.cs" />
100101
<Compile Include="Log.cs" />
101102
<Compile Include="Patching\Diff.cs" />
102103
<Compile Include="Patching\BsaDiff.cs" />
@@ -121,7 +122,8 @@
121122
<DesignTime>True</DesignTime>
122123
<DependentUpon>Game.resx</DependentUpon>
123124
</Compile>
124-
<Compile Include="RegistryHelper.cs" />
125+
<Compile Include="SettingsPathStore.cs" />
126+
<Compile Include="RegistryPathStore.cs" />
125127
<Compile Include="Properties\Localization.Designer.cs">
126128
<AutoGen>True</AutoGen>
127129
<DesignTime>True</DesignTime>

Installer/UI/Prompts.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,27 @@ namespace TaleOfTwoWastelands.UI
77
public class Prompts : IPrompts
88
{
99
private readonly FileDialog openDialog, saveDialog;
10+
1011
private readonly ILog Log;
12+
private readonly IPathStore _store;
1113

12-
public string Fallout3Path { get; private set; }
14+
public string Fallout3Path { get; private set; }
1315
public string FalloutNVPath { get; private set; }
1416
public string TTWSavePath { get; private set; }
1517

16-
public Prompts(OpenFileDialog openDialog, SaveFileDialog saveDialog, ILog log)
18+
public Prompts(OpenFileDialog openDialog, SaveFileDialog saveDialog, ILog log, IPathStore store)
1719
{
1820
Log = log;
21+
_store = store;
1922

2023
this.openDialog = openDialog;
2124
this.saveDialog = saveDialog;
2225

2326
if (Program.IsElevated)
2427
{
25-
Fallout3Path = RegistryHelper.GetPathFromKey("Fallout3");
26-
FalloutNVPath = RegistryHelper.GetPathFromKey("FalloutNV");
27-
TTWSavePath = RegistryHelper.GetPathFromKey("TaleOfTwoWastelands");
28+
Fallout3Path = store.GetPathFromKey("Fallout3");
29+
FalloutNVPath = store.GetPathFromKey("FalloutNV");
30+
TTWSavePath = store.GetPathFromKey("TaleOfTwoWastelands");
2831
}
2932
}
3033

@@ -72,7 +75,7 @@ private string FindByUserPrompt(FileDialog dialog, string name, string keyName,
7275
var path = Path.GetDirectoryName(dialog.FileName);
7376
Log.File("User {2}changed {0} directory to '{1}'", name, path, manual ? "manually " : " ");
7477

75-
RegistryHelper.SetPathFromKey(keyName, path);
78+
_store.SetPathFromKey(keyName, path);
7679

7780
return path;
7881
}

PatchMaker/Program.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ static void Main()
4646
_dirTTWMain = Path.Combine(InDir, "Main Files");
4747
_dirTTWOptional = Path.Combine(InDir, "Optional Files");
4848

49-
var bethKey = RegistryHelper.GetBethKey();
49+
var helper = new RegistryPathStore();
50+
var bethKey = helper.GetBethKey();
5051

5152
var fo3Key = bethKey.CreateSubKey("Fallout3");
5253
Debug.Assert(fo3Key != null, "fo3Key != null");

0 commit comments

Comments
 (0)