diff --git a/.editorconfig b/.editorconfig index 9c1d16a..d54638d 100644 --- a/.editorconfig +++ b/.editorconfig @@ -13,14 +13,20 @@ trim_trailing_whitespace = true [*.cs] dotnet_analyzer_diagnostic.severity = warning dotnet_diagnostic.CA1707.severity = none +dotnet_diagnostic.CA1716.severity = none +dotnet_diagnostic.CA1848.severity = none +dotnet_diagnostic.CA2254.severity = none dotnet_diagnostic.CA5350.severity = none dotnet_diagnostic.CA5351.severity = none +dotnet_diagnostic.IDE0005.severity = none dotnet_diagnostic.IDE0008.severity = none +dotnet_diagnostic.IDE0010.severity = none dotnet_diagnostic.IDE0017.severity = none dotnet_diagnostic.IDE0048.severity = none dotnet_diagnostic.IDE0055.severity = none dotnet_diagnostic.IDE0058.severity = none dotnet_diagnostic.IDE0160.severity = none +dotnet_diagnostic.SYSLIB1045.severity = none # ReSharper properties diff --git a/.gitignore b/.gitignore index 85e7030..9865879 100644 --- a/.gitignore +++ b/.gitignore @@ -29,7 +29,7 @@ x86/ bld/ [Bb]in/ [Oo]bj/ -[Ll]og/ +# [Ll]og/ [Ll]ogs/ # Visual Studio 2015/2017 cache/options directory @@ -399,6 +399,6 @@ FodyWeavers.xsd .idea/ # User Define -build/ +dist/ nuget.config *.[Dd]esigner.cs \ No newline at end of file diff --git a/CodeCleanupOnSave.csx b/CodeCleanupOnSave.csx index d0c39a5..7dcefb9 100644 --- a/CodeCleanupOnSave.csx +++ b/CodeCleanupOnSave.csx @@ -1,16 +1,27 @@ +#r "nuget: Newtonsoft.Json, 13.0.0" + +using System.Xml; +using System.IO; +using Newtonsoft.Json.Linq; + var path = Directory.GetFiles(@".idea", "workspace.xml", SearchOption.AllDirectories).First(); - const string findStr = """ -"keyToString": { -"""; - const string replaceStr = """ -"keyToString": { - "rider.code.cleanup.on.save": "true", -"""; - var content = File.ReadAllText(path); - if(content.Contains("rider.code.cleanup.on.save")){ - Console.WriteLine("alreay added"); - return; - } - content = content.Replace(findStr, replaceStr); - Console.WriteLine(content); - File.WriteAllText(path, content); \ No newline at end of file +XmlDocument xdoc = new XmlDocument(); +using(var fs = File.Open(path, FileMode.Open)){ + xdoc.Load(fs); + fs.Seek(0, SeekOrigin.Begin); + var propertiesComponent = xdoc.SelectSingleNode("""//component[@name="PropertiesComponent"]"""); + var jsonStr = propertiesComponent.InnerText; + var jsonObj = JObject.Parse(jsonStr); + var keyToStringObj = jsonObj["keyToString"] as JObject; + if (keyToStringObj.ContainsKey("rider.code.cleanup.on.save")) return; + + keyToStringObj.Add(new JProperty("rider.code.cleanup.on.save", "true")); + var newNode = xdoc.CreateCDataSection(jsonObj.ToString()); + propertiesComponent.InnerText=string.Empty; + propertiesComponent.AppendChild(newNode); + var settings = new XmlWriterSettings { Indent = true }; + using(var writer = XmlWriter.Create(fs, settings)){ + xdoc.WriteTo(writer); + } + +} \ No newline at end of file diff --git a/CodeQuality.props b/CodeQuality.props index df0775d..2c63bb2 100644 --- a/CodeQuality.props +++ b/CodeQuality.props @@ -13,5 +13,9 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive + + + + \ No newline at end of file diff --git a/Directory.Build.props b/Directory.Build.props index 54e6a10..186e24a 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,10 +1,26 @@ - enable - ../dist + nsnail ../dist - $(BaseOutputPath)/$(MSBuildProjectName)/bin + ../dist + © 2006-2023 nsnail + 功能全面的实用工具 - 程序员的瑞士军刀 + false + true + enable $(BaseIntermediateOutputPath)/$(MSBuildProjectName)/obj $(BaseIntermediateOutputPath)/$(MSBuildProjectName)/obj + $(BaseOutputPath)/$(MSBuildProjectName)/bin + dot + git + https://github.com/nsnail/dot.git + Dot + $(AssemblyName) + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + \ No newline at end of file diff --git a/GenerateResx.targets b/GenerateResx.targets index e2769a2..b392ded 100644 --- a/GenerateResx.targets +++ b/GenerateResx.targets @@ -1,9 +1,9 @@ - - + + - - + + \ No newline at end of file diff --git a/StyleCopAnalyzers.ruleset b/StyleCopAnalyzers.ruleset index f89a00e..2a53f74 100644 --- a/StyleCopAnalyzers.ruleset +++ b/StyleCopAnalyzers.ruleset @@ -3,219 +3,211 @@ Description="StyleCop.Analyzers with default action. Rules with IsEnabledByDefault = false are disabled." ToolsVersion="14.0"> - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/AddMetaFilesToSln.csx b/SyncMetaFiles.csx similarity index 94% rename from AddMetaFilesToSln.csx rename to SyncMetaFiles.csx index b378f00..887689a 100644 --- a/AddMetaFilesToSln.csx +++ b/SyncMetaFiles.csx @@ -6,7 +6,7 @@ var slnFile = Directory.GetFiles(@".", "*.sln").First(); $""" ProjectSection(SolutionItems) = preProject {string.Join('\n', - Directory.GetFiles(@".", "*").Where(x => !x.EndsWith(".sln")) + Directory.GetFiles(@".", "*").Where(x => !x.EndsWith(".sln") && !x.EndsWith(".user")) .Select(x=>$"\t\t{Path.GetFileName(x)} = {Path.GetFileName(x)}"))} {'\t'}EndProjectSection """); diff --git a/dot.sln b/dot.sln index d73e0c9..77ed431 100644 --- a/dot.sln +++ b/dot.sln @@ -11,7 +11,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "meta", "meta", "{AD79881E-7 .gitattributes = .gitattributes .gitignore = .gitignore .tgitconfig = .tgitconfig - AddMetaFilesToSln.csx = AddMetaFilesToSln.csx build.cake = build.cake code-format.cmd = code-format.cmd CodeCleanupOnSave.csx = CodeCleanupOnSave.csx @@ -31,7 +30,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "meta", "meta", "{AD79881E-7 StyleCopAnalyzers.ruleset = StyleCopAnalyzers.ruleset switch-nuget.cmd = switch-nuget.cmd switch-project.cmd = switch-project.cmd - switcher.json = switcher.json + switcher.nsext.json = switcher.nsext.json + SyncMetaFiles.csx = SyncMetaFiles.csx EndProjectSection EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "tests", "tests\tests.csproj", "{15EF00AD-DFA8-4BE2-985E-85DA8092CB2F}" diff --git a/dot.sln.DotSettings b/dot.sln.DotSettings index e0c09a2..57d85a0 100644 --- a/dot.sln.DotSettings +++ b/dot.sln.DotSettings @@ -1,4 +1,10 @@ + DO_NOT_SHOW + DO_NOT_SHOW + NEVER + NEVER + NEVER + NEVER False 1 1 diff --git a/src/Color/Main.cs b/src/Color/Main.cs index afe4575..a22e437 100644 --- a/src/Color/Main.cs +++ b/src/Color/Main.cs @@ -4,8 +4,8 @@ using System.Runtime.Versioning; namespace Dot.Color; -[Description(nameof(Str.ScreenPixelTool))] -[Localization(typeof(Str))] +[Description(nameof(Ln.ScreenPixelTool))] +[Localization(typeof(Ln))] [SupportedOSPlatform(nameof(OSPlatform.Windows))] // ReSharper disable once ClassNeverInstantiated.Global diff --git a/src/Color/WinInfo.cs b/src/Color/WinInfo.cs index fd157bc..ff6eb7b 100644 --- a/src/Color/WinInfo.cs +++ b/src/Color/WinInfo.cs @@ -9,30 +9,30 @@ namespace Dot.Color; [SupportedOSPlatform(nameof(OSPlatform.Windows))] internal sealed class WinInfo : Form { - private const int _WINDOW_SIZE = 480; //窗口大小 - private const int _ZOOM_RATE = 16; //缩放倍率 + private const int _WINDOW_SIZE = 480; // 窗口大小 + private const int _ZOOM_RATE = 16; // 缩放倍率 private readonly Graphics _graphics; private readonly PictureBox _pbox; private bool _disposed; public WinInfo() { - FormBorderStyle = FormBorderStyle.None; - TopMost = true; - MinimizeBox = false; - MaximizeBox = false; - Size = new Size(_WINDOW_SIZE, _WINDOW_SIZE); - StartPosition = FormStartPosition.Manual; - Location = new Point(0, 0); - _pbox = new PictureBox(); - _pbox.Location = new Point(0, 0); - _pbox.Size = Size; - _pbox.Image = new Bitmap(_WINDOW_SIZE, _WINDOW_SIZE); - _graphics = Graphics.FromImage(_pbox.Image); - _graphics.InterpolationMode = InterpolationMode.NearestNeighbor; //指定最临近插值法,禁止平滑缩放(模糊) - _graphics.CompositingQuality = CompositingQuality.HighQuality; - _graphics.SmoothingMode = SmoothingMode.None; - _pbox.MouseEnter += PboxOnMouseEnter; + FormBorderStyle = FormBorderStyle.None; + TopMost = true; + MinimizeBox = false; + MaximizeBox = false; + Size = new Size(_WINDOW_SIZE, _WINDOW_SIZE); + StartPosition = FormStartPosition.Manual; + Location = new Point(0, 0); + _pbox = new PictureBox(); + _pbox.Location = new Point(0, 0); + _pbox.Size = Size; + _pbox.Image = new Bitmap(_WINDOW_SIZE, _WINDOW_SIZE); + _graphics = Graphics.FromImage(_pbox.Image); + _graphics.InterpolationMode = InterpolationMode.NearestNeighbor; // 指定最临近插值法,禁止平滑缩放(模糊) + _graphics.CompositingQuality = CompositingQuality.HighQuality; + _graphics.SmoothingMode = SmoothingMode.None; + _pbox.MouseEnter += PboxOnMouseEnter; Controls.Add(_pbox); } @@ -46,13 +46,13 @@ internal sealed class WinInfo : Form // 计算复制小图的区域 var copySize = new Size(_WINDOW_SIZE / _ZOOM_RATE, _WINDOW_SIZE / _ZOOM_RATE); _graphics.DrawImage(img, new Rectangle(0, 0, _WINDOW_SIZE, _WINDOW_SIZE) // - , x - copySize.Width / 2 // 左移x,使光标位置居中 - , y - copySize.Height / 2 // 上移y,使光标位置居中 - , copySize.Width, copySize.Height, GraphicsUnit.Pixel); - using var pen = new Pen(System.Drawing.Color.Aqua); //绘制准星 + , x - copySize.Width / 2 // 左移x,使光标位置居中 + , y - copySize.Height / 2 // 上移y,使光标位置居中 + , copySize.Width, copySize.Height, GraphicsUnit.Pixel); + using var pen = new Pen(System.Drawing.Color.Aqua); // 绘制准星 _graphics.DrawRectangle(pen, _WINDOW_SIZE / 2 - _ZOOM_RATE / 2 // - , _WINDOW_SIZE / 2 - _ZOOM_RATE / 2 // - , _ZOOM_RATE, _ZOOM_RATE); + , _WINDOW_SIZE / 2 - _ZOOM_RATE / 2 // + , _ZOOM_RATE, _ZOOM_RATE); // 取鼠标位置颜色 var posColor = img.GetPixel(x, y); @@ -60,9 +60,9 @@ internal sealed class WinInfo : Form // 绘制底部文字信息 _graphics.FillRectangle(Brushes.Black, 0, _WINDOW_SIZE - 30, _WINDOW_SIZE, 30); _graphics.DrawString( // - $"{Str.ClickCopyColor} X: {x} Y: {y} RGB({posColor.R},{posColor.G},{posColor.B})" - , new Font(FontFamily.GenericSerif, 10) // - , Brushes.White, 0, _WINDOW_SIZE - 20); + $"{Ln.ClickCopyColor} X: {x} Y: {y} RGB({posColor.R},{posColor.G},{posColor.B})" + , new Font(FontFamily.GenericSerif, 10) // + , Brushes.White, 0, _WINDOW_SIZE - 20); // 触发重绘 _pbox.Refresh(); diff --git a/src/Color/WinMain.cs b/src/Color/WinMain.cs index 82c5d76..908579c 100644 --- a/src/Color/WinMain.cs +++ b/src/Color/WinMain.cs @@ -10,7 +10,7 @@ namespace Dot.Color; internal sealed class WinMain : Form { private readonly Bitmap _bmp; - private readonly WinInfo _winInfo = new(); //小图窗口 + private readonly WinInfo _winInfo = new(); // 小图窗口 private bool _disposed; @@ -20,11 +20,11 @@ internal sealed class WinMain : Form Win32.ShowWindow(Win32.GetConsoleWindow(), Win32.SW_HIDE); FormBorderStyle = FormBorderStyle.None; - Size = Screen.PrimaryScreen!.Bounds.Size; - StartPosition = FormStartPosition.Manual; - Location = new Point(0, 0); - Opacity = 0.01d; //主窗体加载截图过程设置为透明避免闪烁 - _bmp = new Bitmap(Size.Width, Size.Height); + Size = Screen.PrimaryScreen!.Bounds.Size; + StartPosition = FormStartPosition.Manual; + Location = new Point(0, 0); + Opacity = 0.01d; // 主窗体加载截图过程设置为透明避免闪烁 + _bmp = new Bitmap(Size.Width, Size.Height); using var g = Graphics.FromImage(_bmp); g.CopyFromScreen(0, 0, 0, 0, Size); } diff --git a/src/DirOption.cs b/src/DirOption.cs index ffac2fc..830bbe3 100644 --- a/src/DirOption.cs +++ b/src/DirOption.cs @@ -5,31 +5,31 @@ namespace Dot; internal class DirOption : OptionBase { [CommandOption("-e|--exclude")] - [Description(nameof(Str.ExcludePathRegexes))] - [Localization(typeof(Str))] + [Description(nameof(Ln.ExcludePathRegexes))] + [Localization(typeof(Ln))] public IEnumerable ExcludeRegexes { get; set; } [CommandOption("-f|--filter")] - [Description(nameof(Str.FileSearchPattern))] - [Localization(typeof(Str))] + [Description(nameof(Ln.FileSearchPattern))] + [Localization(typeof(Ln))] [DefaultValue("*")] public string Filter { get; set; } [CommandOption("-d|--max-depth")] - [Description(nameof(Str.MaxRecursionDepth))] - [Localization(typeof(Str))] + [Description(nameof(Ln.MaxRecursionDepth))] + [Localization(typeof(Ln))] [DefaultValue(int.MaxValue)] public int MaxRecursionDepth { get; set; } [CommandArgument(0, "[path]")] - [Description(nameof(Str.FolderPath))] - [Localization(typeof(Str))] + [Description(nameof(Ln.FolderPath))] + [Localization(typeof(Ln))] [DefaultValue(".")] public string Path { get; set; } [CommandOption("-w|--write")] - [Description(nameof(Str.WriteMode))] - [Localization(typeof(Str))] + [Description(nameof(Ln.WriteMode))] + [Localization(typeof(Ln))] [DefaultValue(false)] public bool WriteMode { get; set; } } \ No newline at end of file diff --git a/src/FilesTool.cs b/src/FilesTool.cs index b512d81..5a0d32a 100644 --- a/src/FilesTool.cs +++ b/src/FilesTool.cs @@ -10,14 +10,14 @@ internal abstract class FilesTool : ToolBase where TOption : DirOption { // ReSharper disable once StaticMemberInGenericType - private static readonly object _lock = new(); //线程锁 - private readonly ConcurrentDictionary _writeStats = new(); //写入统计:后缀,数量 - private int _breakCnt; //跳过文件数 - private ProgressTask _childTask; //子任务进度 - private int _excludeCnt; //排除文件数 - private int _readCnt; //读取文件数 - private int _totalCnt; //总文件数 - private int _writeCnt; //写入文件数 + private static readonly object _lock = new(); // 线程锁 + private readonly ConcurrentDictionary _writeStats = new(); // 写入统计:后缀,数量 + private int _breakCnt; // 跳过文件数 + private ProgressTask _childTask; // 子任务进度 + private int _excludeCnt; // 排除文件数 + private int _readCnt; // 读取文件数 + private int _totalCnt; // 总文件数 + private int _writeCnt; // 写入文件数 protected static FileStream CreateTempFile(out string file) { @@ -52,7 +52,7 @@ internal abstract class FilesTool : ToolBase { return !Directory.Exists(Opt.Path) ? throw new ArgumentException( // - nameof(Opt.Path), string.Format(CultureInfo.InvariantCulture, Str.PathNotFound, Opt.Path)) + nameof(Opt.Path), string.Format(CultureInfo.InvariantCulture, Ln.PathNotFound, Opt.Path)) : CoreInternal(); } @@ -69,7 +69,7 @@ internal abstract class FilesTool : ToolBase } _childTask.Description - = $"{Str.Read}: [green]{_readCnt}[/]/{_totalCnt}, {Str.Write}: [red]{_writeCnt}[/], {Str.Break}: [gray]{_breakCnt}[/], {Str.Exclude}: [yellow]{_excludeCnt}[/]"; + = $"{Ln.Read}: [green]{_readCnt}[/]/{_totalCnt}, {Ln.Write}: [red]{_writeCnt}[/], {Ln.Break}: [gray]{_breakCnt}[/], {Ln.Exclude}: [yellow]{_excludeCnt}[/]"; } } @@ -81,7 +81,7 @@ internal abstract class FilesTool : ToolBase private async Task CoreInternal() { if (!Opt.WriteMode) { - AnsiConsole.MarkupLine(CultureInfo.InvariantCulture, "[gray]{0}[/]", Str.ExerciseMode); + AnsiConsole.MarkupLine(CultureInfo.InvariantCulture, "[gray]{0}[/]", Ln.ExerciseMode); } IEnumerable fileList; @@ -93,7 +93,7 @@ internal abstract class FilesTool : ToolBase , new SpinnerColumn() // , new TaskDescriptionColumn { Alignment = Justify.Left }) // .StartAsync(async ctx => { - var taskSearchfile = ctx.AddTask(Str.SearchingFile).IsIndeterminate(); + var taskSearchfile = ctx.AddTask(Ln.SearchingFile).IsIndeterminate(); _childTask = ctx.AddTask("-/-", false); fileList = EnumerateFiles(Opt.Path, Opt.Filter, out _excludeCnt); _totalCnt = fileList.Count(); @@ -111,7 +111,7 @@ internal abstract class FilesTool : ToolBase _ = grid.AddRow(kv.Key, kv.Value.ToString(CultureInfo.InvariantCulture)); } - AnsiConsole.Write(new Panel(grid).Header(Str.WriteFileStats)); + AnsiConsole.Write(new Panel(grid).Header(Ln.WriteFileStats)); } // ReSharper disable once ReturnTypeCanBeEnumerable.Local @@ -119,7 +119,7 @@ internal abstract class FilesTool : ToolBase { var exCnt = 0; - //默认排除.git 、 node_modules 目录 + // 默认排除.git 、 node_modules 目录 if (Opt.ExcludeRegexes?.FirstOrDefault() is null) { Opt.ExcludeRegexes = new[] { @"\.git", "node_modules" }; } diff --git a/src/Get/Main.cs b/src/Get/Main.cs index 07f4d07..cebf001 100644 --- a/src/Get/Main.cs +++ b/src/Get/Main.cs @@ -6,8 +6,8 @@ using NSExt.Extensions; namespace Dot.Get; -[Description(nameof(Str.DownloadTool))] -[Localization(typeof(Str))] +[Description(nameof(Ln.DownloadTool))] +[Localization(typeof(Ln))] internal sealed partial class Main : ToolBase