private void Form1_Load(object sender, EventArgs e) { ftpaddress = ConfigurationManager.AppSettings["FtpAddress"]; ftpaccount = ConfigurationManager.AppSettings["FtpAccount"]; ftppassword = ConfigurationManager.AppSettings["FtpPassword"]; updateFile = ConfigurationManager.AppSettings["UpdateFile"]; updateProcess = ConfigurationManager.AppSettings["UpdateProcess"]; updateProcessPath = ConfigurationManager.AppSettings["UpdateProcessPath"]; isStartAfterUpdate = ConfigurationManager.AppSettings["IsStartAfterUpdate"]; string path = AppDomain.CurrentDomain.BaseDirectory; if (!Directory.Exists(path + "BackUp")) { Directory.CreateDirectory(path + "BackUp"); } //MessageBox.Show(path); verModle = ReadConfig(path + "UpdateVersion.xml"); string passive = ConfigurationManager.AppSettings["Passive"]; //下载更新文件 ftp = new FTPHelper(ftpaddress, "", ftpaccount, ftppassword, passive == "1"?true:false); bool ret = ftp.Download(path, updateFile); if (ret) { listBoxTip.Items.Clear(); //开始解析文件,查看哪些文件需要更新 arrUpdate = ParseVersionFile(path + updateFile); foreach (var item in arrUpdate) { listBoxTip.Items.Add(item); } progressBar1.Maximum = arrUpdate.Count; if (arrUpdate.Count > 0) { DialogResult dr = MessageBox.Show("有更新文件,确认更新?", "提示", MessageBoxButtons.OKCancel); if (dr == DialogResult.OK) { if (KillProcess()) { Thread.Sleep(2000); Thread td = new Thread(WorkThread); td.Start(); } else { MessageBox.Show("请关闭更新进程,然后手动执行更新程序"); } } else { this.Close(); } } else { if (File.Exists(path + updateFile)) { File.Delete(path + updateFile); } //File.Move(path + updateFile, path + "UpdateVersion.xml"); if (args != null && args.Length > 0 && args[0] == "1") { MessageBox.Show("项目工程没有更新!"); } this.Close(); } } else { MessageBox.Show("下载文件出错" + updateFile); } }