2
0
mirror of https://github.com/9ParsonsB/Pulsar.git synced 2025-04-05 17:39:39 -04:00
pulsar/ObservatoryCore/ObservatoryCore.cs
F K 6d6b6f7951
[Core] Make Prereading the default behavior, re-enable settings upgrade (#140)
Pre-reading is good. And turns out a number of plugins kinda depend on it now. Time to make it default.

Also, comment out settings upgrades so settings are carried over from version to version when running in the IDE -- which makes using it far better.
2024-01-30 20:48:18 -05:00

81 lines
3.1 KiB
C#

using Observatory.PluginManagement;
using Observatory.Utils;
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)
{
SettingsManager.Load();
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;
SettingsManager.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();
}
}
}