diff --git a/Wabbajack.Common/Enums/RunMode.cs b/Wabbajack.Common/Enums/RunMode.cs deleted file mode 100644 index 6d2ff5fc..00000000 --- a/Wabbajack.Common/Enums/RunMode.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Wabbajack -{ - public enum RunMode - { - Compile, - Install - } -} diff --git a/Wabbajack.Common/Wabbajack.Common.csproj b/Wabbajack.Common/Wabbajack.Common.csproj index 38e5dd66..265ff2d8 100644 --- a/Wabbajack.Common/Wabbajack.Common.csproj +++ b/Wabbajack.Common/Wabbajack.Common.csproj @@ -93,7 +93,6 @@ - diff --git a/Wabbajack/App.xaml b/Wabbajack/App.xaml index 310e335e..17c85ac3 100644 --- a/Wabbajack/App.xaml +++ b/Wabbajack/App.xaml @@ -1,8 +1,10 @@ - + diff --git a/Wabbajack/App.xaml.cs b/Wabbajack/App.xaml.cs index ab75edd9..b69397e4 100644 --- a/Wabbajack/App.xaml.cs +++ b/Wabbajack/App.xaml.cs @@ -25,13 +25,6 @@ namespace Wabbajack { ExtensionManager.Associate(appPath); } - - string[] args = Environment.GetCommandLineArgs(); - StartupUri = new Uri("Views/ModeSelectionWindow.xaml", UriKind.Relative); - if (args.Length != 3) return; - if (!args[1].Contains("-i")) return; - // modlists gets loaded using a shell command - StartupUri = new Uri("Views/MainWindow.xaml", UriKind.Relative); } } -} \ No newline at end of file +} diff --git a/Wabbajack/Resources/Icons/github.png b/Wabbajack/Resources/Icons/github.png index ea6ff545..192846a1 100644 Binary files a/Wabbajack/Resources/Icons/github.png and b/Wabbajack/Resources/Icons/github.png differ diff --git a/Wabbajack/Resources/Icons/github_light.png b/Wabbajack/Resources/Icons/github_light.png deleted file mode 100644 index 192846a1..00000000 Binary files a/Wabbajack/Resources/Icons/github_light.png and /dev/null differ diff --git a/Wabbajack/Resources/Icons/patreon.png b/Wabbajack/Resources/Icons/patreon.png index d6d1e045..617b38ec 100644 Binary files a/Wabbajack/Resources/Icons/patreon.png and b/Wabbajack/Resources/Icons/patreon.png differ diff --git a/Wabbajack/Resources/Icons/patreon_light.png b/Wabbajack/Resources/Icons/patreon_light.png deleted file mode 100644 index 617b38ec..00000000 Binary files a/Wabbajack/Resources/Icons/patreon_light.png and /dev/null differ diff --git a/Wabbajack/View Models/InstallerVM.cs b/Wabbajack/View Models/InstallerVM.cs index 991e2953..eefae2c2 100644 --- a/Wabbajack/View Models/InstallerVM.cs +++ b/Wabbajack/View Models/InstallerVM.cs @@ -80,13 +80,16 @@ namespace Wabbajack public ObservableCollectionExtended StatusList { get; } = new ObservableCollectionExtended(); public ObservableCollectionExtended Log => MWVM.Log; + private readonly ObservableAsPropertyHelper _CurrentSettings; + public ModlistInstallationSettings CurrentSettings => _CurrentSettings.Value; + // Command properties public IReactiveCommand BeginCommand { get; } public IReactiveCommand ShowReportCommand { get; } public IReactiveCommand OpenReadmeCommand { get; } public IReactiveCommand VisitWebsiteCommand { get; } - public InstallerVM(MainWindowVM mainWindowVM, string source) + public InstallerVM(MainWindowVM mainWindowVM) { if (Path.GetDirectoryName(Assembly.GetEntryAssembly().Location.ToLower()) == KnownFolders.Downloads.Path.ToLower()) { @@ -100,7 +103,6 @@ namespace Wabbajack } MWVM = mainWindowVM; - ModListPath = source; Location = new FilePickerVM() { @@ -120,16 +122,22 @@ namespace Wabbajack .Select(x => Utils.IsDirectoryPathValid(x)); // Load settings - ModlistInstallationSettings settings = MWVM.Settings.Installer.ModlistSettings.TryCreate(source); - Location.TargetPath = settings.InstallationLocation; - DownloadLocation.TargetPath = settings.DownloadLocation; - MWVM.Settings.SaveSignal - .Subscribe(_ => + _CurrentSettings = this.WhenAny(x => x.ModListPath) + .Select(path => path == null ? null : MWVM.Settings.Installer.ModlistSettings.TryCreate(path)) + .ToProperty(this, nameof(CurrentSettings)); + this.WhenAny(x => x.CurrentSettings) + .Pairwise() + .Subscribe(settingsPair => { - settings.InstallationLocation = Location.TargetPath; - settings.DownloadLocation = DownloadLocation.TargetPath; + SaveSettings(settingsPair.Previous); + if (settingsPair.Current == null) return; + Location.TargetPath = settingsPair.Current.InstallationLocation; + DownloadLocation.TargetPath = settingsPair.Current.DownloadLocation; }) .DisposeWith(CompositeDisposable); + MWVM.Settings.SaveSignal + .Subscribe(_ => SaveSettings(CurrentSettings)) + .DisposeWith(CompositeDisposable); _modList = this.WhenAny(x => x.ModListPath) .ObserveOn(RxApp.TaskpoolScheduler) @@ -137,22 +145,7 @@ namespace Wabbajack { if (modListPath == null) return default(ModListVM); var modList = AInstaller.LoadFromFile(modListPath); - if (modList == null) - { - MessageBox.Show("Invalid Modlist, or file not found.", "Invalid Modlist", MessageBoxButton.OK, - MessageBoxImage.Error); - Application.Current.Dispatcher.Invoke(() => - { - MWVM.MainWindow.ExitWhenClosing = false; - var window = new ModeSelectionWindow - { - ShowActivated = true - }; - window.Show(); - MWVM.MainWindow.Close(); - }); - return default(ModListVM); - } + if (modList == null) return default(ModListVM); return new ModListVM(modList, modListPath); }) .ObserveOnGuiThread() @@ -361,5 +354,12 @@ namespace Wabbajack } }); } + + private void SaveSettings(ModlistInstallationSettings settings) + { + if (settings == null) return; + settings.InstallationLocation = Location.TargetPath; + settings.DownloadLocation = DownloadLocation.TargetPath; + } } } diff --git a/Wabbajack/View Models/MainWindowVM.cs b/Wabbajack/View Models/MainWindowVM.cs index 8511f187..8946a7b4 100644 --- a/Wabbajack/View Models/MainWindowVM.cs +++ b/Wabbajack/View Models/MainWindowVM.cs @@ -21,24 +21,22 @@ namespace Wabbajack public MainSettings Settings { get; } - private readonly ObservableAsPropertyHelper _activePane; - public ViewModel ActivePane => _activePane.Value; + [Reactive] + public ViewModel ActivePane { get; set; } public ObservableCollectionExtended Log { get; } = new ObservableCollectionExtended(); - [Reactive] - public RunMode Mode { get; set; } + public readonly Lazy Compiler; + public readonly Lazy Installer; + public readonly ModeSelectionVM ModeSelectionVM; - private readonly Lazy _compiler; - private readonly Lazy _installer; - - public MainWindowVM(RunMode mode, string source, MainWindow mainWindow, MainSettings settings) + public MainWindowVM(MainWindow mainWindow, MainSettings settings) { - Mode = mode; MainWindow = mainWindow; Settings = settings; - _installer = new Lazy(() => new InstallerVM(this, source)); - _compiler = new Lazy(() => new CompilerVM(this)); + Installer = new Lazy(() => new InstallerVM(this)); + Compiler = new Lazy(() => new CompilerVM(this)); + ModeSelectionVM = new ModeSelectionVM(this); // Set up logging Utils.LogMessages @@ -53,23 +51,8 @@ namespace Wabbajack .Subscribe() .DisposeWith(CompositeDisposable); - // Wire mode to drive the active pane. - // Note: This is currently made into a derivative property driven by mode, - // but it can be easily changed into a normal property that can be set from anywhere if needed - _activePane = this.WhenAny(x => x.Mode) - .Select(m => - { - switch (m) - { - case RunMode.Compile: - return _compiler.Value; - case RunMode.Install: - return _installer.Value; - default: - return default; - } - }) - .ToProperty(this, nameof(ActivePane)); + // Start on mode selection + ActivePane = ModeSelectionVM; } } } diff --git a/Wabbajack/View Models/ModeSelectionVM.cs b/Wabbajack/View Models/ModeSelectionVM.cs new file mode 100644 index 00000000..0e027faf --- /dev/null +++ b/Wabbajack/View Models/ModeSelectionVM.cs @@ -0,0 +1,81 @@ +using Alphaleonis.Win32.Filesystem; +using ReactiveUI; +using ReactiveUI.Fody.Helpers; +using System.Collections.ObjectModel; +using System.Linq; +using System.Reactive.Linq; +using System.Windows.Input; +using Wabbajack.Common; +using Wabbajack.Lib; +using Wabbajack.Lib.ModListRegistry; + +namespace Wabbajack +{ + public class ModeSelectionVM : ViewModel + { + public ObservableCollection ModLists { get; } = new ObservableCollection(ModlistMetadata.LoadFromGithub()); + + [Reactive] + public ModlistMetadata SelectedModList { get; set; } + + private MainWindowVM _mainVM; + public ICommand DownloadAndInstallCommand { get; } + public ICommand InstallCommand { get; } + public ICommand CompileCommand { get; } + + public ModeSelectionVM(MainWindowVM mainVM) + { + _mainVM = mainVM; + InstallCommand = ReactiveCommand.Create( + execute: () => + { + OpenInstaller( + UIUtils.OpenFileDialog( + $"*{ExtensionManager.Extension}|*{ExtensionManager.Extension}", + initialDirectory: mainVM.Settings.Installer.LastInstalledListLocation)); + }); + + CompileCommand = ReactiveCommand.Create( + execute: () => + { + mainVM.ActivePane = mainVM.Compiler.Value; + }); + + DownloadAndInstallCommand = ReactiveCommand.Create( + canExecute: this.WhenAny(x => x.SelectedModList) + .Select(x => x != null) + .ObserveOnGuiThread(), + execute: () => + { + OpenInstaller(Download()); + }); + } + + private void OpenInstaller(string path) + { + if (path == null) return; + var installer = _mainVM.Installer.Value; + _mainVM.Settings.Installer.LastInstalledListLocation = path; + _mainVM.ActivePane = installer; + installer.ModListPath = path; + } + + private string Download() + { + if (!Directory.Exists(Consts.ModListDownloadFolder)) + Directory.CreateDirectory(Consts.ModListDownloadFolder); + + string dest = Path.Combine(Consts.ModListDownloadFolder, SelectedModList.Links.MachineURL + ExtensionManager.Extension); + + var window = new DownloadWindow(SelectedModList.Links.Download, + SelectedModList.Title, + SelectedModList.Links.DownloadMetadata?.Size ?? 0, + dest); + window.ShowDialog(); + + if (window.Result == DownloadWindow.WindowResult.Completed) + return dest; + return null; + } + } +} diff --git a/Wabbajack/View Models/ModeSelectionWindowVM.cs b/Wabbajack/View Models/ModeSelectionWindowVM.cs deleted file mode 100644 index 805a5691..00000000 --- a/Wabbajack/View Models/ModeSelectionWindowVM.cs +++ /dev/null @@ -1,48 +0,0 @@ -using Alphaleonis.Win32.Filesystem; -using ReactiveUI; -using ReactiveUI.Fody.Helpers; -using System.Collections.ObjectModel; -using System.Linq; -using System.Reactive.Linq; -using Wabbajack.Common; -using Wabbajack.Lib; -using Wabbajack.Lib.ModListRegistry; - -namespace Wabbajack.UI -{ - public class ModeSelectionWindowVM : ViewModel - { - public ObservableCollection ModLists { get; } = new ObservableCollection(ModlistMetadata.LoadFromGithub()); - - [Reactive] - public ModlistMetadata SelectedModList { get; set; } - - private readonly ObservableAsPropertyHelper _canInstall; - public bool CanInstall => _canInstall.Value; - - public ModeSelectionWindowVM() - { - _canInstall = this.WhenAny(x => x.SelectedModList) - .Select(x => x != null) - .ToProperty(this, nameof(CanInstall)); - } - - internal string Download() - { - if (!Directory.Exists(Consts.ModListDownloadFolder)) - Directory.CreateDirectory(Consts.ModListDownloadFolder); - - string dest = Path.Combine(Consts.ModListDownloadFolder, SelectedModList.Links.MachineURL + ExtensionManager.Extension); - - var window = new DownloadWindow(SelectedModList.Links.Download, - SelectedModList.Title, - SelectedModList.Links.DownloadMetadata?.Size ?? 0, - dest); - window.ShowDialog(); - - if (window.Result == DownloadWindow.WindowResult.Completed) - return dest; - return null; - } - } -} diff --git a/Wabbajack/Views/DownloadWindow.xaml b/Wabbajack/Views/DownloadWindow.xaml index a38bf253..87340cf3 100644 --- a/Wabbajack/Views/DownloadWindow.xaml +++ b/Wabbajack/Views/DownloadWindow.xaml @@ -1,4 +1,4 @@ - /// Interaction logic for DownloadWindow.xaml diff --git a/Wabbajack/Views/LinksView.xaml b/Wabbajack/Views/LinksView.xaml new file mode 100644 index 00000000..b5458a91 --- /dev/null +++ b/Wabbajack/Views/LinksView.xaml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + diff --git a/Wabbajack/Views/LinksView.xaml.cs b/Wabbajack/Views/LinksView.xaml.cs new file mode 100644 index 00000000..f315993d --- /dev/null +++ b/Wabbajack/Views/LinksView.xaml.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace Wabbajack +{ + /// + /// Interaction logic for LinksView.xaml + /// + public partial class LinksView : UserControl + { + public LinksView() + { + InitializeComponent(); + } + + private void GitHub_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) + { + Process.Start("https://github.com/wabbajack-tools/wabbajack"); + } + + private void Patreon_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) + { + Process.Start("https://www.patreon.com/user?u=11907933"); + } + + private void Discord_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) + { + Process.Start("https://discord.gg/zgbrkmA"); + } + } +} diff --git a/Wabbajack/Views/MainWindow.xaml b/Wabbajack/Views/MainWindow.xaml index 3d92d10c..bfd044d6 100644 --- a/Wabbajack/Views/MainWindow.xaml +++ b/Wabbajack/Views/MainWindow.xaml @@ -26,6 +26,9 @@ + + + diff --git a/Wabbajack/Views/MainWindow.xaml.cs b/Wabbajack/Views/MainWindow.xaml.cs index a38e5c30..241bc101 100644 --- a/Wabbajack/Views/MainWindow.xaml.cs +++ b/Wabbajack/Views/MainWindow.xaml.cs @@ -16,26 +16,10 @@ namespace Wabbajack public MainWindow() { - string[] args = Environment.GetCommandLineArgs(); - - if (args.Length != 3) return; - var modlistPath = args[2]; _settings = MainSettings.LoadSettings(); - Initialize(RunMode.Install, modlistPath, _settings); - } - - public MainWindow(RunMode mode, string source, MainSettings settings) - { - Initialize(mode, source, settings); - } - - private void Initialize(RunMode mode, string source, MainSettings settings) - { - InitializeComponent(); - _settings = settings; - _mwvm = new MainWindowVM(mode, source, this, settings); - Utils.Log($"Wabbajack Build - {ThisAssembly.Git.Sha}"); + _mwvm = new MainWindowVM(this, _settings); DataContext = _mwvm; + Utils.Log($"Wabbajack Build - {ThisAssembly.Git.Sha}"); } internal bool ExitWhenClosing = true; diff --git a/Wabbajack/Views/ModeSelectionWindow.xaml b/Wabbajack/Views/ModeSelectionView.xaml similarity index 75% rename from Wabbajack/Views/ModeSelectionWindow.xaml rename to Wabbajack/Views/ModeSelectionView.xaml index 37364ec8..dcedca3c 100644 --- a/Wabbajack/Views/ModeSelectionWindow.xaml +++ b/Wabbajack/Views/ModeSelectionView.xaml @@ -1,62 +1,36 @@ - - - - - - - - - - + - + diff --git a/Wabbajack/Views/ModeSelectionView.xaml.cs b/Wabbajack/Views/ModeSelectionView.xaml.cs new file mode 100644 index 00000000..c211a056 --- /dev/null +++ b/Wabbajack/Views/ModeSelectionView.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace Wabbajack +{ + /// + /// Interaction logic for ModeSelectionView.xaml + /// + public partial class ModeSelectionView : UserControl + { + public ModeSelectionView() + { + InitializeComponent(); + } + } +} diff --git a/Wabbajack/Views/ModeSelectionWindow.xaml.cs b/Wabbajack/Views/ModeSelectionWindow.xaml.cs deleted file mode 100644 index 09bf0c8e..00000000 --- a/Wabbajack/Views/ModeSelectionWindow.xaml.cs +++ /dev/null @@ -1,97 +0,0 @@ -using System.ComponentModel; -using System.Diagnostics; -using System.IO; -using System.Windows; -using System.Windows.Input; -using Wabbajack.Common; -using Wabbajack.Lib; -using Wabbajack.UI; - -namespace Wabbajack -{ - /// - /// Interaction logic for ModeSelectionWindow.xaml - /// - public partial class ModeSelectionWindow : Window - { - MainSettings _settings; - - public ModeSelectionWindow() - { - InitializeComponent(); - var bannerImage = UIUtils.BitmapImageFromResource("Wabbajack.Resources.banner_small_dark.png"); - Banner.Source = bannerImage; - var patreonIcon = UIUtils.BitmapImageFromResource("Wabbajack.Resources.Icons.patreon_light.png"); - Patreon.Source = patreonIcon; - var githubIcon = UIUtils.BitmapImageFromResource("Wabbajack.Resources.Icons.github_light.png"); - GitHub.Source = githubIcon; - var discordIcon = UIUtils.BitmapImageFromResource("Wabbajack.Resources.Icons.discord.png"); - Discord.Source = discordIcon; - - _settings = MainSettings.LoadSettings(); - DataContext = new ModeSelectionWindowVM(); - } - - private void CreateModlist_Click(object sender, RoutedEventArgs e) - { - ShutdownOnClose = false; - var window = new MainWindow(RunMode.Compile, null, _settings); - window.Left = Left; - window.Top = Top; - window.Show(); - Close(); - } - - private void InstallModlist_Click(object sender, RoutedEventArgs e) - { - var result = ((ModeSelectionWindowVM)DataContext).Download(); - if (result != null) - { - OpenMainWindowInstall(result); - } - } - - private void InstallFromList_Click(object sender, RoutedEventArgs e) - { - OpenMainWindowInstall( - UIUtils.OpenFileDialog( - $"*{ExtensionManager.Extension}|*{ExtensionManager.Extension}", - initialDirectory: _settings.Installer.LastInstalledListLocation)); - } - - private void OpenMainWindowInstall(string file) - { - if (file == null) return; - ShutdownOnClose = false; - _settings.Installer.LastInstalledListLocation = Path.GetDirectoryName(file); - var window = new MainWindow(RunMode.Install, file, _settings); - window.Left = Left; - window.Top = Top; - window.Show(); - Close(); - } - - public void Close_Window(object sender, CancelEventArgs e) - { - if (ShutdownOnClose) - Application.Current.Shutdown(); - } - - public bool ShutdownOnClose { get; set; } = true; - - private void GitHub_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) - { - Process.Start("https://github.com/wabbajack-tools/wabbajack"); - } - - private void Patreon_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) - { - Process.Start("https://www.patreon.com/user?u=11907933"); - } - - private void Discord_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) - { - Process.Start("https://discord.gg/zgbrkmA"); - } - } -} diff --git a/Wabbajack/Wabbajack.csproj b/Wabbajack/Wabbajack.csproj index 28e66d18..78473051 100644 --- a/Wabbajack/Wabbajack.csproj +++ b/Wabbajack/Wabbajack.csproj @@ -169,6 +169,12 @@ Designer + + LinksView.xaml + + + ModeSelectionView.xaml + MO2CompilerConfigView.xaml @@ -208,7 +214,7 @@ DownloadWindow.xaml - + FilePicker.xaml @@ -221,9 +227,6 @@ LogCpuView.xaml - - ModeSelectionWindow.xaml - @@ -237,6 +240,14 @@ VortexCompilerConfigView.xaml + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + Designer MSBuild:Compile @@ -295,10 +306,6 @@ MainWindow.xaml Code - - Designer - MSBuild:Compile - MSBuild:Compile Designer @@ -378,22 +385,16 @@ - - - + - - - - - + @@ -484,5 +485,9 @@ + + + + \ No newline at end of file