using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Welling_Motor_Debug_Tool { public partial class Version : Form { //存储路径文件 LocalInfo localInfo = new LocalInfo(); //服务器配置 string IP, Port, User, PassWD; //FTP ftp myFtp = new ftp(); public Version() { InitializeComponent(); } private void Version_Load(object sender, EventArgs e) { //更新版本信息 label_Ver.Text = "版本: V" + mainForm.Version; label_BT.Text = "编译时间:" + System.IO.File.GetLastWriteTime(this.GetType().Assembly.Location).ToString("yyyy-MM-dd HH:mm:ss"); //导入网络配置 if (System.IO.File.Exists(localInfo.LocalPath + localInfo.ConfigFileName)) //存在配置文件,导入配置信息 { //打开文件 StreamReader objReader = new StreamReader(localInfo.LocalPath + localInfo.ConfigFileName); string sLine = ""; ArrayList array_CfgInfo = new ArrayList(); array_CfgInfo.Clear(); while (sLine != null) { sLine = objReader.ReadLine(); array_CfgInfo.Add(sLine); } objReader.Close(); //解析配置文件 try { //Server Set IP, Port, User, PassWS, ModelPath; IP = array_CfgInfo[12].ToString().Split(':')[1]; Port = array_CfgInfo[13].ToString().Split(':')[1]; User = array_CfgInfo[14].ToString().Split(':')[1]; PassWD = array_CfgInfo[15].ToString().Split(':')[1]; myFtp.FtpOption(IP, Port, User, PassWD); } catch (System.Exception) { MessageBox.Show("参数格式错误,写入默认值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { MessageBox.Show("参数文件丢失!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); this.Close(); } } private void button_CheckVersion_Click(object sender, EventArgs e) { //检查网络状态 if (myFtp.CheckFtp() == false) { MessageBox.Show("网络断开", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } else { //检查本地文件删除 if (System.IO.File.Exists(localInfo.LocalPath + "\\Version")) System.IO.File.Delete(localInfo.LocalPath + "\\Version"); //读取最新版本号 myFtp.DownloadFile("/Tools/Welling_Motor_Debug_Tool/Version", localInfo.LocalPath); StreamReader objReader = new StreamReader(localInfo.LocalPath + "\\Version"); string sLine = ""; ArrayList arrText = new ArrayList();//创建一个动态数组 while (sLine != null) { sLine = objReader.ReadLine(); arrText.Add(sLine); } objReader.Close(); System.IO.File.Delete(localInfo.LocalPath + "\\Version"); //检查是否有最新版本 string[] VerOld = mainForm.Version.Trim().Split('.'); string[] VerNew = arrText[0].ToString().Trim().Split('.'); if (Convert.ToInt16(VerNew[0]) <= Convert.ToInt16(VerOld[0])) { if (Convert.ToInt16(VerNew[1]) <= Convert.ToInt16(VerOld[1])) { if (Convert.ToInt16(VerNew[2]) <= Convert.ToInt16(VerOld[2])) { MessageBox.Show("版本已是最新", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } } //下载最新版本 string SavePath = Directory.GetCurrentDirectory(); string[] FileList = myFtp.GetFileNameList("/Tools/Welling_Motor_Debug_Tool"); foreach (string file in FileList) { if (file.Contains(".exe")) { myFtp.DownloadFile("/Tools/Welling_Motor_Debug_Tool/" + file, SavePath); MessageBox.Show("最新版本下载完成,请手动删除旧版本\r\n最新版本:" + file, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } } } } }