Form1.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. using System;
  2. using System.ComponentModel;
  3. using System.Drawing;
  4. using System.IO;
  5. using System.Windows.Forms;
  6. using System.Xml;
  7. using Newtonsoft.Json.Linq;
  8. namespace prBrowserUpdateList
  9. {
  10. public class Form1 : Form
  11. {
  12. public static string path = AppDomain.CurrentDomain.BaseDirectory;
  13. public static JArray fileStringArray = new JArray();
  14. private IContainer components = null;
  15. private Button btnCreateList;
  16. public Form1()
  17. {
  18. InitializeComponent();
  19. }
  20. private void btnCreateList_Click(object sender, EventArgs e)
  21. {
  22. if (string.IsNullOrEmpty(path))
  23. {
  24. MessageBox.Show("路径不存在!");
  25. }
  26. else
  27. {
  28. DirectoryInfo dir = new DirectoryInfo(path);
  29. if (!dir.Exists)
  30. {
  31. MessageBox.Show("路径不存在!");
  32. }
  33. else
  34. {
  35. GetChildDicsNameApp(dir);
  36. string pathService = path + "\\service";
  37. dir = new DirectoryInfo(pathService);
  38. if (!dir.Exists)
  39. {
  40. MessageBox.Show("路径不存在!");
  41. }
  42. else
  43. {
  44. GetChildDicsNameService(dir);
  45. }
  46. }
  47. }
  48. if (fileStringArray.Count > 0)
  49. {
  50. SetUpdateList();
  51. }
  52. }
  53. public static DirectoryInfo[] GetChildDicsName(DirectoryInfo dir)
  54. {
  55. FileInfo[] fileArray = dir.GetFiles();
  56. DirectoryInfo[] childDirs = dir.GetDirectories();
  57. FileInfo[] array = fileArray;
  58. foreach (FileInfo file in array)
  59. {
  60. string absolutePath = dir.FullName;
  61. string relativePath = absolutePath.Replace(path, "");
  62. if (relativePath != "")
  63. {
  64. relativePath += "\\";
  65. }
  66. string fileName = file.Name;
  67. if (!(fileName == "debug.log") && !(fileName == "prBrowser.exe.config") && !(fileName == "prBrowserUpdate.exe.config") && !(fileName == "prBrowserUpdateList.exe") && !(fileName == "prBrowserUpdateList.exe.config") && !(fileName == "prBrowserUpdateList.pdb") && !(fileName == "web.config"))
  68. {
  69. JObject inputObj = new JObject();
  70. inputObj.Add("key", (JToken)fileName);
  71. inputObj.Add("value", (JToken)relativePath);
  72. fileStringArray.Add(inputObj);
  73. }
  74. }
  75. if (childDirs.Length != 0)
  76. {
  77. DirectoryInfo[] array2 = childDirs;
  78. foreach (DirectoryInfo dirChild in array2)
  79. {
  80. if (!(dirChild.Name == "Cache") && !(dirChild.Name == "x64") && !(dirChild.Name == "x86") && !(dirChild.Name == "log"))
  81. {
  82. GetChildDicsName(dirChild);
  83. }
  84. }
  85. }
  86. return childDirs;
  87. }
  88. public void SetUpdateList()
  89. {
  90. try
  91. {
  92. XmlDocument xmlDoc = new XmlDocument();
  93. XmlElement xml = xmlDoc.CreateElement("", "file", "");
  94. xmlDoc.AppendChild(xml);
  95. XmlNode file = xmlDoc.SelectSingleNode("file");
  96. XmlElement list = xmlDoc.CreateElement("list");
  97. foreach (JObject fileObj in fileStringArray)
  98. {
  99. XmlElement add = xmlDoc.CreateElement("add");
  100. add.SetAttribute("key", fileObj["key"]!.ToString());
  101. add.SetAttribute("value", fileObj["value"]!.ToString());
  102. list.AppendChild(add);
  103. }
  104. file.AppendChild(list);
  105. string nowDate = DateTime.Now.ToString("yyyy-MM-dd");
  106. string nowTime = DateTime.Now.ToString("HH:mm:ss");
  107. if (!Directory.Exists(path + "UpdateList"))
  108. {
  109. Directory.CreateDirectory(path + "UpdateList");
  110. }
  111. string outputPath = path + "UpdateList\\UpdateList" + nowDate.Replace("-", "") + nowTime.Replace(":", "") + ".xml";
  112. xmlDoc.Save(outputPath);
  113. MessageBox.Show("生成更新列表成功");
  114. Application.Exit();
  115. }
  116. catch (Exception ex)
  117. {
  118. MessageBox.Show("生成失败:" + ex.Message);
  119. }
  120. }
  121. private void button1_Click(object sender, EventArgs e)
  122. {
  123. }
  124. public static DirectoryInfo[] GetChildDicsNameApp(DirectoryInfo dir)
  125. {
  126. FileInfo[] fileArray = dir.GetFiles();
  127. DirectoryInfo[] childDirs = dir.GetDirectories();
  128. FileInfo[] array = fileArray;
  129. foreach (FileInfo file in array)
  130. {
  131. string absolutePath = dir.FullName;
  132. string relativePath = absolutePath.Replace(path, "");
  133. if (relativePath != "")
  134. {
  135. relativePath += "\\";
  136. }
  137. string fileName = file.Name;
  138. if (fileName.IndexOf("prBrowser") >= 0 && !(fileName == "prBrowserUpdate.exe"))
  139. {
  140. JObject inputObj = new JObject();
  141. inputObj.Add("key", (JToken)fileName);
  142. inputObj.Add("value", (JToken)relativePath);
  143. fileStringArray.Add(inputObj);
  144. }
  145. }
  146. return childDirs;
  147. }
  148. public static DirectoryInfo[] GetChildDicsNameService(DirectoryInfo dir)
  149. {
  150. FileInfo[] fileArray = dir.GetFiles();
  151. DirectoryInfo[] childDirs = dir.GetDirectories();
  152. FileInfo[] array = fileArray;
  153. foreach (FileInfo file in array)
  154. {
  155. string absolutePath = dir.FullName;
  156. string relativePath = absolutePath.Replace(path, "");
  157. if (relativePath != "")
  158. {
  159. relativePath += "\\";
  160. }
  161. string fileName = file.Name;
  162. JObject inputObj = new JObject();
  163. inputObj.Add("key", (JToken)fileName);
  164. inputObj.Add("value", (JToken)relativePath);
  165. fileStringArray.Add(inputObj);
  166. }
  167. if (childDirs.Length != 0)
  168. {
  169. DirectoryInfo[] array2 = childDirs;
  170. foreach (DirectoryInfo dirChild in array2)
  171. {
  172. GetChildDicsNameService(dirChild);
  173. }
  174. }
  175. return childDirs;
  176. }
  177. protected override void Dispose(bool disposing)
  178. {
  179. if (disposing && components != null)
  180. {
  181. components.Dispose();
  182. }
  183. base.Dispose(disposing);
  184. }
  185. private void InitializeComponent()
  186. {
  187. System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
  188. this.btnCreateList = new System.Windows.Forms.Button();
  189. this.SuspendLayout();
  190. //
  191. // btnCreateList
  192. //
  193. this.btnCreateList.Location = new System.Drawing.Point(157, 62);
  194. this.btnCreateList.Name = "btnCreateList";
  195. this.btnCreateList.Size = new System.Drawing.Size(142, 23);
  196. this.btnCreateList.TabIndex = 0;
  197. this.btnCreateList.Text = "生成浏览器更新列表";
  198. this.btnCreateList.UseVisualStyleBackColor = true;
  199. this.btnCreateList.Click += new System.EventHandler(this.btnCreateList_Click);
  200. //
  201. // Form1
  202. //
  203. this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
  204. this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  205. this.ClientSize = new System.Drawing.Size(449, 212);
  206. this.Controls.Add(this.btnCreateList);
  207. this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
  208. this.Name = "Form1";
  209. this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
  210. this.Text = "Form1";
  211. this.ResumeLayout(false);
  212. }
  213. }
  214. }