2020-04-01 19:14:21 +00:00
|
|
|
|
using Newtonsoft.Json;
|
2019-11-06 03:22:38 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Reactive;
|
|
|
|
|
using System.Reactive.Subjects;
|
2020-05-25 17:34:25 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2019-11-14 05:28:27 +00:00
|
|
|
|
using Wabbajack.Common;
|
2020-04-23 04:02:50 +00:00
|
|
|
|
using Wabbajack.Common.Serialization.Json;
|
2020-01-05 03:09:02 +00:00
|
|
|
|
using Wabbajack.Lib;
|
2019-11-06 03:22:38 +00:00
|
|
|
|
|
|
|
|
|
namespace Wabbajack
|
|
|
|
|
{
|
2020-04-23 04:02:50 +00:00
|
|
|
|
[JsonName("MainSettings")]
|
2019-11-06 03:22:38 +00:00
|
|
|
|
[JsonObject(MemberSerialization.OptOut)]
|
2020-01-06 04:49:11 +00:00
|
|
|
|
public class MainSettings
|
2019-11-06 03:22:38 +00:00
|
|
|
|
{
|
2020-04-23 04:02:50 +00:00
|
|
|
|
public byte Version { get; set; } = Consts.SettingsVersion;
|
2020-03-04 11:21:44 +00:00
|
|
|
|
|
2019-11-06 03:22:38 +00:00
|
|
|
|
public double PosX { get; set; }
|
|
|
|
|
public double PosY { get; set; }
|
|
|
|
|
public double Height { get; set; }
|
|
|
|
|
public double Width { get; set; }
|
2019-11-14 05:28:27 +00:00
|
|
|
|
public InstallerSettings Installer { get; set; } = new InstallerSettings();
|
2020-05-10 04:35:39 +00:00
|
|
|
|
public FiltersSettings Filters { get; set; } = new FiltersSettings();
|
2019-11-14 05:28:27 +00:00
|
|
|
|
public CompilerSettings Compiler { get; set; } = new CompilerSettings();
|
2020-01-06 04:49:11 +00:00
|
|
|
|
public PerformanceSettings Performance { get; set; } = new PerformanceSettings();
|
2019-11-06 03:22:38 +00:00
|
|
|
|
|
|
|
|
|
private Subject<Unit> _saveSignal = new Subject<Unit>();
|
2020-01-05 03:09:02 +00:00
|
|
|
|
[JsonIgnore]
|
2019-11-06 03:22:38 +00:00
|
|
|
|
public IObservable<Unit> SaveSignal => _saveSignal;
|
|
|
|
|
|
2020-05-25 17:34:25 +00:00
|
|
|
|
public static async ValueTask<(MainSettings settings, bool loaded)> TryLoadTypicalSettings()
|
2019-11-06 03:22:38 +00:00
|
|
|
|
{
|
2020-03-28 20:04:22 +00:00
|
|
|
|
if (!Consts.SettingsFile.Exists)
|
2019-12-01 22:20:26 +00:00
|
|
|
|
{
|
2020-05-25 17:34:25 +00:00
|
|
|
|
return default;
|
2019-12-01 22:20:26 +00:00
|
|
|
|
}
|
2020-03-04 10:56:35 +00:00
|
|
|
|
|
2020-03-04 11:21:44 +00:00
|
|
|
|
// Version check
|
2020-04-01 19:14:21 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
2020-05-25 17:34:25 +00:00
|
|
|
|
var settings = Consts.SettingsFile.FromJson<MainSettings>();
|
2020-04-01 19:14:21 +00:00
|
|
|
|
if (settings.Version == Consts.SettingsVersion)
|
2020-05-25 17:34:25 +00:00
|
|
|
|
return (settings, true);
|
2020-04-01 19:14:21 +00:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Utils.Error(ex, "Error loading settings");
|
|
|
|
|
}
|
2020-03-04 11:21:44 +00:00
|
|
|
|
|
2020-04-01 19:12:02 +00:00
|
|
|
|
var backup = Consts.SettingsFile.AppendToName("-backup");
|
2020-03-28 20:04:22 +00:00
|
|
|
|
backup.Delete();
|
2020-03-04 11:21:44 +00:00
|
|
|
|
|
2020-05-25 17:34:25 +00:00
|
|
|
|
await Consts.SettingsFile.CopyToAsync(backup);
|
2020-03-28 20:04:22 +00:00
|
|
|
|
Consts.SettingsFile.Delete();
|
2020-03-04 11:21:44 +00:00
|
|
|
|
|
2020-05-25 17:34:25 +00:00
|
|
|
|
return default;
|
2019-11-06 03:22:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-25 17:34:25 +00:00
|
|
|
|
public static async ValueTask SaveSettings(MainSettings settings)
|
2019-11-06 03:22:38 +00:00
|
|
|
|
{
|
|
|
|
|
settings._saveSignal.OnNext(Unit.Default);
|
|
|
|
|
|
|
|
|
|
// Might add this if people are putting save work on other threads or other
|
|
|
|
|
// things that delay the operation.
|
|
|
|
|
//settings._saveSignal.OnCompleted();
|
|
|
|
|
//await settings._saveSignal;
|
|
|
|
|
|
2020-05-25 17:34:25 +00:00
|
|
|
|
await settings.ToJsonAsync(Consts.SettingsFile);
|
2019-11-06 03:22:38 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-23 04:02:50 +00:00
|
|
|
|
[JsonName("InstallerSettings")]
|
2019-11-14 05:28:27 +00:00
|
|
|
|
public class InstallerSettings
|
|
|
|
|
{
|
2020-03-28 20:04:22 +00:00
|
|
|
|
public AbsolutePath LastInstalledListLocation { get; set; }
|
|
|
|
|
public Dictionary<AbsolutePath, Mo2ModlistInstallationSettings> Mo2ModlistSettings { get; } = new Dictionary<AbsolutePath, Mo2ModlistInstallationSettings>();
|
2019-11-14 05:28:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-23 04:02:50 +00:00
|
|
|
|
[JsonName("Mo2ModListInstallerSettings")]
|
2019-12-03 02:38:33 +00:00
|
|
|
|
public class Mo2ModlistInstallationSettings
|
2019-11-06 03:22:38 +00:00
|
|
|
|
{
|
2020-03-28 20:04:22 +00:00
|
|
|
|
public AbsolutePath InstallationLocation { get; set; }
|
|
|
|
|
public AbsolutePath DownloadLocation { get; set; }
|
2019-12-10 00:46:44 +00:00
|
|
|
|
public bool AutomaticallyOverrideExistingInstall { get; set; }
|
2019-11-06 03:22:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-23 04:02:50 +00:00
|
|
|
|
[JsonName("CompilerSettings")]
|
2019-11-14 05:28:27 +00:00
|
|
|
|
public class CompilerSettings
|
|
|
|
|
{
|
|
|
|
|
public ModManager LastCompiledModManager { get; set; }
|
2020-03-28 20:04:22 +00:00
|
|
|
|
public AbsolutePath OutputLocation { get; set; }
|
2019-11-14 05:28:27 +00:00
|
|
|
|
public MO2CompilationSettings MO2Compilation { get; } = new MO2CompilationSettings();
|
|
|
|
|
}
|
2020-05-10 04:35:39 +00:00
|
|
|
|
|
|
|
|
|
[JsonName("FiltersSettings")]
|
|
|
|
|
[JsonObject(MemberSerialization.OptOut)]
|
|
|
|
|
public class FiltersSettings : ViewModel
|
|
|
|
|
{
|
2020-05-10 04:59:34 +00:00
|
|
|
|
public bool ShowNSFW { get; set; }
|
2020-05-10 04:35:39 +00:00
|
|
|
|
public bool OnlyInstalled { get; set; }
|
|
|
|
|
public string Game { get; set; }
|
|
|
|
|
public string Search { get; set; }
|
|
|
|
|
private bool _isPersistent = true;
|
2020-05-10 04:59:34 +00:00
|
|
|
|
public bool IsPersistent { get => _isPersistent; set => RaiseAndSetIfChanged(ref _isPersistent, value); }
|
2020-05-10 04:35:39 +00:00
|
|
|
|
}
|
2019-11-14 05:28:27 +00:00
|
|
|
|
|
2020-04-23 04:02:50 +00:00
|
|
|
|
[JsonName("PerformanceSettings")]
|
2020-01-06 04:49:11 +00:00
|
|
|
|
[JsonObject(MemberSerialization.OptOut)]
|
|
|
|
|
public class PerformanceSettings : ViewModel
|
|
|
|
|
{
|
2020-03-04 11:21:44 +00:00
|
|
|
|
private bool _manual;
|
|
|
|
|
public bool Manual { get => _manual; set => RaiseAndSetIfChanged(ref _manual, value); }
|
2020-01-06 04:49:11 +00:00
|
|
|
|
|
2020-03-04 11:21:44 +00:00
|
|
|
|
private byte _maxCores = byte.MaxValue;
|
|
|
|
|
public byte MaxCores { get => _maxCores; set => RaiseAndSetIfChanged(ref _maxCores, value); }
|
2020-01-06 04:49:11 +00:00
|
|
|
|
|
2020-03-04 11:21:44 +00:00
|
|
|
|
private Percent _targetUsage = Percent.One;
|
|
|
|
|
public Percent TargetUsage { get => _targetUsage; set => RaiseAndSetIfChanged(ref _targetUsage, value); }
|
2020-01-10 04:55:57 +00:00
|
|
|
|
|
|
|
|
|
public void AttachToBatchProcessor(ABatchProcessor processor)
|
|
|
|
|
{
|
|
|
|
|
processor.Add(
|
|
|
|
|
this.WhenAny(x => x.Manual)
|
|
|
|
|
.Subscribe(processor.ManualCoreLimit));
|
|
|
|
|
processor.Add(
|
|
|
|
|
this.WhenAny(x => x.MaxCores)
|
|
|
|
|
.Subscribe(processor.MaxCores));
|
|
|
|
|
processor.Add(
|
|
|
|
|
this.WhenAny(x => x.TargetUsage)
|
|
|
|
|
.Subscribe(processor.TargetUsagePercent));
|
|
|
|
|
}
|
2020-01-06 04:49:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-23 04:02:50 +00:00
|
|
|
|
[JsonName("CompilationModlistSettings")]
|
2019-11-14 05:28:27 +00:00
|
|
|
|
public class CompilationModlistSettings
|
2019-11-06 03:22:38 +00:00
|
|
|
|
{
|
|
|
|
|
public string ModListName { get; set; }
|
2020-04-16 15:16:49 +00:00
|
|
|
|
public string Version { get; set; }
|
2019-11-06 03:22:38 +00:00
|
|
|
|
public string Author { get; set; }
|
|
|
|
|
public string Description { get; set; }
|
|
|
|
|
public string Website { get; set; }
|
|
|
|
|
public string Readme { get; set; }
|
2020-04-27 09:58:33 +00:00
|
|
|
|
public bool IsNSFW { get; set; }
|
2020-03-28 20:04:22 +00:00
|
|
|
|
public AbsolutePath SplashScreen { get; set; }
|
2019-11-14 05:28:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-23 04:02:50 +00:00
|
|
|
|
[JsonName("MO2CompilationSettings")]
|
2019-11-14 05:28:27 +00:00
|
|
|
|
public class MO2CompilationSettings
|
|
|
|
|
{
|
2020-03-28 20:04:22 +00:00
|
|
|
|
public AbsolutePath DownloadLocation { get; set; }
|
|
|
|
|
public AbsolutePath LastCompiledProfileLocation { get; set; }
|
|
|
|
|
public Dictionary<AbsolutePath, CompilationModlistSettings> ModlistSettings { get; } = new Dictionary<AbsolutePath, CompilationModlistSettings>();
|
2019-11-14 05:28:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-11-06 03:22:38 +00:00
|
|
|
|
}
|