Form1.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using ShopSystem.Model.Sys;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Threading.Tasks;
  6. using System.Windows.Forms;
  7. using Y.Utils.BaseUtils;
  8. using Y.Utils.FileUtils;
  9. using Y.Utils.JsonUtils;
  10. using Y.Utils.TxtUtils;
  11. namespace Version.Builder
  12. {
  13. public partial class Form1 : Form
  14. {
  15. DateTime beginTime = DateTime.Now;
  16. DateTime endTime = DateTime.Now;
  17. public Form1()
  18. {
  19. InitializeComponent();
  20. }
  21. private void BtBuild_Click(object sender, EventArgs e)
  22. {
  23. Task.Factory.StartNew(() =>
  24. {
  25. this.Invoke(new Action(() => { LbResult.Text = "开始检索并生成目录文件,请稍候……"; }));
  26. beginTime = DateTime.Now;
  27. string path = TbPath.Text;
  28. string parentPath = DirTool.Parent(path);
  29. FileCodeHelper fcode = new FileCodeHelper();
  30. if (Directory.Exists(path) && Directory.Exists(parentPath))
  31. {
  32. List<string> fileList = FileTool.GetAllFile(path);
  33. if (!ListTool.IsNullOrEmpty(fileList))
  34. {
  35. VersionModel version = new VersionModel()
  36. { Number = DateTime.Now.Second, Path = path, FileList = new List<VersionFile>(), };
  37. foreach (var item in fileList)
  38. {
  39. version.FileList.Add(new VersionFile()
  40. {
  41. File = item.Replace(path, ""),
  42. MD5 = fcode.GetMD5(item),
  43. });
  44. }
  45. string file = string.Format(@"{0}\version.txt", parentPath);
  46. string json = JsonTool.ToStr(version);
  47. TxtTool.Create(file, json);
  48. }
  49. }
  50. endTime = DateTime.Now;
  51. this.Invoke(new Action(() => { LbResult.Text = string.Format("生成完成,用时:{0}秒。", (endTime - beginTime).TotalSeconds); }));
  52. });
  53. }
  54. }
  55. }