wabbajack/Wabbajack/View Models/ModeSelectionVM.cs

62 lines
2.0 KiB
C#
Raw Normal View History

using AutoUpdaterDotNET;
using ReactiveUI;
2019-11-24 08:12:28 +00:00
using ReactiveUI.Fody.Helpers;
using System;
2020-01-10 04:27:59 +00:00
using System.IO;
2019-11-24 08:12:28 +00:00
using System.Linq;
using System.Reactive;
2019-11-24 08:12:28 +00:00
using System.Reactive.Linq;
using System.Windows.Input;
using Wabbajack.Common;
using Wabbajack.Lib;
namespace Wabbajack
{
public class ModeSelectionVM : ViewModel
{
private MainWindowVM _mainVM;
2019-11-30 09:08:04 +00:00
public ICommand BrowseCommand { get; }
2019-11-24 08:12:28 +00:00
public ICommand InstallCommand { get; }
public ICommand CompileCommand { get; }
public ReactiveCommand<Unit, Unit> UpdateCommand { get; }
2019-11-24 08:12:28 +00:00
public ModeSelectionVM(MainWindowVM mainVM)
{
_mainVM = mainVM;
2019-11-24 08:12:28 +00:00
InstallCommand = ReactiveCommand.Create(
execute: () =>
{
var path = mainVM.Settings.Installer.LastInstalledListLocation;
if (string.IsNullOrWhiteSpace(path)
|| !File.Exists(path))
{
path = UIUtils.OpenFileDialog($"*{Consts.ModListExtension}|*{Consts.ModListExtension}");
}
2019-11-30 09:08:04 +00:00
_mainVM.OpenInstaller(path);
2019-11-24 08:12:28 +00:00
});
CompileCommand = ReactiveCommand.Create(() => mainVM.NavigateTo(mainVM.Compiler.Value));
BrowseCommand = ReactiveCommand.Create(() => mainVM.NavigateTo(mainVM.Gallery.Value));
UpdateCommand = ReactiveCommand.Create(
canExecute: mainVM.WhenAny(x => x.UpdateAvailable)
.ObserveOnGuiThread(),
execute: () =>
{
try
{
if (AutoUpdater.DownloadUpdate())
{
mainVM.ShutdownApplication();
}
}
catch (Exception exception)
{
Utils.Error(exception, "Could not download update.");
}
});
2019-11-24 08:12:28 +00:00
}
}
}