This repository has been archived by the owner on Apr 27, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Utility.cs
93 lines (83 loc) · 2.87 KB
/
Utility.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
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using Microsoft.Win32;
namespace BFtools
{
public static class Utility
{
public static string ToInt(this bool value)
{
return value ? "1" : "0";
}
public static RegistryKey GetRegistryKey()
{
RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\EA Games\Battlefield 4", true); // 64bit
if (key == null || key.GetValue("Install Dir") == null)
key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\EA GAMES\Battlefield 4", true); // 32bit
if (key == null || key.GetValue("Install Dir") == null)
key = null; // N/A
return key;
}
public static void KillProcesses(IEnumerable<Process> processes, bool waitForExit = false)
{
foreach (var process in processes)
{
try
{
process.Kill();
if (waitForExit)
process.WaitForExit();
}
catch
{
// ignored
}
}
}
public static float GetDirectXVersion()
{
string outputFile = Environment.GetEnvironmentVariable("temp") + @"\dxdiag.tmp";
try
{
Process dxdiag = new Process
{
StartInfo =
{
FileName = "dxdiag.exe",
Arguments = "/t " + outputFile
}
};
dxdiag.Start();
dxdiag.WaitForExit();
if (File.Exists(outputFile))
{
string[] lines = File.ReadAllLines(outputFile);
File.Delete(outputFile);
foreach (string line in lines)
{
if (line.Contains("DirectX "))
{
if (line.Contains("DirectX 9")) return 9;
if (line.Contains("DirectX 10")) return 10;
if (line.Contains("DirectX 11")) return 11;
if (line.Contains("DirectX 11.1")) return 11.1f;
if (line.Contains("DirectX 11.2")) return 11.2f;
if (line.Contains("DirectX 11.3")) return 11.3f;
if (line.Contains("DirectX 12")) return 12;
if (line.Contains("DirectX 12.1")) return 12.1f;
if (line.Contains("DirectX 12.2")) return 12.2f;
if (line.Contains("DirectX 13")) return 13;
}
}
}
}
catch
{
// ignored
}
return 0;
}
}
}