forked from nomi-san/parsec-vdd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
121 lines (104 loc) · 3.42 KB
/
Program.cs
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
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ParsecVDisplay
{
public static class Program
{
public const string AppId = "QpHOX8IBUHBznGtqk9xm1";
public const string AppName = "ParsecVDisplay";
public const string AppVersion = "1.0.2";
public const string GitHubRepo = "nomi-san/parsec-vdd";
[STAThread]
static int Main(string[] args)
{
if (args.Length >= 2 && args[0] == "-custom")
{
var modes = Display.ParseModes(args[1]);
ParsecVDD.SetCustomDisplayModes(modes);
if (args.Length >= 3)
{
if (Enum.TryParse<ParsecVDD.ParentGPU>(args[2], true, out var kind))
{
ParsecVDD.SetParentGPU(kind);
}
}
return 0;
}
if (args.Length > 0 && args[0] == "-cli")
{
args = args.Skip(1).ToArray();
return CLI.Execute(args);
}
if (SingleInstance())
{
App.LoadTranslations();
if (InitDriver())
{
Helper.StayAwake(false);
Daemon.Start();
Application.Run(new Tray());
Daemon.Stop();
ParsecVDD.Uninit();
}
}
return 0;
}
static bool SingleInstance()
{
bool isOwned = false;
var signal = new EventWaitHandle(false,
EventResetMode.AutoReset, AppId, out isOwned);
if (isOwned)
{
Task.Run(() =>
{
while (signal.WaitOne())
{
Tray.Instance?.Invoke(Tray.Instance.ShowApp);
}
});
}
else
{
signal.Set();
signal.Dispose();
}
return isOwned;
}
static bool InitDriver()
{
string error = null;
var status = ParsecVDD.QueryStatus();
if (!(status == Device.Status.OK || Config.SkipDriverCheck))
{
switch (status)
{
case Device.Status.RESTART_REQUIRED:
error = App.GetTranslation("t_msg_must_restart_pc");
break;
case Device.Status.DISABLED:
error = App.GetTranslation("t_msg_driver_is_disabled", ParsecVDD.ADAPTER);
break;
case Device.Status.NOT_INSTALLED:
error = App.GetTranslation("t_msg_please_install_driver");
break;
default:
error = App.GetTranslation("t_msg_driver_status_not_ok", status);
break;
}
}
else if (ParsecVDD.Init() != true)
{
error = App.GetTranslation("t_msg_failed_to_obtain_handle");
}
if (error != null)
{
MessageBox.Show(error, AppName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
return error == null;
}
}
}