Browse Source

文件加密和文件打包添加进度回调方法(可监测运行的进度)

yuzhengyang 8 years ago
parent
commit
1fb8e4c5be

+ 11 - 1
Fork.Net/Oreo.Plugins/Oreo.FileMan/Views/MainForm.Designer.cs

@@ -34,6 +34,7 @@
             this.button4 = new System.Windows.Forms.Button();
             this.button4 = new System.Windows.Forms.Button();
             this.BtFileDecrypt = new System.Windows.Forms.Button();
             this.BtFileDecrypt = new System.Windows.Forms.Button();
             this.button1 = new System.Windows.Forms.Button();
             this.button1 = new System.Windows.Forms.Button();
+            this.progressBar1 = new System.Windows.Forms.ProgressBar();
             this.SuspendLayout();
             this.SuspendLayout();
             // 
             // 
             // BtFileEncrypt
             // BtFileEncrypt
@@ -94,11 +95,19 @@
             this.button1.UseVisualStyleBackColor = true;
             this.button1.UseVisualStyleBackColor = true;
             this.button1.Click += new System.EventHandler(this.button1_Click);
             this.button1.Click += new System.EventHandler(this.button1_Click);
             // 
             // 
+            // progressBar1
+            // 
+            this.progressBar1.Location = new System.Drawing.Point(12, 284);
+            this.progressBar1.Name = "progressBar1";
+            this.progressBar1.Size = new System.Drawing.Size(281, 23);
+            this.progressBar1.TabIndex = 6;
+            // 
             // MainForm
             // MainForm
             // 
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
-            this.ClientSize = new System.Drawing.Size(284, 261);
+            this.ClientSize = new System.Drawing.Size(305, 319);
+            this.Controls.Add(this.progressBar1);
             this.Controls.Add(this.button1);
             this.Controls.Add(this.button1);
             this.Controls.Add(this.BtFileDecrypt);
             this.Controls.Add(this.BtFileDecrypt);
             this.Controls.Add(this.button4);
             this.Controls.Add(this.button4);
@@ -120,5 +129,6 @@
         private System.Windows.Forms.Button button4;
         private System.Windows.Forms.Button button4;
         private System.Windows.Forms.Button BtFileDecrypt;
         private System.Windows.Forms.Button BtFileDecrypt;
         private System.Windows.Forms.Button button1;
         private System.Windows.Forms.Button button1;
+        private System.Windows.Forms.ProgressBar progressBar1;
     }
     }
 }
 }

+ 62 - 22
Fork.Net/Oreo.Plugins/Oreo.FileMan/Views/MainForm.cs

@@ -10,6 +10,7 @@ using System.Linq;
 using System.Text;
 using System.Text;
 using System.Threading.Tasks;
 using System.Threading.Tasks;
 using System.Windows.Forms;
 using System.Windows.Forms;
+using System.Xml.Linq;
 using Y.Utils.DataUtils.EncryptUtils;
 using Y.Utils.DataUtils.EncryptUtils;
 using Y.Utils.IOUtils.FileUtils;
 using Y.Utils.IOUtils.FileUtils;
 using Y.Utils.IOUtils.PathUtils;
 using Y.Utils.IOUtils.PathUtils;
@@ -39,11 +40,14 @@ namespace Oreo.FileMan.Views
 
 
                     if (!File.Exists(newfile))
                     if (!File.Exists(newfile))
                     {
                     {
-                        int spendtime = 0;
-                        if ((spendtime = FileEncryptTool.Encrypt(file, newfile, pwd)) > 0)
+                        Task.Factory.StartNew(() =>
                         {
                         {
-                            MessageBox.Show("恭喜你,加密成功。共耗时:" + spendtime, "加密成功");
-                        }
+                            int spendtime = 0;
+                            if ((spendtime = FileEncryptTool.Encrypt(file, newfile, pwd, UIProgress)) > 0)
+                            {
+                                MessageBox.Show("恭喜你,加密成功。共耗时:" + spendtime, "加密成功");
+                            }
+                        });
                     }
                     }
                     else
                     else
                     {
                     {
@@ -68,11 +72,14 @@ namespace Oreo.FileMan.Views
                     string newfile = file.Substring(0, file.Length - ".fmk".Length);
                     string newfile = file.Substring(0, file.Length - ".fmk".Length);
                     if (!File.Exists(newfile))
                     if (!File.Exists(newfile))
                     {
                     {
-                        int spendtime = 0;
-                        if ((spendtime = FileEncryptTool.Decrypt(file, newfile, pwd)) > 0)
+                        Task.Factory.StartNew(() =>
                         {
                         {
-                            MessageBox.Show("恭喜你,解密成功。共耗时:" + spendtime, "解密成功");
-                        }
+                            int spendtime = 0;
+                            if ((spendtime = FileEncryptTool.Decrypt(file, newfile, pwd, UIProgress)) > 0)
+                            {
+                                MessageBox.Show("恭喜你,解密成功。共耗时:" + spendtime, "解密成功");
+                            }
+                        });
                     }
                     }
                     else
                     else
                     {
                     {
@@ -84,50 +91,71 @@ namespace Oreo.FileMan.Views
 
 
         private void MainForm_Load(object sender, EventArgs e)
         private void MainForm_Load(object sender, EventArgs e)
         {
         {
-            bool flag = CanUpdate();
+
         }
         }
 
 
         private void button2_Click(object sender, EventArgs e)
         private void button2_Click(object sender, EventArgs e)
         {
         {
-            int flag = FilePackageTool.Pack(@"D:\temp\测试打包\新建文件夹", @"D:\temp\测试打包\新建文件夹.pkg");
-            if (flag > 0)
-                MessageBox.Show("打包成功");
+            Task.Factory.StartNew(() =>
+            {
+                int flag = FilePackageTool.Pack(@"D:\Temp\测试压缩\Root", @"D:\Temp\测试压缩\Root.pkg", UIProgress);
+                if (flag > 0)
+                    MessageBox.Show("打包成功");
+            });
         }
         }
 
 
         private void button1_Click(object sender, EventArgs e)
         private void button1_Click(object sender, EventArgs e)
         {
         {
-            int flag = FilePackageTool.Unpack(@"D:\temp\测试打包\新建文件夹.pkg", @"D:\temp\测试打包\新建文件夹");
-            if (flag > 0)
-                MessageBox.Show("拆包成功");
+            Task.Factory.StartNew(() =>
+            {
+                int flag = FilePackageTool.Unpack(@"D:\Temp\测试压缩\Root.pkg", @"D:\Temp\测试压缩\Root", UIProgress);
+                if (flag > 0)
+                    MessageBox.Show("拆包成功");
+            });
+        }
+        private void UIProgress(long current, long total)
+        {
+            BeginInvoke(new Action(() =>
+            {
+                progressBar1.Maximum = 100;
+                progressBar1.Value = (int)(current * 100 / total);
+            }));
         }
         }
 
 
         private bool CanUpdate()
         private bool CanUpdate()
         {
         {
+            string file = AppDomain.CurrentDomain.BaseDirectory + "Settings";
             string key = "TodayUpdateTimes";
             string key = "TodayUpdateTimes";
             DateTime today = DateTime.Parse(string.Format("{0}-{1}-{2} 00:00:00", DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day));
             DateTime today = DateTime.Parse(string.Format("{0}-{1}-{2} 00:00:00", DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day));
             DateTime setday = today;
             DateTime setday = today;
 
 
             //读取配置
             //读取配置
-            string temp = ConfigurationManager.AppSettings[key];
+            string temp = CanUpdateGetConfig(file, key);
             if (DateTime.TryParse(temp, out setday) && setday >= today && setday <= today.AddDays(1))
             if (DateTime.TryParse(temp, out setday) && setday >= today && setday <= today.AddDays(1))
             {
             {
                 if (setday.Hour < 3)
                 if (setday.Hour < 3)
-                    CanUpdateSetConfig(key, setday.AddHours(1).ToString());//累加hour记录次数
+                    CanUpdateSetConfig(file, key, setday.AddHours(1).ToString());//累加hour记录次数
                 else
                 else
                     return false;
                     return false;
             }
             }
             else
             else
             {
             {
                 //配置失效,设置为默认值
                 //配置失效,设置为默认值
-                CanUpdateSetConfig(key, today.ToString());
+                CanUpdateSetConfig(file, key, today.ToString());
             }
             }
             return true;
             return true;
         }
         }
-        private bool CanUpdateSetConfig(string key, string value)
+        private bool CanUpdateSetConfig(string file, string key, string value)
         {
         {
             try
             try
             {
             {
-                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
+                //文件不存在则创建
+                if (!File.Exists(file + ".config"))
+                {
+                    XElement xe = new XElement("configuration");
+                    xe.Save(file + ".config");
+                }
+                Configuration config = ConfigurationManager.OpenExeConfiguration(file);
                 if (config.AppSettings.Settings.AllKeys.Contains(key))
                 if (config.AppSettings.Settings.AllKeys.Contains(key))
                 {
                 {
                     config.AppSettings.Settings[key].Value = value;
                     config.AppSettings.Settings[key].Value = value;
@@ -137,13 +165,25 @@ namespace Oreo.FileMan.Views
                     config.AppSettings.Settings.Add(key, value);
                     config.AppSettings.Settings.Add(key, value);
                 }
                 }
                 config.Save(ConfigurationSaveMode.Modified);
                 config.Save(ConfigurationSaveMode.Modified);
-                ConfigurationManager.RefreshSection("appSettings");
                 return true;
                 return true;
             }
             }
-            catch
+            catch (Exception e)
             {
             {
                 return false;
                 return false;
             }
             }
         }
         }
+        private string CanUpdateGetConfig(string file, string key)
+        {
+            try
+            {
+                Configuration config = ConfigurationManager.OpenExeConfiguration(file);
+                if (config.AppSettings.Settings.AllKeys.Contains(key))
+                {
+                    return config.AppSettings.Settings[key].Value;
+                }
+            }
+            catch (Exception e) { }
+            return null;
+        }
     }
     }
 }
 }

+ 12 - 0
Fork.Net/Y.Utils/DelegateUtils/ProgressDelegate.cs

@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Y.Utils.DelegateUtils
+{
+    public class ProgressDelegate
+    {
+        public delegate void ProgressHandler(long current, long total);
+    }
+}

+ 16 - 7
Fork.Net/Y.Utils/IOUtils/FileUtils/FileEncryptTool.cs

@@ -1,7 +1,7 @@
 //************************************************************************
 //************************************************************************
 //      https://github.com/yuzhengyang
 //      https://github.com/yuzhengyang
 //      author:     yuzhengyang
 //      author:     yuzhengyang
-//      date:       2017.6.8 - 2017.6.14
+//      date:       2017.6.8 - 2017.6.16
 //      desc:       文件加密工具
 //      desc:       文件加密工具
 //      Copyright (c) yuzhengyang. All rights reserved.
 //      Copyright (c) yuzhengyang. All rights reserved.
 //************************************************************************
 //************************************************************************
@@ -11,6 +11,7 @@ using System.IO;
 using System.Linq;
 using System.Linq;
 using System.Text;
 using System.Text;
 using Y.Utils.DataUtils.EncryptUtils;
 using Y.Utils.DataUtils.EncryptUtils;
+using Y.Utils.DelegateUtils;
 
 
 namespace Y.Utils.IOUtils.FileUtils
 namespace Y.Utils.IOUtils.FileUtils
 {
 {
@@ -36,7 +37,7 @@ namespace Y.Utils.IOUtils.FileUtils
         /// -12:加密后的目标文件已存在
         /// -12:加密后的目标文件已存在
         /// -404:未知错误,操作失败
         /// -404:未知错误,操作失败
         /// </returns>
         /// </returns>
-        public static int Encrypt(string srcFile, string dstFile, string password, bool overwrite = true)
+        public static int Encrypt(string srcFile, string dstFile, string password, ProgressDelegate.ProgressHandler progress, bool overwrite = true)
         {
         {
             DateTime beginTime = DateTime.Now;
             DateTime beginTime = DateTime.Now;
             if (!File.Exists(srcFile)) return -11; //要加密的文件不存在
             if (!File.Exists(srcFile)) return -11; //要加密的文件不存在
@@ -46,6 +47,7 @@ namespace Y.Utils.IOUtils.FileUtils
             string pwdMd5 = MD5Tool.Encrypt(MD5Tool.Encrypt(fmtPwd));
             string pwdMd5 = MD5Tool.Encrypt(MD5Tool.Encrypt(fmtPwd));
 
 
             string md5 = FileTool.GetMD5(srcFile);
             string md5 = FileTool.GetMD5(srcFile);
+            long current = 0;
             using (FileStream fsRead = new FileStream(srcFile, FileMode.Open))
             using (FileStream fsRead = new FileStream(srcFile, FileMode.Open))
             {
             {
                 using (FileStream fsWrite = new FileStream(dstFile, FileMode.Create))
                 using (FileStream fsWrite = new FileStream(dstFile, FileMode.Create))
@@ -97,6 +99,8 @@ namespace Y.Utils.IOUtils.FileUtils
                                 byte[] enbyte = AesTool.Encrypt(buffer, fmtPwd);
                                 byte[] enbyte = AesTool.Encrypt(buffer, fmtPwd);
                                 fsWrite.Write(enbyte, 0, enbyte.Length);
                                 fsWrite.Write(enbyte, 0, enbyte.Length);
                             }
                             }
+                            current += readCount;
+                            progress?.Invoke(current, fsRead.Length);
                         }
                         }
                         return (int)Math.Ceiling((DateTime.Now - beginTime).TotalSeconds);//操作成功
                         return (int)Math.Ceiling((DateTime.Now - beginTime).TotalSeconds);//操作成功
                     }
                     }
@@ -123,7 +127,7 @@ namespace Y.Utils.IOUtils.FileUtils
         /// -90:解锁密码错误
         /// -90:解锁密码错误
         /// -404:未知错误,操作失败
         /// -404:未知错误,操作失败
         /// </returns>
         /// </returns>
-        public static int Decrypt(string srcFile, string dstFile, string password, bool overwrite = true)
+        public static int Decrypt(string srcFile, string dstFile, string password, ProgressDelegate.ProgressHandler progress, bool overwrite = true)
         {
         {
             DateTime beginTime = DateTime.Now;
             DateTime beginTime = DateTime.Now;
             if (!File.Exists(srcFile)) return -11;//要解密的文件不存在
             if (!File.Exists(srcFile)) return -11;//要解密的文件不存在
@@ -132,6 +136,8 @@ namespace Y.Utils.IOUtils.FileUtils
             string fmtPwd = AesTool.FmtPassword(password);
             string fmtPwd = AesTool.FmtPassword(password);
             string pwdMd5 = MD5Tool.Encrypt(MD5Tool.Encrypt(fmtPwd));
             string pwdMd5 = MD5Tool.Encrypt(MD5Tool.Encrypt(fmtPwd));
             List<string> headdata = new List<string>();
             List<string> headdata = new List<string>();
+
+            long current = 0;
             using (FileStream fsRead = new FileStream(srcFile, FileMode.Open))
             using (FileStream fsRead = new FileStream(srcFile, FileMode.Open))
             {
             {
                 using (FileStream fsWrite = new FileStream(dstFile, FileMode.Create))
                 using (FileStream fsWrite = new FileStream(dstFile, FileMode.Create))
@@ -140,26 +146,27 @@ namespace Y.Utils.IOUtils.FileUtils
                     {
                     {
                         //读取文件类型标识和版本号
                         //读取文件类型标识和版本号
                         byte[] filetype = Encoding.Default.GetBytes(FileType);
                         byte[] filetype = Encoding.Default.GetBytes(FileType);
-                        fsRead.Read(filetype, 0, filetype.Length);
+                        current += fsRead.Read(filetype, 0, filetype.Length);
                         string filetypestr = Encoding.Default.GetString(filetype);
                         string filetypestr = Encoding.Default.GetString(filetype);
                         byte[] fileversion = Encoding.Default.GetBytes(FileVersion);
                         byte[] fileversion = Encoding.Default.GetBytes(FileVersion);
-                        fsRead.Read(fileversion, 0, fileversion.Length);
+                        current += fsRead.Read(fileversion, 0, fileversion.Length);
                         string fileversionstr = Encoding.Default.GetString(fileversion);
                         string fileversionstr = Encoding.Default.GetString(fileversion);
                         if (filetypestr != FileType && fileversionstr != FileVersion) return -20;//文件类型不匹配
                         if (filetypestr != FileType && fileversionstr != FileVersion) return -20;//文件类型不匹配
 
 
                         //读取头部信息个数
                         //读取头部信息个数
                         byte[] count = new byte[4];
                         byte[] count = new byte[4];
-                        fsRead.Read(count, 0, count.Length);
+                        current += fsRead.Read(count, 0, count.Length);
                         int countint = BitConverter.ToInt32(count, 0);
                         int countint = BitConverter.ToInt32(count, 0);
                         //读取各部分长度和数据
                         //读取各部分长度和数据
                         byte[] headlength = new byte[4 * countint];
                         byte[] headlength = new byte[4 * countint];
                         if (fsRead.Read(headlength, 0, headlength.Length) == headlength.Length)
                         if (fsRead.Read(headlength, 0, headlength.Length) == headlength.Length)
                         {
                         {
+                            current += headlength.Length;
                             for (int i = 0; i < countint; i++)
                             for (int i = 0; i < countint; i++)
                             {
                             {
                                 int datalong = BitConverter.ToInt32(headlength, i * 4);
                                 int datalong = BitConverter.ToInt32(headlength, i * 4);
                                 byte[] tempdata = new byte[datalong];
                                 byte[] tempdata = new byte[datalong];
-                                fsRead.Read(tempdata, 0, datalong);
+                                current += fsRead.Read(tempdata, 0, datalong);
                                 headdata.Add(Encoding.Default.GetString(tempdata));
                                 headdata.Add(Encoding.Default.GetString(tempdata));
                             }
                             }
                         }
                         }
@@ -182,6 +189,8 @@ namespace Y.Utils.IOUtils.FileUtils
                                 byte[] debyte = AesTool.Decrypt(buffer, fmtPwd);
                                 byte[] debyte = AesTool.Decrypt(buffer, fmtPwd);
                                 fsWrite.Write(debyte, 0, debyte.Length);
                                 fsWrite.Write(debyte, 0, debyte.Length);
                             }
                             }
+                            current += readCount;
+                            progress?.Invoke(current, fsRead.Length);
                         }
                         }
                     }
                     }
                     catch (Exception e) { }
                     catch (Exception e) { }

+ 27 - 9
Fork.Net/Y.Utils/IOUtils/FileUtils/FilePackageTool.cs

@@ -15,6 +15,7 @@ using System.Resources;
 using System.Runtime.Serialization.Formatters.Binary;
 using System.Runtime.Serialization.Formatters.Binary;
 using System.Text;
 using System.Text;
 using Y.Utils.DataUtils.Collections;
 using Y.Utils.DataUtils.Collections;
+using Y.Utils.DelegateUtils;
 using Y.Utils.IOUtils.PathUtils;
 using Y.Utils.IOUtils.PathUtils;
 
 
 namespace Y.Utils.IOUtils.FileUtils
 namespace Y.Utils.IOUtils.FileUtils
@@ -29,15 +30,19 @@ namespace Y.Utils.IOUtils.FileUtils
         private static int FileBuffer = 1024 * 1024;
         private static int FileBuffer = 1024 * 1024;
 
 
         /// <summary>
         /// <summary>
-        /// 打包
+        /// 文件打包
         /// </summary>
         /// </summary>
+        /// <param name="srcPath">要打包的路径</param>
+        /// <param name="dstFile">打包后的文件</param>
+        /// <param name="progress">回调进度</param>
+        /// <param name="overwrite">覆盖打包后的文件(重复时)</param>
         /// <returns>
         /// <returns>
         /// -11;//要打包的路径不存在
         /// -11;//要打包的路径不存在
         /// -12;//打包后的目标文件已存在
         /// -12;//打包后的目标文件已存在
         /// -13;//要打包的路径中没有文件
         /// -13;//要打包的路径中没有文件
         /// -404;//未知错误,操作失败
         /// -404;//未知错误,操作失败
         /// </returns>
         /// </returns>
-        public static int Pack(string srcPath, string dstFile, bool overwrite = true)
+        public static int Pack(string srcPath, string dstFile, ProgressDelegate.ProgressHandler progress, bool overwrite = true)
         {
         {
             DateTime beginTime = DateTime.Now;
             DateTime beginTime = DateTime.Now;
             if (!Directory.Exists(srcPath)) return -11;//要打包的路径不存在
             if (!Directory.Exists(srcPath)) return -11;//要打包的路径不存在
@@ -47,7 +52,8 @@ namespace Y.Utils.IOUtils.FileUtils
             List<FilePackageModel> files = CreateFilePackageModel(tempfiles, srcPath);
             List<FilePackageModel> files = CreateFilePackageModel(tempfiles, srcPath);
             if (ListTool.HasElements(files))
             if (ListTool.HasElements(files))
             {
             {
-                long allfilesize = files.Sum(x => x.Size);
+                long allfilesize = files.Sum(x => x.Size);//文件总大小
+                long surplusfilesize = allfilesize;//剩余要写入的文件大小
                 using (FileStream fsWrite = new FileStream(dstFile, FileMode.Create))
                 using (FileStream fsWrite = new FileStream(dstFile, FileMode.Create))
                 {
                 {
                     try
                     try
@@ -82,14 +88,15 @@ namespace Y.Utils.IOUtils.FileUtils
                                 while ((readCount = fsRead.Read(buffer, 0, buffer.Length)) > 0)
                                 while ((readCount = fsRead.Read(buffer, 0, buffer.Length)) > 0)
                                 {
                                 {
                                     fsWrite.Write(buffer, 0, readCount);
                                     fsWrite.Write(buffer, 0, readCount);
-                                    allfilesize -= readCount;
+                                    surplusfilesize -= readCount;
+                                    progress?.Invoke(allfilesize - surplusfilesize, allfilesize);
                                 }
                                 }
                             }
                             }
                         });
                         });
                     }
                     }
                     catch (Exception e) { }
                     catch (Exception e) { }
                 }
                 }
-                if (allfilesize == 0)
+                if (surplusfilesize == 0)
                 {
                 {
                     return (int)Math.Ceiling((DateTime.Now - beginTime).TotalSeconds);//操作成功
                     return (int)Math.Ceiling((DateTime.Now - beginTime).TotalSeconds);//操作成功
                 }
                 }
@@ -103,15 +110,19 @@ namespace Y.Utils.IOUtils.FileUtils
             return -404;//未知错误,操作失败
             return -404;//未知错误,操作失败
         }
         }
         /// <summary>
         /// <summary>
-        /// 
+        /// 
         /// </summary>
         /// </summary>
+        /// <param name="srcFile">包文件路径</param>
+        /// <param name="dstPath">拆包到的目录 </param>
+        /// <param name="progress">回调进度</param>
+        /// <param name="overwrite">覆盖拆包后的文件(重复时)</param>
         /// <returns>
         /// <returns>
         /// -11; //要解包的文件不存在
         /// -11; //要解包的文件不存在
         /// -12;//要解包的目标文件夹已存在
         /// -12;//要解包的目标文件夹已存在
         /// -20;// 文件类型不匹配
         /// -20;// 文件类型不匹配
         /// -404;//未知错误,操作失败
         /// -404;//未知错误,操作失败
         /// </returns>
         /// </returns>
-        public static int Unpack(string srcFile, string dstPath, bool overwrite = true)
+        public static int Unpack(string srcFile, string dstPath, ProgressDelegate.ProgressHandler progress, bool overwrite = true)
         {
         {
             DateTime beginTime = DateTime.Now;
             DateTime beginTime = DateTime.Now;
             if (!File.Exists(srcFile)) return -11; //要解包的文件不存在
             if (!File.Exists(srcFile)) return -11; //要解包的文件不存在
@@ -137,6 +148,8 @@ namespace Y.Utils.IOUtils.FileUtils
                         List<FilePackageModel> files = GetFilePackageModel(headdata);
                         List<FilePackageModel> files = GetFilePackageModel(headdata);
                         if (ListTool.HasElements(files))
                         if (ListTool.HasElements(files))
                         {
                         {
+                            long allfilesize = files.Sum(x => x.Size);//文件总大小
+                            long current = 0;//当前进度
                             //读取写出所有文件
                             //读取写出所有文件
                             files.ForEach(x =>
                             files.ForEach(x =>
                             {
                             {
@@ -153,11 +166,15 @@ namespace Y.Utils.IOUtils.FileUtils
                                             readCount = fsRead.Read(buffer, 0, buffer.Length);
                                             readCount = fsRead.Read(buffer, 0, buffer.Length);
                                             fsWrite.Write(buffer, 0, readCount);
                                             fsWrite.Write(buffer, 0, readCount);
                                             size -= readCount;
                                             size -= readCount;
+                                            current += readCount;
+                                            progress?.Invoke(current, allfilesize);
                                         }
                                         }
                                         if (size <= FileBuffer)
                                         if (size <= FileBuffer)
                                         {
                                         {
                                             readCount = fsRead.Read(buffer, 0, (int)size);
                                             readCount = fsRead.Read(buffer, 0, (int)size);
                                             fsWrite.Write(buffer, 0, readCount);
                                             fsWrite.Write(buffer, 0, readCount);
+                                            current += readCount;
+                                            progress?.Invoke(current, allfilesize);
                                         }
                                         }
                                     }
                                     }
                                 }
                                 }
@@ -167,8 +184,8 @@ namespace Y.Utils.IOUtils.FileUtils
                             foreach (var file in files)
                             foreach (var file in files)
                             {
                             {
                                 string temp = DirTool.Combine(dstPath, file.Path, file.Name);
                                 string temp = DirTool.Combine(dstPath, file.Path, file.Name);
-                                string tempMD5 = FileTool.GetMD5(temp);
-                                if (tempMD5 != file.MD5)//验证文件MD5不匹配则跳出验证
+                                string tempCk = FileTool.GetMD5(temp);
+                                if (tempCk != file.MD5)//验证文件(Size:速度会快一些,MD5在大文件的验证上非常耗时)
                                 {
                                 {
                                     allCheck = false;
                                     allCheck = false;
                                     break;
                                     break;
@@ -183,6 +200,7 @@ namespace Y.Utils.IOUtils.FileUtils
             return -404;//未知错误,操作失败
             return -404;//未知错误,操作失败
         }
         }
 
 
+
         /// <summary>
         /// <summary>
         /// 获取文件类型的类型版本
         /// 获取文件类型的类型版本
         /// </summary>
         /// </summary>

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

@@ -52,6 +52,7 @@
   </ItemGroup>
   </ItemGroup>
   <ItemGroup>
   <ItemGroup>
     <Compile Include="AppUtils\AppUnique.cs" />
     <Compile Include="AppUtils\AppUnique.cs" />
+    <Compile Include="DelegateUtils\ProgressDelegate.cs" />
     <Compile Include="IOUtils\FileUtils\FileCompressTool.cs" />
     <Compile Include="IOUtils\FileUtils\FileCompressTool.cs" />
     <Compile Include="IOUtils\FileUtils\FilePackageModel.cs" />
     <Compile Include="IOUtils\FileUtils\FilePackageModel.cs" />
     <Compile Include="IOUtils\FileUtils\FilePackageTool.cs" />
     <Compile Include="IOUtils\FileUtils\FilePackageTool.cs" />