1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Core - Ensure application data folder exists

UI - Properly catch exceptions during exception display
UI - Display fatal exceptions during Core creation, even before Core initialisation
This commit is contained in:
Robert 2020-03-12 19:34:53 +01:00
parent 0ccc1fed3d
commit d009b11e97
4 changed files with 45 additions and 24 deletions

View File

@ -39,7 +39,14 @@ namespace Artemis.Core.Ninject
.Configure(c => c.When(HasAccessToProtectedService).InSingletonScope());
});
Kernel.Bind<LiteRepository>().ToMethod(t => new LiteRepository(Constants.ConnectionString)).InSingletonScope();
Kernel.Bind<LiteRepository>().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 =>

View File

@ -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;

View File

@ -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<ExceptionDialogViewModel>(arguments));
}
catch (Exception)
{
//ignored
}
try
{
await ShowDialog<ExceptionDialogViewModel>(arguments);
}
catch (Exception)
{
// ignored
}
});
}
private async Task<object> ShowDialog(string identifier, DialogViewModelBase viewModel)

View File

@ -38,7 +38,15 @@ namespace Artemis.UI
var viewManager = Kernel.Get<IViewManager>();
// Create the Artemis core
_core = Kernel.Get<ICoreService>();
try
{
_core = Kernel.Get<ICoreService>();
}
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<IWindowManager>().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<IWindowManager>().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(() =>