MainForm.cs 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. using Oreo.VersionBuilder.Commons;
  2. using Oreo.VersionBuilder.Models;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Data;
  7. using System.Diagnostics;
  8. using System.Drawing;
  9. using System.IO;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using System.Windows.Forms;
  14. using Y.Utils.DataUtils.Collections;
  15. using Y.Utils.DataUtils.JsonUtils;
  16. using Y.Utils.IOUtils.FileUtils;
  17. using Y.Utils.IOUtils.TxtUtils;
  18. namespace Oreo.VersionBuilder.Views
  19. {
  20. public partial class MainForm : Form
  21. {
  22. string NowOpenFile = "";
  23. public MainForm()
  24. {
  25. InitializeComponent();
  26. }
  27. private void MainForm_Load(object sender, EventArgs e)
  28. {
  29. }
  30. #region 菜单项
  31. private void 新建ToolStripMenuItem_Click(object sender, EventArgs e)
  32. {
  33. Clear();
  34. TsslRunStatus.Text = "新建版本文件";
  35. }
  36. private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
  37. {
  38. Clear();
  39. OpenFileDialog fileDialog = new OpenFileDialog();
  40. fileDialog.Filter = "版本文件|*.version|文本文档|*.txt";
  41. if (fileDialog.ShowDialog() == DialogResult.OK)
  42. {
  43. string file = fileDialog.FileName;
  44. NowOpenFile = file;
  45. if (!string.IsNullOrWhiteSpace(file))
  46. {
  47. VersionModel vm = JsonTool.ToObjFromFile<VersionModel>(file);
  48. if (vm != null)
  49. {
  50. TbCodeName.Text = vm.CodeName;
  51. TbVersionNumber.Text = vm.VersionNumber;
  52. TbVersionDesc.Text = vm.VersionDesc;
  53. TbServerPath.Text = vm.ServerPath;
  54. TbPluginName.Text = vm.PluginName;
  55. TbPluginEntry.Text = vm.PluginEntry;
  56. TbBeforeUpdateStartProcess.Text = string.Join(",", vm.BeforeUpdateStartProcess);
  57. TbBeforeUpdateKillProcess.Text = string.Join(",", vm.BeforeUpdateKillProcess);
  58. TbAfterUpdateStartProcess.Text = string.Join(",", vm.AfterUpdateStartProcess);
  59. TbAfterUpdateKillProcess.Text = string.Join(",", vm.AfterUpdateKillProcess);
  60. if (ListTool.HasElements(vm.FileList))
  61. {
  62. vm.FileList.ForEach(f =>
  63. {
  64. DgFileList.Rows.Add(new object[] {
  65. f.ServerFile,f.LocalFile,f.FileMD5,f.IsClean
  66. });
  67. });
  68. }
  69. TsslRunStatus.Text = "已打开:" + Path.GetFileName(NowOpenFile);
  70. }
  71. else
  72. {
  73. TsslRunStatus.Text = "打开:" + Path.GetFileName(NowOpenFile) + " 失败!";
  74. }
  75. }
  76. }
  77. }
  78. private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
  79. {
  80. Close();
  81. }
  82. private void 生成配置ToolStripMenuItem_Click(object sender, EventArgs e)
  83. {
  84. VersionModel vm = GatherModel();
  85. string vmJson = JsonTool.ToStr(vm);
  86. string vmFile = string.IsNullOrWhiteSpace(NowOpenFile) ?
  87. R.Paths.VersionFile + string.Format("{0}.version", DateTime.Now.ToString("MMddHHmmss")) :
  88. NowOpenFile;
  89. TxtTool.Create(vmFile, vmJson);
  90. TsslRunStatus.Text = "构建成功:" + Path.GetFileName(vmFile);
  91. }
  92. private void 生成配置到指定目录ToolStripMenuItem_Click(object sender, EventArgs e)
  93. {
  94. SaveFileDialog fileDialog = new SaveFileDialog();
  95. fileDialog.InitialDirectory = R.Paths.VersionFile;
  96. fileDialog.Filter = "版本文件|*.version";
  97. if (fileDialog.ShowDialog() == DialogResult.OK)
  98. {
  99. VersionModel vm = GatherModel();
  100. string vmJson = JsonTool.ToStr(vm);
  101. TxtTool.Create(fileDialog.FileName, vmJson);
  102. TsslRunStatus.Text = "构建成功:" + Path.GetFileName(fileDialog.FileName);
  103. }
  104. }
  105. private void 打开默认配置目录ToolStripMenuItem_Click(object sender, EventArgs e)
  106. {
  107. Process.Start("explorer", R.Paths.VersionFile);
  108. TsslRunStatus.Text = "已打开默认输出目录";
  109. }
  110. #endregion
  111. #region 按钮项
  112. private void BtImport_Click(object sender, EventArgs e)
  113. {
  114. FolderBrowserDialog dialog = new FolderBrowserDialog();
  115. dialog.Description = "请选择要导入的文件路径";
  116. if (dialog.ShowDialog() == DialogResult.OK)
  117. {
  118. string foldPath = dialog.SelectedPath;
  119. List<string> fileList = FileTool.GetAllFile(foldPath);
  120. if (ListTool.HasElements(fileList))
  121. {
  122. FileCodeTool fc = new FileCodeTool();
  123. fileList.ForEach(x =>
  124. {
  125. string relativePath = x.Replace(foldPath, "");
  126. DgFileList.Rows.Add(new object[] {
  127. relativePath, relativePath,fc.GetMD5(x), false });
  128. });
  129. }
  130. }
  131. }
  132. private void BtAddFile_Click(object sender, EventArgs e)
  133. {
  134. OpenFileDialog fileDialog = new OpenFileDialog();
  135. if (fileDialog.ShowDialog() == DialogResult.OK)
  136. {
  137. FileCodeTool fc = new FileCodeTool();
  138. DgFileList.Rows.Add(new object[] {
  139. fileDialog.FileName, fileDialog.FileName,
  140. fc.GetMD5(fileDialog.FileName), false });
  141. }
  142. }
  143. private void BtClear_Click(object sender, EventArgs e)
  144. {
  145. DgFileList.Rows.Clear();
  146. }
  147. #endregion
  148. private VersionModel GatherModel()
  149. {
  150. VersionModel rs = new VersionModel()
  151. {
  152. CodeName = TbCodeName.Text.Trim(),
  153. VersionNumber = TbVersionNumber.Text.Trim(),
  154. VersionDesc = TbVersionDesc.Text.Trim(),
  155. ServerPath = TbServerPath.Text.Trim(),
  156. PluginName = TbPluginName.Text.Trim(),
  157. PluginEntry = TbPluginEntry.Text.Trim(),
  158. BeforeUpdateStartProcess = TbBeforeUpdateStartProcess.Text.Trim().Split(','),
  159. BeforeUpdateKillProcess = TbBeforeUpdateKillProcess.Text.Trim().Split(','),
  160. AfterUpdateStartProcess = TbAfterUpdateStartProcess.Text.Trim().Split(','),
  161. AfterUpdateKillProcess = TbAfterUpdateKillProcess.Text.Trim().Split(','),
  162. };
  163. if (DgFileList.Rows.Count > 0)
  164. {
  165. rs.FileList = new List<VersionFile>();
  166. foreach (DataGridViewRow row in DgFileList.Rows)
  167. {
  168. rs.FileList.Add(new VersionFile()
  169. {
  170. ServerFile = row.Cells["ClFileListServer"].Value.ToString(),
  171. LocalFile = row.Cells["ClFileListLocal"].Value.ToString(),
  172. FileMD5 = row.Cells["ClFileListMD5"].Value.ToString(),
  173. IsClean = (bool)row.Cells["ClFileListClean"].Value,
  174. });
  175. }
  176. }
  177. return rs;
  178. }
  179. private void Clear()
  180. {
  181. NowOpenFile = "";
  182. TbCodeName.Text = "";
  183. TbVersionNumber.Text = "";
  184. TbVersionDesc.Text = "";
  185. TbServerPath.Text = "";
  186. TbPluginName.Text = "";
  187. TbPluginEntry.Text = "";
  188. TbBeforeUpdateStartProcess.Text = "";
  189. TbBeforeUpdateKillProcess.Text = "";
  190. TbAfterUpdateStartProcess.Text = "";
  191. TbAfterUpdateKillProcess.Text = "";
  192. DgFileList.Rows.Clear();
  193. }
  194. }
  195. }