Пример #1
0
        /// <summary>
        /// Save <see cref="NebulaSettings"/> to file
        /// </summary>
        public static async Task SaveSettingsAsync(NebulaSettings settings = null)
        {
            string file = Path.Combine(SettingsDirectory.FullName, SettingsFileName);

            if (File.Exists(file))
            {
                File.Delete(file);
            }
            await using FileStream fs = File.OpenWrite(file);
            await JsonSerializer.SerializeAsync(fs, settings ?? NebulaClient.Settings, new JsonSerializerOptions
            {
                IgnoreNullValues         = true,
                WriteIndented            = true,
                IgnoreReadOnlyProperties = true
            });
        }
Пример #2
0
        /// <summary>
        /// Load Settings from file
        /// </summary>
        /// <returns><see cref="NebulaSettings"/></returns>
        public static NebulaSettings LoadSettings()
        {
            string file = Path.Combine(SettingsDirectory.FullName, SettingsFileName);

            if (!File.Exists(file))
            {
                Task.Run(async() => await SaveSettingsAsync(new NebulaSettings())).Wait();
            }
            NebulaSettings settings = JsonSerializer.Deserialize <NebulaSettings>(File.ReadAllText(Path.Combine(SettingsDirectory.FullName, SettingsFileName)),
                                                                                  new JsonSerializerOptions
            {
                IgnoreNullValues         = true,
                WriteIndented            = true,
                IgnoreReadOnlyProperties = true
            });

            settings.OnSettingsLoaded();
            return(settings);
        }