55 lines
1.8 KiB
C#
55 lines
1.8 KiB
C#
using System.IO;
|
|
using Newtonsoft.Json;
|
|
using RothenburgAR.Common;
|
|
|
|
namespace RothenburgAR.UI
|
|
{
|
|
class SettingsManager : Singleton<SettingsManager>
|
|
{
|
|
public bool? IsInitialized { get; private set; }
|
|
|
|
public class AppSettings
|
|
{
|
|
public string Language { get; set; }
|
|
public FontsizeSetting? Fontsize { get; set; }
|
|
public int? ColorschemeID { get; set; }
|
|
}
|
|
|
|
public AppSettings Settings { get; private set; }
|
|
|
|
public void Start()
|
|
{
|
|
if (File.Exists(PathHelper.SettingsFilePath))
|
|
{
|
|
//load settings file into settings object if existent
|
|
var json = File.ReadAllText(PathHelper.SettingsFilePath);
|
|
Settings = JsonConvert.DeserializeObject<AppSettings>(json);
|
|
|
|
IsInitialized = true;
|
|
|
|
if (Settings.Language != null)
|
|
LanguageManager.Instance.CurrentLanguageKey = Settings.Language;
|
|
|
|
if (Settings.ColorschemeID.HasValue)
|
|
UIColorSchemeManager.Instance.SetUiColorScheme(Settings.ColorschemeID.Value);
|
|
|
|
if (Settings.Fontsize.HasValue)
|
|
FontsizeManager.Instance.CurrentFontsizeSetting = Settings.Fontsize.Value;
|
|
|
|
if (Settings.Language == null || !Settings.ColorschemeID.HasValue || !Settings.Fontsize.HasValue)
|
|
IsInitialized = false;
|
|
}
|
|
else
|
|
{
|
|
Settings = new AppSettings();
|
|
IsInitialized = false;
|
|
}
|
|
}
|
|
|
|
public void PersistSettings()
|
|
{
|
|
var json = JsonConvert.SerializeObject(Settings);
|
|
File.WriteAllText(PathHelper.SettingsFilePath, json);
|
|
}
|
|
}
|
|
} |