@@ -6,7 +6,7 @@ namespace UniGetUI.PackageEngine.Serializable
66{
77 public class InstallOptions : SerializableComponent < InstallOptions >
88 {
9- private readonly IReadOnlyDictionary < string , bool > DefaultBoolValues = new Dictionary < string , bool > ( )
9+ public readonly IReadOnlyDictionary < string , bool > _defaultBoolValues = new Dictionary < string , bool > ( )
1010 { // OverridesNextLevelOpts is deliberately skipped here
1111 { "SkipHashCheck" , false } ,
1212 { "InteractiveInstallation" , false } ,
@@ -20,7 +20,7 @@ public class InstallOptions: SerializableComponent<InstallOptions>
2020 { "AbortOnPreUninstallFail" , true } ,
2121 } ;
2222
23- private readonly IReadOnlyDictionary < string , string > DefaultStringValues = new Dictionary < string , string > ( )
23+ public readonly IReadOnlyDictionary < string , string > _defaultStringValues = new Dictionary < string , string > ( )
2424 {
2525 { "Architecture" , "" } ,
2626 { "InstallationScope" , "" } ,
@@ -34,7 +34,7 @@ public class InstallOptions: SerializableComponent<InstallOptions>
3434 { "PostUninstallCommand" , "" } ,
3535 } ;
3636
37- private readonly IReadOnlyList < string > DefaultListValues = new List < string > ( )
37+ public readonly IReadOnlyList < string > _defaultListValues = new List < string > ( )
3838 {
3939 "CustomParameters_Install" ,
4040 "CustomParameters_Update" ,
@@ -75,13 +75,13 @@ public override InstallOptions Copy()
7575 {
7676 var copy = new InstallOptions ( ) ;
7777
78- foreach ( var ( boolKey , _) in DefaultBoolValues )
78+ foreach ( var ( boolKey , _) in _defaultBoolValues )
7979 copy . SetValueToProperty ( boolKey , GetValueFromProperty < bool > ( boolKey ) ) ;
8080
81- foreach ( var ( stringKey , _) in DefaultStringValues )
81+ foreach ( var ( stringKey , _) in _defaultStringValues )
8282 copy . SetValueToProperty ( stringKey , GetValueFromProperty < string > ( stringKey ) ) ;
8383
84- foreach ( var listKey in DefaultListValues )
84+ foreach ( var listKey in _defaultListValues )
8585 copy . SetValueToProperty ( listKey , GetValueFromProperty < IReadOnlyList < string > > ( listKey ) . ToList ( ) ) ;
8686
8787 // Handle non-automated OverridesNextLevelOpts
@@ -103,17 +103,13 @@ public T GetValueFromProperty<T>(string name)
103103
104104 public override void LoadFromJson ( JsonNode data )
105105 {
106- foreach ( var ( boolKey , defValue ) in DefaultBoolValues )
107- {
108- // RemoveDataOnUninstall should not be loaded from disk
109- if ( boolKey == "RemoveDataOnUninstall" ) continue ;
106+ foreach ( var ( boolKey , defValue ) in _defaultBoolValues )
110107 SetValueToProperty ( boolKey , data [ boolKey ] ? . GetVal < bool > ( ) ?? defValue ) ;
111- }
112108
113- foreach ( var ( stringKey , defValue ) in DefaultStringValues )
109+ foreach ( var ( stringKey , defValue ) in _defaultStringValues )
114110 SetValueToProperty ( stringKey , data [ stringKey ] ? . GetVal < string > ( ) ?? defValue ) ;
115111
116- foreach ( var listKey in DefaultListValues )
112+ foreach ( var listKey in _defaultListValues )
117113 SetValueToProperty ( listKey , ReadArrayFromJson ( data , listKey ) ) ;
118114
119115 // Handle case where setting has not been migrated yet
@@ -137,22 +133,22 @@ public override JsonNode AsJsonNode()
137133 {
138134 JsonObject obj = new ( ) ;
139135
140- if ( OverridesNextLevelOpts is not false )
136+ if ( OverridesNextLevelOpts is not false || DiffersFromDefault ( ) )
141137 obj . Add ( nameof ( OverridesNextLevelOpts ) , OverridesNextLevelOpts ) ;
142138
143- foreach ( var ( boolKey , defValue ) in DefaultBoolValues )
139+ foreach ( var ( boolKey , defValue ) in _defaultBoolValues )
144140 {
145141 bool currentValue = GetValueFromProperty < bool > ( boolKey ) ;
146142 if ( currentValue != defValue ) obj . Add ( boolKey , currentValue ) ;
147143 }
148144
149- foreach ( var ( stringKey , defValue ) in DefaultStringValues )
145+ foreach ( var ( stringKey , defValue ) in _defaultStringValues )
150146 {
151147 string currentValue = GetValueFromProperty < string > ( stringKey ) ;
152148 if ( currentValue != defValue ) obj . Add ( stringKey , currentValue ) ;
153149 }
154150
155- foreach ( var listKey in DefaultListValues )
151+ foreach ( var listKey in _defaultListValues )
156152 {
157153 IReadOnlyList < string > currentValue = GetValueFromProperty < IReadOnlyList < string > > ( listKey ) ;
158154
@@ -176,13 +172,13 @@ private static List<string> ReadArrayFromJson(JsonNode data, string name)
176172
177173 public bool DiffersFromDefault ( )
178174 {
179- foreach ( var ( boolKey , defValue ) in DefaultBoolValues )
175+ foreach ( var ( boolKey , defValue ) in _defaultBoolValues )
180176 if ( GetValueFromProperty < bool > ( boolKey ) != defValue ) return true ;
181177
182- foreach ( var ( stringKey , defValue ) in DefaultStringValues )
178+ foreach ( var ( stringKey , defValue ) in _defaultStringValues )
183179 if ( GetValueFromProperty < string > ( stringKey ) != defValue ) return true ;
184180
185- foreach ( var listKey in DefaultListValues )
181+ foreach ( var listKey in _defaultListValues )
186182 {
187183 IReadOnlyList < string > currentValue = GetValueFromProperty < IReadOnlyList < string > > ( listKey ) ;
188184 if ( currentValue . Where ( x => x . Any ( ) ) . Any ( ) ) return true ;
0 commit comments