mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
85 lines
3.0 KiB
C#
85 lines
3.0 KiB
C#
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<ModlistMetadata> ModLists { get; } = new ObservableCollection<ModlistMetadata>(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: () =>
|
|
{
|
|
var path = mainVM.Settings.Installer.LastInstalledListLocation;
|
|
if (string.IsNullOrWhiteSpace(path)
|
|
|| !File.Exists(path))
|
|
{
|
|
path = UIUtils.OpenFileDialog($"*{ExtensionManager.Extension}|*{ExtensionManager.Extension}");
|
|
}
|
|
OpenInstaller(path);
|
|
});
|
|
|
|
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.TargetPath = 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;
|
|
}
|
|
}
|
|
}
|