Skip to content

Commit eb0e8a9

Browse files
committed
smarter handling for null key names
1 parent 90d377a commit eb0e8a9

1 file changed

Lines changed: 32 additions & 22 deletions

File tree

FlashpointSecurePlayer/RegistryStates.cs

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,10 @@ private void DeleteValueInRegistryView(string keyName, string valueName, Registr
443443
}
444444

445445
private string TestKeyDeletedInRegistryView(string keyName, RegistryView registryView) {
446+
if (keyName == null) {
447+
return keyName;
448+
}
449+
446450
List<string> keyNames = keyName.Split('\\').ToList();
447451

448452
if (!keyNames.Any()) {
@@ -612,7 +616,9 @@ private bool CompareKeys(RegistryView registryView, RegistryStateElement registr
612616
return true;
613617
}
614618

615-
if (String.IsNullOrEmpty(activeRegistryStateElement._Deleted)) {
619+
// empty = key existed before
620+
// null = key ignored
621+
if (activeRegistryStateElement._Deleted == String.Empty) {
616622
// key did exist before
617623
// that means it should still exist
618624
try {
@@ -1121,34 +1127,38 @@ public override void Activate(string templateName) {
11211127
// therefore, _Deleted is ignored on all but the active registry state
11221128
switch (registryStateElement.Type) {
11231129
case TYPE.KEY:
1124-
try {
1125-
SetKeyInRegistryView(keyName, registryView);
1126-
} catch (SecurityException ex) {
1127-
// key doesn't exist and we can't set it
1128-
LogExceptionToLauncher(ex);
1129-
throw new TaskRequiresElevationException("Setting the key \"" + keyName + "\" requires elevation.");
1130-
} catch (UnauthorizedAccessException ex) {
1131-
// key exists and we can't set it
1132-
LogExceptionToLauncher(ex);
1133-
} catch (InvalidOperationException ex) {
1134-
// key marked for deletion
1135-
LogExceptionToLauncher(ex);
1136-
throw new InvalidRegistryStateException("The key \"" + keyName + "\" is marked for deletion.");
1137-
} catch (Exception ex) {
1138-
// key doesn't exist and can't be created
1139-
LogExceptionToLauncher(ex);
1140-
throw new InvalidRegistryStateException("The key \"" + keyName + "\" could not be set.");
1130+
if (keyName != null) {
1131+
try {
1132+
SetKeyInRegistryView(keyName, registryView);
1133+
} catch (SecurityException ex) {
1134+
// key doesn't exist and we can't set it
1135+
LogExceptionToLauncher(ex);
1136+
throw new TaskRequiresElevationException("Setting the key \"" + keyName + "\" requires elevation.");
1137+
} catch (UnauthorizedAccessException ex) {
1138+
// key exists and we can't set it
1139+
LogExceptionToLauncher(ex);
1140+
} catch (InvalidOperationException ex) {
1141+
// key marked for deletion
1142+
LogExceptionToLauncher(ex);
1143+
throw new InvalidRegistryStateException("The key \"" + keyName + "\" is marked for deletion.");
1144+
} catch (Exception ex) {
1145+
// key doesn't exist and can't be created
1146+
LogExceptionToLauncher(ex);
1147+
throw new InvalidRegistryStateException("The key \"" + keyName + "\" could not be set.");
1148+
}
11411149
}
11421150
break;
11431151
case TYPE.VALUE:
1144-
if (registryStateElement.Value != null) {
1152+
value = String.IsNullOrEmpty(activeRegistryStateElement._ValueExpanded)
1153+
? registryStateElement.Value
1154+
: activeRegistryStateElement._ValueExpanded;
1155+
1156+
if (keyName != null && value != null) {
11451157
try {
11461158
SetValueInRegistryView(
11471159
keyName,
11481160
registryStateElement.ValueName,
1149-
String.IsNullOrEmpty(activeRegistryStateElement._ValueExpanded)
1150-
? registryStateElement.Value
1151-
: activeRegistryStateElement._ValueExpanded,
1161+
value,
11521162
registryStateElement.ValueKind.GetValueOrDefault(),
11531163
registryView
11541164
);

0 commit comments

Comments
 (0)