2019-10-12 03:07:57 +00:00
|
|
|
using ReactiveUI;
|
2019-10-11 22:18:51 +00:00
|
|
|
using System;
|
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 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-09-26 20:18:41 +00:00
|
|
|
using Wabbajack.NexusApi;
|
2019-10-11 10:14:01 +00:00
|
|
|
using Wabbajack.UI;
|
2019-07-22 22:17:46 +00:00
|
|
|
|
|
|
|
namespace Wabbajack
|
|
|
|
{
|
2019-10-09 09:18:03 +00:00
|
|
|
public enum TaskMode { INSTALLING, BUILDING }
|
2019-10-09 22:59:58 +00:00
|
|
|
internal class AppState : ViewModel, IDataErrorInfo
|
2019-07-22 22:17:46 +00:00
|
|
|
{
|
2019-10-11 10:14:01 +00:00
|
|
|
public const bool GcCollect = true;
|
2019-10-11 08:53:12 +00:00
|
|
|
|
2019-10-11 10:14:01 +00:00
|
|
|
private SlideShow _slideShow;
|
|
|
|
|
|
|
|
public bool installing = false;
|
2019-10-09 09:15:08 +00:00
|
|
|
|
2019-09-14 04:35:42 +00:00
|
|
|
private string _mo2Folder;
|
|
|
|
|
|
|
|
private readonly DateTime _startTime;
|
|
|
|
|
|
|
|
public volatile bool Dirty;
|
|
|
|
|
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-11 22:30:12 +00:00
|
|
|
// Command properties
|
|
|
|
public IReactiveCommand ChangePathCommand => ReactiveCommand.Create(ExecuteChangePath);
|
|
|
|
public IReactiveCommand ChangeDownloadPathCommand => ReactiveCommand.Create(ExecuteChangeDownloadPath);
|
|
|
|
public IReactiveCommand BeginCommand => ReactiveCommand.Create(ExecuteBegin);
|
|
|
|
public IReactiveCommand ShowReportCommand => ReactiveCommand.Create(ShowReport);
|
|
|
|
public IReactiveCommand VisitNexusSiteCommand => ReactiveCommand.Create(VisitNexusSite);
|
2019-10-12 03:07:57 +00:00
|
|
|
public IReactiveCommand OpenReadmeCommand { get; }
|
2019-10-11 22:30:12 +00:00
|
|
|
public IReactiveCommand OpenModListPropertiesCommand => ReactiveCommand.Create(OpenModListProperties);
|
|
|
|
public IReactiveCommand SlideShowNextItemCommand { get; }
|
|
|
|
|
2019-10-11 22:34:59 +00:00
|
|
|
public AppState(TaskMode mode)
|
2019-07-30 21:45:04 +00:00
|
|
|
{
|
2019-10-11 08:53:12 +00:00
|
|
|
_wabbajackLogo = UIUtils.BitmapImageFromResource("Wabbajack.UI.banner.png");
|
|
|
|
_splashScreenImage = _wabbajackLogo;
|
|
|
|
_noneImage = UIUtils.BitmapImageFromResource("Wabbajack.UI.none.jpg");
|
|
|
|
_nextIcon = UIUtils.BitmapImageFromResource("Wabbajack.UI.Icons.next.png");
|
2019-10-07 17:49:39 +00:00
|
|
|
|
2019-10-11 10:14:01 +00:00
|
|
|
_slideShow = new SlideShow(this, true);
|
2019-10-11 22:30:12 +00:00
|
|
|
this.SlideShowNextItemCommand = ReactiveCommand.Create(_slideShow.UpdateSlideShowItem);
|
2019-09-26 03:18:36 +00:00
|
|
|
|
2019-09-14 04:35:42 +00:00
|
|
|
if (Assembly.GetEntryAssembly().Location.ToLower().Contains("\\downloads\\"))
|
|
|
|
{
|
|
|
|
MessageBox.Show(
|
2019-10-05 15:05:51 +00:00
|
|
|
"This app seems to be running inside a folder called 'Downloads', such folders are often highly monitored by antivirus software and they can often " +
|
|
|
|
"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);
|
|
|
|
}
|
|
|
|
|
|
|
|
_startTime = DateTime.Now;
|
|
|
|
|
|
|
|
Mode = mode;
|
|
|
|
Dirty = false;
|
|
|
|
|
2019-10-12 03:07:57 +00:00
|
|
|
this.OpenReadmeCommand = ReactiveCommand.Create(
|
|
|
|
execute: this.OpenReadmeWindow,
|
|
|
|
canExecute: this.WhenAny(x => x.ModList)
|
|
|
|
.Select(modList => !string.IsNullOrEmpty(modList?.Readme)));
|
|
|
|
|
2019-10-11 08:53:12 +00:00
|
|
|
slideshowThread = new Thread(UpdateLoop)
|
2019-10-07 11:48:39 +00:00
|
|
|
{
|
|
|
|
Priority = ThreadPriority.BelowNormal,
|
|
|
|
IsBackground = true
|
|
|
|
};
|
2019-10-10 12:16:14 +00:00
|
|
|
slideshowThread.Start();
|
2019-07-30 21:45:04 +00:00
|
|
|
}
|
|
|
|
|
2019-10-11 16:49:08 +00:00
|
|
|
public DateTime lastSlideShowUpdate = new DateTime();
|
2019-09-26 03:18:36 +00:00
|
|
|
|
2019-10-09 22:59:58 +00:00
|
|
|
public ObservableCollection<string> Log { get; } = new ObservableCollection<string>();
|
|
|
|
public ObservableCollection<CPUStatus> Status { get; } = new ObservableCollection<CPUStatus>();
|
2019-07-22 22:17:46 +00:00
|
|
|
|
2019-10-09 09:18:03 +00:00
|
|
|
private TaskMode _Mode;
|
|
|
|
public TaskMode Mode { get => _Mode; set => this.RaiseAndSetIfChanged(ref _Mode, value); }
|
2019-07-30 21:45:04 +00:00
|
|
|
|
2019-10-09 23:50:35 +00:00
|
|
|
private string _ModListName;
|
|
|
|
public string ModListName { get => _ModListName; set => this.RaiseAndSetIfChanged(ref _ModListName, value); }
|
2019-10-05 15:05:51 +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-08-30 23:57:56 +00:00
|
|
|
public Visibility ShowReportButton => _htmlReport == null ? Visibility.Collapsed : Visibility.Visible;
|
|
|
|
|
2019-10-09 22:59:58 +00:00
|
|
|
private string _htmlReport;
|
2019-08-30 23:57:56 +00:00
|
|
|
public string HTMLReport
|
|
|
|
{
|
2019-09-14 04:35:42 +00:00
|
|
|
get => _htmlReport;
|
2019-08-30 23:57:56 +00:00
|
|
|
set
|
|
|
|
{
|
|
|
|
_htmlReport = value;
|
2019-10-11 22:18:51 +00:00
|
|
|
this.RaisePropertyChanged();
|
|
|
|
this.RaisePropertyChanged(nameof(ShowReportButton));
|
2019-08-30 23:57:56 +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-10-09 22:59:58 +00:00
|
|
|
private List<CPUStatus> InternalStatus { get; } = new List<CPUStatus>();
|
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()
|
|
|
|
{
|
|
|
|
if (Mode == TaskMode.INSTALLING)
|
|
|
|
{
|
|
|
|
var folder = UIUtils.ShowFolderSelectionDialog("Select Installation directory");
|
2019-10-11 08:53:12 +00:00
|
|
|
if (folder == null) return;
|
|
|
|
Location = folder;
|
|
|
|
if (DownloadLocation == null)
|
|
|
|
DownloadLocation = Path.Combine(Location, "downloads");
|
2019-10-09 09:22:03 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var folder = UIUtils.ShowFolderSelectionDialog("Select Your MO2 profile directory");
|
|
|
|
Location = folder;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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 = "";
|
|
|
|
using (var fs = new FileStream(_modListPath, FileMode.Open, FileAccess.Read, FileShare.Read))
|
|
|
|
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
|
|
|
|
|
|
|
var viewer = new TextViewer(text, _ModListName);
|
|
|
|
viewer.Show();
|
2019-10-11 12:57:42 +00:00
|
|
|
}
|
2019-09-26 03:18:36 +00:00
|
|
|
|
2019-09-18 03:12:25 +00:00
|
|
|
private bool _uiReady = false;
|
|
|
|
public bool UIReady
|
|
|
|
{
|
|
|
|
get => _uiReady;
|
2019-10-09 22:59:58 +00:00
|
|
|
set => this.RaiseAndSetIfChanged(ref _uiReady, value);
|
2019-09-18 03:12:25 +00:00
|
|
|
}
|
|
|
|
|
2019-10-09 13:31:44 +00:00
|
|
|
private readonly BitmapImage _wabbajackLogo = null;
|
2019-10-11 10:14:01 +00:00
|
|
|
public readonly BitmapImage _noneImage = null;
|
2019-09-26 03:18:36 +00:00
|
|
|
private BitmapImage _splashScreenImage = null;
|
|
|
|
public BitmapImage SplashScreenImage
|
|
|
|
{
|
|
|
|
get => _splashScreenImage;
|
|
|
|
set
|
|
|
|
{
|
|
|
|
_splashScreenImage = value;
|
2019-10-11 22:18:51 +00:00
|
|
|
this.RaisePropertyChanged();
|
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-10-07 17:49:39 +00:00
|
|
|
private BitmapImage _nextIcon = null;
|
|
|
|
public BitmapImage NextIcon { get => _nextIcon; set => this.RaiseAndSetIfChanged(ref _nextIcon, 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-01 22:39:25 +00:00
|
|
|
private string _modListPath;
|
|
|
|
|
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-07 15:52:31 +00:00
|
|
|
public bool SplashShowNSFW { get => _splashShowNSFW; set => this.RaiseAndSetIfChanged(ref _splashShowNSFW, value); }
|
2019-10-11 10:14:01 +00:00
|
|
|
private readonly Thread slideshowThread = null;
|
2019-10-08 15:54:53 +00:00
|
|
|
private bool _enableSlideShow = true;
|
|
|
|
public bool EnableSlideShow
|
|
|
|
{
|
|
|
|
get => _enableSlideShow;
|
|
|
|
set
|
|
|
|
{
|
|
|
|
RaiseAndSetIfChanged(ref _enableSlideShow, value);
|
2019-10-11 10:14:01 +00:00
|
|
|
if (!slideshowThread.IsAlive) return;
|
|
|
|
if (!_enableSlideShow)
|
2019-10-08 15:54:53 +00:00
|
|
|
{
|
2019-10-11 10:14:01 +00:00
|
|
|
ApplyModlistProperties();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_slideShow.UpdateSlideShowItem();
|
2019-10-08 15:54:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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-11 08:53:12 +00:00
|
|
|
case TaskMode.BUILDING when Location != null && Directory.Exists(Location) && File.Exists(Path.Combine(Location, "modlist.txt")):
|
|
|
|
Location = Path.Combine(Location, "modlist.txt");
|
|
|
|
validationMessage = null;
|
|
|
|
ConfigureForBuild();
|
|
|
|
break;
|
|
|
|
case TaskMode.INSTALLING when Location != null && Directory.Exists(Location) && !Directory.EnumerateFileSystemEntries(Location).Any():
|
|
|
|
validationMessage = null;
|
|
|
|
break;
|
|
|
|
case TaskMode.INSTALLING when Location != null && Directory.Exists(Location) && Directory.EnumerateFileSystemEntries(Location).Any():
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
private void UpdateLoop()
|
|
|
|
{
|
2019-09-27 04:07:54 +00:00
|
|
|
while (Running)
|
2019-07-22 22:17:46 +00:00
|
|
|
{
|
|
|
|
if (Dirty)
|
|
|
|
lock (InternalStatus)
|
|
|
|
{
|
2019-10-11 08:53:12 +00:00
|
|
|
CPUStatus[] data = InternalStatus.ToArray();
|
2019-10-11 22:34:59 +00:00
|
|
|
Application.Current.Dispatcher.Invoke(() =>
|
2019-07-22 22:17:46 +00:00
|
|
|
{
|
2019-09-14 04:35:42 +00:00
|
|
|
for (var idx = 0; idx < data.Length; idx += 1)
|
2019-07-22 22:17:46 +00:00
|
|
|
if (idx >= Status.Count)
|
|
|
|
Status.Add(data[idx]);
|
|
|
|
else if (Status[idx] != data[idx])
|
|
|
|
Status[idx] = data[idx];
|
|
|
|
});
|
|
|
|
Dirty = false;
|
|
|
|
}
|
2019-09-14 04:35:42 +00:00
|
|
|
|
2019-10-11 10:14:01 +00:00
|
|
|
if (_slideShow.SlidesQueue.Any())
|
2019-09-26 03:18:36 +00:00
|
|
|
{
|
2019-10-11 16:49:08 +00:00
|
|
|
if (DateTime.Now - lastSlideShowUpdate > TimeSpan.FromSeconds(10))
|
2019-09-26 03:18:36 +00:00
|
|
|
{
|
2019-10-11 10:14:01 +00:00
|
|
|
_slideShow.UpdateSlideShowItem();
|
2019-10-09 13:44:25 +00:00
|
|
|
}
|
2019-10-08 16:21:16 +00:00
|
|
|
}
|
2019-10-11 16:49:08 +00:00
|
|
|
Thread.Sleep(1000);
|
2019-10-08 11:34:23 +00:00
|
|
|
}
|
|
|
|
}
|
2019-09-27 04:07:54 +00:00
|
|
|
|
2019-10-08 11:34:23 +00:00
|
|
|
public bool Running { get; set; } = true;
|
2019-10-09 09:22:03 +00:00
|
|
|
private void ApplyModlistProperties()
|
2019-10-08 11:34:23 +00:00
|
|
|
{
|
2019-10-12 03:07:57 +00:00
|
|
|
SplashScreenModName = this.ModList.Name;
|
|
|
|
SplashScreenAuthorName = this.ModList.Author;
|
|
|
|
_nexusSiteURL = this.ModList.Website;
|
|
|
|
SplashScreenSummary = this.ModList.Description;
|
|
|
|
if (!string.IsNullOrEmpty(this.ModList.Image) && this.ModList.Image.Length == 36)
|
2019-10-08 11:34:23 +00:00
|
|
|
{
|
2019-10-09 13:31:44 +00:00
|
|
|
SplashScreenImage = _wabbajackLogo;
|
2019-10-11 11:15:54 +00:00
|
|
|
using (var fs = new FileStream(_modListPath, FileMode.Open, FileAccess.Read, FileShare.Read))
|
|
|
|
using (var ar = new ZipArchive(fs, ZipArchiveMode.Read))
|
|
|
|
using (var ms = new MemoryStream())
|
|
|
|
{
|
2019-10-12 03:07:57 +00:00
|
|
|
var entry = ar.GetEntry(this.ModList.Image);
|
2019-10-11 11:15:54 +00:00
|
|
|
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();
|
|
|
|
|
|
|
|
SplashScreenImage = image;
|
|
|
|
}
|
2019-10-08 11:34:23 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-10-11 11:15:54 +00:00
|
|
|
SplashScreenImage = _wabbajackLogo;
|
2019-10-08 11:34:23 +00:00
|
|
|
}
|
|
|
|
}
|
2019-07-31 03:59:19 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
public void SetProgress(int id, string msg, int progress)
|
|
|
|
{
|
|
|
|
lock (InternalStatus)
|
|
|
|
{
|
|
|
|
Dirty = true;
|
2019-09-14 04:35:42 +00:00
|
|
|
while (id >= InternalStatus.Count) InternalStatus.Add(new CPUStatus());
|
2019-07-22 22:17:46 +00:00
|
|
|
|
2019-10-09 22:59:58 +00:00
|
|
|
InternalStatus[id] = new CPUStatus { ID = id, Msg = msg, Progress = progress };
|
2019-07-22 22:17:46 +00:00
|
|
|
}
|
|
|
|
}
|
2019-07-31 03:59:19 +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);
|
|
|
|
ModListName = profile_name;
|
2019-10-09 09:18:03 +00:00
|
|
|
Mode = TaskMode.BUILDING;
|
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-09 09:22:03 +00:00
|
|
|
_modListPath = source;
|
|
|
|
Mode = TaskMode.INSTALLING;
|
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);
|
|
|
|
|
|
|
|
ApplyModlistProperties();
|
|
|
|
|
2019-10-11 10:14:01 +00:00
|
|
|
_slideShow.SlideShowElements = modlist.Archives.OfType<NexusMod>().Select(m =>
|
|
|
|
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-11 10:14:01 +00:00
|
|
|
_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-09 09:18:03 +00:00
|
|
|
if (Mode == TaskMode.INSTALLING)
|
2019-07-31 03:59:19 +00:00
|
|
|
{
|
2019-10-10 12:16:14 +00:00
|
|
|
installing = true;
|
2019-10-12 03:07:57 +00:00
|
|
|
var installer = new Installer(_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-08 11:34:23 +00:00
|
|
|
Running = false;
|
2019-10-10 12:16:14 +00:00
|
|
|
installing = false;
|
2019-10-08 11:34:23 +00:00
|
|
|
slideshowThread.Abort();
|
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
|
|
|
}
|