148 lines
		
	
	
		
			5.5 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			148 lines
		
	
	
		
			5.5 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| using System;
 | |
| using System.Collections.Generic;
 | |
| using System.ComponentModel;
 | |
| using System.Data;
 | |
| using System.Drawing;
 | |
| using System.Linq;
 | |
| using System.Text;
 | |
| using System.Windows.Forms;
 | |
| using System.Threading;
 | |
| using System.Diagnostics;
 | |
| using System.IO;
 | |
| using System.Collections;
 | |
| using System.Threading.Tasks;
 | |
| 
 | |
| 
 | |
| namespace AIMSAutoUpdate
 | |
| {
 | |
|     public partial class frmAutoUpdate : Form
 | |
|     {
 | |
|         private Thread threadStart;
 | |
|         private int intProgressBar = 0;
 | |
|         private XmlOperator xmlOpe = new XmlOperator(AppDomain.CurrentDomain.BaseDirectory + @"\UpdateList.xml");
 | |
|         private string updateUrl = string.Empty;
 | |
|         private string tempUpdatePath = string.Empty;
 | |
|         private string FtpAddress;
 | |
|         private string User;
 | |
|         private string PassWord;
 | |
|         private string SysName;
 | |
|         private string Versions;
 | |
|         private string encoding;
 | |
| 
 | |
|         public frmAutoUpdate()
 | |
|         {
 | |
|             InitializeComponent();
 | |
|             System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;
 | |
|         }
 | |
|         private void frmAutoUpdate_Load(object sender, EventArgs e)
 | |
|         {
 | |
|             try
 | |
|             {
 | |
|                 FtpAddress = xmlOpe.GetNode("FtpAddress")[0].ToString();
 | |
|                 User = xmlOpe.GetNode("User")[0].ToString();
 | |
|                 PassWord = xmlOpe.GetNode("PassWord")[0].ToString();
 | |
|                 SysName = xmlOpe.GetNode("SysName")[0].ToString();
 | |
|                 Versions = xmlOpe.GetNode("Version")[0].ToString();
 | |
|                 encoding = xmlOpe.GetNode("Encoding")[0].ToString();
 | |
|                 Text = "自动升级程序";
 | |
|                 System.Diagnostics.Process[] myProcesses = System.Diagnostics.Process.GetProcesses();
 | |
|                 foreach (System.Diagnostics.Process myProcess in myProcesses)
 | |
|                 {
 | |
|                     if (myProcess.ProcessName == SysName)
 | |
|                     {
 | |
|                         myProcess.CloseMainWindow();
 | |
|                         myProcess.Kill();
 | |
|                         myProcess.WaitForExit();
 | |
|                         myProcess.Close();
 | |
|                         continue;
 | |
|                     }
 | |
|                 }
 | |
|                 timer2.Enabled = true;
 | |
|                 timer2.Start();
 | |
| 
 | |
|             }
 | |
|             catch (Exception)
 | |
|             {
 | |
|                 MessageBox.Show("更新失败!");
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         public void WaitingOpen_Fun()
 | |
|         {
 | |
|             for (int i = 0; i < FTPTransmission.ListFileDirectory.Count; i++)
 | |
|             {
 | |
|                 try
 | |
|                 {
 | |
|                     if (FTPTransmission.ListFileDirectory[i].filename.Contains("AIMSAutoUpdate")) continue;
 | |
|                     FTPTransmission.download(FTPTransmission.ListFileDirectory[i].localPath, FTPTransmission.ListFileDirectory[i].ftpPath, User, PassWord);
 | |
|                     intProgressBar = i + 1;
 | |
|                 }
 | |
|                 catch (Exception ex)
 | |
|                 {
 | |
|                     MessageBox.Show(ex.Message);
 | |
|                     continue;
 | |
|                 }
 | |
|             }
 | |
|         }
 | |
|          
 | |
|         int count = 0;
 | |
|         private void timer1_Tick_1(object sender, EventArgs e)
 | |
|         {
 | |
|             progressBar1.Value = intProgressBar;
 | |
|             label5.Text = intProgressBar.ToString();
 | |
|             if (intProgressBar >= FTPTransmission.ListFileDirectory.Count)
 | |
|             {
 | |
|                 count++;
 | |
|             }
 | |
|             if (count == 10)
 | |
|             {
 | |
|                 MessageBox.Show("更新完成,请重新启动!", "系统提示");
 | |
|                 System.Environment.Exit(0);
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         private void timer2_Tick(object sender, EventArgs e)
 | |
|         {
 | |
|             timer2.Interval = 1000000000;
 | |
|             XmlFiles serverXmlFiles = new XmlFiles(AppDomain.CurrentDomain.BaseDirectory + @"\UpdateList.xml");
 | |
|             Hashtable htUpdateFile = new Hashtable();
 | |
|             int availableUpdate = new AppUpdater().CheckForUpdate(serverXmlFiles, out htUpdateFile);
 | |
| 
 | |
|             FTPTransmission.ListFileDirectory.Clear();
 | |
|             FTPTransmission.downftp(FtpAddress, AppDomain.CurrentDomain.BaseDirectory, User, PassWord, htUpdateFile, encoding);
 | |
| 
 | |
|             FTPTransmission.nowListFileDirectory.Clear();
 | |
|             FTPTransmission.downNow(AppDomain.CurrentDomain.BaseDirectory);
 | |
|             if (FTPTransmission.ListFileDirectory.Count <= 0)// StartPrmAndExit();
 | |
|                 System.Environment.Exit(0);
 | |
|             for (int i = FTPTransmission.ListFileDirectory.Count - 1; i >= 0; i--)
 | |
|             {
 | |
|                 try
 | |
|                 {
 | |
|                     for (int j = 0; j < FTPTransmission.nowListFileDirectory.Count; j++)
 | |
|                     {
 | |
|                         if (FTPTransmission.nowListFileDirectory[j].MD5Hash == FTPTransmission.ListFileDirectory[i].MD5Hash && FTPTransmission.nowListFileDirectory[j].filelength == FTPTransmission.ListFileDirectory[i].filelength)
 | |
|                         {
 | |
|                             FTPTransmission.ListFileDirectory.Remove(FTPTransmission.ListFileDirectory[i]);
 | |
|                             break;
 | |
|                         }
 | |
|                     }
 | |
|                 }
 | |
|                 catch (Exception)
 | |
|                 {
 | |
|                     continue;
 | |
|                 }
 | |
|             }
 | |
|             progressBar1.Value = 0;
 | |
|             progressBar1.Minimum = 0;
 | |
|             progressBar1.Maximum = FTPTransmission.ListFileDirectory.Count;
 | |
|             label4.Text = FTPTransmission.ListFileDirectory.Count.ToString();
 | |
|             timer1.Start();
 | |
|             threadStart = new Thread(new ThreadStart(WaitingOpen_Fun));
 | |
|             threadStart.Start();
 | |
|         }
 | |
| 
 | |
| 
 | |
|     }
 | |
| }
 |