2019-10-12 08:02:58 +00:00
|
|
|
|
using Syroot.Windows.IO;
|
2019-10-11 22:18:51 +00:00
|
|
|
|
using System;
|
2019-10-12 21:10:58 +00:00
|
|
|
|
using ReactiveUI;
|
2019-07-22 22:17:46 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Collections.ObjectModel;
|
2019-07-30 21:45:04 +00:00
|
|
|
|
using System.ComponentModel;
|
2019-08-30 23:57:56 +00:00
|
|
|
|
using System.Diagnostics;
|
2019-07-22 22:17:46 +00:00
|
|
|
|
using System.IO;
|
2019-10-11 11:15:54 +00:00
|
|
|
|
using System.IO.Compression;
|
2019-09-26 03:18:36 +00:00
|
|
|
|
using System.Linq;
|
2019-10-04 20:50:34 +00:00
|
|
|
|
using System.Net.Http;
|
2019-10-12 18:18:21 +00:00
|
|
|
|
using System.Reactive.Subjects;
|
2019-10-12 03:07:57 +00:00
|
|
|
|
using System.Reactive.Disposables;
|
|
|
|
|
using System.Reactive.Linq;
|
2019-07-22 22:17:46 +00:00
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Threading;
|
2019-07-31 03:59:19 +00:00
|
|
|
|
using System.Windows;
|
|
|
|
|
using System.Windows.Input;
|
2019-09-26 03:18:36 +00:00
|
|
|
|
using System.Windows.Media.Imaging;
|
2019-07-22 22:17:46 +00:00
|
|
|
|
using System.Windows.Threading;
|
|
|
|
|
using Wabbajack.Common;
|
2019-10-12 22:15:20 +00:00
|
|
|
|
using Wabbajack.Downloaders;
|
2019-09-26 20:18:41 +00:00
|
|
|
|
using Wabbajack.NexusApi;
|
2019-10-11 10:14:01 +00:00
|
|
|
|
using Wabbajack.UI;
|
2019-10-12 18:18:21 +00:00
|
|
|
|
using DynamicData;
|
|
|
|
|
using DynamicData.Binding;
|
2019-10-12 21:04:14 +00:00
|
|
|
|
using System.Reactive;
|
2019-07-22 22:17:46 +00:00
|
|
|
|
|
|
|
|
|
namespace Wabbajack
|
|
|
|
|
{
|
2019-10-12 21:04:14 +00:00
|
|
|
|
public class AppState : ViewModel, IDataErrorInfo
|
2019-07-22 22:17:46 +00:00
|
|
|
|
{
|
2019-10-13 19:12:33 +00:00
|
|
|
|
public SlideShow Slideshow { get; }
|
2019-10-11 10:14:01 +00:00
|
|
|
|
|
2019-09-14 04:35:42 +00:00
|
|
|
|
private string _mo2Folder;
|
|
|
|
|
|
2019-10-12 03:12:43 +00:00
|
|
|
|
private readonly BitmapImage _wabbajackLogo = UIUtils.BitmapImageFromResource("Wabbajack.UI.banner.png");
|
|
|
|
|
public readonly BitmapImage _noneImage = UIUtils.BitmapImageFromResource("Wabbajack.UI.none.jpg");
|
2019-09-14 04:35:42 +00:00
|
|
|
|
|
2019-10-12 18:18:21 +00:00
|
|
|
|
private readonly Subject<CPUStatus> _statusSubject = new Subject<CPUStatus>();
|
|
|
|
|
public ObservableCollectionExtended<CPUStatus> Status { get; } = new ObservableCollectionExtended<CPUStatus>();
|
2019-09-14 04:35:42 +00:00
|
|
|
|
|
2019-10-12 03:07:57 +00:00
|
|
|
|
private ModList _ModList;
|
|
|
|
|
public ModList ModList { get => _ModList; private set => this.RaiseAndSetIfChanged(ref _ModList, value); }
|
|
|
|
|
|
2019-10-12 03:12:43 +00:00
|
|
|
|
private string _ModListPath;
|
|
|
|
|
public string ModListPath { get => _ModListPath; private set => this.RaiseAndSetIfChanged(ref _ModListPath, value); }
|
|
|
|
|
|
2019-10-13 18:59:29 +00:00
|
|
|
|
private RunMode _Mode;
|
|
|
|
|
public RunMode Mode { get => _Mode; private set => this.RaiseAndSetIfChanged(ref _Mode, value); }
|
2019-10-12 03:31:33 +00:00
|
|
|
|
|
|
|
|
|
private string _ModListName;
|
|
|
|
|
public string ModListName { get => _ModListName; set => this.RaiseAndSetIfChanged(ref _ModListName, value); }
|
|
|
|
|
|
2019-10-12 03:12:43 +00:00
|
|
|
|
private bool _EnableSlideShow = true;
|
|
|
|
|
public bool EnableSlideShow { get => _EnableSlideShow; set => this.RaiseAndSetIfChanged(ref _EnableSlideShow, value); }
|
|
|
|
|
|
|
|
|
|
private BitmapImage _SplashScreenImage;
|
|
|
|
|
public BitmapImage SplashScreenImage { get => _SplashScreenImage; set => this.RaiseAndSetIfChanged(ref _SplashScreenImage, value); }
|
2019-10-12 21:04:14 +00:00
|
|
|
|
|
2019-10-12 03:12:43 +00:00
|
|
|
|
private BitmapImage _NextIcon = UIUtils.BitmapImageFromResource("Wabbajack.UI.Icons.next.png");
|
|
|
|
|
public BitmapImage NextIcon { get => _NextIcon; set => this.RaiseAndSetIfChanged(ref _NextIcon, value); }
|
|
|
|
|
|
2019-10-12 18:42:47 +00:00
|
|
|
|
private bool _UIReady;
|
|
|
|
|
public bool UIReady { get => _UIReady; set => this.RaiseAndSetIfChanged(ref _UIReady, value); }
|
|
|
|
|
|
2019-10-12 19:11:52 +00:00
|
|
|
|
private string _HTMLReport;
|
|
|
|
|
public string HTMLReport { get => _HTMLReport; set => this.RaiseAndSetIfChanged(ref _HTMLReport, value); }
|
|
|
|
|
|
2019-10-12 21:04:14 +00:00
|
|
|
|
private bool _Installing;
|
|
|
|
|
public bool Installing { get => _Installing; set => this.RaiseAndSetIfChanged(ref _Installing, value); }
|
|
|
|
|
|
2019-10-11 22:30:12 +00:00
|
|
|
|
// Command properties
|
2019-10-13 08:03:41 +00:00
|
|
|
|
public IReactiveCommand ChangePathCommand { get; }
|
|
|
|
|
public IReactiveCommand ChangeDownloadPathCommand { get; }
|
2019-10-12 18:42:47 +00:00
|
|
|
|
public IReactiveCommand BeginCommand { get; }
|
2019-10-13 08:03:41 +00:00
|
|
|
|
public IReactiveCommand ShowReportCommand { get; }
|
|
|
|
|
public IReactiveCommand VisitNexusSiteCommand { get; }
|
2019-10-12 03:07:57 +00:00
|
|
|
|
public IReactiveCommand OpenReadmeCommand { get; }
|
2019-10-13 08:03:41 +00:00
|
|
|
|
public IReactiveCommand OpenModListPropertiesCommand { get; }
|
|
|
|
|
public IReactiveCommand SlideShowNextItemCommand { get; } = ReactiveCommand.Create(() => { });
|
2019-10-11 22:30:12 +00:00
|
|
|
|
|
2019-10-13 18:59:29 +00:00
|
|
|
|
public AppState(RunMode mode)
|
2019-07-30 21:45:04 +00:00
|
|
|
|
{
|
2019-10-12 08:02:58 +00:00
|
|
|
|
if (Path.GetDirectoryName(Assembly.GetEntryAssembly().Location.ToLower()) == KnownFolders.Downloads.Path.ToLower())
|
2019-09-14 04:35:42 +00:00
|
|
|
|
{
|
|
|
|
|
MessageBox.Show(
|
2019-10-12 09:12:53 +00:00
|
|
|
|
"Wabbajack is running inside your Downloads folder. This folder is often highly monitored by antivirus software and these can often " +
|
2019-10-12 08:02:58 +00:00
|
|
|
|
"conflict with the operations Wabbajack needs to perform. Please move this executable outside of your Downloads folder and then restart the app.",
|
|
|
|
|
"Cannot run inside Downloads",
|
2019-09-14 04:35:42 +00:00
|
|
|
|
MessageBoxButton.OK,
|
|
|
|
|
MessageBoxImage.Error);
|
|
|
|
|
Environment.Exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Mode = mode;
|
|
|
|
|
|
2019-10-13 08:03:41 +00:00
|
|
|
|
// Define commands
|
|
|
|
|
this.ChangePathCommand = ReactiveCommand.Create(ExecuteChangePath);
|
|
|
|
|
this.ChangeDownloadPathCommand = ReactiveCommand.Create(ExecuteChangeDownloadPath);
|
|
|
|
|
this.ShowReportCommand = ReactiveCommand.Create(ShowReport);
|
|
|
|
|
this.VisitNexusSiteCommand = ReactiveCommand.Create(VisitNexusSite);
|
|
|
|
|
this.OpenModListPropertiesCommand = ReactiveCommand.Create(OpenModListProperties);
|
2019-10-12 03:07:57 +00:00
|
|
|
|
this.OpenReadmeCommand = ReactiveCommand.Create(
|
|
|
|
|
execute: this.OpenReadmeWindow,
|
2019-10-13 08:11:31 +00:00
|
|
|
|
canExecute: Observable.CombineLatest(
|
|
|
|
|
this.WhenAny(x => x.ModList)
|
|
|
|
|
.Select(modList => !string.IsNullOrEmpty(modList?.Readme)),
|
|
|
|
|
this.WhenAny(x => x.UIReady),
|
|
|
|
|
resultSelector: (modListExists, uiReady) => modListExists && uiReady)
|
2019-10-12 18:42:47 +00:00
|
|
|
|
.ObserveOnGuiThread());
|
|
|
|
|
this.BeginCommand = ReactiveCommand.Create(
|
|
|
|
|
execute: this.ExecuteBegin,
|
|
|
|
|
canExecute: this.WhenAny(x => x.UIReady)
|
|
|
|
|
.ObserveOnGuiThread());
|
2019-10-12 03:07:57 +00:00
|
|
|
|
|
2019-10-12 03:31:33 +00:00
|
|
|
|
// Apply modlist properties when it changes
|
|
|
|
|
this.WhenAny(x => x.ModList)
|
|
|
|
|
.NotNull()
|
|
|
|
|
.Subscribe(modList =>
|
|
|
|
|
{
|
|
|
|
|
this.SplashScreenModName = modList.Name;
|
|
|
|
|
this.SplashScreenAuthorName = modList.Author;
|
|
|
|
|
this._nexusSiteURL = modList.Website;
|
|
|
|
|
this.SplashScreenSummary = modList.Description;
|
|
|
|
|
})
|
|
|
|
|
.DisposeWith(this.CompositeDisposable);
|
|
|
|
|
|
2019-10-13 19:12:33 +00:00
|
|
|
|
this.Slideshow = new SlideShow(this);
|
2019-10-12 03:12:43 +00:00
|
|
|
|
|
|
|
|
|
// Update splashscreen when modlist changes
|
|
|
|
|
Observable.CombineLatest(
|
|
|
|
|
this.WhenAny(x => x.ModList),
|
|
|
|
|
this.WhenAny(x => x.ModListPath),
|
|
|
|
|
this.WhenAny(x => x.EnableSlideShow),
|
|
|
|
|
(modList, modListPath, enableSlideShow) => (modList, modListPath, enableSlideShow))
|
2019-10-13 06:38:51 +00:00
|
|
|
|
// Do any potential unzipping on a background thread
|
2019-10-12 03:12:43 +00:00
|
|
|
|
.ObserveOn(RxApp.TaskpoolScheduler)
|
|
|
|
|
.Select(u =>
|
|
|
|
|
{
|
|
|
|
|
if (u.enableSlideShow
|
|
|
|
|
&& u.modList != null
|
|
|
|
|
&& u.modListPath != null
|
|
|
|
|
&& File.Exists(u.modListPath)
|
|
|
|
|
&& !string.IsNullOrEmpty(u.modList.Image)
|
|
|
|
|
&& u.modList.Image.Length == 36)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
using (var fs = new FileStream(u.modListPath, FileMode.Open, FileAccess.Read, FileShare.Read))
|
|
|
|
|
using (var ar = new ZipArchive(fs, ZipArchiveMode.Read))
|
|
|
|
|
using (var ms = new MemoryStream())
|
|
|
|
|
{
|
|
|
|
|
var entry = ar.GetEntry(u.modList.Image);
|
|
|
|
|
using (var e = entry.Open())
|
|
|
|
|
e.CopyTo(ms);
|
|
|
|
|
var image = new BitmapImage();
|
|
|
|
|
image.BeginInit();
|
|
|
|
|
image.CacheOption = BitmapCacheOption.OnLoad;
|
|
|
|
|
image.StreamSource = ms;
|
|
|
|
|
image.EndInit();
|
|
|
|
|
image.Freeze();
|
|
|
|
|
|
|
|
|
|
return image;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
|
|
|
|
this.LogMsg("Error loading splash image.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return _wabbajackLogo;
|
|
|
|
|
})
|
|
|
|
|
.ObserveOn(RxApp.MainThreadScheduler)
|
|
|
|
|
.StartWith(_wabbajackLogo)
|
|
|
|
|
.Subscribe(bitmap => this.SplashScreenImage = bitmap)
|
|
|
|
|
.DisposeWith(this.CompositeDisposable);
|
|
|
|
|
|
2019-10-12 21:04:14 +00:00
|
|
|
|
/// Wire slideshow updates
|
|
|
|
|
// Merge all the sources that trigger a slideshow update
|
|
|
|
|
Observable.Merge(
|
|
|
|
|
// If the natural timer fires
|
|
|
|
|
Observable.Interval(TimeSpan.FromSeconds(10)).Unit(),
|
|
|
|
|
// If user requests one manually
|
2019-10-13 08:03:41 +00:00
|
|
|
|
this.SlideShowNextItemCommand.StartingExecution())
|
2019-10-12 21:04:14 +00:00
|
|
|
|
// When enabled, fire an initial signal
|
|
|
|
|
.StartWith(Unit.Default)
|
|
|
|
|
// Only subscribe to slideshow triggers if enabled and installing
|
|
|
|
|
.FilterSwitch(
|
|
|
|
|
Observable.CombineLatest(
|
|
|
|
|
this.WhenAny(x => x.EnableSlideShow),
|
|
|
|
|
this.WhenAny(x => x.Installing),
|
|
|
|
|
resultSelector: (enabled, installing) => enabled && installing))
|
|
|
|
|
// Don't ever update more than once every half second. ToDo: Update to debounce
|
|
|
|
|
.Throttle(TimeSpan.FromMilliseconds(500), RxApp.MainThreadScheduler)
|
|
|
|
|
.ObserveOn(RxApp.MainThreadScheduler)
|
2019-10-13 19:12:33 +00:00
|
|
|
|
.Subscribe(_ => this.Slideshow.UpdateSlideShowItem())
|
2019-10-12 03:12:43 +00:00
|
|
|
|
.DisposeWith(this.CompositeDisposable);
|
|
|
|
|
|
2019-10-12 18:18:21 +00:00
|
|
|
|
// Initialize work queue
|
|
|
|
|
WorkQueue.Init(
|
|
|
|
|
report_function: (id, msg, progress) => this._statusSubject.OnNext(new CPUStatus() { ID = id, Msg = msg, Progress = progress }),
|
|
|
|
|
report_queue_size: (max, current) => this.SetQueueSize(max, current));
|
|
|
|
|
// Compile progress updates and populate ObservableCollection
|
|
|
|
|
this._statusSubject
|
|
|
|
|
.ObserveOn(RxApp.TaskpoolScheduler)
|
|
|
|
|
.ToObservableChangeSet(x => x.ID)
|
|
|
|
|
.Batch(TimeSpan.FromMilliseconds(250))
|
|
|
|
|
.EnsureUniqueChanges()
|
|
|
|
|
.ObserveOn(RxApp.MainThreadScheduler)
|
|
|
|
|
.Sort(SortExpressionComparer<CPUStatus>.Ascending(s => s.ID), SortOptimisations.ComparesImmutableValuesOnly)
|
|
|
|
|
.Bind(this.Status)
|
|
|
|
|
.Subscribe()
|
|
|
|
|
.DisposeWith(this.CompositeDisposable);
|
2019-07-30 21:45:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-10-09 22:59:58 +00:00
|
|
|
|
public ObservableCollection<string> Log { get; } = new ObservableCollection<string>();
|
2019-07-22 22:17:46 +00:00
|
|
|
|
|
2019-10-09 23:50:35 +00:00
|
|
|
|
private string _Location;
|
|
|
|
|
public string Location { get => _Location; set => this.RaiseAndSetIfChanged(ref _Location, value); }
|
2019-07-31 03:59:19 +00:00
|
|
|
|
|
2019-10-09 23:50:35 +00:00
|
|
|
|
private string _LocationLabel;
|
|
|
|
|
public string LocationLabel { get => _LocationLabel; set => this.RaiseAndSetIfChanged(ref _LocationLabel, value); }
|
2019-10-09 22:59:58 +00:00
|
|
|
|
|
2019-10-09 23:50:35 +00:00
|
|
|
|
private string _DownloadLocation;
|
|
|
|
|
public string DownloadLocation { get => _DownloadLocation; set => this.RaiseAndSetIfChanged(ref _DownloadLocation, value); }
|
2019-09-03 22:12:39 +00:00
|
|
|
|
|
2019-10-10 12:16:14 +00:00
|
|
|
|
private int _queueProgress;
|
|
|
|
|
public int QueueProgress { get => _queueProgress; set => this.RaiseAndSetIfChanged(ref _queueProgress, value); }
|
2019-07-22 22:17:46 +00:00
|
|
|
|
|
2019-09-14 04:35:42 +00:00
|
|
|
|
public string LogFile { get; }
|
2019-07-22 22:17:46 +00:00
|
|
|
|
|
2019-10-09 09:22:03 +00:00
|
|
|
|
private void ExecuteChangePath()
|
|
|
|
|
{
|
2019-10-13 18:59:29 +00:00
|
|
|
|
switch (this.Mode)
|
2019-10-09 09:22:03 +00:00
|
|
|
|
{
|
2019-10-13 18:59:29 +00:00
|
|
|
|
case RunMode.Compile:
|
|
|
|
|
Location = UIUtils.ShowFolderSelectionDialog("Select Your MO2 profile directory");
|
|
|
|
|
break;
|
|
|
|
|
case RunMode.Install:
|
|
|
|
|
var folder = UIUtils.ShowFolderSelectionDialog("Select Installation directory");
|
|
|
|
|
if (folder == null) return;
|
|
|
|
|
Location = folder;
|
|
|
|
|
if (DownloadLocation == null)
|
|
|
|
|
{
|
|
|
|
|
DownloadLocation = Path.Combine(Location, "downloads");
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
throw new NotImplementedException();
|
2019-10-09 09:22:03 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ExecuteChangeDownloadPath()
|
|
|
|
|
{
|
|
|
|
|
var folder = UIUtils.ShowFolderSelectionDialog("Select a location for MO2 downloads");
|
|
|
|
|
if (folder != null) DownloadLocation = folder;
|
|
|
|
|
}
|
2019-09-26 03:18:36 +00:00
|
|
|
|
|
2019-10-09 09:22:03 +00:00
|
|
|
|
private void ShowReport()
|
|
|
|
|
{
|
|
|
|
|
var file = Path.GetTempFileName() + ".html";
|
|
|
|
|
File.WriteAllText(file, HTMLReport);
|
|
|
|
|
Process.Start(file);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string _nexusSiteURL = null;
|
2019-09-26 03:18:36 +00:00
|
|
|
|
private void VisitNexusSite()
|
|
|
|
|
{
|
|
|
|
|
if (_nexusSiteURL != null && _nexusSiteURL.StartsWith("https://"))
|
|
|
|
|
{
|
|
|
|
|
Process.Start(_nexusSiteURL);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-09 09:22:03 +00:00
|
|
|
|
private ModlistPropertiesWindow modlistPropertiesWindow;
|
2019-10-11 08:53:12 +00:00
|
|
|
|
public string newImagePath;
|
2019-10-11 12:57:42 +00:00
|
|
|
|
public string readmePath;
|
2019-10-09 09:22:03 +00:00
|
|
|
|
public bool ChangedProperties;
|
|
|
|
|
private void OpenModListProperties()
|
|
|
|
|
{
|
|
|
|
|
if (UIReady)
|
|
|
|
|
{
|
|
|
|
|
if (modlistPropertiesWindow == null)
|
|
|
|
|
{
|
|
|
|
|
modlistPropertiesWindow = new ModlistPropertiesWindow(this);
|
|
|
|
|
newImagePath = null;
|
|
|
|
|
ChangedProperties = false;
|
|
|
|
|
|
|
|
|
|
}
|
2019-10-09 09:45:23 +00:00
|
|
|
|
if(!modlistPropertiesWindow.IsClosed)
|
|
|
|
|
modlistPropertiesWindow.Show();
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
modlistPropertiesWindow = null;
|
|
|
|
|
OpenModListProperties();
|
|
|
|
|
}
|
2019-10-09 09:22:03 +00:00
|
|
|
|
}
|
2019-10-11 12:57:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OpenReadmeWindow()
|
|
|
|
|
{
|
2019-10-12 03:07:57 +00:00
|
|
|
|
if (!UIReady || string.IsNullOrEmpty(this.ModList.Readme)) return;
|
2019-10-11 13:06:56 +00:00
|
|
|
|
var text = "";
|
2019-10-12 03:12:43 +00:00
|
|
|
|
using (var fs = new FileStream(this.ModListPath, FileMode.Open, FileAccess.Read, FileShare.Read))
|
2019-10-11 13:06:56 +00:00
|
|
|
|
using (var ar = new ZipArchive(fs, ZipArchiveMode.Read))
|
|
|
|
|
using (var ms = new MemoryStream())
|
2019-10-11 12:57:42 +00:00
|
|
|
|
{
|
2019-10-12 03:07:57 +00:00
|
|
|
|
var entry = ar.GetEntry(this.ModList.Readme);
|
2019-10-11 13:06:56 +00:00
|
|
|
|
using (var e = entry.Open())
|
|
|
|
|
e.CopyTo(ms);
|
|
|
|
|
ms.Seek(0, SeekOrigin.Begin);
|
|
|
|
|
using (var sr = new StreamReader(ms))
|
2019-10-11 12:57:42 +00:00
|
|
|
|
{
|
2019-10-11 13:06:56 +00:00
|
|
|
|
string line;
|
|
|
|
|
while ((line = sr.ReadLine()) != null)
|
|
|
|
|
text += line+Environment.NewLine;
|
2019-10-11 12:57:42 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-10-11 13:06:56 +00:00
|
|
|
|
|
2019-10-12 03:12:43 +00:00
|
|
|
|
var viewer = new TextViewer(text, this.ModListName);
|
2019-10-11 13:06:56 +00:00
|
|
|
|
viewer.Show();
|
2019-10-11 12:57:42 +00:00
|
|
|
|
}
|
2019-09-26 03:18:36 +00:00
|
|
|
|
|
2019-10-09 23:50:35 +00:00
|
|
|
|
private string _SplashScreenModName = "Wabbajack";
|
|
|
|
|
public string SplashScreenModName { get => _SplashScreenModName; set => this.RaiseAndSetIfChanged(ref _SplashScreenModName, value); }
|
2019-09-26 03:18:36 +00:00
|
|
|
|
|
2019-10-09 23:50:35 +00:00
|
|
|
|
private string _SplashScreenAuthorName = "Halgari & the Wabbajack Team";
|
|
|
|
|
public string SplashScreenAuthorName { get => _SplashScreenAuthorName; set => this.RaiseAndSetIfChanged(ref _SplashScreenAuthorName, value); }
|
2019-09-26 03:18:36 +00:00
|
|
|
|
|
2019-10-09 23:50:35 +00:00
|
|
|
|
private string _SplashScreenSummary;
|
|
|
|
|
public string SplashScreenSummary { get => _SplashScreenSummary; set => this.RaiseAndSetIfChanged(ref _SplashScreenSummary, value); }
|
2019-10-11 17:34:22 +00:00
|
|
|
|
private bool _splashShowNSFW = false;
|
2019-10-12 21:04:14 +00:00
|
|
|
|
public bool SplashShowNSFW { get => _splashShowNSFW; set => this.RaiseAndSetIfChanged(ref _splashShowNSFW, value); }
|
2019-09-26 03:18:36 +00:00
|
|
|
|
|
2019-10-09 22:59:58 +00:00
|
|
|
|
public string Error => "Error";
|
2019-09-14 04:35:42 +00:00
|
|
|
|
|
2019-10-09 22:59:58 +00:00
|
|
|
|
public string this[string columnName] => Validate(columnName);
|
2019-09-26 14:35:34 +00:00
|
|
|
|
|
|
|
|
|
private string Validate(string columnName)
|
|
|
|
|
{
|
|
|
|
|
string validationMessage = null;
|
|
|
|
|
switch (columnName)
|
|
|
|
|
{
|
|
|
|
|
case "Location":
|
|
|
|
|
if (Location == null)
|
|
|
|
|
{
|
|
|
|
|
validationMessage = null;
|
|
|
|
|
}
|
2019-10-11 08:53:12 +00:00
|
|
|
|
else switch (Mode)
|
2019-09-26 14:35:34 +00:00
|
|
|
|
{
|
2019-10-13 18:59:29 +00:00
|
|
|
|
case RunMode.Compile when Location != null && Directory.Exists(Location) && File.Exists(Path.Combine(Location, "modlist.txt")):
|
2019-10-11 08:53:12 +00:00
|
|
|
|
Location = Path.Combine(Location, "modlist.txt");
|
|
|
|
|
validationMessage = null;
|
|
|
|
|
ConfigureForBuild();
|
|
|
|
|
break;
|
2019-10-13 18:59:29 +00:00
|
|
|
|
case RunMode.Install when Location != null && Directory.Exists(Location) && !Directory.EnumerateFileSystemEntries(Location).Any():
|
2019-10-11 08:53:12 +00:00
|
|
|
|
validationMessage = null;
|
|
|
|
|
break;
|
2019-10-13 18:59:29 +00:00
|
|
|
|
case RunMode.Install when Location != null && Directory.Exists(Location) && Directory.EnumerateFileSystemEntries(Location).Any():
|
2019-10-11 08:53:12 +00:00
|
|
|
|
validationMessage = "You have selected a non-empty directory. Installing the modlist here might result in a broken install!";
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
validationMessage = "Invalid Mod Organizer profile directory";
|
|
|
|
|
break;
|
2019-09-26 14:35:34 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return validationMessage;
|
2019-07-22 22:17:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void LogMsg(string msg)
|
|
|
|
|
{
|
2019-10-11 22:34:59 +00:00
|
|
|
|
Application.Current.Dispatcher.Invoke(() => Log.Add(msg));
|
2019-07-22 22:17:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-02 23:04:04 +00:00
|
|
|
|
public void SetQueueSize(int max, int current)
|
|
|
|
|
{
|
2019-08-22 22:05:16 +00:00
|
|
|
|
if (max == 0)
|
|
|
|
|
max = 1;
|
2019-08-02 23:04:04 +00:00
|
|
|
|
var total = current * 100 / max;
|
|
|
|
|
QueueProgress = total;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-31 03:59:19 +00:00
|
|
|
|
private void ConfigureForBuild()
|
|
|
|
|
{
|
|
|
|
|
var profile_folder = Path.GetDirectoryName(Location);
|
|
|
|
|
var mo2folder = Path.GetDirectoryName(Path.GetDirectoryName(profile_folder));
|
|
|
|
|
if (!File.Exists(Path.Combine(mo2folder, "ModOrganizer.exe")))
|
|
|
|
|
LogMsg($"Error! No ModOrganizer2.exe found in {mo2folder}");
|
|
|
|
|
|
|
|
|
|
var profile_name = Path.GetFileName(profile_folder);
|
2019-10-12 03:12:43 +00:00
|
|
|
|
this.ModListName = profile_name;
|
2019-10-13 18:59:29 +00:00
|
|
|
|
this.Mode = RunMode.Compile;
|
2019-09-03 22:12:39 +00:00
|
|
|
|
|
2019-09-26 22:32:15 +00:00
|
|
|
|
var tmp_compiler = new Compiler(mo2folder);
|
2019-09-03 22:12:39 +00:00
|
|
|
|
DownloadLocation = tmp_compiler.MO2DownloadsFolder;
|
|
|
|
|
|
2019-07-31 03:59:19 +00:00
|
|
|
|
_mo2Folder = mo2folder;
|
|
|
|
|
}
|
2019-10-11 10:14:01 +00:00
|
|
|
|
|
2019-10-09 09:22:03 +00:00
|
|
|
|
internal void ConfigureForInstall(string source, ModList modlist)
|
2019-08-30 23:57:56 +00:00
|
|
|
|
{
|
2019-10-12 03:07:57 +00:00
|
|
|
|
this.ModList = modlist;
|
2019-10-12 03:12:43 +00:00
|
|
|
|
this.ModListPath = source;
|
2019-10-13 18:59:29 +00:00
|
|
|
|
this.Mode = RunMode.Install;
|
2019-10-12 03:07:57 +00:00
|
|
|
|
ModListName = this.ModList.Name;
|
|
|
|
|
HTMLReport = this.ModList.ReportHTML;
|
2019-10-09 09:22:03 +00:00
|
|
|
|
Location = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
|
|
|
|
|
2019-10-13 19:12:33 +00:00
|
|
|
|
this.Slideshow.SlideShowElements = modlist.Archives
|
2019-10-12 22:15:20 +00:00
|
|
|
|
.Select(m => m.State)
|
|
|
|
|
.OfType<NexusDownloader.State>()
|
|
|
|
|
.Select(m =>
|
2019-10-11 10:14:01 +00:00
|
|
|
|
new Slide(NexusApiUtils.FixupSummary(m.ModName),m.ModID,
|
|
|
|
|
NexusApiUtils.FixupSummary(m.Summary), NexusApiUtils.FixupSummary(m.Author),
|
|
|
|
|
m.Adult,m.NexusURL,m.SlideShowPic)).ToList();
|
2019-10-09 09:22:03 +00:00
|
|
|
|
|
|
|
|
|
|
2019-10-13 19:12:33 +00:00
|
|
|
|
this.Slideshow.PreloadSlideShow();
|
2019-08-30 23:57:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-31 03:59:19 +00:00
|
|
|
|
private void ExecuteBegin()
|
|
|
|
|
{
|
2019-09-18 03:12:25 +00:00
|
|
|
|
UIReady = false;
|
2019-10-13 18:59:29 +00:00
|
|
|
|
if (this.Mode == RunMode.Install)
|
2019-07-31 03:59:19 +00:00
|
|
|
|
{
|
2019-10-12 21:04:14 +00:00
|
|
|
|
this.Installing = true;
|
2019-10-12 03:12:43 +00:00
|
|
|
|
var installer = new Installer(this.ModListPath, this.ModList, Location)
|
2019-10-07 11:48:39 +00:00
|
|
|
|
{
|
|
|
|
|
DownloadFolder = DownloadLocation
|
|
|
|
|
};
|
2019-07-31 03:59:19 +00:00
|
|
|
|
var th = new Thread(() =>
|
|
|
|
|
{
|
2019-09-18 03:12:25 +00:00
|
|
|
|
UIReady = false;
|
2019-07-31 03:59:19 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
installer.Install();
|
|
|
|
|
}
|
2019-08-02 22:31:13 +00:00
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2019-08-22 22:05:16 +00:00
|
|
|
|
while (ex.InnerException != null) ex = ex.InnerException;
|
2019-08-07 23:06:38 +00:00
|
|
|
|
LogMsg(ex.StackTrace);
|
2019-08-22 23:29:44 +00:00
|
|
|
|
LogMsg(ex.ToString());
|
2019-08-02 22:31:13 +00:00
|
|
|
|
LogMsg($"{ex.Message} - Can't continue");
|
2019-07-31 03:59:19 +00:00
|
|
|
|
}
|
2019-09-18 03:12:25 +00:00
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
UIReady = true;
|
2019-10-12 21:04:14 +00:00
|
|
|
|
this.Installing = false;
|
2019-09-18 03:12:25 +00:00
|
|
|
|
}
|
2019-10-07 11:48:39 +00:00
|
|
|
|
})
|
|
|
|
|
{
|
|
|
|
|
Priority = ThreadPriority.BelowNormal
|
|
|
|
|
};
|
2019-07-31 03:59:19 +00:00
|
|
|
|
th.Start();
|
|
|
|
|
}
|
2019-09-26 14:35:34 +00:00
|
|
|
|
else if (_mo2Folder != null)
|
2019-07-31 03:59:19 +00:00
|
|
|
|
{
|
2019-10-07 11:48:39 +00:00
|
|
|
|
var compiler = new Compiler(_mo2Folder)
|
|
|
|
|
{
|
2019-10-07 14:44:28 +00:00
|
|
|
|
MO2Profile = ModListName,
|
|
|
|
|
ModListName = ChangedProperties ? SplashScreenModName : null,
|
|
|
|
|
ModListAuthor = ChangedProperties ? SplashScreenAuthorName : null,
|
|
|
|
|
ModListDescription = ChangedProperties ? SplashScreenSummary : null,
|
2019-10-11 12:57:42 +00:00
|
|
|
|
ModListImage = ChangedProperties ? newImagePath : null,
|
|
|
|
|
ModListWebsite = ChangedProperties ? _nexusSiteURL : null,
|
|
|
|
|
ModListReadme = ChangedProperties ? readmePath : null
|
2019-10-07 11:48:39 +00:00
|
|
|
|
};
|
2019-07-31 03:59:19 +00:00
|
|
|
|
var th = new Thread(() =>
|
|
|
|
|
{
|
2019-09-18 03:12:25 +00:00
|
|
|
|
UIReady = false;
|
2019-08-07 23:06:38 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
compiler.Compile();
|
2019-08-30 23:57:56 +00:00
|
|
|
|
if (compiler.ModList != null && compiler.ModList.ReportHTML != null)
|
|
|
|
|
HTMLReport = compiler.ModList.ReportHTML;
|
2019-08-07 23:06:38 +00:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2019-08-22 22:05:16 +00:00
|
|
|
|
while (ex.InnerException != null) ex = ex.InnerException;
|
2019-08-07 23:06:38 +00:00
|
|
|
|
LogMsg(ex.StackTrace);
|
2019-08-22 23:29:44 +00:00
|
|
|
|
LogMsg(ex.ToString());
|
2019-08-07 23:06:38 +00:00
|
|
|
|
LogMsg($"{ex.Message} - Can't continue");
|
|
|
|
|
}
|
2019-09-18 03:12:25 +00:00
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
UIReady = true;
|
|
|
|
|
}
|
2019-10-07 11:48:39 +00:00
|
|
|
|
})
|
|
|
|
|
{
|
|
|
|
|
Priority = ThreadPriority.BelowNormal
|
|
|
|
|
};
|
2019-07-31 03:59:19 +00:00
|
|
|
|
th.Start();
|
|
|
|
|
}
|
2019-09-26 14:35:34 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Utils.Log("Cannot compile modlist: no valid Mod Organizer profile directory selected.");
|
|
|
|
|
UIReady = true;
|
|
|
|
|
}
|
2019-07-31 03:59:19 +00:00
|
|
|
|
}
|
2019-10-09 22:59:58 +00:00
|
|
|
|
}
|
2019-09-14 04:35:42 +00:00
|
|
|
|
|
2019-10-09 22:59:58 +00:00
|
|
|
|
public class CPUStatus
|
|
|
|
|
{
|
|
|
|
|
public int Progress { get; internal set; }
|
|
|
|
|
public string Msg { get; internal set; }
|
|
|
|
|
public int ID { get; internal set; }
|
|
|
|
|
}
|
2019-07-22 22:17:46 +00:00
|
|
|
|
}
|