Skip to content

Commit 0e15536

Browse files
committed
better fix for registry hang
1 parent bb9ede8 commit 0e15536

1 file changed

Lines changed: 42 additions & 45 deletions

File tree

FlashpointSecurePlayer/RegistryStates.cs

Lines changed: 42 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ private bool CompareValues(object value, RegistryView registryView, RegistryStat
707707

708708
if (activeRegistryStateElement != null) {
709709
// if value existed before
710-
if (!String.IsNullOrEmpty(activeRegistryStateElement._Deleted)) {
710+
if (activeRegistryStateElement.Value != null) {
711711
// value kind before also matters
712712
if (valueKind == activeRegistryStateElement.ValueKind) {
713713
// get value before
@@ -1042,7 +1042,7 @@ public override void Activate(string templateName) {
10421042
try {
10431043
valueExpanded = Environment.ExpandEnvironmentVariables(registryStateElement.Value);
10441044

1045-
if (valueExpanded != registryStateElement.Value) {
1045+
if (!valueExpanded.Equals(registryStateElement.Value, StringComparison.Ordinal)) {
10461046
activeRegistryStateElement._ValueExpanded = valueExpanded;
10471047
}
10481048
} catch {
@@ -1076,22 +1076,20 @@ public override void Activate(string templateName) {
10761076
LogExceptionToLauncher(ex);
10771077
throw new TaskRequiresElevationException("Accessing the key \"" + keyName + "\" requires elevation.");
10781078
}
1079-
1080-
if (String.IsNullOrEmpty(keyDeleted)) {
1081-
// we create a value
1082-
// the value does not exist
1083-
activeRegistryStateElement.Type = TYPE.VALUE;
1084-
activeRegistryStateElement._Deleted = registryStateElement.ValueName;
1085-
} else {
1086-
// we create a value
1087-
// the value, and the key it belonged to, does not exist
1088-
activeRegistryStateElement.Type = TYPE.KEY;
1089-
activeRegistryStateElement._Deleted = keyDeleted;
1090-
}
10911079
} else {
1092-
// we edit a value that exists
1080+
keyDeleted = null;
1081+
}
1082+
1083+
if (String.IsNullOrEmpty(keyDeleted)) {
1084+
// we create a value
1085+
// the value does not exist
10931086
activeRegistryStateElement.Type = TYPE.VALUE;
10941087
activeRegistryStateElement.Value = value;
1088+
} else {
1089+
// we create a value
1090+
// the value, and the key it belonged to, does not exist
1091+
activeRegistryStateElement.Type = TYPE.KEY;
1092+
activeRegistryStateElement._Deleted = keyDeleted;
10951093
}
10961094
}
10971095

@@ -1300,11 +1298,11 @@ public void Deactivate(MODIFICATIONS_REVERT_METHOD modificationsRevertMethod) {
13001298
// value doesn't exist
13011299
value = null;
13021300
}
1303-
1301+
13041302
if ((activeRegistryStateElement.Type == TYPE.KEY
13051303
&& registryStateElement.Type == TYPE.VALUE)
13061304
|| (activeRegistryStateElement.Type == TYPE.VALUE
1307-
&& !String.IsNullOrEmpty(activeRegistryStateElement._Deleted))) {
1305+
&& activeRegistryStateElement.Value == null)) {
13081306
// we previously created a value
13091307
// the value, (and potentially the key it belonged to) did not exist before
13101308
// the value may or may not exist now
@@ -1323,7 +1321,7 @@ public void Deactivate(MODIFICATIONS_REVERT_METHOD modificationsRevertMethod) {
13231321
}
13241322
}
13251323
} else if (activeRegistryStateElement.Type == TYPE.VALUE
1326-
&& String.IsNullOrEmpty(activeRegistryStateElement._Deleted)) {
1324+
&& activeRegistryStateElement.Value != null) {
13271325
// we previously edited a value that existed before
13281326
// we need to check it still exists in one of the two valid states
13291327
if (value == null) {
@@ -1399,9 +1397,32 @@ public void Deactivate(MODIFICATIONS_REVERT_METHOD modificationsRevertMethod) {
13991397
}
14001398
break;
14011399
case TYPE.VALUE:
1402-
if (String.IsNullOrEmpty(activeRegistryStateElement._Deleted)
1403-
&& activeRegistryStateElement.Value != null // in case ValueName is also empty
1404-
&& modificationsRevertMethod != MODIFICATIONS_REVERT_METHOD.DELETE_ALL) {
1400+
if (activeRegistryStateElement.Value == null
1401+
|| modificationsRevertMethod == MODIFICATIONS_REVERT_METHOD.DELETE_ALL) {
1402+
try {
1403+
// value didn't exist before
1404+
DeleteValueInRegistryView(
1405+
GetUserKeyValueName(
1406+
activeRegistryStateElement.KeyName,
1407+
activeCurrentUser,
1408+
activeAdministrator
1409+
),
1410+
1411+
activeRegistryStateElement.ValueName,
1412+
registryView
1413+
);
1414+
} catch (SecurityException ex) {
1415+
// value exists and we can't modify it
1416+
LogExceptionToLauncher(ex);
1417+
throw new TaskRequiresElevationException("Deleting the value \"" + activeRegistryStateElement.ValueName + "\" requires elevation.");
1418+
} catch (UnauthorizedAccessException ex) {
1419+
// value exists and we can't modify it
1420+
LogExceptionToLauncher(ex);
1421+
throw new TaskRequiresElevationException("Deleting the value \"" + activeRegistryStateElement.ValueName + "\" requires elevation.");
1422+
} catch {
1423+
// value doesn't exist
1424+
}
1425+
} else {
14051426
string keyName = GetUserKeyValueName(activeRegistryStateElement.KeyName, activeCurrentUser, activeAdministrator);
14061427

14071428
try {
@@ -1434,30 +1455,6 @@ public void Deactivate(MODIFICATIONS_REVERT_METHOD modificationsRevertMethod) {
14341455
LogExceptionToLauncher(ex);
14351456
throw new InvalidRegistryStateException("The value \"" + activeRegistryStateElement.ValueName + "\" in key \"" + keyName + "\" could not be set.");
14361457
}
1437-
} else {
1438-
try {
1439-
// value didn't exist before
1440-
DeleteValueInRegistryView(
1441-
GetUserKeyValueName(
1442-
activeRegistryStateElement.KeyName,
1443-
activeCurrentUser,
1444-
activeAdministrator
1445-
),
1446-
1447-
activeRegistryStateElement.ValueName,
1448-
registryView
1449-
);
1450-
} catch (SecurityException ex) {
1451-
// value exists and we can't modify it
1452-
LogExceptionToLauncher(ex);
1453-
throw new TaskRequiresElevationException("Deleting the value \"" + activeRegistryStateElement.ValueName + "\" requires elevation.");
1454-
} catch (UnauthorizedAccessException ex) {
1455-
// value exists and we can't modify it
1456-
LogExceptionToLauncher(ex);
1457-
throw new TaskRequiresElevationException("Deleting the value \"" + activeRegistryStateElement.ValueName + "\" requires elevation.");
1458-
} catch {
1459-
// value doesn't exist
1460-
}
14611458
}
14621459
break;
14631460
}

0 commit comments

Comments
 (0)