mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
66db4e6ddd
Log collection moved up to MainWindow. Since there will be many sub-VMs moving forward, a singleton based setup was desired. RxUI's Splat was an option, but we already had Utils.Log right there. Also now GUI printed messages will go to the log on the disk for later inspection.
93 lines
2.9 KiB
C#
93 lines
2.9 KiB
C#
using Alphaleonis.Win32.Filesystem;
|
|
using System;
|
|
using System.ComponentModel;
|
|
using System.Threading;
|
|
using System.Windows;
|
|
using Wabbajack.Common;
|
|
using Wabbajack.Lib;
|
|
using Application = System.Windows.Application;
|
|
using MessageBox = System.Windows.MessageBox;
|
|
|
|
namespace Wabbajack
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for MainWindow.xaml
|
|
/// </summary>
|
|
public partial class MainWindow : Window
|
|
{
|
|
private MainWindowVM _mwvm;
|
|
|
|
public MainWindow(RunMode mode, string source)
|
|
{
|
|
var args = Environment.GetCommandLineArgs();
|
|
|
|
InitializeComponent();
|
|
|
|
this._mwvm = new MainWindowVM(mode);
|
|
var context = _mwvm.AppState;
|
|
Utils.Log($"Wabbajack Build - {ThisAssembly.Git.Sha}");
|
|
SetupHandlers();
|
|
DataContext = _mwvm;
|
|
|
|
new Thread(() =>
|
|
{
|
|
if (mode == RunMode.Compile)
|
|
{
|
|
Utils.Log("Compiler ready to execute");
|
|
context.Location = Path.GetDirectoryName(source);
|
|
context.LocationLabel = "MO2 Profile:";
|
|
}
|
|
else if (mode == RunMode.Install)
|
|
{
|
|
context.UIReady = false;
|
|
context.LocationLabel = "Installation Location:";
|
|
var modlist = Installer.LoadFromFile(source);
|
|
if (modlist == null)
|
|
{
|
|
MessageBox.Show("Invalid Modlist, or file not found.", "Invalid Modlist", MessageBoxButton.OK,
|
|
MessageBoxImage.Error);
|
|
Dispatcher.Invoke(() =>
|
|
{
|
|
ExitWhenClosing = false;
|
|
var window = new ModeSelectionWindow
|
|
{
|
|
ShowActivated = true
|
|
};
|
|
window.Show();
|
|
Close();
|
|
});
|
|
}
|
|
else
|
|
{
|
|
context.ConfigureForInstall(source, modlist);
|
|
}
|
|
|
|
}
|
|
|
|
context.UIReady = true;
|
|
}).Start();
|
|
}
|
|
|
|
private void SetupHandlers()
|
|
{
|
|
AppDomain.CurrentDomain.UnhandledException += AppHandler;
|
|
}
|
|
|
|
private void AppHandler(object sender, UnhandledExceptionEventArgs e)
|
|
{
|
|
Utils.Log("Uncaught error:");
|
|
Utils.Log(((Exception)e.ExceptionObject).ExceptionToString());
|
|
}
|
|
|
|
internal bool ExitWhenClosing = true;
|
|
|
|
private void Window_Closing(object sender, CancelEventArgs e)
|
|
{
|
|
_mwvm.Dispose();
|
|
if (ExitWhenClosing)
|
|
{
|
|
Application.Current.Shutdown();
|
|
}
|
|
}
|
|
}
|
|
} |