2
0
mirror of https://github.com/9ParsonsB/Pulsar.git synced 2025-04-05 17:39:39 -04:00
pulsar/ObservatoryCore/ObservatoryCore.cs
2023-05-05 09:42:50 -02:30

78 lines
3.0 KiB
C#

using Observatory.PluginManagement;
using System.Reflection.PortableExecutable;
namespace Observatory
{
internal static class ObservatoryCore
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
if (args.Length > 0 && File.Exists(args[0]))
{
var fileInfo = new FileInfo(args[0]);
if (fileInfo.Extension == ".eop" || fileInfo.Extension == ".zip")
File.Copy(
fileInfo.FullName,
$"{AppDomain.CurrentDomain.BaseDirectory}{Path.DirectorySeparatorChar}plugins{Path.DirectorySeparatorChar}{fileInfo.Name}");
}
string version = System.Reflection.Assembly.GetEntryAssembly()?.GetName().Version?.ToString() ?? "0";
try
{
if (Properties.Core.Default.CoreVersion != version)
{
try
{
Properties.Core.Default.Upgrade();
}
catch
{
// Silently ignore properties upgrade failure.
}
Properties.Core.Default.CoreVersion = version;
Properties.Core.Default.Save();
}
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new UI.CoreForm());
PluginManagement.PluginManager.GetInstance.Shutdown();
}
catch (Exception ex)
{
LogError(ex, version);
}
}
internal static void LogError(Exception ex, string context)
{
var docPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments);
var errorMessage = new System.Text.StringBuilder();
var timestamp = DateTime.Now.ToString("G");
errorMessage
.AppendLine($"[{timestamp}] Error encountered in Elite Observatory {context}")
.AppendLine(FormatExceptionMessage(ex))
.AppendLine();
System.IO.File.AppendAllText(docPath + System.IO.Path.DirectorySeparatorChar + "ObservatoryCrashLog.txt", errorMessage.ToString());
}
static string FormatExceptionMessage(Exception ex, bool inner = false)
{
var errorMessage = new System.Text.StringBuilder();
errorMessage
.AppendLine($"{(inner ? "Inner e" : "E")}xception message: {ex.Message}")
.AppendLine($"Stack trace:")
.AppendLine(ex.StackTrace);
if (ex.InnerException != null)
errorMessage.AppendLine(FormatExceptionMessage(ex.InnerException, true));
return errorMessage.ToString();
}
}
}