FrmLoading.cs
4.8 KB
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
using System;
using Model;
using System.Threading;
using System.Windows.Forms;
using BLL;
using System.Diagnostics;
using System.IO;
namespace SmartScan
{
public partial class FrmLoading : Asa.FaceControl.FormBase
{
private readonly bool back;
public FrmLoading(bool back)
{
this.back = back;
InitializeComponent();
}
private void Init()
{
Process current = Process.GetCurrentProcess();
FileInfo fileInfo = new FileInfo(current.MainModule.FileName);
DateTime dateTime = fileInfo.LastWriteTime;
string version = $"{dateTime.Year%10}.{dateTime.Month}.{dateTime.Day.ToString("00")}{dateTime.Hour.ToString("00")}";
LogNet.log.Info($"===== 程序开始 {version} =====");
Common.config = new BLL.Config();
Common.config.SoftVersion = version;
//BLL.Config.Backgrounder = back;
ExtraFileData.Init();
Common.extraKey = ExtraFileData.Titles;
Asa.FaceControl.Language.LoadPath(FilePath.LANGUAGE_DIR);
LogNet.log.Debug("加载语言文件夹:" + FilePath.LANGUAGE_DIR);
Asa.FaceControl.Language.LoadLanguage(Common.config.Language);
Common.cameraVision = new Asa.Camera.VisionLib(FilePath.CONFIG_CAMERA, Common.config.EnabledCamera);
LogNet.log.Info("加载相机,数量:" + Common.cameraVision.Count);
if (Common.config.EnabledIO)
{
string ip = Common.config.IOIPAddress;
Common.ioModule = new BLL.IOManage(ip,Common.config.iomodule);
Common.ioModule.Connect();
LogNet.log.Info($"加载IO模块,IP地址:{ip},iomodule:{Common.config.iomodule}");
}
if (Config.Func_EnabledOCR)
{
LogNet.log.Info("启用OCR模块");
}
Common.lightSource = new();
Common.extension = new(Common.config);
Common.labelEdit = new();
Common.mateEdit = new();
WebService.Open();
ReadMacro();
Shortcut();
Invoke(new Action(() => { Close(); }));
}
private void ReadMacro()
{
LogNet.log.Info("读取关键字文件");
LogNet.log.Debug("关键字文件路径:" + FilePath.CONFIG_MACRO_KEY);
Common.macroKey = new();
if (System.IO.File.Exists(FilePath.CONFIG_MACRO_KEY))
{
string[] lines = System.IO.File.ReadAllLines(FilePath.CONFIG_MACRO_KEY);
Common.macroKey.AddRange(lines);
LogNet.log.Debug($"添加关键字 {lines.Length} 行");
}
else
{
LogNet.log.Debug("关键字文件路径不存在");
}
}
private void Shortcut()
{
if (!Common.config.CheckShortcut) return;
string name = System.IO.Path.GetFileNameWithoutExtension(Application.ExecutablePath);
string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + string.Format("\\{0}.lnk", name);
if (System.IO.File.Exists(path)) return;
//向cmd窗口发送输入信息
string str = Application.StartupPath + "\\myshortcut.vbs";
if (!System.IO.File.Exists(str)) return;
str = "\"" + str + "\"";
str += " /shortcut:" + name;
str += " /target:\"" + Application.ExecutablePath + "\"";
str += " /directory:\"" + Application.StartupPath + "\"";
str += " /description:" + string.Format("{0:yyyy-MM-dd}", DateTime.Now);
str += "&exit";
System.Diagnostics.Process process = new();
process.StartInfo.FileName = "cmd.exe";
process.StartInfo.UseShellExecute = false; //是否使用操作系统shell启动
process.StartInfo.RedirectStandardInput = true; //接受来自调用程序的输入信息
process.StartInfo.RedirectStandardOutput = true; //由调用程序获取输出信息
process.StartInfo.RedirectStandardError = true; //重定向标准错误输出
process.StartInfo.CreateNoWindow = true; //不显示程序窗口
process.Start();
process.StandardInput.WriteLine(str);
process.StandardInput.AutoFlush = true;
process.WaitForExit();
process.Close();
}
private void FrmLoading_Load(object sender, EventArgs e)
{
if (!back) faceLoading1.Start();
new Thread(new ThreadStart(() => Init())).Start();
}
private void FrmLoading_Activated(object sender, EventArgs e)
{
if (back) Hide();
}
}
}