-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
84 lines (69 loc) · 2.68 KB
/
Copy pathProgram.cs
File metadata and controls
84 lines (69 loc) · 2.68 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
using System;
using System.Reflection;
using System.Windows.Forms;
using AWLM.Core;
namespace AWLM
{
static class Program
{
[STAThread]
static void Main(string[] args)
{
if (args.Length > 0)
{
bool attached = NativeMethods.AttachConsole(NativeMethods.ATTACH_PARENT_PROCESS);
bool allocated = false;
if (!attached)
{
NativeMethods.AllocConsole();
allocated = true;
}
Console.WriteLine();
// Run async CLI work synchronously — fine here since we're not pumping a UI message loop
CliHandler.HandleArgs(args).GetAwaiter().GetResult();
Console.WriteLine();
Console.Out.Flush();
if (allocated)
NativeMethods.FreeConsole();
return;
}
// Create Mutex
// This mutex ensures that there is only one instance of the app running for the user
string mutexName = "SRPManager_SingleInstance_" + Environment.UserName.ToUpperInvariant();
using (var mutex = new System.Threading.Mutex(true, mutexName, out bool isNewInstance))
{
if (!isNewInstance)
{
MessageBox.Show(
"SRPManager is already running.",
"SRPManager",
MessageBoxButtons.OK,
MessageBoxIcon.Information);
return;
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new AWLM_App());
}
}
}
public static class AppBuildVersion
{
public static string Version =>
Assembly.GetExecutingAssembly()
.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?
.InformationalVersion
?? Assembly.GetExecutingAssembly().GetName().Version?.ToString()
?? "unknown";
}
internal static class NativeMethods
{
internal const uint ATTACH_PARENT_PROCESS = 0xFFFFFFFF;
[System.Runtime.InteropServices.DllImport("kernel32.dll", SetLastError = true)]
internal static extern bool AttachConsole(uint dwProcessId);
[System.Runtime.InteropServices.DllImport("kernel32.dll", SetLastError = true)]
internal static extern bool AllocConsole();
[System.Runtime.InteropServices.DllImport("kernel32.dll", SetLastError = true)]
internal static extern bool FreeConsole();
}
}