Version.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.IO;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. namespace Welling_Motor_Debug_Tool
  13. {
  14. public partial class Version : Form
  15. {
  16. //存储路径文件
  17. LocalInfo localInfo = new LocalInfo();
  18. //服务器配置
  19. string IP, Port, User, PassWD;
  20. //FTP
  21. ftp myFtp = new ftp();
  22. public Version()
  23. {
  24. InitializeComponent();
  25. }
  26. private void Version_Load(object sender, EventArgs e)
  27. {
  28. //更新版本信息
  29. label_Ver.Text = "版本: V" + mainForm.Version;
  30. label_BT.Text = "编译时间:" + System.IO.File.GetLastWriteTime(this.GetType().Assembly.Location).ToString("yyyy-MM-dd HH:mm:ss");
  31. //导入网络配置
  32. if (System.IO.File.Exists(localInfo.LocalPath + localInfo.ConfigFileName)) //存在配置文件,导入配置信息
  33. {
  34. //打开文件
  35. StreamReader objReader = new StreamReader(localInfo.LocalPath + localInfo.ConfigFileName);
  36. string sLine = "";
  37. ArrayList array_CfgInfo = new ArrayList();
  38. array_CfgInfo.Clear();
  39. while (sLine != null)
  40. {
  41. sLine = objReader.ReadLine();
  42. array_CfgInfo.Add(sLine);
  43. }
  44. objReader.Close();
  45. //解析配置文件
  46. try
  47. {
  48. //Server Set IP, Port, User, PassWS, ModelPath;
  49. IP = array_CfgInfo[12].ToString().Split(':')[1];
  50. Port = array_CfgInfo[13].ToString().Split(':')[1];
  51. User = array_CfgInfo[14].ToString().Split(':')[1];
  52. PassWD = array_CfgInfo[15].ToString().Split(':')[1];
  53. myFtp.FtpOption(IP, Port, User, PassWD);
  54. }
  55. catch (System.Exception)
  56. {
  57. MessageBox.Show("参数格式错误,写入默认值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  58. }
  59. }
  60. else
  61. {
  62. MessageBox.Show("参数文件丢失!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  63. this.Close();
  64. }
  65. }
  66. private void button_CheckVersion_Click(object sender, EventArgs e)
  67. {
  68. //检查网络状态
  69. if (myFtp.CheckFtp() == false)
  70. {
  71. MessageBox.Show("网络断开", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  72. return;
  73. }
  74. else
  75. {
  76. //检查本地文件删除
  77. if (System.IO.File.Exists(localInfo.LocalPath + "\\Version"))
  78. System.IO.File.Delete(localInfo.LocalPath + "\\Version");
  79. //读取最新版本号
  80. myFtp.DownloadFile("/Tools/Welling_Motor_Debug_Tool/Version", localInfo.LocalPath);
  81. StreamReader objReader = new StreamReader(localInfo.LocalPath + "\\Version");
  82. string sLine = "";
  83. ArrayList arrText = new ArrayList();//创建一个动态数组
  84. while (sLine != null)
  85. {
  86. sLine = objReader.ReadLine();
  87. arrText.Add(sLine);
  88. }
  89. objReader.Close();
  90. System.IO.File.Delete(localInfo.LocalPath + "\\Version");
  91. //检查是否有最新版本
  92. string[] VerOld = mainForm.Version.Trim().Split('.');
  93. string[] VerNew = arrText[0].ToString().Trim().Split('.');
  94. if (Convert.ToInt16(VerNew[0]) <= Convert.ToInt16(VerOld[0]))
  95. {
  96. if (Convert.ToInt16(VerNew[1]) <= Convert.ToInt16(VerOld[1]))
  97. {
  98. if (Convert.ToInt16(VerNew[2]) <= Convert.ToInt16(VerOld[2]))
  99. {
  100. MessageBox.Show("版本已是最新", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  101. return;
  102. }
  103. }
  104. }
  105. //下载最新版本
  106. string SavePath = Directory.GetCurrentDirectory();
  107. string[] FileList = myFtp.GetFileNameList("/Tools/Welling_Motor_Debug_Tool");
  108. foreach (string file in FileList)
  109. {
  110. if (file.Contains(".exe"))
  111. {
  112. myFtp.DownloadFile("/Tools/Welling_Motor_Debug_Tool/" + file, SavePath);
  113. MessageBox.Show("最新版本下载完成,请手动删除旧版本\r\n最新版本:" + file, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  114. return;
  115. }
  116. }
  117. }
  118. }
  119. }
  120. }