Repository navigation
Expand file tree
/
Copy pathProgram.cs
More file actions
73 lines (66 loc) · 2.13 KB
/
Copy pathProgram.cs
File metadata and controls
73 lines (66 loc) · 2.13 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
using Microsoft.UI.Dispatching;
using Microsoft.UI.Xaml;
using System.Runtime.InteropServices;
using WinRT;
namespace ProxiLock;
internal static class Program
{
private static Mutex? _instanceMutex;
[STAThread]
private static void Main(string[] args)
{
try
{
_instanceMutex = new Mutex(true, "ProxiLock.SingleInstance", out var createdNew);
if (!createdNew)
return;
SetProcessDpiAwarenessContext(new IntPtr(-4));
ComWrappersSupport.InitializeComWrappers();
AppDomain.CurrentDomain.ProcessExit += (_, _) =>
{
try { App.CurrentApp.ShutdownForProcessExit(); } catch { }
};
Application.Start(_initializationParams =>
{
try
{
var context = new DispatcherQueueSynchronizationContext(
DispatcherQueue.GetForCurrentThread());
SynchronizationContext.SetSynchronizationContext(context);
new App();
}
catch (Exception ex)
{
LogStartupError("Application callback", ex);
throw;
}
});
}
catch (Exception ex)
{
LogStartupError("Application.Start", ex);
throw;
}
finally
{
GC.KeepAlive(_instanceMutex);
}
}
private static void LogStartupError(string stage, Exception ex)
{
try
{
var directory = Path.Combine(
Environment.GetEnvironmentVariable("LOCALAPPDATA")
?? Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
"ProxiLock", "logs");
Directory.CreateDirectory(directory);
File.AppendAllText(
Path.Combine(directory, "startup.log"),
$"{DateTimeOffset.Now:O} [{stage}] {ex}\r\n");
}
catch { }
}
[DllImport("user32.dll")]
private static extern bool SetProcessDpiAwarenessContext(IntPtr dpiContext);
}