This repository has been archived by the owner on Apr 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 773
/
GlobalHelper.cs
98 lines (87 loc) · 3.91 KB
/
GlobalHelper.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
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Windows.Forms;
using System.Xml.Linq;
namespace LECommonLibrary
{
public static class GlobalHelper
{
public static string GlobalVersionPath =
Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
"LEVersion.xml");
public static string GetLEVersion()
{
try
{
var doc = XDocument.Load(GlobalVersionPath);
return doc.Descendants("LEVersion").First().Attribute("Version").Value;
}
catch
{
return "0.0.0.0";
}
}
public static void ShowErrorDebugMessageBox(string commandLine, uint errorCode)
{
MessageBox.Show(String.Format("Error Number: {0}\r\n" +
"Commands: {1}\r\n" +
"\r\n" +
"{2}\r\n" +
"{3}\r\n" +
"If you have any antivirus software running, please turn it off and try again.\r\n"
+
"If this window still shows, try go to Safe Mode and drag the application "
+
"executable onto LEProc.exe.\r\n"
+
"If you have tried all above but none of them works, feel free to submit an issue at\r\n"
+
"https://github.com/xupefei/Locale-Emulator/issues.\r\n" +
"\r\n" +
"\r\n" +
"You can press CTRL+C to copy this message to your clipboard.\r\n",
Convert.ToString(errorCode, 16).ToUpper(),
commandLine,
String.Format("{0} {1}",
Environment.OSVersion,
SystemHelper.Is64BitOS() ? "x64" : "x86"),
GenerateSystemDllVersionList()
),
"Locale Emulator Version " + GetLEVersion());
}
private static string GenerateSystemDllVersionList()
{
string[] dlls = {"NTDLL.DLL", "KERNELBASE.DLL", "KERNEL32.DLL", "USER32.DLL", "GDI32.DLL"};
var result = new StringBuilder();
foreach (var dll in dlls)
{
var version = FileVersionInfo.GetVersionInfo(
Path.Combine(
Path.GetPathRoot(Environment.SystemDirectory),
SystemHelper.Is64BitOS() ? @"Windows\SysWOW64\" : @"Windows\System32\",
dll));
result.Append(dll);
result.Append(": ");
result.Append(String.Format(
"{0}.{1}.{2}.{3}",
version.FileMajorPart,
version.FileMinorPart,
version.FileBuildPart,
version.FilePrivatePart));
result.Append("\r\n");
}
return result.ToString();
}
public static bool CheckCoreDLLs()
{
string[] dlls = {"LoaderDll.dll", "LocaleEmulator.dll"};
return
dlls.Select(dll => Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), dll))
.All(File.Exists);
}
}
}