Clean up the three GUI launcher projects

pull/32/head
Miepee 4 years ago
parent af27f1a6e7
commit cd56089fe8

@ -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<Match> 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
/// </summary>
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);
});
}
}

@ -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
/// </summary>
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);
});
}
}

@ -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
/// </summary>
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);
}
}
Loading…
Cancel
Save