diff --git a/src/Convert2Lf/Main.cs b/src/Convert2Lf/Main.cs index eb6b801..233020a 100644 --- a/src/Convert2Lf/Main.cs +++ b/src/Convert2Lf/Main.cs @@ -81,7 +81,7 @@ public sealed class Main : Tool, IDisposable _procedCnt += procedCnt; _replaceCnt += replaceCnt; _breakCnt += breakCnt; - _step2Bar.Message = $"已处理:{_procedCnt}/{_totalCnt},替换:{_replaceCnt},跳过:{_breakCnt}"; + _step2Bar.Message = string.Format(Strings.ShowMessageTemp, _procedCnt, _totalCnt, _replaceCnt, _breakCnt); } } @@ -94,16 +94,17 @@ public sealed class Main : Tool, IDisposable [SuppressMessage("ReSharper", "PossibleMultipleEnumeration")] public override void Run() { - if (!Directory.Exists(Opt.Path)) throw new ArgumentException(nameof(Opt.Path), $"指定的路径“{Opt.Path}”不存在"); + if (!Directory.Exists(Opt.Path)) + throw new ArgumentException(nameof(Opt.Path), string.Format(Strings.PathNotFound, Opt.Path)); - using var step1Bar = new IndeterminateProgressBar("查找文件...", DefaultProgressBarOptions); + using var step1Bar = new IndeterminateProgressBar(Strings.SearchingFile, DefaultProgressBarOptions); var fileList = EnumerateFiles(Opt.Path, Opt.Filter); _totalCnt = fileList.Count(); - step1Bar.Message = "查找文件...OK"; + step1Bar.Message = Strings.SearchingFileOK; step1Bar.Finished(); _step2Bar = step1Bar.Spawn(_totalCnt, string.Empty, DefaultProgressBarOptions); diff --git a/src/Convert2Lf/Option.cs b/src/Convert2Lf/Option.cs index 35a84b7..7f3384d 100644 --- a/src/Convert2Lf/Option.cs +++ b/src/Convert2Lf/Option.cs @@ -1,11 +1,4 @@ namespace Dot.Convert2Lf; -[Verb("convert-lf", HelpText = "换行符转换为lf")] -public class Option : IOption -{ - [Option('f', "filter", Required = false, HelpText = "文件通配符", Default = "*.*")] - public string Filter { get; set; } //normal options here - - [Option('p', "path", Required = false, HelpText = "要处理的目录路径", Default = ".")] - public string Path { get; set; } -} \ No newline at end of file +[Verb("convert-lf", HelpText = nameof(Strings.ConvertEndOfLineToLF), ResourceType = typeof(Strings))] +public class Option : DirOption { } \ No newline at end of file diff --git a/src/DirOption.cs b/src/DirOption.cs new file mode 100644 index 0000000..62c3017 --- /dev/null +++ b/src/DirOption.cs @@ -0,0 +1,11 @@ +namespace Dot; + +public class DirOption : IOption +{ + [Option('f', "filter", Required = false, HelpText = nameof(Strings.FileSearchPattern), Default = "*.*" + , ResourceType = typeof(Strings))] + public string Filter { get; set; } + + [Value(0, HelpText = nameof(Strings.FolderPath), Default = ".", ResourceType = typeof(Strings))] + public string Path { get; set; } +} \ No newline at end of file diff --git a/src/GlobalUsings.cs b/src/GlobalUsings.cs index a9e96a1..38b2f93 100644 --- a/src/GlobalUsings.cs +++ b/src/GlobalUsings.cs @@ -1,2 +1,3 @@ global using ShellProgressBar; -global using CommandLine; \ No newline at end of file +global using CommandLine; +global using Dot.Lang; \ No newline at end of file diff --git a/src/Guid/Main.cs b/src/Guid/Main.cs index 7537bc3..0b157ce 100644 --- a/src/Guid/Main.cs +++ b/src/Guid/Main.cs @@ -12,6 +12,6 @@ public sealed class Main : Tool var guid = System.Guid.NewGuid().ToString(); if (Opt.Upper) guid = guid.ToUpper(); ClipboardService.SetText(guid); - Console.WriteLine($"已复制到剪贴板:{guid}"); + Console.WriteLine(Strings.Copied, guid); } } \ No newline at end of file diff --git a/src/Guid/Option.cs b/src/Guid/Option.cs index 0c1c419..44801e2 100644 --- a/src/Guid/Option.cs +++ b/src/Guid/Option.cs @@ -1,8 +1,8 @@ namespace Dot.Guid; -[Verb("guid", HelpText = "GUID工具")] +[Verb("guid", HelpText = nameof(Strings.GuidTool), ResourceType = typeof(Strings))] public class Option : IOption { - [Option('u', "upper", HelpText = "大写", Default = false)] + [Option('u', "upper", HelpText = nameof(Strings.UseUppercase), Default = false, ResourceType = typeof(Strings))] public bool Upper { get; set; } //normal options here } \ No newline at end of file diff --git a/src/Lang/Strings.Designer.cs b/src/Lang/Strings.Designer.cs new file mode 100644 index 0000000..2a141ff --- /dev/null +++ b/src/Lang/Strings.Designer.cs @@ -0,0 +1,224 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Dot.Lang { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + public class Strings { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Strings() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + public static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Dot.Lang.Strings", typeof(Strings).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + public static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to 转换换行符为LF. + /// + public static string ConvertEndOfLineToLF { + get { + return ResourceManager.GetString("ConvertEndOfLineToLF", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to {0}(已复制到剪贴板). + /// + public static string Copied { + get { + return ResourceManager.GetString("Copied", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to 文件通配符. + /// + public static string FileSearchPattern { + get { + return ResourceManager.GetString("FileSearchPattern", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to 要处理的目录路径. + /// + public static string FolderPath { + get { + return ResourceManager.GetString("FolderPath", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to GUID工具. + /// + public static string GuidTool { + get { + return ResourceManager.GetString("GuidTool", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to 文本编码工具. + /// + public static string HelpForText { + get { + return ResourceManager.GetString("HelpForText", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to 要处理的文本(默认取取剪贴板值). + /// + public static string HelpForTextArg0 { + get { + return ResourceManager.GetString("HelpForTextArg0", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to 输入文本为空. + /// + public static string InputTextIsEmpty { + get { + return ResourceManager.GetString("InputTextIsEmpty", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to 指定的路径“{0}”不存在. + /// + public static string PathNotFound { + get { + return ResourceManager.GetString("PathNotFound", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to BitSet 1:[0-9],2:[a-z],4:[A-Z],8:[ascii.0x21-0x2F]. + /// + public static string PwdGenerateTypes { + get { + return ResourceManager.GetString("PwdGenerateTypes", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to 密码长度. + /// + public static string PwdLength { + get { + return ResourceManager.GetString("PwdLength", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to 随机密码生成器. + /// + public static string RandomPasswordGenerator { + get { + return ResourceManager.GetString("RandomPasswordGenerator", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to 移除文件尾部换行和空格. + /// + public static string RemoveTrailingWhiteSpaces { + get { + return ResourceManager.GetString("RemoveTrailingWhiteSpaces", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to 查找文件.... + /// + public static string SearchingFile { + get { + return ResourceManager.GetString("SearchingFile", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to 查找文件...OK. + /// + public static string SearchingFileOK { + get { + return ResourceManager.GetString("SearchingFileOK", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to 已读取:{0}/{1},处理:{2},跳过:{3}. + /// + public static string ShowMessageTemp { + get { + return ResourceManager.GetString("ShowMessageTemp", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to 移除文件的uf8 bom. + /// + public static string TrimUtf8Bom { + get { + return ResourceManager.GetString("TrimUtf8Bom", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to 使用大写输出. + /// + public static string UseUppercase { + get { + return ResourceManager.GetString("UseUppercase", resourceCulture); + } + } + } +} \ No newline at end of file diff --git a/src/Lang/Strings.resx b/src/Lang/Strings.resx new file mode 100644 index 0000000..7dc2879 --- /dev/null +++ b/src/Lang/Strings.resx @@ -0,0 +1,85 @@ + + + + + + + + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, + PublicKeyToken=b77a5c561934e089 + + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, + PublicKeyToken=b77a5c561934e089 + + + + 输入文本为空 + + + 查找文件... + + + 指定的路径“{0}”不存在 + + + 查找文件...OK + + + 已读取:{0}/{1},处理:{2},跳过:{3} + + + 文本编码工具 + + + 要处理的文本(默认取取剪贴板值) + + + {0}(已复制到剪贴板) + + + 文件通配符 + + + 要处理的目录路径 + + + 转换换行符为LF + + + GUID工具 + + + 使用大写输出 + + + 随机密码生成器 + + + + 密码长度 + + + + + BitSet 1:[0-9],2:[a-z],4:[A-Z],8:[ascii.0x21-0x2F] + + + + 移除文件尾部换行和空格 + + + 移除文件的uf8 bom + + \ No newline at end of file diff --git a/src/Random/Main.cs b/src/Pwd/Main.cs similarity index 76% rename from src/Random/Main.cs rename to src/Pwd/Main.cs index ef55cda..7cdf363 100644 --- a/src/Random/Main.cs +++ b/src/Pwd/Main.cs @@ -1,10 +1,9 @@ -using System.Text.RegularExpressions; using NSExt.Extensions; using TextCopy; -namespace Dot.Random; +namespace Dot.Pwd; -public sealed partial class Main : Tool +public sealed class Main : Tool { private readonly char[][] _charTable = { "0123456789".ToCharArray() // @@ -16,18 +15,6 @@ public sealed partial class Main : Tool public Main(Option opt) : base(opt) { } - [GeneratedRegex("[a-z]")] - private static partial Regex RegexLowerCaseLetter(); - - [GeneratedRegex("\\d")] - private static partial Regex RegexNumber(); - - [GeneratedRegex("[^\\da-zA-Z]")] - private static partial Regex RegexSpecialCharacter(); - - [GeneratedRegex("[A-Z]")] - private static partial Regex RegexUpperCaseLetter(); - public override void Run() { unsafe { @@ -60,7 +47,7 @@ public sealed partial class Main : Tool var result = new string(pDest, 0, Opt.Length); ClipboardService.SetText(result); - Console.WriteLine($"已复制到剪贴板:{result}"); + Console.WriteLine(Strings.Copied, result); } } } \ No newline at end of file diff --git a/src/Pwd/Option.cs b/src/Pwd/Option.cs new file mode 100644 index 0000000..80f9558 --- /dev/null +++ b/src/Pwd/Option.cs @@ -0,0 +1,21 @@ +namespace Dot.Pwd; + +[Verb("pwd", HelpText = nameof(Strings.RandomPasswordGenerator), ResourceType = typeof(Strings))] +public class Option : IOption +{ + [Flags] + public enum GenerateTypes + { + Number = 1 + , LowerCaseLetter = 2 + , UpperCaseLetter = 4 + , SpecialCharacter = 8 + } + + [Value(1, Required = true, HelpText = nameof(Strings.PwdLength), ResourceType = typeof(Strings))] + public int Length { get; set; } + + + [Value(0, Required = true, HelpText = nameof(Strings.PwdGenerateTypes), ResourceType = typeof(Strings))] + public GenerateTypes Type { get; set; } +} \ No newline at end of file diff --git a/src/Random/Option.cs b/src/Random/Option.cs deleted file mode 100644 index a1a524f..0000000 --- a/src/Random/Option.cs +++ /dev/null @@ -1,21 +0,0 @@ -namespace Dot.Random; - -[Verb("rand", HelpText = "随机数生成器")] -public class Option : IOption -{ - [Flags] - public enum GenerateTypes - { - Number = 1 - , LowerCaseLetter = 2 - , UpperCaseLetter = 4 - , SpecialCharacter = 8 - } - - [Value(1, MetaName = "长度", Required = true, HelpText = "随机数字长度")] - public int Length { get; set; } - - - [Value(0, MetaName = "生成类型", Required = true, HelpText = "BitSet 1:[0-9],2:[a-z],4:[A-Z],8:[ascii.0x21-0x2F]")] - public GenerateTypes Type { get; set; } -} \ No newline at end of file diff --git a/src/RemoveTrailingWhiteSpace/Main.cs b/src/RemoveTrailingWhiteSpace/Main.cs index 3667008..becca13 100644 --- a/src/RemoveTrailingWhiteSpace/Main.cs +++ b/src/RemoveTrailingWhiteSpace/Main.cs @@ -70,7 +70,7 @@ public sealed class Main : Tool, IDisposable _procedCnt += procedCnt; _replaceCnt += removeCnt; _breakCnt += breakCnt; - _step2Bar.Message = $"已处理:{_procedCnt}/{_totalCnt},替换:{_replaceCnt},跳过:{_breakCnt}"; + _step2Bar.Message = string.Format(Strings.ShowMessageTemp, _procedCnt, _totalCnt, _replaceCnt, _breakCnt); } } @@ -84,16 +84,17 @@ public sealed class Main : Tool, IDisposable [SuppressMessage("ReSharper", "PossibleMultipleEnumeration")] public override void Run() { - if (!Directory.Exists(Opt.Path)) throw new ArgumentException(nameof(Opt.Path), $"指定的路径“{Opt.Path}”不存在"); + if (!Directory.Exists(Opt.Path)) + throw new ArgumentException(nameof(Opt.Path), string.Format(Strings.PathNotFound, Opt.Path)); - using var step1Bar = new IndeterminateProgressBar("查找文件...", DefaultProgressBarOptions); + using var step1Bar = new IndeterminateProgressBar(Strings.SearchingFile, DefaultProgressBarOptions); var fileList = EnumerateFiles(Opt.Path, Opt.Filter); _totalCnt = fileList.Count(); - step1Bar.Message = "查找文件...OK"; + step1Bar.Message = Strings.SearchingFileOK; step1Bar.Finished(); _step2Bar = step1Bar.Spawn(_totalCnt, string.Empty, DefaultProgressBarOptions); diff --git a/src/RemoveTrailingWhiteSpace/Option.cs b/src/RemoveTrailingWhiteSpace/Option.cs index 3cf42c8..4a4ee03 100644 --- a/src/RemoveTrailingWhiteSpace/Option.cs +++ b/src/RemoveTrailingWhiteSpace/Option.cs @@ -1,11 +1,4 @@ namespace Dot.RemoveTrailingWhiteSpace; -[Verb("remove-whitespace", HelpText = "移除文件尾部换行和空格")] -public class Option : IOption -{ - [Option('f', "filter", Required = false, HelpText = "文件通配符", Default = "*.*")] - public string Filter { get; set; } //normal options here - - [Option('p', "path", Required = false, HelpText = "要处理的目录路径", Default = ".")] - public string Path { get; set; } -} \ No newline at end of file +[Verb("remove-whitespace", HelpText = nameof(Strings.RemoveTrailingWhiteSpaces), ResourceType = typeof(Strings))] +public class Option : DirOption { } \ No newline at end of file diff --git a/src/Text/Main.cs b/src/Text/Main.cs index b84dd1a..8d9d3ed 100644 --- a/src/Text/Main.cs +++ b/src/Text/Main.cs @@ -28,7 +28,7 @@ public sealed class Main : Tool public Main(Option opt) : base(opt) { if (Opt.Text.NullOrEmpty()) Opt.Text = ClipboardService.GetText(); - if (Opt.Text.NullOrEmpty()) throw new ArgumentException("输入文本为空"); + if (Opt.Text.NullOrEmpty()) throw new ArgumentException(Strings.InputTextIsEmpty); } private static Output BuildOutput(string text, Encoding enc) diff --git a/src/Text/Option.cs b/src/Text/Option.cs index 3ce844b..caa3109 100644 --- a/src/Text/Option.cs +++ b/src/Text/Option.cs @@ -1,8 +1,8 @@ namespace Dot.Text; -[Verb("text", HelpText = "文本编码工具")] +[Verb("text", HelpText = nameof(Strings.HelpForText), ResourceType = typeof(Strings))] public class Option : IOption { - [Value(0, MetaName = "文本", HelpText = "要处理的文本,不指定此参数:取剪贴板值")] + [Value(0, HelpText = nameof(Strings.HelpForTextArg0), ResourceType = typeof(Strings))] public string Text { get; set; } } \ No newline at end of file diff --git a/src/Tool.cs b/src/Tool.cs index ff4641c..e9ff1c7 100644 --- a/src/Tool.cs +++ b/src/Tool.cs @@ -12,7 +12,7 @@ public abstract class Tool : ITool , BackgroundCharacter = '\u2593' }; - protected virtual TOption Opt { get; set; } + protected TOption Opt { get; set; } protected Tool(TOption opt) { diff --git a/src/ToolsFactory.cs b/src/ToolsFactory.cs index b02ca76..2993e51 100644 --- a/src/ToolsFactory.cs +++ b/src/ToolsFactory.cs @@ -10,7 +10,7 @@ public static class ToolsFactory Option o => new Main(o) , Convert2Lf.Option o => new Convert2Lf.Main(o) , RemoveTrailingWhiteSpace.Option o => new RemoveTrailingWhiteSpace.Main(o) - , Random.Option o => new Random.Main(o) + , Pwd.Option o => new Pwd.Main(o) , Text.Option o => new Text.Main(o) , Guid.Option o => new Guid.Main(o) , _ => throw new ArgumentOutOfRangeException(nameof(option)) diff --git a/src/TrimUtf8Bom/Main.cs b/src/TrimUtf8Bom/Main.cs index 93dc51f..774380a 100644 --- a/src/TrimUtf8Bom/Main.cs +++ b/src/TrimUtf8Bom/Main.cs @@ -33,7 +33,7 @@ public sealed class Main : Tool, IDisposable _procedCnt += procedCnt; _trimCnt += replaceCnt; _breakCnt += breakCnt; - _step2Bar.Message = $"已处理:{_procedCnt}/{_totalCnt},移除BOM:{_trimCnt},跳过:{_breakCnt}"; + _step2Bar.Message = string.Format(Strings.ShowMessageTemp, _procedCnt, _totalCnt, _trimCnt, _breakCnt); } } @@ -46,17 +46,18 @@ public sealed class Main : Tool, IDisposable [SuppressMessage("ReSharper", "PossibleMultipleEnumeration")] public override void Run() { - if (!Directory.Exists(Opt.Path)) throw new ArgumentException(nameof(Opt.Path), $"指定的路径“{Opt.Path}”不存在"); + if (!Directory.Exists(Opt.Path)) + throw new ArgumentException(nameof(Opt.Path), string.Format(Strings.PathNotFound, Opt.Path)); var utf8Bom = new byte[] { 0xef, 0xbb, 0xbf }; - using var step1Bar = new IndeterminateProgressBar("查找文件...", DefaultProgressBarOptions); + using var step1Bar = new IndeterminateProgressBar(Strings.SearchingFile, DefaultProgressBarOptions); var fileList = EnumerateFiles(Opt.Path, Opt.Filter); _totalCnt = fileList.Count(); - step1Bar.Message = "查找文件...OK"; + step1Bar.Message = Strings.SearchingFileOK; step1Bar.Finished(); _step2Bar = step1Bar.Spawn(_totalCnt, string.Empty, DefaultProgressBarOptions); diff --git a/src/TrimUtf8Bom/Option.cs b/src/TrimUtf8Bom/Option.cs index 390aa98..2119fce 100644 --- a/src/TrimUtf8Bom/Option.cs +++ b/src/TrimUtf8Bom/Option.cs @@ -1,11 +1,4 @@ namespace Dot.TrimUtf8Bom; -[Verb("trim-utf8-bom", HelpText = "移除文件的uf8 bom")] -public class Option : IOption -{ - [Option('f', "filter", Required = false, HelpText = "文件通配符", Default = "*.*")] - public string Filter { get; set; } //normal options here - - [Option('p', "path", Required = false, HelpText = "要处理的目录路径", Default = ".")] - public string Path { get; set; } -} \ No newline at end of file +[Verb("trim-utf8-bom", HelpText = nameof(Strings.TrimUtf8Bom), ResourceType = typeof(Strings))] +public class Option : DirOption { } \ No newline at end of file diff --git a/src/dot.csproj b/src/dot.csproj index b168f25..4a362a0 100644 --- a/src/dot.csproj +++ b/src/dot.csproj @@ -11,7 +11,7 @@ Copyright (c) 2022 nsnail https://github.com/nsnail/dot.git git - 功能全面的实用工具-程序员的瑞士军刀 + 功能全面的实用工具 - 程序员的瑞士军刀 @@ -29,4 +29,19 @@ + + + PublicResXFileCodeGenerator + Strings.Designer.cs + + + + + + True + True + Strings.resx + + + \ No newline at end of file