lith vor 4 Jahren
Commit
cda522ba74

+ 25 - 0
FileZip.sln

@@ -0,0 +1,25 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 16
+VisualStudioVersion = 16.0.29503.13
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FileZip", "FileZip\FileZip.csproj", "{6FA12BB6-521C-47BE-8D4A-70A342C3C1F8}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Any CPU = Debug|Any CPU
+		Release|Any CPU = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{6FA12BB6-521C-47BE-8D4A-70A342C3C1F8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{6FA12BB6-521C-47BE-8D4A-70A342C3C1F8}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{6FA12BB6-521C-47BE-8D4A-70A342C3C1F8}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{6FA12BB6-521C-47BE-8D4A-70A342C3C1F8}.Release|Any CPU.Build.0 = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+	GlobalSection(ExtensibilityGlobals) = postSolution
+		SolutionGuid = {9DE03764-EDBD-4172-8CBE-3425AD3A181D}
+	EndGlobalSection
+EndGlobal

+ 89 - 0
FileZip/Cmd/Compression.cs

@@ -0,0 +1,89 @@
+using SharpCompress.Common;
+using SharpCompress.Writers;
+using System.IO;
+using Vit.ConsoleUtil;
+
+namespace FileZip.Cmd
+{
+    public class Compression
+    {
+
+        #region zip
+        [Command("zip")]
+        [Remarks("压缩为gzip文件。参数说明:")]
+        [Remarks("-i[--input] 待压缩目录 例如 \"/data/a\"")]
+        [Remarks("-o[--output] 压缩后文件名(若不指定,加压到压缩文件夹所在目录),例如 \"/data/a.zip\"")]
+        [Remarks("示例: zip -i \"/data/a\" -o \"/data/a.zip\" ")]
+        public static void zip(string[] args)
+        {
+            compression(args);
+        }
+        #endregion
+         
+
+
+
+        #region compression
+        public static void compression(string[] args)
+        {
+
+            ArchiveType archiveType;
+            CompressionType compressionType;
+            string fileSuffix;
+
+            #region (x.1) get arg
+
+            switch (args[0]) 
+            {
+                //case "gzip": archiveType = ArchiveType.GZip; compressionType = CompressionType.GZip; fileSuffix = "gz"; break;
+                //case "rar": archiveType = ArchiveType.Rar; compressionType = CompressionType.Deflate; fileSuffix = "rar"; break;
+                //case "7z": archiveType = ArchiveType.SevenZip; compressionType = CompressionType.de; fileSuffix = "7z"; break;
+                //case "tar": archiveType = ArchiveType.Tar; compressionType = CompressionType.GZip; fileSuffix = "tar"; break;
+                case "zip": archiveType = ArchiveType.Zip; compressionType = CompressionType.Deflate; fileSuffix = "zip"; break;
+                default: return;
+            }
+
+
+            string input = ConsoleHelp.GetArg(args, "-i") ?? ConsoleHelp.GetArg(args, "--input");
+            if (string.IsNullOrEmpty(input))
+            {
+                ConsoleHelp.Log("请指定待压缩目录");
+                return;
+            }
+
+            string output = ConsoleHelp.GetArg(args, "-o") ?? ConsoleHelp.GetArg(args, "--output");
+            if (string.IsNullOrEmpty(output))
+            {
+                output = input + "."+ fileSuffix;              
+            }
+            #endregion
+
+ 
+
+
+            #region (x.2) 开始压缩
+
+            ConsoleHelp.Log("开始压缩");
+            ConsoleHelp.Log("待压缩文件:" + input);
+            ConsoleHelp.Log("压缩后文件名:" + output);
+
+            var writerOptions=new WriterOptions(compressionType);
+            writerOptions.ArchiveEncoding.Default = System.Text.Encoding.GetEncoding("utf-8");
+
+            using (var fileStream = File.OpenWrite(output))
+            using (var writer = WriterFactory.Open(fileStream, archiveType, writerOptions))
+            {               
+                writer.WriteAll(input, "*", SearchOption.AllDirectories);           
+            }
+
+            #endregion
+
+            ConsoleHelp.Log("文件压缩成功!!!");
+        }
+
+        #endregion
+
+
+
+    }
+}

+ 83 - 0
FileZip/Cmd/Marge.cs

@@ -0,0 +1,83 @@
+using System.IO;
+using System.Linq;
+using Vit.ConsoleUtil;
+
+namespace FileZip.Cmd
+{
+    public class Marge
+    {
+
+        [Command("marge")]        
+        [Remarks("合并文件。参数说明:")]
+        [Remarks("-i[--input] 待合并的文件夹 或 文件查询字符串。 如 /data/a/1.7z.* ")]
+        [Remarks("-o[--output] 合并后文件")]
+        [Remarks("示例: marge -i \"/data/a\" -o /data/a.7z  ")]
+        public static void marge(string[] args)
+        {
+            #region (x.1) get arg 
+            string input = ConsoleHelp.GetArg(args, "-i") ?? ConsoleHelp.GetArg(args, "--input");
+            if (string.IsNullOrEmpty(input))
+            {
+                ConsoleHelp.Log("请指定要合并的文件(夹)");
+                return;
+            }
+
+            string output= ConsoleHelp.GetArg(args,"-o") ?? ConsoleHelp.GetArg(args, "--output");
+            if (string.IsNullOrEmpty(output))
+            {
+                ConsoleHelp.Log("请指定输出文件");
+                return;
+            }           
+            #endregion
+
+            ConsoleHelp.Log("开始合并");          
+            ConsoleHelp.Log("待合并的文件(夹):" + input);
+            ConsoleHelp.Log("输出文件:" + output);
+
+
+            #region (x.2)获取 要合并的文件
+            string[] inFiles;
+            if (input.IndexOf('*') > 0)
+            {
+                inFiles = new DirectoryInfo(Path.GetDirectoryName(input)).GetFiles(Path.GetFileName(input)).OrderBy(m => m.Name).Select(m => m.FullName).ToArray();
+            }
+            else
+            {
+                inFiles = new DirectoryInfo(input).GetFiles().OrderBy(m => m.Name).Select(m => m.FullName).ToArray();
+            }
+            var sum = inFiles.Count();
+            ConsoleHelp.Log("要合并的文件总数:" + sum);
+
+            #endregion
+
+
+            #region (x.3)合并文件       
+            File.Delete(output);
+            using (var sw = new FileStream(output, FileMode.CreateNew))
+            {               
+                int finished = 0;
+                foreach (var inFile in inFiles)
+                {
+                    ConsoleHelp.Log($"[{ ++finished }/{sum}]合并文件:"+inFile);
+                    using (var reader = new FileStream(inFile, FileMode.Open))
+                    {
+                        reader.CopyTo(sw);
+                    }
+                }
+            }
+            #endregion
+
+            ConsoleHelp.Log("文件合并成功!!!");
+
+        }
+
+
+
+
+
+
+
+
+
+    }
+}

+ 143 - 0
FileZip/Cmd/Un7z.cs

@@ -0,0 +1,143 @@
+using SharpCompress.Archives;
+using SharpCompress.Common;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using Vit.ConsoleUtil;
+
+namespace FileZip.Cmd
+{
+    public class Un7z
+    {
+
+
+        #region un7z
+        
+        [Command("un7z")]
+        [Remarks("解压7z文件。参数说明:")]
+        [Remarks("-i[--input] 待解压文件 例如 \"/data/a.7z.001\"")]
+        [Remarks("-o[--output] 输出目录,(若不指定,则解压到压缩文件所在目录)")]
+        [Remarks("-m[--mute] 若指定,则不输出解压的文件(夹)信息")]
+        [Remarks("-mf[--mutefile] 若指定,则不输出解压的文件信息")]
+        [Remarks("示例: un7z -i \"/data/a.7z\" -o \"/data/out\" --mute ")]
+        public static void un7z(string[] args)
+        {
+            #region (x.1) get arg
+            string  input = ConsoleHelp.GetArg(args, "-i") ?? ConsoleHelp.GetArg(args, "--input");
+            if (string.IsNullOrEmpty(input))
+            {
+                ConsoleHelp.Log("请指定待解压文件");
+                return;
+            }
+
+            string output = ConsoleHelp.GetArg(args, "-o") ?? ConsoleHelp.GetArg(args, "--output");
+            if (string.IsNullOrEmpty(output))
+            {
+                //var directory = Path.GetDirectoryName(input);
+                //output = Path.Combine(directory,Path.GetFileNameWithoutExtension(input));
+                //if (output == input) 
+                //{
+                //    output = directory;
+                //}
+                output = Path.GetDirectoryName(input);
+
+                //ConsoleHelp.Log("请指定输出目录");
+                //return;
+            }
+            Directory.CreateDirectory(output);
+
+            bool printFile = (
+                (ConsoleHelp.GetArg(args, "-m") == null && ConsoleHelp.GetArg(args, "--mute") == null )
+             &&(ConsoleHelp.GetArg(args, "-mf") == null && ConsoleHelp.GetArg(args, "--mutefile") == null)  );
+
+            bool printDirectory = (ConsoleHelp.GetArg(args, "-m") == null && ConsoleHelp.GetArg(args, "--mute") == null);
+            #endregion
+
+            bool inputFileIsTemp = false;
+
+
+            try
+            {
+                #region (x.2)若为压缩分卷文件则合并到临时文件
+                {
+                    var extension = Path.GetExtension(input).TrimStart('.');
+                    if (int.TryParse(extension, out _))
+                    {
+                        var fileSearch = Path.Combine(Path.GetDirectoryName(input), Path.GetFileNameWithoutExtension(input) + ".*");
+
+                        input= Path.Combine(Path.GetDirectoryName(input),"tmp_"+ Path.GetFileNameWithoutExtension(input) + ".tmp");
+                      
+                        inputFileIsTemp = true;
+                        var cmd = new List<string>() { "marge" };
+                        cmd.AddRange(new[] { "-i", fileSearch });
+                        cmd.AddRange(new[] { "-o", input });                        
+                        Marge.marge(cmd.ToArray());
+                    }
+                }
+                #endregion
+
+
+
+                #region (x.3) 开始解压
+
+                ConsoleHelp.Log("开始解压");
+                ConsoleHelp.Log("待解压文件:" + input);
+                ConsoleHelp.Log("输出目录:" + output);
+               
+                using (var archive = ArchiveFactory.Open(input))
+                {
+                    var sum = archive.Entries.Count();
+
+                    if (sum == 0)
+                    {
+                        ConsoleHelp.Log("压缩文件中没有文件");
+                        return;
+                    }
+
+                    int finished = 0;
+                    int step = sum / 100;
+                    int nextStep = step;
+                    foreach (var entry in archive.Entries)
+                    {
+                        finished++;
+
+                        if (finished >= nextStep)
+                        {
+                            nextStep += step;
+                            ConsoleHelp.Log($"[{ finished }/{sum} ] 已完成 { finished * 100 / sum }%");
+                        }
+
+                        if (entry.IsDirectory)
+                        {
+                            if (printDirectory) ConsoleHelp.Log($"[{ finished }/{sum} d]  " + entry.Key);
+                        }
+                        else
+                        {
+
+                            if (printFile) ConsoleHelp.Log($"[{ finished }/{sum} f]  " + entry.Key);
+                            entry.WriteToDirectory(output, new ExtractionOptions() { ExtractFullPath = true, Overwrite = true });
+                        }
+                    }
+                }
+
+                #endregion
+            }
+            finally
+            {
+                if (inputFileIsTemp)
+                {
+                    ConsoleHelp.Log("删除临时文件:" + input);
+                    File.Delete(input);
+                }
+            }
+
+            ConsoleHelp.Log("文件解压成功!!!");
+        }
+
+        #endregion
+
+ 
+
+
+    }
+}

+ 132 - 0
FileZip/Cmd/Unrar.cs

@@ -0,0 +1,132 @@
+using SharpCompress.Archives;
+using SharpCompress.Common;
+using SharpCompress.Readers;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using Vit.ConsoleUtil;
+
+namespace FileZip.Cmd
+{
+    public class Unrar
+    {
+
+
+        #region unrar
+        
+        [Command("unrar")]
+        [Remarks("解压rar文件。参数说明:")]
+        [Remarks("-i[--input] 待解压文件 例如 \"/data/a.rar.001\"")]
+        [Remarks("-o[--output] 输出目录,(若不指定,则解压到压缩文件所在目录)")]
+        [Remarks("-m[--mute] 若指定,则不输出解压的文件(夹)信息")]
+        [Remarks("-mf[--mutefile] 若指定,则不输出解压的文件信息")]
+        [Remarks("示例: unrar -i \"/data/a.rar\" -o \"/data/out\" --mute ")]
+        public static void Cmd_un7z(string[] args)
+        {
+            #region (x.1) get arg
+            string  input = ConsoleHelp.GetArg(args, "-i") ?? ConsoleHelp.GetArg(args, "--input");
+            if (string.IsNullOrEmpty(input))
+            {
+                ConsoleHelp.Log("请指定待解压文件");
+                return;
+            }
+
+            string output = ConsoleHelp.GetArg(args, "-o") ?? ConsoleHelp.GetArg(args, "--output");
+            if (string.IsNullOrEmpty(output))
+            {
+                //var directory = Path.GetDirectoryName(input);
+                //output = Path.Combine(directory, Path.GetFileNameWithoutExtension(input));
+                //if (output == input)
+                //{
+                //    output = directory;
+                //}
+                output = Path.GetDirectoryName(input);
+
+                //ConsoleHelp.Log("请指定输出目录");
+                //return;
+            }
+            Directory.CreateDirectory(output);
+
+            bool printFile = (
+                (ConsoleHelp.GetArg(args, "-m") == null && ConsoleHelp.GetArg(args, "--mute") == null )
+             &&(ConsoleHelp.GetArg(args, "-mf") == null && ConsoleHelp.GetArg(args, "--mutefile") == null)  );
+
+            bool printDirectory = (ConsoleHelp.GetArg(args, "-m") == null && ConsoleHelp.GetArg(args, "--mute") == null);
+            #endregion
+
+            bool inputFileIsTemp = false;
+
+
+            try
+            {
+                #region (x.2)若为压缩分卷文件则合并到临时文件
+                {
+                    var extension = Path.GetExtension(input).TrimStart('.');
+                    if (int.TryParse(extension, out _))
+                    {
+                        var fileSearch = Path.Combine(Path.GetDirectoryName(input), Path.GetFileNameWithoutExtension(input) + ".*");
+
+                        input= Path.Combine(Path.GetDirectoryName(input),"tmp_"+ Path.GetFileNameWithoutExtension(input) + ".tmp");
+                      
+                        inputFileIsTemp = true;
+                        var cmd = new List<string>() { "marge" };
+                        cmd.AddRange(new[] { "-i", fileSearch });
+                        cmd.AddRange(new[] { "-o", input });                        
+                        Marge.marge(cmd.ToArray());
+                    }
+                }
+                #endregion
+
+
+
+                #region (x.3) 开始解压
+
+                ConsoleHelp.Log("开始解压");
+                ConsoleHelp.Log("待解压文件:" + input);
+                ConsoleHelp.Log("输出目录:" + output);
+                using (Stream stream = File.OpenRead(input))
+                using (var reader = ReaderFactory.Open(stream))
+                {
+                    int fileCount = 0;
+                    int directoryCount = 0;              
+                    while (reader.MoveToNextEntry())
+                    {
+                        var entry = reader.Entry;                
+
+                        if (entry.IsDirectory)
+                        {
+                            directoryCount++;
+                            if (printDirectory) ConsoleHelp.Log($"[{ fileCount }-{directoryCount} d]: " + entry.Key);
+                        }
+                        else
+                        {
+                            fileCount++;
+                            if (printFile) ConsoleHelp.Log($"[{ fileCount }-{directoryCount} f]: " + entry.Key);
+                            reader.WriteEntryToDirectory(output, new ExtractionOptions() { ExtractFullPath = true, Overwrite = true });
+                        }
+                    }
+                }
+ 
+
+                #endregion
+            }
+            finally
+            {
+                if (inputFileIsTemp)
+                {
+                    ConsoleHelp.Log("删除临时文件:" + input);
+                    File.Delete(input);
+                }
+            }
+
+            ConsoleHelp.Log("文件解压成功!!!");
+        }
+
+        #endregion
+
+
+ 
+
+
+    }
+}

+ 33 - 0
FileZip/Cmd/Unzip.cs

@@ -0,0 +1,33 @@
+using SharpCompress.Archives;
+using SharpCompress.Common;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using Vit.ConsoleUtil;
+
+namespace FileZip.Cmd
+{
+    public class Unzip
+    {
+
+
+        #region unzip
+        
+        [Command("unzip")]
+        [Remarks("解压zip文件。参数说明:")]
+        [Remarks("-i[--input] 待解压文件 例如 \"/data/a.zip.001\"")]
+        [Remarks("-o[--output] 输出目录,(若不指定,则解压到压缩文件所在目录)")]
+        [Remarks("-m[--mute] 若指定,则不输出解压的文件(夹)信息")]
+        [Remarks("-mf[--mutefile] 若指定,则不输出解压的文件信息")]
+        [Remarks("示例: unzip -i \"/data/a.zip\" -o \"/data/out\" --mute ")]
+        public static void unzip(string[] args)
+        {          
+            Un7z.un7z(args);
+        }
+        #endregion
+
+ 
+
+
+    }
+}

+ 48 - 0
FileZip/ConsoleUtil/Attribute.cs

@@ -0,0 +1,48 @@
+#region << 版本注释-v1 >>
+/*
+ * ========================================================================
+ * 版本:v1
+ * 时间:2020-04-08
+ * 作者:lith
+ * 邮箱:sersms@163.com
+ * 说明: 
+ * ========================================================================
+*/
+#endregion
+
+using System;
+
+namespace Vit.ConsoleUtil
+{
+    #region CommandAttribute
+    /// <summary>
+    /// 命令名称,若不指定内容则使用函数名
+    /// </summary>
+    [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
+    public class CommandAttribute : System.Attribute
+    {
+        public string Value { get; set; }
+
+        public CommandAttribute(string Value = null)
+        {
+            this.Value = Value;
+        }
+    }
+    #endregion
+
+    #region RemarksAttribute
+    /// <summary>
+    /// 命令说明,用以提示用户
+    /// </summary>
+    [AttributeUsage(AttributeTargets.Method, AllowMultiple = true, Inherited = false)]
+    public class RemarksAttribute : System.Attribute
+    {
+        public string Value { get; set; }
+
+        public RemarksAttribute(string Value)
+        {
+            this.Value = Value;
+        }
+    }
+    #endregion
+}

+ 193 - 0
FileZip/ConsoleUtil/ConsoleHelp.cs

@@ -0,0 +1,193 @@
+#region << 版本注释-v1 >>
+/*
+ * ========================================================================
+ * 版本:v1
+ * 时间:2020-04-08
+ * 作者:lith
+ * 邮箱:sersms@163.com
+ * 说明: 
+ * ========================================================================
+*/
+#endregion
+
+using System;
+using System.Linq;
+using System.Reflection;
+
+namespace Vit.ConsoleUtil
+{
+    #region ConsoleHelp
+    public class ConsoleHelp
+    {
+        public static Action<string> Log = (msg) => { Console.WriteLine(msg); };
+
+
+        #region GetArg
+        /// <summary>
+        ///  null: 未指定参数
+        ///  ""  : 指定了参数,但未指定值
+        ///  其他: 指定了参数,其为参数的值
+        /// </summary>
+        /// <param name="args"> </param>
+        /// <param name="argName">参数名 如 "-createTable"</param>
+        /// <returns></returns>
+        public static string GetArg(string[] args, string argName)
+        {
+            var index = Array.IndexOf(args, argName);
+            if (index < 0) return null;
+
+            if (index + 1 == args.Length)
+            {
+                return "";
+            }
+
+            var value = args[index + 1];
+            if (value.StartsWith('-')) return "";
+            return value;
+        }
+        #endregion
+
+
+
+        #region Exec
+        /// <summary> 
+        /// 查找CommandAttribute特性的静态函数并按参数指定调用
+        /// </summary>
+        /// <param name="args"></param>
+        public static void Exec(string[] args)
+        {
+
+            //var arg = new List<string>() { "un7z" };
+            //arg.AddRange(new[] { "-i", "T:\\temp\\tileset.7z.001" });
+            //arg.AddRange(new[] { "-o", "T:\\temp\\un7z" });
+            //args = arg.ToArray();
+
+            #region (x.1)通过反射获取所有命令            
+            var cmdMap =
+                //获取所有type
+                Assembly.GetEntryAssembly().GetTypes()
+                //获取所有静态函数
+                .SelectMany(type => type.GetMethods(BindingFlags.Static | BindingFlags.Public))
+                //获取指定CommandAttribute的函数
+                .Where(m => m.GetCustomAttribute<CommandAttribute>() != null)
+                //按照 命令名称 和 Method 构建Dictionary 
+                .ToDictionary(
+                  m => (m.GetCustomAttribute<CommandAttribute>().Value ?? m.Name)
+                  , m => m
+                );
+            #endregion
+
+
+            #region (x.2)若未指定命令名称,则输出帮助文档            
+            if (args == null || args.Length == 0 || string.IsNullOrEmpty(args[0]))
+            {
+                #region 输出命令帮助文档
+                ConsoleHelp.Log("命令帮助文档:");
+                foreach (var cmd in cmdMap)
+                {
+                    ConsoleHelp.Log("---------------");
+                    ConsoleHelp.Log(cmd.Key);
+                    cmd.Value.GetCustomAttributes<RemarksAttribute>()?.Select(m => m.Value).ToList().ForEach(ConsoleHelp.Log);
+                }
+                ConsoleHelp.Log("---------------");
+                ConsoleHelp.Log("");
+                ConsoleHelp.Log("");
+                #endregion
+                return;
+            }
+            #endregion
+
+
+            #region (x.3)通过第一个参数查找命令并调用            
+            try
+            {
+                cmdMap.TryGetValue(args[0], out var method);
+
+                if (method == null)
+                {
+                    ConsoleHelp.Log($"出错:命令 { args[0] } 不存在!");
+                    return;
+                }
+                ConsoleHelp.Log("------------------------------");        
+                ConsoleHelp.Log($"开始执行命令 { args[0] } ...");
+                ConsoleHelp.Log("---------------");
+
+                method.Invoke(null, new object[] { args });
+            }
+            catch (Exception ex)
+            {
+                ex = ex.GetBaseException();
+                ConsoleHelp.Log("出错:" + ex.Message);
+                ConsoleHelp.Log("出错:" + ex.StackTrace);
+                return;
+            }
+            #endregion
+
+            ConsoleHelp.Log("结束!!");
+            return;
+        }
+
+
+
+
+        #endregion
+
+
+        #region command help
+        [Command("help")]
+        [Remarks("帮助文档:")]
+        [Remarks("-c[--command] 要查询的命令。若不指定则返回所有命令的文档。如 help ")]
+        [Remarks("示例: help -c help")]
+        public static void Help(string[] args)
+        {
+
+            string cmdName = ConsoleHelp.GetArg(args, "-c") ?? ConsoleHelp.GetArg(args, "--command");
+
+            #region (x.1)通过反射获取所有命令            
+            var cmdMap =
+                //获取所有type
+                Assembly.GetEntryAssembly().GetTypes()
+                //获取所有静态函数
+                .SelectMany(type => type.GetMethods(BindingFlags.Static | BindingFlags.Public))
+                //获取指定CommandAttribute的函数
+                .Where(m => m.GetCustomAttribute<CommandAttribute>() != null)
+                //按照 命令名称 和 Method 构建Dictionary 
+                .ToDictionary(
+                  m => (m.GetCustomAttribute<CommandAttribute>().Value ?? m.Name)
+                  , m => m
+                );
+            #endregion
+
+
+            #region (x.2)筛选指定命令
+            if (!string.IsNullOrEmpty(cmdName))
+            {
+                cmdMap.TryGetValue(cmdName, out var cmdMethod);
+
+                cmdMap = new System.Collections.Generic.Dictionary<string, MethodInfo>();
+                if (cmdMethod != null)
+                {
+                    cmdMap[cmdName] = cmdMethod;
+                }
+            }
+            #endregion
+
+            #region (x.3)输出命令帮助文档
+            ConsoleHelp.Log("命令帮助文档:");
+            foreach (var cmd in cmdMap)
+            {
+                ConsoleHelp.Log("---------------");
+                ConsoleHelp.Log(cmd.Key);
+                cmd.Value.GetCustomAttributes<RemarksAttribute>()?.Select(m => m.Value).ToList().ForEach(ConsoleHelp.Log);
+            }
+            ConsoleHelp.Log("---------------");
+            ConsoleHelp.Log("");
+            ConsoleHelp.Log("");
+            #endregion
+
+        }
+        #endregion
+
+    }
+    #endregion
+}

+ 64 - 0
FileZip/Doc/FileZip_Readme.txt

@@ -0,0 +1,64 @@
+ FileZip
+
+
+为net core2.1开发的文件夹工具,包括 文件夹合并、加压(zip) 和 解压(unzip、un7z、unrar)工具
+
+运行环境 dotnet core 2.1
+
+-----------------------------------
+dotnet FileZip.dll
+
+程序会显示使用文档
+
+-----------------
+
+dotnet FileZip.dll marge -i "E:\t 2" -o "E:\t 2.7z"
+
+dotnet FileZip.dll un7z -i "E:\t\m.7z" -o "E:\t\t2"
+
+
+
+
+命令帮助文档:
+---------------
+help
+帮助文档:
+-c[--command] 要查询的命令。若不指定则返回所有命令的文档。如 help
+示例: help -c help
+---------------
+zip
+压缩为gzip文件。参数说明:
+-i[--input] 待压缩目录 例如 "/data/a"
+-o[--output] 压缩后文件名(若不指定,加压到压缩文件夹所在目录),例如 "/data/a.zip"
+示例: zip -i "/data/a" -o "/data/a.zip"
+---------------
+marge
+合并文件。参数说明:
+-i[--input] 待合并的文件夹 或 文件查询字符串。 如 /data/a/1.7z.*
+-o[--output] 合并后文件
+示例: marge -i "/data/a" -o /data/a.7z
+---------------
+un7z
+解压7z文件。参数说明:
+-i[--input] 待解压文件 例如 "/data/a.7z.001"
+-o[--output] 输出目录,(若不指定,则解压到压缩文件所在目录)
+-m[--mute] 若指定,则不输出解压的文件(夹)信息
+-mf[--mutefile] 若指定,则不输出解压的文件信息
+示例: un7z -i "/data/a.7z" -o "/data/out" --mute
+---------------
+unrar
+解压rar文件。参数说明:
+-i[--input] 待解压文件 例如 "/data/a.rar.001"
+-o[--output] 输出目录,(若不指定,则解压到压缩文件所在目录)
+-m[--mute] 若指定,则不输出解压的文件(夹)信息
+-mf[--mutefile] 若指定,则不输出解压的文件信息
+示例: unrar -i "/data/a.rar" -o "/data/out" --mute
+---------------
+unzip
+解压zip文件。参数说明:
+-i[--input] 待解压文件 例如 "/data/a.zip.001"
+-o[--output] 输出目录,(若不指定,则解压到压缩文件所在目录)
+-m[--mute] 若指定,则不输出解压的文件(夹)信息
+-mf[--mutefile] 若指定,则不输出解压的文件信息
+示例: unzip -i "/data/a.zip" -o "/data/out" --mute
+---------------

+ 3 - 0
FileZip/Doc/dotnet_start.bat

@@ -0,0 +1,3 @@
+cd /d FileZip
+dotnet FileZip.dll
+pause

+ 25 - 0
FileZip/FileZip.csproj

@@ -0,0 +1,25 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <OutputType>Exe</OutputType>
+    <TargetFramework>netcoreapp2.1</TargetFramework>
+    <Version>1.2</Version>
+    <Authors>Lith</Authors>
+    <Description>sersms@163.com</Description>
+  </PropertyGroup>
+
+  
+  <ItemGroup>
+    <PackageReference Include="sharpcompress" Version="0.25.1" />  
+  </ItemGroup>
+
+  
+  <ItemGroup>
+    <Folder Include="Doc\" />
+  </ItemGroup>
+
+ 
+
+ 
+
+</Project>

+ 55 - 0
FileZip/Program.cs

@@ -0,0 +1,55 @@
+using System.Collections.Generic;
+using Vit.ConsoleUtil;
+
+namespace Main
+{
+    public class Program
+    {
+        /// <summary> 
+        /// 
+        /// </summary>
+        /// <param name="args"></param>
+        public static void Main(string[] args)
+        {
+
+            //var arg = new List<string>() { "un7z" };
+            //arg.AddRange(new[] { "-i", "T:\\temp\\tileset.7z.001" });
+            //arg.AddRange(new[] { "-o", "T:\\temp\\tileset" });
+            //args = arg.ToArray();
+
+            //var arg = new List<string>() { "unrar" };
+            //arg.AddRange(new[] { "-i", "T:\\temp\\tileset.rar" });
+            //arg.AddRange(new[] { "-o", "T:\\temp\\tileset" });
+            //args = arg.ToArray();
+
+            //var arg = new List<string>() { "unzip" };
+            //arg.AddRange(new[] { "-i", "T:\\temp\\tileset.zip" });
+            //arg.AddRange(new[] { "-o", "T:\\temp\\tileset" });
+            //args = arg.ToArray();
+
+            //var arg = new List<string>() { "zip" };
+            //arg.AddRange(new[] { "-i", "T:\\temp\\tileset" });
+            ////arg.AddRange(new[] { "-o", "T:\\temp\\tileset.zip" });
+            //args = arg.ToArray();
+
+            Vit.ConsoleUtil.ConsoleHelp.Log("[FileZip] version: " + System.Diagnostics.FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetEntryAssembly().Location).FileVersion);
+
+            ConsoleHelp.Exec(args);
+            return;
+        }  
+    }
+
+
+
+
+
+ 
+
+
+
+
+
+}
+
+
+

+ 15 - 0
FileZip/Properties/PublishProfiles/FolderProfile.pubxml

@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+https://go.microsoft.com/fwlink/?LinkID=208121. 
+-->
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <PublishProtocol>FileSystem</PublishProtocol>
+    <Configuration>Release</Configuration>
+    <Platform>Any CPU</Platform>
+    <TargetFramework>netcoreapp2.1</TargetFramework>
+    <PublishDir>bin\FileZip</PublishDir>
+    <SelfContained>false</SelfContained>
+    <_IsPortable>true</_IsPortable>
+  </PropertyGroup>
+</Project>