3 Commits

Author SHA1 Message Date
8e0836dc15 1.1.1 (#6)
* <feat> + 时间同步工具
2022-12-02 18:16:05 +08:00
6c7102af61 patch (#4)
* <clean>
2022-12-01 17:33:39 +08:00
de264e58a0 1.1.0 (#2)
* <feat> 多语言支持
* <feat> text tool 只读模式
2022-12-01 17:26:37 +08:00
41 changed files with 2399 additions and 262 deletions

45
.editorconfig Normal file
View File

@ -0,0 +1,45 @@
root = true
[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
# ReSharper properties
resharper_align_linq_query = true
resharper_align_multiline_argument = true
resharper_align_multiline_array_and_object_initializer = true
resharper_align_multiline_binary_patterns = true
resharper_align_multiline_calls_chain = true
resharper_align_multiline_extends_list = true
resharper_align_multiline_parameter = true
resharper_align_multiline_property_pattern = true
resharper_align_multiline_switch_expression = true
resharper_align_multiple_declaration = true
resharper_align_multline_type_parameter_constrains = true
resharper_align_multline_type_parameter_list = true
resharper_align_tuple_components = true
resharper_allow_comment_after_lbrace = true
resharper_csharp_empty_block_style = together_same_line
resharper_csharp_outdent_commas = true
resharper_csharp_stick_comment = false
resharper_csharp_wrap_before_comma = true
resharper_indent_nested_foreach_stmt = true
resharper_indent_nested_for_stmt = true
resharper_indent_nested_while_stmt = true
resharper_indent_preprocessor_if = usual_indent
resharper_indent_preprocessor_other = usual_indent
resharper_int_align = true
resharper_keep_existing_arrangement = false
resharper_place_linq_into_on_new_line = false
resharper_place_simple_switch_expression_on_single_line = true
resharper_wrap_before_eq = true
resharper_wrap_chained_method_calls = chop_if_long
resharper_wrap_switch_expression = chop_if_long
# Microsoft .NET properties
csharp_indent_braces = false
csharp_new_line_before_open_brace = local_functions, methods, types

816
.gitignore vendored
View File

@ -1,23 +1,805 @@
build ## Ignore Visual Studio temporary files, build results, and
bin ## files generated by popular Visual Studio add-ons.
obj ##
packages ## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore
Migrations
_gsdata_ # User-specific files
_ReSharper* *.rsuser
TestResults
app_data
nuget.config
*.suo *.suo
*.user *.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Mono auto generated files
mono_crash.*
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
[Ww][Ii][Nn]32/
[Aa][Rr][Mm]/
[Aa][Rr][Mm]64/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
[Ll]ogs/
# Visual Studio 2015/2017 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# Visual Studio 2017 auto generated files
Generated\ Files/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUnit
*.VisualState.xml
TestResult.xml
nunit-*.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# Benchmark Results
BenchmarkDotNet.Artifacts/
# .NET Core
project.lock.json
project.fragment.lock.json
artifacts/
# ASP.NET Scaffolding
ScaffoldingReadMe.txt
# StyleCop
StyleCopReport.xml
# Files built by Visual Studio
*_i.c
*_p.c
*_h.h
*.ilk
*.meta
*.obj
*.iobj
*.pch
*.pdb
*.ipdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*_wpftmp.csproj
*.log *.log
*.tlog
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# Visual Studio Trace Files
*.e2e
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# AxoCover is a Code Coverage Tool
.axoCover/*
!.axoCover/settings.json
# Coverlet is a free, cross platform Code Coverage Tool
coverage*.json
coverage*.xml
coverage*.info
# Visual Studio code coverage results
*.coverage
*.coveragexml
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# Note: Comment the next line if you want to checkin your web deploy settings,
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml *.pubxml
*.publish.xml *.publishproj
.svn
.vs # Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/
# NuGet Packages
*.nupkg
# NuGet Symbol Packages
*.snupkg
# The packages folder can be ignored because of Package Restore
**/[Pp]ackages/*
# except build/, which is used as an MSBuild target.
!**/[Pp]ackages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/[Pp]ackages/repositories.config
# NuGet v3's project.json files produces more ignorable files
*.nuget.props
*.nuget.targets
# Microsoft Azure Build Output
csx/
*.build.csdef
# Microsoft Azure Emulator
ecf/
rcf/
# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
*.appx
*.appxbundle
*.appxupload
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!?*.[Cc]ache/
# Others
ClientBin/
~$*
*~
*.dbmdl *.dbmdl
*.dbproj.schemaview
*.jfm *.jfm
*.exe *.pfx
.idea *.publishsettings
node_modules orleans.codegen.cs
dist
# Including strong name files can present a security risk
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
#*.snk
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
ServiceFabricBackup/
*.rptproj.bak
# SQL Server files
*.mdf
*.ldf
*.ndf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
*.rptproj.rsuser
*- [Bb]ackup.rdl
*- [Bb]ackup ([0-9]).rdl
*- [Bb]ackup ([0-9][0-9]).rdl
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
node_modules/
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw
# Visual Studio 6 auto-generated project file (contains which files were open etc.)
*.vbp
# Visual Studio 6 workspace and project file (working project files containing files to include in project)
*.dsw
*.dsp
# Visual Studio 6 technical files
*.ncb
*.aps
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
paket-files/
# FAKE - F# Make
.fake/
# CodeRush personal settings
.cr/personal
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
# Cake - Uncomment if you are using it
# tools/**
# !tools/packages.config
# Tabs Studio
*.tss
# Telerik's JustMock configuration file
*.jmconfig
# BizTalk build output
*.btp.cs
*.btm.cs
*.odx.cs
*.xsd.cs
# OpenCover UI analysis results
OpenCover/
# Azure Stream Analytics local run output
ASALocalRun/
# MSBuild Binary and Structured Log
*.binlog
# NVidia Nsight GPU debugger configuration file
*.nvuser
# MFractors (Xamarin productivity tool) working folder
.mfractor/
# Local History for Visual Studio
.localhistory/
# Visual Studio History (VSHistory) files
.vshistory/
# BeatPulse healthcheck temp database
healthchecksdb
# Backup folder for Package Reference Convert tool in Visual Studio 2017
MigrationBackup/
# Ionide (cross platform F# VS Code tools) working folder
.ionide/
# Fody - auto-generated XML schema
FodyWeavers.xsd
# VS Code files for those working on multiple tools
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
*.code-workspace
# Local History for Visual Studio Code
.history/
# Windows Installer files from build outputs
*.cab
*.msi
*.msix
*.msm
*.msp
# JetBrains Rider
*.sln.iml
.idea/
# User define
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore
# User-specific files
*.rsuser
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Mono auto generated files
mono_crash.*
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
[Ww][Ii][Nn]32/
[Aa][Rr][Mm]/
[Aa][Rr][Mm]64/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
[Ll]ogs/
# Visual Studio 2015/2017 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# Visual Studio 2017 auto generated files
Generated\ Files/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUnit
*.VisualState.xml
TestResult.xml
nunit-*.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# Benchmark Results
BenchmarkDotNet.Artifacts/
# .NET Core
project.lock.json
project.fragment.lock.json
artifacts/
# ASP.NET Scaffolding
ScaffoldingReadMe.txt
# StyleCop
StyleCopReport.xml
# Files built by Visual Studio
*_i.c
*_p.c
*_h.h
*.ilk
*.meta
*.obj
*.iobj
*.pch
*.pdb
*.ipdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*_wpftmp.csproj
*.log
*.tlog
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# Visual Studio Trace Files
*.e2e
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# AxoCover is a Code Coverage Tool
.axoCover/*
!.axoCover/settings.json
# Coverlet is a free, cross platform Code Coverage Tool
coverage*.json
coverage*.xml
coverage*.info
# Visual Studio code coverage results
*.coverage
*.coveragexml
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# Note: Comment the next line if you want to checkin your web deploy settings,
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/
# NuGet Packages
*.nupkg
# NuGet Symbol Packages
*.snupkg
# The packages folder can be ignored because of Package Restore
**/[Pp]ackages/*
# except build/, which is used as an MSBuild target.
!**/[Pp]ackages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/[Pp]ackages/repositories.config
# NuGet v3's project.json files produces more ignorable files
*.nuget.props
*.nuget.targets
# Microsoft Azure Build Output
csx/
*.build.csdef
# Microsoft Azure Emulator
ecf/
rcf/
# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
*.appx
*.appxbundle
*.appxupload
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!?*.[Cc]ache/
# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
orleans.codegen.cs
# Including strong name files can present a security risk
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
#*.snk
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
ServiceFabricBackup/
*.rptproj.bak
# SQL Server files
*.mdf
*.ldf
*.ndf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
*.rptproj.rsuser
*- [Bb]ackup.rdl
*- [Bb]ackup ([0-9]).rdl
*- [Bb]ackup ([0-9][0-9]).rdl
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
node_modules/
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw
# Visual Studio 6 auto-generated project file (contains which files were open etc.)
*.vbp
# Visual Studio 6 workspace and project file (working project files containing files to include in project)
*.dsw
*.dsp
# Visual Studio 6 technical files
*.ncb
*.aps
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
paket-files/
# FAKE - F# Make
.fake/
# CodeRush personal settings
.cr/personal
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
# Cake - Uncomment if you are using it
# tools/**
# !tools/packages.config
# Tabs Studio
*.tss
# Telerik's JustMock configuration file
*.jmconfig
# BizTalk build output
*.btp.cs
*.btm.cs
*.odx.cs
*.xsd.cs
# OpenCover UI analysis results
OpenCover/
# Azure Stream Analytics local run output
ASALocalRun/
# MSBuild Binary and Structured Log
*.binlog
# NVidia Nsight GPU debugger configuration file
*.nvuser
# MFractors (Xamarin productivity tool) working folder
.mfractor/
# Local History for Visual Studio
.localhistory/
# Visual Studio History (VSHistory) files
.vshistory/
# BeatPulse healthcheck temp database
healthchecksdb
# Backup folder for Package Reference Convert tool in Visual Studio 2017
MigrationBackup/
# Ionide (cross platform F# VS Code tools) working folder
.ionide/
# Fody - auto-generated XML schema
FodyWeavers.xsd
# VS Code files for those working on multiple tools
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
*.code-workspace
# Local History for Visual Studio Code
.history/
# Windows Installer files from build outputs
*.cab
*.msi
*.msix
*.msm
*.msp
# JetBrains Rider
*.sln.iml
.idea/
# User Define
build/
nuget.config

View File

@ -1,4 +1,4 @@
[hook "startcommit"] [hook "startcommit"]
cmdline = code-format.cmd cmdline = code-format.cmd
wait = true wait = true
show = true show = true

View File

@ -1,2 +1,3 @@
# dot # dot
功能全面的实用工具-程序员的瑞士军刀
A full-featured utility - the programmer's swiss army knife

View File

@ -1,3 +1,3 @@
dotnet build dotnet build
dotnet publish -c Release -r win-x64 --sc -p:PublishSingleFile=true -o ./build/win-x64 dotnet publish -c Release -r win-x64 --sc -p:"PublishSingleFile=true" -o ./build/win-x64
rm -r ./build/temp Remove-Item -r ./build/temp

View File

@ -1,3 +1,3 @@
dot trim-utf8-bom dot rm-bom
dot remove-whitespace dot rm-blank
dot convert-lf dot tolf

16
dot.sln
View File

@ -5,6 +5,22 @@ VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "dot", "src\dot.csproj", "{E7608D54-4A3B-4B4B-ADA0-7852987CA21F}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "dot", "src\dot.csproj", "{E7608D54-4A3B-4B4B-ADA0-7852987CA21F}"
EndProject EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "root-files", "root-files", "{AD79881E-74D9-4EC7-AFE9-82D10CD32C3A}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
.gitattributes = .gitattributes
.gitignore = .gitignore
.tgitconfig = .tgitconfig
build.ps1 = build.ps1
code-format.cmd = code-format.cmd
Directory.Build.props = Directory.Build.props
dot.sln.DotSettings = dot.sln.DotSettings
git-clean.ps1 = git-clean.ps1
LICENSE = LICENSE
README.md = README.md
global.json = global.json
EndProjectSection
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU

View File

@ -1,4 +1,7 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> <wpf:ResourceDictionary xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:s="clr-namespace:System;assembly=mscorlib"
xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xml:space="preserve">
<s:String x:Key="/Default/CodeStyle/CSharpFileLayoutPatterns/Pattern/@EntryValue">&lt;?xml version="1.0" encoding="utf-16"?&gt; <s:String x:Key="/Default/CodeStyle/CSharpFileLayoutPatterns/Pattern/@EntryValue">&lt;?xml version="1.0" encoding="utf-16"?&gt;
&lt;Patterns xmlns="urn:schemas-jetbrains-com:member-reordering-patterns"&gt; &lt;Patterns xmlns="urn:schemas-jetbrains-com:member-reordering-patterns"&gt;
&lt;TypePattern&gt; &lt;TypePattern&gt;
@ -36,10 +39,12 @@
&lt;/Entry&gt; &lt;/Entry&gt;
&lt;/TypePattern&gt; &lt;/TypePattern&gt;
&lt;/Patterns&gt;</s:String> &lt;/Patterns&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=Constants/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AA_BB" /&gt;</s:String> <s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=Constants/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AA_BB" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateConstants/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="_" Suffix="" Style="AA_BB" /&gt;</s:String> <s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateConstants/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="_" Suffix="" Style="AA_BB" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateStaticReadonly/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" /&gt;</s:String> <s:String
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=StaticReadonly/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String> x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateStaticReadonly/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" /&gt;</s:String>
<s:Boolean x:Key="/Default/ReSpeller/ReSpellerEnabled/@EntryValue">False</s:Boolean> <s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=StaticReadonly/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=TooWideLocalVariableScope/@EntryIndexedValue">HINT</s:String> <s:Boolean x:Key="/Default/ReSpeller/ReSpellerEnabled/@EntryValue">False</s:Boolean>
<s:String
x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=TooWideLocalVariableScope/@EntryIndexedValue">HINT</s:String>
</wpf:ResourceDictionary> </wpf:ResourceDictionary>

10
global.json Normal file
View File

@ -0,0 +1,10 @@
{
"sdk": {
"version": "7.0.100",
"allowPrerelease": true,
"rollForward": "major"
},
"tools": {
"dotnet": "7.0.100"
}
}

View File

@ -1,11 +0,0 @@
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; }
}

14
src/DirOption.cs Normal file
View File

@ -0,0 +1,14 @@
namespace Dot;
public class DirOption : IOption
{
[Option('f', "filter", HelpText = nameof(Str.FileSearchPattern), Default = "*.*", ResourceType = typeof(Str))]
public string Filter { get; set; }
[Value(0, HelpText = nameof(Str.FolderPath), Default = ".", ResourceType = typeof(Str))]
public string Path { get; set; }
[Option('r', "readonly", HelpText = nameof(Str.ReadOnly), Default = false, ResourceType = typeof(Str))]
public bool ReadOnly { get; set; }
}

View File

@ -1,2 +1,3 @@
global using ShellProgressBar; global using ShellProgressBar;
global using CommandLine; global using CommandLine;
global using Dot.Lang;

View File

@ -7,11 +7,12 @@ public sealed class Main : Tool<Option>
public Main(Option opt) : base(opt) { } public Main(Option opt) : base(opt) { }
public override void Run() public override Task Run()
{ {
var guid = System.Guid.NewGuid().ToString(); var guid = System.Guid.NewGuid().ToString();
if (Opt.Upper) guid = guid.ToUpper(); if (Opt.Upper) guid = guid.ToUpper();
ClipboardService.SetText(guid); ClipboardService.SetText(guid);
Console.WriteLine($"已复制到剪贴板:{guid}"); Console.WriteLine(Str.Copied, guid);
return Task.CompletedTask;
} }
} }

View File

@ -1,8 +1,8 @@
namespace Dot.Guid; namespace Dot.Guid;
[Verb("guid", HelpText = "GUID工具")] [Verb("guid", HelpText = nameof(Str.GuidTool), ResourceType = typeof(Str))]
public class Option : IOption public class Option : IOption
{ {
[Option('u', "upper", HelpText = "大写", Default = false)] [Option('u', "upper", HelpText = nameof(Str.UseUppercase), Default = false, ResourceType = typeof(Str))]
public bool Upper { get; set; } //normal options here public bool Upper { get; set; } //normal options here
} }

View File

@ -2,5 +2,5 @@ namespace Dot;
public interface ITool public interface ITool
{ {
void Run(); Task Run();
} }

341
src/Lang/Str.Designer.cs generated Normal file
View File

@ -0,0 +1,341 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Dot.Lang {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// 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 Str {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Str() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[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.Str", typeof(Str).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
public static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Looks up a localized string similar to 转换换行符为LF.
/// </summary>
public static string ConvertEndOfLineToLF {
get {
return ResourceManager.GetString("ConvertEndOfLineToLF", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to {0}(已复制到剪贴板).
/// </summary>
public static string Copied {
get {
return ResourceManager.GetString("Copied", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to 文件通配符.
/// </summary>
public static string FileSearchPattern {
get {
return ResourceManager.GetString("FileSearchPattern", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to 要处理的目录路径.
/// </summary>
public static string FolderPath {
get {
return ResourceManager.GetString("FolderPath", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to GUID工具.
/// </summary>
public static string GuidTool {
get {
return ResourceManager.GetString("GuidTool", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to 文本编码工具.
/// </summary>
public static string HelpForText {
get {
return ResourceManager.GetString("HelpForText", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to 输入文本为空.
/// </summary>
public static string InputTextIsEmpty {
get {
return ResourceManager.GetString("InputTextIsEmpty", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Local clock offset.
/// </summary>
public static string LocalClockOffset {
get {
return ResourceManager.GetString("LocalClockOffset", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to {0}, 本机时钟偏移: {1} ms.
/// </summary>
public static string LocalTimeOffset {
get {
return ResourceManager.GetString("LocalTimeOffset", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to 本机时间已同步.
/// </summary>
public static string LocalTimeSyncDone {
get {
return ResourceManager.GetString("LocalTimeSyncDone", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to 没有需要处理的文件.
/// </summary>
public static string NoFileToBeProcessed {
get {
return ResourceManager.GetString("NoFileToBeProcessed", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to {0} 通信中....
/// </summary>
public static string NtpCalling {
get {
return ResourceManager.GetString("NtpCalling", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to 成功 {0}/{1} , 本机时钟偏移平均值: {2} ms.
/// </summary>
public static string NtpReceiveDone {
get {
return ResourceManager.GetString("NtpReceiveDone", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to {0}/{1} 个 NTP 服务器.
/// </summary>
public static string NtpServerCount {
get {
return ResourceManager.GetString("NtpServerCount", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to 指定的路径“{0}”不存在.
/// </summary>
public static string PathNotFound {
get {
return ResourceManager.GetString("PathNotFound", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to 按下任意键继续....
/// </summary>
public static string PressAnyKey {
get {
return ResourceManager.GetString("PressAnyKey", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to BitSet 1[0-9]2[a-z]4[A-Z]8[ascii.0x21-0x2F].
/// </summary>
public static string PwdGenerateTypes {
get {
return ResourceManager.GetString("PwdGenerateTypes", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to 密码长度.
/// </summary>
public static string PwdLength {
get {
return ResourceManager.GetString("PwdLength", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to 随机密码生成器.
/// </summary>
public static string RandomPasswordGenerator {
get {
return ResourceManager.GetString("RandomPasswordGenerator", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to 只读模式(仅做测试,不实际修改).
/// </summary>
public static string ReadOnly {
get {
return ResourceManager.GetString("ReadOnly", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to 移除文件尾部换行和空格.
/// </summary>
public static string RemoveTrailingWhiteSpaces {
get {
return ResourceManager.GetString("RemoveTrailingWhiteSpaces", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to 查找文件....
/// </summary>
public static string SearchingFile {
get {
return ResourceManager.GetString("SearchingFile", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to {0} 个文件.
/// </summary>
public static string SearchingFileOK {
get {
return ResourceManager.GetString("SearchingFileOK", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Server.
/// </summary>
public static string Server {
get {
return ResourceManager.GetString("Server", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to 已读取:{0}/{1},处理:{2},跳过:{3}.
/// </summary>
public static string ShowMessageTemp {
get {
return ResourceManager.GetString("ShowMessageTemp", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Status.
/// </summary>
public static string Status {
get {
return ResourceManager.GetString("Status", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to 同步本机时间.
/// </summary>
public static string SyncToLocalTime {
get {
return ResourceManager.GetString("SyncToLocalTime", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to 要处理的文本(默认取取剪贴板值).
/// </summary>
public static string TextTobeProcessed {
get {
return ResourceManager.GetString("TextTobeProcessed", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to 连接NTP服务器超时时间 (毫秒).
/// </summary>
public static string TimeoutMillSecs {
get {
return ResourceManager.GetString("TimeoutMillSecs", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to 移除文件的uf8 bom.
/// </summary>
public static string TrimUtf8Bom {
get {
return ResourceManager.GetString("TrimUtf8Bom", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to 使用大写输出.
/// </summary>
public static string UseUppercase {
get {
return ResourceManager.GetString("UseUppercase", resourceCulture);
}
}
}
}

116
src/Lang/Str.en-US.resx Normal file
View File

@ -0,0 +1,116 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
id="root" xmlns="">
<xsd:element name="root" msdata:IsDataSet="true"></xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>1.3</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089
</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089
</value>
</resheader>
<data name="InputTextIsEmpty" xml:space="preserve">
<value>The input text is empty</value>
</data>
<data name="SearchingFile" xml:space="preserve">
<value>Find files...</value>
</data>
<data name="PathNotFound" xml:space="preserve">
<value>The specified path "{0}" does not exist</value>
</data>
<data name="SearchingFileOK" xml:space="preserve">
<value>Find files...OK</value>
</data>
<data name="ShowMessageTemp" xml:space="preserve">
<value>Read: {0}/{1}, processed: {2}, skipped: {3}</value>
</data>
<data name="HelpForText" xml:space="preserve">
<value>Text encoding tool</value>
</data>
<data name="Copied" xml:space="preserve">
<value>{0}(copied to clipboard)</value>
</data>
<data name="FileSearchPattern" xml:space="preserve">
<value>File wildcards</value>
</data>
<data name="FolderPath" xml:space="preserve">
<value>Directory path to be processed</value>
</data>
<data name="ConvertEndOfLineToLF" xml:space="preserve">
<value>Convert newline characters to LF</value>
</data>
<data name="GuidTool" xml:space="preserve">
<value>GUID tool</value>
</data>
<data name="UseUppercase" xml:space="preserve">
<value>Use uppercase output</value>
</data>
<data name="RandomPasswordGenerator" xml:space="preserve">
<value>Random password generator</value>
</data>
<data name="PwdLength" xml:space="preserve">
<value>Password length</value>
</data>
<data name="PwdGenerateTypes" xml:space="preserve">
<value>BitSet 1[0-9]2[a-z]4[A-Z]8[ascii.0x21-0x2F]</value>
</data>
<data name="RemoveTrailingWhiteSpaces" xml:space="preserve">
<value>Remove line breaks and spaces at the end of the file</value>
</data>
<data name="TrimUtf8Bom" xml:space="preserve">
<value>Remove the uf8 bom of the file</value>
</data>
<data name="TextTobeProcessed" xml:space="preserve">
<value>Text to be processed (clipboard value is taken by default)</value>
</data>
<data name="PressAnyKey" xml:space="preserve">
<value>Press any key to continue...</value>
</data>
<data name="ReadOnly" xml:space="preserve">
<value>Read-only mode (only for testing, no actual modification)</value>
</data>
<data name="NoFileToBeProcessed" xml:space="preserve">
<value>No documents to be processed</value>
</data>
<data name="TimeoutMillSecs" xml:space="preserve">
<value>Timeout for connecting to the NTP server (milliseconds)</value>
</data>
<data name="SyncToLocalTime" xml:space="preserve">
<value>Synchronize local time</value>
</data>
<data name="NtpReceiveDone" xml:space="preserve">
<value>Success {0}/{1}, the average value of the clock offset of the machine:{2}ms</value>
</data>
<data name="NtpServerCount" xml:space="preserve">
<value>{0}/{1} NTP servers</value>
</data>
<data name="NtpCalling" xml:space="preserve">
<value>{0} In communication...</value>
</data>
<data name="LocalTimeOffset" xml:space="preserve">
<value>{0}, local clock offset: {1} ms</value>
</data>
<data name="LocalTimeSyncDone" xml:space="preserve">
<value>Local time has been synchronized</value>
</data>
<data name="Server" xml:space="preserve">
<value>Server</value>
</data>
<data name="Status" xml:space="preserve">
<value>Status</value>
</data>
<data name="LocalClockOffset" xml:space="preserve">
<value>Local clock offset</value>
</data>
</root>

125
src/Lang/Str.resx Normal file
View File

@ -0,0 +1,125 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
id="root"
xmlns="">
<xsd:element name="root" msdata:IsDataSet="true">
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>1.3</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089
</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089
</value>
</resheader>
<data name="InputTextIsEmpty" xml:space="preserve">
<value>输入文本为空</value>
</data>
<data name="SearchingFile" xml:space="preserve">
<value>查找文件...</value>
</data>
<data name="PathNotFound" xml:space="preserve">
<value>指定的路径“{0}”不存在</value>
</data>
<data name="SearchingFileOK" xml:space="preserve">
<value>{0} 个文件</value>
</data>
<data name="ShowMessageTemp" xml:space="preserve">
<value>已读取:{0}/{1},处理:{2},跳过:{3}</value>
</data>
<data name="HelpForText" xml:space="preserve">
<value>文本编码工具</value>
</data>
<data name="TextTobeProcessed" xml:space="preserve">
<value>要处理的文本(默认取取剪贴板值)</value>
</data>
<data name="Copied" xml:space="preserve">
<value>{0}(已复制到剪贴板)</value>
</data>
<data name="FileSearchPattern" xml:space="preserve">
<value>文件通配符</value>
</data>
<data name="TimeoutMillSecs" xml:space="preserve">
<value>连接NTP服务器超时时间 (毫秒)</value>
</data>
<data name="SyncToLocalTime" xml:space="preserve">
<value>同步本机时间</value>
</data>
<data name="FolderPath" xml:space="preserve">
<value>要处理的目录路径</value>
</data>
<data name="ConvertEndOfLineToLF" xml:space="preserve">
<value>转换换行符为LF</value>
</data>
<data name="GuidTool" xml:space="preserve">
<value>GUID工具</value>
</data>
<data name="UseUppercase" xml:space="preserve">
<value>使用大写输出</value>
</data>
<data name="RandomPasswordGenerator" xml:space="preserve">
<value>随机密码生成器</value>
</data>
<data name="PwdLength" xml:space="preserve">
<value>密码长度</value>
</data>
<data name="PwdGenerateTypes" xml:space="preserve">
<value>BitSet 1[0-9]2[a-z]4[A-Z]8[ascii.0x21-0x2F]</value>
</data>
<data name="RemoveTrailingWhiteSpaces" xml:space="preserve">
<value>移除文件尾部换行和空格</value>
</data>
<data name="TrimUtf8Bom" xml:space="preserve">
<value>移除文件的uf8 bom</value>
</data>
<data name="PressAnyKey" xml:space="preserve">
<value>按下任意键继续...</value>
</data>
<data name="ReadOnly" xml:space="preserve">
<value>只读模式(仅做测试,不实际修改)</value>
</data>
<data name="NoFileToBeProcessed" xml:space="preserve">
<value>没有需要处理的文件</value>
</data>
<data name="NtpReceiveDone" xml:space="preserve">
<value>成功 {0}/{1} , 本机时钟偏移平均值: {2} ms</value>
</data>
<data name="NtpServerCount" xml:space="preserve">
<value>{0}/{1} 个 NTP 服务器</value>
</data>
<data name="NtpCalling" xml:space="preserve">
<value>{0} 通信中...</value>
</data>
<data name="LocalTimeOffset" xml:space="preserve">
<value>{0}, 本机时钟偏移: {1} ms</value>
</data>
<data name="LocalTimeSyncDone" xml:space="preserve">
<value>本机时间已同步</value>
</data>
<data name="Server" xml:space="preserve">
<value>Server</value>
</data>
<data name="Status" xml:space="preserve">
<value>Status</value>
</data>
<data name="LocalClockOffset" xml:space="preserve">
<value>Local clock offset</value>
</data>
</root>

251
src/Lang/Strings.Designer.cs generated Normal file
View File

@ -0,0 +1,251 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Dot.Lang {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// 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() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[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;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
public static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Looks up a localized string similar to 转换换行符为LF.
/// </summary>
public static string ConvertEndOfLineToLF {
get {
return ResourceManager.GetString("ConvertEndOfLineToLF", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to {0}(已复制到剪贴板).
/// </summary>
public static string Copied {
get {
return ResourceManager.GetString("Copied", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to 文件通配符.
/// </summary>
public static string FileSearchPattern {
get {
return ResourceManager.GetString("FileSearchPattern", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to 要处理的目录路径.
/// </summary>
public static string FolderPath {
get {
return ResourceManager.GetString("FolderPath", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to GUID工具.
/// </summary>
public static string GuidTool {
get {
return ResourceManager.GetString("GuidTool", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to 文本编码工具.
/// </summary>
public static string HelpForText {
get {
return ResourceManager.GetString("HelpForText", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to 输入文本为空.
/// </summary>
public static string InputTextIsEmpty {
get {
return ResourceManager.GetString("InputTextIsEmpty", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to 没有需要处理的文件.
/// </summary>
public static string NoFileToBeProcessed {
get {
return ResourceManager.GetString("NoFileToBeProcessed", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to 指定的路径“{0}”不存在.
/// </summary>
public static string PathNotFound {
get {
return ResourceManager.GetString("PathNotFound", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to 按下任意键继续....
/// </summary>
public static string PressAnyKey {
get {
return ResourceManager.GetString("PressAnyKey", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to BitSet 1[0-9]2[a-z]4[A-Z]8[ascii.0x21-0x2F].
/// </summary>
public static string PwdGenerateTypes {
get {
return ResourceManager.GetString("PwdGenerateTypes", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to 密码长度.
/// </summary>
public static string PwdLength {
get {
return ResourceManager.GetString("PwdLength", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to 随机密码生成器.
/// </summary>
public static string RandomPasswordGenerator {
get {
return ResourceManager.GetString("RandomPasswordGenerator", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to 只读模式(仅做测试,不实际修改).
/// </summary>
public static string ReadOnly {
get {
return ResourceManager.GetString("ReadOnly", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to 移除文件尾部换行和空格.
/// </summary>
public static string RemoveTrailingWhiteSpaces {
get {
return ResourceManager.GetString("RemoveTrailingWhiteSpaces", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to 查找文件....
/// </summary>
public static string SearchingFile {
get {
return ResourceManager.GetString("SearchingFile", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to {0} 个文件.
/// </summary>
public static string SearchingFileOK {
get {
return ResourceManager.GetString("SearchingFileOK", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to 已读取:{0}/{1},处理:{2},跳过:{3}.
/// </summary>
public static string ShowMessageTemp {
get {
return ResourceManager.GetString("ShowMessageTemp", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to 要处理的文本(默认取取剪贴板值).
/// </summary>
public static string TextTobeProcessed {
get {
return ResourceManager.GetString("TextTobeProcessed", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to 移除文件的uf8 bom.
/// </summary>
public static string TrimUtf8Bom {
get {
return ResourceManager.GetString("TrimUtf8Bom", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to 使用大写输出.
/// </summary>
public static string UseUppercase {
get {
return ResourceManager.GetString("UseUppercase", resourceCulture);
}
}
}
}

View File

@ -0,0 +1,86 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
id="root" xmlns="">
<xsd:element name="root" msdata:IsDataSet="true"></xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>1.3</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089
</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089
</value>
</resheader>
<data name="InputTextIsEmpty" xml:space="preserve">
<value>The input text is empty</value>
</data>
<data name="SearchingFile" xml:space="preserve">
<value>Find files...</value>
</data>
<data name="PathNotFound" xml:space="preserve">
<value>The specified path "{0}" does not exist</value>
</data>
<data name="SearchingFileOK" xml:space="preserve">
<value>Find files...OK</value>
</data>
<data name="ShowMessageTemp" xml:space="preserve">
<value>Read: {0}/{1}, processed: {2}, skipped: {3}</value>
</data>
<data name="HelpForText" xml:space="preserve">
<value>Text encoding tool</value>
</data>
<data name="Copied" xml:space="preserve">
<value>{0}(copied to clipboard)</value>
</data>
<data name="FileSearchPattern" xml:space="preserve">
<value>File wildcards</value>
</data>
<data name="FolderPath" xml:space="preserve">
<value>Directory path to be processed</value>
</data>
<data name="ConvertEndOfLineToLF" xml:space="preserve">
<value>Convert newline characters to LF</value>
</data>
<data name="GuidTool" xml:space="preserve">
<value>GUID tool</value>
</data>
<data name="UseUppercase" xml:space="preserve">
<value>Use uppercase output</value>
</data>
<data name="RandomPasswordGenerator" xml:space="preserve">
<value>Random password generator</value>
</data>
<data name="PwdLength" xml:space="preserve">
<value>Password length</value>
</data>
<data name="PwdGenerateTypes" xml:space="preserve">
<value>BitSet 1[0-9]2[a-z]4[A-Z]8[ascii.0x21-0x2F]</value>
</data>
<data name="RemoveTrailingWhiteSpaces" xml:space="preserve">
<value>Remove line breaks and spaces at the end of the file</value>
</data>
<data name="TrimUtf8Bom" xml:space="preserve">
<value>Remove the uf8 bom of the file</value>
</data>
<data name="TextTobeProcessed" xml:space="preserve">
<value>Text to be processed (clipboard value is taken by default)</value>
</data>
<data name="PressAnyKey" xml:space="preserve">
<value>Press any key to continue...</value>
</data>
<data name="ReadOnly" xml:space="preserve">
<value>Read-only mode (only for testing, no actual modification)</value>
</data>
<data name="NoFileToBeProcessed" xml:space="preserve">
<value>No documents to be processed</value>
</data>
</root>

94
src/Lang/Strings.resx Normal file
View File

@ -0,0 +1,94 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
id="root"
xmlns="">
<xsd:element name="root" msdata:IsDataSet="true">
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>1.3</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089
</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089
</value>
</resheader>
<data name="InputTextIsEmpty" xml:space="preserve">
<value>输入文本为空</value>
</data>
<data name="SearchingFile" xml:space="preserve">
<value>查找文件...</value>
</data>
<data name="PathNotFound" xml:space="preserve">
<value>指定的路径“{0}”不存在</value>
</data>
<data name="SearchingFileOK" xml:space="preserve">
<value>{0} 个文件</value>
</data>
<data name="ShowMessageTemp" xml:space="preserve">
<value>已读取:{0}/{1},处理:{2},跳过:{3}</value>
</data>
<data name="HelpForText" xml:space="preserve">
<value>文本编码工具</value>
</data>
<data name="TextTobeProcessed" xml:space="preserve">
<value>要处理的文本(默认取取剪贴板值)</value>
</data>
<data name="Copied" xml:space="preserve">
<value>{0}(已复制到剪贴板)</value>
</data>
<data name="FileSearchPattern" xml:space="preserve">
<value>文件通配符</value>
</data>
<data name="FolderPath" xml:space="preserve">
<value>要处理的目录路径</value>
</data>
<data name="ConvertEndOfLineToLF" xml:space="preserve">
<value>转换换行符为LF</value>
</data>
<data name="GuidTool" xml:space="preserve">
<value>GUID工具</value>
</data>
<data name="UseUppercase" xml:space="preserve">
<value>使用大写输出</value>
</data>
<data name="RandomPasswordGenerator" xml:space="preserve">
<value>随机密码生成器</value>
</data>
<data name="PwdLength" xml:space="preserve">
<value>密码长度</value>
</data>
<data name="PwdGenerateTypes" xml:space="preserve">
<value>BitSet 1[0-9]2[a-z]4[A-Z]8[ascii.0x21-0x2F]</value>
</data>
<data name="RemoveTrailingWhiteSpaces" xml:space="preserve">
<value>移除文件尾部换行和空格</value>
</data>
<data name="TrimUtf8Bom" xml:space="preserve">
<value>移除文件的uf8 bom</value>
</data>
<data name="PressAnyKey" xml:space="preserve">
<value>按下任意键继续...</value>
</data>
<data name="ReadOnly" xml:space="preserve">
<value>只读模式(仅做测试,不实际修改)</value>
</data>
<data name="NoFileToBeProcessed" xml:space="preserve">
<value>没有需要处理的文件</value>
</data>
</root>

View File

@ -10,10 +10,10 @@ Type[] LoadVerbs()
} }
void Run(object args) async Task Run(object args)
{ {
var tool = ToolsFactory.Create(args as IOption); var tool = ToolsFactory.Create(args as IOption);
tool.Run(); await tool.Run();
} }
@ -22,7 +22,7 @@ void Run(object args)
var types = LoadVerbs(); var types = LoadVerbs();
try { try {
Parser.Default.ParseArguments(args, types).WithParsed(Run); await Parser.Default.ParseArguments(args, types).WithParsedAsync(Run);
} }
catch (ArgumentException ex) { catch (ArgumentException ex) {
Console.Error.WriteLine(ex.Message); Console.Error.WriteLine(ex.Message);

View File

@ -1,10 +1,9 @@
using System.Text.RegularExpressions;
using NSExt.Extensions; using NSExt.Extensions;
using TextCopy; using TextCopy;
namespace Dot.Random; namespace Dot.Pwd;
public sealed partial class Main : Tool<Option> public sealed class Main : Tool<Option>
{ {
private readonly char[][] _charTable = { private readonly char[][] _charTable = {
"0123456789".ToCharArray() // "0123456789".ToCharArray() //
@ -16,19 +15,7 @@ public sealed partial class Main : Tool<Option>
public Main(Option opt) : base(opt) { } public Main(Option opt) : base(opt) { }
[GeneratedRegex("[a-z]")] public override Task Run()
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 { unsafe {
var pSource = stackalloc char[_charTable.Sum(x => x.Length)]; var pSource = stackalloc char[_charTable.Sum(x => x.Length)];
@ -60,7 +47,9 @@ public sealed partial class Main : Tool<Option>
var result = new string(pDest, 0, Opt.Length); var result = new string(pDest, 0, Opt.Length);
ClipboardService.SetText(result); ClipboardService.SetText(result);
Console.WriteLine($"已复制到剪贴板:{result}"); Console.WriteLine(Str.Copied, result);
} }
return Task.CompletedTask;
} }
} }

21
src/Pwd/Option.cs Normal file
View File

@ -0,0 +1,21 @@
namespace Dot.Pwd;
[Verb("pwd", HelpText = nameof(Str.RandomPasswordGenerator), ResourceType = typeof(Str))]
public class Option : IOption
{
[Flags]
public enum GenerateTypes
{
Number = 1
, LowerCaseLetter = 2
, UpperCaseLetter = 4
, SpecialCharacter = 8
}
[Value(1, Required = true, HelpText = nameof(Str.PwdLength), ResourceType = typeof(Str))]
public int Length { get; set; }
[Value(0, Required = true, HelpText = nameof(Str.PwdGenerateTypes), ResourceType = typeof(Str))]
public GenerateTypes Type { get; set; }
}

View File

@ -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; }
}

View File

@ -1,11 +0,0 @@
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; }
}

View File

@ -1,7 +1,7 @@
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using NSExt.Extensions; using NSExt.Extensions;
namespace Dot.RemoveTrailingWhiteSpace; namespace Dot.RmBlank;
public sealed class Main : Tool<Option>, IDisposable public sealed class Main : Tool<Option>, IDisposable
{ {
@ -27,22 +27,29 @@ public sealed class Main : Tool<Option>, IDisposable
_disposed = true; _disposed = true;
} }
private void FileHandle(string file) private async ValueTask FileHandle(string file, CancellationToken _)
{ {
_step2Bar.Tick(); _step2Bar.Tick();
ShowMessage(1, 0, 0); ShowMessage(1, 0, 0);
var spacesCnt = 0; var spacesCnt = 0;
using var fsr = OpenFileToWrite(file); await using var fsrw = OpenFileStream(file, FileMode.Open, FileAccess.ReadWrite);
if (fsr.Length == 0 || (spacesCnt = GetSpacesCnt(fsr)) == 0) {
if (Opt.ReadOnly) { //测试,只读模式
ShowMessage(0, 1, 0);
return;
}
if (fsrw is null || fsrw.Length == 0 || (spacesCnt = GetSpacesCnt(fsrw)) == 0) {
ShowMessage(0, 0, 1); ShowMessage(0, 0, 1);
return; return;
} }
fsr.Seek(0, SeekOrigin.Begin); fsrw.Seek(0, SeekOrigin.Begin);
if (!fsr.IsTextStream()) return; if (!fsrw.IsTextStream()) return;
ShowMessage(0, 1, 0); ShowMessage(0, 1, 0);
fsr.SetLength(fsr.Length - spacesCnt); fsrw.SetLength(fsrw.Length - spacesCnt);
} }
private static int GetSpacesCnt(Stream fsr) private static int GetSpacesCnt(Stream fsr)
@ -70,7 +77,7 @@ public sealed class Main : Tool<Option>, IDisposable
_procedCnt += procedCnt; _procedCnt += procedCnt;
_replaceCnt += removeCnt; _replaceCnt += removeCnt;
_breakCnt += breakCnt; _breakCnt += breakCnt;
_step2Bar.Message = $"已处理:{_procedCnt}/{_totalCnt},替换:{_replaceCnt},跳过:{_breakCnt}"; _step2Bar.Message = string.Format(Str.ShowMessageTemp, _procedCnt, _totalCnt, _replaceCnt, _breakCnt);
} }
} }
@ -82,22 +89,25 @@ public sealed class Main : Tool<Option>, IDisposable
/// <inheritdoc /> /// <inheritdoc />
[SuppressMessage("ReSharper", "PossibleMultipleEnumeration")] [SuppressMessage("ReSharper", "PossibleMultipleEnumeration")]
public override void Run() public override async Task 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(Str.PathNotFound, Opt.Path));
using var step1Bar = new IndeterminateProgressBar("查找文件...", DefaultProgressBarOptions); using var step1Bar = new IndeterminateProgressBar(Str.SearchingFile, DefaultProgressBarOptions);
var fileList = EnumerateFiles(Opt.Path, Opt.Filter); var fileList = EnumerateFiles(Opt.Path, Opt.Filter);
_totalCnt = fileList.Count(); _totalCnt = fileList.Count();
step1Bar.Message = "查找文件...OK"; step1Bar.Message = string.Format(Str.SearchingFileOK, _totalCnt);
step1Bar.Finished(); step1Bar.Finished();
if (_totalCnt == 0) return;
_step2Bar = step1Bar.Spawn(_totalCnt, string.Empty, DefaultProgressBarOptions); _step2Bar = step1Bar.Spawn(_totalCnt, string.Empty, DefaultProgressBarOptions);
Parallel.ForEach(fileList, FileHandle); await Parallel.ForEachAsync(fileList, FileHandle);
} }
} }

4
src/RmBlank/Option.cs Normal file
View File

@ -0,0 +1,4 @@
namespace Dot.RmBlank;
[Verb("rm-blank", HelpText = nameof(Str.RemoveTrailingWhiteSpaces), ResourceType = typeof(Str))]
public class Option : DirOption { }

110
src/RmBom/Main.cs Normal file
View File

@ -0,0 +1,110 @@
using System.Diagnostics.CodeAnalysis;
namespace Dot.RmBom;
public sealed class Main : Tool<Option>, IDisposable
{
private int _breakCnt;
private bool _disposed;
private static readonly object _lockObj = new();
private int _procedCnt;
private ChildProgressBar _step2Bar;
private int _totalCnt;
private int _trimCnt;
private readonly byte[] _utf8Bom = { 0xef, 0xbb, 0xbf };
public Main(Option opt) : base(opt) { }
~Main()
{
Dispose(false);
}
private bool CreateTempFile(Stream fsr, string tmpFile)
{
Span<byte> buffer = stackalloc byte[_utf8Bom.Length];
var readLen = fsr.Read(buffer);
if (readLen != _utf8Bom.Length || !buffer.SequenceEqual(_utf8Bom)) return false;
using var fsw = OpenFileStream(tmpFile, FileMode.OpenOrCreate, FileAccess.Write);
int data;
while ((data = fsr.ReadByte()) != -1) fsw.WriteByte((byte)data);
return true;
}
private void Dispose(bool disposing)
{
if (_disposed) return;
if (disposing) _step2Bar?.Dispose();
_disposed = true;
}
private async ValueTask FileHandle(string file, CancellationToken _)
{
_step2Bar.Tick();
ShowMessage(1, 0, 0);
var tmpFile = $"{file}.tmp";
bool isReplaced;
await using (var fsr = OpenFileStream(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) {
if (Opt.ReadOnly) { //测试,只读模式
ShowMessage(0, 1, 0);
return;
}
if (fsr is null) {
ShowMessage(0, 0, 1);
return;
}
isReplaced = CreateTempFile(fsr, tmpFile);
}
if (isReplaced) {
MoveFile(tmpFile, file);
ShowMessage(0, 1, 0);
}
else {
ShowMessage(0, 0, 1);
}
}
private void ShowMessage(int procedCnt, int replaceCnt, int breakCnt)
{
lock (_lockObj) {
_procedCnt += procedCnt;
_trimCnt += replaceCnt;
_breakCnt += breakCnt;
_step2Bar.Message = string.Format(Str.ShowMessageTemp, _procedCnt, _totalCnt, _trimCnt, _breakCnt);
}
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
[SuppressMessage("ReSharper", "PossibleMultipleEnumeration")]
public override async Task Run()
{
if (!Directory.Exists(Opt.Path))
throw new ArgumentException(nameof(Opt.Path), string.Format(Str.PathNotFound, Opt.Path));
using var step1Bar = new IndeterminateProgressBar(Str.SearchingFile, DefaultProgressBarOptions);
var fileList = EnumerateFiles(Opt.Path, Opt.Filter);
_totalCnt = fileList.Count();
step1Bar.Message = string.Format(Str.SearchingFileOK, _totalCnt);
step1Bar.Finished();
if (_totalCnt == 0) return;
_step2Bar = step1Bar.Spawn(_totalCnt, string.Empty, DefaultProgressBarOptions);
await Parallel.ForEachAsync(fileList, FileHandle);
}
}

4
src/RmBom/Option.cs Normal file
View File

@ -0,0 +1,4 @@
namespace Dot.RmBom;
[Verb("rm-bom", HelpText = nameof(Str.TrimUtf8Bom), ResourceType = typeof(Str))]
public class Option : DirOption { }

View File

@ -25,11 +25,7 @@ public sealed class Main : Tool<Option>
public ReadOnlySpan<char> UrlEncode; public ReadOnlySpan<char> UrlEncode;
} }
public Main(Option opt) : base(opt) public Main(Option opt) : base(opt) { }
{
if (Opt.Text.NullOrEmpty()) Opt.Text = ClipboardService.GetText();
if (Opt.Text.NullOrEmpty()) throw new ArgumentException("输入文本为空");
}
private static Output BuildOutput(string text, Encoding enc) private static Output BuildOutput(string text, Encoding enc)
{ {
@ -68,6 +64,22 @@ public sealed class Main : Tool<Option>
return ret; return ret;
} }
private static void ParseAndShow(string text)
{
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
var ansi = BuildOutput(text, Encoding.GetEncoding("gbk"));
var utf8 = BuildOutput(text, Encoding.UTF8);
var unicodeLittleEndian = BuildOutput(text, Encoding.Unicode);
var unicodeBigEndian = BuildOutput(text, Encoding.BigEndianUnicode);
PrintOutput(ansi);
PrintOutput(utf8);
PrintOutput(unicodeLittleEndian);
PrintOutput(unicodeBigEndian);
}
private static void PrintOutput(Output o) private static void PrintOutput(Output o)
{ {
var outputTemp = $""" var outputTemp = $"""
@ -89,18 +101,14 @@ html-decode: {o.HtmlDecode}
Console.WriteLine(outputTemp); Console.WriteLine(outputTemp);
} }
public override void Run() public override async Task Run()
{ {
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); if (Opt.Text.NullOrEmpty()) Opt.Text = await ClipboardService.GetTextAsync();
var ansi = BuildOutput(Opt.Text, Encoding.GetEncoding("gbk")); if (Opt.Text.NullOrEmpty()) throw new ArgumentException(Str.InputTextIsEmpty);
var utf8 = BuildOutput(Opt.Text, Encoding.UTF8);
var unicodeLittleEndian = BuildOutput(Opt.Text, Encoding.Unicode);
var unicodeBigEndian = BuildOutput(Opt.Text, Encoding.BigEndianUnicode);
PrintOutput(ansi); ParseAndShow(Opt.Text);
PrintOutput(utf8); Console.Write(Str.PressAnyKey);
PrintOutput(unicodeLittleEndian); Console.ReadKey();
PrintOutput(unicodeBigEndian);
} }
} }

View File

@ -1,8 +1,8 @@
namespace Dot.Text; namespace Dot.Text;
[Verb("text", HelpText = "文本编码工具")] [Verb("text", HelpText = nameof(Str.HelpForText), ResourceType = typeof(Str))]
public class Option : IOption public class Option : IOption
{ {
[Value(0, MetaName = "文本", HelpText = "要处理的文本,不指定此参数:取剪贴板值")] [Value(0, HelpText = nameof(Str.TextTobeProcessed), ResourceType = typeof(Str))]
public string Text { get; set; } public string Text { get; set; }
} }

194
src/Time/Main.cs Normal file
View File

@ -0,0 +1,194 @@
using System.Diagnostics.CodeAnalysis;
using System.Net.Sockets;
using System.Runtime.InteropServices;
namespace Dot.Time;
public sealed class Main : Tool<Option>
{
private enum ServerStatues : byte
{
Ready
, Connecting
, Succeed
, Failed
}
[StructLayout(LayoutKind.Explicit)]
private ref struct Systemtime
{
[FieldOffset(6)] public ushort wDay;
[FieldOffset(4)] public ushort wDayOfWeek;
[FieldOffset(8)] public ushort wHour;
[FieldOffset(14)] public ushort wMilliseconds;
[FieldOffset(10)] public ushort wMinute;
[FieldOffset(2)] public ushort wMonth;
[FieldOffset(12)] public ushort wSecond;
[FieldOffset(0)] public ushort wYear;
}
private const int _MAX_DEGREE_OF_PARALLELISM = 10;
private const int _NTP_PORT = 123;
private readonly char[] _loading = { '-', '\\', '|', '/' };
private int _procedCnt;
private readonly int _serverCnt;
private readonly Dictionary<string, Server> _serverDictionary;
private readonly string[] _serverDomains = {
"ntp.ntsc.ac.cn", "cn.ntp.org.cn", "edu.ntp.org.cn"
, "cn.pool.ntp.org", "time.pool.aliyun.com", "time1.aliyun.com"
, "time2.aliyun.com", "time3.aliyun.com", "time4.aliyun.com"
, "time5.aliyun.com", "time6.aliyun.com", "time7.aliyun.com"
, "time1.cloud.tencent.com", "time2.cloud.tencent.com"
, "time3.cloud.tencent.com", "time4.cloud.tencent.com"
, "time5.cloud.tencent.com", "ntp.sjtu.edu.cn", "ntp.neu.edu.cn"
, "ntp.bupt.edu.cn", "ntp.shu.edu.cn", "pool.ntp.org", "0.pool.ntp.org"
, "1.pool.ntp.org", "2.pool.ntp.org", "3.pool.ntp.org"
, "asia.pool.ntp.org", "time1.google.com", "time2.google.com"
, "time3.google.com", "time4.google.com", "time.apple.com"
, "time1.apple.com", "time2.apple.com", "time3.apple.com"
, "time4.apple.com", "time5.apple.com", "time6.apple.com"
, "time7.apple.com", "time.windows.com", "time.nist.gov"
, "time-nw.nist.gov", "time-a.nist.gov", "time-b.nist.gov"
, "stdtime.gov.hk"
};
private int _successCnt;
public Main(Option opt) : base(opt)
{
_serverCnt = _serverDomains.Length;
_serverDictionary = _serverDomains.ToDictionary(x => x, _ => new Server { Status = ServerStatues.Ready });
}
private TimeSpan GetNtpOffset(string server)
{
Span<byte> ntpData = stackalloc byte[48];
ntpData[0] = 0x1B;
using var socket
= new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp) {
ReceiveTimeout = Opt.Timeout
};
try {
socket.Connect(server, _NTP_PORT);
socket.Send(ntpData);
var timeBefore = DateTime.Now;
socket.Receive(ntpData);
var transferTime = DateTime.Now - timeBefore;
var intPart = ((ulong)ntpData[40] << 24) //
| ((ulong)ntpData[41] << 16) //
| ((ulong)ntpData[42] << 8) //
| ntpData[43];
var fractPart = ((ulong)ntpData[44] << 24) //
| ((ulong)ntpData[45] << 16) //
| ((ulong)ntpData[46] << 8) //
| ntpData[47];
var from1900Ms = intPart * 1000 + fractPart * 1000 / 0x100000000L;
var onlineTime = new DateTime(1900, 1, 1).AddMilliseconds((long)from1900Ms) + transferTime / 2;
return DateTime.UtcNow - onlineTime;
}
catch (Exception) {
return TimeSpan.Zero;
}
finally {
socket.Close();
}
}
private async void Printing()
{
const string outputTemp = "{0,-30}\t{1}\t{2,20}\t{3,20}";
var rolling = 0;
Console.Clear();
while (true) {
await Task.Delay(100);
Console.SetCursorPosition(0, 0);
var row = //
_serverDictionary.Select(x //
=> string.Format(outputTemp, x.Key
, x.Value.Status == ServerStatues.Connecting
? _loading[++rolling % 4]
: ' ', x.Value.Status
, x.Value.Offset == TimeSpan.Zero
? string.Empty
: x.Value.Offset));
Console.WriteLine(outputTemp, Str.Server, ' ', Str.Status, Str.LocalClockOffset);
Console.WriteLine(string.Join(Environment.NewLine, row));
if (_procedCnt == _serverCnt) break;
}
}
[DllImport("Kernel32.dll")]
private static extern void SetLocalTime(Systemtime st);
private static void SetSysteTime(DateTime time)
{
var timeToSet = new Systemtime {
wDay = (ushort)time.Day
, wDayOfWeek = (ushort)time.DayOfWeek
, wHour = (ushort)time.Hour
, wMilliseconds = (ushort)time.Millisecond
, wMinute = (ushort)time.Minute
, wMonth = (ushort)time.Month
, wSecond = (ushort)time.Second
, wYear = (ushort)time.Year
};
SetLocalTime(timeToSet);
}
[SuppressMessage("ReSharper", "AccessToDisposedClosure")]
public override async Task Run()
{
var tPrinting = Task.Run(Printing);
await Parallel.ForEachAsync(_serverDictionary
, new ParallelOptions { MaxDegreeOfParallelism = _MAX_DEGREE_OF_PARALLELISM }
, (server, _) => {
server.Value.Status = ServerStatues.Connecting;
var offset = GetNtpOffset(server.Key);
Interlocked.Increment(ref _procedCnt);
if (offset == TimeSpan.Zero) {
server.Value.Status = ServerStatues.Failed;
}
else {
server.Value.Status = ServerStatues.Succeed;
Interlocked.Increment(ref _successCnt);
server.Value.Offset = offset;
}
return ValueTask.CompletedTask;
});
tPrinting.Wait();
var avgOffset = TimeSpan.FromTicks((long)_serverDictionary //
.Where(x => x.Value.Status == ServerStatues.Succeed)
.Average(x => x.Value.Offset.Ticks));
Console.WriteLine(Str.NtpReceiveDone, _successCnt, _serverCnt, avgOffset.TotalMilliseconds);
if (!Opt.Sync) return;
Console.WriteLine();
SetSysteTime(DateTime.Now - avgOffset);
Console.WriteLine(Str.LocalTimeSyncDone);
}
private record Server
{
public TimeSpan Offset;
public ServerStatues Status;
}
}

11
src/Time/Option.cs Normal file
View File

@ -0,0 +1,11 @@
namespace Dot.Time;
[Verb("time", HelpText = nameof(Str.HelpForText), ResourceType = typeof(Str))]
public class Option : IOption
{
[Option('s', "sync", HelpText = nameof(Str.SyncToLocalTime), Default = false, ResourceType = typeof(Str))]
public bool Sync { get; set; }
[Option('t', "timeout", HelpText = nameof(Str.TimeoutMillSecs), Default = 3000, ResourceType = typeof(Str))]
public int Timeout { get; set; }
}

View File

@ -1,6 +1,6 @@
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
namespace Dot.Convert2Lf; namespace Dot.ToLf;
public sealed class Main : Tool<Option>, IDisposable public sealed class Main : Tool<Option>, IDisposable
{ {
@ -26,7 +26,7 @@ public sealed class Main : Tool<Option>, IDisposable
_disposed = true; _disposed = true;
} }
private void FileHandle(string file) private async ValueTask FileHandle(string file, CancellationToken _)
{ {
_step2Bar.Tick(); _step2Bar.Tick();
ShowMessage(1, 0, 0); ShowMessage(1, 0, 0);
@ -36,8 +36,19 @@ public sealed class Main : Tool<Option>, IDisposable
var isBin = false; var isBin = false;
int data; int data;
using (var fsr = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { await using (var fsr = OpenFileStream(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) {
using var fsw = new FileStream(tmpFile, FileMode.OpenOrCreate, FileAccess.Write); if (Opt.ReadOnly) { //测试,只读模式
ShowMessage(0, 1, 0);
return;
}
if (fsr is null) {
ShowMessage(0, 0, 1);
return;
}
await using var fsw = OpenFileStream(tmpFile, FileMode.OpenOrCreate, FileAccess.Write);
while ((data = fsr.ReadByte()) != -1) { while ((data = fsr.ReadByte()) != -1) {
switch (data) { switch (data) {
@ -81,7 +92,7 @@ public sealed class Main : Tool<Option>, IDisposable
_procedCnt += procedCnt; _procedCnt += procedCnt;
_replaceCnt += replaceCnt; _replaceCnt += replaceCnt;
_breakCnt += breakCnt; _breakCnt += breakCnt;
_step2Bar.Message = $"已处理:{_procedCnt}/{_totalCnt},替换:{_replaceCnt},跳过:{_breakCnt}"; _step2Bar.Message = string.Format(Str.ShowMessageTemp, _procedCnt, _totalCnt, _replaceCnt, _breakCnt);
} }
} }
@ -92,22 +103,25 @@ public sealed class Main : Tool<Option>, IDisposable
} }
[SuppressMessage("ReSharper", "PossibleMultipleEnumeration")] [SuppressMessage("ReSharper", "PossibleMultipleEnumeration")]
public override void Run() public override async Task 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(Str.PathNotFound, Opt.Path));
using var step1Bar = new IndeterminateProgressBar("查找文件...", DefaultProgressBarOptions); using var step1Bar = new IndeterminateProgressBar(Str.SearchingFile, DefaultProgressBarOptions);
var fileList = EnumerateFiles(Opt.Path, Opt.Filter); var fileList = EnumerateFiles(Opt.Path, Opt.Filter);
_totalCnt = fileList.Count(); _totalCnt = fileList.Count();
step1Bar.Message = "查找文件...OK"; step1Bar.Message = string.Format(Str.SearchingFileOK, _totalCnt);
step1Bar.Finished(); step1Bar.Finished();
if (_totalCnt == 0) return;
_step2Bar = step1Bar.Spawn(_totalCnt, string.Empty, DefaultProgressBarOptions); _step2Bar = step1Bar.Spawn(_totalCnt, string.Empty, DefaultProgressBarOptions);
Parallel.ForEach(fileList, FileHandle); await Parallel.ForEachAsync(fileList, FileHandle);
} }
} }

4
src/ToLf/Option.cs Normal file
View File

@ -0,0 +1,4 @@
namespace Dot.ToLf;
[Verb("tolf", HelpText = nameof(Str.ConvertEndOfLineToLF), ResourceType = typeof(Str))]
public class Option : DirOption { }

View File

@ -9,10 +9,11 @@ public abstract class Tool<TOption> : ITool
, ForegroundColor = ConsoleColor.Yellow , ForegroundColor = ConsoleColor.Yellow
, ForegroundColorDone = ConsoleColor.DarkGreen , ForegroundColorDone = ConsoleColor.DarkGreen
, BackgroundColor = ConsoleColor.DarkGray , BackgroundColor = ConsoleColor.DarkGray
, BackgroundCharacter = '\u2593' , BackgroundCharacter = '\u2500'
, ProgressCharacter = '\u2500'
}; };
protected virtual TOption Opt { get; set; } protected TOption Opt { get; }
protected Tool(TOption opt) protected Tool(TOption opt)
{ {
@ -43,20 +44,27 @@ public abstract class Tool<TOption> : ITool
} }
} }
protected static FileStream OpenFileToWrite(string file) protected static FileStream OpenFileStream(string file, FileMode mode, FileAccess access
, FileShare share = FileShare.Read)
{ {
FileStream fsr; FileStream fsr = null;
try { try {
fsr = new FileStream(file, FileMode.Open, FileAccess.ReadWrite, FileShare.Read); fsr = new FileStream(file, mode, access, share);
} }
catch (UnauthorizedAccessException) { catch (UnauthorizedAccessException) {
File.SetAttributes(file, new FileInfo(file).Attributes & ~FileAttributes.ReadOnly); try {
fsr = new FileStream(file, FileMode.Open, FileAccess.ReadWrite, FileShare.Read); File.SetAttributes(file, new FileInfo(file).Attributes & ~FileAttributes.ReadOnly);
fsr = new FileStream(file, mode, access, share);
}
catch (Exception) {
// ignored
}
} }
catch (IOException) { }
return fsr; return fsr;
} }
public abstract void Run(); public abstract Task Run();
} }

View File

@ -1,4 +1,4 @@
using Dot.TrimUtf8Bom; using Dot.RmBom;
namespace Dot; namespace Dot;
@ -7,13 +7,14 @@ public static class ToolsFactory
public static ITool Create(IOption option) public static ITool Create(IOption option)
{ {
return option switch { return option switch {
Option o => new Main(o) Option o => new Main(o)
, Convert2Lf.Option o => new Convert2Lf.Main(o) , ToLf.Option o => new ToLf.Main(o)
, RemoveTrailingWhiteSpace.Option o => new RemoveTrailingWhiteSpace.Main(o) , RmBlank.Option o => new RmBlank.Main(o)
, Random.Option o => new Random.Main(o) , Pwd.Option o => new Pwd.Main(o)
, Text.Option o => new Text.Main(o) , Text.Option o => new Text.Main(o)
, Guid.Option o => new Guid.Main(o) , Guid.Option o => new Guid.Main(o)
, _ => throw new ArgumentOutOfRangeException(nameof(option)) , Time.Option o => new Time.Main(o)
, _ => throw new ArgumentOutOfRangeException(nameof(option))
}; };
} }
} }

View File

@ -1,90 +0,0 @@
using System.Diagnostics.CodeAnalysis;
namespace Dot.TrimUtf8Bom;
public sealed class Main : Tool<Option>, IDisposable
{
private int _breakCnt;
private bool _disposed;
private static readonly object _lockObj = new();
private int _procedCnt;
private ChildProgressBar _step2Bar;
private int _totalCnt;
private int _trimCnt;
public Main(Option opt) : base(opt) { }
~Main()
{
Dispose(false);
}
private void Dispose(bool disposing)
{
if (_disposed) return;
if (disposing) _step2Bar?.Dispose();
_disposed = true;
}
private void ShowMessage(int procedCnt, int replaceCnt, int breakCnt)
{
lock (_lockObj) {
_procedCnt += procedCnt;
_trimCnt += replaceCnt;
_breakCnt += breakCnt;
_step2Bar.Message = $"已处理:{_procedCnt}/{_totalCnt}移除BOM{_trimCnt},跳过:{_breakCnt}";
}
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
[SuppressMessage("ReSharper", "PossibleMultipleEnumeration")]
public override void Run()
{
if (!Directory.Exists(Opt.Path)) throw new ArgumentException(nameof(Opt.Path), $"指定的路径“{Opt.Path}”不存在");
var utf8Bom = new byte[] { 0xef, 0xbb, 0xbf };
using var step1Bar = new IndeterminateProgressBar("查找文件...", DefaultProgressBarOptions);
var fileList = EnumerateFiles(Opt.Path, Opt.Filter);
_totalCnt = fileList.Count();
step1Bar.Message = "查找文件...OK";
step1Bar.Finished();
_step2Bar = step1Bar.Spawn(_totalCnt, string.Empty, DefaultProgressBarOptions);
Parallel.ForEach(fileList, file => {
_step2Bar.Tick();
ShowMessage(1, 0, 0);
var tmpFile = $"{file}.tmp";
var isReplaced = false;
using (var fsr = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) {
Span<byte> buffer = stackalloc byte[utf8Bom.Length];
var readLen = fsr.Read(buffer);
if (readLen == utf8Bom.Length && buffer.SequenceEqual(utf8Bom)) {
using var fsw = new FileStream(tmpFile, FileMode.OpenOrCreate, FileAccess.Write);
int data;
while ((data = fsr.ReadByte()) != -1) fsw.WriteByte((byte)data);
isReplaced = true;
}
}
if (isReplaced) {
MoveFile(tmpFile, file);
ShowMessage(0, 1, 0);
}
else {
ShowMessage(0, 0, 1);
}
});
}
}

View File

@ -1,11 +0,0 @@
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; }
}

View File

@ -6,12 +6,12 @@
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<RootNamespace>Dot</RootNamespace> <RootNamespace>Dot</RootNamespace>
<AssemblyName>dot</AssemblyName> <AssemblyName>dot</AssemblyName>
<Version>1.0.1</Version> <Version>1.1.1</Version>
<Authors>nsnail</Authors> <Authors>nsnail</Authors>
<Copyright>Copyright (c) 2022 nsnail</Copyright> <Copyright>Copyright (c) 2022 nsnail</Copyright>
<RepositoryUrl>https://github.com/nsnail/dot.git</RepositoryUrl> <RepositoryUrl>https://github.com/nsnail/dot.git</RepositoryUrl>
<RepositoryType>git</RepositoryType> <RepositoryType>git</RepositoryType>
<AssemblyTitle>功能全面的实用工具-程序员的瑞士军刀</AssemblyTitle> <AssemblyTitle>功能全面的实用工具 - 程序员的瑞士军刀</AssemblyTitle>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' "> <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
@ -29,4 +29,19 @@
<PackageReference Include="TextCopy" Version="6.2.0"/> <PackageReference Include="TextCopy" Version="6.2.0"/>
</ItemGroup> </ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Lang\Str.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>Str.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Compile Update="Lang\Str.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Str.resx</DependentUpon>
</Compile>
</ItemGroup>
</Project> </Project>