2019-11-02 20:55:14 +00:00
|
|
|
|
using System;
|
2019-08-04 22:08:03 +00:00
|
|
|
|
using System.ComponentModel;
|
2019-07-22 22:17:46 +00:00
|
|
|
|
using System.Windows;
|
2019-11-25 05:43:56 +00:00
|
|
|
|
using MahApps.Metro.Controls;
|
2019-07-22 22:17:46 +00:00
|
|
|
|
using Wabbajack.Common;
|
2019-09-27 04:07:54 +00:00
|
|
|
|
using Application = System.Windows.Application;
|
2019-07-22 22:17:46 +00:00
|
|
|
|
|
|
|
|
|
namespace Wabbajack
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2019-09-14 04:35:42 +00:00
|
|
|
|
/// Interaction logic for MainWindow.xaml
|
2019-07-22 22:17:46 +00:00
|
|
|
|
/// </summary>
|
2019-11-25 05:43:56 +00:00
|
|
|
|
public partial class MainWindow : MetroWindow
|
2019-07-22 22:17:46 +00:00
|
|
|
|
{
|
2019-10-23 04:15:42 +00:00
|
|
|
|
private MainWindowVM _mwvm;
|
2019-11-06 03:22:38 +00:00
|
|
|
|
private MainSettings _settings;
|
2019-09-14 04:35:42 +00:00
|
|
|
|
|
2019-12-01 22:20:26 +00:00
|
|
|
|
internal bool ExitWhenClosing = true;
|
|
|
|
|
|
2019-11-02 20:55:14 +00:00
|
|
|
|
public MainWindow()
|
|
|
|
|
{
|
2019-12-01 22:20:26 +00:00
|
|
|
|
// 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.Log("Uncaught error:");
|
|
|
|
|
Wabbajack.Common.Utils.Log(((Exception)e.ExceptionObject).ExceptionToString());
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var appPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
|
|
|
|
|
if (!ExtensionManager.IsAssociated() || ExtensionManager.NeedsUpdating(appPath))
|
|
|
|
|
{
|
|
|
|
|
ExtensionManager.Associate(appPath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
2019-11-24 08:12:28 +00:00
|
|
|
|
_mwvm = new MainWindowVM(this, _settings);
|
2019-11-21 15:04:33 +00:00
|
|
|
|
DataContext = _mwvm;
|
2019-12-01 22:20:26 +00:00
|
|
|
|
}
|
2019-11-30 00:25:39 +00:00
|
|
|
|
|
2019-12-01 22:20:26 +00:00
|
|
|
|
public void Init(MainWindowVM vm, MainSettings settings)
|
|
|
|
|
{
|
|
|
|
|
DataContext = vm;
|
|
|
|
|
_mwvm = vm;
|
|
|
|
|
_settings = settings;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void RunWhenLoaded(Action a)
|
|
|
|
|
{
|
|
|
|
|
if (IsLoaded)
|
2019-11-30 00:25:39 +00:00
|
|
|
|
{
|
2019-12-01 22:20:26 +00:00
|
|
|
|
a();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
this.Loaded += (sender, e) =>
|
|
|
|
|
{
|
|
|
|
|
a();
|
|
|
|
|
};
|
|
|
|
|
}
|
2019-07-22 22:17:46 +00:00
|
|
|
|
}
|
2019-08-04 22:08:03 +00:00
|
|
|
|
|
2019-12-01 22:20:26 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
2019-09-27 04:07:54 +00:00
|
|
|
|
|
2019-08-04 22:08:03 +00:00
|
|
|
|
private void Window_Closing(object sender, CancelEventArgs e)
|
|
|
|
|
{
|
2019-10-23 04:15:42 +00:00
|
|
|
|
_mwvm.Dispose();
|
2019-11-30 00:25:39 +00:00
|
|
|
|
_settings.PosX = Left;
|
|
|
|
|
_settings.PosY = Top;
|
|
|
|
|
_settings.Width = Width;
|
|
|
|
|
_settings.Height = Height;
|
2019-11-21 15:04:33 +00:00
|
|
|
|
MainSettings.SaveSettings(_settings);
|
2019-09-27 04:07:54 +00:00
|
|
|
|
if (ExitWhenClosing)
|
2019-10-23 04:15:42 +00:00
|
|
|
|
{
|
2019-09-27 04:07:54 +00:00
|
|
|
|
Application.Current.Shutdown();
|
2019-10-23 04:15:42 +00:00
|
|
|
|
}
|
2019-08-04 22:08:03 +00:00
|
|
|
|
}
|
2019-07-22 22:17:46 +00:00
|
|
|
|
}
|
2019-11-21 15:04:33 +00:00
|
|
|
|
}
|