📄 appupdate.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.IO;
using System.Text;
using System.Net;
using System.Diagnostics;
using System.Threading;
namespace UpdateEr
{
/// <summary>
/// AppUpdate 的摘要说明。
/// </summary>
public class AppUpdate : System.Windows.Forms.Form
{
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Timer timer;
private System.ComponentModel.IContainer components;
public AppUpdate()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
this.timer.Start();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
[STAThread]
static void Main() {
Application.Run(new AppUpdate());
}
//正在更新
private void loadFile(){
String temp = "";
string fileUrlPath = "http://www.ESST.cn/SoftUpdate/TZLYIMS";
try{
WebRequest Wrequest = WebRequest.Create("http://www.ESST.cn/SoftUpdate/TZLYIMS/softUpdate.htm");
WebResponse Wresponse = Wrequest.GetResponse();
Stream Sm = Wresponse.GetResponseStream();
StreamReader Sr = new StreamReader(Sm,Encoding.GetEncoding("GB2312"));
temp = Sr.ReadToEnd().ToString();
Sr.Close();
}catch(Exception ex){
MessageBox.Show("升级检查时遇到错误,请关闭窗口重试。\n\n错误信息:" + ex.Message.ToString());
return;
}
int oneI = temp.IndexOf("]");
string dURL = temp.Substring(oneI+2,temp.Length-1-oneI-2);
try{
string[] fileS = dURL.Split(';');
for(int i=0;i<fileS.Length;i++){
string fileName = fileS[i].ToString();
this.label2.Text = "正在更新:" + fileName;
//DB2005.DLL是数据库文件,不允许更新
if(fileName != "" && !fileName.ToUpper().Equals("DB2005.DLL")){
string remoteUri = fileUrlPath + "/" + fileS[i].ToString();
WebClient myWebClient = new WebClient();
myWebClient.DownloadFile(remoteUri,fileName);
}
}
}catch(Exception ex){
MessageBox.Show("下载升级文件时出错,请关闭窗口重新启动程序。\n\n错误信息:" + ex.Message.ToString());
}
//下载完成,重新启动原程序
System.Diagnostics.Process p = new Process();
p.StartInfo.FileName = Application.StartupPath + "\\Eboer.MIS.MF.WinForm.exe";
p.Start();
Application.Exit();
}
//从网址中取出最后一个文件名,前提是这个网址中包含文件名
private string GetFileName(string urlStr){
if(urlStr.IndexOf("/") > 0){
string[] str = urlStr.Split('/');
return str[str.Length - 1];
}
return "";
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(AppUpdate));
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.label2 = new System.Windows.Forms.Label();
this.timer = new System.Windows.Forms.Timer(this.components);
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.groupBox1.Location = new System.Drawing.Point(8, 0);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(464, 40);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
//
// label2
//
this.label2.Location = new System.Drawing.Point(8, 16);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(440, 16);
this.label2.TabIndex = 3;
this.label2.Text = "准备升级中....";
//
// timer
//
this.timer.Interval = 30;
this.timer.Tick += new System.EventHandler(this.timer_Tick);
//
// AppUpdate
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(480, 45);
this.Controls.Add(this.groupBox1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "AppUpdate";
this.Text = "系统升级....";
this.groupBox1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 更新程序
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void timer_Tick(object sender, System.EventArgs e) {
this.timer.Stop();
Thread t = new Thread(new ThreadStart(this.loadFile));
t.Start();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -