mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Initial settings systems
Waiting to do position/size implementation until new ModeSelection systems are finished
This commit is contained in:
parent
becf1c0ecd
commit
9e8ea6d281
@ -92,10 +92,11 @@ namespace Wabbajack.Lib
|
||||
}
|
||||
}
|
||||
|
||||
public static string OpenFileDialog(string filter)
|
||||
public static string OpenFileDialog(string filter, string initialDirectory = null)
|
||||
{
|
||||
OpenFileDialog ofd = new OpenFileDialog();
|
||||
ofd.Filter = filter;
|
||||
ofd.InitialDirectory = initialDirectory;
|
||||
if (ofd.ShowDialog() == DialogResult.OK)
|
||||
return ofd.FileName;
|
||||
return null;
|
||||
|
70
Wabbajack/Settings.cs
Normal file
70
Wabbajack/Settings.cs
Normal file
@ -0,0 +1,70 @@
|
||||
using Newtonsoft.Json;
|
||||
using ReactiveUI.Fody.Helpers;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reactive;
|
||||
using System.Reactive.Linq;
|
||||
using System.Reactive.Subjects;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Wabbajack
|
||||
{
|
||||
[JsonObject(MemberSerialization.OptOut)]
|
||||
public class MainSettings
|
||||
{
|
||||
private static string Filename = "settings.json";
|
||||
|
||||
public double PosX { get; set; }
|
||||
public double PosY { get; set; }
|
||||
public double Height { get; set; }
|
||||
public double Width { get; set; }
|
||||
public string LastInstalledListLocation { get; set; }
|
||||
public Dictionary<string, InstallationSettings> InstallationSettings { get; } = new Dictionary<string, InstallationSettings>();
|
||||
public string LastCompiledProfileLocation { get; set; }
|
||||
public Dictionary<string, CompilationSettings> CompilationSettings { get; } = new Dictionary<string, CompilationSettings>();
|
||||
|
||||
[JsonIgnoreAttribute]
|
||||
private Subject<Unit> _saveSignal = new Subject<Unit>();
|
||||
public IObservable<Unit> SaveSignal => _saveSignal;
|
||||
|
||||
public static MainSettings LoadSettings()
|
||||
{
|
||||
if (!File.Exists(Filename)) return new MainSettings();
|
||||
return JsonConvert.DeserializeObject<MainSettings>(File.ReadAllText(Filename));
|
||||
}
|
||||
|
||||
public static void SaveSettings(MainSettings settings)
|
||||
{
|
||||
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;
|
||||
|
||||
File.WriteAllText(Filename, JsonConvert.SerializeObject(settings, Formatting.Indented));
|
||||
}
|
||||
}
|
||||
|
||||
public class InstallationSettings
|
||||
{
|
||||
public string InstallationLocation { get; set; }
|
||||
public string DownloadLocation { get; set; }
|
||||
}
|
||||
|
||||
public class CompilationSettings
|
||||
{
|
||||
public string ModListName { get; set; }
|
||||
public string Author { get; set; }
|
||||
public string Description { get; set; }
|
||||
public string Website { get; set; }
|
||||
public string Readme { get; set; }
|
||||
public string SplashScreen { get; set; }
|
||||
public string Location { get; set; }
|
||||
public string DownloadLocation { get; set; }
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
using ReactiveUI;
|
||||
using ReactiveUI;
|
||||
using ReactiveUI.Fody.Helpers;
|
||||
using System;
|
||||
using System.IO;
|
||||
@ -44,7 +44,7 @@ namespace Wabbajack
|
||||
public BitmapImage Image => _Image.Value;
|
||||
|
||||
[Reactive]
|
||||
public string NexusSiteURL { get; set; }
|
||||
public string Website { get; set; }
|
||||
|
||||
[Reactive]
|
||||
public string ReadMeText { get; set; }
|
||||
@ -80,6 +80,36 @@ namespace Wabbajack
|
||||
.ToProperty(this, nameof(this.Image));
|
||||
|
||||
ConfigureForBuild(source);
|
||||
|
||||
// Load settings
|
||||
CompilationSettings settings = this.MWVM.Settings.CompilationSettings.TryCreate(source);
|
||||
this.AuthorName = settings.Author;
|
||||
this.ModListName = settings.ModListName;
|
||||
this.Summary = settings.Description;
|
||||
this.ReadMeText = settings.Readme;
|
||||
this.ImagePath = settings.SplashScreen;
|
||||
this.Website = settings.Website;
|
||||
if (!string.IsNullOrWhiteSpace(settings.DownloadLocation))
|
||||
{
|
||||
this.DownloadLocation = settings.DownloadLocation;
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(settings.Location))
|
||||
{
|
||||
this.Location = settings.Location;
|
||||
}
|
||||
this.MWVM.Settings.SaveSignal
|
||||
.Subscribe(_ =>
|
||||
{
|
||||
settings.Author = this.AuthorName;
|
||||
settings.ModListName = this.ModListName;
|
||||
settings.Description = this.Summary;
|
||||
settings.Readme = this.ReadMeText;
|
||||
settings.SplashScreen = this.ImagePath;
|
||||
settings.Website = this.Website;
|
||||
settings.Location = this.Location;
|
||||
settings.DownloadLocation = this.DownloadLocation;
|
||||
})
|
||||
.DisposeWith(this.CompositeDisposable);
|
||||
}
|
||||
|
||||
private void ConfigureForBuild(string location)
|
||||
@ -109,7 +139,7 @@ namespace Wabbajack
|
||||
ModListAuthor = this.AuthorName,
|
||||
ModListDescription = this.Summary,
|
||||
ModListImage = this.ImagePath,
|
||||
ModListWebsite = this.NexusSiteURL,
|
||||
ModListWebsite = this.Website,
|
||||
ModListReadme = this.ReadMeText,
|
||||
};
|
||||
await Task.Run(() =>
|
||||
|
@ -1,32 +1,18 @@
|
||||
using Syroot.Windows.IO;
|
||||
using System;
|
||||
using ReactiveUI;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Reactive.Subjects;
|
||||
using System.Reactive.Disposables;
|
||||
using System.Reactive.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Threading;
|
||||
using Wabbajack.Common;
|
||||
using Wabbajack.Lib.Downloaders;
|
||||
using Wabbajack.Lib.NexusApi;
|
||||
using DynamicData;
|
||||
using DynamicData.Binding;
|
||||
using System.Reactive;
|
||||
using System.Text;
|
||||
using Wabbajack.Lib;
|
||||
using Splat;
|
||||
using ReactiveUI.Fody.Helpers;
|
||||
|
||||
namespace Wabbajack
|
||||
@ -96,7 +82,7 @@ namespace Wabbajack
|
||||
public IReactiveCommand OpenReadmeCommand { get; }
|
||||
public IReactiveCommand VisitWebsiteCommand { get; }
|
||||
|
||||
public InstallerVM(MainWindowVM mainWindowVM)
|
||||
public InstallerVM(MainWindowVM mainWindowVM, string source)
|
||||
{
|
||||
if (Path.GetDirectoryName(Assembly.GetEntryAssembly().Location.ToLower()) == KnownFolders.Downloads.Path.ToLower())
|
||||
{
|
||||
@ -110,13 +96,26 @@ namespace Wabbajack
|
||||
}
|
||||
|
||||
this.MWVM = mainWindowVM;
|
||||
this.ModListPath = source;
|
||||
|
||||
// Load settings
|
||||
InstallationSettings settings = this.MWVM.Settings.InstallationSettings.TryCreate(source);
|
||||
this.Location = settings.InstallationLocation;
|
||||
this.DownloadLocation = settings.DownloadLocation;
|
||||
this.MWVM.Settings.SaveSignal
|
||||
.Subscribe(_ =>
|
||||
{
|
||||
settings.InstallationLocation = this.Location;
|
||||
settings.DownloadLocation = this.DownloadLocation;
|
||||
})
|
||||
.DisposeWith(this.CompositeDisposable);
|
||||
|
||||
this._ModList = this.WhenAny(x => x.ModListPath)
|
||||
.ObserveOn(RxApp.TaskpoolScheduler)
|
||||
.Select(source =>
|
||||
.Select(modListPath =>
|
||||
{
|
||||
if (source == null) return default(ModListVM);
|
||||
var modList = Installer.LoadFromFile(source);
|
||||
if (modListPath == null) return default(ModListVM);
|
||||
var modList = Installer.LoadFromFile(modListPath);
|
||||
if (modList == null)
|
||||
{
|
||||
MessageBox.Show("Invalid Modlist, or file not found.", "Invalid Modlist", MessageBoxButton.OK,
|
||||
@ -133,7 +132,7 @@ namespace Wabbajack
|
||||
});
|
||||
return default(ModListVM);
|
||||
}
|
||||
return new ModListVM(modList, source);
|
||||
return new ModListVM(modList, modListPath);
|
||||
})
|
||||
.ObserveOnGuiThread()
|
||||
.StartWith(default(ModListVM))
|
||||
|
@ -26,6 +26,8 @@ namespace Wabbajack
|
||||
{
|
||||
public MainWindow MainWindow { get; }
|
||||
|
||||
public MainSettings Settings { get; }
|
||||
|
||||
private readonly ObservableAsPropertyHelper<ViewModel> _ActivePane;
|
||||
public ViewModel ActivePane => _ActivePane.Value;
|
||||
|
||||
@ -34,7 +36,6 @@ namespace Wabbajack
|
||||
|
||||
public ObservableCollectionExtended<CPUStatus> StatusList { get; } = new ObservableCollectionExtended<CPUStatus>();
|
||||
|
||||
private Subject<string> _logSubj = new Subject<string>();
|
||||
public ObservableCollectionExtended<string> Log { get; } = new ObservableCollectionExtended<string>();
|
||||
|
||||
[Reactive]
|
||||
@ -43,11 +44,12 @@ namespace Wabbajack
|
||||
private readonly Lazy<CompilerVM> _Compiler;
|
||||
private readonly Lazy<InstallerVM> _Installer;
|
||||
|
||||
public MainWindowVM(RunMode mode, string source, MainWindow mainWindow)
|
||||
public MainWindowVM(RunMode mode, string source, MainWindow mainWindow, MainSettings settings)
|
||||
{
|
||||
this.Mode = mode;
|
||||
this.MainWindow = mainWindow;
|
||||
this._Installer = new Lazy<InstallerVM>(() => new InstallerVM(this));
|
||||
this.Settings = settings;
|
||||
this._Installer = new Lazy<InstallerVM>(() => new InstallerVM(this, source));
|
||||
this._Compiler = new Lazy<CompilerVM>(() => new CompilerVM(this, source));
|
||||
|
||||
// Set up logging
|
||||
@ -82,11 +84,6 @@ namespace Wabbajack
|
||||
}
|
||||
})
|
||||
.ToProperty(this, nameof(this.ActivePane));
|
||||
this.WhenAny(x => x.ActivePane)
|
||||
.ObserveOn(RxApp.TaskpoolScheduler)
|
||||
.WhereCastable<ViewModel, InstallerVM>()
|
||||
.Subscribe(vm => vm.ModListPath = source)
|
||||
.DisposeWith(this.CompositeDisposable);
|
||||
|
||||
// Compile progress updates and populate ObservableCollection
|
||||
WorkQueue.Status
|
||||
|
@ -106,7 +106,7 @@
|
||||
Text="{Binding Summary}"
|
||||
TextWrapping="Wrap" />
|
||||
<TextBlock Margin="{StaticResource TitleMargin}" Text="Website" />
|
||||
<TextBox Style="{StaticResource ValueStyle}" Text="{Binding NexusSiteURL}" />
|
||||
<TextBox Style="{StaticResource ValueStyle}" Text="{Binding Website}" />
|
||||
<TextBlock
|
||||
Margin="{StaticResource TitleMargin}"
|
||||
Text="Readme Path"
|
||||
|
@ -13,6 +13,7 @@ namespace Wabbajack
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
private MainWindowVM _mwvm;
|
||||
private MainSettings _settings;
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
@ -20,19 +21,20 @@ namespace Wabbajack
|
||||
|
||||
if (args.Length != 3) return;
|
||||
var modlistPath = args[2];
|
||||
Initialize(RunMode.Install, modlistPath);
|
||||
this._settings = MainSettings.LoadSettings();
|
||||
Initialize(RunMode.Install, modlistPath, this._settings);
|
||||
}
|
||||
|
||||
public MainWindow(RunMode mode, string source)
|
||||
public MainWindow(RunMode mode, string source, MainSettings settings)
|
||||
{
|
||||
Initialize(mode, source);
|
||||
Initialize(mode, source, settings);
|
||||
}
|
||||
|
||||
private void Initialize(RunMode mode, string source)
|
||||
private void Initialize(RunMode mode, string source, MainSettings settings)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
_mwvm = new MainWindowVM(mode, source, this);
|
||||
this._settings = settings;
|
||||
_mwvm = new MainWindowVM(mode, source, this, settings);
|
||||
Utils.Log($"Wabbajack Build - {ThisAssembly.Git.Sha}");
|
||||
this.DataContext = _mwvm;
|
||||
}
|
||||
@ -42,6 +44,7 @@ namespace Wabbajack
|
||||
private void Window_Closing(object sender, CancelEventArgs e)
|
||||
{
|
||||
_mwvm.Dispose();
|
||||
MainSettings.SaveSettings(this._settings);
|
||||
if (ExitWhenClosing)
|
||||
{
|
||||
Application.Current.Shutdown();
|
||||
|
@ -1,6 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using Wabbajack.Common;
|
||||
@ -16,7 +17,7 @@ namespace Wabbajack
|
||||
/// </summary>
|
||||
public partial class ModeSelectionWindow : Window
|
||||
{
|
||||
private List<ModlistMetadata> _lists;
|
||||
MainSettings settings;
|
||||
|
||||
public ModeSelectionWindow()
|
||||
{
|
||||
@ -30,6 +31,7 @@ namespace Wabbajack
|
||||
var discordIcon = UIUtils.BitmapImageFromResource("Wabbajack.Resources.Icons.discord.png");
|
||||
Discord.Source = discordIcon;
|
||||
|
||||
settings = MainSettings.LoadSettings();
|
||||
DataContext = new ModeSelectionWindowVM();
|
||||
}
|
||||
|
||||
@ -37,7 +39,9 @@ namespace Wabbajack
|
||||
{
|
||||
OpenMainWindow(
|
||||
RunMode.Compile,
|
||||
UIUtils.OpenFileDialog("MO2 Modlist(modlist.txt)|modlist.txt"));
|
||||
UIUtils.OpenFileDialog(
|
||||
"MO2 Modlist(modlist.txt)|modlist.txt",
|
||||
initialDirectory: settings.LastCompiledProfileLocation));
|
||||
}
|
||||
|
||||
private void InstallModlist_Click(object sender, RoutedEventArgs e)
|
||||
@ -57,7 +61,18 @@ namespace Wabbajack
|
||||
{
|
||||
if (file == null) return;
|
||||
ShutdownOnClose = false;
|
||||
var window = new MainWindow(mode, file);
|
||||
switch (mode)
|
||||
{
|
||||
case RunMode.Compile:
|
||||
settings.LastCompiledProfileLocation = Path.GetDirectoryName(file);
|
||||
break;
|
||||
case RunMode.Install:
|
||||
settings.LastInstalledListLocation = Path.GetDirectoryName(file);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
var window = new MainWindow(mode, file, settings);
|
||||
window.Left = this.Left;
|
||||
window.Top = this.Top;
|
||||
window.Show();
|
||||
@ -90,7 +105,9 @@ namespace Wabbajack
|
||||
private void InstallFromList_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
OpenMainWindow(RunMode.Install,
|
||||
UIUtils.OpenFileDialog($"*{ExtensionManager.Extension}|*{ExtensionManager.Extension}"));
|
||||
UIUtils.OpenFileDialog(
|
||||
$"*{ExtensionManager.Extension}|*{ExtensionManager.Extension}",
|
||||
initialDirectory: settings.LastInstalledListLocation));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -163,6 +163,7 @@
|
||||
</ApplicationDefinition>
|
||||
<Compile Include="Converters\BoolToVisibilityConverter.cs" />
|
||||
<Compile Include="Extensions\EnumerableExt.cs" />
|
||||
<Compile Include="Settings.cs" />
|
||||
<Compile Include="View Models\ModListVM.cs" />
|
||||
<Compile Include="View Models\ModVM.cs" />
|
||||
<Compile Include="Views\CompilerView.xaml.cs">
|
||||
|
Loading…
Reference in New Issue
Block a user