-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathProgram.cs
More file actions
87 lines (76 loc) · 2.65 KB
/
Program.cs
File metadata and controls
87 lines (76 loc) · 2.65 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
using System;
using System.Diagnostics;
using System.IO;
using System.Threading;
using System.Windows;
using System.Windows.Interop;
using TopmostApp.Interop;
using System.Windows.Media;
using VoicemeeterOsdProgram.Updater;
namespace VoicemeeterOsdProgram;
public class Program
{
public const string Name = "VoicemeeterFancyOSD";
public const string UniqueName = "AtgDev_VoicemeeterFancyOSD";
public static App wpf_app;
[STAThread]
static void Main(string[] args) // if *Host.exe is launched "*Host.exe" may be the args[0]
{
#if DEBUG
//if (!Debugger.IsAttached) Debugger.Launch();
#endif
AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
AppDomain.CurrentDomain.ProcessExit += OnProcessExit;
ArgsHandler.HandleSpecial(args);
if (AppLifeManager.IsAlreadyRunning && (args.Length == 0))
{
args = [ArgsHandler.Args.OpenSettings];
}
Thread thread = new(() =>
{
ComponentDispatcher.ThreadFilterMessage += OnTerminationSignal;
AppLifeManager.Start(args, () =>
{
RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly;
System.Windows.Media.RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly;
wpf_app = new();
wpf_app.Run();
});
});
//If you launch directly from the host bridge it won't be STA.
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
}
private static void OnTerminationSignal(ref MSG msg, ref bool handled)
{
if ((msg.message == (int)WindowMessage.WM_CLOSE) || (msg.message == (int)WindowMessage.WM_QUIT))
{
Debug.WriteLine("TERMINATION SIGNAL RECEIVED");
wpf_app?.Dispatcher.Invoke(() =>
{
wpf_app.Shutdown();
});
}
}
private static void OnUnhandledException(object sender, UnhandledExceptionEventArgs e)
{
Debug.WriteLine("UNHANDLED EXCEPTION");
try
{
var ex = e.ExceptionObject as Exception;
var path = AppDomain.CurrentDomain.BaseDirectory + @"\crashes";
var filePath = path + @$"\crash {DateTime.Now:dd-MM-yyyy HH-mm-ss}.log";
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
using StreamWriter sr = new(filePath);
sr.WriteLine($"{ex.GetType}\n{ex.Message}\n{ex.StackTrace}");
}
catch { }
}
private static void OnProcessExit(object sender, EventArgs e)
{
Debug.WriteLine("PROCESS EXIT");
}
}