Version.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. string ChangeLog = "修改记录:\r\n" + "V2.1.6\r\n" +
  18. "1,修改控制器内阻校准指令,增加写入存储标志;\r\n" +
  19. "2,参数生成界面增加导入样机测试记录的文件功能;\r\n" +
  20. "3,参数生成界面增加锁,防止误触。\r\n\r\n" +
  21. mainForm.Version + "\r\n" +
  22. "1,解决系统显示缩放后,截图显示不完全的问题;\r\n" +
  23. "2,允许离线使用是关闭网络定时检测;\r\n" +
  24. "3,定时检测网络断开时不自动关闭,此时不允许使用,等待网络恢复;\r\n" +
  25. "4,启动登录密码错误时不自动关闭,重新进入登录;\r\n" +
  26. "5,部分提示框修改为自动关闭;\r\n" +
  27. "6,增加读取本机信息功能;\r\n" +
  28. "7,启动时自动上传登录日志,包含本机信息。\r\n"
  29. ;
  30. //存储路径文件
  31. LocalInfo localInfo = new LocalInfo();
  32. //服务器配置
  33. string IP, Port, User, PassWD;
  34. //FTP
  35. ftp myFtp = new ftp();
  36. public Version()
  37. {
  38. InitializeComponent();
  39. }
  40. private void Version_Load(object sender, EventArgs e)
  41. {
  42. //更新版本信息
  43. label_Ver.Text = "版本: V" + mainForm.Version;
  44. label_BT.Text = "编译时间:" + System.IO.File.GetLastWriteTime(this.GetType().Assembly.Location).ToString("yyyy-MM-dd HH:mm:ss");
  45. //修改日志
  46. richTextBox_Log.AppendText(ChangeLog);
  47. //导入网络配置
  48. if (System.IO.File.Exists(localInfo.LocalPath + localInfo.ConfigFileName)) //存在配置文件,导入配置信息
  49. {
  50. //打开文件
  51. StreamReader objReader = new StreamReader(localInfo.LocalPath + localInfo.ConfigFileName);
  52. string sLine = "";
  53. ArrayList array_CfgInfo = new ArrayList();
  54. array_CfgInfo.Clear();
  55. while (sLine != null)
  56. {
  57. sLine = objReader.ReadLine();
  58. array_CfgInfo.Add(sLine);
  59. }
  60. objReader.Close();
  61. //解析配置文件
  62. try
  63. {
  64. //Server Set IP, Port, User, PassWS, ModelPath;
  65. IP = array_CfgInfo[12].ToString().Split(':')[1];
  66. Port = array_CfgInfo[13].ToString().Split(':')[1];
  67. User = array_CfgInfo[14].ToString().Split(':')[1];
  68. PassWD = array_CfgInfo[15].ToString().Split(':')[1];
  69. myFtp.FtpOption(IP, Port, User, PassWD, "admin", "ttium_admin");
  70. }
  71. catch (System.Exception)
  72. {
  73. MessageBox.Show("参数格式错误,写入默认值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  74. }
  75. }
  76. else
  77. {
  78. MessageBox.Show("参数文件丢失!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  79. this.Close();
  80. }
  81. }
  82. private void button_CheckVersion_Click(object sender, EventArgs e)
  83. {
  84. //检查网络状态
  85. if (myFtp.CheckFtp() == false)
  86. {
  87. MessageBox.Show("网络断开", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  88. return;
  89. }
  90. else
  91. {
  92. //检查本地文件删除
  93. if (System.IO.File.Exists(localInfo.LocalPath + "\\Version"))
  94. System.IO.File.Delete(localInfo.LocalPath + "\\Version");
  95. //读取最新版本号
  96. myFtp.DownloadFile("/Tools/Welling_Motor_Debug_Tool/Version", localInfo.LocalPath);
  97. StreamReader objReader = new StreamReader(localInfo.LocalPath + "\\Version");
  98. string sLine = "";
  99. ArrayList arrText = new ArrayList();//创建一个动态数组
  100. while (sLine != null)
  101. {
  102. sLine = objReader.ReadLine();
  103. arrText.Add(sLine);
  104. }
  105. objReader.Close();
  106. System.IO.File.Delete(localInfo.LocalPath + "\\Version");
  107. //检查是否有最新版本
  108. string[] VerOld = mainForm.Version.Trim().Split('.');
  109. string[] VerNew = arrText[0].ToString().Trim().Split('.');
  110. if (Convert.ToInt16(VerNew[0]) <= Convert.ToInt16(VerOld[0]))
  111. {
  112. if (Convert.ToInt16(VerNew[1]) <= Convert.ToInt16(VerOld[1]))
  113. {
  114. if (Convert.ToInt16(VerNew[2]) <= Convert.ToInt16(VerOld[2]))
  115. {
  116. MessageBox.Show("版本已是最新", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  117. return;
  118. }
  119. }
  120. }
  121. //下载最新版本
  122. string SavePath = Directory.GetCurrentDirectory();
  123. string[] FileList = myFtp.GetFileNameList("/Tools/Welling_Motor_Debug_Tool");
  124. foreach (string file in FileList)
  125. {
  126. if (file.Contains(".exe"))
  127. {
  128. myFtp.DownloadFile("/Tools/Welling_Motor_Debug_Tool/" + file, SavePath);
  129. MessageBox.Show("最新版本下载完成,请手动删除旧版本\r\n最新版本:" + file, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  130. return;
  131. }
  132. }
  133. }
  134. }
  135. }
  136. }