-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
72 lines (64 loc) · 1.88 KB
/
Copy pathProgram.cs
File metadata and controls
72 lines (64 loc) · 1.88 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
using System.Runtime.Versioning;
namespace CMAPI.Installer;
internal static class Program
{
[STAThread]
[SupportedOSPlatform("windows")]
private static void Main(string[] args)
{
ApplicationConfiguration.Initialize();
if (!WaitForRequestedProcess(args))
{
MessageBox.Show(
"CMAPI Setup could not confirm that the previous CMAPI " +
"launcher closed. No files were changed. Close CMAPI and " +
"run Setup again.",
"CMAPI Setup",
MessageBoxButtons.OK,
MessageBoxIcon.Error
);
return;
}
Application.Run(new InstallerForm(
InstallerPackage.Resolve(args),
GetOption(args, "--game-path")
));
}
private static bool WaitForRequestedProcess(string[] args)
{
string? value = GetOption(args, "--wait-for-process");
if (string.IsNullOrWhiteSpace(value))
return true;
if (!int.TryParse(value, out int processId) || processId <= 0)
return false;
try
{
using System.Diagnostics.Process process =
System.Diagnostics.Process.GetProcessById(processId);
return process.WaitForExit(15_000);
}
catch (ArgumentException)
{
// The process exited before Setup could open it.
return true;
}
catch
{
return false;
}
}
private static string? GetOption(string[] args, string name)
{
for (int index = 0; index < args.Length - 1; index++)
{
if (string.Equals(
args[index],
name,
StringComparison.OrdinalIgnoreCase))
{
return args[index + 1];
}
}
return null;
}
}