File tree Expand file tree Collapse file tree
optimizerDuck.Test/Domain/Customize
optimizerDuck/Domain/Customize Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -541,6 +541,54 @@ public void RegistryToggle_GetState_ReturnsFalseWhenKeyAbsentAndNullInOffValues(
541541 Assert . False ( toggle . GetState ( ) ) ;
542542 }
543543
544+ [ Fact ]
545+ public void RegistryToggle_GetState_ReturnsTrueWhenValueAbsentAndDefaultValueIsOn ( )
546+ {
547+ // Windows states only what differs from its own default, so an absent value is the
548+ // declared default, not "off".
549+ var toggle = new RegistryToggle
550+ {
551+ Path = TestKeyPath ,
552+ Name = "MissingDefaultOnTest" ,
553+ OnValues = [ 0 ] ,
554+ OffValues = [ 1 ] ,
555+ DefaultValue = 0 ,
556+ } ;
557+
558+ Assert . True ( toggle . GetState ( ) ) ;
559+ }
560+
561+ [ Fact ]
562+ public void RegistryToggle_GetState_ReturnsFalseWhenValueAbsentAndDefaultValueIsOff ( )
563+ {
564+ var toggle = new RegistryToggle
565+ {
566+ Path = TestKeyPath ,
567+ Name = "MissingDefaultOffTest" ,
568+ OnValues = [ 0 ] ,
569+ OffValues = [ 1 ] ,
570+ DefaultValue = 1 ,
571+ } ;
572+
573+ Assert . False ( toggle . GetState ( ) ) ;
574+ }
575+
576+ [ Fact ]
577+ public void RegistryToggle_GetState_KeyAbsentPrefersNullEntryOverDefaultValue ( )
578+ {
579+ // An explicit null entry already states the absent case, so it wins over the default.
580+ var toggle = new RegistryToggle
581+ {
582+ Path = TestKeyPath ,
583+ Name = "MissingNullWinsTest" ,
584+ OnValues = [ 1 ] ,
585+ OffValues = [ 0 , null ] ,
586+ DefaultValue = 1 ,
587+ } ;
588+
589+ Assert . False ( toggle . GetState ( ) ) ;
590+ }
591+
544592 [ Fact ]
545593 public void RegistryToggle_SetState_WritesFirstValueFromList ( )
546594 {
Original file line number Diff line number Diff line change @@ -43,7 +43,9 @@ public class ShowThisPc : BaseCustomizeSetting
4343 Name = "{20D04FE0-3AEA-1069-A2D8-08002B30309D}" ,
4444 OnValues = [ 0 ] ,
4545 OffValues = [ 1 ] ,
46- DefaultValue = 0 ,
46+ // Windows states only the icons it hides, and it never placed This PC on
47+ // the desktop by default, so an absent value means hidden.
48+ DefaultValue = 1 ,
4749 } ,
4850 ] ;
4951 }
Original file line number Diff line number Diff line change @@ -33,8 +33,9 @@ public class RegistryToggle
3333 public IReadOnlyList < object ? > OffValues { get ; init ; } = [ 0 ] ;
3434
3535 /// <summary>
36- /// Gets the default state value when the key is missing. Used for Reset to Default.
37- /// Default is <c>0</c>.
36+ /// Gets the value that decides the state when the value is absent from the registry.
37+ /// Windows stores only what differs from its own default, so an absent value is the
38+ /// default, not "off". Default is <c>0</c>.
3839 /// </summary>
3940 public object ? DefaultValue { get ; init ; } = 0 ;
4041
@@ -50,10 +51,25 @@ public class RegistryToggle
5051 /// <summary>
5152 /// Reads the registry and returns whether the toggle is currently on. The result is
5253 /// <see langword="true" /> when the value matches any entry in <see cref="OnValues" />.
54+ /// An absent value is classified through <see cref="DefaultValue" />; a
55+ /// <see langword="null" /> entry in either list states the absent case itself and wins
56+ /// over that default.
5357 /// </summary>
5458 public bool GetState ( )
5559 {
5660 var value = GetRawValue ( ) ;
61+
62+ if ( value is null )
63+ {
64+ if ( IsValueInList ( null , OnValues ) )
65+ return true ;
66+
67+ if ( IsValueInList ( null , OffValues ) )
68+ return false ;
69+
70+ value = DefaultValue ;
71+ }
72+
5773 return IsValueInList ( value , OnValues ) ;
5874 }
5975
You can’t perform that action at this time.
0 commit comments