Skip to content

Commit a0b4093

Browse files
committed
make the 8.3 filename fix less ugly
1 parent 8c214ee commit a0b4093

File tree

4 files changed

+50
-14
lines changed

4 files changed

+50
-14
lines changed

FlashpointSecurePlayer/EnvironmentVariables.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public void Activate(string name, string server, string applicationMutexName) {
4545
value = environmentVariablesElement.Value;
4646

4747
try {
48-
Environment.SetEnvironmentVariable(environmentVariablesElement.Name, RemoveVariablesFromCanonicalizedValue(value) as string);
48+
Environment.SetEnvironmentVariable(environmentVariablesElement.Name, RemoveVariablesFromLengthenedValue(value) as string);
4949
} catch (ArgumentException) {
5050
throw new EnvironmentVariablesFailedException();
5151
} catch (SecurityException) {

FlashpointSecurePlayer/FlashpointSecurePlayer.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,8 @@ private async Task ActivateModificationsAsync(string commandLine, ErrorDelegate
227227
errorDelegate(Properties.Resources.ConfigurationFailedLoad);
228228
} catch (TaskRequiresElevationException) {
229229
AskLaunchAsAdministratorUser();
230+
} catch (ArgumentException) {
231+
errorDelegate(Properties.Resources.GameIsMissingFiles);
230232
}
231233
}
232234

@@ -260,6 +262,8 @@ private async Task DeactivateModificationsAsync(ErrorDelegate errorDelegate) {
260262
errorDelegate(Properties.Resources.ConfigurationFailedLoad);
261263
} catch (TaskRequiresElevationException) {
262264
AskLaunchAsAdministratorUser();
265+
} catch (ArgumentException) {
266+
errorDelegate(Properties.Resources.GameIsMissingFiles);
263267
}
264268

265269
try {
@@ -446,10 +450,11 @@ await ActivateModificationsAsync(Software, delegate (string text) {
446450
SoftwareProcessStartInfo = new ProcessStartInfo();
447451
}
448452

449-
SoftwareProcessStartInfo.FileName = Path.GetFullPath(argv[0]);
453+
string fullPath = Path.GetFullPath(argv[0]);
454+
SoftwareProcessStartInfo.FileName = fullPath;
450455
SoftwareProcessStartInfo.Arguments = GetCommandLineArgumentRange(Software, 1, -1);
451456
SoftwareProcessStartInfo.ErrorDialog = false;
452-
SoftwareProcessStartInfo.WorkingDirectory = Path.GetDirectoryName(Path.GetFullPath(argv[0]));
457+
SoftwareProcessStartInfo.WorkingDirectory = Path.GetDirectoryName(fullPath);
453458

454459
Process process = Process.Start(SoftwareProcessStartInfo);
455460

FlashpointSecurePlayer/Program.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,12 +1127,16 @@ public static string RemoveValueStringSlash(string valueString) {
11271127
return valueString;
11281128
}
11291129

1130-
public static object CanonicalizeValue(object value, string path) {
1130+
public static object LengthenValue(object value, string path) {
11311131
// since it's a value we'll just check it exists
11321132
if (!(value is string valueString)) {
11331133
return value;
11341134
}
11351135

1136+
if (String.IsNullOrEmpty(path)) {
1137+
return value;
1138+
}
1139+
11361140
if (valueString.Length <= MAX_PATH * 2 + 15) {
11371141
// get the short path
11381142
StringBuilder shortPathName = new StringBuilder(MAX_PATH);
@@ -1158,7 +1162,7 @@ public static object CanonicalizeValue(object value, string path) {
11581162
// find path in registry value
11591163
// string must begin with path
11601164
// string cannot exceed MAX_PATH*2+15 characters
1161-
public static object AddVariablesToCanonicalizedValue(object value) {
1165+
public static object AddVariablesToLengthenedValue(object value) {
11621166
// since it's a value we'll just check it exists
11631167
if (!(value is string valueString)) {
11641168
return value;
@@ -1188,7 +1192,7 @@ public static object AddVariablesToCanonicalizedValue(object value) {
11881192
return valueString;
11891193
}
11901194

1191-
public static object RemoveVariablesFromCanonicalizedValue(object value) {
1195+
public static object RemoveVariablesFromLengthenedValue(object value) {
11921196
// TODO: multistrings?
11931197
if (!(value is string valueString)) {
11941198
return value;

FlashpointSecurePlayer/RegistryBackups.cs

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,17 @@ public async Task StopImportAsync() {
797797
string keyDeleted = null;
798798
string keyName = null;
799799
object value = null;
800+
string fullPath = null;
801+
802+
try {
803+
fullPath = Path.GetFullPath(Name);
804+
} catch (PathTooLongException) {
805+
throw new ArgumentException();
806+
} catch (SecurityException) {
807+
throw new TaskRequiresElevationException();
808+
} catch (NotSupportedException) {
809+
throw new ArgumentException();
810+
}
800811

801812
RegistryView registryView = RegistryView.Registry32;
802813

@@ -836,7 +847,7 @@ public async Task StopImportAsync() {
836847
break;
837848
case TYPE.VALUE:
838849
try {
839-
value = AddVariablesToCanonicalizedValue(CanonicalizeValue(GetValueInRegistryView(keyName, registryBackupElement.ValueName, registryView), RemoveTrailingSlash(Application.StartupPath) + "\\" + Name));
850+
value = AddVariablesToLengthenedValue(LengthenValue(GetValueInRegistryView(keyName, registryBackupElement.ValueName, registryView), fullPath));
840851
} catch (ArgumentException) {
841852
// value doesn't exist
842853
value = null;
@@ -899,7 +910,7 @@ public async Task StopImportAsync() {
899910
break;
900911
case TYPE.VALUE:
901912
try {
902-
SetValueInRegistryView(keyName, registryBackupElement.ValueName, RemoveVariablesFromCanonicalizedValue(registryBackupElement.Value), registryBackupElement.ValueKind.GetValueOrDefault(), registryView);
913+
SetValueInRegistryView(keyName, registryBackupElement.ValueName, RemoveVariablesFromLengthenedValue(registryBackupElement.Value), registryBackupElement.ValueKind.GetValueOrDefault(), registryView);
903914
} catch (InvalidOperationException) {
904915
// value marked for deletion
905916
Deactivate();
@@ -999,7 +1010,7 @@ public async Task StopImportAsync() {
9991010
if (value == null) {
10001011
clear = true;
10011012
} else {
1002-
if (value.ToString() != RemoveVariablesFromCanonicalizedValue(registryBackupElement.Value).ToString()) {
1013+
if (value.ToString() != RemoveVariablesFromLengthenedValue(registryBackupElement.Value).ToString()) {
10031014
clear = true;
10041015
}
10051016
}
@@ -1042,7 +1053,7 @@ public async Task StopImportAsync() {
10421053
if (String.IsNullOrEmpty(activeRegistryBackupElement._Deleted)) {
10431054
try {
10441055
// value was different before
1045-
SetValueInRegistryView(GetUserKeyValueName(activeRegistryBackupElement.KeyName), activeRegistryBackupElement.ValueName, RemoveVariablesFromCanonicalizedValue(activeRegistryBackupElement.Value), activeRegistryBackupElement.ValueKind.GetValueOrDefault(), registryView);
1056+
SetValueInRegistryView(GetUserKeyValueName(activeRegistryBackupElement.KeyName), activeRegistryBackupElement.ValueName, RemoveVariablesFromLengthenedValue(activeRegistryBackupElement.Value), activeRegistryBackupElement.ValueKind.GetValueOrDefault(), registryView);
10461057
} catch (InvalidOperationException) {
10471058
// value doesn't exist and can't be created
10481059
throw new RegistryBackupFailedException();
@@ -1125,6 +1136,14 @@ private void ModificationAdded(RegistryTraceData registryTraceData) {
11251136

11261137
ulong safeKeyHandle = registryTraceData.KeyHandle & 0x00000000FFFFFFFF;
11271138
object value = null;
1139+
string fullPath = null;
1140+
1141+
try {
1142+
fullPath = Path.GetFullPath(Name);
1143+
}
1144+
catch (PathTooLongException) { }
1145+
catch (SecurityException) { }
1146+
catch (NotSupportedException) { }
11281147

11291148
RegistryView registryView = RegistryView.Registry32;
11301149

@@ -1138,9 +1157,9 @@ private void ModificationAdded(RegistryTraceData registryTraceData) {
11381157

11391158
registryBackupElement.ValueKind = GetValueKindInRegistryView(registryBackupElement.KeyName, registryBackupElement.ValueName, registryView);
11401159
value = null;
1141-
1160+
11421161
try {
1143-
value = AddVariablesToCanonicalizedValue(CanonicalizeValue(GetValueInRegistryView(registryBackupElement.KeyName, registryBackupElement.ValueName, registryView), RemoveTrailingSlash(Application.StartupPath) + "\\" + Name));
1162+
value = AddVariablesToLengthenedValue(LengthenValue(GetValueInRegistryView(registryBackupElement.KeyName, registryBackupElement.ValueName, registryView), fullPath));
11441163
} catch (ArgumentException) {
11451164
// value doesn't exist
11461165
value = null;
@@ -1180,7 +1199,7 @@ private void ModificationAdded(RegistryTraceData registryTraceData) {
11801199
value = null;
11811200

11821201
try {
1183-
value = AddVariablesToCanonicalizedValue(CanonicalizeValue(GetValueInRegistryView(registryBackupElement.KeyName, registryBackupElement.ValueName, registryView), RemoveTrailingSlash(Application.StartupPath) + "\\" + Name));
1202+
value = AddVariablesToLengthenedValue(LengthenValue(GetValueInRegistryView(registryBackupElement.KeyName, registryBackupElement.ValueName, registryView), fullPath));
11841203
} catch (ArgumentException) {
11851204
} catch (SecurityException) {
11861205
// we have permission to access the key at this point so this must not be important
@@ -1326,6 +1345,14 @@ private void KCBStopped(RegistryTraceData registryTraceData) {
13261345
KeyValuePair<DateTime, RegistryBackupElement> queuedModification;
13271346
RegistryBackupElement registryBackupElement;
13281347
object value = null;
1348+
string fullPath = null;
1349+
1350+
try {
1351+
fullPath = Path.GetFullPath(Name);
1352+
}
1353+
catch (PathTooLongException) { }
1354+
catch (SecurityException) { }
1355+
catch (NotSupportedException) { }
13291356

13301357
RegistryView registryView = RegistryView.Registry32;
13311358

@@ -1348,7 +1375,7 @@ private void KCBStopped(RegistryTraceData registryTraceData) {
13481375

13491376
// value
13501377
try {
1351-
value = AddVariablesToCanonicalizedValue(CanonicalizeValue(GetValueInRegistryView(registryBackupElement.KeyName, registryBackupElement.ValueName, registryView), RemoveTrailingSlash(Application.StartupPath) + "\\" + Name));
1378+
value = AddVariablesToLengthenedValue(LengthenValue(GetValueInRegistryView(registryBackupElement.KeyName, registryBackupElement.ValueName, registryView), fullPath));
13521379
} catch (ArgumentException) {
13531380
// value doesn't exist
13541381
value = null;

0 commit comments

Comments
 (0)