mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Cleaning of startup code. Bugfix for window size defaults not being applied
This commit is contained in:
parent
4965f78c07
commit
36359e4416
@ -14,19 +14,7 @@ namespace Wabbajack
|
||||
{
|
||||
public App()
|
||||
{
|
||||
// Wire any unhandled crashing exceptions to log before exiting
|
||||
AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
|
||||
{
|
||||
// Don't do any special logging side effects
|
||||
Utils.Log("Uncaught error:");
|
||||
Utils.Log(((Exception)e.ExceptionObject).ExceptionToString());
|
||||
};
|
||||
|
||||
var appPath = Assembly.GetExecutingAssembly().Location;
|
||||
if (!ExtensionManager.IsAssociated() || ExtensionManager.NeedsUpdating(appPath))
|
||||
{
|
||||
ExtensionManager.Associate(appPath);
|
||||
}
|
||||
// Initialization in MainWindow ctor
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,11 +24,15 @@ namespace Wabbajack
|
||||
private Subject<Unit> _saveSignal = new Subject<Unit>();
|
||||
public IObservable<Unit> SaveSignal => _saveSignal;
|
||||
|
||||
public static MainSettings LoadSettings()
|
||||
public static bool TryLoadTypicalSettings(out MainSettings settings)
|
||||
{
|
||||
string[] args = Environment.GetCommandLineArgs();
|
||||
if (!File.Exists(_filename) || args.Length > 1 && args[1] == "nosettings") return new MainSettings();
|
||||
return JsonConvert.DeserializeObject<MainSettings>(File.ReadAllText(_filename));
|
||||
if (!File.Exists(_filename))
|
||||
{
|
||||
settings = default;
|
||||
return false;
|
||||
}
|
||||
settings = JsonConvert.DeserializeObject<MainSettings>(File.ReadAllText(_filename));
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void SaveSettings(MainSettings settings)
|
||||
|
@ -15,23 +15,82 @@ namespace Wabbajack
|
||||
private MainWindowVM _mwvm;
|
||||
private MainSettings _settings;
|
||||
|
||||
internal bool ExitWhenClosing = true;
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
_settings = MainSettings.LoadSettings();
|
||||
Left = _settings.PosX;
|
||||
Top = _settings.PosY;
|
||||
_mwvm = new MainWindowVM(this, _settings);
|
||||
DataContext = _mwvm;
|
||||
// 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}");
|
||||
|
||||
this.Loaded += (sender, e) =>
|
||||
// Load settings
|
||||
string[] args = Environment.GetCommandLineArgs();
|
||||
if ((args.Length > 1 && args[1] == "nosettings")
|
||||
|| !MainSettings.TryLoadTypicalSettings(out var settings))
|
||||
{
|
||||
Width = _settings.Width;
|
||||
Height = _settings.Height;
|
||||
};
|
||||
_settings = new MainSettings();
|
||||
RunWhenLoaded(DefaultSettings);
|
||||
}
|
||||
else
|
||||
{
|
||||
_settings = settings;
|
||||
RunWhenLoaded(LoadSettings);
|
||||
}
|
||||
|
||||
// Set datacontext
|
||||
_mwvm = new MainWindowVM(this, _settings);
|
||||
DataContext = _mwvm;
|
||||
}
|
||||
|
||||
internal bool ExitWhenClosing = true;
|
||||
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)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user