-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHelpers.cs
More file actions
135 lines (115 loc) · 2.79 KB
/
Copy pathHelpers.cs
File metadata and controls
135 lines (115 loc) · 2.79 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
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
namespace ControlLauncher;
internal sealed class Helpers
{
[DllImport("CheckDXR.dll", EntryPoint = "checkDXR")]
private static extern bool CheckDXR();
[DllImport("CheckCDLL.dll", EntryPoint = "checkCDLL")]
private static extern bool CheckCDLL();
[DllImport("shell32.dll", SetLastError = true)]
private static extern IntPtr CommandLineToArgvW([MarshalAs(UnmanagedType.LPWStr)] string lpCmdLine, out int pNumArgs);
#if DEBUG
public const bool DEBUG = true;
#else
public const bool DEBUG = false;
#endif
/// <summary>
/// Checks the OS version and returns true if it's Windows 7 or 8/8.1. See: <see href="https://learn.microsoft.com/en-us/windows/win32/sysinfo/operating-system-version">Operating System Version</see>
/// </summary>
/// <returns>True if the current OS is Windows 7 or 8/8.1, false otherwise.</returns>
public static bool IsWin7OrWin8()
{
return Environment.OSVersion.Version is { Major: 6, Minor: >= 1 and <= 3 };
}
private static bool CheckRedistributable()
{
try
{
return CheckCDLL();
}
catch (DllNotFoundException)
{
return false;
}
}
public static bool CheckForRaytracing()
{
try
{
return CheckDXR();
}
catch (DllNotFoundException)
{
return false;
}
}
/// <summary>
/// Checks whether the VC++ redistributable is installed and launches the installer if needed.
/// </summary>
/// <returns>True if the redistributable is installed, false otherwise or if the installer failed.</returns>
public static bool InstallRedistributableIfNeeded()
{
var vcInstallAttempted = false;
if (CheckRedistributable())
return true;
if (!DEBUG)
{
vcInstallAttempted = true;
try
{
var vcProcess = Process.Start("VC_redist.x64.exe", "/install /norestart");
if (vcProcess == null)
return false;
vcProcess.WaitForExit();
}
catch (Exception e)
{
return false;
}
}
if (!vcInstallAttempted)
return true;
return CheckRedistributable();
}
public static bool IsLauncherInGameDir()
{
try
{
CheckDXR();
CheckCDLL();
}
catch (DllNotFoundException)
{
return false;
}
return true;
}
private static IEnumerable<string> CommandLineToArgs(string commandLine)
{
var argv = CommandLineToArgvW(commandLine, out var argc);
if (argv == IntPtr.Zero)
return Array.Empty<string>();
try
{
var args = new string[argc];
for (var i = 0; i < args.Length; i++)
{
var p = Marshal.ReadIntPtr(argv, i * IntPtr.Size);
args[i] = Marshal.PtrToStringUni(p)!;
}
return args;
}
finally
{
Marshal.FreeHGlobal(argv);
}
}
public static string[] GetCommandLineArgs()
{
return CommandLineToArgs(Environment.CommandLine).Skip(1).ToArray();
}
}