diff --git a/Wabbajack.Lib/UI/UIUtils.cs b/Wabbajack.Lib/UI/UIUtils.cs index ee7ad62e..13471acb 100644 --- a/Wabbajack.Lib/UI/UIUtils.cs +++ b/Wabbajack.Lib/UI/UIUtils.cs @@ -62,15 +62,36 @@ namespace Wabbajack.Lib return null; } - public static BitmapImage BitmapImageFromResource(string name) + public static BitmapImage BitmapImageFromResource(string name) => BitmapImageFromStream(Utils.GetResourceStream(name)); + + public static BitmapImage BitmapImageFromStream(Stream stream) { var img = new BitmapImage(); img.BeginInit(); - img.StreamSource = Utils.GetResourceStream(name); + img.StreamSource = stream; img.EndInit(); return img; } + public static bool TryGetBitmapImageFromFile(string path, out BitmapImage bitmapImage) + { + try + { + if (!File.Exists(path)) + { + bitmapImage = default; + return false; + } + bitmapImage = new BitmapImage(new Uri(path, UriKind.RelativeOrAbsolute)); + return true; + } + catch (Exception) + { + bitmapImage = default; + return false; + } + } + public static string OpenFileDialog(string filter) { OpenFileDialog ofd = new OpenFileDialog(); diff --git a/Wabbajack/Extensions/ReactiveUIExt.cs b/Wabbajack/Extensions/ReactiveUIExt.cs index 0f1bda7a..ac2158aa 100644 --- a/Wabbajack/Extensions/ReactiveUIExt.cs +++ b/Wabbajack/Extensions/ReactiveUIExt.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Linq.Expressions; using System.Reactive; using System.Reactive.Linq; +using System.Threading.Tasks; using DynamicData; using DynamicData.Kernel; using ReactiveUI; @@ -92,6 +93,57 @@ namespace Wabbajack .Unit(); } + public static IObservable SelectTask(this IObservable source, Func task) + { + return source + .SelectMany(async i => + { + await task(i).ConfigureAwait(false); + return System.Reactive.Unit.Default; + }); + } + + public static IObservable SelectTask(this IObservable source, Func task) + { + return source + .SelectMany(async _ => + { + await task().ConfigureAwait(false); + return System.Reactive.Unit.Default; + }); + } + + public static IObservable SelectTask(this IObservable source, Func> task) + { + return source + .SelectMany(_ => task()); + } + + public static IObservable SelectTask(this IObservable source, Func> task) + { + return source + .SelectMany(x => task(x)); + } + + public static IObservable DoTask(this IObservable source, Func task) + { + return source + .SelectMany(async (x) => + { + await task(x).ConfigureAwait(false); + return x; + }); + } + + public static IObservable WhereCastable(this IObservable source) + where R : class + where T : class + { + return source + .Select(x => x as R) + .NotNull(); + } + /// These snippets were provided by RolandPheasant (author of DynamicData) /// They'll be going into the official library at some point, but are here for now. #region Dynamic Data EnsureUniqueChanges diff --git a/Wabbajack/Themes/Styles.xaml b/Wabbajack/Themes/Styles.xaml index 317947ac..8c5c839d 100644 --- a/Wabbajack/Themes/Styles.xaml +++ b/Wabbajack/Themes/Styles.xaml @@ -807,7 +807,7 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Wabbajack/Views/CompilerView.xaml.cs b/Wabbajack/Views/CompilerView.xaml.cs new file mode 100644 index 00000000..d1a3eab5 --- /dev/null +++ b/Wabbajack/Views/CompilerView.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 CompilerView.xaml + /// + public partial class CompilerView : UserControl + { + public CompilerView() + { + InitializeComponent(); + } + } +} diff --git a/Wabbajack/Views/InstallationView.xaml b/Wabbajack/Views/InstallationView.xaml new file mode 100644 index 00000000..8e9672c9 --- /dev/null +++ b/Wabbajack/Views/InstallationView.xaml @@ -0,0 +1,199 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Wabbajack/Views/InstallationView.xaml.cs b/Wabbajack/Views/InstallationView.xaml.cs new file mode 100644 index 00000000..08c51bcb --- /dev/null +++ b/Wabbajack/Views/InstallationView.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 InstallationView.xaml + /// + public partial class InstallationView : UserControl + { + public InstallationView() + { + InitializeComponent(); + } + } +} diff --git a/Wabbajack/Views/MainWindow.xaml b/Wabbajack/Views/MainWindow.xaml index 6d3304e9..d9a70a45 100644 --- a/Wabbajack/Views/MainWindow.xaml +++ b/Wabbajack/Views/MainWindow.xaml @@ -16,194 +16,14 @@ Style="{StaticResource {x:Type Window}}" WindowStyle="ToolWindow" mc:Ignorable="d"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + diff --git a/Wabbajack/Views/MainWindow.xaml.cs b/Wabbajack/Views/MainWindow.xaml.cs index bd500ac2..06ff272b 100644 --- a/Wabbajack/Views/MainWindow.xaml.cs +++ b/Wabbajack/Views/MainWindow.xaml.cs @@ -19,52 +19,11 @@ namespace Wabbajack public MainWindow(RunMode mode, string source) { - var args = Environment.GetCommandLineArgs(); - InitializeComponent(); - this._mwvm = new MainWindowVM(mode); - var context = _mwvm.AppState; + _mwvm = new MainWindowVM(mode, source, this); Utils.Log($"Wabbajack Build - {ThisAssembly.Git.Sha}"); - DataContext = _mwvm; - - new Thread(() => - { - if (mode == RunMode.Compile) - { - Utils.Log("Compiler ready to execute"); - context.Location = Path.GetDirectoryName(source); - context.LocationLabel = "MO2 Profile:"; - } - else if (mode == RunMode.Install) - { - context.UIReady = false; - context.LocationLabel = "Installation Location:"; - var modlist = Installer.LoadFromFile(source); - if (modlist == null) - { - MessageBox.Show("Invalid Modlist, or file not found.", "Invalid Modlist", MessageBoxButton.OK, - MessageBoxImage.Error); - Dispatcher.Invoke(() => - { - ExitWhenClosing = false; - var window = new ModeSelectionWindow - { - ShowActivated = true - }; - window.Show(); - Close(); - }); - } - else - { - context.ConfigureForInstall(source, modlist); - } - - } - - context.UIReady = true; - }).Start(); + this.DataContext = _mwvm; } internal bool ExitWhenClosing = true; diff --git a/Wabbajack/Views/ModlistPropertiesWindow.xaml b/Wabbajack/Views/ModlistPropertiesWindow.xaml deleted file mode 100644 index 3ca100bf..00000000 --- a/Wabbajack/Views/ModlistPropertiesWindow.xaml +++ /dev/null @@ -1,60 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Wabbajack/Views/ModlistPropertiesWindow.xaml.cs b/Wabbajack/Views/ModlistPropertiesWindow.xaml.cs deleted file mode 100644 index e3d3fa5a..00000000 --- a/Wabbajack/Views/ModlistPropertiesWindow.xaml.cs +++ /dev/null @@ -1,75 +0,0 @@ -using System; -using System.ComponentModel; -using System.Windows; -using System.Windows.Media.Imaging; -using Wabbajack.Lib; - -namespace Wabbajack -{ - /// - /// Interaction logic for ModlistPropertiesWindow.xaml - /// - public partial class ModlistPropertiesWindow : Window - { - internal string newBannerFile; - internal readonly AppState state; - internal ModlistPropertiesWindow(AppState _state) - { - InitializeComponent(); - var bannerImage = UIUtils.BitmapImageFromResource("Wabbajack.Resources.Banner_Dark.png"); - SplashScreenProperty.Source = bannerImage; - - newBannerFile = null; - state = _state; - } - - private void SetSplashScreen_Click(object sender, RoutedEventArgs e) - { - var file = UIUtils.OpenFileDialog("Banner image|*.png"); - if (file != null) - { - newBannerFile = file; - SplashScreenProperty.Source = new BitmapImage(new Uri(file)); - } - } - - private void SaveProperties_Click(object sender, RoutedEventArgs e) - { - if (state.UIReady) - { - if (newBannerFile != null) - { - BitmapImage splashScreen = new BitmapImage(new Uri(newBannerFile)); - state.newImagePath = newBannerFile; - state.Slideshow.Image = splashScreen; - } - - state.Slideshow.ModName = ModlistNameProperty.Text; - state.Slideshow.Summary = ModlistDescriptionProperty.Text; - state.Slideshow.AuthorName = ModlistAuthorProperty.Text; - state.Slideshow.NexusSiteURL = ModlistWebsiteProperty.Text; - state.readmePath = ModlistReadmeProperty.Text; - - state.ChangedProperties = true; - - Hide(); - } - } - - public bool IsClosed { get; private set; } - protected override void OnClosed(EventArgs e) - { - base.OnClosed(e); - IsClosed = true; - } - - private void ChooseReadme_Click(object sender, RoutedEventArgs e) - { - var file = UIUtils.OpenFileDialog("Readme|*.txt"); - if (file != null) - { - ModlistReadmeProperty.Text = file; - } - } - } -} diff --git a/Wabbajack/Views/SlideshowView.xaml b/Wabbajack/Views/SlideshowView.xaml index 3f72411d..f8707337 100644 --- a/Wabbajack/Views/SlideshowView.xaml +++ b/Wabbajack/Views/SlideshowView.xaml @@ -33,11 +33,11 @@