@@ -6,21 +6,12 @@ namespace UniGetUI.Core.SettingsEngine;
66
77public partial class Settings
88{
9- public static void ExportToJSON ( string path )
9+ public static void ExportToFile_JSON ( string path )
1010 {
11- Dictionary < string , string > settings = [ ] ;
12- foreach ( string entry in Directory . EnumerateFiles ( CoreData . UniGetUIUserConfigurationDirectory ) )
13- {
14- if ( new [ ] { "OperationHistory" , "WinGetAlreadyUpgradedPackages.json" , "TelemetryClientToken" , "CurrentSessionToken" } . Contains ( entry . Split ( "\\ " ) [ ^ 1 ] ) )
15- continue ;
16-
17- settings . Add ( Path . GetFileName ( entry ) , File . ReadAllText ( entry ) ) ;
18- }
19-
20- File . WriteAllText ( path , JsonSerializer . Serialize ( settings , SerializationOptions ) ) ;
11+ File . WriteAllText ( path , ExportToString_JSON ( ) ) ;
2112 }
2213
23- public static void ImportFromJSON ( string path )
14+ public static void ImportFromFile_JSON ( string path )
2415 {
2516 if ( Path . GetDirectoryName ( path ) == CoreData . UniGetUIUserConfigurationDirectory )
2617 {
@@ -29,16 +20,34 @@ public static void ImportFromJSON(string path)
2920 File . Copy ( path , newPath ) ;
3021 path = newPath ;
3122 }
23+ ImportFromString_JSON ( path ) ;
24+ }
25+
26+ public static string ExportToString_JSON ( )
27+ {
28+ Dictionary < string , string > settings = [ ] ;
29+ foreach ( string entry in Directory . EnumerateFiles ( CoreData . UniGetUIUserConfigurationDirectory ) )
30+ {
31+ if ( new [ ] { "OperationHistory" , "WinGetAlreadyUpgradedPackages.json" , "TelemetryClientToken" , "CurrentSessionToken" } . Contains ( Path . GetFileName ( entry ) ) )
32+ continue ;
33+
34+ settings . Add ( Path . GetFileName ( entry ) , File . ReadAllText ( entry ) ) ;
35+ }
36+ return JsonSerializer . Serialize ( settings , SerializationOptions ) ;
37+ }
3238
39+ public static void ImportFromString_JSON ( string jsonContent )
40+ {
3341 ResetSettings ( ) ;
34- Dictionary < string , string > settings = JsonSerializer . Deserialize < Dictionary < string , string > > ( File . ReadAllText ( path ) , SerializationOptions ) ?? [ ] ;
42+ Dictionary < string , string > settings = JsonSerializer . Deserialize < Dictionary < string , string > > ( jsonContent , SerializationOptions ) ?? [ ] ;
3543 foreach ( KeyValuePair < string , string > entry in settings )
3644 {
37- if ( new [ ] { "OperationHistory" , "WinGetAlreadyUpgradedPackages.json" , "TelemetryClientToken" , "CurrentSessionToken" } . Contains ( entry . Key ) )
45+ if ( new [ ] { "OperationHistory" , "WinGetAlreadyUpgradedPackages.json" , "TelemetryClientToken" , "CurrentSessionToken" } . Contains ( entry . Key ) )
3846 continue ;
3947
4048 File . WriteAllText ( Path . Join ( CoreData . UniGetUIUserConfigurationDirectory , entry . Key ) , entry . Value ) ;
4149 }
50+ Logger . Info ( "Settings successfully imported from string content." ) ;
4251 }
4352
4453 public static void ResetSettings ( )
0 commit comments