From cd56089fe8818bd6a6f9546a04b1cc5ab58508c1 Mon Sep 17 00:00:00 2001 From: Miepee <38186597+Miepee@users.noreply.github.com> Date: Sat, 21 May 2022 19:56:31 +0200 Subject: [PATCH] Clean up the three GUI launcher projects --- AM2RLauncher/AM2RLauncher.Gtk/Program.cs | 27 +++++++++++++----------- AM2RLauncher/AM2RLauncher.Mac/Program.cs | 16 +++++++------- AM2RLauncher/AM2RLauncher.Wpf/Program.cs | 16 +++++++------- 3 files changed, 31 insertions(+), 28 deletions(-) diff --git a/AM2RLauncher/AM2RLauncher.Gtk/Program.cs b/AM2RLauncher/AM2RLauncher.Gtk/Program.cs index 3c3b81b..469503c 100644 --- a/AM2RLauncher/AM2RLauncher.Gtk/Program.cs +++ b/AM2RLauncher/AM2RLauncher.Gtk/Program.cs @@ -2,6 +2,7 @@ using log4net; using log4net.Config; using System; +using System.Collections.Generic; using System.IO; using System.Linq; using System.Text.RegularExpressions; @@ -9,6 +10,7 @@ using AM2RLauncher.Core; using log4net.Repository.Hierarchy; using Application = Eto.Forms.Application; using FileInfo = System.IO.FileInfo; +// ReSharper disable LocalizableElement - we want hardcoded strings for console writes. namespace AM2RLauncher.Gtk; @@ -34,11 +36,11 @@ internal static class MainClass Directory.CreateDirectory(launcherDataPath); // Now, see if log4netConfig exists, if not write it again. - if (!File.Exists(launcherDataPath + "/log4net.config")) - File.WriteAllText(launcherDataPath + "/log4net.config", Properties.Resources.log4netContents.Replace("${DATADIR}", launcherDataPath)); + if (!File.Exists($"{launcherDataPath}/log4net.config")) + File.WriteAllText($"{launcherDataPath}/log4net.config", Properties.Resources.log4netContents.Replace("${DATADIR}", launcherDataPath)); // Configure logger - XmlConfigurator.Configure(new FileInfo(launcherDataPath + "/log4net.config")); + XmlConfigurator.Configure(new FileInfo($"{launcherDataPath}/log4net.config")); // if we're on debug, always set log level to debug #if DEBUG @@ -50,10 +52,11 @@ internal static class MainClass { string osRelease = File.ReadAllText("/etc/os-release"); Regex lineRegex = new Regex(".*=.*"); - var results = lineRegex.Matches(osRelease).ToList(); - var version = results.FirstOrDefault(x => x.Value.Contains("VERSION")); - log.Info("Current Distro: " + results.FirstOrDefault(x => x.Value.Contains("NAME"))?.Value.Substring(5).Replace("\"", "") + - (version == null ? "" : " " + version.Value.Substring(8).Replace("\"", ""))); + List results = lineRegex.Matches(osRelease).ToList(); + Match version = results.FirstOrDefault(x => x.Value.Contains("VERSION")); + string distroName = results.FirstOrDefault(x => x.Value.Contains("NAME"))?.Value[5..].Replace("\"", ""); + string versionName = version == null ? "" : version.Value[8..].Replace("\"", ""); + log.Info($"Current Distro: {distroName} {versionName}"); } else log.Error("Couldn't determine the currently running distro!"); @@ -68,9 +71,9 @@ internal static class MainClass } catch (Exception e) { - log.Error("An unhandled exception has occurred: \n*****Stack Trace*****\n\n" + e.StackTrace); - Console.WriteLine(Language.Text.UnhandledException + "\n" + e.Message + "\n*****Stack Trace*****\n\n" + e.StackTrace); - Console.WriteLine("Check the logs at " + launcherDataPath + " for more info!"); + log.Error($"An unhandled exception has occurred: \n*****Stack Trace*****\n\n{e.StackTrace}"); + Console.WriteLine($"{Language.Text.UnhandledException}\n{e.Message}\n*****Stack Trace*****\n\n{e.StackTrace}"); + Console.WriteLine($"Check the logs at {launcherDataPath} for more info!"); } } @@ -79,10 +82,10 @@ internal static class MainClass /// private static void GTKLauncher_UnhandledException(object sender, Eto.UnhandledExceptionEventArgs e) { - log.Error("An unhandled exception has occurred: \n*****Stack Trace*****\n\n" + e.ExceptionObject); + log.Error($"An unhandled exception has occurred: \n*****Stack Trace*****\n\n{e.ExceptionObject}"); Application.Instance.Invoke(() => { - MessageBox.Show(Language.Text.UnhandledException + "\n*****Stack Trace*****\n\n" + e.ExceptionObject, "GTK", MessageBoxType.Error); + MessageBox.Show($"{Language.Text.UnhandledException}\n*****Stack Trace*****\n\n{e.ExceptionObject}", "GTK", MessageBoxType.Error); }); } } \ No newline at end of file diff --git a/AM2RLauncher/AM2RLauncher.Mac/Program.cs b/AM2RLauncher/AM2RLauncher.Mac/Program.cs index 27bfe6a..976037c 100644 --- a/AM2RLauncher/AM2RLauncher.Mac/Program.cs +++ b/AM2RLauncher/AM2RLauncher.Mac/Program.cs @@ -2,10 +2,10 @@ using log4net; using log4net.Config; using System; -using System.Diagnostics.CodeAnalysis; using System.IO; using AM2RLauncher.Core; using log4net.Repository.Hierarchy; +// ReSharper disable LocalizableElement - we want hardcoded strings for console writes. namespace AM2RLauncher.Mac; @@ -32,15 +32,15 @@ internal static class MainClass Directory.CreateDirectory(launcherDataPath); // Now, see if log4netConfig exists, if not write it again. - if (!File.Exists(launcherDataPath + "/log4net.config")) - File.WriteAllText(launcherDataPath + "/log4net.config", Properties.Resources.log4netContents.Replace("${DATADIR}", launcherDataPath)); + if (!File.Exists($"{launcherDataPath}/log4net.config")) + File.WriteAllText($"{launcherDataPath}/log4net.config", Properties.Resources.log4netContents.Replace("${DATADIR}", launcherDataPath)); // Configure logger XmlConfigurator.Configure(new FileInfo(launcherDataPath + "/log4net.config")); // if we're on debug, always set logLevel to debug #if DEBUG - ((Logger)log.Logger).Level = log4net.Core.Level.Debug; + ((Logger)log.Logger).Level = log4net.Core.Level.Debug; #endif try @@ -53,8 +53,8 @@ internal static class MainClass catch (Exception e) { log.Error("An unhandled exception has occurred: \n*****Stack Trace*****\n\n" + e.StackTrace); - Console.WriteLine(Language.Text.UnhandledException + "\n" + e.Message + "\n*****Stack Trace*****\n\n" + e.StackTrace); - Console.WriteLine("Check the logs at " + launcherDataPath + " for more info!"); + Console.WriteLine($"{Language.Text.UnhandledException}\n{e.Message}\n*****Stack Trace*****\n\n{e.StackTrace}"); + Console.WriteLine($"Check the logs at {launcherDataPath} for more info!"); } } @@ -63,10 +63,10 @@ internal static class MainClass /// private static void MacLauncher_UnhandledException(object sender, Eto.UnhandledExceptionEventArgs e) { - log.Error("An unhandled exception has occurred: \n*****Stack Trace*****\n\n" + e.ExceptionObject); + log.Error($"An unhandled exception has occurred: \n*****Stack Trace*****\n\n{e.ExceptionObject}"); Application.Instance.Invoke(() => { - MessageBox.Show(Language.Text.UnhandledException + "\n*****Stack Trace*****\n\n" + e.ExceptionObject, "Mac", MessageBoxType.Error); + MessageBox.Show($"{Language.Text.UnhandledException}\n*****Stack Trace*****\n\n{e.ExceptionObject}", "Mac", MessageBoxType.Error); }); } } \ No newline at end of file diff --git a/AM2RLauncher/AM2RLauncher.Wpf/Program.cs b/AM2RLauncher/AM2RLauncher.Wpf/Program.cs index 5fc854c..f6d8305 100644 --- a/AM2RLauncher/AM2RLauncher.Wpf/Program.cs +++ b/AM2RLauncher/AM2RLauncher.Wpf/Program.cs @@ -3,9 +3,9 @@ using log4net; using log4net.Config; using System; using System.IO; -using System.Reflection; using AM2RLauncher.Core; using log4net.Repository.Hierarchy; +// ReSharper disable LocalizableElement - we want hardcoded strings for console writes. namespace AM2RLauncher.Wpf; @@ -31,11 +31,11 @@ internal static class MainClass Directory.CreateDirectory(launcherDataPath); // Now, see if log4netConfig exists, if not write it again. - if (!File.Exists(launcherDataPath + "/log4net.config")) - File.WriteAllText(launcherDataPath + "/log4net.config", Properties.Resources.log4netContents.Replace("${DATADIR}", launcherDataPath)); + if (!File.Exists($"{launcherDataPath}/log4net.config")) + File.WriteAllText($"{launcherDataPath}/log4net.config", Properties.Resources.log4netContents.Replace("${DATADIR}", launcherDataPath)); // Configure logger - XmlConfigurator.Configure(new FileInfo(launcherDataPath + "/log4net.config")); + XmlConfigurator.Configure(new FileInfo($"{launcherDataPath}/log4net.config")); // if we're on debug, always set log level to debug #if DEBUG @@ -56,8 +56,8 @@ internal static class MainClass } catch (Exception e) { - log.Error("An unhandled exception has occurred: \n*****Stack Trace*****\n\n" + e.StackTrace); - System.Windows.Forms.MessageBox.Show(Language.Text.UnhandledException + "\n" + e.Message + "\n*****Stack Trace*****\n\n" + e.StackTrace, "Microsoft .NET Framework", + log.Error($"An unhandled exception has occurred: \n*****Stack Trace*****\n\n{e.StackTrace}"); + System.Windows.Forms.MessageBox.Show($"{Language.Text.UnhandledException}\n{e.Message}\n*****Stack Trace*****\n\n{e.StackTrace}", "Microsoft .NET Framework", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); } } @@ -67,7 +67,7 @@ internal static class MainClass /// private static void WinLauncher_UnhandledException(object sender, Eto.UnhandledExceptionEventArgs e) { - log.Error("An unhandled exception has occurred: \n*****Stack Trace*****\n\n" + e.ExceptionObject); - MessageBox.Show(Language.Text.UnhandledException + "\n*****Stack Trace*****\n\n" + e.ExceptionObject, "Microsoft .NET Framework", MessageBoxType.Error); + log.Error($"An unhandled exception has occurred: \n*****Stack Trace*****\n\n{e.ExceptionObject}"); + MessageBox.Show($"{Language.Text.UnhandledException}\n*****Stack Trace*****\n\n{e.ExceptionObject}", "Microsoft .NET Framework", MessageBoxType.Error); } } \ No newline at end of file