From c6facb89df5683b8324a456e60744f5c1198e5f0 Mon Sep 17 00:00:00 2001 From: tk Date: Tue, 6 Jun 2023 16:53:37 +0800 Subject: [PATCH] clean --- .editorconfig | 23 +++-- .gitignore | 4 +- .tgitconfig | 2 +- CodeCleanupOnSave.csx | 27 ------ CodeQuality.props | 22 ++++- CopyPackageXmlCommentFiles.targets | 10 +++ Directory.Build.props | 10 +-- ImageOptimize.csx | 90 +++++++++++-------- NuGet.Config | 9 ++ ResharperCodeClean.csx | 44 ++++++++++ SafetyDelUnusedResx.ahk | 17 ---- StyleCopAnalyzers.ruleset | 4 +- SyncMetaFiles.csx | 15 ++-- code-format.cmd => dot-clean.cmd | 0 dot.sln | 13 +-- dot.sln.DotSettings | 14 ++- dotnet-tools.json | 36 ++++++-- global.json | 16 ++-- package.json | 12 +++ resharper-clean-full.cmd | 1 + resharper-clean.ps1 | 4 + src/Color/Main.cs | 2 +- src/Color/WinInfo.cs | 50 +++++------ src/Color/WinMain.cs | 12 +-- src/CsxEditor.cs | 6 +- src/DirOption.cs | 2 +- src/FilesTool.cs | 32 +++---- src/Get/Main.cs | 72 ++++++++-------- src/Git/Main.cs | 29 +++---- src/Git/TaskStatusColumn.cs | 10 +-- src/Guid/Main.cs | 2 +- src/IP/Main.cs | 8 +- src/Json/Main.cs | 25 +++--- src/Languages/Ln.en-US.resx | 2 +- src/Native/KeyboardHook.cs | 4 +- src/Native/MouseHook.cs | 8 +- src/Native/VkCode.cs | 4 +- src/Native/Win32.cs | 6 +- src/Pwd/Main.cs | 2 +- src/Pwd/Option.cs | 9 +- src/Rbom/Main.cs | 2 +- src/Text/Main.cs | 79 ++++++++--------- src/Time/Main.cs | 22 ++--- src/Time/TaskStatusColumn.cs | 10 +-- src/ToLf/Main.cs | 4 +- src/ToolBase.cs | 8 +- src/Tran/BaiduSignCracker.cs | 5 +- src/Tran/Dto/BaiduTranslateResultDto.cs | 4 + src/Tran/Main.cs | 6 +- src/Tran/WinMain.cs | 109 ++++++++++++------------ src/Trim/Main.cs | 2 +- src/dot.csproj | 6 +- stylecop.json | 13 +-- switch-nuget.cmd | 2 - switch-project.cmd | 2 - switcher.nsext.json | 8 -- tests/tests.csproj | 8 +- 57 files changed, 534 insertions(+), 414 deletions(-) delete mode 100644 CodeCleanupOnSave.csx create mode 100644 CopyPackageXmlCommentFiles.targets create mode 100644 NuGet.Config create mode 100644 ResharperCodeClean.csx delete mode 100644 SafetyDelUnusedResx.ahk rename code-format.cmd => dot-clean.cmd (100%) create mode 100644 package.json create mode 100644 resharper-clean-full.cmd create mode 100644 resharper-clean.ps1 delete mode 100644 switch-nuget.cmd delete mode 100644 switch-project.cmd delete mode 100644 switcher.nsext.json diff --git a/.editorconfig b/.editorconfig index d54638d..f49270b 100644 --- a/.editorconfig +++ b/.editorconfig @@ -10,22 +10,33 @@ indent_style = space insert_final_newline = false trim_trailing_whitespace = true +[{*.json,*.yml}] +indent_size = 2 + [*.cs] dotnet_analyzer_diagnostic.severity = warning +dotnet_diagnostic.CA1200.severity = none 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.IDE0270.severity = none +dotnet_diagnostic.RCS1123.severity = none +dotnet_diagnostic.RCS1141.severity = none +dotnet_diagnostic.RCS1142.severity = none +dotnet_diagnostic.RCS1181.severity = none +dotnet_diagnostic.RCS1186.severity = none +dotnet_diagnostic.S101.severity = none +dotnet_diagnostic.S1075.severity = none +dotnet_diagnostic.S1199.severity = none +dotnet_diagnostic.S125.severity = none +dotnet_diagnostic.S2094.severity = none +dotnet_diagnostic.S3925.severity = none +dotnet_diagnostic.S4663.severity = none dotnet_diagnostic.SYSLIB1045.severity = none diff --git a/.gitignore b/.gitignore index 9865879..4425a13 100644 --- a/.gitignore +++ b/.gitignore @@ -400,5 +400,5 @@ FodyWeavers.xsd # User Define dist/ -nuget.config -*.[Dd]esigner.cs \ No newline at end of file +*.[Dd]esigner.cs +*.db \ No newline at end of file diff --git a/.tgitconfig b/.tgitconfig index 380a28a..a5035e7 100644 --- a/.tgitconfig +++ b/.tgitconfig @@ -1,4 +1,4 @@ [hook "startcommit"] - cmdline = code-format.cmd + cmdline = dot-clean.cmd wait = true show = true \ No newline at end of file diff --git a/CodeCleanupOnSave.csx b/CodeCleanupOnSave.csx deleted file mode 100644 index 7dcefb9..0000000 --- a/CodeCleanupOnSave.csx +++ /dev/null @@ -1,27 +0,0 @@ -#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(); -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 2c63bb2..e3f6f0a 100644 --- a/CodeQuality.props +++ b/CodeQuality.props @@ -1,6 +1,6 @@ - ../StyleCopAnalyzers.ruleset + $(SolutionDir)/StyleCopAnalyzers.ruleset true true true @@ -13,6 +13,26 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/CopyPackageXmlCommentFiles.targets b/CopyPackageXmlCommentFiles.targets new file mode 100644 index 0000000..5f7a4f5 --- /dev/null +++ b/CopyPackageXmlCommentFiles.targets @@ -0,0 +1,10 @@ + + + + + + + + \ No newline at end of file diff --git a/Directory.Build.props b/Directory.Build.props index 186e24a..1b5418a 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,16 +1,16 @@ + + $(MSBuildThisFileDirectory) nsnail - ../dist - ../dist + $(SolutionDir)/dist + $(SolutionDir)/dist © 2006-2023 nsnail 功能全面的实用工具 - 程序员的瑞士军刀 false true enable - $(BaseIntermediateOutputPath)/$(MSBuildProjectName)/obj - $(BaseIntermediateOutputPath)/$(MSBuildProjectName)/obj - $(BaseOutputPath)/$(MSBuildProjectName)/bin + beta dot git https://github.com/nsnail/dot.git diff --git a/ImageOptimize.csx b/ImageOptimize.csx index 8e6aca7..ccbbeaa 100644 --- a/ImageOptimize.csx +++ b/ImageOptimize.csx @@ -4,42 +4,62 @@ * */ - var files = Directory.EnumerateFiles(".", "*.png" - , new EnumerationOptions { - RecurseSubdirectories = true - , AttributesToSkip = FileAttributes.ReparsePoint - , IgnoreInaccessible = true - }) - .ToArray(); +var files = Directory + .EnumerateFiles( + ".", + "*.png", + new EnumerationOptions + { + RecurseSubdirectories = true, + AttributesToSkip = FileAttributes.ReparsePoint, + IgnoreInaccessible = true + } + ) + .ToArray(); - Parallel.ForEach(files, file => { - var startInfo = new ProcessStartInfo { - FileName = "pngquant" - , Arguments - = $"\"{file}\" --force --output \"{file}\" --skip-if-larger" - }; - using var p = Process.Start(startInfo); - p.WaitForExit(); - Console.WriteLine($"{file}: {p.ExitCode}"); - }); +Parallel.ForEach( + files, + file => + { + var startInfo = new ProcessStartInfo + { + FileName = "pngquant", + Arguments = $"\"{file}\" --force --output \"{file}\" --skip-if-larger" + }; + using var p = Process.Start(startInfo); + p.WaitForExit(); + Console.WriteLine($"{file}: {p.ExitCode}"); + } +); - files = new[] { "*.jpg", "*.jpeg" } - .SelectMany(x => Directory.EnumerateFiles( - ".", x - , new EnumerationOptions { - RecurseSubdirectories = true - , AttributesToSkip = FileAttributes.ReparsePoint - , IgnoreInaccessible = true - })) - .ToArray(); +files = new[] { "*.jpg", "*.jpeg" } + .SelectMany( + x => + Directory.EnumerateFiles( + ".", + x, + new EnumerationOptions + { + RecurseSubdirectories = true, + AttributesToSkip = FileAttributes.ReparsePoint, + IgnoreInaccessible = true + } + ) + ) + .ToArray(); - Parallel.ForEach(files, file => { - var startInfo = new ProcessStartInfo { - FileName = "jpegtran" - , Arguments = $"-copy none -optimize -perfect \"{file}\" \"{file}\"" - }; - using var p = Process.Start(startInfo); - p.WaitForExit(); - Console.WriteLine($"{file}: {p.ExitCode}"); - }); \ No newline at end of file +Parallel.ForEach( + files, + file => + { + var startInfo = new ProcessStartInfo + { + FileName = "jpegtran", + Arguments = $"-copy none -optimize -perfect \"{file}\" \"{file}\"" + }; + using var p = Process.Start(startInfo); + p.WaitForExit(); + Console.WriteLine($"{file}: {p.ExitCode}"); + } +); \ No newline at end of file diff --git a/NuGet.Config b/NuGet.Config new file mode 100644 index 0000000..cf3bdd8 --- /dev/null +++ b/NuGet.Config @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/ResharperCodeClean.csx b/ResharperCodeClean.csx new file mode 100644 index 0000000..622b86a --- /dev/null +++ b/ResharperCodeClean.csx @@ -0,0 +1,44 @@ +using System.Text.RegularExpressions; +using System.Net.Http; +using System.Net.Http.Json; + + +{ + var files = string.Join( + ';', + Args[0] + .Split('\n', StringSplitOptions.RemoveEmptyEntries) + .Select(x => x.Replace('\\', '/').Trim()) + ); + + Console.WriteLine(files); + + using var p = Process.Start( + new ProcessStartInfo + { + CreateNoWindow = true, + FileName = "dotnet", + Arguments = $"jb cleanupcode --include=\"{files}\" --no-build ./ShopCore.sln", + UseShellExecute = false, + RedirectStandardOutput = true + } + ); + p.WaitForExit(); + Console.WriteLine(p.StandardOutput.ReadToEnd()); + + using var p2 = Process.Start( + new ProcessStartInfo + { + CreateNoWindow = true, + FileName = "git", + Arguments = $"status", + UseShellExecute = false, + RedirectStandardOutput = true + } + ); + p2.WaitForExit(); + var content = p2.StandardOutput.ReadToEnd(); + Console.WriteLine(content); + + return content.Contains("working tree clean") ? 0 : 1; +} \ No newline at end of file diff --git a/SafetyDelUnusedResx.ahk b/SafetyDelUnusedResx.ahk deleted file mode 100644 index d2c097b..0000000 --- a/SafetyDelUnusedResx.ahk +++ /dev/null @@ -1,17 +0,0 @@ -Hotkey,^d,start -return -start: -loop,100{ - send,{AppsKey} - Sleep,100 - send,{Up} - Sleep,100 - send,{Up} - Sleep,100 - Send,{Enter} - Sleep,500 - Send,{Esc}, - Sleep,100 - Send,{Down} - Sleep,100 -} \ No newline at end of file diff --git a/StyleCopAnalyzers.ruleset b/StyleCopAnalyzers.ruleset index 2a53f74..7db480d 100644 --- a/StyleCopAnalyzers.ruleset +++ b/StyleCopAnalyzers.ruleset @@ -56,7 +56,7 @@ - + @@ -111,7 +111,7 @@ - + diff --git a/SyncMetaFiles.csx b/SyncMetaFiles.csx index 887689a..3965804 100644 --- a/SyncMetaFiles.csx +++ b/SyncMetaFiles.csx @@ -1,14 +1,17 @@ using System.Text.RegularExpressions; var slnFile = Directory.GetFiles(@".", "*.sln").First(); - var content = File.ReadAllText(slnFile); - content = Regex.Replace(content,@"ProjectSection\(SolutionItems\) = preProject(?:.|\n)*?EndProjectSection", - $""" +var content = File.ReadAllText(slnFile); +content = Regex.Replace( + content, + @"ProjectSection\(SolutionItems\) = preProject(?:.|\n)*?EndProjectSection", + $""" ProjectSection(SolutionItems) = preProject {string.Join('\n', Directory.GetFiles(@".", "*").Where(x => !x.EndsWith(".sln") && !x.EndsWith(".user")) .Select(x=>$"\t\t{Path.GetFileName(x)} = {Path.GetFileName(x)}"))} {'\t'}EndProjectSection -"""); - Console.WriteLine(content); - File.WriteAllText(slnFile, content); \ No newline at end of file +""" +); +Console.WriteLine(content); +File.WriteAllText(slnFile, content); \ No newline at end of file diff --git a/code-format.cmd b/dot-clean.cmd similarity index 100% rename from code-format.cmd rename to dot-clean.cmd diff --git a/dot.sln b/dot.sln index 77ed431..2e70918 100644 --- a/dot.sln +++ b/dot.sln @@ -12,10 +12,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "meta", "meta", "{AD79881E-7 .gitignore = .gitignore .tgitconfig = .tgitconfig build.cake = build.cake - code-format.cmd = code-format.cmd - CodeCleanupOnSave.csx = CodeCleanupOnSave.csx CodeQuality.props = CodeQuality.props + CopyPackageXmlCommentFiles.targets = CopyPackageXmlCommentFiles.targets Directory.Build.props = Directory.Build.props + dot-clean.cmd = dot-clean.cmd dot.sln.DotSettings = dot.sln.DotSettings dotnet-tools.json = dotnet-tools.json GenerateResx.targets = GenerateResx.targets @@ -23,14 +23,15 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "meta", "meta", "{AD79881E-7 global.json = global.json ImageOptimize.csx = ImageOptimize.csx LICENSE = LICENSE + NuGet.Config = NuGet.Config + package.json = package.json README.md = README.md README.zh-CN.md = README.zh-CN.md - SafetyDelUnusedResx.ahk = SafetyDelUnusedResx.ahk + resharper-clean-full.cmd = resharper-clean-full.cmd + resharper-clean.ps1 = resharper-clean.ps1 + ResharperCodeClean.csx = ResharperCodeClean.csx stylecop.json = stylecop.json StyleCopAnalyzers.ruleset = StyleCopAnalyzers.ruleset - switch-nuget.cmd = switch-nuget.cmd - switch-project.cmd = switch-project.cmd - switcher.nsext.json = switcher.nsext.json SyncMetaFiles.csx = SyncMetaFiles.csx EndProjectSection EndProject diff --git a/dot.sln.DotSettings b/dot.sln.DotSettings index 57d85a0..075aead 100644 --- a/dot.sln.DotSettings +++ b/dot.sln.DotSettings @@ -5,7 +5,8 @@ NEVER NEVER NEVER - False + UI + True 1 1 OFF @@ -58,4 +59,15 @@ </Entry> </TypePattern> </Patterns> + True + True + True + True + True + True + True + True + True + True + True \ No newline at end of file diff --git a/dotnet-tools.json b/dotnet-tools.json index 4f358a6..827097d 100644 --- a/dotnet-tools.json +++ b/dotnet-tools.json @@ -1,12 +1,30 @@ { - "version": 1, - "isRoot": true, - "tools": { - "dotnet-t4": { - "version": "2.3.1", - "commands": [ - "t4" - ] - } + "version": 1, + "isRoot": true, + "tools": { + "dotnet-t4": { + "version": "2.3.1", + "commands": [ + "t4" + ] + }, + "cake.tool": { + "version": "3.0.0", + "commands": [ + "dotnet-cake" + ] + }, + "dotnet-script": { + "version": "1.4.0", + "commands": [ + "dotnet-script" + ] + }, + "jetbrains.resharper.globaltools": { + "version": "2022.3.2", + "commands": [ + "jb" + ] } + } } \ No newline at end of file diff --git a/global.json b/global.json index 0e46db0..f94282e 100644 --- a/global.json +++ b/global.json @@ -1,10 +1,10 @@ { - "sdk": { - "version": "7.0.100", - "allowPrerelease": true, - "rollForward": "major" - }, - "tools": { - "dotnet": "7.0.100" - } + "sdk": { + "version": "7.0.100", + "allowPrerelease": true, + "rollForward": "major" + }, + "tools": { + "dotnet": "7.0.100" + } } \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..44b7af1 --- /dev/null +++ b/package.json @@ -0,0 +1,12 @@ +{ + "devDependencies": { + "cz-conventional-changelog": "^3.3.0", + "prettier": "2.8.1", + "prettier-plugin-csharp": "0.6.0-development" + }, + "config": { + "commitizen": { + "path": "./node_modules/cz-conventional-changelog" + } + } +} \ No newline at end of file diff --git a/resharper-clean-full.cmd b/resharper-clean-full.cmd new file mode 100644 index 0000000..21f5a22 --- /dev/null +++ b/resharper-clean-full.cmd @@ -0,0 +1 @@ +dotnet jb cleanupcode --no-build ./dot.sln \ No newline at end of file diff --git a/resharper-clean.ps1 b/resharper-clean.ps1 new file mode 100644 index 0000000..f15a255 --- /dev/null +++ b/resharper-clean.ps1 @@ -0,0 +1,4 @@ +$files=$(foreach ($line in $(git diff head origin/dev --stat-width 200) | findstr '\|'){$line.split('\|')[0].trim()}) -join ';' +echo $files +dotnet jb cleanupcode --no-build --include="$files" ./ShopCore.sln +dotnet script ./PushSign.csx \ No newline at end of file diff --git a/src/Color/Main.cs b/src/Color/Main.cs index a22e437..5c32acd 100644 --- a/src/Color/Main.cs +++ b/src/Color/Main.cs @@ -11,7 +11,7 @@ namespace Dot.Color; // ReSharper disable once ClassNeverInstantiated.Global internal sealed class Main : ToolBase