Form1.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using Azylee.Core.DataUtils.CollectionUtils;
  2. using Azylee.Core.IOUtils.DirUtils;
  3. using Azylee.Core.IOUtils.FileUtils;
  4. using Azylee.Core.IOUtils.TxtUtils;
  5. using Azylee.Core.Plus.DataUtils.JsonUtils;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.IO;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. using Version.Builder.Models;
  12. namespace Version.Builder
  13. {
  14. public partial class Form1 : Form
  15. {
  16. DateTime beginTime = DateTime.Now;
  17. DateTime endTime = DateTime.Now;
  18. public Form1()
  19. {
  20. InitializeComponent();
  21. }
  22. private void BtBuild_Click(object sender, EventArgs e)
  23. {
  24. Task.Factory.StartNew(() =>
  25. {
  26. beginTime = DateTime.Now;
  27. Toast("开始检索并生成目录文件,请稍候……");
  28. CreateVersionMap();
  29. Toast(string.Format("生成完成,用时:{0:f2} 毫秒。",
  30. (DateTime.Now - beginTime).TotalMilliseconds));
  31. });
  32. }
  33. private void CreateVersionMap()
  34. {
  35. string versionNumber = TbVersionNumber.Text;
  36. string ftpPath = TbFtpPath.Text;
  37. string[] beginClose = TbBeginClose.Text.Split(';');
  38. string[] endRun = TbEndRun.Text.Split(';');
  39. string path = TbPath.Text;
  40. string parentPath = DirTool.Parent(path);
  41. FileCodeTool fcode = new FileCodeTool();
  42. if (Directory.Exists(path) && Directory.Exists(parentPath))
  43. {
  44. List<string> fileList = FileTool.GetAllFile(path);
  45. if (!ListTool.IsNullOrEmpty(fileList))
  46. {
  47. VersionModel version = new VersionModel()
  48. {
  49. Number = versionNumber,
  50. ServerPath = ftpPath,
  51. BeginCloseProcess = beginClose,
  52. EndRunProcess = endRun,
  53. FileList = new List<VersionFile>()
  54. };
  55. foreach (var item in fileList)
  56. {
  57. version.FileList.Add(new VersionFile()
  58. {
  59. File = item.Replace(path, ""),
  60. MD5 = fcode.GetMD5(item),
  61. });
  62. }
  63. string file = string.Format(@"{0}\update.version", parentPath, versionNumber);
  64. string json = JsonTool.ToStr(version);
  65. TxtTool.Create(file, json);
  66. }
  67. }
  68. }
  69. public void Toast(string msg)
  70. {
  71. Invoke(new Action(() =>
  72. {
  73. LbResult.Text = msg;
  74. }));
  75. }
  76. }
  77. }