FrmLoading.cs
5.4 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
128
129
130
131
132
133
134
135
136
137
138
using BLL;
using Model;
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Threading;
using System.Windows.Forms;
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);
LogNet.log = log4net.LogManager.GetLogger("SmartScan");
//DateTime dateTime = fileInfo.LastWriteTime;
//string version = $"{dateTime.Year%10}.{dateTime.Month}.{dateTime.Day.ToString("00")}{dateTime.Hour.ToString("00")}";
string version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
LogNet.log.Info($"===== 程序开始 {version} =====");
BLLCommon.config = new BLL.Config();
BLLCommon.config.SoftVersion = version;
//BLL.Config.Backgrounder = back;
ExtraFileData.Init();
BLLCommon.extraKey = ExtraFileData.Titles;
Asa.FaceControl.Language.LoadPath(FilePath.LANGUAGE_DIR);
LogNet.log.Debug("加载语言文件夹:" + FilePath.LANGUAGE_DIR);
Asa.FaceControl.Language.LoadLanguage(BLLCommon.config.Language);
Camera.LoadCamera();
if (BLLCommon.config.EnabledIO)
{
string ip = BLLCommon.config.IOIPAddress;
BLLCommon.ioModule = new BLL.IOManage(ip, BLLCommon.config.iomodule);
BLLCommon.ioModule.Connect();
LogNet.log.Info($"加载IO模块,IP地址:{ip},iomodule:{BLLCommon.config.iomodule}");
}
if (Config.Func_EnabledOCR)
{
LogNet.log.Info("启用OCR模块");
}
BLLCommon.lightSource = new();
BLLCommon.extension = new(BLLCommon.config);
BLLCommon.labelEdit = new();
BLLCommon.mateEdit = new();
//如果是直接启动ns100就不需要开启条码规则服务
//WebService.Open();
ReadMacro();
Shortcut();
Invoke(new Action(() => { Close(); }));
}
private void ReadMacro()
{
LogNet.log.Info("读取关键字文件");
LogNet.log.Debug("关键字文件路径:" + FilePath.CONFIG_MACRO_KEY);
BLLCommon.macroKey = new();
BLLCommon.macroKeyValue = new();
if (System.IO.File.Exists(FilePath.CONFIG_MACRO_KEY))
{
string[] lines = System.IO.File.ReadAllLines(FilePath.CONFIG_MACRO_KEY);
BLLCommon.macroKey.AddRange(lines);
LogNet.log.Debug($"添加关键字 {lines.Length} 行");
}
else
{
LogNet.log.Debug("关键字文件路径不存在");
}
if (System.IO.File.Exists(FilePath.CONFIG_MACRO_Value))
{
string[] lines = System.IO.File.ReadAllLines(FilePath.CONFIG_MACRO_Value);
BLLCommon.macroKeyValue.AddRange(lines);
LogNet.log.Debug($"添加关键字 {lines.Length} 行");
}
else
{
LogNet.log.Debug("关键字文件路径不存在");
}
}
private void Shortcut()
{
if (!BLLCommon.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();
}
}
}