-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathStart.cs
146 lines (131 loc) · 3.87 KB
/
Start.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
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
136
137
138
139
140
141
142
143
144
145
146
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Diagnostics;
using System.Threading;
using CSRegexStringLayer;
using CSProcessLayer;
namespace RadioEye
{
public partial class Start : Form
{
StringBuilder szDevice;
public Start(ref StringBuilder szDeviceTmp)
{
szDevice = szDeviceTmp;
InitializeComponent();
}
private void Start_Load(object sender, EventArgs e)
{
timer.Start();
lab_Tip.Text = "Checking Libnfc Components...";
lab_Ret.Text = "";
}
int TimerCount = 0;
bool bOk = true;
private void timer_Tick(object sender, EventArgs e)
{
if (!bOk)
{
timer.Dispose();
Thread.Sleep(3000);
System.Environment.Exit(0);
}
string szRet = "";
TimerCount++;
switch (TimerCount)
{
case 1:
timer.Stop();
bOk = Set_LabelRet(Chk_Component(ref szRet), szRet);
timer.Start();
break;
case 2:
lab_Tip.Text = "Checking RFID Device...";
lab_Ret.Text = "";
break;
case 3:
timer.Stop();
bOk = Set_LabelRet(Chk_Device(ref szRet), szRet);
timer.Start();
break;
case 4:
lab_Tip.Text = "Welcome to the RadioEye...";
lab_Ret.Text = "";
break;
case 5:
break;
case 6:
timer.Dispose();
this.Close();
break;
}
}
private bool Set_LabelRet(bool bStatus, string szRet)
{
if (bStatus)
{
lab_Ret.ForeColor = Color.Green;
lab_Ret.Text = szRet;
}
else
{
lab_Ret.ForeColor = Color.Red;
lab_Ret.Text = szRet;
}
return bStatus;
}
private bool Chk_Component(ref string szRet)
{
string[] szFileList = new string[]
{
"nfc/libnfc.dll",
"nfc/libusb0.dll",
"nfc/nfc-list.exe",
"nfc/nfc-mfsetuid.exe",
"nfc/nfc-mfclassic.exe",
"nfc/mfoc.exe",
};
foreach (string szFileItem in szFileList)
{
if (!File.Exists(szFileItem))
{
szRet = "Error! " + szFileItem + " does not exist";
return false;
}
}
szRet = "OK!";
return true;
}
private bool Chk_Device(ref string szRet)
{
ProcessLayer pl = new ProcessLayer();
bool bSuccess = pl.SyncStart("nfc/nfc-list.exe", null);
if (!bSuccess)
{
szRet = "Error! Can not connect to the device";
return false;
}
string[] RegexRet = RegexStringLayer.GetSubString(pl.m_RetOutputMsg.ToString(), "NFC device:\\s*(.+)\\s*/");
bool bRet;
if (string.IsNullOrWhiteSpace(RegexRet[0]))
{
bRet = false;
szRet = "Error! Can not connect to the device";
}
else
{
bRet = true;
szRet = "Device: " + RegexRet[0];
szDevice.Append(RegexRet[0]);
}
return bRet;
}
}
}