@@ -1125,9 +1125,9 @@ public override void Activate(string templateName) {
11251125
11261126 // we don't delete existing keys/values, since the program just won't use deleted keys/values
11271127 // therefore, _Deleted is ignored on all but the active registry state
1128- switch ( registryStateElement . Type ) {
1129- case TYPE . KEY :
1130- if ( keyName != null ) {
1128+ if ( keyName != null ) {
1129+ switch ( registryStateElement . Type ) {
1130+ case TYPE . KEY :
11311131 try {
11321132 SetKeyInRegistryView ( keyName , registryView ) ;
11331133 } catch ( SecurityException ex ) {
@@ -1146,45 +1146,45 @@ public override void Activate(string templateName) {
11461146 LogExceptionToLauncher ( ex ) ;
11471147 throw new InvalidRegistryStateException ( "The key \" " + keyName + "\" could not be set." ) ;
11481148 }
1149- }
1150- break ;
1151- case TYPE . VALUE :
1152- value = String . IsNullOrEmpty ( activeRegistryStateElement . _ValueExpanded )
1153- ? registryStateElement . Value
1154- : activeRegistryStateElement . _ValueExpanded ;
1155-
1156- if ( keyName != null && value != null ) {
1157- try {
1158- SetValueInRegistryView (
1159- keyName ,
1160- registryStateElement . ValueName ,
1161- value ,
1162- registryStateElement . ValueKind . GetValueOrDefault ( ) ,
1163- registryView
1164- ) ;
1165- } catch ( SecurityException ex ) {
1166- // value exists and we can't set it
1167- LogExceptionToLauncher ( ex ) ;
1168- throw new TaskRequiresElevationException ( "Setting the value \" " + registryStateElement . ValueName + " \" in key \" " + keyName + " \" requires elevation." ) ;
1169- } catch ( UnauthorizedAccessException ex ) {
1170- // value exists and we can't set it
1171- LogExceptionToLauncher ( ex ) ;
1172- throw new TaskRequiresElevationException ( "Setting the value \" " + registryStateElement . ValueName + " \" in key \" " + keyName + " \" requires elevation." ) ;
1173- } catch ( FormatException ex ) {
1174- // value must be Base64
1175- LogExceptionToLauncher ( ex ) ;
1176- throw new InvalidRegistryStateException ( "The value \" " + registryStateElement . ValueName + " \" in key \" " + keyName + " \" must be Base64." ) ;
1177- } catch ( InvalidOperationException ex ) {
1178- // value marked for deletion
1179- LogExceptionToLauncher ( ex ) ;
1180- throw new InvalidRegistryStateException ( "The value \" " + registryStateElement . ValueName + " \" in key \" " + keyName + " \" is marked for deletion." ) ;
1181- } catch ( Exception ex ) {
1182- // value doesn't exist and can't be created
1183- LogExceptionToLauncher ( ex ) ;
1184- throw new InvalidRegistryStateException ( "The value \" " + registryStateElement . ValueName + " \" in key \" " + keyName + " \" could not be set." ) ;
1149+ break ;
1150+ case TYPE . VALUE :
1151+ value = String . IsNullOrEmpty ( activeRegistryStateElement . _ValueExpanded )
1152+ ? registryStateElement . Value
1153+ : activeRegistryStateElement . _ValueExpanded ;
1154+
1155+ if ( value != null ) {
1156+ try {
1157+ SetValueInRegistryView (
1158+ keyName ,
1159+ registryStateElement . ValueName ,
1160+ value ,
1161+ registryStateElement . ValueKind . GetValueOrDefault ( ) ,
1162+ registryView
1163+ ) ;
1164+ } catch ( SecurityException ex ) {
1165+ // value exists and we can't set it
1166+ LogExceptionToLauncher ( ex ) ;
1167+ throw new TaskRequiresElevationException ( "Setting the value \" " + registryStateElement . ValueName + " \" in key \" " + keyName + " \" requires elevation." ) ;
1168+ } catch ( UnauthorizedAccessException ex ) {
1169+ // value exists and we can't set it
1170+ LogExceptionToLauncher ( ex ) ;
1171+ throw new TaskRequiresElevationException ( "Setting the value \" " + registryStateElement . ValueName + " \" in key \" " + keyName + " \" requires elevation." ) ;
1172+ } catch ( FormatException ex ) {
1173+ // value must be Base64
1174+ LogExceptionToLauncher ( ex ) ;
1175+ throw new InvalidRegistryStateException ( "The value \" " + registryStateElement . ValueName + " \" in key \" " + keyName + " \" must be Base64." ) ;
1176+ } catch ( InvalidOperationException ex ) {
1177+ // value marked for deletion
1178+ LogExceptionToLauncher ( ex ) ;
1179+ throw new InvalidRegistryStateException ( "The value \" " + registryStateElement . ValueName + " \" in key \" " + keyName + " \" is marked for deletion." ) ;
1180+ } catch ( Exception ex ) {
1181+ // value doesn't exist and can't be created
1182+ LogExceptionToLauncher ( ex ) ;
1183+ throw new InvalidRegistryStateException ( "The value \" " + registryStateElement . ValueName + " \" in key \" " + keyName + " \" could not be set." ) ;
1184+ }
11851185 }
1186+ break ;
11861187 }
1187- break ;
11881188 }
11891189
11901190 ProgressManager . CurrentGoal . Steps ++ ;
@@ -1279,6 +1279,7 @@ public void Deactivate(MODIFICATIONS_REVERT_METHOD modificationsRevertMethod) {
12791279 // registryStateElement represents the value the key SHOULD have *right now*
12801280 // but if there was a partial move, it may instead be the active value
12811281 if ( registryStateElement != null ) {
1282+ keyName = null ;
12821283 value = null ;
12831284 clear = false ;
12841285
@@ -1387,20 +1388,19 @@ public void Deactivate(MODIFICATIONS_REVERT_METHOD modificationsRevertMethod) {
13871388 case TYPE . KEY :
13881389 if ( ! String . IsNullOrEmpty ( activeRegistryStateElement . _Deleted )
13891390 || modificationsRevertMethod == MODIFICATIONS_REVERT_METHOD . DELETE_ALL ) {
1390- keyName = String . IsNullOrEmpty ( activeRegistryStateElement . _Deleted )
1391- ? activeRegistryStateElement . KeyName
1392- : activeRegistryStateElement . _Deleted ;
1391+ keyName = GetUserKeyValueName (
1392+ String . IsNullOrEmpty ( activeRegistryStateElement . _Deleted )
1393+ ? activeRegistryStateElement . KeyName
1394+ : activeRegistryStateElement . _Deleted ,
1395+ activeCurrentUser ,
1396+ activeAdministrator
1397+ ) ;
13931398
13941399 if ( keyName != null ) {
13951400 try {
13961401 // key didn't exist before
13971402 DeleteKeyInRegistryView (
1398- GetUserKeyValueName (
1399- keyName ,
1400- activeCurrentUser ,
1401- activeAdministrator
1402- ) ,
1403-
1403+ keyName ,
14041404 registryView
14051405 ) ;
14061406 } catch ( SecurityException ex ) {
@@ -1420,16 +1420,13 @@ public void Deactivate(MODIFICATIONS_REVERT_METHOD modificationsRevertMethod) {
14201420 case TYPE . VALUE :
14211421 if ( activeRegistryStateElement . Value == null
14221422 || modificationsRevertMethod == MODIFICATIONS_REVERT_METHOD . DELETE_ALL ) {
1423- if ( activeRegistryStateElement . KeyName != null ) {
1423+ keyName = GetUserKeyValueName ( activeRegistryStateElement . KeyName , activeCurrentUser , activeAdministrator ) ;
1424+
1425+ if ( keyName != null ) {
14241426 try {
14251427 // value didn't exist before
14261428 DeleteValueInRegistryView (
1427- GetUserKeyValueName (
1428- activeRegistryStateElement . KeyName ,
1429- activeCurrentUser ,
1430- activeAdministrator
1431- ) ,
1432-
1429+ keyName ,
14331430 activeRegistryStateElement . ValueName ,
14341431 registryView
14351432 ) ;
0 commit comments