-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLauncher.cs
70 lines (64 loc) · 1.82 KB
/
Launcher.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
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Windows;
namespace ControlLauncher;
internal sealed class Launcher
{
public static bool LaunchDX11(string[] args)
{
return Launch("Control_DX11.exe", args);
}
public static bool LaunchDX12(string[] args)
{
return Launch("Control_DX12.exe", args);
}
private static bool Launch(string relativeExePath, string[] args)
{
if (Helpers.DEBUG)
{
// makes for easier debugging
var argsString = string.Join(" ", args).Trim();
var argsMessage = argsString == "" ? "no args" : $"args \"{argsString}\"";
MessageBox.Show($"Starting {relativeExePath} with {argsMessage}");
return true;
}
try
{
var process = new Process
{
StartInfo =
{
FileName = relativeExePath,
Arguments = string.Join(" ", args),
WorkingDirectory = AppContext.BaseDirectory,
UseShellExecute = false,
RedirectStandardOutput = false,
RedirectStandardError = false,
RedirectStandardInput = false,
},
};
process.Start();
return true;
}
catch (Win32Exception ex)
{
// error codes: https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-erref/18d8fbe8-a967-4f1c-ae50-99ca8e491d2d
switch (ex.NativeErrorCode)
{
case 2: // ERROR_FILE_NOT_FOUND
MessageBox.Show("Error launching the game: The launcher is not in Control's game directory", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
break;
default:
MessageBox.Show($"Error launching the game: Unknown error (Code 0x{ex.NativeErrorCode:08X})", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
break;
}
}
catch (Exception ex)
{
Trace.WriteLine(ex.GetType());
MessageBox.Show("Error launching the game: " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
return false;
}
}