Repository navigation
Expand file tree
/
Copy pathProgram.cs
More file actions
199 lines (170 loc) · 6.08 KB
/
Copy pathProgram.cs
File metadata and controls
199 lines (170 loc) · 6.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
using Avalonia;
using Avalonia.Controls.Platform;
using QuiverLauncher.Services;
using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using Velopack;
using Velopack.Locators;
namespace QuiverLauncher
{
class Program
{
[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)
{
// Must be first: Velopack install/update hooks exit inside Run().
// Linux/macOS share packages by packId (/var/tmp or Library/Caches); disable
// startup auto-apply so a second AppImage/.app is not silently updated.
var velopack = VelopackApp.Build();
if (!OperatingSystem.IsWindows())
velopack.SetAutoApplyOnStartup(false);
velopack.Run();
QuiverLauncherPaths.VelopackRootAppDirProvider = () =>
{
try
{
return VelopackLocator.Current?.RootAppDir;
}
catch
{
return null;
}
};
// Linux/macOS: library beside AppImage / .app when that folder is writable.
QuiverLauncherPaths.VelopackPackageDirectoryProvider = ResolveVelopackPackageDirectory;
QuiverLauncherPaths.CompletePendingDataMove();
QuiverLauncherPaths.EnsureUserDataRootExists();
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
{
QuiverLauncherPaths.EnsureUserDataRootExists();
File.AppendAllText(QuiverLauncherPaths.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 string? ResolveVelopackPackageDirectory()
{
try
{
var locator = VelopackLocator.Current;
if (locator is null)
return null;
if (OperatingSystem.IsLinux() &&
locator is LinuxVelopackLocator linux &&
!string.IsNullOrWhiteSpace(linux.AppImagePath))
{
return Path.GetDirectoryName(linux.AppImagePath);
}
if (OperatingSystem.IsMacOS())
{
return QuiverLauncherPaths.ResolveMacOsPackageDirectory(
locator.RootAppDir,
locator.AppContentDir,
AppDomain.CurrentDomain.BaseDirectory);
}
}
catch
{
// Not a Velopack install, or locator unavailable.
}
return null;
}
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()
{
var builder = AppBuilder.Configure<App>()
.UsePlatformDetect()
.WithInterFont()
.LogToTrace();
// Gamescope (Steam Deck Gaming Mode) treats separate X11 popup windows as
// fullscreen surfaces. Embed popups in the main window so ContextMenus
// stay composited over Quiver instead of showing a black letterbox.
if (OperatingSystem.IsLinux())
{
builder = builder.With(new X11PlatformOptions { OverlayPopups = true });
}
return builder;
}
}
}