diff --git a/Elite Dangerous Addon Launcher V2.csproj b/Elite Dangerous Addon Launcher V2.csproj index 92f27a4..99e8320 100644 --- a/Elite Dangerous Addon Launcher V2.csproj +++ b/Elite Dangerous Addon Launcher V2.csproj @@ -6,8 +6,8 @@ Elite_Dangerous_Addon_Launcher_V2 enable true - 1.1.5.377 - 1.1.5.377 + 1.1.5.382 + 1.1.5.382 elite-dangerous-icon.ico app.png https://github.com/jimmyeao/Elite-Dangerous-Addon-Launcher-V2 @@ -39,6 +39,9 @@ + + + diff --git a/LoggingConfig.cs b/LoggingConfig.cs new file mode 100644 index 0000000..00f8e25 --- /dev/null +++ b/LoggingConfig.cs @@ -0,0 +1,67 @@ +using Serilog; +using Serilog.Sinks.File; +using System; +using System.IO; +using System.Linq; +using System.Text; + + +namespace Elite_Dangerous_Addon_Launcher_V2 +{ + public static class LoggingConfig + { + #region Public Fields + + public static string? logFileFullPath; + + #endregion Public Fields + + #region Public Methods + + public static void Configure() + { + var filePathHook = new CaptureFilePathHook(); + string appDataFolder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); + string folderPath = Path.Combine(appDataFolder, "Elite_Dangerous_Addon_Lau"); + var logFilePath = Path.Combine(folderPath, "EDAL.log"); + + Log.Logger = new LoggerConfiguration() + .MinimumLevel.Debug() + .Enrich.FromLogContext() + .WriteTo.Console() + .WriteTo.File(logFilePath, + rollingInterval: RollingInterval.Day, + fileSizeLimitBytes: 10_000_000, // 10 MB file size limit + retainedFileCountLimit: 1, // Retain only the last file + hooks: filePathHook, + rollOnFileSizeLimit: true) // Roll over on file size limit + .CreateLogger(); + + Log.Information("Logger Created"); + logFileFullPath = filePathHook.Path; + } + + + + #endregion Public Methods + } + + internal class CaptureFilePathHook : FileLifecycleHooks + { + #region Public Properties + + public string? Path { get; private set; } + + #endregion Public Properties + + #region Public Methods + + public override Stream OnFileOpened(string path, Stream underlyingStream, Encoding encoding) + { + Path = path; + return base.OnFileOpened(path, underlyingStream, encoding); + } + + #endregion Public Methods + } +} \ No newline at end of file diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index bb22335..cd567ce 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -2,6 +2,7 @@ using Microsoft.Win32; using Newtonsoft.Json; using System; +using Serilog; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; @@ -63,7 +64,7 @@ public string ApplicationVersion public MainWindow(string profileName = null) { InitializeComponent(); - + LoggingConfig.Configure(); if (!string.IsNullOrEmpty(profileName)) { // Use the profileName to load the appropriate profile @@ -420,12 +421,14 @@ public void ShowWhatsNew() private void Btn_Launch_Click(object sender, RoutedEventArgs e) { // Code to launch all enabled apps + Log.Information("Launching all enabled apps.."); foreach (var app in AppState.Instance.CurrentProfile.Apps) { if (app.IsEnabled) { Btn_Launch.IsEnabled = false; LaunchApp(app); + Log.Information("Launching {AppName}..", app.Name); } } } @@ -623,7 +626,7 @@ private async Task LoadSettingsAsync() // If the settings file doesn't exist, use defaults settings = new Settings { Theme = "Default" }; } - + Log.Information("Settings loaded: {Settings}", settings); return settings; } @@ -685,61 +688,65 @@ private void OnProfileChanged(Profile oldProfile, Profile newProfile) private void ProcessExitHandler(object sender, EventArgs e) //triggered when EDLaunch exits { - Btn_Launch.IsEnabled = true; - bool closeAllApps = false; Application.Current.Dispatcher.Invoke(() => { - closeAllApps = CloseAllAppsCheckbox.IsChecked == true; - }); - // if EDLaunch has quit, does the user want us to kill all the apps? - if (closeAllApps) - { - try + Btn_Launch.IsEnabled = true; + bool closeAllApps = CloseAllAppsCheckbox.IsChecked == true; + + // if EDLaunch has quit, does the user want us to kill all the apps? + if (closeAllApps) { - foreach (string p in processList) + Log.Information("CloseAllAppsOnExit is enabled, closing all apps.."); + try { - foreach (Process process in Process.GetProcessesByName(p)) + foreach (string p in processList) { - // Temp is a document which you need to kill. - if (process.ProcessName.Contains(p)) - process.CloseMainWindow(); + Log.Information("Closing {0}", p); + foreach (Process process in Process.GetProcessesByName(p)) + { + // Temp is a document which you need to kill. + if (process.ProcessName.Contains(p)) + process.CloseMainWindow(); + } } } + catch + { + // if something went wrong, don't raise an exception + Log.Error("An error occurred trying to close all apps.."); + } + // doesn't seem to want to kill VoiceAttack nicely.. + try + { + Process[] procs = Process.GetProcessesByName("VoiceAttack"); + foreach (var proc in procs) { proc.Kill(); } //sadly this means next time it starts, it will complain it was shutdown in an unclean fashion + } + catch + { + // if something went wrong, don't raise an exception + } + // Elite Dangerous Odyssey Materials Helper is a little strange, let's deal with its + // multiple running processes.. + try + { + Process[] procs = Process.GetProcessesByName("Elite Dangerous Odyssey Materials Helper"); + foreach (var proc in procs) { proc.CloseMainWindow(); } + } + catch + { + // if something went wrong, don't raise an exception + } + // sleep for 5 seconds then quit + for (int i = 5; i != 0; i--) + { + Thread.Sleep(1000); + } + Environment.Exit(0); } - catch - { - // if something went wrong, don't raise an exception - } - // doesn't seem to want to kill VoiceAttack nicely.. - try - { - Process[] procs = Process.GetProcessesByName("VoiceAttack"); - foreach (var proc in procs) { proc.Kill(); } //sadly this means next time it starts, it will complain it was shutdown in an unclean fashion - } - catch - { - // if something went wrong, don't raise an exception - } - // Elite Dangerous Odyssey Materials Helper is a little strange, let's deal with its - // multiple running processes.. - try - { - Process[] procs = Process.GetProcessesByName("Elite Dangerous Odyssey Materials Helper"); - foreach (var proc in procs) { proc.CloseMainWindow(); } - } - catch - { - // if something went wrong, don't raise an exception - } - // sleep for 5 seconds then quit - for (int i = 5; i != 0; i--) - { - Thread.Sleep(1000); - } - Environment.Exit(0); - } + }); } + private async Task SaveSettingsAsync(Settings settings) { string localFolder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);