-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
91 lines (89 loc) · 3.39 KB
/
Program.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
using System;
using System.Diagnostics;
using System.Reflection;
using System.Windows.Forms;
using ViPER4WindowsBin.Utils;
namespace ViPER4WindowsBin
{
internal static class Program
{
[STAThread]
private static void Main(string[] szArgs)
{
if (RunningInstance() != null)
return;
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
string szLanguagePath = "";
string szLanguageFile = "";
string baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
if (!baseDirectory.EndsWith("\\"))
baseDirectory += "\\";
string szFolder = baseDirectory + "Language\\";
string str1 = new ConfigFile(baseDirectory + "Config.ini").ReadConfig("$LANGUAGE_NAME");
if (str1 == "")
str1 = "English";
string[] strArray = new FolderExplorer().ListFiles(szFolder);
string str2 = "";
foreach (string szConfigPath in strArray)
{
if (new ConfigFile(szConfigPath).ReadConfig("$LANGUAGE_NAME").Trim() == str1)
{
str2 = szConfigPath;
break;
}
}
if (str2 != "")
{
szLanguagePath = szFolder;
szLanguageFile = str2;
}
else if (str1 == "English")
{
_ = (int)MessageBox.Show("Can not load default language (English), use built-in language.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
else
{
string str3 = "English";
foreach (string szConfigPath in strArray)
{
if (new ConfigFile(szConfigPath).ReadConfig("$LANGUAGE_NAME").Trim() == str3)
{
str2 = szConfigPath;
break;
}
}
if (str2 != "")
{
szLanguagePath = szFolder;
szLanguageFile = str2;
}
else
{
_ = (int)MessageBox.Show("Can not load default language (English), use built-in language.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
}
if (szLanguagePath != "" && szLanguageFile != "")
GlobalMessages.LoadMessages(szLanguageFile);
if (!RegHelper.CheckConfigRegister())
{
_ = (int)MessageBox.Show(GlobalMessages.DRIVER_NOT_CONFIG, GlobalMessages.ERROR, MessageBoxButtons.OK, MessageBoxIcon.Hand);
}
else
{
FrmMain.SetLanguage(szLanguagePath, szLanguageFile);
Application.Run(new FrmMain(szArgs));
}
}
private static Process RunningInstance()
{
Process currentProcess = Process.GetCurrentProcess();
foreach (Process process in Process.GetProcessesByName(currentProcess.ProcessName))
{
if (process.Id != currentProcess.Id && Assembly.GetExecutingAssembly().Location.Replace("/", "\\") == currentProcess.MainModule.FileName)
return process;
}
return null;
}
}
}