2019-08-25 23:52:03 +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-09-26 03:18:36 +00:00
|
|
|
|
using System.Linq;
|
2019-10-04 20:50:34 +00:00
|
|
|
|
using System.Net.Http;
|
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-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-09 09:15:08 +00:00
|
|
|
|
private const int MAX_CACHE_SIZE = 10;
|
|
|
|
|
|
2019-09-14 04:35:42 +00:00
|
|
|
|
private string _mo2Folder;
|
|
|
|
|
|
|
|
|
|
private ModList _modList;
|
2019-09-26 03:18:36 +00:00
|
|
|
|
|
2019-09-14 04:35:42 +00:00
|
|
|
|
private readonly DateTime _startTime;
|
|
|
|
|
|
|
|
|
|
public volatile bool Dirty;
|
|
|
|
|
|
|
|
|
|
private readonly Dispatcher dispatcher;
|
|
|
|
|
|
2019-10-09 09:18:03 +00:00
|
|
|
|
public AppState(Dispatcher d, TaskMode mode)
|
2019-07-30 21:45:04 +00:00
|
|
|
|
{
|
2019-09-26 03:18:36 +00:00
|
|
|
|
var image = new BitmapImage();
|
|
|
|
|
image.BeginInit();
|
2019-10-09 09:33:23 +00:00
|
|
|
|
image.StreamSource = Assembly.GetExecutingAssembly().GetManifestResourceStream("Wabbajack.UI.banner.png");
|
2019-09-26 03:18:36 +00:00
|
|
|
|
image.EndInit();
|
|
|
|
|
_wabbajackLogo = image;
|
|
|
|
|
_splashScreenImage = image;
|
|
|
|
|
|
2019-10-09 13:31:44 +00:00
|
|
|
|
image = new BitmapImage();
|
|
|
|
|
image.BeginInit();
|
|
|
|
|
image.StreamSource = Assembly.GetExecutingAssembly().GetManifestResourceStream("Wabbajack.UI.none.jpg");
|
|
|
|
|
image.EndInit();
|
|
|
|
|
_noneImage = image;
|
|
|
|
|
|
2019-10-07 17:49:39 +00:00
|
|
|
|
image = new BitmapImage();
|
|
|
|
|
image.BeginInit();
|
2019-10-09 09:33:23 +00:00
|
|
|
|
image.StreamSource = Assembly.GetExecutingAssembly().GetManifestResourceStream("Wabbajack.UI.Icons.next.png");
|
2019-10-07 17:49:39 +00:00
|
|
|
|
image.EndInit();
|
|
|
|
|
_nextIcon = image;
|
|
|
|
|
|
2019-09-26 03:18:36 +00:00
|
|
|
|
SetupSlideshow();
|
|
|
|
|
|
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;
|
|
|
|
|
dispatcher = d;
|
|
|
|
|
|
2019-10-07 11:48:39 +00:00
|
|
|
|
var th = new Thread(() => UpdateLoop())
|
|
|
|
|
{
|
|
|
|
|
Priority = ThreadPriority.BelowNormal,
|
|
|
|
|
IsBackground = true
|
|
|
|
|
};
|
2019-09-14 04:35:42 +00:00
|
|
|
|
th.Start();
|
2019-07-30 21:45:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-26 03:18:36 +00:00
|
|
|
|
private void SetupSlideshow()
|
|
|
|
|
{
|
2019-09-26 20:18:41 +00:00
|
|
|
|
var files = NexusApiClient.CachedSlideShow;
|
2019-09-26 03:18:36 +00:00
|
|
|
|
if (files.Any())
|
|
|
|
|
{
|
|
|
|
|
SlideShowElements = files.ToList();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Random _random = new Random();
|
2019-09-26 20:18:41 +00:00
|
|
|
|
public List<SlideShowItem> SlideShowElements = new List<SlideShowItem>();
|
2019-09-26 03:18:36 +00:00
|
|
|
|
private DateTime _lastSlideShowUpdate = new DateTime();
|
|
|
|
|
|
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-09 22:59:58 +00:00
|
|
|
|
RaisePropertyChanged();
|
|
|
|
|
RaisePropertyChanged(nameof(ShowReportButton));
|
2019-08-30 23:57:56 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-09 23:50:35 +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 22:59:58 +00:00
|
|
|
|
private ICommand _changePath;
|
2019-09-14 04:35:42 +00:00
|
|
|
|
public ICommand ChangePath
|
2019-07-22 22:17:46 +00:00
|
|
|
|
{
|
2019-09-14 04:35:42 +00:00
|
|
|
|
get
|
2019-09-04 01:43:16 +00:00
|
|
|
|
{
|
2019-09-14 04:35:42 +00:00
|
|
|
|
if (_changePath == null) _changePath = new LambdaCommand(() => true, () => ExecuteChangePath());
|
|
|
|
|
return _changePath;
|
2019-09-04 01:43:16 +00:00
|
|
|
|
}
|
2019-09-14 04:35:42 +00:00
|
|
|
|
}
|
2019-09-04 01:43:16 +00:00
|
|
|
|
|
2019-10-09 22:59:58 +00:00
|
|
|
|
private ICommand _changeDownloadPath;
|
2019-09-14 04:35:42 +00:00
|
|
|
|
public ICommand ChangeDownloadPath
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (_changeDownloadPath == null)
|
|
|
|
|
_changeDownloadPath = new LambdaCommand(() => true, () => ExecuteChangeDownloadPath());
|
|
|
|
|
return _changeDownloadPath;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-07-22 22:17:46 +00:00
|
|
|
|
|
2019-10-09 22:59:58 +00:00
|
|
|
|
private ICommand _begin;
|
2019-09-14 04:35:42 +00:00
|
|
|
|
public ICommand Begin
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (_begin == null) _begin = new LambdaCommand(() => true, () => ExecuteBegin());
|
|
|
|
|
return _begin;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-07-22 22:17:46 +00:00
|
|
|
|
|
2019-10-09 22:59:58 +00:00
|
|
|
|
private ICommand _showReportCommand;
|
2019-09-14 04:35:42 +00:00
|
|
|
|
public ICommand ShowReportCommand
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (_showReportCommand == null) _showReportCommand = new LambdaCommand(() => true, () => ShowReport());
|
|
|
|
|
return _showReportCommand;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-07-22 22:17:46 +00:00
|
|
|
|
|
2019-10-09 22:59:58 +00:00
|
|
|
|
private ICommand _visitNexusSiteCommand;
|
2019-09-26 03:18:36 +00:00
|
|
|
|
public ICommand VisitNexusSiteCommand
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (_visitNexusSiteCommand == null) _visitNexusSiteCommand = new LambdaCommand(() => true, () => VisitNexusSite());
|
|
|
|
|
return _visitNexusSiteCommand;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-07 12:02:31 +00:00
|
|
|
|
public ICommand OpenModListPropertiesCommand
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return new LambdaCommand(() => true, () => OpenModListProperties());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-07 18:03:29 +00:00
|
|
|
|
public ICommand SlideShowNextItem
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2019-10-08 14:21:51 +00:00
|
|
|
|
return new LambdaCommand(() => true, () => {
|
2019-10-08 15:54:53 +00:00
|
|
|
|
UpdateSlideShowItem(false);
|
2019-10-08 14:21:51 +00:00
|
|
|
|
});
|
2019-10-07 18:03:29 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-09 09:22:03 +00:00
|
|
|
|
private void ExecuteChangePath()
|
|
|
|
|
{
|
|
|
|
|
if (Mode == TaskMode.INSTALLING)
|
|
|
|
|
{
|
|
|
|
|
var folder = UIUtils.ShowFolderSelectionDialog("Select Installation directory");
|
|
|
|
|
if (folder != null)
|
|
|
|
|
{
|
|
|
|
|
Location = folder;
|
|
|
|
|
if (DownloadLocation == null)
|
|
|
|
|
DownloadLocation = Path.Combine(Location, "downloads");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
internal string newImagePath;
|
|
|
|
|
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-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;
|
|
|
|
|
private readonly BitmapImage _noneImage = null;
|
2019-10-08 11:34:23 +00:00
|
|
|
|
private bool _originalImage = true;
|
2019-09-26 03:18:36 +00:00
|
|
|
|
private BitmapImage _splashScreenImage = null;
|
|
|
|
|
public BitmapImage SplashScreenImage
|
|
|
|
|
{
|
|
|
|
|
get => _splashScreenImage;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_splashScreenImage = value;
|
2019-10-09 22:59:58 +00:00
|
|
|
|
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-07 15:52:31 +00:00
|
|
|
|
private bool _splashShowNSFW = true;
|
|
|
|
|
public bool SplashShowNSFW { get => _splashShowNSFW; set => this.RaiseAndSetIfChanged(ref _splashShowNSFW, value); }
|
2019-10-08 11:34:23 +00:00
|
|
|
|
internal Thread slideshowThread = null;
|
|
|
|
|
internal int slideshowSleepTime = 1000;
|
2019-10-08 15:54:53 +00:00
|
|
|
|
private bool _enableSlideShow = true;
|
|
|
|
|
public bool EnableSlideShow
|
|
|
|
|
{
|
|
|
|
|
get => _enableSlideShow;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
RaiseAndSetIfChanged(ref _enableSlideShow, value);
|
|
|
|
|
if (!_enableSlideShow)
|
|
|
|
|
{
|
|
|
|
|
if (slideshowThread.IsAlive)
|
|
|
|
|
{
|
|
|
|
|
ApplyModlistProperties();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
UpdateSlideShowItem(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
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-09 09:18:03 +00:00
|
|
|
|
else if (Mode == TaskMode.BUILDING && Location != null && Directory.Exists(Location) && File.Exists(Path.Combine(Location, "modlist.txt")))
|
2019-09-26 14:35:34 +00:00
|
|
|
|
{
|
|
|
|
|
Location = Path.Combine(Location, "modlist.txt");
|
|
|
|
|
validationMessage = null;
|
|
|
|
|
ConfigureForBuild();
|
|
|
|
|
}
|
2019-10-09 09:18:03 +00:00
|
|
|
|
else if (Mode == TaskMode.INSTALLING && Location != null && Directory.Exists(Location) && !Directory.EnumerateFileSystemEntries(Location).Any())
|
2019-10-05 15:05:51 +00:00
|
|
|
|
{
|
|
|
|
|
validationMessage = null;
|
|
|
|
|
}
|
2019-10-09 09:18:03 +00:00
|
|
|
|
else if (Mode == TaskMode.INSTALLING && Location != null && Directory.Exists(Location) && Directory.EnumerateFileSystemEntries(Location).Any())
|
2019-10-05 15:05:51 +00:00
|
|
|
|
{
|
|
|
|
|
validationMessage = "You have selected a non-empty directory. Installing the modlist here might result in a broken install!";
|
|
|
|
|
}
|
2019-09-26 14:35:34 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
validationMessage = "Invalid Mod Organizer profile directory";
|
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
var data = InternalStatus.ToArray();
|
|
|
|
|
dispatcher.Invoke(() =>
|
|
|
|
|
{
|
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-09 13:31:44 +00:00
|
|
|
|
if (slidesQueue.Any())
|
2019-09-26 03:18:36 +00:00
|
|
|
|
{
|
|
|
|
|
if (DateTime.Now - _lastSlideShowUpdate > TimeSpan.FromSeconds(10))
|
|
|
|
|
{
|
2019-10-08 15:54:53 +00:00
|
|
|
|
UpdateSlideShowItem(true);
|
2019-10-08 11:34:23 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Thread.Sleep(1000);
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-10-08 15:54:53 +00:00
|
|
|
|
private void UpdateSlideShowItem(bool fromLoop)
|
2019-10-08 11:34:23 +00:00
|
|
|
|
{
|
|
|
|
|
if (EnableSlideShow)
|
|
|
|
|
{
|
|
|
|
|
SlideShowItem element = slidesQueue.Peek();
|
2019-10-09 13:31:44 +00:00
|
|
|
|
if(element.ImageURL == null)
|
2019-10-08 11:34:23 +00:00
|
|
|
|
{
|
2019-10-09 13:31:44 +00:00
|
|
|
|
SplashScreenImage = _noneImage;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
string cachePath = Path.Combine(SlideshowCacheDir, element.ModID + ".slideshowcache");
|
|
|
|
|
if (!element.Adult || (element.Adult && SplashShowNSFW))
|
|
|
|
|
{
|
|
|
|
|
dispatcher.Invoke(() => {
|
|
|
|
|
// max cached files achieved
|
|
|
|
|
if (cachedSlides.Count == MAX_CACHE_SIZE)
|
2019-10-08 16:34:48 +00:00
|
|
|
|
{
|
2019-10-09 13:31:44 +00:00
|
|
|
|
if (File.Exists(cachePath) && !IsFileLocked(cachePath))
|
|
|
|
|
{
|
|
|
|
|
File.Delete(cachePath);
|
|
|
|
|
cachedSlides.RemoveAt(0);
|
|
|
|
|
}
|
2019-10-08 16:34:48 +00:00
|
|
|
|
}
|
2019-10-09 13:31:44 +00:00
|
|
|
|
var data = new MemoryStream();
|
|
|
|
|
if (!IsFileLocked(cachePath))
|
|
|
|
|
{
|
|
|
|
|
using (var stream = new FileStream(cachePath, FileMode.Open, FileAccess.Read))
|
|
|
|
|
stream.CopyTo(data);
|
|
|
|
|
|
|
|
|
|
data.Seek(0, SeekOrigin.Begin);
|
|
|
|
|
|
|
|
|
|
var bitmap = new BitmapImage();
|
|
|
|
|
bitmap.BeginInit();
|
|
|
|
|
bitmap.CacheOption = BitmapCacheOption.OnLoad;
|
|
|
|
|
bitmap.StreamSource = data;
|
|
|
|
|
bitmap.EndInit();
|
|
|
|
|
|
|
|
|
|
SplashScreenImage = bitmap;
|
|
|
|
|
_originalImage = false;
|
|
|
|
|
SplashScreenModName = element.ModName;
|
|
|
|
|
SplashScreenAuthorName = element.AuthorName;
|
|
|
|
|
SplashScreenSummary = element.ModSummary;
|
|
|
|
|
_nexusSiteURL = element.ModURL;
|
|
|
|
|
|
|
|
|
|
if (fromLoop)
|
|
|
|
|
_lastSlideShowUpdate = DateTime.Now;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2019-09-26 03:18:36 +00:00
|
|
|
|
}
|
2019-10-08 11:34:23 +00:00
|
|
|
|
slidesQueue.Dequeue();
|
2019-10-08 15:54:53 +00:00
|
|
|
|
QueueRandomSlide(false, true);
|
2019-10-08 11:34:23 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-09-26 03:18:36 +00:00
|
|
|
|
|
2019-10-08 11:34:23 +00:00
|
|
|
|
private string SlideshowCacheDir;
|
|
|
|
|
private List<string> cachedSlides;
|
|
|
|
|
private Queue<SlideShowItem> slidesQueue;
|
2019-10-08 15:54:53 +00:00
|
|
|
|
private SlideShowItem lastSlide;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Caches a slide
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="url">The url</param>
|
|
|
|
|
/// <param name="dest">The destination</param>
|
2019-10-08 11:34:23 +00:00
|
|
|
|
private void CacheSlide(string url, string dest)
|
|
|
|
|
{
|
2019-10-08 16:21:16 +00:00
|
|
|
|
bool sync = false;
|
2019-10-08 11:34:23 +00:00
|
|
|
|
dispatcher.Invoke(() => {
|
|
|
|
|
var file = new FileStream(dest, FileMode.Create, FileAccess.Write);
|
2019-10-08 16:21:16 +00:00
|
|
|
|
if (sync)
|
|
|
|
|
{
|
|
|
|
|
using (var stream = new HttpClient().GetStreamSync(url))
|
|
|
|
|
stream.CopyTo(file);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
using (var stream = new HttpClient().GetStreamAsync(url))
|
|
|
|
|
{
|
|
|
|
|
stream.Wait();
|
|
|
|
|
stream.Result.CopyTo(file);
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-10-08 11:34:23 +00:00
|
|
|
|
});
|
|
|
|
|
}
|
2019-10-08 15:54:53 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Queues a random slide
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="init">Only used if called from the Preloadfunction</param>
|
|
|
|
|
/// <param name="checkLast">If to not queue the same thing again</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
private bool QueueRandomSlide(bool init, bool checkLast)
|
2019-10-08 11:34:23 +00:00
|
|
|
|
{
|
|
|
|
|
bool result = false;
|
|
|
|
|
var idx = _random.Next(0, SlideShowElements.Count);
|
|
|
|
|
var element = SlideShowElements[idx];
|
2019-10-08 15:54:53 +00:00
|
|
|
|
if (checkLast)
|
|
|
|
|
{
|
|
|
|
|
while(element == lastSlide && (!element.Adult || (element.Adult && SplashShowNSFW)))
|
|
|
|
|
{
|
|
|
|
|
idx = _random.Next(0, SlideShowElements.Count);
|
|
|
|
|
element = SlideShowElements[idx];
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-10-09 12:44:36 +00:00
|
|
|
|
|
2019-10-09 13:31:44 +00:00
|
|
|
|
string id = element.ModID;
|
|
|
|
|
string cacheFile = Path.Combine(SlideshowCacheDir, id + ".slideshowcache");
|
|
|
|
|
|
|
|
|
|
if(element.ImageURL == null)
|
|
|
|
|
{
|
|
|
|
|
if(!init)
|
|
|
|
|
slidesQueue.Enqueue(element);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-10-09 12:44:36 +00:00
|
|
|
|
// if the file doesen't exist, we cache it and add it to the cachedSlide list and to the
|
|
|
|
|
// slidesQueue
|
|
|
|
|
// return true for the PreloadSlideshow
|
|
|
|
|
if (!File.Exists(cacheFile))
|
|
|
|
|
{
|
|
|
|
|
CacheSlide(element.ImageURL, cacheFile);
|
|
|
|
|
cachedSlides.Add(id);
|
2019-10-08 15:54:53 +00:00
|
|
|
|
slidesQueue.Enqueue(element);
|
2019-10-09 12:44:36 +00:00
|
|
|
|
result = true;
|
|
|
|
|
}
|
|
|
|
|
// if the file exists and was not called from preloadslideshow, we queue the slide
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (!init)
|
|
|
|
|
slidesQueue.Enqueue(element);
|
|
|
|
|
}
|
|
|
|
|
// set the last element to the current element after queueing
|
|
|
|
|
lastSlide = element;
|
2019-10-08 15:54:53 +00:00
|
|
|
|
}
|
2019-10-08 11:34:23 +00:00
|
|
|
|
return result;
|
2019-07-22 22:17:46 +00:00
|
|
|
|
}
|
2019-10-08 15:54:53 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Caches 3 random images and puts them in the queue
|
|
|
|
|
/// </summary>
|
2019-10-08 11:34:23 +00:00
|
|
|
|
private void PreloadSlideshow()
|
|
|
|
|
{
|
|
|
|
|
cachedSlides = new List<string>();
|
|
|
|
|
slidesQueue = new Queue<SlideShowItem>();
|
2019-07-22 22:17:46 +00:00
|
|
|
|
|
2019-10-08 11:34:23 +00:00
|
|
|
|
if (!Directory.Exists(SlideshowCacheDir))
|
|
|
|
|
Directory.CreateDirectory(SlideshowCacheDir);
|
|
|
|
|
|
|
|
|
|
int turns = 0;
|
|
|
|
|
for(int i = 0; i < SlideShowElements.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
if (turns >= 3)
|
|
|
|
|
break;
|
|
|
|
|
|
2019-10-08 15:54:53 +00:00
|
|
|
|
if (QueueRandomSlide(true, false))
|
2019-10-08 11:34:23 +00:00
|
|
|
|
turns++;
|
|
|
|
|
else
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-10-08 15:54:53 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Deletes the slideshow cache
|
|
|
|
|
/// </summary>
|
2019-10-08 11:34:23 +00:00
|
|
|
|
private void DeleteCache()
|
|
|
|
|
{
|
|
|
|
|
if (Directory.Exists(SlideshowCacheDir))
|
|
|
|
|
{
|
|
|
|
|
foreach (string s in Directory.GetFiles(SlideshowCacheDir))
|
|
|
|
|
File.Delete(s);
|
2019-10-08 16:34:48 +00:00
|
|
|
|
//Directory.Delete(SlideshowCacheDir);
|
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
|
|
|
|
{
|
|
|
|
|
SplashScreenModName = _modList.Name;
|
|
|
|
|
SplashScreenAuthorName = _modList.Author;
|
|
|
|
|
_nexusSiteURL = _modList.Website;
|
|
|
|
|
SplashScreenSummary = _modList.Description;
|
|
|
|
|
if (_modList.Image != null)
|
|
|
|
|
{
|
|
|
|
|
//TODO: if(_modList.Image != null) SplashScreenImage = _modList.Image;
|
2019-10-09 13:31:44 +00:00
|
|
|
|
SplashScreenImage = _wabbajackLogo;
|
2019-10-08 11:34:23 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (!_originalImage) {
|
2019-10-09 13:31:44 +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)
|
|
|
|
|
{
|
|
|
|
|
dispatcher.Invoke(() => Log.Add(msg));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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-09 09:22:03 +00:00
|
|
|
|
internal void ConfigureForInstall(string source, ModList modlist)
|
2019-08-30 23:57:56 +00:00
|
|
|
|
{
|
2019-10-09 09:22:03 +00:00
|
|
|
|
SlideshowCacheDir = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "slideshow_cache");
|
|
|
|
|
DeleteCache();
|
|
|
|
|
|
|
|
|
|
_modList = modlist;
|
|
|
|
|
_modListPath = source;
|
|
|
|
|
Mode = TaskMode.INSTALLING;
|
|
|
|
|
ModListName = _modList.Name;
|
|
|
|
|
HTMLReport = _modList.ReportHTML;
|
|
|
|
|
Location = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
|
|
|
|
|
|
|
|
|
ApplyModlistProperties();
|
|
|
|
|
|
|
|
|
|
SlideShowElements = modlist.Archives.OfType<NexusMod>().Select(m => new SlideShowItem
|
|
|
|
|
{
|
|
|
|
|
ModName = NexusApiUtils.FixupSummary(m.ModName),
|
|
|
|
|
AuthorName = NexusApiUtils.FixupSummary(m.Author),
|
|
|
|
|
ModSummary = NexusApiUtils.FixupSummary(m.Summary),
|
|
|
|
|
ImageURL = m.SlideShowPic,
|
|
|
|
|
ModURL = m.NexusURL,
|
|
|
|
|
Adult = m.Adult,
|
|
|
|
|
ModID = m.ModID
|
|
|
|
|
}).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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-08 11:34:23 +00:00
|
|
|
|
slideshowThread = new Thread(() => UpdateLoop())
|
2019-10-07 16:06:25 +00:00
|
|
|
|
{
|
|
|
|
|
Priority = ThreadPriority.BelowNormal,
|
|
|
|
|
IsBackground = true
|
|
|
|
|
};
|
2019-10-08 11:34:23 +00:00
|
|
|
|
slideshowThread.Start();
|
2019-10-07 11:48:39 +00:00
|
|
|
|
var installer = new Installer(_modListPath, _modList, Location)
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
DeleteCache();
|
|
|
|
|
Running = false;
|
|
|
|
|
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-07 17:16:27 +00:00
|
|
|
|
ModListImage = ChangedProperties ? newImagePath ?? null : null,
|
2019-10-07 14:44:28 +00:00
|
|
|
|
ModListWebsite = ChangedProperties ? _nexusSiteURL : 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-08 16:34:48 +00:00
|
|
|
|
|
|
|
|
|
private bool IsFileLocked(string path)
|
|
|
|
|
{
|
|
|
|
|
bool result = false;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
using (var stream = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.None))
|
|
|
|
|
{
|
|
|
|
|
result = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (IOException) { result = true; }
|
|
|
|
|
return result;
|
|
|
|
|
}
|
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
|
|
|
|
}
|