bloxstrap/Bloxstrap/Settings.cs
pizzaboxer bacb650ddc Features and bugfixes for v1.1.0
- Features
    - Add Discord Rich Presence support (the nuget package is like a year and a half out of date so submodule it is lol)
    - Add update checker
    - Add start menu folder creation

- Bugfixes
   - Fix "Directory is not empty" error when updating Roblox
   - Fix uninstalling sometimes not working properly

- Quality of Life
   - Split Bootstrapper class into partial files
   - Renamed TaskDialogStyle to VistaDialog for name simplification
2022-08-11 08:26:28 +01:00

71 lines
2.0 KiB
C#

using System.Diagnostics;
using System.Text.Json;
using Bloxstrap.Enums;
namespace Bloxstrap
{
public class SettingsFormat
{
public string VersionGuid { get; set; }
public BootstrapperStyle BootstrapperStyle { get; set; } = BootstrapperStyle.ProgressDialog;
public BootstrapperIcon BootstrapperIcon { get; set; } = BootstrapperIcon.IconBloxstrap;
public bool UseDiscordRichPresence { get; set; } = true;
public bool UseOldDeathSound { get; set; } = true;
}
public class SettingsManager
{
public SettingsFormat Settings = new();
public bool ShouldSave = false;
private string _saveLocation;
public string SaveLocation
{
get => _saveLocation;
set
{
if (!String.IsNullOrEmpty(_saveLocation))
return;
_saveLocation = value;
string settingsJson = "";
if (File.Exists(_saveLocation))
settingsJson = File.ReadAllText(_saveLocation);
Debug.WriteLine(settingsJson);
try
{
Settings = JsonSerializer.Deserialize<SettingsFormat>(settingsJson);
}
catch (Exception ex)
{
Debug.WriteLine($"Failed to fetch settings! Reverting to defaults... ({ex.Message})");
// Settings = new();
}
}
}
public void Save()
{
Debug.WriteLine("Attempting to save...");
string SettingsJson = JsonSerializer.Serialize(Settings, new JsonSerializerOptions { WriteIndented = true });
Debug.WriteLine(SettingsJson);
if (!ShouldSave)
{
Debug.WriteLine("ShouldSave set to false, not saving...");
return;
}
// save settings
File.WriteAllText(SaveLocation, SettingsJson);
}
}
}