File tree Expand file tree Collapse file tree
UniGetUI.PackageEngine.PackageManagerClasses/Packages/Classes
UniGetUI.PackageEngine.Serializable Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11using System . Collections . Concurrent ;
22using System . Runtime . InteropServices ;
33using System . Text . Json ;
4+ using System . Text . Json . Nodes ;
45using UniGetUI . Core . Data ;
56using UniGetUI . Core . Language ;
67using UniGetUI . Core . Logging ;
@@ -221,20 +222,13 @@ public void LoadFromDisk()
221222 try
222223 {
223224 if ( ! optionsFile . Exists )
224- {
225225 return ;
226- }
227-
228- using FileStream inputStream = optionsFile . OpenRead ( ) ;
229- SerializableInstallationOptions_v1 ? options = JsonSerializer . Deserialize < SerializableInstallationOptions_v1 > (
230- inputStream , SerializationHelpers . DefaultOptions ) ;
231-
232- if ( options is null )
233- {
234- throw new InvalidOperationException ( "Deserialized options cannot be null!" ) ;
235- }
236226
237- FromSerializable ( options ) ;
227+ var rawData = File . ReadAllText ( optionsFile . FullName ) ;
228+ JsonNode ? jsonData = JsonNode . Parse ( rawData ) ;
229+ if ( jsonData is null ) return ;
230+ var serializedOptions = SerializableInstallationOptions_v1 . FromJsonString ( jsonData ) ;
231+ FromSerializable ( serializedOptions ) ;
238232 }
239233 catch ( JsonException )
240234 {
Original file line number Diff line number Diff line change 1+ using System . Text . Json . Nodes ;
2+
13namespace UniGetUI . PackageEngine . Serializable
24{
35 public class SerializableInstallationOptions_v1
@@ -29,5 +31,25 @@ public SerializableInstallationOptions_v1 Copy()
2931 SkipMinorUpdates = SkipMinorUpdates ,
3032 } ;
3133 }
34+
35+ public static SerializableInstallationOptions_v1 FromJsonString ( JsonNode data )
36+ {
37+ var options = new SerializableInstallationOptions_v1 ( ) ;
38+ options . SkipHashCheck = data [ nameof ( SkipHashCheck ) ] ? . GetValue < bool > ( ) ?? false ;
39+ options . InteractiveInstallation = data [ nameof ( InteractiveInstallation ) ] ? . GetValue < bool > ( ) ?? false ;
40+ options . RunAsAdministrator = data [ nameof ( RunAsAdministrator ) ] ? . GetValue < bool > ( ) ?? false ;
41+ options . Architecture = data [ nameof ( Architecture ) ] ? . GetValue < string > ( ) ?? "" ;
42+ options . InstallationScope = data [ nameof ( InstallationScope ) ] ? . GetValue < string > ( ) ?? "" ;
43+
44+ options . CustomParameters = new List < string > ( ) ;
45+ foreach ( var element in data [ nameof ( CustomParameters ) ] ? . AsArray ( ) ?? [ ] )
46+ if ( element is not null ) options . CustomParameters . Add ( element . GetValue < string > ( ) ) ;
47+
48+ options . PreRelease = data [ nameof ( PreRelease ) ] ? . GetValue < bool > ( ) ?? false ;
49+ options . CustomInstallLocation = data [ nameof ( CustomInstallLocation ) ] ? . GetValue < string > ( ) ?? "" ;
50+ options . Version = data [ nameof ( Version ) ] ? . GetValue < string > ( ) ?? "" ;
51+ options . SkipMinorUpdates = data [ nameof ( SkipMinorUpdates ) ] ? . GetValue < bool > ( ) ?? false ;
52+ return options ;
53+ }
3254 }
3355}
You can’t perform that action at this time.
0 commit comments