11using System ;
22using System . Collections . Generic ;
3+ using System . Diagnostics ;
4+ using System . IO ;
35using System . Linq ;
46using System . Windows . Forms ;
57
@@ -13,9 +15,48 @@ static class Program
1315 [ STAThread ]
1416 static void Main ( )
1517 {
16- Application . EnableVisualStyles ( ) ;
17- Application . SetCompatibleTextRenderingDefault ( false ) ;
18- Application . Run ( new frmMain ( ) ) ;
18+ string strError ;
19+ if ( CheckInit ( out strError ) )
20+ {
21+ Application . EnableVisualStyles ( ) ;
22+ Application . SetCompatibleTextRenderingDefault ( false ) ;
23+ Application . Run ( new frmMain ( ) ) ;
24+ }
25+ else
26+ {
27+ if ( MessageBox . Show ( strError , "无法启动程序" , MessageBoxButtons . OKCancel , MessageBoxIcon . Error ) == DialogResult . OK )
28+ {
29+ System . Diagnostics . Process . Start ( "https://github.com/xiaoxinpro/SerialPortHelper/releases" ) ;
30+ }
31+ Application . Exit ( ) ;
32+ }
33+
34+ }
35+
36+ static bool CheckInit ( out string message )
37+ {
38+ message = "" ;
39+
40+ //获取运行目录
41+ string strPath = System . AppDomain . CurrentDomain . SetupInformation . ApplicationBase ;
42+
43+ //判断SerialPortHelperLib.dll是否有效
44+ string strPathSerialPortHelperLib = strPath + @"SerialPortHelperLib.dll" ;
45+ if ( ! File . Exists ( strPathSerialPortHelperLib ) )
46+ {
47+ message = "缺少SerialPortHelperLib.dll文件,请安装最新版本。" ;
48+ return false ;
49+ }
50+
51+ //判断SerialPortHelperLib.dll版本号
52+ Version verSerialPortHelperLib = new Version ( FileVersionInfo . GetVersionInfo ( strPathSerialPortHelperLib ) . FileVersion ) ;
53+ if ( verSerialPortHelperLib < new Version ( "18.6.8.0" ) )
54+ {
55+ message = "类库文件SerialPortHelperLib.dll版本过低,请安装最新版本。" ;
56+ return false ;
57+ }
58+
59+ return true ;
1960 }
2061 }
2162}
0 commit comments