| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228 |
- using System;
- using System.ComponentModel;
- using System.Drawing;
- using System.IO;
- using System.Windows.Forms;
- using System.Xml;
- using Newtonsoft.Json.Linq;
- namespace prBrowserUpdateList
- {
- public class Form1 : Form
- {
- public static string path = AppDomain.CurrentDomain.BaseDirectory;
- public static JArray fileStringArray = new JArray();
- private IContainer components = null;
- private Button btnCreateList;
- public Form1()
- {
- InitializeComponent();
- }
- private void btnCreateList_Click(object sender, EventArgs e)
- {
- if (string.IsNullOrEmpty(path))
- {
- MessageBox.Show("路径不存在!");
- }
- else
- {
- DirectoryInfo dir = new DirectoryInfo(path);
- if (!dir.Exists)
- {
- MessageBox.Show("路径不存在!");
- }
- else
- {
- GetChildDicsNameApp(dir);
- string pathService = path + "\\service";
- dir = new DirectoryInfo(pathService);
- if (!dir.Exists)
- {
- MessageBox.Show("路径不存在!");
- }
- else
- {
- GetChildDicsNameService(dir);
- }
- }
- }
- if (fileStringArray.Count > 0)
- {
- SetUpdateList();
- }
- }
- public static DirectoryInfo[] GetChildDicsName(DirectoryInfo dir)
- {
- FileInfo[] fileArray = dir.GetFiles();
- DirectoryInfo[] childDirs = dir.GetDirectories();
- FileInfo[] array = fileArray;
- foreach (FileInfo file in array)
- {
- string absolutePath = dir.FullName;
- string relativePath = absolutePath.Replace(path, "");
- if (relativePath != "")
- {
- relativePath += "\\";
- }
- string fileName = file.Name;
- 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"))
- {
- JObject inputObj = new JObject();
- inputObj.Add("key", (JToken)fileName);
- inputObj.Add("value", (JToken)relativePath);
- fileStringArray.Add(inputObj);
- }
- }
- if (childDirs.Length != 0)
- {
- DirectoryInfo[] array2 = childDirs;
- foreach (DirectoryInfo dirChild in array2)
- {
- if (!(dirChild.Name == "Cache") && !(dirChild.Name == "x64") && !(dirChild.Name == "x86") && !(dirChild.Name == "log"))
- {
- GetChildDicsName(dirChild);
- }
- }
- }
- return childDirs;
- }
- public void SetUpdateList()
- {
- try
- {
- XmlDocument xmlDoc = new XmlDocument();
- XmlElement xml = xmlDoc.CreateElement("", "file", "");
- xmlDoc.AppendChild(xml);
- XmlNode file = xmlDoc.SelectSingleNode("file");
- XmlElement list = xmlDoc.CreateElement("list");
- foreach (JObject fileObj in fileStringArray)
- {
- XmlElement add = xmlDoc.CreateElement("add");
- add.SetAttribute("key", fileObj["key"]!.ToString());
- add.SetAttribute("value", fileObj["value"]!.ToString());
- list.AppendChild(add);
- }
- file.AppendChild(list);
- string nowDate = DateTime.Now.ToString("yyyy-MM-dd");
- string nowTime = DateTime.Now.ToString("HH:mm:ss");
- if (!Directory.Exists(path + "UpdateList"))
- {
- Directory.CreateDirectory(path + "UpdateList");
- }
- string outputPath = path + "UpdateList\\UpdateList" + nowDate.Replace("-", "") + nowTime.Replace(":", "") + ".xml";
- xmlDoc.Save(outputPath);
- MessageBox.Show("生成更新列表成功");
- Application.Exit();
- }
- catch (Exception ex)
- {
- MessageBox.Show("生成失败:" + ex.Message);
- }
- }
- private void button1_Click(object sender, EventArgs e)
- {
- }
- public static DirectoryInfo[] GetChildDicsNameApp(DirectoryInfo dir)
- {
- FileInfo[] fileArray = dir.GetFiles();
- DirectoryInfo[] childDirs = dir.GetDirectories();
- FileInfo[] array = fileArray;
- foreach (FileInfo file in array)
- {
- string absolutePath = dir.FullName;
- string relativePath = absolutePath.Replace(path, "");
- if (relativePath != "")
- {
- relativePath += "\\";
- }
- string fileName = file.Name;
- if (fileName.IndexOf("prBrowser") >= 0 && !(fileName == "prBrowserUpdate.exe"))
- {
- JObject inputObj = new JObject();
- inputObj.Add("key", (JToken)fileName);
- inputObj.Add("value", (JToken)relativePath);
- fileStringArray.Add(inputObj);
- }
- }
- return childDirs;
- }
- public static DirectoryInfo[] GetChildDicsNameService(DirectoryInfo dir)
- {
- FileInfo[] fileArray = dir.GetFiles();
- DirectoryInfo[] childDirs = dir.GetDirectories();
- FileInfo[] array = fileArray;
- foreach (FileInfo file in array)
- {
- string absolutePath = dir.FullName;
- string relativePath = absolutePath.Replace(path, "");
- if (relativePath != "")
- {
- relativePath += "\\";
- }
- string fileName = file.Name;
- JObject inputObj = new JObject();
- inputObj.Add("key", (JToken)fileName);
- inputObj.Add("value", (JToken)relativePath);
- fileStringArray.Add(inputObj);
- }
- if (childDirs.Length != 0)
- {
- DirectoryInfo[] array2 = childDirs;
- foreach (DirectoryInfo dirChild in array2)
- {
- GetChildDicsNameService(dirChild);
- }
- }
- return childDirs;
- }
- protected override void Dispose(bool disposing)
- {
- if (disposing && components != null)
- {
- components.Dispose();
- }
- base.Dispose(disposing);
- }
- private void InitializeComponent()
- {
- System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
- this.btnCreateList = new System.Windows.Forms.Button();
- this.SuspendLayout();
- //
- // btnCreateList
- //
- this.btnCreateList.Location = new System.Drawing.Point(157, 62);
- this.btnCreateList.Name = "btnCreateList";
- this.btnCreateList.Size = new System.Drawing.Size(142, 23);
- this.btnCreateList.TabIndex = 0;
- this.btnCreateList.Text = "生成浏览器更新列表";
- this.btnCreateList.UseVisualStyleBackColor = true;
- this.btnCreateList.Click += new System.EventHandler(this.btnCreateList_Click);
- //
- // Form1
- //
- this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(449, 212);
- this.Controls.Add(this.btnCreateList);
- this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
- this.Name = "Form1";
- this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
- this.Text = "Form1";
- this.ResumeLayout(false);
- }
- }
- }
|