-
Notifications
You must be signed in to change notification settings - Fork 92
/
Copy pathFormMain.cs
64 lines (56 loc) · 2.26 KB
/
FormMain.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
using System.Diagnostics;
using System.Globalization;
using System.Runtime.InteropServices;
namespace SecureDNSClientPortable
{
public partial class FormMain : Form
{
public static readonly Architecture ArchOs = RuntimeInformation.OSArchitecture;
public static readonly Architecture ArchProcess = RuntimeInformation.ProcessArchitecture;
public FormMain()
{
InitializeComponent();
Hide();
Opacity = 0;
try
{
// Setting Culture Is Necessary To Read Args In Any Windows Display Language Other Than English
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture;
CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.InvariantCulture;
string? appPath = null;
bool x64 = ArchProcess == Architecture.X64 && ArchOs == Architecture.X64;
bool x86 = ArchProcess == Architecture.X86 &&
(ArchOs == Architecture.X86 || ArchOs == Architecture.X64 ||
ArchOs == Architecture.Arm || ArchOs == Architecture.Arm64);
if (x64 || x86)
appPath = Path.GetFullPath(Path.Combine(AppContext.BaseDirectory, "SecureDNSClient", "SecureDNSClient.exe"));
if (!string.IsNullOrEmpty(appPath))
{
string args = $"-IsPortable=True";
Process.Start(appPath, args);
}
else
{
string msgNotSupported = $"Can't Run {ArchProcess} Application On {ArchOs} OS.";
MessageBox.Show(msgNotSupported, "Not Supported", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
try
{
Task.Delay(3000).Wait();
Close();
Environment.Exit(0);
Application.Exit();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}