Form1.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Threading.Tasks;
  5. using System.Windows.Forms;
  6. using Version.Builder.Models;
  7. using Y.Utils.DataUtils.Collections;
  8. using Y.Utils.DataUtils.JsonUtils;
  9. using Y.Utils.IOUtils.FileUtils;
  10. using Y.Utils.IOUtils.PathUtils;
  11. using Y.Utils.IOUtils.TxtUtils;
  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. this.Invoke(new Action(() => { LbResult.Text = "开始检索并生成目录文件,请稍候……"; }));
  27. beginTime = DateTime.Now;
  28. string path = TbPath.Text;
  29. string parentPath = DirTool.Parent(path);
  30. FileCodeTool fcode = new FileCodeTool();
  31. if (Directory.Exists(path) && Directory.Exists(parentPath))
  32. {
  33. List<string> fileList = FileTool.GetAllFile(path);
  34. if (!ListTool.IsNullOrEmpty(fileList))
  35. {
  36. VersionModel version = new VersionModel()
  37. { Number = DateTime.Now.Second, Path = path, FileList = new List<VersionFile>(), };
  38. foreach (var item in fileList)
  39. {
  40. version.FileList.Add(new VersionFile()
  41. {
  42. File = item.Replace(path, ""),
  43. MD5 = fcode.GetMD5(item),
  44. });
  45. }
  46. string file = string.Format(@"{0}\version.txt", parentPath);
  47. string json = JsonTool.ToStr(version);
  48. TxtTool.Create(file, json);
  49. }
  50. }
  51. endTime = DateTime.Now;
  52. this.Invoke(new Action(() => { LbResult.Text = string.Format("生成完成,用时:{0:f2} 毫秒。", (endTime - beginTime).TotalMilliseconds); }));
  53. });
  54. }
  55. }
  56. }