diff --git a/src/Artemis.Core/Ninject/CoreModule.cs b/src/Artemis.Core/Ninject/CoreModule.cs index 66ea2d9d0..646e9b031 100644 --- a/src/Artemis.Core/Ninject/CoreModule.cs +++ b/src/Artemis.Core/Ninject/CoreModule.cs @@ -39,7 +39,14 @@ namespace Artemis.Core.Ninject .Configure(c => c.When(HasAccessToProtectedService).InSingletonScope()); }); - Kernel.Bind().ToMethod(t => new LiteRepository(Constants.ConnectionString)).InSingletonScope(); + Kernel.Bind().ToMethod(t => + { + // Ensure the data folder exists + if (!Directory.Exists(Constants.DataFolder)) + Directory.CreateDirectory(Constants.DataFolder); + + return new LiteRepository(Constants.ConnectionString); + }).InSingletonScope(); // Bind all repositories as singletons Kernel.Bind(x => diff --git a/src/Artemis.Core/Services/RgbService.cs b/src/Artemis.Core/Services/RgbService.cs index 4c7944eb7..6534bd656 100644 --- a/src/Artemis.Core/Services/RgbService.cs +++ b/src/Artemis.Core/Services/RgbService.cs @@ -1,8 +1,6 @@ using System; using System.Collections.Generic; -using System.Linq; using Artemis.Core.Events; -using Artemis.Core.Plugins.Abstract; using Artemis.Core.Plugins.Models; using Artemis.Core.RGB.NET; using Artemis.Core.Services.Interfaces; diff --git a/src/Artemis.UI.Shared/Services/Dialog/DialogService.cs b/src/Artemis.UI.Shared/Services/Dialog/DialogService.cs index b56b7cb8e..3ece782f6 100644 --- a/src/Artemis.UI.Shared/Services/Dialog/DialogService.cs +++ b/src/Artemis.UI.Shared/Services/Dialog/DialogService.cs @@ -95,14 +95,18 @@ namespace Artemis.UI.Shared.Services.Dialog new ConstructorArgument("message", message), new ConstructorArgument("exception", exception) }; - try + + await Execute.OnUIThreadAsync(async () => { - await Execute.OnUIThreadAsync(async () => await ShowDialog(arguments)); - } - catch (Exception) - { - //ignored - } + try + { + await ShowDialog(arguments); + } + catch (Exception) + { + // ignored + } + }); } private async Task ShowDialog(string identifier, DialogViewModelBase viewModel) diff --git a/src/Artemis.UI/Bootstrapper.cs b/src/Artemis.UI/Bootstrapper.cs index 840588978..6f10c09dd 100644 --- a/src/Artemis.UI/Bootstrapper.cs +++ b/src/Artemis.UI/Bootstrapper.cs @@ -38,7 +38,15 @@ namespace Artemis.UI var viewManager = Kernel.Get(); // Create the Artemis core - _core = Kernel.Get(); + try + { + _core = Kernel.Get(); + } + catch (Exception e) + { + HandleFatalException(e, logger); + throw; + } // Create and bind the root view, this is a tray icon so don't show it with the window manager Execute.OnUIThread(() => viewManager.CreateAndBindViewForModelIfNecessary(RootViewModel)); @@ -58,19 +66,7 @@ namespace Artemis.UI } catch (Exception e) { - logger.Fatal(e, "Fatal exception during initialization, shutting down."); - - // Can't use a pretty exception dialog here since the UI might not even be visible - Execute.OnUIThread(() => - { - Kernel.Get().ShowMessageBox(e.Message + "\n\n Please refer the log file for more details.", - "Fatal exception during initialization", - MessageBoxButton.OK, - MessageBoxImage.Error - ); - Environment.Exit(1); - }); - + HandleFatalException(e, logger); throw; } }); @@ -106,6 +102,22 @@ namespace Artemis.UI e.Handled = true; } + private void HandleFatalException(Exception e, ILogger logger) + { + logger.Fatal(e, "Fatal exception during initialization, shutting down."); + + // Can't use a pretty exception dialog here since the UI might not even be visible + Execute.OnUIThread(() => + { + Kernel.Get().ShowMessageBox(e.Message + "\n\n Please refer the log file for more details.", + "Fatal exception during initialization", + MessageBoxButton.OK, + MessageBoxImage.Error + ); + Environment.Exit(1); + }); + } + private void ShowMainWindow(IWindowManager windowManager, SplashViewModel splashViewModel) { Execute.OnUIThread(() =>