diff --git a/Wabbajack.Common/Consts.cs b/Wabbajack.Common/Consts.cs index 07fa6143..085f16a4 100644 --- a/Wabbajack.Common/Consts.cs +++ b/Wabbajack.Common/Consts.cs @@ -106,5 +106,8 @@ namespace Wabbajack.Common public static string LogsFolder = "logs"; public static int MaxOldLogs = 50; + + public static string SettingsFile => Path.Combine(LocalAppDataPath, "settings.json"); + public static byte SettingsVersion => 1; } } diff --git a/Wabbajack/Settings.cs b/Wabbajack/Settings.cs index 66b42622..b2a20ce2 100644 --- a/Wabbajack/Settings.cs +++ b/Wabbajack/Settings.cs @@ -1,10 +1,8 @@ using Newtonsoft.Json; -using ReactiveUI.Fody.Helpers; using System; using System.Collections.Generic; using System.IO; using System.Reactive; -using System.Reactive.Disposables; using System.Reactive.Subjects; using Wabbajack.Common; using Wabbajack.Lib; @@ -14,7 +12,7 @@ namespace Wabbajack [JsonObject(MemberSerialization.OptOut)] public class MainSettings { - private static string _filename = "settings.json"; + public byte Version { get; set; } public double PosX { get; set; } public double PosY { get; set; } @@ -30,13 +28,26 @@ namespace Wabbajack public static bool TryLoadTypicalSettings(out MainSettings settings) { - if (!File.Exists(_filename)) + if (!File.Exists(Consts.SettingsFile)) { settings = default; return false; } - settings = JsonConvert.DeserializeObject(File.ReadAllText(_filename)); - return true; + + // Version check + settings = JsonConvert.DeserializeObject(File.ReadAllText(Consts.SettingsFile)); + if (settings.Version == Consts.SettingsVersion) + return true; + + var backup = Consts.SettingsFile + "-backup.json"; + if(File.Exists(backup)) + File.Delete(backup); + + File.Copy(Consts.SettingsFile, backup); + File.Delete(Consts.SettingsFile); + + settings = default; + return false; } public static void SaveSettings(MainSettings settings) @@ -48,7 +59,7 @@ namespace Wabbajack //settings._saveSignal.OnCompleted(); //await settings._saveSignal; - File.WriteAllText(_filename, JsonConvert.SerializeObject(settings, Formatting.Indented)); + File.WriteAllText(Consts.SettingsFile, JsonConvert.SerializeObject(settings, Formatting.Indented)); } } @@ -76,14 +87,14 @@ namespace Wabbajack [JsonObject(MemberSerialization.OptOut)] public class PerformanceSettings : ViewModel { - private bool _Manual = false; - public bool Manual { get => _Manual; set => this.RaiseAndSetIfChanged(ref _Manual, value); } + private bool _manual; + public bool Manual { get => _manual; set => RaiseAndSetIfChanged(ref _manual, value); } - private byte _MaxCores = byte.MaxValue; - public byte MaxCores { get => _MaxCores; set => this.RaiseAndSetIfChanged(ref _MaxCores, value); } + private byte _maxCores = byte.MaxValue; + public byte MaxCores { get => _maxCores; set => RaiseAndSetIfChanged(ref _maxCores, value); } - private Percent _TargetUsage = Percent.One; - public Percent TargetUsage { get => _TargetUsage; set => this.RaiseAndSetIfChanged(ref _TargetUsage, value); } + private Percent _targetUsage = Percent.One; + public Percent TargetUsage { get => _targetUsage; set => RaiseAndSetIfChanged(ref _targetUsage, value); } public void AttachToBatchProcessor(ABatchProcessor processor) { diff --git a/Wabbajack/Views/MainWindow.xaml.cs b/Wabbajack/Views/MainWindow.xaml.cs index da5f95db..ebfb03f8 100644 --- a/Wabbajack/Views/MainWindow.xaml.cs +++ b/Wabbajack/Views/MainWindow.xaml.cs @@ -59,7 +59,10 @@ namespace Wabbajack }; if (CLIArguments.NoSettings || !MainSettings.TryLoadTypicalSettings(out var settings)) { - _settings = new MainSettings(); + _settings = new MainSettings + { + Version = Consts.SettingsVersion + }; RunWhenLoaded(DefaultSettings); } else