diff --git a/Bin/Debug/CommonControls/.NET4 示例/Itrycn_Project.exe b/Bin/Debug/CommonControls/.NET4 示例/Itrycn_Project.exe index 3b7db33..1d51c25 100644 Binary files a/Bin/Debug/CommonControls/.NET4 示例/Itrycn_Project.exe and b/Bin/Debug/CommonControls/.NET4 示例/Itrycn_Project.exe differ diff --git a/Bin/Debug/CommonControls/.NET4 示例/MyDb.dll b/Bin/Debug/CommonControls/.NET4 示例/MyDb.dll index 357b85a..45845a5 100644 Binary files a/Bin/Debug/CommonControls/.NET4 示例/MyDb.dll and b/Bin/Debug/CommonControls/.NET4 示例/MyDb.dll differ diff --git a/Bin/Debug/CommonControls/.NET4 示例/MyDb.xml b/Bin/Debug/CommonControls/.NET4 示例/MyDb.xml index 4768abb..c3d0f9c 100644 --- a/Bin/Debug/CommonControls/.NET4 示例/MyDb.xml +++ b/Bin/Debug/CommonControls/.NET4 示例/MyDb.xml @@ -1614,6 +1614,88 @@ + + + 大文件与批量文件操作类,支持中途取消操作,本类需要实例化操作 + + + + + 传输进度 + + 当前传输完成的值 + 全部值,为-1表示无法获取 + 当前传输的百分比,为-1表示无法获取 + + + + 传输进度 + + + + + 取消事件 + + + + + 大文件按流复制文件,支持自动创建目标文件夹。 true:复制成功 false:复制失败 + + 原始文件路径 + 复制目标文件路径 + + + + + 复制文件夹到目标文件夹,不支持进度事件,支持中途取消 + + 源文件夹 + 目标文件夹 + 返回复制操作是否成功的标识,成功返回0,负数表示复制失败的文件数量。1表示源文件夹不存在 + + + + 复制文件夹到目标文件夹,支持进度事件,支持中途取消 + + 源文件夹 + 目标文件夹 + 返回复制操作是否成功的标识,成功返回0,负数表示复制失败的文件数量。1表示源文件夹不存在 + + + + 复制文件夹到目标文件夹,支持中途取消 + + 源文件夹 + 目标文件夹 + 初始的文件数量 + 总数量,如果不计算,则使用-1 + 操作的数量,包含成功的和失败的 + 返回复制操作是否成功的标识,成功返回0,负数表示复制失败的文件数量。1表示源文件夹不存在 + + + + 获取文件夹中的文件数量 + + 文件夹路径 + 返回文件数量,中途取消则返回-1 + + + + 获取文件夹的大小 + + 文件夹路径 + 返回文件数量,中途取消则返回-1 + + + + 添加文件到指定文件夹,会进行自动重命名,并返回重命名后的文件名(含路径) + + 要添加的文件路径 + 要添加到的文件夹 + 是否根据时间进行重命名 + 返回是否成功执行 + 成功执行则返回路径,否则返回空 + Hosts操作类 @@ -1992,11 +2074,11 @@ - 复制文件夹到目标文件夹 + 复制文件夹到目标文件夹(从3.0.2205.2601版本起已更换实现底层) 源文件夹 目标文件夹 - 返回移动操作是否成功的标识,成功返回0,负数表示复制失败的文件数量。1表示源文件夹不存在 + 返回复制操作是否成功的标识,成功返回0,负数表示复制失败的文件数量。1表示源文件夹不存在 diff --git a/Bin/Debug/CommonControls/.NET4 示例/MyDb_SQLite.dll b/Bin/Debug/CommonControls/.NET4 示例/MyDb_SQLite.dll index e85cb54..61db6a7 100644 Binary files a/Bin/Debug/CommonControls/.NET4 示例/MyDb_SQLite.dll and b/Bin/Debug/CommonControls/.NET4 示例/MyDb_SQLite.dll differ diff --git a/Bin/Debug/CommonControls/.NET4 示例/RyPrint.dll b/Bin/Debug/CommonControls/.NET4 示例/RyPrint.dll index c45563e..c639d9e 100644 Binary files a/Bin/Debug/CommonControls/.NET4 示例/RyPrint.dll and b/Bin/Debug/CommonControls/.NET4 示例/RyPrint.dll differ diff --git a/Bin/Debug/CommonControls/.NET4 示例/ryControls.dll b/Bin/Debug/CommonControls/.NET4 示例/ryControls.dll index 0b65b6b..893428e 100644 Binary files a/Bin/Debug/CommonControls/.NET4 示例/ryControls.dll and b/Bin/Debug/CommonControls/.NET4 示例/ryControls.dll differ diff --git a/Bin/Debug/CommonControls/.NET4 示例/ryControls.xml b/Bin/Debug/CommonControls/.NET4 示例/ryControls.xml index 12003aa..b1b565f 100644 --- a/Bin/Debug/CommonControls/.NET4 示例/ryControls.xml +++ b/Bin/Debug/CommonControls/.NET4 示例/ryControls.xml @@ -8697,6 +8697,11 @@ 标题栏图标尺寸 + + + 窗体图标,如果设置本项,将不使用Icon属性 + + 标题栏图标与窗体左边框的距离 diff --git a/Bin/Debug/CommonControls/.NET4 示例/ryUpdate.dll b/Bin/Debug/CommonControls/.NET4 示例/ryUpdate.dll index e83a60d..1567cfd 100644 Binary files a/Bin/Debug/CommonControls/.NET4 示例/ryUpdate.dll and b/Bin/Debug/CommonControls/.NET4 示例/ryUpdate.dll differ diff --git a/Bin/Debug/CommonControls/.NET4/MyDb.dll b/Bin/Debug/CommonControls/.NET4/MyDb.dll index 357b85a..45845a5 100644 Binary files a/Bin/Debug/CommonControls/.NET4/MyDb.dll and b/Bin/Debug/CommonControls/.NET4/MyDb.dll differ diff --git a/Bin/Debug/CommonControls/.NET4/MyDb.xml b/Bin/Debug/CommonControls/.NET4/MyDb.xml index 4768abb..c3d0f9c 100644 --- a/Bin/Debug/CommonControls/.NET4/MyDb.xml +++ b/Bin/Debug/CommonControls/.NET4/MyDb.xml @@ -1614,6 +1614,88 @@ + + + 大文件与批量文件操作类,支持中途取消操作,本类需要实例化操作 + + + + + 传输进度 + + 当前传输完成的值 + 全部值,为-1表示无法获取 + 当前传输的百分比,为-1表示无法获取 + + + + 传输进度 + + + + + 取消事件 + + + + + 大文件按流复制文件,支持自动创建目标文件夹。 true:复制成功 false:复制失败 + + 原始文件路径 + 复制目标文件路径 + + + + + 复制文件夹到目标文件夹,不支持进度事件,支持中途取消 + + 源文件夹 + 目标文件夹 + 返回复制操作是否成功的标识,成功返回0,负数表示复制失败的文件数量。1表示源文件夹不存在 + + + + 复制文件夹到目标文件夹,支持进度事件,支持中途取消 + + 源文件夹 + 目标文件夹 + 返回复制操作是否成功的标识,成功返回0,负数表示复制失败的文件数量。1表示源文件夹不存在 + + + + 复制文件夹到目标文件夹,支持中途取消 + + 源文件夹 + 目标文件夹 + 初始的文件数量 + 总数量,如果不计算,则使用-1 + 操作的数量,包含成功的和失败的 + 返回复制操作是否成功的标识,成功返回0,负数表示复制失败的文件数量。1表示源文件夹不存在 + + + + 获取文件夹中的文件数量 + + 文件夹路径 + 返回文件数量,中途取消则返回-1 + + + + 获取文件夹的大小 + + 文件夹路径 + 返回文件数量,中途取消则返回-1 + + + + 添加文件到指定文件夹,会进行自动重命名,并返回重命名后的文件名(含路径) + + 要添加的文件路径 + 要添加到的文件夹 + 是否根据时间进行重命名 + 返回是否成功执行 + 成功执行则返回路径,否则返回空 + Hosts操作类 @@ -1992,11 +2074,11 @@ - 复制文件夹到目标文件夹 + 复制文件夹到目标文件夹(从3.0.2205.2601版本起已更换实现底层) 源文件夹 目标文件夹 - 返回移动操作是否成功的标识,成功返回0,负数表示复制失败的文件数量。1表示源文件夹不存在 + 返回复制操作是否成功的标识,成功返回0,负数表示复制失败的文件数量。1表示源文件夹不存在 diff --git a/Bin/Debug/CommonControls/.NET4/MyDb_MySQL.dll b/Bin/Debug/CommonControls/.NET4/MyDb_MySQL.dll index 3b5e47d..cacda7a 100644 Binary files a/Bin/Debug/CommonControls/.NET4/MyDb_MySQL.dll and b/Bin/Debug/CommonControls/.NET4/MyDb_MySQL.dll differ diff --git a/Bin/Debug/CommonControls/.NET4/MyDb_SQLite.dll b/Bin/Debug/CommonControls/.NET4/MyDb_SQLite.dll index e85cb54..61db6a7 100644 Binary files a/Bin/Debug/CommonControls/.NET4/MyDb_SQLite.dll and b/Bin/Debug/CommonControls/.NET4/MyDb_SQLite.dll differ diff --git a/Bin/Debug/CommonControls/.NET4/RyPrint.dll b/Bin/Debug/CommonControls/.NET4/RyPrint.dll index c45563e..c639d9e 100644 Binary files a/Bin/Debug/CommonControls/.NET4/RyPrint.dll and b/Bin/Debug/CommonControls/.NET4/RyPrint.dll differ diff --git a/Bin/Debug/CommonControls/.NET4/ryControls.dll b/Bin/Debug/CommonControls/.NET4/ryControls.dll index 0b65b6b..893428e 100644 Binary files a/Bin/Debug/CommonControls/.NET4/ryControls.dll and b/Bin/Debug/CommonControls/.NET4/ryControls.dll differ diff --git a/Bin/Debug/CommonControls/.NET4/ryControls.xml b/Bin/Debug/CommonControls/.NET4/ryControls.xml index 12003aa..b1b565f 100644 --- a/Bin/Debug/CommonControls/.NET4/ryControls.xml +++ b/Bin/Debug/CommonControls/.NET4/ryControls.xml @@ -8697,6 +8697,11 @@ 标题栏图标尺寸 + + + 窗体图标,如果设置本项,将不使用Icon属性 + + 标题栏图标与窗体左边框的距离 diff --git a/Bin/Debug/CommonControls/.NET4/ryUpdate.dll b/Bin/Debug/CommonControls/.NET4/ryUpdate.dll index e83a60d..1567cfd 100644 Binary files a/Bin/Debug/CommonControls/.NET4/ryUpdate.dll and b/Bin/Debug/CommonControls/.NET4/ryUpdate.dll differ diff --git a/Bin/Release/CommonControls/.NET4 示例/Itrycn_Project.exe b/Bin/Release/CommonControls/.NET4 示例/Itrycn_Project.exe index 444cddf..edd2f05 100644 Binary files a/Bin/Release/CommonControls/.NET4 示例/Itrycn_Project.exe and b/Bin/Release/CommonControls/.NET4 示例/Itrycn_Project.exe differ diff --git a/Bin/Release/CommonControls/.NET4 示例/MyDb.dll b/Bin/Release/CommonControls/.NET4 示例/MyDb.dll index cc7fcc0..c9aa0fe 100644 Binary files a/Bin/Release/CommonControls/.NET4 示例/MyDb.dll and b/Bin/Release/CommonControls/.NET4 示例/MyDb.dll differ diff --git a/Bin/Release/CommonControls/.NET4 示例/MyDb.xml b/Bin/Release/CommonControls/.NET4 示例/MyDb.xml index 0c73939..a616cd0 100644 --- a/Bin/Release/CommonControls/.NET4 示例/MyDb.xml +++ b/Bin/Release/CommonControls/.NET4 示例/MyDb.xml @@ -1614,6 +1614,88 @@ + + + 大文件与批量文件操作类,支持中途取消操作,本类需要实例化操作 + + + + + 传输进度 + + 当前传输完成的值 + 全部值,为-1表示无法获取 + 当前传输的百分比,为-1表示无法获取 + + + + 传输进度 + + + + + 取消事件 + + + + + 大文件按流复制文件,支持自动创建目标文件夹。 true:复制成功 false:复制失败 + + 原始文件路径 + 复制目标文件路径 + + + + + 复制文件夹到目标文件夹,不支持进度事件,支持中途取消 + + 源文件夹 + 目标文件夹 + 返回复制操作是否成功的标识,成功返回0,负数表示复制失败的文件数量。1表示源文件夹不存在 + + + + 复制文件夹到目标文件夹,支持进度事件,支持中途取消 + + 源文件夹 + 目标文件夹 + 返回复制操作是否成功的标识,成功返回0,负数表示复制失败的文件数量。1表示源文件夹不存在 + + + + 复制文件夹到目标文件夹,支持中途取消 + + 源文件夹 + 目标文件夹 + 初始的文件数量 + 总数量,如果不计算,则使用-1 + 操作的数量,包含成功的和失败的 + 返回复制操作是否成功的标识,成功返回0,负数表示复制失败的文件数量。1表示源文件夹不存在 + + + + 获取文件夹中的文件数量 + + 文件夹路径 + 返回文件数量,中途取消则返回-1 + + + + 获取文件夹的大小 + + 文件夹路径 + 返回文件数量,中途取消则返回-1 + + + + 添加文件到指定文件夹,会进行自动重命名,并返回重命名后的文件名(含路径) + + 要添加的文件路径 + 要添加到的文件夹 + 是否根据时间进行重命名 + 返回是否成功执行 + 成功执行则返回路径,否则返回空 + Hosts操作类 @@ -1992,11 +2074,11 @@ - 复制文件夹到目标文件夹 + 复制文件夹到目标文件夹(从3.0.2205.2601版本起已更换实现底层) 源文件夹 目标文件夹 - 返回移动操作是否成功的标识,成功返回0,负数表示复制失败的文件数量。1表示源文件夹不存在 + 返回复制操作是否成功的标识,成功返回0,负数表示复制失败的文件数量。1表示源文件夹不存在 diff --git a/Bin/Release/CommonControls/.NET4 示例/MyDb_SQLite.dll b/Bin/Release/CommonControls/.NET4 示例/MyDb_SQLite.dll index 0972e0b..cd8754b 100644 Binary files a/Bin/Release/CommonControls/.NET4 示例/MyDb_SQLite.dll and b/Bin/Release/CommonControls/.NET4 示例/MyDb_SQLite.dll differ diff --git a/Bin/Release/CommonControls/.NET4 示例/RyPrint.dll b/Bin/Release/CommonControls/.NET4 示例/RyPrint.dll index 4b7fde8..d08761b 100644 Binary files a/Bin/Release/CommonControls/.NET4 示例/RyPrint.dll and b/Bin/Release/CommonControls/.NET4 示例/RyPrint.dll differ diff --git a/Bin/Release/CommonControls/.NET4 示例/ryControls.dll b/Bin/Release/CommonControls/.NET4 示例/ryControls.dll index f9de466..c4cf250 100644 Binary files a/Bin/Release/CommonControls/.NET4 示例/ryControls.dll and b/Bin/Release/CommonControls/.NET4 示例/ryControls.dll differ diff --git a/Bin/Release/CommonControls/.NET4 示例/ryControls.xml b/Bin/Release/CommonControls/.NET4 示例/ryControls.xml index 12003aa..b1b565f 100644 --- a/Bin/Release/CommonControls/.NET4 示例/ryControls.xml +++ b/Bin/Release/CommonControls/.NET4 示例/ryControls.xml @@ -8697,6 +8697,11 @@ 标题栏图标尺寸 + + + 窗体图标,如果设置本项,将不使用Icon属性 + + 标题栏图标与窗体左边框的距离 diff --git a/Bin/Release/CommonControls/.NET4 示例/ryUpdate.dll b/Bin/Release/CommonControls/.NET4 示例/ryUpdate.dll index 750fb7f..adf37b2 100644 Binary files a/Bin/Release/CommonControls/.NET4 示例/ryUpdate.dll and b/Bin/Release/CommonControls/.NET4 示例/ryUpdate.dll differ diff --git a/Bin/Release/CommonControls/.NET4/MyDb.dll b/Bin/Release/CommonControls/.NET4/MyDb.dll index cc7fcc0..c9aa0fe 100644 Binary files a/Bin/Release/CommonControls/.NET4/MyDb.dll and b/Bin/Release/CommonControls/.NET4/MyDb.dll differ diff --git a/Bin/Release/CommonControls/.NET4/MyDb.xml b/Bin/Release/CommonControls/.NET4/MyDb.xml index 0c73939..a616cd0 100644 --- a/Bin/Release/CommonControls/.NET4/MyDb.xml +++ b/Bin/Release/CommonControls/.NET4/MyDb.xml @@ -1614,6 +1614,88 @@ + + + 大文件与批量文件操作类,支持中途取消操作,本类需要实例化操作 + + + + + 传输进度 + + 当前传输完成的值 + 全部值,为-1表示无法获取 + 当前传输的百分比,为-1表示无法获取 + + + + 传输进度 + + + + + 取消事件 + + + + + 大文件按流复制文件,支持自动创建目标文件夹。 true:复制成功 false:复制失败 + + 原始文件路径 + 复制目标文件路径 + + + + + 复制文件夹到目标文件夹,不支持进度事件,支持中途取消 + + 源文件夹 + 目标文件夹 + 返回复制操作是否成功的标识,成功返回0,负数表示复制失败的文件数量。1表示源文件夹不存在 + + + + 复制文件夹到目标文件夹,支持进度事件,支持中途取消 + + 源文件夹 + 目标文件夹 + 返回复制操作是否成功的标识,成功返回0,负数表示复制失败的文件数量。1表示源文件夹不存在 + + + + 复制文件夹到目标文件夹,支持中途取消 + + 源文件夹 + 目标文件夹 + 初始的文件数量 + 总数量,如果不计算,则使用-1 + 操作的数量,包含成功的和失败的 + 返回复制操作是否成功的标识,成功返回0,负数表示复制失败的文件数量。1表示源文件夹不存在 + + + + 获取文件夹中的文件数量 + + 文件夹路径 + 返回文件数量,中途取消则返回-1 + + + + 获取文件夹的大小 + + 文件夹路径 + 返回文件数量,中途取消则返回-1 + + + + 添加文件到指定文件夹,会进行自动重命名,并返回重命名后的文件名(含路径) + + 要添加的文件路径 + 要添加到的文件夹 + 是否根据时间进行重命名 + 返回是否成功执行 + 成功执行则返回路径,否则返回空 + Hosts操作类 @@ -1992,11 +2074,11 @@ - 复制文件夹到目标文件夹 + 复制文件夹到目标文件夹(从3.0.2205.2601版本起已更换实现底层) 源文件夹 目标文件夹 - 返回移动操作是否成功的标识,成功返回0,负数表示复制失败的文件数量。1表示源文件夹不存在 + 返回复制操作是否成功的标识,成功返回0,负数表示复制失败的文件数量。1表示源文件夹不存在 diff --git a/Bin/Release/CommonControls/.NET4/MyDb_MySQL.dll b/Bin/Release/CommonControls/.NET4/MyDb_MySQL.dll index c4002ce..eb98bf2 100644 Binary files a/Bin/Release/CommonControls/.NET4/MyDb_MySQL.dll and b/Bin/Release/CommonControls/.NET4/MyDb_MySQL.dll differ diff --git a/Bin/Release/CommonControls/.NET4/MyDb_SQLite.dll b/Bin/Release/CommonControls/.NET4/MyDb_SQLite.dll index 0972e0b..cd8754b 100644 Binary files a/Bin/Release/CommonControls/.NET4/MyDb_SQLite.dll and b/Bin/Release/CommonControls/.NET4/MyDb_SQLite.dll differ diff --git a/Bin/Release/CommonControls/.NET4/RyPrint.dll b/Bin/Release/CommonControls/.NET4/RyPrint.dll index 4b7fde8..d08761b 100644 Binary files a/Bin/Release/CommonControls/.NET4/RyPrint.dll and b/Bin/Release/CommonControls/.NET4/RyPrint.dll differ diff --git a/Bin/Release/CommonControls/.NET4/ryControls.dll b/Bin/Release/CommonControls/.NET4/ryControls.dll index f9de466..c4cf250 100644 Binary files a/Bin/Release/CommonControls/.NET4/ryControls.dll and b/Bin/Release/CommonControls/.NET4/ryControls.dll differ diff --git a/Bin/Release/CommonControls/.NET4/ryControls.xml b/Bin/Release/CommonControls/.NET4/ryControls.xml index 12003aa..b1b565f 100644 --- a/Bin/Release/CommonControls/.NET4/ryControls.xml +++ b/Bin/Release/CommonControls/.NET4/ryControls.xml @@ -8697,6 +8697,11 @@ 标题栏图标尺寸 + + + 窗体图标,如果设置本项,将不使用Icon属性 + + 标题栏图标与窗体左边框的距离 diff --git a/Bin/Release/CommonControls/.NET4/ryUpdate.dll b/Bin/Release/CommonControls/.NET4/ryUpdate.dll index 750fb7f..adf37b2 100644 Binary files a/Bin/Release/CommonControls/.NET4/ryUpdate.dll and b/Bin/Release/CommonControls/.NET4/ryUpdate.dll differ diff --git a/CHANGELOG.md b/CHANGELOG.md index 4120286..29476de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,10 @@ -### 2022-05-09更新 +### 2022-05-26更新 +------ +#### MyDbV4 V3.0.2205.2601 +- *.[新增]新增BigFileOp类,支持对大文件和批量文件操作处理。 +- *.[改进]RyFiles类的部分函数更换为BigFileOp类底层操作。 + +### 2022-05-09更新 ------ #### MyDbV4 V3.0.2205.0901 - *.[改进]RyForm类的Show函数针对窗体最小化或不在屏幕内的情况做出优化。 diff --git a/Source/Itrycn_Project2/Properties/AssemblyInfo.cs b/Source/Itrycn_Project2/Properties/AssemblyInfo.cs index b974ffc..cbb4b45 100644 --- a/Source/Itrycn_Project2/Properties/AssemblyInfo.cs +++ b/Source/Itrycn_Project2/Properties/AssemblyInfo.cs @@ -10,7 +10,7 @@ using System.Runtime.InteropServices; [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("Itrycn_Project")] -[assembly: AssemblyCopyright("Copyright © 2021")] +[assembly: AssemblyCopyright("Copyright © 2022")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] diff --git a/Source/MyDb/FileFuns/BigFileOp.cs b/Source/MyDb/FileFuns/BigFileOp.cs new file mode 100644 index 0000000..60c55c3 --- /dev/null +++ b/Source/MyDb/FileFuns/BigFileOp.cs @@ -0,0 +1,296 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.IO; +using System.Linq; +using System.Text; + +namespace ryCommon +{ + /// + /// 大文件与批量文件操作类,支持中途取消操作,本类需要实例化操作 + /// + public class BigFileOp + { + /// + /// 传输进度 + /// + /// 当前传输完成的值 + /// 全部值,为-1表示无法获取 + /// 当前传输的百分比,为-1表示无法获取 + public delegate void TranProgressHandler(long curValue, long totalValue, double percent); + /// + /// 传输进度 + /// + public static event TranProgressHandler OnProgress; + /// + /// 取消事件 + /// + public static event CancelEventHandler OnCanel; + /// + /// 大文件按流复制文件,支持自动创建目标文件夹。 true:复制成功 false:复制失败 + /// + /// 原始文件路径 + /// 复制目标文件路径 + /// + public bool CopyBigFile(string soucrePath, string targetPath) + { + try + { + var TranSize = 1024 * 1024 * 2;//每次读取2M + //读取复制文件流 + using (FileStream fsRead = new FileStream(soucrePath, FileMode.Open, FileAccess.Read)) + { + if (RyFiles.DeleteFile(targetPath) != 0) + { + return false; + } + RyFiles.CreateDirectory(System.IO.Path.GetDirectoryName(targetPath)); + OnProgress?.Invoke(0, fsRead.Length, 0); + var totalSize = fsRead.Length; + //写入文件复制流 + using (FileStream fsWrite = new FileStream(targetPath, FileMode.OpenOrCreate, FileAccess.Write)) + { + byte[] buffer = new byte[TranSize]; + var curSize = 0L; + CancelEventArgs e1 = new CancelEventArgs(); + //可能文件比较大,要循环读取,每次读取2M + while (true) + { + if (OnCanel != null) + { + OnCanel?.Invoke(this, e1); + if (e1.Cancel) { + fsWrite.Close(); + RyFiles.DeleteFile(targetPath); + break; + } + } + //每次读取的数据 n:是每次读取到的实际数据大小 + int n = fsRead.Read(buffer, 0, buffer.Count()); + //如果n=0说明读取的数据为空,已经读取到最后了,跳出循环 + if (n == 0) + { + break; + } + curSize += n; + OnProgress?.Invoke(curSize, totalSize, totalSize == 0 ? 0 : curSize / (double)totalSize); + //写入每次读取的实际数据大小 + fsWrite.Write(buffer, 0, n); + } + } + OnProgress?.Invoke(totalSize, totalSize, 100); + if (!System.IO.File.Exists(targetPath)) + { + return false; + } + } + return true; + } + catch + { + return false; + } + } + /// + /// 复制文件夹到目标文件夹,不支持进度事件,支持中途取消 + /// + /// 源文件夹 + /// 目标文件夹 + /// 返回复制操作是否成功的标识,成功返回0,负数表示复制失败的文件数量。1表示源文件夹不存在 + public int CopyFolder(string fromDir, string ToDir) + { + return CopyFolder(fromDir,ToDir,0,-1,out _); + } + /// + /// 复制文件夹到目标文件夹,支持进度事件,支持中途取消 + /// + /// 源文件夹 + /// 目标文件夹 + /// 返回复制操作是否成功的标识,成功返回0,负数表示复制失败的文件数量。1表示源文件夹不存在 + public int CopyFolderByProgress(string fromDir, string ToDir) + { + var FileCount = GetFilesCount(fromDir); + return CopyFolder(fromDir, ToDir, 0, FileCount, out _); + } + /// + /// 复制文件夹到目标文件夹,支持中途取消 + /// + /// 源文件夹 + /// 目标文件夹 + /// 初始的文件数量 + /// 总数量,如果不计算,则使用-1 + /// 操作的数量,包含成功的和失败的 + /// 返回复制操作是否成功的标识,成功返回0,负数表示复制失败的文件数量。1表示源文件夹不存在 + private int CopyFolder(string fromDir, string ToDir,int StartCount,int TotalCount, out int Count) + { + Count = StartCount; + var _fromDir = fromDir.TrimEnd('\\'); + var _ToDir = ToDir.TrimEnd('\\'); + if (!Directory.Exists(_fromDir)) { return 1; } + var files = Directory.GetFiles(fromDir); + var error = 0; + CancelEventArgs e1 = new CancelEventArgs(); + foreach (var file in files) + { + if (OnCanel != null) + { + OnCanel?.Invoke(this, e1); + if (e1.Cancel) { break; } + } + if (!CopyBigFile(file, _ToDir + "\\" + Path.GetFileName(file))) + { + error++; + } + Count++; + var percent = 0d; + if (TotalCount>0) { percent = Count / (double)TotalCount; } + else if (TotalCount == -1) { percent = -1; } + OnProgress?.Invoke(Count, TotalCount, percent); + } + var dirs = Directory.GetDirectories(_fromDir); + foreach (var dir in dirs) + { + int result = CopyFolder(dir, _ToDir + "\\" + Path.GetFileName(dir), Count, TotalCount, out var _Count); + Count += _Count; + if (OnCanel != null) + { + OnCanel?.Invoke(this, e1); + if (e1.Cancel) { break; } + } + if (result > 0) + { + error++; + } + else if (result < 0) + { + error+=-result; + } + } + return -error; + } + /// + /// 获取文件夹中的文件数量 + /// + /// 文件夹路径 + /// 返回文件数量,中途取消则返回-1 + public int GetFilesCount(string Dir) + { + var _fromDir = Dir.TrimEnd('\\'); + if (!Directory.Exists(_fromDir)) { return 0; } + var files = Directory.GetFiles(_fromDir); + var count = 0; + CancelEventArgs e1 = new CancelEventArgs(); + count += files.Length; + var dirs = Directory.GetDirectories(_fromDir); + foreach (var dir in dirs) + { + if (OnCanel != null) + { + OnCanel?.Invoke(this, e1); + if (e1.Cancel) { count = -1; break; } + } + var result= GetFilesCount(dir); + if (result == -1) { count = -1;break; } + count+= result; + } + return count; + } + /// + /// 获取文件夹的大小 + /// + /// 文件夹路径 + /// 返回文件数量,中途取消则返回-1 + public long GetFolderSize(string Dir) + { + var _fromDir = Dir.TrimEnd('\\'); + if (!Directory.Exists(_fromDir)) { return 0; } + var files = Directory.GetFiles(_fromDir); + var size = 0L; + CancelEventArgs e1 = new CancelEventArgs(); + for (int i = 0; i < files.Length; i++) + { + if (OnCanel != null && i %5==0) + { + OnCanel?.Invoke(this, e1); + if (e1.Cancel) { size = -1; break; } + } + size +=RyFiles.GetFileSize(files[i]); + } + var dirs = Directory.GetDirectories(_fromDir); + foreach (var dir in dirs) + { + if (OnCanel != null) + { + OnCanel?.Invoke(this, e1); + if (e1.Cancel) { size = -1; break; } + } + var result = GetFilesCount(dir); + if (result == -1) { size = -1; break; } + size += result; + } + return size; + } + /// + /// 添加文件到指定文件夹,会进行自动重命名,并返回重命名后的文件名(含路径) + /// + /// 要添加的文件路径 + /// 要添加到的文件夹 + /// 是否根据时间进行重命名 + /// 返回是否成功执行 + /// 成功执行则返回路径,否则返回空 + public string AddFileToFolder(string filepath, string toFolder, bool RenameByTime, out bool OK) + { + OK = false; + var _toFolder = toFolder.TrimEnd('\\'); + RyFiles.CreateDirectory(_toFolder); + if (!System.IO.Directory.Exists(_toFolder)) { return ""; } + if (!System.IO.File.Exists(filepath) && !System.IO.Directory.Exists(filepath)) { return ""; } + var filename = System.IO.Path.GetFileName(filepath); + if (RenameByTime) { filename = DateTime.Now.ToString("yyyyMMddHHmmss") + System.IO.Path.GetExtension(filepath); } + if (!System.IO.File.Exists(_toFolder + "\\" + filename) && !System.IO.Directory.Exists(_toFolder + "\\" + filename)) + { + if (CopyBigFile(filepath, _toFolder + "\\" + filename)) + { + OK = true; + return _toFolder + "\\" + filename; + } + return "";//如果复制失败,则返回空路径 + } + else //如果目标路径已经存在同名文件 + { + int index = 0; + string filename_noext; + if (RenameByTime) { filename_noext = DateTime.Now.ToString("yyyyMMddHHmmss"); } + else { filename_noext = System.IO.Path.GetFileNameWithoutExtension(filepath); } + var ext = System.IO.Path.GetExtension(filepath); + CancelEventArgs e1 = new CancelEventArgs(); + while (index < 20) //最多重试20次 + { + if (OnCanel != null) + { + OnCanel?.Invoke(this, e1); + if (e1.Cancel) + { + break; + } + } + Random rd = new Random(Guid.NewGuid().GetHashCode()); + if (RenameByTime) { filename_noext = DateTime.Now.ToString("yyyyMMddHHmmss"); } + var to_path = _toFolder + "\\" + filename_noext + "_" + rd.Next(1000, 9999) + ext; + if (!System.IO.File.Exists(to_path) && !System.IO.Directory.Exists(to_path)) + { + if (CopyBigFile(filepath, to_path)) + { + OK = true; + return to_path; + } + return ""; + } + index++; + } + return ""; + } + } + } +} diff --git a/Source/MyDb/FileFuns/RyFiles.cs b/Source/MyDb/FileFuns/RyFiles.cs index d2630d5..32c9c45 100644 --- a/Source/MyDb/FileFuns/RyFiles.cs +++ b/Source/MyDb/FileFuns/RyFiles.cs @@ -1,6 +1,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.ComponentModel; using System.Drawing; using System.Drawing.Imaging; using System.IO; @@ -16,6 +17,7 @@ namespace ryCommon /// public class RyFiles { + private static BigFileOp file_op = new BigFileOp(); #region 【内部类型定义】 private struct SHFILEOPSTRUCT { @@ -285,6 +287,7 @@ namespace ryCommon /// 要复制的文件名 /// 复制到的目的文件名或路径 /// + [Obsolete("已过时,即将在将来移除该函数,请使用CopyBigFile代替")] public static int CopyFile(string sourceFileName, string destinationFileName) { string errorMsg = ""; @@ -353,66 +356,17 @@ namespace ryCommon /// public static bool CopyBigFile(string soucrePath, string targetPath) { - try - { - //读取复制文件流 - using (FileStream fsRead = new FileStream(soucrePath, FileMode.Open, FileAccess.Read)) - { - //写入文件复制流 - using (FileStream fsWrite = new FileStream(targetPath, FileMode.OpenOrCreate, FileAccess.Write)) - { - byte[] buffer = new byte[1024 * 1024 * 2]; //每次读取2M - //可能文件比较大,要循环读取,每次读取2M - while (true) - { - //每次读取的数据 n:是每次读取到的实际数据大小 - int n = fsRead.Read(buffer, 0, buffer.Count()); - //如果n=0说明读取的数据为空,已经读取到最后了,跳出循环 - if (n == 0) - { - break; - } - //写入每次读取的实际数据大小 - fsWrite.Write(buffer, 0, n); - } - } - } - return true; - } - catch - { - return false; - } + return file_op.CopyBigFile(soucrePath, targetPath); } /// - /// 复制文件夹到目标文件夹 + /// 复制文件夹到目标文件夹(从3.0.2205.2601版本起已更换实现底层) /// /// 源文件夹 /// 目标文件夹 - /// 返回移动操作是否成功的标识,成功返回0,负数表示复制失败的文件数量。1表示源文件夹不存在 + /// 返回复制操作是否成功的标识,成功返回0,负数表示复制失败的文件数量。1表示源文件夹不存在 public static int CopyFolder(string fromDir, string ToDir) { - var _fromDir = fromDir.TrimEnd('\\'); - var _ToDir=ToDir.TrimEnd('\\'); - if (!Directory.Exists(_fromDir)) { return 1; } - var files = Directory.GetFiles(fromDir); - var error = 0; - foreach (var file in files) - { - if (CopyFile(file, _ToDir + "\\" + Path.GetFileName(file)) != 0) - { - error++; - } - } - var dirs = Directory.GetDirectories(_fromDir); - foreach (var dir in dirs) - { - if (CopyFolder(dir, _ToDir + "\\" + Path.GetFileName(dir)) > 0) - { - error++; - } - } - return -error; + return file_op.CopyFolder(fromDir, ToDir); } #endregion 【复制文件操作】 @@ -672,7 +626,7 @@ namespace ryCommon } } [DllImport("Kernel32", CharSet = CharSet.Unicode)] - private static extern Int32 GetShortPathName(String path, StringBuilder shortPath, Int32 shortPathLength); + private static extern int GetShortPathName(String path, StringBuilder shortPath, Int32 shortPathLength); /// /// 打开文件夹并定位文件 /// @@ -830,10 +784,7 @@ namespace ryCommon /// public static void WriteAllText(string path, string content, Encoding encoding) { - if (!System.IO.Directory.Exists(System.IO.Path.GetDirectoryName(path))) - { - System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(path)); - } + CreateDirectory(System.IO.Path.GetDirectoryName(path)); System.IO.File.WriteAllText(path, content, encoding); } /// @@ -864,7 +815,7 @@ namespace ryCommon /// /// /// - public static Int64 GetFileSize(string path) + public static long GetFileSize(string path) { try { @@ -883,48 +834,7 @@ namespace ryCommon /// 成功执行则返回路径,否则返回空 public static string AddFileToFolder(string filepath,string toFolder,bool RenameByTime, out bool OK) { - OK = false; - var _toFolder = toFolder.TrimEnd('\\'); - CreateDirectory(_toFolder); - if (!System.IO.Directory.Exists(_toFolder)) { return ""; } - if (!System.IO.File.Exists(filepath) && !System.IO.Directory.Exists(filepath)) { return ""; } - var filename = System.IO.Path.GetFileName(filepath); - if (RenameByTime) { filename = DateTime.Now.ToString("yyyyMMddHHmmss") + System.IO.Path.GetExtension(filepath); } - if(!System.IO.File.Exists(_toFolder+"\\"+ filename) && !System.IO.Directory.Exists(_toFolder + "\\" + filename)) { - string errorMsg = ""; - if (ToMoveOrCopy(WFunc.FO_COPY, filepath, _toFolder + "\\" + filename, false, false, false, ref errorMsg) == 0) - { - OK = true; - return _toFolder + "\\" + filename; - } - return "";//如果复制失败,则返回空路径 - } - else //如果目标路径已经存在同名文件 - { - int index = 0; - string filename_noext; - if (RenameByTime) { filename_noext = DateTime.Now.ToString("yyyyMMddHHmmss"); } - else { filename_noext = System.IO.Path.GetFileNameWithoutExtension(filepath); } - var ext= System.IO.Path.GetExtension(filepath); - while (index<20) //最多重试20次 - { - Random rd = new Random(Guid.NewGuid().GetHashCode()); - if (RenameByTime) { filename_noext = DateTime.Now.ToString("yyyyMMddHHmmss"); } - var to_path = _toFolder + "\\" + filename_noext+"_"+ rd.Next(1000, 9999)+ ext; - if(!System.IO.File.Exists(to_path) && !System.IO.Directory.Exists(to_path)) - { - string errorMsg = ""; - if (ToMoveOrCopy(WFunc.FO_COPY, filepath, to_path, false, false, false, ref errorMsg) == 0) - { - OK = true; - return to_path; - } - return ""; - } - index++; - } - return ""; - } + return file_op.AddFileToFolder(filepath, toFolder, RenameByTime,out OK); } /// /// 获取文件大小字符串 diff --git a/Source/MyDb/MyDbV4.csproj b/Source/MyDb/MyDbV4.csproj index a8ce5cc..2d4f6a9 100644 --- a/Source/MyDb/MyDbV4.csproj +++ b/Source/MyDb/MyDbV4.csproj @@ -75,6 +75,7 @@ + diff --git a/Source/MyDb/Properties/AssemblyInfo.cs b/Source/MyDb/Properties/AssemblyInfo.cs index a33fa43..950931c 100644 --- a/Source/MyDb/Properties/AssemblyInfo.cs +++ b/Source/MyDb/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System; //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, // 方法是按如下所示使用“*”: : // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("3.0.2205.0901")] -[assembly: AssemblyFileVersion("3.0.2205.0901")] \ No newline at end of file +[assembly: AssemblyVersion("3.0.2205.2601")] +[assembly: AssemblyFileVersion("3.0.2205.2601")] \ No newline at end of file diff --git a/Source/ryControls/Gdu.WinFormUI/Forms/GMForm.cs b/Source/ryControls/Gdu.WinFormUI/Forms/GMForm.cs index 7eaa442..95d0699 100644 --- a/Source/ryControls/Gdu.WinFormUI/Forms/GMForm.cs +++ b/Source/ryControls/Gdu.WinFormUI/Forms/GMForm.cs @@ -337,6 +337,24 @@ namespace MGdu.WinFormUI Invalidate(); } } + private Image gmform_icon = null; + /// + /// 窗体图标,如果设置本项,将不使用Icon属性 + /// + [Category("GMForm")] + [Description("窗体图标,如果设置本项,将不使用Icon属性")] + public Image GMFormIcon + { + get + { + return gmform_icon; + } + set + { + gmform_icon = value; + Invalidate(); + } + } /// /// 标题栏图标与窗体左边框的距离 /// @@ -1124,7 +1142,14 @@ namespace MGdu.WinFormUI { if (ShowIcon && Icon != null && XTheme.DrawCaptionIcon) { - g.DrawIcon(this.Icon, IconRect); + if (GMFormIcon == null) + { + g.DrawIcon(this.Icon, IconRect); + } + else + { + g.DrawImage(this.GMFormIcon, IconRect); + } } if (!string.IsNullOrEmpty(Text) && XTheme.DrawCaptionText)