@@ -17,6 +17,21 @@ public partial class MainForm : Form
1717 /// </summary>
1818 private string launchAppName ;
1919
20+ /// <summary>
21+ /// 需要更新的业务应用程序所在目录
22+ /// </summary>
23+ private string launchAppDirectoryName ;
24+
25+ /// <summary>
26+ /// 需要更新的业务应用程序版本号
27+ /// </summary>
28+ private string launchAppVer ;
29+
30+ /// <summary>
31+ /// 需要更新的业务应用程序关联的进程
32+ /// </summary>
33+ private Process [ ] launchProcess ;
34+
2035 /// <summary>
2136 /// 检查更新模式:0,自动更新;1,手动检查(区别就是,自动更新的状态下,除非有新版本更新,才会显示提示框)
2237 /// </summary>
@@ -36,14 +51,27 @@ public MainForm(string _launchAppName, string _checkMode)
3651
3752 private void MainForm_Load ( object sender , EventArgs e )
3853 {
54+ //通过业务应用程序名,获取其进程信息
55+ launchProcess = Process . GetProcessesByName ( launchAppName ) ;
56+
57+ if ( launchProcess . Length > 0 )
58+ {
59+ launchAppDirectoryName = Path . GetDirectoryName ( launchProcess [ 0 ] . MainModule . FileName ) ;
60+ launchAppVer = launchProcess [ 0 ] . MainModule . FileVersionInfo . ProductVersion ;
61+ }
62+ else
63+ {
64+ HHMessageBox . Show ( "应用程序未启动: _" + launchAppName ) ;
65+ Application . Exit ( ) ;
66+ }
67+
3968 //下载服务器上版本更新信息
4069 verInfo = DownloadUpdateInfo ( Program . ServerUpdateUrl ) ;
4170
4271 if ( verInfo != null )
4372 {
4473 //比较版本号
45- string currentAppVer = Application . ProductVersion ;
46- if ( VersionCompare ( currentAppVer , verInfo . ReleaseVersion ) >= 0 )
74+ if ( VersionCompare ( launchAppVer , verInfo . ReleaseVersion ) >= 0 )
4775 {
4876 //this.Hide();//隐藏当前窗口
4977
@@ -85,35 +113,20 @@ private void btnUpdateNow_Click(object sender, EventArgs e)
85113 {
86114 this . Hide ( ) ; //隐藏当前窗口
87115
88- //通过业务应用程序名,获取其所在位置
89- Process [ ] processes = Process . GetProcessesByName ( launchAppName ) ;
116+ UpdateWork work = new UpdateWork ( launchAppDirectoryName , verInfo ) ;
90117
91- if ( processes . Length > 0 )
118+ //关闭业务应用程序关联的进程
119+ foreach ( Process p in launchProcess )
92120 {
93- //获取 需要更新的业务应用程序所在目录
94- string launchAppDirectoryName = Path . GetDirectoryName ( processes [ 0 ] . MainModule . FileName ) ;
95- UpdateWork work = new UpdateWork ( launchAppDirectoryName , verInfo ) ;
96-
97- //关闭业务应用程序关联的进程
98- foreach ( Process p in processes )
99- {
100- p . Kill ( ) ;
101- p . Close ( ) ;
102- }
103-
104- UpdateForm updateForm = new UpdateForm ( work ) ;
105- if ( updateForm . ShowDialog ( ) == DialogResult . OK )
106- {
107- Application . Exit ( ) ;
108- }
121+ p . Kill ( ) ;
122+ p . Close ( ) ;
109123 }
110- else
124+
125+ UpdateForm updateForm = new UpdateForm ( work ) ;
126+ if ( updateForm . ShowDialog ( ) == DialogResult . OK )
111127 {
112- HHMessageBox . Show ( "应用程序未启动: _" + launchAppName ) ;
113128 Application . Exit ( ) ;
114129 }
115-
116-
117130 }
118131 /// <summary>
119132 /// 忽略本次版本更新
@@ -176,7 +189,7 @@ private RemoteVersionInfo DownloadUpdateInfo(string serverUrl)
176189 try
177190 {
178191 byte [ ] bJson = updateClt . DownloadData ( serverUrl ) ;
179- updateJson = System . Text . Encoding . Default . GetString ( bJson ) ;
192+ updateJson = System . Text . Encoding . UTF8 . GetString ( bJson ) ;
180193 }
181194 catch ( Exception ex )
182195 {
0 commit comments