2019-10-20 11:26:42 +00:00
|
|
|
|
using Alphaleonis.Win32.Filesystem;
|
2019-11-02 23:27:23 +00:00
|
|
|
|
using ReactiveUI;
|
2019-11-02 23:23:11 +00:00
|
|
|
|
using ReactiveUI.Fody.Helpers;
|
2019-10-20 11:26:42 +00:00
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
|
using System.Linq;
|
2019-11-02 23:27:23 +00:00
|
|
|
|
using System.Reactive.Linq;
|
2019-10-20 11:26:42 +00:00
|
|
|
|
using Wabbajack.Common;
|
|
|
|
|
using Wabbajack.Lib;
|
|
|
|
|
using Wabbajack.Lib.ModListRegistry;
|
|
|
|
|
|
|
|
|
|
namespace Wabbajack.UI
|
|
|
|
|
{
|
2019-11-02 20:55:14 +00:00
|
|
|
|
public class ModeSelectionWindowVM : ViewModel
|
2019-10-20 11:26:42 +00:00
|
|
|
|
{
|
2019-11-02 20:55:14 +00:00
|
|
|
|
public ObservableCollection<ModlistMetadata> ModLists { get; } = new ObservableCollection<ModlistMetadata>(ModlistMetadata.LoadFromGithub());
|
2019-10-20 11:26:42 +00:00
|
|
|
|
|
2019-11-02 23:23:11 +00:00
|
|
|
|
[Reactive]
|
|
|
|
|
public ModlistMetadata SelectedModList { get; set; }
|
2019-10-22 12:05:57 +00:00
|
|
|
|
|
2019-11-21 15:45:00 +00:00
|
|
|
|
private readonly ObservableAsPropertyHelper<bool> _canInstall;
|
|
|
|
|
public bool CanInstall => _canInstall.Value;
|
2019-11-02 23:27:23 +00:00
|
|
|
|
|
|
|
|
|
public ModeSelectionWindowVM()
|
|
|
|
|
{
|
2019-11-21 15:45:00 +00:00
|
|
|
|
_canInstall = this.WhenAny(x => x.SelectedModList)
|
2019-11-02 23:27:23 +00:00
|
|
|
|
.Select(x => x != null)
|
2019-11-21 15:04:33 +00:00
|
|
|
|
.ToProperty(this, nameof(CanInstall));
|
2019-11-02 23:27:23 +00:00
|
|
|
|
}
|
2019-10-20 11:26:42 +00:00
|
|
|
|
|
|
|
|
|
internal string Download()
|
|
|
|
|
{
|
|
|
|
|
if (!Directory.Exists(Consts.ModListDownloadFolder))
|
|
|
|
|
Directory.CreateDirectory(Consts.ModListDownloadFolder);
|
|
|
|
|
|
2019-10-28 13:27:04 +00:00
|
|
|
|
string dest = Path.Combine(Consts.ModListDownloadFolder, SelectedModList.Links.MachineURL + ExtensionManager.Extension);
|
2019-10-20 11:26:42 +00:00
|
|
|
|
|
2019-11-08 05:19:39 +00:00
|
|
|
|
var window = new DownloadWindow(SelectedModList.Links.Download,
|
|
|
|
|
SelectedModList.Title,
|
|
|
|
|
SelectedModList.Links.DownloadMetadata?.Size ?? 0,
|
|
|
|
|
dest);
|
2019-10-20 11:26:42 +00:00
|
|
|
|
window.ShowDialog();
|
|
|
|
|
|
|
|
|
|
if (window.Result == DownloadWindow.WindowResult.Completed)
|
|
|
|
|
return dest;
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|