Browse Source

更新模块已完成

yuzhengyang 8 years ago
parent
commit
e332755bcf

+ 159 - 21
Fork.Net/Version.Builder/Form1.Designer.cs

@@ -29,70 +29,208 @@
         private void InitializeComponent()
         {
             this.LbResult = new System.Windows.Forms.Label();
-            this.LbTitle = new System.Windows.Forms.Label();
+            this.LbPath = new System.Windows.Forms.Label();
             this.TbPath = new System.Windows.Forms.TextBox();
             this.BtBuild = new System.Windows.Forms.Button();
+            this.groupBox1 = new System.Windows.Forms.GroupBox();
+            this.LbFtpPath = new System.Windows.Forms.Label();
+            this.TbFtpPath = new System.Windows.Forms.TextBox();
+            this.groupBox2 = new System.Windows.Forms.GroupBox();
+            this.LbBeginClose = new System.Windows.Forms.Label();
+            this.LbEndRun = new System.Windows.Forms.Label();
+            this.TbBeginClose = new System.Windows.Forms.TextBox();
+            this.TbEndRun = new System.Windows.Forms.TextBox();
+            this.groupBox3 = new System.Windows.Forms.GroupBox();
+            this.LbVersionNumber = new System.Windows.Forms.Label();
+            this.TbVersionNumber = new System.Windows.Forms.TextBox();
+            this.groupBox1.SuspendLayout();
+            this.groupBox2.SuspendLayout();
+            this.groupBox3.SuspendLayout();
             this.SuspendLayout();
             // 
             // LbResult
             // 
             this.LbResult.BackColor = System.Drawing.Color.White;
             this.LbResult.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
-            this.LbResult.Location = new System.Drawing.Point(23, 132);
+            this.LbResult.Dock = System.Windows.Forms.DockStyle.Bottom;
+            this.LbResult.Location = new System.Drawing.Point(0, 396);
             this.LbResult.Name = "LbResult";
-            this.LbResult.Size = new System.Drawing.Size(453, 23);
+            this.LbResult.Size = new System.Drawing.Size(515, 21);
             this.LbResult.TabIndex = 7;
             this.LbResult.Text = "就绪";
-            this.LbResult.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
+            this.LbResult.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
             // 
-            // LbTitle
+            // LbPath
             // 
-            this.LbTitle.AutoSize = true;
-            this.LbTitle.Location = new System.Drawing.Point(21, 19);
-            this.LbTitle.Name = "LbTitle";
-            this.LbTitle.Size = new System.Drawing.Size(77, 12);
-            this.LbTitle.TabIndex = 6;
-            this.LbTitle.Text = "请输入路径:";
+            this.LbPath.AutoSize = true;
+            this.LbPath.Location = new System.Drawing.Point(20, 33);
+            this.LbPath.Name = "LbPath";
+            this.LbPath.Size = new System.Drawing.Size(65, 12);
+            this.LbPath.TabIndex = 6;
+            this.LbPath.Text = "文件路径:";
             // 
             // TbPath
             // 
-            this.TbPath.Location = new System.Drawing.Point(23, 47);
+            this.TbPath.Location = new System.Drawing.Point(91, 30);
             this.TbPath.Name = "TbPath";
-            this.TbPath.Size = new System.Drawing.Size(453, 21);
+            this.TbPath.Size = new System.Drawing.Size(384, 21);
             this.TbPath.TabIndex = 5;
+            this.TbPath.Text = "D:\\FTP\\Application\\1.0";
             // 
             // BtBuild
             // 
-            this.BtBuild.Location = new System.Drawing.Point(401, 87);
+            this.BtBuild.Location = new System.Drawing.Point(11, 355);
             this.BtBuild.Name = "BtBuild";
-            this.BtBuild.Size = new System.Drawing.Size(75, 23);
+            this.BtBuild.Size = new System.Drawing.Size(490, 23);
             this.BtBuild.TabIndex = 4;
             this.BtBuild.Text = "生成";
             this.BtBuild.UseVisualStyleBackColor = true;
             this.BtBuild.Click += new System.EventHandler(this.BtBuild_Click);
             // 
+            // groupBox1
+            // 
+            this.groupBox1.Controls.Add(this.TbFtpPath);
+            this.groupBox1.Controls.Add(this.LbFtpPath);
+            this.groupBox1.Controls.Add(this.LbPath);
+            this.groupBox1.Controls.Add(this.TbPath);
+            this.groupBox1.Location = new System.Drawing.Point(12, 106);
+            this.groupBox1.Name = "groupBox1";
+            this.groupBox1.Size = new System.Drawing.Size(491, 107);
+            this.groupBox1.TabIndex = 8;
+            this.groupBox1.TabStop = false;
+            this.groupBox1.Text = "文件配置";
+            // 
+            // LbFtpPath
+            // 
+            this.LbFtpPath.AutoSize = true;
+            this.LbFtpPath.Location = new System.Drawing.Point(20, 64);
+            this.LbFtpPath.Name = "LbFtpPath";
+            this.LbFtpPath.Size = new System.Drawing.Size(59, 12);
+            this.LbFtpPath.TabIndex = 7;
+            this.LbFtpPath.Text = "FTP目录:";
+            // 
+            // TbFtpPath
+            // 
+            this.TbFtpPath.Location = new System.Drawing.Point(91, 61);
+            this.TbFtpPath.Name = "TbFtpPath";
+            this.TbFtpPath.Size = new System.Drawing.Size(384, 21);
+            this.TbFtpPath.TabIndex = 8;
+            this.TbFtpPath.Text = "Application\\1.0";
+            // 
+            // groupBox2
+            // 
+            this.groupBox2.Controls.Add(this.TbEndRun);
+            this.groupBox2.Controls.Add(this.TbBeginClose);
+            this.groupBox2.Controls.Add(this.LbEndRun);
+            this.groupBox2.Controls.Add(this.LbBeginClose);
+            this.groupBox2.Location = new System.Drawing.Point(12, 228);
+            this.groupBox2.Name = "groupBox2";
+            this.groupBox2.Size = new System.Drawing.Size(490, 108);
+            this.groupBox2.TabIndex = 9;
+            this.groupBox2.TabStop = false;
+            this.groupBox2.Text = "高级设置";
+            // 
+            // LbBeginClose
+            // 
+            this.LbBeginClose.AutoSize = true;
+            this.LbBeginClose.Location = new System.Drawing.Point(20, 35);
+            this.LbBeginClose.Name = "LbBeginClose";
+            this.LbBeginClose.Size = new System.Drawing.Size(101, 12);
+            this.LbBeginClose.TabIndex = 0;
+            this.LbBeginClose.Text = "更新前关闭进程:";
+            // 
+            // LbEndRun
+            // 
+            this.LbEndRun.AutoSize = true;
+            this.LbEndRun.Location = new System.Drawing.Point(22, 69);
+            this.LbEndRun.Name = "LbEndRun";
+            this.LbEndRun.Size = new System.Drawing.Size(101, 12);
+            this.LbEndRun.TabIndex = 1;
+            this.LbEndRun.Text = "更新后启动程序:";
+            // 
+            // TbBeginClose
+            // 
+            this.TbBeginClose.Location = new System.Drawing.Point(127, 32);
+            this.TbBeginClose.Name = "TbBeginClose";
+            this.TbBeginClose.Size = new System.Drawing.Size(348, 21);
+            this.TbBeginClose.TabIndex = 2;
+            this.TbBeginClose.Text = "UDefrag;logreader;";
+            // 
+            // TbEndRun
+            // 
+            this.TbEndRun.Location = new System.Drawing.Point(127, 66);
+            this.TbEndRun.Name = "TbEndRun";
+            this.TbEndRun.Size = new System.Drawing.Size(348, 21);
+            this.TbEndRun.TabIndex = 3;
+            this.TbEndRun.Text = "笔记本键盘设置.EXE;DoubleForm\\磁盘碎片整理.exe";
+            // 
+            // groupBox3
+            // 
+            this.groupBox3.Controls.Add(this.LbVersionNumber);
+            this.groupBox3.Controls.Add(this.TbVersionNumber);
+            this.groupBox3.Location = new System.Drawing.Point(13, 13);
+            this.groupBox3.Name = "groupBox3";
+            this.groupBox3.Size = new System.Drawing.Size(488, 76);
+            this.groupBox3.TabIndex = 10;
+            this.groupBox3.TabStop = false;
+            this.groupBox3.Text = "基础信息";
+            // 
+            // LbVersionNumber
+            // 
+            this.LbVersionNumber.AutoSize = true;
+            this.LbVersionNumber.Location = new System.Drawing.Point(19, 35);
+            this.LbVersionNumber.Name = "LbVersionNumber";
+            this.LbVersionNumber.Size = new System.Drawing.Size(53, 12);
+            this.LbVersionNumber.TabIndex = 8;
+            this.LbVersionNumber.Text = "版本号:";
+            // 
+            // TbVersionNumber
+            // 
+            this.TbVersionNumber.Location = new System.Drawing.Point(90, 32);
+            this.TbVersionNumber.Name = "TbVersionNumber";
+            this.TbVersionNumber.Size = new System.Drawing.Size(384, 21);
+            this.TbVersionNumber.TabIndex = 7;
+            this.TbVersionNumber.Text = "1.0.0.0";
+            // 
             // Form1
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
-            this.ClientSize = new System.Drawing.Size(515, 185);
+            this.ClientSize = new System.Drawing.Size(515, 417);
+            this.Controls.Add(this.groupBox3);
+            this.Controls.Add(this.groupBox2);
+            this.Controls.Add(this.groupBox1);
             this.Controls.Add(this.LbResult);
-            this.Controls.Add(this.LbTitle);
-            this.Controls.Add(this.TbPath);
             this.Controls.Add(this.BtBuild);
             this.Name = "Form1";
-            this.Text = "Form1";
+            this.Text = "版本文件生成器";
+            this.groupBox1.ResumeLayout(false);
+            this.groupBox1.PerformLayout();
+            this.groupBox2.ResumeLayout(false);
+            this.groupBox2.PerformLayout();
+            this.groupBox3.ResumeLayout(false);
+            this.groupBox3.PerformLayout();
             this.ResumeLayout(false);
-            this.PerformLayout();
 
         }
 
         #endregion
 
         private System.Windows.Forms.Label LbResult;
-        private System.Windows.Forms.Label LbTitle;
+        private System.Windows.Forms.Label LbPath;
         private System.Windows.Forms.TextBox TbPath;
         private System.Windows.Forms.Button BtBuild;
+        private System.Windows.Forms.GroupBox groupBox1;
+        private System.Windows.Forms.TextBox TbFtpPath;
+        private System.Windows.Forms.Label LbFtpPath;
+        private System.Windows.Forms.GroupBox groupBox2;
+        private System.Windows.Forms.Label LbEndRun;
+        private System.Windows.Forms.Label LbBeginClose;
+        private System.Windows.Forms.TextBox TbEndRun;
+        private System.Windows.Forms.TextBox TbBeginClose;
+        private System.Windows.Forms.GroupBox groupBox3;
+        private System.Windows.Forms.Label LbVersionNumber;
+        private System.Windows.Forms.TextBox TbVersionNumber;
     }
 }
 

+ 47 - 22
Fork.Net/Version.Builder/Form1.cs

@@ -25,34 +25,59 @@ namespace Version.Builder
         {
             Task.Factory.StartNew(() =>
             {
-                this.Invoke(new Action(() => { LbResult.Text = "开始检索并生成目录文件,请稍候……"; }));
                 beginTime = DateTime.Now;
-                string path = TbPath.Text;
-                string parentPath = DirTool.Parent(path);
-                FileCodeTool fcode = new FileCodeTool();
-                if (Directory.Exists(path) && Directory.Exists(parentPath))
+                Toast("开始检索并生成目录文件,请稍候……");
+
+                CreateVersionMap();
+
+                Toast(string.Format("生成完成,用时:{0:f2} 毫秒。",
+                    (DateTime.Now - beginTime).TotalMilliseconds));
+            });
+        }
+        private void CreateVersionMap()
+        {
+            string versionNumber = TbVersionNumber.Text;
+            string ftpPath = TbFtpPath.Text;
+            string[] beginClose = TbBeginClose.Text.Split(';');
+            string[] endRun = TbEndRun.Text.Split(';');
+
+            string path = TbPath.Text;
+            string parentPath = DirTool.Parent(path);
+            FileCodeTool fcode = new FileCodeTool();
+            if (Directory.Exists(path) && Directory.Exists(parentPath))
+            {
+                List<string> fileList = FileTool.GetAllFile(path);
+                if (!ListTool.IsNullOrEmpty(fileList))
                 {
-                    List<string> fileList = FileTool.GetAllFile(path);
-                    if (!ListTool.IsNullOrEmpty(fileList))
+                    VersionModel version = new VersionModel()
                     {
-                        VersionModel version = new VersionModel()
-                        { Number = DateTime.Now.Second, Path = path, FileList = new List<VersionFile>(), };
-                        foreach (var item in fileList)
+                        Number = versionNumber,
+                        ServerPath = ftpPath,
+                        BeginCloseProcess = beginClose,
+                        EndRunProcess = endRun,
+                        FileList = new List<VersionFile>()
+                    };
+
+                    foreach (var item in fileList)
+                    {
+                        version.FileList.Add(new VersionFile()
                         {
-                            version.FileList.Add(new VersionFile()
-                            {
-                                File = item.Replace(path, ""),
-                                MD5 = fcode.GetMD5(item),
-                            });
-                        }
-                        string file = string.Format(@"{0}\version.txt", parentPath);
-                        string json = JsonTool.ToStr(version);
-                        TxtTool.Create(file, json);
+                            File = item.Replace(path, ""),
+                            MD5 = fcode.GetMD5(item),
+                        });
                     }
+                    string file = string.Format(@"{0}\update.version", parentPath, versionNumber);
+                    string json = JsonTool.ToStr(version);
+                    TxtTool.Create(file, json);
                 }
-                endTime = DateTime.Now;
-                this.Invoke(new Action(() => { LbResult.Text = string.Format("生成完成,用时:{0:f2} 毫秒。", (endTime - beginTime).TotalMilliseconds); }));
-            });
+            }
+        }
+        public void Toast(string msg)
+        {
+            Invoke(new Action(() =>
+            {
+                LbResult.Text = msg;
+            }));
         }
     }
 }

+ 5 - 3
Fork.Net/Version.Builder/Models/VersionModel.cs

@@ -8,9 +8,11 @@ namespace Version.Builder.Models
 {
     public class VersionModel
     {
-        public int Number { get; set; }
-        public string Path { get; set; }
-        public bool Clean { get; set; }
+        public string Number { get; set; }
+        public string ServerPath { get; set; }
+        public bool DoClean { get; set; }
+        public string[] BeginCloseProcess { get; set; }
+        public string[] EndRunProcess { get; set; }
         public List<VersionFile> FileList { get; set; }
     }
     public class VersionFile

+ 33 - 0
Fork.Net/Version.Update/Commons/R.cs

@@ -0,0 +1,33 @@
+using System;
+using System.Diagnostics;
+using System.IO;
+using System.Reflection;
+
+namespace Version.Update.Commons
+{
+    public static class R
+    {
+        public static bool Release = false;
+        public static string AppName = "Version.Update";
+        public static string AppPath = AppDomain.CurrentDomain.BaseDirectory;
+        public static string AppFile = Process.GetCurrentProcess().MainModule.FileName;
+
+        public static DateTime StartTime = DateTime.Now;
+        public static string MachineName = Environment.MachineName;
+        public static Module Module = Assembly.GetExecutingAssembly().GetModules()[0];
+
+        public static string VersionFile = Path.Combine(AppPath, "update.version");
+        public static string FtpIp = "192.168.3.56";
+        public static string FtpAccount = "Administrator";
+        public static string FtpPassword = "yuzhengyang";
+
+        public static class cst
+        {
+            public const string FILE_SUCC = "√";
+            public const string FILE_FAIL = "×";
+            public const string FILE_JUMP = "-";
+            public const int WAIT_TIME = 50;
+            public const int STEP_WAIT_TIME = 1000;
+        }
+    }
+}

+ 88 - 140
Fork.Net/Version.Update/Form1.Designer.cs

@@ -28,28 +28,22 @@
         /// </summary>
         private void InitializeComponent()
         {
-            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle10 = new System.Windows.Forms.DataGridViewCellStyle();
-            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle17 = new System.Windows.Forms.DataGridViewCellStyle();
-            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle18 = new System.Windows.Forms.DataGridViewCellStyle();
-            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle11 = new System.Windows.Forms.DataGridViewCellStyle();
-            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle12 = new System.Windows.Forms.DataGridViewCellStyle();
-            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle13 = new System.Windows.Forms.DataGridViewCellStyle();
-            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle14 = new System.Windows.Forms.DataGridViewCellStyle();
-            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle15 = new System.Windows.Forms.DataGridViewCellStyle();
-            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle16 = new System.Windows.Forms.DataGridViewCellStyle();
+            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
+            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle6 = new System.Windows.Forms.DataGridViewCellStyle();
+            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle7 = new System.Windows.Forms.DataGridViewCellStyle();
+            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle();
+            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle();
+            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle4 = new System.Windows.Forms.DataGridViewCellStyle();
+            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle5 = new System.Windows.Forms.DataGridViewCellStyle();
             this.DgvFileList = new System.Windows.Forms.DataGridView();
             this.ColNum = new System.Windows.Forms.DataGridViewTextBoxColumn();
             this.ColFile = new System.Windows.Forms.DataGridViewTextBoxColumn();
             this.ColDown = new System.Windows.Forms.DataGridViewTextBoxColumn();
-            this.ColBack = new System.Windows.Forms.DataGridViewTextBoxColumn();
             this.ColUpdate = new System.Windows.Forms.DataGridViewTextBoxColumn();
-            this.ColRoll = new System.Windows.Forms.DataGridViewTextBoxColumn();
-            this.BtRollback = new System.Windows.Forms.Button();
-            this.BtUpdate = new System.Windows.Forms.Button();
-            this.BtBackup = new System.Windows.Forms.Button();
-            this.BtDownload = new System.Windows.Forms.Button();
             this.PbStatus = new System.Windows.Forms.ProgressBar();
-            this.BtClean = new System.Windows.Forms.Button();
+            this.LbStatus = new System.Windows.Forms.Label();
+            this.LbTitle = new System.Windows.Forms.Label();
+            this.LbRetry = new System.Windows.Forms.Label();
             ((System.ComponentModel.ISupportInitialize)(this.DgvFileList)).BeginInit();
             this.SuspendLayout();
             // 
@@ -60,49 +54,47 @@
             this.DgvFileList.AllowUserToResizeColumns = false;
             this.DgvFileList.AllowUserToResizeRows = false;
             this.DgvFileList.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
-            dataGridViewCellStyle10.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
-            dataGridViewCellStyle10.BackColor = System.Drawing.SystemColors.Control;
-            dataGridViewCellStyle10.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            dataGridViewCellStyle10.ForeColor = System.Drawing.SystemColors.WindowText;
-            dataGridViewCellStyle10.SelectionBackColor = System.Drawing.SystemColors.Highlight;
-            dataGridViewCellStyle10.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
-            dataGridViewCellStyle10.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
-            this.DgvFileList.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle10;
+            dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
+            dataGridViewCellStyle1.BackColor = System.Drawing.SystemColors.Control;
+            dataGridViewCellStyle1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            dataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.WindowText;
+            dataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight;
+            dataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
+            dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
+            this.DgvFileList.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle1;
             this.DgvFileList.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
             this.DgvFileList.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
             this.ColNum,
             this.ColFile,
             this.ColDown,
-            this.ColBack,
-            this.ColUpdate,
-            this.ColRoll});
-            dataGridViewCellStyle17.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
-            dataGridViewCellStyle17.BackColor = System.Drawing.SystemColors.Window;
-            dataGridViewCellStyle17.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            dataGridViewCellStyle17.ForeColor = System.Drawing.SystemColors.ControlText;
-            dataGridViewCellStyle17.SelectionBackColor = System.Drawing.SystemColors.Highlight;
-            dataGridViewCellStyle17.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
-            dataGridViewCellStyle17.WrapMode = System.Windows.Forms.DataGridViewTriState.False;
-            this.DgvFileList.DefaultCellStyle = dataGridViewCellStyle17;
-            this.DgvFileList.Location = new System.Drawing.Point(12, 48);
+            this.ColUpdate});
+            dataGridViewCellStyle6.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
+            dataGridViewCellStyle6.BackColor = System.Drawing.SystemColors.Window;
+            dataGridViewCellStyle6.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            dataGridViewCellStyle6.ForeColor = System.Drawing.SystemColors.ControlText;
+            dataGridViewCellStyle6.SelectionBackColor = System.Drawing.SystemColors.Highlight;
+            dataGridViewCellStyle6.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
+            dataGridViewCellStyle6.WrapMode = System.Windows.Forms.DataGridViewTriState.False;
+            this.DgvFileList.DefaultCellStyle = dataGridViewCellStyle6;
+            this.DgvFileList.Location = new System.Drawing.Point(11, 124);
             this.DgvFileList.Name = "DgvFileList";
             this.DgvFileList.ReadOnly = true;
-            dataGridViewCellStyle18.BackColor = System.Drawing.SystemColors.Control;
-            dataGridViewCellStyle18.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            dataGridViewCellStyle18.ForeColor = System.Drawing.SystemColors.WindowText;
-            dataGridViewCellStyle18.SelectionBackColor = System.Drawing.SystemColors.Highlight;
-            dataGridViewCellStyle18.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
-            dataGridViewCellStyle18.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
-            this.DgvFileList.RowHeadersDefaultCellStyle = dataGridViewCellStyle18;
+            dataGridViewCellStyle7.BackColor = System.Drawing.SystemColors.Control;
+            dataGridViewCellStyle7.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            dataGridViewCellStyle7.ForeColor = System.Drawing.SystemColors.WindowText;
+            dataGridViewCellStyle7.SelectionBackColor = System.Drawing.SystemColors.Highlight;
+            dataGridViewCellStyle7.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
+            dataGridViewCellStyle7.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
+            this.DgvFileList.RowHeadersDefaultCellStyle = dataGridViewCellStyle7;
             this.DgvFileList.RowHeadersVisible = false;
             this.DgvFileList.RowTemplate.Height = 23;
-            this.DgvFileList.Size = new System.Drawing.Size(699, 424);
+            this.DgvFileList.Size = new System.Drawing.Size(379, 252);
             this.DgvFileList.TabIndex = 10;
             // 
             // ColNum
             // 
-            dataGridViewCellStyle11.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
-            this.ColNum.DefaultCellStyle = dataGridViewCellStyle11;
+            dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
+            this.ColNum.DefaultCellStyle = dataGridViewCellStyle2;
             this.ColNum.FillWeight = 10F;
             this.ColNum.HeaderText = "序号";
             this.ColNum.Name = "ColNum";
@@ -112,8 +104,8 @@
             // 
             // ColFile
             // 
-            dataGridViewCellStyle12.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
-            this.ColFile.DefaultCellStyle = dataGridViewCellStyle12;
+            dataGridViewCellStyle3.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
+            this.ColFile.DefaultCellStyle = dataGridViewCellStyle3;
             this.ColFile.FillWeight = 40F;
             this.ColFile.HeaderText = "文件";
             this.ColFile.Name = "ColFile";
@@ -123,8 +115,8 @@
             // 
             // ColDown
             // 
-            dataGridViewCellStyle13.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
-            this.ColDown.DefaultCellStyle = dataGridViewCellStyle13;
+            dataGridViewCellStyle4.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
+            this.ColDown.DefaultCellStyle = dataGridViewCellStyle4;
             this.ColDown.FillWeight = 10F;
             this.ColDown.HeaderText = "下载";
             this.ColDown.Name = "ColDown";
@@ -132,21 +124,10 @@
             this.ColDown.Resizable = System.Windows.Forms.DataGridViewTriState.False;
             this.ColDown.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
             // 
-            // ColBack
-            // 
-            dataGridViewCellStyle14.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
-            this.ColBack.DefaultCellStyle = dataGridViewCellStyle14;
-            this.ColBack.FillWeight = 10F;
-            this.ColBack.HeaderText = "备份";
-            this.ColBack.Name = "ColBack";
-            this.ColBack.ReadOnly = true;
-            this.ColBack.Resizable = System.Windows.Forms.DataGridViewTriState.False;
-            this.ColBack.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
-            // 
             // ColUpdate
             // 
-            dataGridViewCellStyle15.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
-            this.ColUpdate.DefaultCellStyle = dataGridViewCellStyle15;
+            dataGridViewCellStyle5.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
+            this.ColUpdate.DefaultCellStyle = dataGridViewCellStyle5;
             this.ColUpdate.FillWeight = 10F;
             this.ColUpdate.HeaderText = "更新";
             this.ColUpdate.Name = "ColUpdate";
@@ -154,110 +135,77 @@
             this.ColUpdate.Resizable = System.Windows.Forms.DataGridViewTriState.False;
             this.ColUpdate.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
             // 
-            // ColRoll
-            // 
-            dataGridViewCellStyle16.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
-            this.ColRoll.DefaultCellStyle = dataGridViewCellStyle16;
-            this.ColRoll.FillWeight = 10F;
-            this.ColRoll.HeaderText = "还原";
-            this.ColRoll.Name = "ColRoll";
-            this.ColRoll.ReadOnly = true;
-            this.ColRoll.Resizable = System.Windows.Forms.DataGridViewTriState.False;
-            this.ColRoll.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
-            // 
-            // BtRollback
-            // 
-            this.BtRollback.Location = new System.Drawing.Point(634, 15);
-            this.BtRollback.Name = "BtRollback";
-            this.BtRollback.Size = new System.Drawing.Size(75, 23);
-            this.BtRollback.TabIndex = 14;
-            this.BtRollback.Text = "还原";
-            this.BtRollback.UseVisualStyleBackColor = true;
-            this.BtRollback.Click += new System.EventHandler(this.BtRollback_Click);
-            // 
-            // BtUpdate
-            // 
-            this.BtUpdate.Location = new System.Drawing.Point(556, 15);
-            this.BtUpdate.Name = "BtUpdate";
-            this.BtUpdate.Size = new System.Drawing.Size(75, 23);
-            this.BtUpdate.TabIndex = 13;
-            this.BtUpdate.Text = "更新";
-            this.BtUpdate.UseVisualStyleBackColor = true;
-            this.BtUpdate.Click += new System.EventHandler(this.BtUpdate_Click);
-            // 
-            // BtBackup
-            // 
-            this.BtBackup.Location = new System.Drawing.Point(478, 15);
-            this.BtBackup.Name = "BtBackup";
-            this.BtBackup.Size = new System.Drawing.Size(75, 23);
-            this.BtBackup.TabIndex = 12;
-            this.BtBackup.Text = "备份";
-            this.BtBackup.UseVisualStyleBackColor = true;
-            this.BtBackup.Click += new System.EventHandler(this.BtBackup_Click);
-            // 
-            // BtDownload
-            // 
-            this.BtDownload.Location = new System.Drawing.Point(401, 15);
-            this.BtDownload.Name = "BtDownload";
-            this.BtDownload.Size = new System.Drawing.Size(75, 23);
-            this.BtDownload.TabIndex = 11;
-            this.BtDownload.Text = "下载";
-            this.BtDownload.UseVisualStyleBackColor = true;
-            this.BtDownload.Click += new System.EventHandler(this.BtDownload_Click);
-            // 
             // PbStatus
             // 
-            this.PbStatus.Location = new System.Drawing.Point(-6, 484);
+            this.PbStatus.Location = new System.Drawing.Point(12, 40);
             this.PbStatus.Name = "PbStatus";
-            this.PbStatus.Size = new System.Drawing.Size(738, 23);
+            this.PbStatus.Size = new System.Drawing.Size(379, 16);
             this.PbStatus.TabIndex = 15;
             // 
-            // BtClean
-            // 
-            this.BtClean.Location = new System.Drawing.Point(264, 15);
-            this.BtClean.Name = "BtClean";
-            this.BtClean.Size = new System.Drawing.Size(75, 23);
-            this.BtClean.TabIndex = 16;
-            this.BtClean.Text = "清理";
-            this.BtClean.UseVisualStyleBackColor = true;
-            this.BtClean.Click += new System.EventHandler(this.BtClean_Click);
+            // LbStatus
+            // 
+            this.LbStatus.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
+            this.LbStatus.Location = new System.Drawing.Point(12, 73);
+            this.LbStatus.Name = "LbStatus";
+            this.LbStatus.Size = new System.Drawing.Size(378, 23);
+            this.LbStatus.TabIndex = 16;
+            this.LbStatus.Text = "更新状态";
+            this.LbStatus.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
+            this.LbStatus.DoubleClick += new System.EventHandler(this.LbStatus_DoubleClick);
+            // 
+            // LbTitle
+            // 
+            this.LbTitle.AutoSize = true;
+            this.LbTitle.Location = new System.Drawing.Point(12, 13);
+            this.LbTitle.Name = "LbTitle";
+            this.LbTitle.Size = new System.Drawing.Size(71, 12);
+            this.LbTitle.TabIndex = 17;
+            this.LbTitle.Text = "正在更新...";
+            // 
+            // LbRetry
+            // 
+            this.LbRetry.AutoSize = true;
+            this.LbRetry.ForeColor = System.Drawing.SystemColors.Highlight;
+            this.LbRetry.Location = new System.Drawing.Point(349, 13);
+            this.LbRetry.Name = "LbRetry";
+            this.LbRetry.Size = new System.Drawing.Size(29, 12);
+            this.LbRetry.TabIndex = 18;
+            this.LbRetry.Text = "重试";
+            this.LbRetry.Click += new System.EventHandler(this.LbRetry_Click);
             // 
             // Form1
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
-            this.ClientSize = new System.Drawing.Size(727, 489);
-            this.Controls.Add(this.BtClean);
+            this.ClientSize = new System.Drawing.Size(403, 381);
+            this.Controls.Add(this.LbRetry);
+            this.Controls.Add(this.LbTitle);
+            this.Controls.Add(this.LbStatus);
             this.Controls.Add(this.PbStatus);
             this.Controls.Add(this.DgvFileList);
-            this.Controls.Add(this.BtRollback);
-            this.Controls.Add(this.BtUpdate);
-            this.Controls.Add(this.BtBackup);
-            this.Controls.Add(this.BtDownload);
             this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
+            this.MaximizeBox = false;
+            this.MinimizeBox = false;
             this.Name = "Form1";
-            this.Text = "Form1";
+            this.Text = "更新程序";
             this.Load += new System.EventHandler(this.Form1_Load);
             ((System.ComponentModel.ISupportInitialize)(this.DgvFileList)).EndInit();
             this.ResumeLayout(false);
+            this.PerformLayout();
 
         }
 
         #endregion
 
         private System.Windows.Forms.DataGridView DgvFileList;
+        private System.Windows.Forms.ProgressBar PbStatus;
         private System.Windows.Forms.DataGridViewTextBoxColumn ColNum;
         private System.Windows.Forms.DataGridViewTextBoxColumn ColFile;
         private System.Windows.Forms.DataGridViewTextBoxColumn ColDown;
-        private System.Windows.Forms.DataGridViewTextBoxColumn ColBack;
         private System.Windows.Forms.DataGridViewTextBoxColumn ColUpdate;
-        private System.Windows.Forms.DataGridViewTextBoxColumn ColRoll;
-        private System.Windows.Forms.Button BtRollback;
-        private System.Windows.Forms.Button BtUpdate;
-        private System.Windows.Forms.Button BtBackup;
-        private System.Windows.Forms.Button BtDownload;
-        private System.Windows.Forms.ProgressBar PbStatus;
-        private System.Windows.Forms.Button BtClean;
+        private System.Windows.Forms.Label LbStatus;
+        private System.Windows.Forms.Label LbTitle;
+        private System.Windows.Forms.Label LbRetry;
     }
 }
 

+ 238 - 167
Fork.Net/Version.Update/Form1.cs

@@ -5,66 +5,125 @@ using System.Linq;
 using System.Threading;
 using System.Threading.Tasks;
 using System.Windows.Forms;
+using Version.Update.Commons;
 using Version.Update.Models;
 using Y.Utils.DataUtils.Collections;
 using Y.Utils.DataUtils.JsonUtils;
 using Y.Utils.IOUtils.FileUtils;
 using Y.Utils.IOUtils.PathUtils;
 using Y.Utils.NetUtils.FTPUtils;
+using Y.Utils.WindowsUtils.ProcessUtils;
 
 namespace Version.Update
 {
     public partial class Form1 : Form
     {
-        const string FILE_SUCC = "√";
-        const string FILE_FAIL = "×";
-        const string FILE_JUMP = "-";
-        const int WAIT_TIME = 50;
-        string AppDir = AppDomain.CurrentDomain.BaseDirectory;
-        string folder = Guid.NewGuid().ToString();
         string downloadPath = "";
-        string backupPath = "";
         VersionModel version;
-
-        string VersionFile = @"D:\FTP\Application\version1.0.txt";
-        string FtpIp = "192.168.3.56";
-        string FtpAccount = "Administrator";
-        string FtpPassword = "yuzhengyang";
+        int Step = 1, Error = 1;
+        int SmallHeight = 146;
+        int LargeHeight = 420;
         public Form1()
         {
             InitializeComponent();
+            Height = SmallHeight;
+            LbRetry.Visible = false;
         }
 
         private void Form1_Load(object sender, EventArgs e)
         {
-            downloadPath = AppDir + @"VersionUpdate\Download\" + folder;
-            backupPath = AppDir + @"VersionUpdate\Backup\" + folder;
+            UpdateTask();
+        }
+
+        #region 更新功能
+        /// <summary>
+        /// 完整的更新任务
+        /// </summary>
+        void UpdateTask()
+        {
+            LbRetry.Visible = false;
+            Step = 1;
+            Error = 1;
+
+            string folder = Guid.NewGuid().ToString();
+            downloadPath = R.AppPath + @"Temp\Update\" + folder;
 
             Task.Factory.StartNew(() =>
             {
-                //获取配置文件 -> 下载文件
+                UILbStatus("[准备] 正在读取版本文件...");
                 if (GetVersion())
                 {
-                    //DownloadFile(downloadPath);
-                    //BackupFile(backupPath);
-                    //UpdateFile(downloadPath);
-                    //RollBackFile(backupPath);
+                    UILbStatus("[准备] 正在读取版本文件...[完成]");
+                    Thread.Sleep(R.cst.STEP_WAIT_TIME);
 
-                    //Directory.Delete(downloadPath, true);
-                    //Directory.Delete(backupPath, true);
-                }
+                    if (Step == 1)
+                    {
+                        UILbStatus("[1/5] 正在退出相关程序...");
+                        BeginCloseProcess();
+                        Thread.Sleep(R.cst.STEP_WAIT_TIME);
+                        UILbStatus("[1/5] 正在退出相关程序...[完成]");
+                        Thread.Sleep(R.cst.STEP_WAIT_TIME);
+                    }
+                    if (Step == 2)
+                    {
+                        UILbStatus("[2/5] 正在下载新版本的文件...");
+                        DownloadFile(downloadPath);
+                        Thread.Sleep(R.cst.STEP_WAIT_TIME);
+                        UILbStatus("[2/5] 正在下载新版本的文件...[完成]");
+                        Thread.Sleep(R.cst.STEP_WAIT_TIME);
+                    }
+                    if (Step == 3)
+                    {
+                        UILbStatus("[3/5] 正在更新文件...");
+                        UpdateFile(downloadPath);
+                        Thread.Sleep(R.cst.STEP_WAIT_TIME);
+                        UILbStatus("[3/5] 正在更新文件...[完成]");
+                        Thread.Sleep(R.cst.STEP_WAIT_TIME);
+                    }
+                    if (Step == 4)
+                    {
+                        UILbStatus("[4/5] 正在清理冗余文件...");
+                        CleanFile();
+                        Thread.Sleep(R.cst.STEP_WAIT_TIME);
+                        UILbStatus("[4/5] 正在清理冗余文件...[完成]");
+                        Thread.Sleep(R.cst.STEP_WAIT_TIME);
+                    }
+                    if (Step == 5)
+                    {
+                        UILbStatus("[5/5] 准备启动程序...");
+                        EndRunProcess();
+                        UILbStatus("[5/5] 准备启动程序...[完成]");
+                        Thread.Sleep(R.cst.STEP_WAIT_TIME);
+                    }
 
+                    if (Error > 0)
+                    {
+                        UILbStatus("[更新成功 即将退出]");
+                        Thread.Sleep(R.cst.STEP_WAIT_TIME);
+                        UIClose();
+                    }
+                    else
+                    {
+                        UILbStatus("[更新异常 请检查并解决故障后 重新更新]");
+                        UIShowRetry();
+                    }
+                }
+                else
+                {
+                    UILbStatus("[结束] 未发现新版本...");
+                    MessageBox.Show("您已经是最新版本了。", "完成");
+                    UIClose();
+                }
             });
         }
 
-        #region 更新功能
         /// <summary>
         /// 获取版本配置文件
         /// </summary>
         /// <returns></returns>
         bool GetVersion()
         {
-            version = JsonTool.ToObjFromFile<VersionModel>(VersionFile);
+            version = JsonTool.ToObjFromFile<VersionModel>(R.VersionFile);
             if (version != null)
             {
                 try
@@ -72,8 +131,8 @@ namespace Version.Update
                     int num = 1;
                     foreach (var item in version.FileList)
                     {
-                        this.BeginInvoke(new Action(() => { UIDgvFileListAdd(new object[] { num++, Path.GetFileName(item.File) }); }));
-                        Thread.Sleep(WAIT_TIME);
+                        UIDgvFileListAdd(new object[] { num++, Path.GetFileName(item.File) });
+                        Thread.Sleep(R.cst.WAIT_TIME);
                     }
                     return true;
                 }
@@ -93,83 +152,40 @@ namespace Version.Update
                 for (int i = 0; i < version.FileList.Count; i++)
                 {
                     string fileName = Path.GetFileName(version.FileList[i].File);
-                    string sourceFile = version.Path + version.FileList[i].File;
+                    string sourceFile = version.ServerPath + version.FileList[i].File;
                     string destFile = downloadPath + version.FileList[i].File;
                     string destPath = destFile.Substring(0, destFile.Length - fileName.Length);
                     if (DirTool.Create(destPath))
                     {
-                        try
+                        if (File.Exists(R.AppPath + version.FileList[i].File) &&
+                            version.FileList[i].MD5 == fcode.GetMD5(R.AppPath + version.FileList[i].File))
                         {
-                            if (File.Exists(AppDir + version.FileList[i].File) &&
-                                version.FileList[i].MD5 == fcode.GetMD5(AppDir + version.FileList[i].File))
-                            {
-                                this.BeginInvoke(new Action(() => { UIDgvFileListUpdate(i, "ColDown", FILE_JUMP); }));
-                            }
-                            else
-                            {
-                                //File.Copy(sourceFile, destFile);
-                                FtpHelper ftp = new FtpHelper(FtpIp, FtpAccount, FtpPassword);
-                                ftp.DownloadFile(sourceFile, destPath);
-                                this.BeginInvoke(new Action(() => { UIDgvFileListUpdate(i, "ColDown", FILE_SUCC); }));
-                            }
+                            UIDgvFileListUpdate(i, "ColDown", R.cst.FILE_JUMP);
                         }
-                        catch (Exception e)
-                        {
-                            this.BeginInvoke(new Action(() => { UIDgvFileListUpdate(i, "ColDown", FILE_FAIL); }));
-                        }
-                    }
-                    else
-                    {
-                        this.BeginInvoke(new Action(() => { UIDgvFileListUpdate(i, "ColDown", FILE_FAIL); }));
-                    }
-                    Thread.Sleep(WAIT_TIME);
-                }
-            }
-            return false;
-        }
-        /// <summary>
-        /// 备份程序文件
-        /// </summary>
-        /// <returns></returns>
-        bool BackupFile(string backupPath, string downloadPath)
-        {
-            if (DirTool.Create(backupPath))
-            {
-                FileCodeTool fcode = new FileCodeTool();
-                for (int i = 0; i < version.FileList.Count; i++)
-                {
-                    string fileName = Path.GetFileName(version.FileList[i].File);
-                    string sourceFile = AppDir + version.FileList[i].File;
-                    string destFile = backupPath + version.FileList[i].File;
-                    string destPath = destFile.Substring(0, destFile.Length - fileName.Length);
-                    string downloadFile = downloadPath + version.FileList[i].File;
-                    if (DirTool.Create(destPath))
-                    {
-                        try
-                        {
-                            if (File.Exists(sourceFile) && File.Exists(downloadFile) && version.FileList[i].MD5 != fcode.GetMD5(AppDir + version.FileList[i].File))
-                            {
-                                File.Copy(sourceFile, destFile);
-                                this.BeginInvoke(new Action(() => { UIDgvFileListUpdate(i, "ColBack", FILE_SUCC); }));
-                            }
-                            else
-                            {
-                                this.BeginInvoke(new Action(() => { UIDgvFileListUpdate(i, "ColBack", FILE_JUMP); }));
-                            }
-                        }
-                        catch (Exception e)
+                        else
                         {
-                            this.BeginInvoke(new Action(() => { UIDgvFileListUpdate(i, "ColBack", FILE_FAIL); }));
+                            FtpHelper ftp = new FtpHelper(R.FtpIp, R.FtpAccount, R.FtpPassword);
+                            if (!ftp.DownloadFile(sourceFile, destPath))
+                                if (!ftp.DownloadFile(sourceFile, destPath))
+                                    if (!ftp.DownloadFile(sourceFile, destPath))
+                                    {
+                                        MessageBox.Show("更新文件无法被下载,请检查网络重试,谢谢。", "网络故障");
+                                        Step = 5;
+                                        Error = -201;
+                                        return false;
+                                    }
+                            UIDgvFileListUpdate(i, "ColDown", R.cst.FILE_SUCC);
                         }
                     }
                     else
                     {
-                        this.BeginInvoke(new Action(() => { UIDgvFileListUpdate(i, "ColBack", FILE_FAIL); }));
+                        UIDgvFileListUpdate(i, "ColDown", R.cst.FILE_FAIL);
                     }
-                    Thread.Sleep(WAIT_TIME);
+                    Thread.Sleep(R.cst.WAIT_TIME);
                 }
             }
-            return false;
+            Step = 3;
+            return true;
         }
         /// <summary>
         /// 更新程序文件
@@ -181,7 +197,7 @@ namespace Version.Update
             {
                 string fileName = Path.GetFileName(version.FileList[i].File);
                 string sourceFile = downloadPath + version.FileList[i].File;
-                string destFile = AppDir + version.FileList[i].File;
+                string destFile = R.AppPath + version.FileList[i].File;
                 string destPath = destFile.Substring(0, destFile.Length - fileName.Length);
                 if (DirTool.Create(destPath))
                 {
@@ -190,106 +206,119 @@ namespace Version.Update
                         if (File.Exists(sourceFile))
                         {
                             File.Copy(sourceFile, destFile, true);
-                            this.BeginInvoke(new Action(() => { UIDgvFileListUpdate(i, "ColUpdate", FILE_SUCC); }));
+                            UIDgvFileListUpdate(i, "ColUpdate", R.cst.FILE_SUCC);
                         }
                         else
                         {
-                            this.BeginInvoke(new Action(() => { UIDgvFileListUpdate(i, "ColUpdate", FILE_JUMP); }));
+                            UIDgvFileListUpdate(i, "ColUpdate", R.cst.FILE_JUMP);
                         }
                     }
                     catch (Exception e)
                     {
-                        this.BeginInvoke(new Action(() => { UIDgvFileListUpdate(i, "ColUpdate", FILE_FAIL); }));
+                        UIDgvFileListUpdate(i, "ColUpdate", R.cst.FILE_FAIL);
                     }
                 }
                 else
                 {
-                    this.BeginInvoke(new Action(() => { UIDgvFileListUpdate(i, "ColBack", FILE_FAIL); }));
+                    UIDgvFileListUpdate(i, "ColBack", R.cst.FILE_FAIL);
                 }
-                Thread.Sleep(WAIT_TIME);
+                Thread.Sleep(R.cst.WAIT_TIME);
             }
+            Step = 4;
             return false;
         }
         /// <summary>
-        /// 还原程序文件
+        /// 清理之前版本遗留文件及空文件夹
         /// </summary>
         /// <returns></returns>
-        bool RollBackFile(string backupPath)
+        void CleanFile()
         {
-            for (int i = 0; i < version.FileList.Count; i++)
+            UIPbStatus(0);
+            #region 删除下载的更新文件和版本文件
+            try
             {
-                string fileName = Path.GetFileName(version.FileList[i].File);
-                string sourceFile = backupPath + version.FileList[i].File;
-                string destFile = AppDir + version.FileList[i].File;
-                string destPath = destFile.Substring(0, destFile.Length - fileName.Length);
-                if (DirTool.Create(destPath))
+                Directory.Delete(R.AppPath + @"Temp\Update\", true);
+                File.Delete(R.VersionFile);
+            }
+            catch { }
+            #endregion
+            UIPbStatus(50);
+            if (version.DoClean)
+            {
+                #region 删除非当前版本文件
+                List<string> file = FileTool.GetAllFile(R.AppPath);
+                if (!ListTool.IsNullOrEmpty(file))
                 {
-                    try
+                    foreach (var f in file)
                     {
-                        if (File.Exists(sourceFile))
+                        int c = version.FileList.Where(x => x.File == "\\" + f.Replace(R.AppPath, "")).Count();
+                        if (c == 0)
                         {
-                            File.Copy(sourceFile, destFile, true);
-                            this.BeginInvoke(new Action(() => { UIDgvFileListUpdate(i, "ColRoll", FILE_SUCC); }));
-                        }
-                        else
-                        {
-                            this.BeginInvoke(new Action(() => { UIDgvFileListUpdate(i, "ColRoll", FILE_JUMP); }));
+                            try { File.Delete(f); } catch { }
                         }
                     }
-                    catch (Exception e)
-                    {
-                        this.BeginInvoke(new Action(() => { UIDgvFileListUpdate(i, "ColRoll", FILE_FAIL); }));
-                    }
+                    Thread.Sleep(R.cst.WAIT_TIME);
                 }
-                else
+                #endregion
+                #region 删除空文件夹
+                List<string> path = DirTool.GetAllPath(R.AppPath);
+                if (!ListTool.IsNullOrEmpty(path))
                 {
-                    this.BeginInvoke(new Action(() => { UIDgvFileListUpdate(i, "ColRoll", FILE_FAIL); }));
+                    path = path.OrderByDescending(x => x).ToList();
+                    foreach (var p in path)
+                    {
+                        if (Directory.GetFiles(p).Length == 0 && Directory.GetDirectories(p).Length == 0)
+                        {
+                            if (Directory.Exists(p))
+                            {
+                                try { Directory.Delete(p); } catch { }
+                            }
+                        }
+                        Thread.Sleep(R.cst.WAIT_TIME);
+                    }
                 }
-                Thread.Sleep(WAIT_TIME);
+                #endregion
             }
-            return false;
+            UIPbStatus(100);
+            Step = 5;
         }
         /// <summary>
-        /// 清理之前版本遗留文件及空文件夹
+        /// 更新开始结束程序
         /// </summary>
-        /// <returns></returns>
-        void CleanFile()
+        void BeginCloseProcess()
         {
-            #region 删除非当前版本文件
-            List<string> file = FileTool.GetAllFile(AppDir);
-            if (!ListTool.IsNullOrEmpty(file))
+            int percent = 1;
+            if (!ListTool.IsNullOrEmpty(version.BeginCloseProcess))
             {
-                foreach (var f in file)
+                foreach (var p in version.BeginCloseProcess)
                 {
-                    int c = version.FileList.Where(x => x.File == "\\" + f.Replace(AppDir, "")).Count();
-                    if (c == 0)
-                    {
-                        File.Delete(f);
-                    }
+                    Thread.Sleep(R.cst.WAIT_TIME);
+                    UIPbStatus((int)((double)(percent++) / version.BeginCloseProcess.Count() * 100));
+                    if (!string.IsNullOrWhiteSpace(p))
+                        ProcessTool.KillProcess(p);
                 }
-                Thread.Sleep(WAIT_TIME);
             }
-            #endregion
-            #region 删除空文件夹
-            List<string> path = DirTool.GetAllPath(AppDir);
-            if (!ListTool.IsNullOrEmpty(path))
+            Step = 2;
+        }
+        /// <summary>
+        /// 更新结束启动程序
+        /// </summary>
+        void EndRunProcess()
+        {
+            int percent = 1;
+            if (!ListTool.IsNullOrEmpty(version.EndRunProcess))
             {
-                path = path.OrderByDescending(x => x).ToList();
-                foreach (var p in path)
+                foreach (var p in version.EndRunProcess)
                 {
-                    if (Directory.GetFiles(p).Length == 0 && Directory.GetDirectories(p).Length == 0)
-                    {
-                        if (Directory.Exists(p))
-                        {
-                            Directory.Delete(p);
-                        }
-                    }
-                    Thread.Sleep(WAIT_TIME);
+                    Thread.Sleep(R.cst.WAIT_TIME);
+                    UIPbStatus((int)((double)(percent++) / version.EndRunProcess.Count() * 100));
+                    if (!string.IsNullOrWhiteSpace(p))
+                        ProcessTool.StartProcess(Path.Combine(R.AppPath, p));
                 }
             }
-            #endregion
         }
         #endregion
+
         #region UI刷新
         /// <summary>
         /// 在DgvFileList中添加一条新纪录
@@ -297,41 +326,83 @@ namespace Version.Update
         /// <param name="values"></param>
         void UIDgvFileListAdd(params object[] values)
         {
-            if (values != null)
+            this.BeginInvoke(new Action(() =>
             {
-                DgvFileList.Rows.Add(values);
-            }
+                if (values != null)
+                {
+                    DgvFileList.Rows.Add(values);
+                    DgvFileList.FirstDisplayedScrollingRowIndex = DgvFileList.RowCount - 1;
+                    UIPbStatus((int)((double)(int)(values[0]) / version.FileList.Count * 100));
+                }
+            }));
         }
+        /// <summary>
+        /// 更新DgvFileList控件中的记录
+        /// </summary>
+        /// <param name="row"></param>
+        /// <param name="cell"></param>
+        /// <param name="value"></param>
         void UIDgvFileListUpdate(int row, string cell, string value)
         {
-            DgvFileList.Rows[row].Cells[cell].Value = value;
-            PbStatus.Value = (int)((double)(row + 1) / version.FileList.Count * 100);
+            this.BeginInvoke(new Action(() =>
+            {
+                DgvFileList.Rows[row].Cells[cell].Value = value;
+                if (version.FileList.Count > 5)
+                    DgvFileList.FirstDisplayedScrollingRowIndex = (row - 5) > 0 ? (row - 5) : 0;
+                UIPbStatus((int)((double)(row + 1) / version.FileList.Count * 100));
+            }));
         }
-        #endregion
-
-        private void BtDownload_Click(object sender, EventArgs e)
+        /// <summary>
+        /// 设置ProgressBar的进度百分比
+        /// </summary>
+        /// <param name="percent"></param>
+        void UIPbStatus(int percent)
         {
-            Task.Factory.StartNew(() => { DownloadFile(downloadPath); });
+            Invoke(new Action(() =>
+            {
+                PbStatus.Value = percent;
+            }));
         }
-
-        private void BtBackup_Click(object sender, EventArgs e)
+        /// <summary>
+        /// 更新LbStatus状态信息文本
+        /// </summary>
+        /// <param name="msg"></param>
+        void UILbStatus(string msg)
         {
-            Task.Factory.StartNew(() => { BackupFile(backupPath, downloadPath); });
+            Invoke(new Action(() =>
+            {
+                LbStatus.Text = msg;
+            }));
         }
-
-        private void BtUpdate_Click(object sender, EventArgs e)
+        void UIClose()
         {
-            Task.Factory.StartNew(() => { UpdateFile(downloadPath); });
+            Invoke(new Action(() =>
+            {
+                Close();
+            }));
         }
-
-        private void BtRollback_Click(object sender, EventArgs e)
+        void UIShowRetry()
         {
-            Task.Factory.StartNew(() => { RollBackFile(backupPath); });
+            Invoke(new Action(() => { LbRetry.Visible = true; }));
         }
+        #endregion
 
-        private void BtClean_Click(object sender, EventArgs e)
+        #region 控件事件
+        private void LbStatus_DoubleClick(object sender, EventArgs e)
         {
-            Task.Factory.StartNew(() => { CleanFile(); });
+            if (Height < (SmallHeight + ((LargeHeight - SmallHeight) / 2)))
+            {
+                Height = LargeHeight;
+            }
+            else
+            {
+                Height = SmallHeight;
+            }
         }
+        private void LbRetry_Click(object sender, EventArgs e)
+        {
+            UpdateTask();
+        } 
+        #endregion
     }
 }

+ 0 - 6
Fork.Net/Version.Update/Form1.resx

@@ -126,13 +126,7 @@
   <metadata name="ColDown.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
     <value>True</value>
   </metadata>
-  <metadata name="ColBack.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
-    <value>True</value>
-  </metadata>
   <metadata name="ColUpdate.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
     <value>True</value>
   </metadata>
-  <metadata name="ColRoll.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
-    <value>True</value>
-  </metadata>
 </root>

+ 5 - 3
Fork.Net/Version.Update/Models/VersionModel.cs

@@ -8,9 +8,11 @@ namespace Version.Update.Models
 {
     public class VersionModel
     {
-        public int Number { get; set; }
-        public string Path { get; set; }
-        public bool Clean { get; set; }
+        public string Number { get; set; }
+        public string ServerPath { get; set; }
+        public bool DoClean { get; set; }
+        public string[] BeginCloseProcess { get; set; }
+        public string[] EndRunProcess { get; set; }
         public List<VersionFile> FileList { get; set; }
     }
     public class VersionFile

+ 2 - 1
Fork.Net/Version.Update/Program.cs

@@ -3,6 +3,7 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Threading.Tasks;
 using System.Windows.Forms;
+using Version.Update.Commons;
 
 namespace Version.Update
 {
@@ -12,7 +13,7 @@ namespace Version.Update
         /// 应用程序的主入口点。
         /// </summary>
         [STAThread]
-        static void Main()
+        static void Main(string[] args)
         {
             Application.EnableVisualStyles();
             Application.SetCompatibleTextRenderingDefault(false);

+ 2 - 0
Fork.Net/Version.Update/Version.Update.csproj

@@ -48,6 +48,7 @@
     <Reference Include="System.Xml" />
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="Commons\R.cs" />
     <Compile Include="Form1.cs">
       <SubType>Form</SubType>
     </Compile>
@@ -92,6 +93,7 @@
   <ItemGroup>
     <None Include="FodyWeavers.xml" />
   </ItemGroup>
+  <ItemGroup />
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <Import Project="..\packages\Fody.2.0.6\build\dotnet\Fody.targets" Condition="Exists('..\packages\Fody.2.0.6\build\dotnet\Fody.targets')" />
   <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">

+ 1 - 1
Fork.Net/Y.Test/Program.cs

@@ -17,7 +17,7 @@ namespace Y.Test
         {
             Application.EnableVisualStyles();
             Application.SetCompatibleTextRenderingDefault(false);
-            Application.Run(new TestWebForm());
+            Application.Run(new TestInputForm());
         }
     }
 }

+ 60 - 0
Fork.Net/Y.Test/Views/TestInputForm.Designer.cs

@@ -0,0 +1,60 @@
+namespace Y.Test.Views
+{
+    partial class TestInputForm
+    {
+        /// <summary>
+        /// Required designer variable.
+        /// </summary>
+        private System.ComponentModel.IContainer components = null;
+
+        /// <summary>
+        /// Clean up any resources being used.
+        /// </summary>
+        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
+        protected override void Dispose(bool disposing)
+        {
+            if (disposing && (components != null))
+            {
+                components.Dispose();
+            }
+            base.Dispose(disposing);
+        }
+
+        #region Windows Form Designer generated code
+
+        /// <summary>
+        /// Required method for Designer support - do not modify
+        /// the contents of this method with the code editor.
+        /// </summary>
+        private void InitializeComponent()
+        {
+            this.textBox1 = new System.Windows.Forms.TextBox();
+            this.SuspendLayout();
+            // 
+            // textBox1
+            // 
+            this.textBox1.Location = new System.Drawing.Point(13, 13);
+            this.textBox1.Multiline = true;
+            this.textBox1.Name = "textBox1";
+            this.textBox1.Size = new System.Drawing.Size(524, 352);
+            this.textBox1.TabIndex = 0;
+            // 
+            // TestInputForm
+            // 
+            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
+            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+            this.ClientSize = new System.Drawing.Size(549, 377);
+            this.Controls.Add(this.textBox1);
+            this.Name = "TestInputForm";
+            this.Text = "TestInputForm";
+            this.Load += new System.EventHandler(this.TestInputForm_Load);
+            this.ResumeLayout(false);
+            this.PerformLayout();
+
+        }
+
+        #endregion
+
+        private System.Windows.Forms.TextBox textBox1;
+    }
+}

+ 45 - 0
Fork.Net/Y.Test/Views/TestInputForm.cs

@@ -0,0 +1,45 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Reflection;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+using Y.Utils.WindowsUtils.HookUtils;
+
+namespace Y.Test.Views
+{
+    public partial class TestInputForm : Form
+    {
+        private static UserActivityHook Hook;
+        public TestInputForm()
+        {
+            InitializeComponent();
+        }
+
+        private void TestInputForm_Load(object sender, EventArgs e)
+        {
+            Hook = new UserActivityHook(Assembly.GetExecutingAssembly().GetModules()[0]);
+            Hook.OnMouseActivity += new MouseEventHandler(mouseHandler);
+            Hook.KeyDown += new KeyEventHandler(keyHandler);
+            Hook.Start();
+        }
+        private void mouseHandler(object sender, MouseEventArgs e)
+        {
+            Invoke(new Action(() =>
+            {
+                //textBox1.AppendText("[click1]");
+            }));
+        }
+        private void keyHandler(object sender, KeyEventArgs e)
+        {
+            Invoke(new Action(() =>
+            {
+                textBox1.AppendText("[press" + e.KeyCode + "]");
+            }));
+        }
+    }
+}

+ 120 - 0
Fork.Net/Y.Test/Views/TestInputForm.resx

@@ -0,0 +1,120 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+  <!-- 
+    Microsoft ResX Schema 
+    
+    Version 2.0
+    
+    The primary goals of this format is to allow a simple XML format 
+    that is mostly human readable. The generation and parsing of the 
+    various data types are done through the TypeConverter classes 
+    associated with the data types.
+    
+    Example:
+    
+    ... ado.net/XML headers & schema ...
+    <resheader name="resmimetype">text/microsoft-resx</resheader>
+    <resheader name="version">2.0</resheader>
+    <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+    <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+    <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+    <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+    <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+        <value>[base64 mime encoded serialized .NET Framework object]</value>
+    </data>
+    <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+        <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+        <comment>This is a comment</comment>
+    </data>
+                
+    There are any number of "resheader" rows that contain simple 
+    name/value pairs.
+    
+    Each data row contains a name, and value. The row also contains a 
+    type or mimetype. Type corresponds to a .NET class that support 
+    text/value conversion through the TypeConverter architecture. 
+    Classes that don't support this are serialized and stored with the 
+    mimetype set.
+    
+    The mimetype is used for serialized objects, and tells the 
+    ResXResourceReader how to depersist the object. This is currently not 
+    extensible. For a given mimetype the value must be set accordingly:
+    
+    Note - application/x-microsoft.net.object.binary.base64 is the format 
+    that the ResXResourceWriter will generate, however the reader can 
+    read any of the formats listed below.
+    
+    mimetype: application/x-microsoft.net.object.binary.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
+            : and then encoded with base64 encoding.
+    
+    mimetype: application/x-microsoft.net.object.soap.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+            : and then encoded with base64 encoding.
+
+    mimetype: application/x-microsoft.net.object.bytearray.base64
+    value   : The object must be serialized into a byte array 
+            : using a System.ComponentModel.TypeConverter
+            : and then encoded with base64 encoding.
+    -->
+  <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+    <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
+    <xsd:element name="root" msdata:IsDataSet="true">
+      <xsd:complexType>
+        <xsd:choice maxOccurs="unbounded">
+          <xsd:element name="metadata">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" />
+              </xsd:sequence>
+              <xsd:attribute name="name" use="required" type="xsd:string" />
+              <xsd:attribute name="type" type="xsd:string" />
+              <xsd:attribute name="mimetype" type="xsd:string" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="assembly">
+            <xsd:complexType>
+              <xsd:attribute name="alias" type="xsd:string" />
+              <xsd:attribute name="name" type="xsd:string" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="data">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+                <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
+              <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+              <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="resheader">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" />
+            </xsd:complexType>
+          </xsd:element>
+        </xsd:choice>
+      </xsd:complexType>
+    </xsd:element>
+  </xsd:schema>
+  <resheader name="resmimetype">
+    <value>text/microsoft-resx</value>
+  </resheader>
+  <resheader name="version">
+    <value>2.0</value>
+  </resheader>
+  <resheader name="reader">
+    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <resheader name="writer">
+    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+</root>

+ 9 - 0
Fork.Net/Y.Test/Y.Test.csproj

@@ -60,6 +60,12 @@
     <Compile Include="Views\MainForm.Designer.cs">
       <DependentUpon>MainForm.cs</DependentUpon>
     </Compile>
+    <Compile Include="Views\TestInputForm.cs">
+      <SubType>Form</SubType>
+    </Compile>
+    <Compile Include="Views\TestInputForm.Designer.cs">
+      <DependentUpon>TestInputForm.cs</DependentUpon>
+    </Compile>
     <Compile Include="Views\TestWebForm.cs">
       <SubType>Form</SubType>
     </Compile>
@@ -81,6 +87,9 @@
     <EmbeddedResource Include="Views\MainForm.resx">
       <DependentUpon>MainForm.cs</DependentUpon>
     </EmbeddedResource>
+    <EmbeddedResource Include="Views\TestInputForm.resx">
+      <DependentUpon>TestInputForm.cs</DependentUpon>
+    </EmbeddedResource>
     <EmbeddedResource Include="Views\TestWebForm.resx">
       <DependentUpon>TestWebForm.cs</DependentUpon>
     </EmbeddedResource>

+ 21 - 16
Fork.Net/Y.Utils/NetUtils/FTPUtils/FTPTool.cs

@@ -35,29 +35,34 @@ namespace Y.Utils.NetUtils.FTPUtils
         }
         public bool DownloadFile(string ftpFilePath, string saveDir)
         {
-            string filename = ftpFilePath.Substring(ftpFilePath.LastIndexOf("\\") + 1);
-            string tmpname = Guid.NewGuid().ToString();
-            string uri = Path.Combine(ftpURI, ftpFilePath);
-            if (!Directory.Exists(saveDir)) Directory.CreateDirectory(saveDir);
-            FtpWebRequest ftp = GetRequest(uri);
-            ftp.Method = WebRequestMethods.Ftp.DownloadFile;
-            using (FtpWebResponse response = (FtpWebResponse)ftp.GetResponse())
+            try
             {
-                using (Stream responseStream = response.GetResponseStream())
+                string filename = ftpFilePath.Substring(ftpFilePath.LastIndexOf("\\") + 1);
+                string tmpname = Guid.NewGuid().ToString();
+                string uri = Path.Combine(ftpURI, ftpFilePath);
+                if (!Directory.Exists(saveDir)) Directory.CreateDirectory(saveDir);
+                FtpWebRequest ftp = GetRequest(uri);
+                ftp.Method = WebRequestMethods.Ftp.DownloadFile;
+                using (FtpWebResponse response = (FtpWebResponse)ftp.GetResponse())
                 {
-                    using (FileStream fs = new FileStream(Path.Combine(saveDir, filename), FileMode.CreateNew))
+                    using (Stream responseStream = response.GetResponseStream())
                     {
-                        byte[] buffer = new byte[2048];
-                        int read = 0;
-                        do
+                        using (FileStream fs = new FileStream(Path.Combine(saveDir, filename), FileMode.CreateNew))
                         {
-                            read = responseStream.Read(buffer, 0, buffer.Length);
-                            fs.Write(buffer, 0, read);
-                        } while (!(read == 0));
-                        fs.Flush();
+                            byte[] buffer = new byte[2048];
+                            int read = 0;
+                            do
+                            {
+                                read = responseStream.Read(buffer, 0, buffer.Length);
+                                fs.Write(buffer, 0, read);
+                            } while (!(read == 0));
+                            fs.Flush();
+                        }
                     }
                 }
+                return true;
             }
+            catch { }
             return false;
         }
     }

+ 1 - 9
Fork.Net/Y.Utils/WindowsUtils/HookUtils/UserActivityHook.cs

@@ -1,14 +1,6 @@
-//############################################################
-//      https://github.com/yuzhengyang
-//      author:yuzhengyang
-//############################################################
-using System;
-using System.Collections.Generic;
-using System.Linq;
+using System;
 using System.Reflection;
 using System.Runtime.InteropServices;
-using System.Text;
-using System.Threading.Tasks;
 using System.Windows.Forms;
 
 namespace Y.Utils.WindowsUtils.HookUtils

+ 65 - 0
Fork.Net/Y.Utils/WindowsUtils/ProcessUtils/ProcessTool.cs

@@ -0,0 +1,65 @@
+//############################################################
+//      https://github.com/yuzhengyang
+//      author:yuzhengyang
+//############################################################
+using System;
+using System.Diagnostics;
+using System.IO;
+using System.Windows.Forms;
+
+namespace Y.Utils.WindowsUtils.ProcessUtils
+{
+    public static class ProcessTool
+    {
+        public static void StartProcess(string appFile)
+        {
+            try
+            {
+                if (File.Exists(appFile))
+                {
+                    Process p = new Process();
+                    p.StartInfo.FileName = appFile;
+                    //p.StartInfo.Arguments = "";
+                    p.StartInfo.UseShellExecute = true;
+                    p.Start();
+                    p.WaitForInputIdle(3000);
+                }
+            }
+            catch (Exception ex) { }
+        }
+        public static bool CheckProcessExists(string name)
+        {
+            Process[] processes = Process.GetProcessesByName(name);
+            foreach (Process p in processes)
+            {
+                return true;
+            }
+            return false;
+        }
+        public static void KillProcess(string name)
+        {
+            try
+            {
+                Process[] processes = Process.GetProcessesByName(name);
+                foreach (Process p in processes)
+                {
+                    p.Kill();
+                    p.Close();
+                }
+            }
+            catch (Exception e) { }
+        }
+        public static void KillCurrentProcess()
+        {
+            Process current = Process.GetCurrentProcess();
+            Process[] processes = Process.GetProcessesByName(current.ProcessName);
+            foreach (Process process in processes)
+            {
+                if (process.Id == current.Id)
+                {
+                    process.Kill();
+                }
+            }
+        }
+    }
+}

+ 1 - 0
Fork.Net/Y.Utils/Y.Utils.csproj

@@ -111,6 +111,7 @@
     <Compile Include="WindowsUtils\InfoUtils\ScreenCapture.cs" />
     <Compile Include="WindowsUtils\InfoUtils\ShortcutTool.cs" />
     <Compile Include="WindowsUtils\InfoUtils\TaskSchedulerTool.cs" />
+    <Compile Include="WindowsUtils\ProcessUtils\ProcessTool.cs" />
   </ItemGroup>
   <ItemGroup>
     <None Include="packages.config" />