mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
107 lines
2.9 KiB
C#
107 lines
2.9 KiB
C#
using System;
|
|
using System.ComponentModel;
|
|
using System.Windows;
|
|
using MahApps.Metro.Controls;
|
|
using Wabbajack.Common;
|
|
using Application = System.Windows.Application;
|
|
using Utils = Wabbajack.Common.Utils;
|
|
|
|
namespace Wabbajack
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for MainWindow.xaml
|
|
/// </summary>
|
|
public partial class MainWindow : MetroWindow
|
|
{
|
|
private MainWindowVM _mwvm;
|
|
private MainSettings _settings;
|
|
|
|
public MainWindow()
|
|
{
|
|
// Wire any unhandled crashing exceptions to log before exiting
|
|
AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
|
|
{
|
|
// Don't do any special logging side effects
|
|
Wabbajack.Common.Utils.Error(((Exception)e.ExceptionObject), "Uncaught error");
|
|
};
|
|
|
|
var appPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
|
|
try
|
|
{
|
|
if (!ExtensionManager.IsAssociated() || ExtensionManager.NeedsUpdating(appPath))
|
|
{
|
|
ExtensionManager.Associate(appPath);
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Utils.Log($"ExtensionManager had an exception:\n{e}");
|
|
}
|
|
|
|
|
|
Wabbajack.Common.Utils.Log($"Wabbajack Build - {ThisAssembly.Git.Sha}");
|
|
|
|
// Load settings
|
|
string[] args = Environment.GetCommandLineArgs();
|
|
if ((args.Length > 1 && args[1] == "nosettings")
|
|
|| !MainSettings.TryLoadTypicalSettings(out var settings))
|
|
{
|
|
_settings = new MainSettings();
|
|
RunWhenLoaded(DefaultSettings);
|
|
}
|
|
else
|
|
{
|
|
_settings = settings;
|
|
RunWhenLoaded(LoadSettings);
|
|
}
|
|
|
|
// Set datacontext
|
|
_mwvm = new MainWindowVM(this, _settings);
|
|
DataContext = _mwvm;
|
|
}
|
|
|
|
public void Init(MainWindowVM vm, MainSettings settings)
|
|
{
|
|
DataContext = vm;
|
|
_mwvm = vm;
|
|
_settings = settings;
|
|
}
|
|
|
|
private void RunWhenLoaded(Action a)
|
|
{
|
|
if (IsLoaded)
|
|
{
|
|
a();
|
|
}
|
|
else
|
|
{
|
|
this.Loaded += (sender, e) =>
|
|
{
|
|
a();
|
|
};
|
|
}
|
|
}
|
|
|
|
private void LoadSettings()
|
|
{
|
|
Width = _settings.Width;
|
|
Height = _settings.Height;
|
|
Left = _settings.PosX;
|
|
Top = _settings.PosY;
|
|
}
|
|
|
|
private void DefaultSettings()
|
|
{
|
|
Width = 1300;
|
|
Height = 960;
|
|
Left = 15;
|
|
Top = 15;
|
|
}
|
|
|
|
private void Window_Closing(object sender, CancelEventArgs e)
|
|
{
|
|
_mwvm.ShutdownApplication();
|
|
}
|
|
}
|
|
}
|