wabbajack/Wabbajack/View Models/ModeSelectionVM.cs
2020-02-02 01:33:12 -06:00

62 lines
2.0 KiB
C#

using AutoUpdaterDotNET;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
using System;
using System.IO;
using System.Linq;
using System.Reactive;
using System.Reactive.Linq;
using System.Windows.Input;
using Wabbajack.Common;
using Wabbajack.Lib;
namespace Wabbajack
{
public class ModeSelectionVM : ViewModel
{
private MainWindowVM _mainVM;
public ICommand BrowseCommand { get; }
public ICommand InstallCommand { get; }
public ICommand CompileCommand { get; }
public ReactiveCommand<Unit, Unit> UpdateCommand { get; }
public ModeSelectionVM(MainWindowVM mainVM)
{
_mainVM = mainVM;
InstallCommand = ReactiveCommand.Create(
execute: () =>
{
var path = mainVM.Settings.Installer.LastInstalledListLocation;
if (string.IsNullOrWhiteSpace(path)
|| !File.Exists(path))
{
path = UIUtils.OpenFileDialog($"*{Consts.ModListExtension}|*{Consts.ModListExtension}");
}
_mainVM.OpenInstaller(path);
});
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.");
}
});
}
}
}