Skip to content

Commit d598769

Browse files
committed
more checks for crash recovery
1 parent eb0e8a9 commit d598769

1 file changed

Lines changed: 86 additions & 75 deletions

File tree

FlashpointSecurePlayer/RegistryStates.cs

Lines changed: 86 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,6 +1254,7 @@ public void Deactivate(MODIFICATIONS_REVERT_METHOD modificationsRevertMethod) {
12541254
RegistryStateElement activeRegistryStateElement = null;
12551255
string activeCurrentUser = activeModificationsElement.RegistryStates._CurrentUser;
12561256
bool activeAdministrator = activeModificationsElement.RegistryStates._Administrator.GetValueOrDefault();
1257+
string keyName = null;
12571258
string value = null;
12581259
bool clear = false;
12591260

@@ -1296,7 +1297,7 @@ public void Deactivate(MODIFICATIONS_REVERT_METHOD modificationsRevertMethod) {
12961297
clear = true;
12971298
}
12981299
} else {
1299-
string keyName = GetUserKeyValueName(registryStateElement.KeyName, activeCurrentUser, activeAdministrator);
1300+
keyName = GetUserKeyValueName(registryStateElement.KeyName, activeCurrentUser, activeAdministrator);
13001301

13011302
try {
13021303
value = GetValueInRegistryView(keyName, registryStateElement.ValueName, registryView) as string;
@@ -1386,88 +1387,98 @@ public void Deactivate(MODIFICATIONS_REVERT_METHOD modificationsRevertMethod) {
13861387
case TYPE.KEY:
13871388
if (!String.IsNullOrEmpty(activeRegistryStateElement._Deleted)
13881389
|| modificationsRevertMethod == MODIFICATIONS_REVERT_METHOD.DELETE_ALL) {
1389-
try {
1390-
// key didn't exist before
1391-
DeleteKeyInRegistryView(
1392-
GetUserKeyValueName(
1393-
activeRegistryStateElement._Deleted,
1394-
activeCurrentUser,
1395-
activeAdministrator
1396-
),
1397-
1398-
registryView
1399-
);
1400-
} catch (SecurityException ex) {
1401-
// key exists and we can't modify it
1402-
LogExceptionToLauncher(ex);
1403-
throw new TaskRequiresElevationException("Deleting the key \"" + activeRegistryStateElement._Deleted + "\" requires elevation.");
1404-
} catch (UnauthorizedAccessException ex) {
1405-
// key exists and we can't modify it
1406-
LogExceptionToLauncher(ex);
1407-
throw new TaskRequiresElevationException("Deleting the key \"" + activeRegistryStateElement._Deleted + "\" requires elevation.");
1408-
} catch {
1409-
// key doesn't exist
1390+
keyName = String.IsNullOrEmpty(activeRegistryStateElement._Deleted)
1391+
? activeRegistryStateElement.KeyName
1392+
: activeRegistryStateElement._Deleted;
1393+
1394+
if (keyName != null) {
1395+
try {
1396+
// key didn't exist before
1397+
DeleteKeyInRegistryView(
1398+
GetUserKeyValueName(
1399+
keyName,
1400+
activeCurrentUser,
1401+
activeAdministrator
1402+
),
1403+
1404+
registryView
1405+
);
1406+
} catch (SecurityException ex) {
1407+
// key exists and we can't modify it
1408+
LogExceptionToLauncher(ex);
1409+
throw new TaskRequiresElevationException("Deleting the key \"" + activeRegistryStateElement._Deleted + "\" requires elevation.");
1410+
} catch (UnauthorizedAccessException ex) {
1411+
// key exists and we can't modify it
1412+
LogExceptionToLauncher(ex);
1413+
throw new TaskRequiresElevationException("Deleting the key \"" + activeRegistryStateElement._Deleted + "\" requires elevation.");
1414+
} catch {
1415+
// key doesn't exist
1416+
}
14101417
}
14111418
}
14121419
break;
14131420
case TYPE.VALUE:
14141421
if (activeRegistryStateElement.Value == null
14151422
|| modificationsRevertMethod == MODIFICATIONS_REVERT_METHOD.DELETE_ALL) {
1416-
try {
1417-
// value didn't exist before
1418-
DeleteValueInRegistryView(
1419-
GetUserKeyValueName(
1420-
activeRegistryStateElement.KeyName,
1421-
activeCurrentUser,
1422-
activeAdministrator
1423-
),
1424-
1425-
activeRegistryStateElement.ValueName,
1426-
registryView
1427-
);
1428-
} catch (SecurityException ex) {
1429-
// value exists and we can't modify it
1430-
LogExceptionToLauncher(ex);
1431-
throw new TaskRequiresElevationException("Deleting the value \"" + activeRegistryStateElement.ValueName + "\" requires elevation.");
1432-
} catch (UnauthorizedAccessException ex) {
1433-
// value exists and we can't modify it
1434-
LogExceptionToLauncher(ex);
1435-
throw new TaskRequiresElevationException("Deleting the value \"" + activeRegistryStateElement.ValueName + "\" requires elevation.");
1436-
} catch {
1437-
// value doesn't exist
1423+
if (activeRegistryStateElement.KeyName != null) {
1424+
try {
1425+
// value didn't exist before
1426+
DeleteValueInRegistryView(
1427+
GetUserKeyValueName(
1428+
activeRegistryStateElement.KeyName,
1429+
activeCurrentUser,
1430+
activeAdministrator
1431+
),
1432+
1433+
activeRegistryStateElement.ValueName,
1434+
registryView
1435+
);
1436+
} catch (SecurityException ex) {
1437+
// value exists and we can't modify it
1438+
LogExceptionToLauncher(ex);
1439+
throw new TaskRequiresElevationException("Deleting the value \"" + activeRegistryStateElement.ValueName + "\" requires elevation.");
1440+
} catch (UnauthorizedAccessException ex) {
1441+
// value exists and we can't modify it
1442+
LogExceptionToLauncher(ex);
1443+
throw new TaskRequiresElevationException("Deleting the value \"" + activeRegistryStateElement.ValueName + "\" requires elevation.");
1444+
} catch {
1445+
// value doesn't exist
1446+
}
14381447
}
14391448
} else {
1440-
string keyName = GetUserKeyValueName(activeRegistryStateElement.KeyName, activeCurrentUser, activeAdministrator);
1441-
1442-
try {
1443-
// value was different before
1444-
SetValueInRegistryView(
1445-
keyName,
1446-
activeRegistryStateElement.ValueName,
1447-
activeRegistryStateElement.Value,
1448-
activeRegistryStateElement.ValueKind.GetValueOrDefault(),
1449-
registryView
1450-
);
1451-
} catch (SecurityException ex) {
1452-
// value exists and we can't modify it
1453-
LogExceptionToLauncher(ex);
1454-
throw new TaskRequiresElevationException("Setting the value \"" + activeRegistryStateElement.ValueName + "\" in key \"" + keyName + "\" requires elevation.");
1455-
} catch (UnauthorizedAccessException ex) {
1456-
// value exists and we can't modify it
1457-
LogExceptionToLauncher(ex);
1458-
throw new TaskRequiresElevationException("Setting the value \"" + activeRegistryStateElement.ValueName + "\" in key \"" + keyName + "\" requires elevation.");
1459-
} catch (FormatException ex) {
1460-
// value must be Base64
1461-
LogExceptionToLauncher(ex);
1462-
throw new InvalidRegistryStateException("The value \"" + activeRegistryStateElement.ValueName + "\" in key \"" + keyName + "\" must be Base64.");
1463-
} catch (InvalidOperationException ex) {
1464-
// value marked for deletion
1465-
LogExceptionToLauncher(ex);
1466-
throw new InvalidRegistryStateException("The value \"" + activeRegistryStateElement.ValueName + "\" in key \"" + keyName + "\" is marked for deletion.");
1467-
} catch (Exception ex) {
1468-
// value doesn't exist and can't be created
1469-
LogExceptionToLauncher(ex);
1470-
throw new InvalidRegistryStateException("The value \"" + activeRegistryStateElement.ValueName + "\" in key \"" + keyName + "\" could not be set.");
1449+
keyName = GetUserKeyValueName(activeRegistryStateElement.KeyName, activeCurrentUser, activeAdministrator);
1450+
1451+
if (keyName != null) {
1452+
try {
1453+
// value was different before
1454+
SetValueInRegistryView(
1455+
keyName,
1456+
activeRegistryStateElement.ValueName,
1457+
activeRegistryStateElement.Value,
1458+
activeRegistryStateElement.ValueKind.GetValueOrDefault(),
1459+
registryView
1460+
);
1461+
} catch (SecurityException ex) {
1462+
// value exists and we can't modify it
1463+
LogExceptionToLauncher(ex);
1464+
throw new TaskRequiresElevationException("Setting the value \"" + activeRegistryStateElement.ValueName + "\" in key \"" + keyName + "\" requires elevation.");
1465+
} catch (UnauthorizedAccessException ex) {
1466+
// value exists and we can't modify it
1467+
LogExceptionToLauncher(ex);
1468+
throw new TaskRequiresElevationException("Setting the value \"" + activeRegistryStateElement.ValueName + "\" in key \"" + keyName + "\" requires elevation.");
1469+
} catch (FormatException ex) {
1470+
// value must be Base64
1471+
LogExceptionToLauncher(ex);
1472+
throw new InvalidRegistryStateException("The value \"" + activeRegistryStateElement.ValueName + "\" in key \"" + keyName + "\" must be Base64.");
1473+
} catch (InvalidOperationException ex) {
1474+
// value marked for deletion
1475+
LogExceptionToLauncher(ex);
1476+
throw new InvalidRegistryStateException("The value \"" + activeRegistryStateElement.ValueName + "\" in key \"" + keyName + "\" is marked for deletion.");
1477+
} catch (Exception ex) {
1478+
// value doesn't exist and can't be created
1479+
LogExceptionToLauncher(ex);
1480+
throw new InvalidRegistryStateException("The value \"" + activeRegistryStateElement.ValueName + "\" in key \"" + keyName + "\" could not be set.");
1481+
}
14711482
}
14721483
}
14731484
break;

0 commit comments

Comments
 (0)