mirror of
https://github.com/tgeorgiadis/quiver-launcher.git
synced 2026-11-22 21:50:52 -05:00
Rename GithubLauncher to Quiver, vendor Quiver.Core into the main repository, add community catalog support, tests, and updated branding assets for the 2.0 release. Co-authored-by: Cursor <cursoragent@cursor.com>
129 lines
3.6 KiB
C#
129 lines
3.6 KiB
C#
using Avalonia;
|
|
using Avalonia.Controls.Platform;
|
|
using System;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using System.Runtime.InteropServices;
|
|
using System.Text;
|
|
|
|
namespace Quiver
|
|
{
|
|
class Program
|
|
{
|
|
private static readonly string CrashLogPath = Path.Combine(
|
|
AppDomain.CurrentDomain.BaseDirectory,
|
|
"crash.log");
|
|
[DllImport("kernel32.dll", SetLastError = true)]
|
|
private static extern bool AttachConsole(int dwProcessId);
|
|
|
|
[DllImport("kernel32.dll")]
|
|
private static extern bool FreeConsole();
|
|
|
|
private const int ATTACH_PARENT_PROCESS = -1;
|
|
|
|
[STAThread]
|
|
public static int Main(string[] args)
|
|
{
|
|
if (args.Length > 0 && args[0].StartsWith("-"))
|
|
{
|
|
if (OperatingSystem.IsWindows())
|
|
{
|
|
if (AttachConsole(ATTACH_PARENT_PROCESS))
|
|
{
|
|
Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = true });
|
|
Console.SetError(new StreamWriter(Console.OpenStandardError()) { AutoFlush = true });
|
|
}
|
|
}
|
|
|
|
int exitCode = RunCLI(args);
|
|
|
|
if (OperatingSystem.IsWindows())
|
|
{
|
|
FreeConsole();
|
|
}
|
|
|
|
return exitCode;
|
|
}
|
|
|
|
#if DEBUG
|
|
RegisterDebugExceptionHandlers();
|
|
#endif
|
|
|
|
DefaultMenuInteractionHandler.MenuShowDelay = TimeSpan.Zero;
|
|
|
|
BuildAvaloniaApp()
|
|
.StartWithClassicDesktopLifetime(args);
|
|
return 0;
|
|
}
|
|
|
|
#if DEBUG
|
|
private static void RegisterDebugExceptionHandlers()
|
|
{
|
|
AppDomain.CurrentDomain.UnhandledException += (_, e) =>
|
|
{
|
|
if (e.ExceptionObject is Exception ex)
|
|
LogCrash("AppDomain.UnhandledException", ex);
|
|
};
|
|
|
|
TaskScheduler.UnobservedTaskException += (_, e) =>
|
|
{
|
|
LogCrash("TaskScheduler.UnobservedTaskException", e.Exception);
|
|
e.SetObserved();
|
|
};
|
|
}
|
|
|
|
internal static void LogCrashFromUiThread(string source, Exception ex)
|
|
{
|
|
LogCrash(source, ex);
|
|
}
|
|
|
|
private static void LogCrash(string source, Exception ex)
|
|
{
|
|
var message = new StringBuilder();
|
|
message.AppendLine($"[{DateTime.UtcNow:O}] {source}");
|
|
message.AppendLine(ex.ToString());
|
|
|
|
try
|
|
{
|
|
File.AppendAllText(CrashLogPath, message.ToString() + Environment.NewLine);
|
|
}
|
|
catch
|
|
{
|
|
// Best-effort logging only.
|
|
}
|
|
|
|
Debug.WriteLine(message.ToString());
|
|
Trace.WriteLine(message.ToString());
|
|
|
|
try
|
|
{
|
|
Console.Error.WriteLine(message.ToString());
|
|
}
|
|
catch
|
|
{
|
|
// WinExe may have no console attached.
|
|
}
|
|
}
|
|
#endif
|
|
|
|
private static int RunCLI(string[] args)
|
|
{
|
|
try
|
|
{
|
|
var cliHandler = new CLIHandler();
|
|
return cliHandler.Execute(args).GetAwaiter().GetResult();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.Error.WriteLine($"Error: {ex.Message}");
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
public static AppBuilder BuildAvaloniaApp()
|
|
=> AppBuilder.Configure<App>()
|
|
.UsePlatformDetect()
|
|
.WithInterFont()
|
|
.LogToTrace();
|
|
}
|
|
} |