mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Lots of compiler backend changes to support multiple
CompilerVM is lightweight now, with sub view models per mod manager mode
This commit is contained in:
parent
6aa2908078
commit
b31f336ddb
@ -173,5 +173,16 @@ namespace Wabbajack
|
||||
{
|
||||
return source.Select(x => !x);
|
||||
}
|
||||
|
||||
public static IObservable<(T Previous, T Current)> Pairwise<T>(this IObservable<T> source)
|
||||
{
|
||||
T prevStorage = default;
|
||||
return source.Select(i =>
|
||||
{
|
||||
var prev = prevStorage;
|
||||
prevStorage = i;
|
||||
return (prev, i);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ using System.Reactive.Subjects;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Wabbajack.Common;
|
||||
|
||||
namespace Wabbajack
|
||||
{
|
||||
@ -22,10 +23,8 @@ namespace Wabbajack
|
||||
public double PosY { get; set; }
|
||||
public double Height { get; set; }
|
||||
public double Width { get; set; }
|
||||
public string LastInstalledListLocation { get; set; }
|
||||
public Dictionary<string, InstallationSettings> InstallationSettings { get; } = new Dictionary<string, InstallationSettings>();
|
||||
public string LastCompiledProfileLocation { get; set; }
|
||||
public Dictionary<string, CompilationSettings> CompilationSettings { get; } = new Dictionary<string, CompilationSettings>();
|
||||
public InstallerSettings Installer { get; set; } = new InstallerSettings();
|
||||
public CompilerSettings Compiler { get; set; } = new CompilerSettings();
|
||||
|
||||
[JsonIgnoreAttribute]
|
||||
private Subject<Unit> _saveSignal = new Subject<Unit>();
|
||||
@ -50,14 +49,27 @@ namespace Wabbajack
|
||||
}
|
||||
}
|
||||
|
||||
public class InstallationSettings
|
||||
public class InstallerSettings
|
||||
{
|
||||
public string LastInstalledListLocation { get; set; }
|
||||
public Dictionary<string, ModlistInstallationSettings> ModlistSettings { get; } = new Dictionary<string, ModlistInstallationSettings>();
|
||||
}
|
||||
|
||||
public class ModlistInstallationSettings
|
||||
{
|
||||
public string InstallationLocation { get; set; }
|
||||
public string StagingLocation { get; set; }
|
||||
public string DownloadLocation { get; set; }
|
||||
}
|
||||
|
||||
public class CompilationSettings
|
||||
public class CompilerSettings
|
||||
{
|
||||
public ModManager LastCompiledModManager { get; set; }
|
||||
public MO2CompilationSettings MO2Compilation { get; } = new MO2CompilationSettings();
|
||||
public VortexCompilationSettings VortexCompilation { get; } = new VortexCompilationSettings();
|
||||
}
|
||||
|
||||
public class CompilationModlistSettings
|
||||
{
|
||||
public string ModListName { get; set; }
|
||||
public string Author { get; set; }
|
||||
@ -65,6 +77,19 @@ namespace Wabbajack
|
||||
public string Website { get; set; }
|
||||
public string Readme { get; set; }
|
||||
public string SplashScreen { get; set; }
|
||||
}
|
||||
|
||||
public class MO2CompilationSettings
|
||||
{
|
||||
public string DownloadLocation { get; set; }
|
||||
public string LastCompiledProfileLocation { get; set; }
|
||||
public Dictionary<string, CompilationModlistSettings> ModlistSettings { get; } = new Dictionary<string, CompilationModlistSettings>();
|
||||
}
|
||||
|
||||
public class VortexCompilationSettings
|
||||
{
|
||||
public string StagingLocation { get; set; }
|
||||
public Game LastCompiledGame { get; set; }
|
||||
public Dictionary<Game, CompilationModlistSettings> ModlistSettings { get; } = new Dictionary<Game, CompilationModlistSettings>();
|
||||
}
|
||||
}
|
||||
|
@ -1,251 +0,0 @@
|
||||
using Microsoft.WindowsAPICodePack.Dialogs;
|
||||
using ReactiveUI;
|
||||
using ReactiveUI.Fody.Helpers;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reactive.Disposables;
|
||||
using System.Reactive.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Media.Imaging;
|
||||
using Wabbajack.Common;
|
||||
using Wabbajack.Lib;
|
||||
|
||||
namespace Wabbajack
|
||||
{
|
||||
public enum CompilerType
|
||||
{
|
||||
MO2,
|
||||
Vortex
|
||||
}
|
||||
|
||||
public class CompilerVM : ViewModel
|
||||
{
|
||||
public MainWindowVM MWVM { get; }
|
||||
|
||||
private readonly ObservableAsPropertyHelper<string> _Mo2Folder;
|
||||
public string Mo2Folder => _Mo2Folder.Value;
|
||||
|
||||
private readonly ObservableAsPropertyHelper<string> _MOProfile;
|
||||
public string MOProfile => _MOProfile.Value;
|
||||
|
||||
[Reactive]
|
||||
public string ModListName { get; set; }
|
||||
|
||||
public FilePickerVM ModlistLocation { get; }
|
||||
|
||||
[Reactive]
|
||||
public bool Compiling { get; set; }
|
||||
|
||||
[Reactive]
|
||||
public string AuthorText { get; set; }
|
||||
|
||||
[Reactive]
|
||||
public string Description { get; set; }
|
||||
|
||||
public FilePickerVM ImagePath { get; }
|
||||
|
||||
private readonly ObservableAsPropertyHelper<BitmapImage> _Image;
|
||||
public BitmapImage Image => _Image.Value;
|
||||
|
||||
[Reactive]
|
||||
public string Website { get; set; }
|
||||
|
||||
public FilePickerVM ReadMeText { get; }
|
||||
|
||||
[Reactive]
|
||||
public string HTMLReport { get; set; }
|
||||
|
||||
public FilePickerVM DownloadLocation { get; }
|
||||
|
||||
public IReactiveCommand BeginCommand { get; }
|
||||
|
||||
[Reactive]
|
||||
public CompilerType SelectedCompilerType { get; set; }
|
||||
|
||||
public CompilerVM(MainWindowVM mainWindowVM, string source)
|
||||
{
|
||||
this.MWVM = mainWindowVM;
|
||||
this.ModlistLocation = new FilePickerVM()
|
||||
{
|
||||
TargetPath = source,
|
||||
DoExistsCheck = true,
|
||||
PathType = FilePickerVM.PathTypeOptions.File,
|
||||
PromptTitle = "Select Modlist"
|
||||
};
|
||||
this.DownloadLocation = new FilePickerVM()
|
||||
{
|
||||
DoExistsCheck = true,
|
||||
PathType = FilePickerVM.PathTypeOptions.Folder,
|
||||
PromptTitle = "Select Download Location",
|
||||
};
|
||||
this.ImagePath = new FilePickerVM()
|
||||
{
|
||||
DoExistsCheck = false,
|
||||
PathType = FilePickerVM.PathTypeOptions.File,
|
||||
Filters =
|
||||
{
|
||||
new CommonFileDialogFilter("Banner image", "*.png")
|
||||
}
|
||||
};
|
||||
this.ReadMeText = new FilePickerVM()
|
||||
{
|
||||
PathType = FilePickerVM.PathTypeOptions.File,
|
||||
DoExistsCheck = true,
|
||||
};
|
||||
|
||||
this.BeginCommand = ReactiveCommand.CreateFromTask(
|
||||
execute: this.ExecuteBegin,
|
||||
canExecute: Observable.CombineLatest(
|
||||
this.WhenAny(x => x.Compiling),
|
||||
this.WhenAny(x => x.ModlistLocation.InError),
|
||||
this.WhenAny(x => x.DownloadLocation.InError),
|
||||
resultSelector: (c, ml, down) => !c && !ml && !down)
|
||||
.ObserveOnGuiThread());
|
||||
|
||||
this._Image = this.WhenAny(x => x.ImagePath.TargetPath)
|
||||
.Select(path =>
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(path)) return UIUtils.BitmapImageFromResource("Wabbajack.Resources.Banner_Dark.png");
|
||||
if (UIUtils.TryGetBitmapImageFromFile(path, out var image))
|
||||
{
|
||||
return image;
|
||||
}
|
||||
return UIUtils.BitmapImageFromResource("Wabbajack.Resources.none.png");
|
||||
})
|
||||
.ToProperty(this, nameof(this.Image));
|
||||
|
||||
this._Mo2Folder = this.WhenAny(x => x.ModlistLocation.TargetPath)
|
||||
.Select(loc =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var profile_folder = Path.GetDirectoryName(loc);
|
||||
return Path.GetDirectoryName(Path.GetDirectoryName(profile_folder));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.ToProperty(this, nameof(this.Mo2Folder));
|
||||
this._MOProfile = this.WhenAny(x => x.ModlistLocation.TargetPath)
|
||||
.Select(loc =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var profile_folder = Path.GetDirectoryName(loc);
|
||||
return Path.GetFileName(profile_folder);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.ToProperty(this, nameof(this.MOProfile));
|
||||
|
||||
// If Mo2 folder changes and download location is empty, set it for convenience
|
||||
this.WhenAny(x => x.Mo2Folder)
|
||||
.Where(x => Directory.Exists(x))
|
||||
.Subscribe(x =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var tmp_compiler = new Compiler(this.Mo2Folder);
|
||||
this.DownloadLocation.TargetPath = tmp_compiler.MO2DownloadsFolder;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Utils.Log($"Error setting default download location {ex}");
|
||||
}
|
||||
})
|
||||
.DisposeWith(this.CompositeDisposable);
|
||||
|
||||
// Wire missing Mo2Folder to signal error state for Modlist Location
|
||||
this.ModlistLocation.AdditionalError = this.WhenAny(x => x.Mo2Folder)
|
||||
.Select<string, IErrorResponse>(moFolder =>
|
||||
{
|
||||
if (Directory.Exists(moFolder)) return ErrorResponse.Success;
|
||||
return ErrorResponse.Fail($"MO2 Folder could not be located from the given modlist location.{Environment.NewLine}Make sure your modlist is inside a valid MO2 distribution.");
|
||||
});
|
||||
|
||||
// Load settings
|
||||
CompilationSettings settings = this.MWVM.Settings.CompilationSettings.TryCreate(source);
|
||||
this.AuthorText = settings.Author;
|
||||
if (string.IsNullOrWhiteSpace(settings.ModListName))
|
||||
{
|
||||
// Set ModlistName initially off just the MO2Profile
|
||||
this.ModListName = this.MOProfile;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.ModListName = settings.ModListName;
|
||||
}
|
||||
this.Description = settings.Description;
|
||||
this.ReadMeText.TargetPath = settings.Readme;
|
||||
this.ImagePath.TargetPath = settings.SplashScreen;
|
||||
this.Website = settings.Website;
|
||||
if (!string.IsNullOrWhiteSpace(settings.DownloadLocation))
|
||||
{
|
||||
this.DownloadLocation.TargetPath = settings.DownloadLocation;
|
||||
}
|
||||
this.MWVM.Settings.SaveSignal
|
||||
.Subscribe(_ =>
|
||||
{
|
||||
settings.Author = this.AuthorText;
|
||||
settings.ModListName = this.ModListName;
|
||||
settings.Description = this.Description;
|
||||
settings.Readme = this.ReadMeText.TargetPath;
|
||||
settings.SplashScreen = this.ImagePath.TargetPath;
|
||||
settings.Website = this.Website;
|
||||
settings.DownloadLocation = this.DownloadLocation.TargetPath;
|
||||
})
|
||||
.DisposeWith(this.CompositeDisposable);
|
||||
}
|
||||
|
||||
private async Task ExecuteBegin()
|
||||
{
|
||||
Compiler compiler;
|
||||
try
|
||||
{
|
||||
compiler = new Compiler(this.Mo2Folder)
|
||||
{
|
||||
MO2Profile = this.MOProfile,
|
||||
ModListName = this.ModListName,
|
||||
ModListAuthor = this.AuthorText,
|
||||
ModListDescription = this.Description,
|
||||
ModListImage = this.ImagePath.TargetPath,
|
||||
ModListWebsite = this.Website,
|
||||
ModListReadme = this.ReadMeText.TargetPath,
|
||||
};
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
while (ex.InnerException != null) ex = ex.InnerException;
|
||||
Utils.Log($"Compiler error: {ex.ExceptionToString()}");
|
||||
return;
|
||||
}
|
||||
await Task.Run(() =>
|
||||
{
|
||||
Compiling = true;
|
||||
try
|
||||
{
|
||||
compiler.Compile();
|
||||
if (compiler.ModList?.ReportHTML != null)
|
||||
{
|
||||
this.HTMLReport = compiler.ModList.ReportHTML;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
while (ex.InnerException != null) ex = ex.InnerException;
|
||||
Utils.Log($"Compiler error: {ex.ExceptionToString()}");
|
||||
}
|
||||
finally
|
||||
{
|
||||
Compiling = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
82
Wabbajack/View Models/Compilers/CompilerVM.cs
Normal file
82
Wabbajack/View Models/Compilers/CompilerVM.cs
Normal file
@ -0,0 +1,82 @@
|
||||
using Microsoft.WindowsAPICodePack.Dialogs;
|
||||
using ReactiveUI;
|
||||
using ReactiveUI.Fody.Helpers;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reactive.Disposables;
|
||||
using System.Reactive.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Media.Imaging;
|
||||
using Wabbajack.Common;
|
||||
using Wabbajack.Lib;
|
||||
|
||||
namespace Wabbajack
|
||||
{
|
||||
public class CompilerVM : ViewModel
|
||||
{
|
||||
public MainWindowVM MWVM { get; }
|
||||
|
||||
[Reactive]
|
||||
public bool Compiling { get; set; }
|
||||
|
||||
private readonly ObservableAsPropertyHelper<BitmapImage> _Image;
|
||||
public BitmapImage Image => _Image.Value;
|
||||
|
||||
[Reactive]
|
||||
public ModManager SelectedCompilerType { get; set; }
|
||||
|
||||
private readonly ObservableAsPropertyHelper<ISubCompilerVM> _Compiler;
|
||||
public ISubCompilerVM Compiler => _Compiler.Value;
|
||||
|
||||
private readonly ObservableAsPropertyHelper<ModlistSettingsEditorVM> _CurrentModlistSettings;
|
||||
public ModlistSettingsEditorVM CurrentModlistSettings => _CurrentModlistSettings.Value;
|
||||
|
||||
public CompilerVM(MainWindowVM mainWindowVM)
|
||||
{
|
||||
this.MWVM = mainWindowVM;
|
||||
|
||||
// Load settings
|
||||
CompilerSettings settings = this.MWVM.Settings.Compiler;
|
||||
this.SelectedCompilerType = settings.LastCompiledModManager;
|
||||
this.MWVM.Settings.SaveSignal
|
||||
.Subscribe(_ =>
|
||||
{
|
||||
settings.LastCompiledModManager = this.SelectedCompilerType;
|
||||
})
|
||||
.DisposeWith(this.CompositeDisposable);
|
||||
|
||||
// Swap to proper sub VM based on selected type
|
||||
this._Compiler = this.WhenAny(x => x.SelectedCompilerType)
|
||||
.Select<ModManager, ISubCompilerVM>(type =>
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case ModManager.MO2:
|
||||
return new MO2CompilerVM(this);
|
||||
case ModManager.Vortex:
|
||||
return new VortexCompilerVM();
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.ToProperty(this, nameof(this.Compiler));
|
||||
|
||||
// Let sub VM determine what settings we're displaying and when
|
||||
this._CurrentModlistSettings = this.WhenAny(x => x.Compiler.ModlistSettings)
|
||||
.ToProperty(this, nameof(this.CurrentModlistSettings));
|
||||
|
||||
this._Image = this.WhenAny(x => x.CurrentModlistSettings.ImagePath.TargetPath)
|
||||
.Select(path =>
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(path)) return UIUtils.BitmapImageFromResource("Wabbajack.Resources.Banner_Dark.png");
|
||||
if (UIUtils.TryGetBitmapImageFromFile(path, out var image))
|
||||
{
|
||||
return image;
|
||||
}
|
||||
return UIUtils.BitmapImageFromResource("Wabbajack.Resources.none.png");
|
||||
})
|
||||
.ToProperty(this, nameof(this.Image));
|
||||
}
|
||||
}
|
||||
}
|
17
Wabbajack/View Models/Compilers/ISubCompilerVM.cs
Normal file
17
Wabbajack/View Models/Compilers/ISubCompilerVM.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using ReactiveUI;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace Wabbajack
|
||||
{
|
||||
public interface ISubCompilerVM
|
||||
{
|
||||
IReactiveCommand BeginCommand { get; }
|
||||
bool Compiling { get; }
|
||||
ModlistSettingsEditorVM ModlistSettings { get; }
|
||||
}
|
||||
}
|
191
Wabbajack/View Models/Compilers/MO2CompilerVM.cs
Normal file
191
Wabbajack/View Models/Compilers/MO2CompilerVM.cs
Normal file
@ -0,0 +1,191 @@
|
||||
using ReactiveUI;
|
||||
using ReactiveUI.Fody.Helpers;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reactive;
|
||||
using System.Reactive.Disposables;
|
||||
using System.Reactive.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Wabbajack.Common;
|
||||
using Wabbajack.Lib;
|
||||
|
||||
namespace Wabbajack
|
||||
{
|
||||
public class MO2CompilerVM : ViewModel, ISubCompilerVM
|
||||
{
|
||||
private readonly ObservableAsPropertyHelper<string> _Mo2Folder;
|
||||
public string Mo2Folder => _Mo2Folder.Value;
|
||||
|
||||
private readonly ObservableAsPropertyHelper<string> _MOProfile;
|
||||
public string MOProfile => _MOProfile.Value;
|
||||
|
||||
public FilePickerVM DownloadLocation { get; }
|
||||
|
||||
public FilePickerVM ModlistLocation { get; }
|
||||
|
||||
public IReactiveCommand BeginCommand { get; }
|
||||
|
||||
private readonly ObservableAsPropertyHelper<bool> _Compiling;
|
||||
public bool Compiling => _Compiling.Value;
|
||||
|
||||
private readonly ObservableAsPropertyHelper<ModlistSettingsEditorVM> _ModlistSettings;
|
||||
public ModlistSettingsEditorVM ModlistSettings => _ModlistSettings.Value;
|
||||
|
||||
public MO2CompilerVM(CompilerVM parent)
|
||||
{
|
||||
this.ModlistLocation = new FilePickerVM()
|
||||
{
|
||||
DoExistsCheck = true,
|
||||
PathType = FilePickerVM.PathTypeOptions.File,
|
||||
PromptTitle = "Select Modlist"
|
||||
};
|
||||
this.DownloadLocation = new FilePickerVM()
|
||||
{
|
||||
DoExistsCheck = true,
|
||||
PathType = FilePickerVM.PathTypeOptions.Folder,
|
||||
PromptTitle = "Select Download Location",
|
||||
};
|
||||
|
||||
this._Mo2Folder = this.WhenAny(x => x.ModlistLocation.TargetPath)
|
||||
.Select(loc =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var profile_folder = Path.GetDirectoryName(loc);
|
||||
return Path.GetDirectoryName(Path.GetDirectoryName(profile_folder));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.ToProperty(this, nameof(this.Mo2Folder));
|
||||
this._MOProfile = this.WhenAny(x => x.ModlistLocation.TargetPath)
|
||||
.Select(loc =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var profile_folder = Path.GetDirectoryName(loc);
|
||||
return Path.GetFileName(profile_folder);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.ToProperty(this, nameof(this.MOProfile));
|
||||
|
||||
// If Mo2 folder changes and download location is empty, set it for convenience
|
||||
this.WhenAny(x => x.Mo2Folder)
|
||||
.Where(x => Directory.Exists(x))
|
||||
.Subscribe(x =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var tmp_compiler = new Compiler(this.Mo2Folder);
|
||||
this.DownloadLocation.TargetPath = tmp_compiler.MO2DownloadsFolder;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Utils.Log($"Error setting default download location {ex}");
|
||||
}
|
||||
})
|
||||
.DisposeWith(this.CompositeDisposable);
|
||||
|
||||
// Wire missing Mo2Folder to signal error state for Modlist Location
|
||||
this.ModlistLocation.AdditionalError = this.WhenAny(x => x.Mo2Folder)
|
||||
.Select<string, IErrorResponse>(moFolder =>
|
||||
{
|
||||
if (Directory.Exists(moFolder)) return ErrorResponse.Success;
|
||||
return ErrorResponse.Fail($"MO2 Folder could not be located from the given modlist location.{Environment.NewLine}Make sure your modlist is inside a valid MO2 distribution.");
|
||||
});
|
||||
|
||||
// Wire start command
|
||||
this.BeginCommand = ReactiveCommand.CreateFromTask(
|
||||
canExecute: Observable.CombineLatest(
|
||||
this.WhenAny(x => x.ModlistLocation.InError),
|
||||
this.WhenAny(x => x.DownloadLocation.InError),
|
||||
resultSelector: (ml, down) => !ml && !down)
|
||||
.ObserveOnGuiThread(),
|
||||
execute: async () =>
|
||||
{
|
||||
Compiler compiler;
|
||||
try
|
||||
{
|
||||
compiler = new Compiler(this.Mo2Folder)
|
||||
{
|
||||
MO2Profile = this.MOProfile,
|
||||
ModListName = this.ModlistSettings.ModListName,
|
||||
ModListAuthor = this.ModlistSettings.AuthorText,
|
||||
ModListDescription = this.ModlistSettings.Description,
|
||||
ModListImage = this.ModlistSettings.ImagePath.TargetPath,
|
||||
ModListWebsite = this.ModlistSettings.Website,
|
||||
ModListReadme = this.ModlistSettings.ReadMeText.TargetPath,
|
||||
};
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
while (ex.InnerException != null) ex = ex.InnerException;
|
||||
Utils.Log($"Compiler error: {ex.ExceptionToString()}");
|
||||
return;
|
||||
}
|
||||
await Task.Run(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
compiler.Compile();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
while (ex.InnerException != null) ex = ex.InnerException;
|
||||
Utils.Log($"Compiler error: {ex.ExceptionToString()}");
|
||||
}
|
||||
});
|
||||
});
|
||||
this._Compiling = this.BeginCommand.IsExecuting
|
||||
.ToProperty(this, nameof(this.Compiling));
|
||||
|
||||
// Load settings
|
||||
var settings = parent.MWVM.Settings.Compiler.MO2Compilation;
|
||||
if (!string.IsNullOrWhiteSpace(settings.DownloadLocation))
|
||||
{
|
||||
this.DownloadLocation.TargetPath = settings.DownloadLocation;
|
||||
}
|
||||
parent.MWVM.Settings.SaveSignal
|
||||
.Subscribe(_ =>
|
||||
{
|
||||
settings.DownloadLocation = this.DownloadLocation.TargetPath;
|
||||
this.ModlistSettings?.Save();
|
||||
})
|
||||
.DisposeWith(this.CompositeDisposable);
|
||||
|
||||
// Load custom modlist settings per MO2 profile
|
||||
this._ModlistSettings = Observable.CombineLatest(
|
||||
this.WhenAny(x => x.ModlistLocation.ErrorState),
|
||||
this.WhenAny(x => x.ModlistLocation.TargetPath),
|
||||
resultSelector: (State, Path) => (State, Path))
|
||||
// A short throttle is a quick hack to make the above changes "atomic"
|
||||
.Throttle(TimeSpan.FromMilliseconds(25))
|
||||
.Select(u =>
|
||||
{
|
||||
if (u.State.Failed) return null;
|
||||
var modlistSettings = settings.ModlistSettings.TryCreate(u.Path);
|
||||
return new ModlistSettingsEditorVM(modlistSettings, this.MOProfile);
|
||||
})
|
||||
// Interject and save old while loading new
|
||||
.Pairwise()
|
||||
.Do(pair =>
|
||||
{
|
||||
pair.Previous?.Save();
|
||||
pair.Current?.Init();
|
||||
})
|
||||
.Select(x => x.Current)
|
||||
// Save to property
|
||||
.ObserveOnGuiThread()
|
||||
.ToProperty(this, nameof(this.ModlistSettings));
|
||||
}
|
||||
}
|
||||
}
|
83
Wabbajack/View Models/Compilers/ModlistSettingsEditorVM.cs
Normal file
83
Wabbajack/View Models/Compilers/ModlistSettingsEditorVM.cs
Normal file
@ -0,0 +1,83 @@
|
||||
using Microsoft.WindowsAPICodePack.Dialogs;
|
||||
using ReactiveUI;
|
||||
using ReactiveUI.Fody.Helpers;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Media.Imaging;
|
||||
using Wabbajack.Lib;
|
||||
|
||||
namespace Wabbajack
|
||||
{
|
||||
public class ModlistSettingsEditorVM : ViewModel
|
||||
{
|
||||
private CompilationModlistSettings settings;
|
||||
private string mo2Profile;
|
||||
|
||||
[Reactive]
|
||||
public string ModListName { get; set; }
|
||||
|
||||
[Reactive]
|
||||
public string AuthorText { get; set; }
|
||||
|
||||
[Reactive]
|
||||
public string Description { get; set; }
|
||||
|
||||
public FilePickerVM ImagePath { get; }
|
||||
|
||||
public FilePickerVM ReadMeText { get; }
|
||||
|
||||
[Reactive]
|
||||
public string Website { get; set; }
|
||||
|
||||
public ModlistSettingsEditorVM(CompilationModlistSettings settings, string mo2Profile)
|
||||
{
|
||||
this.settings = settings;
|
||||
this.mo2Profile = mo2Profile;
|
||||
this.ImagePath = new FilePickerVM()
|
||||
{
|
||||
DoExistsCheck = false,
|
||||
PathType = FilePickerVM.PathTypeOptions.File,
|
||||
Filters =
|
||||
{
|
||||
new CommonFileDialogFilter("Banner image", "*.png")
|
||||
}
|
||||
};
|
||||
this.ReadMeText = new FilePickerVM()
|
||||
{
|
||||
PathType = FilePickerVM.PathTypeOptions.File,
|
||||
DoExistsCheck = true,
|
||||
};
|
||||
}
|
||||
|
||||
public void Init()
|
||||
{
|
||||
this.AuthorText = settings.Author;
|
||||
if (string.IsNullOrWhiteSpace(settings.ModListName))
|
||||
{
|
||||
// Set ModlistName initially off just the MO2Profile
|
||||
this.ModListName = mo2Profile;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.ModListName = settings.ModListName;
|
||||
}
|
||||
this.Description = settings.Description;
|
||||
this.ReadMeText.TargetPath = settings.Readme;
|
||||
this.ImagePath.TargetPath = settings.SplashScreen;
|
||||
this.Website = settings.Website;
|
||||
}
|
||||
|
||||
public void Save()
|
||||
{
|
||||
settings.Author = this.AuthorText;
|
||||
settings.ModListName = this.ModListName;
|
||||
settings.Description = this.Description;
|
||||
settings.Readme = this.ReadMeText.TargetPath;
|
||||
settings.SplashScreen = this.ImagePath.TargetPath;
|
||||
settings.Website = this.Website;
|
||||
}
|
||||
}
|
||||
}
|
19
Wabbajack/View Models/Compilers/VortexCompilerVM.cs
Normal file
19
Wabbajack/View Models/Compilers/VortexCompilerVM.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ReactiveUI;
|
||||
using Wabbajack.Lib;
|
||||
|
||||
namespace Wabbajack
|
||||
{
|
||||
public class VortexCompilerVM : ViewModel, ISubCompilerVM
|
||||
{
|
||||
public IReactiveCommand BeginCommand => throw new NotImplementedException();
|
||||
|
||||
public bool Compiling => throw new NotImplementedException();
|
||||
|
||||
public ModlistSettingsEditorVM ModlistSettings => throw new NotImplementedException();
|
||||
}
|
||||
}
|
@ -115,7 +115,7 @@ namespace Wabbajack
|
||||
.Select(x => Utils.IsDirectoryPathValid(x));
|
||||
|
||||
// Load settings
|
||||
InstallationSettings settings = this.MWVM.Settings.InstallationSettings.TryCreate(source);
|
||||
ModlistInstallationSettings settings = this.MWVM.Settings.Installer.ModlistSettings.TryCreate(source);
|
||||
this.Location.TargetPath = settings.InstallationLocation;
|
||||
this.DownloadLocation.TargetPath = settings.DownloadLocation;
|
||||
this.MWVM.Settings.SaveSignal
|
||||
|
@ -50,7 +50,7 @@ namespace Wabbajack
|
||||
this.MainWindow = mainWindow;
|
||||
this.Settings = settings;
|
||||
this._Installer = new Lazy<InstallerVM>(() => new InstallerVM(this, source));
|
||||
this._Compiler = new Lazy<CompilerVM>(() => new CompilerVM(this, source));
|
||||
this._Compiler = new Lazy<CompilerVM>(() => new CompilerVM(this));
|
||||
|
||||
// Set up logging
|
||||
Utils.LogMessages
|
||||
|
@ -6,6 +6,7 @@
|
||||
xmlns:local="clr-namespace:Wabbajack"
|
||||
xmlns:mahapps="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:wabbacommon="clr-namespace:Wabbajack.Common;assembly=Wabbajack.Common"
|
||||
d:DataContext="{d:DesignInstance local:CompilerVM}"
|
||||
d:DesignHeight="450"
|
||||
d:DesignWidth="800"
|
||||
@ -177,7 +178,7 @@
|
||||
Grid.Row="0"
|
||||
Height="35"
|
||||
Margin="4"
|
||||
IsChecked="{Binding SelectedCompilerType, Converter={StaticResource EqualsToBoolConverter}, ConverterParameter={x:Static local:CompilerType.MO2}}">
|
||||
IsChecked="{Binding SelectedCompilerType, Converter={StaticResource EqualsToBoolConverter}, ConverterParameter={x:Static wabbacommon:ModManager.MO2}}">
|
||||
<local:ImageRadioButtonView.Image>
|
||||
<BitmapImage UriSource="../Resources/MO2Button.png" />
|
||||
</local:ImageRadioButtonView.Image>
|
||||
@ -186,7 +187,7 @@
|
||||
Grid.Row="1"
|
||||
Height="35"
|
||||
Margin="4"
|
||||
IsChecked="{Binding SelectedCompilerType, Converter={StaticResource EqualsToBoolConverter}, ConverterParameter={x:Static local:CompilerType.Vortex}}">
|
||||
IsChecked="{Binding SelectedCompilerType, Converter={StaticResource EqualsToBoolConverter}, ConverterParameter={x:Static wabbacommon:ModManager.Vortex}}">
|
||||
<local:ImageRadioButtonView.Image>
|
||||
<BitmapImage UriSource="../Resources/VortexButton.png" />
|
||||
</local:ImageRadioButtonView.Image>
|
||||
|
@ -37,42 +37,37 @@ namespace Wabbajack
|
||||
|
||||
private void CreateModlist_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
OpenMainWindow(
|
||||
RunMode.Compile,
|
||||
UIUtils.OpenFileDialog(
|
||||
"MO2 Modlist(modlist.txt)|modlist.txt",
|
||||
initialDirectory: settings.LastCompiledProfileLocation));
|
||||
ShutdownOnClose = false;
|
||||
var window = new MainWindow(RunMode.Compile, null, settings);
|
||||
window.Left = this.Left;
|
||||
window.Top = this.Top;
|
||||
window.Show();
|
||||
Close();
|
||||
}
|
||||
|
||||
private void InstallModlist_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
//OpenMainWindow(
|
||||
// RunMode.Install,
|
||||
// UIUtils.OpenFileDialog($"Wabbajack Modlist (*{Consts.ModlistExtension})|*{Consts.ModlistExtension}"));
|
||||
|
||||
var result = ((ModeSelectionWindowVM)DataContext).Download();
|
||||
if (result != null)
|
||||
{
|
||||
OpenMainWindow(RunMode.Install, result);
|
||||
OpenMainWindowInstall(result);
|
||||
}
|
||||
}
|
||||
|
||||
private void OpenMainWindow(RunMode mode, string file)
|
||||
private void InstallFromList_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
OpenMainWindowInstall(
|
||||
UIUtils.OpenFileDialog(
|
||||
$"*{ExtensionManager.Extension}|*{ExtensionManager.Extension}",
|
||||
initialDirectory: settings.Installer.LastInstalledListLocation));
|
||||
}
|
||||
|
||||
private void OpenMainWindowInstall(string file)
|
||||
{
|
||||
if (file == null) return;
|
||||
ShutdownOnClose = false;
|
||||
switch (mode)
|
||||
{
|
||||
case RunMode.Compile:
|
||||
settings.LastCompiledProfileLocation = Path.GetDirectoryName(file);
|
||||
break;
|
||||
case RunMode.Install:
|
||||
settings.LastInstalledListLocation = Path.GetDirectoryName(file);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
var window = new MainWindow(mode, file, settings);
|
||||
settings.Installer.LastInstalledListLocation = Path.GetDirectoryName(file);
|
||||
var window = new MainWindow(RunMode.Install, file, settings);
|
||||
window.Left = this.Left;
|
||||
window.Top = this.Top;
|
||||
window.Show();
|
||||
@ -101,13 +96,5 @@ namespace Wabbajack
|
||||
{
|
||||
Process.Start("https://discord.gg/zgbrkmA");
|
||||
}
|
||||
|
||||
private void InstallFromList_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
OpenMainWindow(RunMode.Install,
|
||||
UIUtils.OpenFileDialog(
|
||||
$"*{ExtensionManager.Extension}|*{ExtensionManager.Extension}",
|
||||
initialDirectory: settings.LastInstalledListLocation));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -162,6 +162,10 @@
|
||||
<SubType>Designer</SubType>
|
||||
</ApplicationDefinition>
|
||||
<Compile Include="Converters\EqualsToBoolConverter.cs" />
|
||||
<Compile Include="View Models\Compilers\ISubCompilerVM.cs" />
|
||||
<Compile Include="View Models\Compilers\MO2CompilerVM.cs" />
|
||||
<Compile Include="View Models\Compilers\ModlistSettingsEditorVM.cs" />
|
||||
<Compile Include="View Models\Compilers\VortexCompilerVM.cs" />
|
||||
<Compile Include="Views\BorderFadeDownView.xaml.cs">
|
||||
<DependentUpon>BorderFadeDownView.xaml</DependentUpon>
|
||||
</Compile>
|
||||
@ -201,7 +205,7 @@
|
||||
<Compile Include="Views\InstallationView.xaml.cs">
|
||||
<DependentUpon>InstallationView.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="View Models\CompilerVM.cs" />
|
||||
<Compile Include="View Models\Compilers\CompilerVM.cs" />
|
||||
<Compile Include="View Models\MainWindowVM.cs" />
|
||||
<Compile Include="Views\LogCpuView.xaml.cs">
|
||||
<DependentUpon>LogCpuView.xaml</DependentUpon>
|
||||
|
Loading…
Reference in New Issue
Block a user