Skip to content

Commit 629f341

Browse files
committed
change PathNames to be non-static
1 parent f941cf8 commit 629f341

2 files changed

Lines changed: 30 additions & 12 deletions

File tree

FlashpointSecurePlayer/RegistryStates.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,12 @@ public enum TYPE {
5656
private const int IMPORT_TIMEOUT = 60;
5757
private const string IMPORT_RESUME = "FLASHPOINTSECUREPLAYERREGISTRYSTATEIMPORTRESUME";
5858
private const string IMPORT_PAUSE = "FLASHPOINTSECUREPLAYERREGISTRYSTATEIMPORTPAUSE";
59+
5960
private readonly object activationLock = new object();
6061
private readonly object deactivationLock = new object();
62+
6163
private string fullPath = null;
64+
private PathNames pathNames = null;
6265
private EventWaitHandle resumeEventWaitHandle = new ManualResetEvent(false);
6366
private Dictionary<ulong, SortedList<DateTime, RegistryStateElement>> modificationsQueue = null;
6467
private Dictionary<ulong, string> kcbModificationKeyNames = null;
@@ -770,6 +773,7 @@ public async Task StartImportAsync(string templateName, BINARY_TYPE binaryType)
770773

771774
try {
772775
modificationsElement.RegistryStates.BinaryType = binaryType;
776+
pathNames = new PathNames();
773777
resumeEventWaitHandle.Reset();
774778
modificationsQueue = new Dictionary<ulong, SortedList<DateTime, RegistryStateElement>>();
775779
kcbModificationKeyNames = new Dictionary<ulong, string>();
@@ -824,9 +828,11 @@ public async Task StartImportAsync(string templateName, BINARY_TYPE binaryType)
824828
} catch {
825829
kernelSession.Dispose();
826830
kernelSession = null;
831+
pathNames = null;
827832
ImportStarted = false;
828833
}
829834
} catch {
835+
pathNames = null;
830836
ImportStarted = false;
831837
}
832838
}
@@ -878,6 +884,7 @@ private async Task StopImportAsync(bool sync) {
878884
} finally {
879885
kernelSession.Dispose();
880886
kernelSession = null;
887+
pathNames = null;
881888
ImportStarted = false;
882889
}
883890
}
@@ -1376,7 +1383,7 @@ private void ModificationAdded(RegistryTraceData registryTraceData) {
13761383
value = null;
13771384

13781385
try {
1379-
value = ReplaceStartupPathEnvironmentVariable(LengthenValue(GetValueInRegistryView(registryStateElement.KeyName, registryStateElement.ValueName, registryView), fullPath));
1386+
value = ReplaceStartupPathEnvironmentVariable(LengthenValue(GetValueInRegistryView(registryStateElement.KeyName, registryStateElement.ValueName, registryView), fullPath, pathNames), pathNames);
13801387
} catch (ArgumentException) {
13811388
// value doesn't exist
13821389
value = null;
@@ -1416,7 +1423,7 @@ private void ModificationAdded(RegistryTraceData registryTraceData) {
14161423
value = null;
14171424

14181425
try {
1419-
value = ReplaceStartupPathEnvironmentVariable(LengthenValue(GetValueInRegistryView(registryStateElement.KeyName, registryStateElement.ValueName, registryView), fullPath));
1426+
value = ReplaceStartupPathEnvironmentVariable(LengthenValue(GetValueInRegistryView(registryStateElement.KeyName, registryStateElement.ValueName, registryView), fullPath, pathNames), pathNames);
14201427
} catch {
14211428
// we have permission to access the key at this point so this must not be important
14221429
}
@@ -1591,7 +1598,7 @@ private void KCBStopped(RegistryTraceData registryTraceData) {
15911598

15921599
// value
15931600
try {
1594-
value = ReplaceStartupPathEnvironmentVariable(LengthenValue(GetValueInRegistryView(registryStateElement.KeyName, registryStateElement.ValueName, registryView), fullPath));
1601+
value = ReplaceStartupPathEnvironmentVariable(LengthenValue(GetValueInRegistryView(registryStateElement.KeyName, registryStateElement.ValueName, registryView), fullPath, pathNames), pathNames);
15951602
} catch (ArgumentException) {
15961603
// value doesn't exist
15971604
value = null;

FlashpointSecurePlayer/Shared.cs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1933,7 +1933,7 @@ private static Configuration ActiveEXEConfiguration {
19331933
}
19341934
}
19351935

1936-
private static class PathNames {
1936+
public class PathNames {
19371937
public class PathNamesShort {
19381938
private readonly Dictionary<string, string> pathNamesShort = new Dictionary<string, string>();
19391939

@@ -1976,8 +1976,8 @@ public string this[string shortPath] {
19761976
}
19771977
}
19781978

1979-
public static PathNamesShort Short { get; } = new PathNamesShort();
1980-
public static PathNamesLong Long { get; } = new PathNamesLong();
1979+
public PathNamesShort Short { get; } = new PathNamesShort();
1980+
public PathNamesLong Long { get; } = new PathNamesLong();
19811981
}
19821982

19831983
private const string URI_SCHEME_HTTP = "http";
@@ -2797,7 +2797,7 @@ public static string RemoveTrailingSlash(string path) {
27972797
//return path.TrimEnd('\\');
27982798
}
27992799

2800-
public static object LengthenValue(object value, string path) {
2800+
public static object LengthenValue(object value, string path, PathNames pathNames) {
28012801
// since it's a value we'll just check it exists
28022802
if (!(value is string valueString)) {
28032803
return value;
@@ -2815,8 +2815,14 @@ public static object LengthenValue(object value, string path) {
28152815
return value;
28162816
}
28172817

2818+
if (pathNames == null
2819+
|| pathNames.Short == null
2820+
|| pathNames.Long == null) {
2821+
pathNames = new PathNames();
2822+
}
2823+
28182824
// get the short path
2819-
string shortPathName = PathNames.Short[path];
2825+
string shortPathName = pathNames.Short[path];
28202826

28212827
if (String.IsNullOrEmpty(shortPathName)) {
28222828
return value;
@@ -2828,7 +2834,7 @@ public static object LengthenValue(object value, string path) {
28282834
}
28292835

28302836
// get the long path
2831-
string longPathName = PathNames.Long[path];
2837+
string longPathName = pathNames.Long[path];
28322838

28332839
if (String.IsNullOrEmpty(longPathName)) {
28342840
return value;
@@ -2839,7 +2845,7 @@ public static object LengthenValue(object value, string path) {
28392845

28402846
// find path in registry value
28412847
// string must begin with path
2842-
public static object ReplaceStartupPathEnvironmentVariable(object lengthenedValue) {
2848+
public static object ReplaceStartupPathEnvironmentVariable(object lengthenedValue, PathNames pathNames) {
28432849
// since it's a value we'll just check it exists
28442850
if (!(lengthenedValue is string lengthenedValueString)) {
28452851
return lengthenedValue;
@@ -2852,8 +2858,13 @@ public static object ReplaceStartupPathEnvironmentVariable(object lengthenedValu
28522858
if (lengthenedValueString.Length > MAX_PATH + MAX_PATH + FP_STARTUP_PATH.Length) {
28532859
return lengthenedValue;
28542860
}
2855-
2856-
string longStartupPathName = PathNames.Long[Application.StartupPath];
2861+
2862+
if (pathNames == null
2863+
|| pathNames.Long == null) {
2864+
pathNames = new PathNames();
2865+
}
2866+
2867+
string longStartupPathName = pathNames.Long[Application.StartupPath];
28572868

28582869
if (String.IsNullOrEmpty(longStartupPathName)) {
28592870
return lengthenedValue;

0 commit comments

Comments
 (0)