mirror of
https://github.com/nsnail/dot.git
synced 2025-08-03 20:45:36 +08:00
Compare commits
8 Commits
v1.0.1
...
247e35484c
Author | SHA1 | Date | |
---|---|---|---|
247e35484c | |||
2efc7ac76e | |||
deebd018f4 | |||
1ba7f3fcfe | |||
f2e8b8b891 | |||
8e0836dc15 | |||
6c7102af61 | |||
de264e58a0 |
12
.config/dotnet-tools.json
Normal file
12
.config/dotnet-tools.json
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"version": 1,
|
||||||
|
"isRoot": true,
|
||||||
|
"tools": {
|
||||||
|
"dotnet-t4": {
|
||||||
|
"version": "2.3.1",
|
||||||
|
"commands": [
|
||||||
|
"t4"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
45
.editorconfig
Normal file
45
.editorconfig
Normal 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
|
817
.gitignore
vendored
817
.gitignore
vendored
@ -1,23 +1,806 @@
|
|||||||
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
|
||||||
|
*.[Dd]esigner.cs
|
@ -1,4 +1,4 @@
|
|||||||
[hook "startcommit"]
|
[hook "startcommit"]
|
||||||
cmdline = code-format.cmd
|
cmdline = code-format.cmd
|
||||||
wait = true
|
wait = true
|
||||||
show = true
|
show = true
|
@ -1,2 +1,3 @@
|
|||||||
# dot
|
# dot
|
||||||
功能全面的实用工具-程序员的瑞士军刀
|
|
||||||
|
A full-featured utility - the programmer's swiss army knife
|
@ -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
|
@ -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
16
dot.sln
@ -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
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
<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"><?xml version="1.0" encoding="utf-16"?>
|
<s:String x:Key="/Default/CodeStyle/CSharpFileLayoutPatterns/Pattern/@EntryValue"><?xml version="1.0" encoding="utf-16"?>
|
||||||
<Patterns xmlns="urn:schemas-jetbrains-com:member-reordering-patterns">
|
<Patterns xmlns="urn:schemas-jetbrains-com:member-reordering-patterns">
|
||||||
<TypePattern>
|
<TypePattern>
|
||||||
@ -8,6 +10,7 @@
|
|||||||
<Kind.Order>
|
<Kind.Order>
|
||||||
<DeclarationKind>Interface</DeclarationKind>
|
<DeclarationKind>Interface</DeclarationKind>
|
||||||
<DeclarationKind>Class</DeclarationKind>
|
<DeclarationKind>Class</DeclarationKind>
|
||||||
|
<DeclarationKind>Record</DeclarationKind>
|
||||||
<DeclarationKind>Enum</DeclarationKind>
|
<DeclarationKind>Enum</DeclarationKind>
|
||||||
<DeclarationKind>Struct</DeclarationKind>
|
<DeclarationKind>Struct</DeclarationKind>
|
||||||
<DeclarationKind>Delegate</DeclarationKind>
|
<DeclarationKind>Delegate</DeclarationKind>
|
||||||
@ -36,10 +39,12 @@
|
|||||||
</Entry>
|
</Entry>
|
||||||
</TypePattern>
|
</TypePattern>
|
||||||
</Patterns></s:String>
|
</Patterns></s:String>
|
||||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=Constants/@EntryIndexedValue"><Policy Inspect="True" Prefix="" Suffix="" Style="AA_BB" /></s:String>
|
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=Constants/@EntryIndexedValue"><Policy Inspect="True" Prefix="" Suffix="" Style="AA_BB" /></s:String>
|
||||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateConstants/@EntryIndexedValue"><Policy Inspect="True" Prefix="_" Suffix="" Style="AA_BB" /></s:String>
|
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateConstants/@EntryIndexedValue"><Policy Inspect="True" Prefix="_" Suffix="" Style="AA_BB" /></s:String>
|
||||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateStaticReadonly/@EntryIndexedValue"><Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" /></s:String>
|
<s:String
|
||||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=StaticReadonly/@EntryIndexedValue"><Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /></s:String>
|
x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateStaticReadonly/@EntryIndexedValue"><Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" /></s:String>
|
||||||
<s:Boolean x:Key="/Default/ReSpeller/ReSpellerEnabled/@EntryValue">False</s:Boolean>
|
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=StaticReadonly/@EntryIndexedValue"><Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /></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
10
global.json
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"sdk": {
|
||||||
|
"version": "7.0.100",
|
||||||
|
"allowPrerelease": true,
|
||||||
|
"rollForward": "major"
|
||||||
|
},
|
||||||
|
"tools": {
|
||||||
|
"dotnet": "7.0.100"
|
||||||
|
}
|
||||||
|
}
|
13
src/Color/Main.cs
Normal file
13
src/Color/Main.cs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
namespace Dot.Color;
|
||||||
|
|
||||||
|
public sealed class Main : ToolBase<Option>
|
||||||
|
|
||||||
|
{
|
||||||
|
public Main(Option opt) : base(opt) { }
|
||||||
|
|
||||||
|
public override Task Run()
|
||||||
|
{
|
||||||
|
Application.Run(new WinMain());
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
}
|
75
src/Color/MouseHook.cs
Normal file
75
src/Color/MouseHook.cs
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
using System.Diagnostics;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
namespace Dot.Color;
|
||||||
|
|
||||||
|
public class MouseHook : IDisposable
|
||||||
|
{
|
||||||
|
[StructLayout(LayoutKind.Explicit)]
|
||||||
|
private struct Msllhookstruct
|
||||||
|
{
|
||||||
|
// [FieldOffset(20)] private readonly nint dwExtraInfo;
|
||||||
|
// [FieldOffset(12)] private readonly uint flags;
|
||||||
|
// [FieldOffset(8)] private readonly uint mouseData;
|
||||||
|
// [FieldOffset(16)] private readonly uint time;
|
||||||
|
[FieldOffset(0)] public readonly int X;
|
||||||
|
[FieldOffset(4)] public readonly int Y;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public event MouseEventHandler MouseEvent = delegate { };
|
||||||
|
private const int _WH_MOUSE_LL = 14;
|
||||||
|
private const int _WM_LBUTTONDOWN = 0x0201;
|
||||||
|
private const int _WM_MOUSEMOVE = 0x0200;
|
||||||
|
private bool _disposed;
|
||||||
|
private readonly nint _hookId;
|
||||||
|
|
||||||
|
public MouseHook()
|
||||||
|
{
|
||||||
|
_hookId = SetHook(HookCallback);
|
||||||
|
}
|
||||||
|
|
||||||
|
~MouseHook()
|
||||||
|
{
|
||||||
|
Dispose(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (_disposed) return;
|
||||||
|
if (disposing) { }
|
||||||
|
|
||||||
|
if (_hookId != default) Win32.UnhookWindowsHookEx(_hookId);
|
||||||
|
_disposed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private nint HookCallback(int nCode, nint wParam, nint lParam)
|
||||||
|
{
|
||||||
|
if (nCode < 0 || (_WM_MOUSEMOVE != wParam && _WM_LBUTTONDOWN != wParam))
|
||||||
|
return Win32.CallNextHookEx(_hookId, nCode, wParam, lParam);
|
||||||
|
var hookStruct = (Msllhookstruct)Marshal.PtrToStructure(lParam, typeof(Msllhookstruct))!;
|
||||||
|
MouseEvent(null, new MouseEventArgs( //
|
||||||
|
wParam == _WM_MOUSEMOVE ? MouseButtons.None : MouseButtons.Left //
|
||||||
|
, 0 //
|
||||||
|
, hookStruct.X //
|
||||||
|
, hookStruct.Y //
|
||||||
|
, 0));
|
||||||
|
return Win32.CallNextHookEx(_hookId, nCode, wParam, lParam);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static nint SetHook(Win32.LowLevelMouseProc proc)
|
||||||
|
{
|
||||||
|
using var curProcess = Process.GetCurrentProcess();
|
||||||
|
using var curModule = curProcess.MainModule!;
|
||||||
|
return Win32.SetWindowsHookEx(_WH_MOUSE_LL, proc, Win32.GetModuleHandle(curModule.ModuleName), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
Dispose(true);
|
||||||
|
GC.SuppressFinalize(this);
|
||||||
|
}
|
||||||
|
}
|
4
src/Color/Option.cs
Normal file
4
src/Color/Option.cs
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
namespace Dot.Color;
|
||||||
|
|
||||||
|
[Verb("color", HelpText = nameof(Str.ScreenPixelTool), ResourceType = typeof(Str))]
|
||||||
|
public class Option : OptionBase { }
|
48
src/Color/Win32.cs
Normal file
48
src/Color/Win32.cs
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
namespace Dot.Color;
|
||||||
|
|
||||||
|
public static partial class Win32
|
||||||
|
{
|
||||||
|
public delegate nint LowLevelMouseProc(int nCode, nint wParam, nint lParam);
|
||||||
|
|
||||||
|
private const string _GDI32_DLL = "gdi32.dll";
|
||||||
|
private const string _KERNEL32_DLL = "kernel32.dll";
|
||||||
|
private const string _USER32_DLL = "user32.dll";
|
||||||
|
public const int SW_HIDE = 0;
|
||||||
|
|
||||||
|
|
||||||
|
[LibraryImport(_USER32_DLL)]
|
||||||
|
internal static partial nint CallNextHookEx(nint hhk, int nCode, nint wParam, nint lParam);
|
||||||
|
|
||||||
|
[LibraryImport(_KERNEL32_DLL)]
|
||||||
|
internal static partial nint GetConsoleWindow();
|
||||||
|
|
||||||
|
|
||||||
|
[LibraryImport(_USER32_DLL)]
|
||||||
|
internal static partial nint GetDesktopWindow();
|
||||||
|
|
||||||
|
|
||||||
|
[LibraryImport(_KERNEL32_DLL, StringMarshalling = StringMarshalling.Utf16)]
|
||||||
|
internal static partial nint GetModuleHandle(string lpModuleName);
|
||||||
|
|
||||||
|
[LibraryImport(_GDI32_DLL)]
|
||||||
|
internal static partial uint GetPixel(nint dc, int x, int y);
|
||||||
|
|
||||||
|
[LibraryImport(_USER32_DLL)]
|
||||||
|
internal static partial nint GetWindowDC(nint hWnd);
|
||||||
|
|
||||||
|
[LibraryImport(_USER32_DLL)]
|
||||||
|
internal static partial int ReleaseDC(nint hWnd, nint dc);
|
||||||
|
|
||||||
|
[LibraryImport(_USER32_DLL)]
|
||||||
|
internal static partial nint SetWindowsHookEx(int idHook, LowLevelMouseProc lpfn, nint hMod, uint dwThreadId);
|
||||||
|
|
||||||
|
[LibraryImport(_USER32_DLL)]
|
||||||
|
[return: MarshalAs(UnmanagedType.Bool)]
|
||||||
|
internal static partial bool ShowWindow(nint hWnd, int nCmdShow);
|
||||||
|
|
||||||
|
[LibraryImport(_USER32_DLL)]
|
||||||
|
[return: MarshalAs(UnmanagedType.Bool)]
|
||||||
|
internal static partial bool UnhookWindowsHookEx(nint hhk);
|
||||||
|
}
|
83
src/Color/WinInfo.cs
Normal file
83
src/Color/WinInfo.cs
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
using System.Drawing.Drawing2D;
|
||||||
|
|
||||||
|
namespace Dot.Color;
|
||||||
|
|
||||||
|
public class WinInfo : Form
|
||||||
|
{
|
||||||
|
private const int _WINDOW_SIZE = 480; //窗口大小
|
||||||
|
private const int _ZOOM_RATE = 16; //缩放倍率
|
||||||
|
private bool _disposed;
|
||||||
|
private readonly Graphics _graphics;
|
||||||
|
private readonly PictureBox _pbox;
|
||||||
|
|
||||||
|
public WinInfo()
|
||||||
|
{
|
||||||
|
FormBorderStyle = FormBorderStyle.None;
|
||||||
|
TopMost = true;
|
||||||
|
MinimizeBox = false;
|
||||||
|
MaximizeBox = false;
|
||||||
|
Size = new Size(_WINDOW_SIZE, _WINDOW_SIZE);
|
||||||
|
StartPosition = FormStartPosition.Manual;
|
||||||
|
Location = new Point(0, 0);
|
||||||
|
_pbox = new PictureBox();
|
||||||
|
_pbox.Location = new Point(0, 0);
|
||||||
|
_pbox.Size = Size;
|
||||||
|
_pbox.Image = new Bitmap(_WINDOW_SIZE, _WINDOW_SIZE);
|
||||||
|
_graphics = Graphics.FromImage(_pbox.Image);
|
||||||
|
_graphics.InterpolationMode = InterpolationMode.NearestNeighbor; //指定最临近插值法,禁止平滑缩放(模糊)
|
||||||
|
_graphics.CompositingQuality = CompositingQuality.HighQuality;
|
||||||
|
_graphics.SmoothingMode = SmoothingMode.None;
|
||||||
|
_pbox.MouseEnter += PboxOnMouseEnter;
|
||||||
|
Controls.Add(_pbox);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
~WinInfo()
|
||||||
|
{
|
||||||
|
Dispose(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void PboxOnMouseEnter(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
// 信息窗口避开鼠标指针指向区域
|
||||||
|
Location = new Point(Location.X, Location.Y == 0 ? Screen.PrimaryScreen!.Bounds.Height - _WINDOW_SIZE : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
base.Dispose(disposing);
|
||||||
|
|
||||||
|
if (_disposed) return;
|
||||||
|
if (disposing) {
|
||||||
|
_graphics?.Dispose();
|
||||||
|
_pbox?.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
_disposed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void UpdateImage(Bitmap img, int x, int y)
|
||||||
|
{
|
||||||
|
// 计算复制小图的区域
|
||||||
|
var copySize = new Size(_WINDOW_SIZE / _ZOOM_RATE, _WINDOW_SIZE / _ZOOM_RATE);
|
||||||
|
_graphics.DrawImage(img, new Rectangle(0, 0, _WINDOW_SIZE, _WINDOW_SIZE) //
|
||||||
|
, x - copySize.Width / 2 // 左移x,使光标位置居中
|
||||||
|
, y - copySize.Height / 2 // 上移y,使光标位置居中
|
||||||
|
, copySize.Width, copySize.Height, GraphicsUnit.Pixel);
|
||||||
|
using var pen = new Pen(System.Drawing.Color.Aqua); //绘制准星
|
||||||
|
_graphics.DrawRectangle(pen, _WINDOW_SIZE / 2 - _ZOOM_RATE / 2 //
|
||||||
|
, _WINDOW_SIZE / 2 - _ZOOM_RATE / 2 //
|
||||||
|
, _ZOOM_RATE, _ZOOM_RATE);
|
||||||
|
|
||||||
|
// 取鼠标位置颜色
|
||||||
|
var posColor = img.GetPixel(x, y);
|
||||||
|
// 绘制底部文字信息
|
||||||
|
_graphics.FillRectangle(Brushes.Black, 0, _WINDOW_SIZE - 30, _WINDOW_SIZE, 30);
|
||||||
|
_graphics.DrawString($"{Str.ClickCopyColor} X: {x} Y: {y} RGB({posColor.R},{posColor.G},{posColor.B})"
|
||||||
|
, new Font(FontFamily.GenericSerif, 10) //
|
||||||
|
, Brushes.White, 0, _WINDOW_SIZE - 20);
|
||||||
|
// 触发重绘
|
||||||
|
_pbox.Refresh();
|
||||||
|
}
|
||||||
|
}
|
72
src/Color/WinMain.cs
Normal file
72
src/Color/WinMain.cs
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
using TextCopy;
|
||||||
|
|
||||||
|
namespace Dot.Color;
|
||||||
|
|
||||||
|
public class WinMain : Form
|
||||||
|
{
|
||||||
|
private readonly Bitmap _bmp;
|
||||||
|
private bool _disposed;
|
||||||
|
private readonly WinInfo _winInfo = new(); //小图窗口
|
||||||
|
|
||||||
|
public WinMain()
|
||||||
|
{
|
||||||
|
// 隐藏控制台窗口,避免捕获到截屏
|
||||||
|
Win32.ShowWindow(Win32.GetConsoleWindow(), Win32.SW_HIDE);
|
||||||
|
|
||||||
|
FormBorderStyle = FormBorderStyle.None;
|
||||||
|
Size = Screen.PrimaryScreen!.Bounds.Size;
|
||||||
|
StartPosition = FormStartPosition.Manual;
|
||||||
|
Location = new Point(0, 0);
|
||||||
|
Opacity = 0.01d; //主窗体加载截图过程设置为透明避免闪烁
|
||||||
|
_bmp = new Bitmap(Size.Width, Size.Height);
|
||||||
|
using var g = Graphics.FromImage(_bmp);
|
||||||
|
g.CopyFromScreen(0, 0, 0, 0, Size);
|
||||||
|
}
|
||||||
|
|
||||||
|
~WinMain()
|
||||||
|
{
|
||||||
|
Dispose(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
base.Dispose(disposing);
|
||||||
|
if (_disposed) return;
|
||||||
|
if (disposing) {
|
||||||
|
_bmp?.Dispose();
|
||||||
|
_winInfo?.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
_disposed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnKeyUp(KeyEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.KeyCode == Keys.Escape) Application.Exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnLoad(EventArgs e)
|
||||||
|
{
|
||||||
|
_winInfo.Show();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnMouseDown(MouseEventArgs e)
|
||||||
|
{
|
||||||
|
var color = _bmp.GetPixel(e.X, e.Y);
|
||||||
|
ClipboardService.SetText(
|
||||||
|
$"{e.X},{e.Y} #{color.R.ToString("X2")}{color.G.ToString("X2")}{color.B.ToString("X2")}({color.R},{color.G},{color.B})");
|
||||||
|
Application.Exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnMouseMove(MouseEventArgs e)
|
||||||
|
{
|
||||||
|
// 移动鼠标时更新小图窗口
|
||||||
|
_winInfo.UpdateImage(_bmp, e.X, e.Y);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnPaint(PaintEventArgs e)
|
||||||
|
{
|
||||||
|
e.Graphics.DrawImage(_bmp, 0, 0);
|
||||||
|
Opacity = 1;
|
||||||
|
}
|
||||||
|
}
|
@ -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
14
src/DirOption.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
namespace Dot;
|
||||||
|
|
||||||
|
public class DirOption : OptionBase
|
||||||
|
{
|
||||||
|
[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; }
|
||||||
|
}
|
111
src/Git/Main.cs
Normal file
111
src/Git/Main.cs
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
using System.Diagnostics;
|
||||||
|
using System.Text;
|
||||||
|
using NSExt.Extensions;
|
||||||
|
|
||||||
|
namespace Dot.Git;
|
||||||
|
|
||||||
|
public class Main : ToolBase<Option>
|
||||||
|
{
|
||||||
|
private const int _POS_Y_MSG = 74; //git command rsp 显示的位置 y
|
||||||
|
private const int _POST_Y_LOADING = 70; //loading 动画显示的位置 y
|
||||||
|
private const int _REP_PATH_LENGTH_LIMIT = 32; //仓库路径长度显示截断阈值
|
||||||
|
private (int x, int y) _cursorPosBackup; //光标位置备份
|
||||||
|
private readonly Encoding _gitOutputEnc; //git command rsp 编码
|
||||||
|
private List<string> _repoPathList; //仓库目录列表
|
||||||
|
|
||||||
|
|
||||||
|
public Main(Option opt) : base(opt)
|
||||||
|
{
|
||||||
|
_gitOutputEnc = Encoding.GetEncoding(Opt.GitOutputEncoding);
|
||||||
|
if (!Directory.Exists(Opt.Path))
|
||||||
|
throw new ArgumentException(nameof(Opt.Path) //
|
||||||
|
, string.Format(Str.PathNotFound, Opt.Path));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private async ValueTask DirHandle(string dir, CancellationToken cancelToken)
|
||||||
|
{
|
||||||
|
var row = _repoPathList.FindIndex(x => x == dir); // 行号
|
||||||
|
var tAnimate = LoadingAnimate(_POST_Y_LOADING, _cursorPosBackup.y + row, out var cts);
|
||||||
|
|
||||||
|
// 打印 git command rsp
|
||||||
|
void ExecRspReceived(object sender, DataReceivedEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.Data is null) return;
|
||||||
|
var msg = Encoding.UTF8.GetString(_gitOutputEnc.GetBytes(e.Data));
|
||||||
|
ConcurrentWrite(_POS_Y_MSG, _cursorPosBackup.y + row, new string(' ', Console.WindowWidth - _POS_Y_MSG));
|
||||||
|
ConcurrentWrite(_POS_Y_MSG, _cursorPosBackup.y + row, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 启动git进程
|
||||||
|
{
|
||||||
|
var startInfo = new ProcessStartInfo {
|
||||||
|
CreateNoWindow = true
|
||||||
|
, WorkingDirectory = dir
|
||||||
|
, FileName = "git"
|
||||||
|
, Arguments = Opt.Args
|
||||||
|
, UseShellExecute = false
|
||||||
|
, RedirectStandardOutput = true
|
||||||
|
, RedirectStandardError = true
|
||||||
|
};
|
||||||
|
using var p = Process.Start(startInfo);
|
||||||
|
p!.OutputDataReceived += ExecRspReceived;
|
||||||
|
p.ErrorDataReceived += ExecRspReceived;
|
||||||
|
p.BeginOutputReadLine();
|
||||||
|
p.BeginErrorReadLine();
|
||||||
|
await p.WaitForExitAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
cts.Cancel();
|
||||||
|
await tAnimate;
|
||||||
|
cts.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void StashCurorPos()
|
||||||
|
{
|
||||||
|
_cursorPosBackup = Console.GetCursorPosition();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public override async Task Run()
|
||||||
|
{
|
||||||
|
// 查找git仓库目录
|
||||||
|
{
|
||||||
|
Console.Write(Str.FindGitReps, Opt.Path);
|
||||||
|
StashCurorPos();
|
||||||
|
|
||||||
|
var tAnimate = LoadingAnimate(_cursorPosBackup.x, _cursorPosBackup.y, out var cts);
|
||||||
|
_repoPathList = Directory.GetDirectories(Opt.Path, ".git" //
|
||||||
|
, new EnumerationOptions //
|
||||||
|
{
|
||||||
|
MaxRecursionDepth = Opt.MaxRecursionDepth
|
||||||
|
, RecurseSubdirectories = true
|
||||||
|
, IgnoreInaccessible = true
|
||||||
|
, AttributesToSkip = FileAttributes.ReparsePoint
|
||||||
|
})
|
||||||
|
.Select(x => Directory.GetParent(x)!.FullName)
|
||||||
|
.ToList();
|
||||||
|
cts.Cancel();
|
||||||
|
await tAnimate;
|
||||||
|
cts.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 打印git仓库目录
|
||||||
|
{
|
||||||
|
Console.WriteLine(Str.Ok);
|
||||||
|
StashCurorPos();
|
||||||
|
|
||||||
|
var i = 0;
|
||||||
|
Console.WriteLine( //
|
||||||
|
string.Join(Environment.NewLine
|
||||||
|
, _repoPathList.Select(
|
||||||
|
x => $"{++i}: {new DirectoryInfo(x).Name.Sub(0, _REP_PATH_LENGTH_LIMIT)}"))
|
||||||
|
//
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 并行执行git命令
|
||||||
|
await Parallel.ForEachAsync(_repoPathList, DirHandle);
|
||||||
|
Console.SetCursorPosition(_cursorPosBackup.x, _cursorPosBackup.y + _repoPathList.Count);
|
||||||
|
}
|
||||||
|
}
|
19
src/Git/Option.cs
Normal file
19
src/Git/Option.cs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
namespace Dot.Git;
|
||||||
|
|
||||||
|
[Verb("git", HelpText = nameof(Str.GitTool), ResourceType = typeof(Str))]
|
||||||
|
public class Option : OptionBase
|
||||||
|
{
|
||||||
|
[Option('a', "args", HelpText = nameof(Str.GitArgs), Default = "status", ResourceType = typeof(Str))]
|
||||||
|
public string Args { get; set; }
|
||||||
|
|
||||||
|
[Option('e', "git-output-encoding", HelpText = nameof(Str.GitOutputEncoding), Default = "utf-8"
|
||||||
|
, ResourceType = typeof(Str))]
|
||||||
|
public string GitOutputEncoding { get; set; }
|
||||||
|
|
||||||
|
[Option('d', "max-recursion-depth", HelpText = nameof(Str.MaxRecursionDepth), Default = int.MaxValue
|
||||||
|
, ResourceType = typeof(Str))]
|
||||||
|
public int MaxRecursionDepth { get; set; }
|
||||||
|
|
||||||
|
[Value(0, HelpText = nameof(Str.FolderPath), Default = ".", ResourceType = typeof(Str))]
|
||||||
|
public string Path { get; set; }
|
||||||
|
}
|
@ -1,2 +1,3 @@
|
|||||||
global using ShellProgressBar;
|
global using ShellProgressBar;
|
||||||
global using CommandLine;
|
global using CommandLine;
|
||||||
|
global using Dot.Lang;
|
@ -2,16 +2,17 @@ using TextCopy;
|
|||||||
|
|
||||||
namespace Dot.Guid;
|
namespace Dot.Guid;
|
||||||
|
|
||||||
public sealed class Main : Tool<Option>
|
public sealed class Main : ToolBase<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;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -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 : OptionBase
|
||||||
{
|
{
|
||||||
[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
|
||||||
}
|
}
|
27
src/IP/Main.cs
Normal file
27
src/IP/Main.cs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
using System.Net.NetworkInformation;
|
||||||
|
using System.Net.Sockets;
|
||||||
|
|
||||||
|
namespace Dot.IP;
|
||||||
|
|
||||||
|
public sealed class Main : ToolBase<Option>
|
||||||
|
|
||||||
|
{
|
||||||
|
public Main(Option opt) : base(opt) { }
|
||||||
|
|
||||||
|
public override async Task Run()
|
||||||
|
{
|
||||||
|
foreach (var item in NetworkInterface.GetAllNetworkInterfaces()) {
|
||||||
|
if (item.NetworkInterfaceType != NetworkInterfaceType.Ethernet ||
|
||||||
|
item.OperationalStatus != OperationalStatus.Up)
|
||||||
|
continue;
|
||||||
|
foreach (var ip in item.GetIPProperties().UnicastAddresses)
|
||||||
|
if (ip.Address.AddressFamily == AddressFamily.InterNetwork)
|
||||||
|
Console.WriteLine(@$"{item.Name}: {ip.Address}");
|
||||||
|
}
|
||||||
|
|
||||||
|
using var http = new HttpClient();
|
||||||
|
Console.Write(Str.PublicIP);
|
||||||
|
var str = await http.GetStringAsync("http://httpbin.org/ip");
|
||||||
|
Console.WriteLine(str);
|
||||||
|
}
|
||||||
|
}
|
4
src/IP/Option.cs
Normal file
4
src/IP/Option.cs
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
namespace Dot.IP;
|
||||||
|
|
||||||
|
[Verb("ip", HelpText = nameof(Str.Ip), ResourceType = typeof(Str))]
|
||||||
|
public class Option : OptionBase { }
|
@ -2,5 +2,5 @@ namespace Dot;
|
|||||||
|
|
||||||
public interface ITool
|
public interface ITool
|
||||||
{
|
{
|
||||||
void Run();
|
Task Run();
|
||||||
}
|
}
|
68
src/Json/Main.cs
Normal file
68
src/Json/Main.cs
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
using System.Text.Json;
|
||||||
|
using NSExt.Extensions;
|
||||||
|
using TextCopy;
|
||||||
|
|
||||||
|
namespace Dot.Json;
|
||||||
|
|
||||||
|
public class Main : ToolBase<Option>
|
||||||
|
{
|
||||||
|
private readonly object _inputObj;
|
||||||
|
|
||||||
|
public Main(Option opt) : base(opt)
|
||||||
|
{
|
||||||
|
var inputText = ClipboardService.GetText();
|
||||||
|
if (inputText.NullOrWhiteSpace()) throw new ArgumentException(Str.InputTextIsEmpty);
|
||||||
|
|
||||||
|
try {
|
||||||
|
_inputObj = inputText.Object<object>();
|
||||||
|
}
|
||||||
|
catch (JsonException) {
|
||||||
|
try {
|
||||||
|
inputText = UnescapeString(inputText);
|
||||||
|
_inputObj = inputText.Object<object>();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
catch (JsonException) { }
|
||||||
|
|
||||||
|
throw new ArgumentException(Str.InvalidJsonString);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private async Task<string> ConvertToString()
|
||||||
|
{
|
||||||
|
var ret = await JsonCompress();
|
||||||
|
ret = ret.Replace("\"", "\\\"");
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Task<string> JsonCompress()
|
||||||
|
{
|
||||||
|
var ret = _inputObj.Json();
|
||||||
|
return Task.FromResult(ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Task<string> JsonFormat()
|
||||||
|
{
|
||||||
|
var ret = _inputObj.Json(true);
|
||||||
|
return Task.FromResult(ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string UnescapeString(string text)
|
||||||
|
{
|
||||||
|
return text.Replace("\\\"", "\"");
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task Run()
|
||||||
|
{
|
||||||
|
string result = null;
|
||||||
|
if (Opt.Compress)
|
||||||
|
result = await JsonCompress();
|
||||||
|
else if (Opt.ConvertToString)
|
||||||
|
result = await ConvertToString();
|
||||||
|
else if (Opt.Format) result = await JsonFormat();
|
||||||
|
|
||||||
|
if (result.NullOrWhiteSpace()) return;
|
||||||
|
await ClipboardService.SetTextAsync(result!);
|
||||||
|
}
|
||||||
|
}
|
15
src/Json/Option.cs
Normal file
15
src/Json/Option.cs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
namespace Dot.Json;
|
||||||
|
|
||||||
|
[Verb("json", HelpText = nameof(Str.Json), ResourceType = typeof(Str))]
|
||||||
|
public class Option : OptionBase
|
||||||
|
{
|
||||||
|
[Option('c', "compress", HelpText = nameof(Str.CompressJson), Default = false, ResourceType = typeof(Str))]
|
||||||
|
public bool Compress { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
[Option('s', "convert-to-string", HelpText = nameof(Str.FormatJson), Default = false, ResourceType = typeof(Str))]
|
||||||
|
public bool ConvertToString { get; set; }
|
||||||
|
|
||||||
|
[Option('f', "format", HelpText = nameof(Str.FormatJson), Default = true, ResourceType = typeof(Str))]
|
||||||
|
public bool Format { get; set; }
|
||||||
|
}
|
176
src/Lang/Str.en-US.resx
Normal file
176
src/Lang/Str.en-US.resx
Normal file
@ -0,0 +1,176 @@
|
|||||||
|
<?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>{0} files</value>
|
||||||
|
</data>
|
||||||
|
<data name="ShowMessageTemp" xml:space="preserve">
|
||||||
|
<value>Read: {0}/{1}, processed: {2}, skipped: {3}</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>
|
||||||
|
<data name="TimeTool" xml:space="preserve">
|
||||||
|
<value>Time synchronization tool</value>
|
||||||
|
</data>
|
||||||
|
<data name="TextTool" xml:space="preserve">
|
||||||
|
<value>Text encoding tool</value>
|
||||||
|
</data>
|
||||||
|
<data name="ScreenPixelTool" xml:space="preserve">
|
||||||
|
<value>Screen coordinate color selection tool</value>
|
||||||
|
</data>
|
||||||
|
<data name="ClickCopyColor" xml:space="preserve">
|
||||||
|
<value>Click the left mouse button to copy the colors and coordinates to the clipboard</value>
|
||||||
|
</data>
|
||||||
|
<data name="PublicIP" xml:space="preserve">
|
||||||
|
<value>Public network ip: </value>
|
||||||
|
</data>
|
||||||
|
<data name="ServerTime" xml:space="preserve">
|
||||||
|
<value>Synchronize local time</value>
|
||||||
|
</data>
|
||||||
|
<data name="Ip" xml:space="preserve">
|
||||||
|
<value>IP tools</value>
|
||||||
|
</data>
|
||||||
|
<data name="KeepSession" xml:space="preserve">
|
||||||
|
<value>Keep the session after executing the command</value>
|
||||||
|
</data>
|
||||||
|
<data name="NtpServerTime" xml:space="preserve">
|
||||||
|
<value>NTP server standard clock: {0}</value>
|
||||||
|
</data>
|
||||||
|
<data name="GitTool" xml:space="preserve">
|
||||||
|
<value>Git batch operation tool</value>
|
||||||
|
</data>
|
||||||
|
<data name="GitArgs" xml:space="preserve">
|
||||||
|
<value>Parameters passed to Git</value>
|
||||||
|
</data>
|
||||||
|
<data name="Ok" xml:space="preserve">
|
||||||
|
<value>OK</value>
|
||||||
|
</data>
|
||||||
|
<data name="FindGitReps" xml:space="preserve">
|
||||||
|
<value>Find all git repository directories under "{0}"...</value>
|
||||||
|
</data>
|
||||||
|
<data name="GitOutputEncoding" xml:space="preserve">
|
||||||
|
<value>Git output encoding</value>
|
||||||
|
</data>
|
||||||
|
<data name="MaxRecursionDepth" xml:space="preserve">
|
||||||
|
<value>Directory search depth</value>
|
||||||
|
</data>
|
||||||
|
<data name="InvalidJsonString" xml:space="preserve">
|
||||||
|
<value>Clipboard does not contain correct Json string</value>
|
||||||
|
</data>
|
||||||
|
<data name="Json" xml:space="preserve">
|
||||||
|
<value>JsonTools</value>
|
||||||
|
</data>
|
||||||
|
<data name="CompressJson" xml:space="preserve">
|
||||||
|
<value>Compress Json text</value>
|
||||||
|
</data>
|
||||||
|
<data name="FormatJson" xml:space="preserve">
|
||||||
|
<value>Format JSON text</value>
|
||||||
|
</data>
|
||||||
|
<data name="GeneratorClass" xml:space="preserve">
|
||||||
|
<value>generate entity classes</value>
|
||||||
|
</data>
|
||||||
|
<data name="JsonToString" xml:space="preserve">
|
||||||
|
<value>Json text escaped into a string</value>
|
||||||
|
</data>
|
||||||
|
</root>
|
185
src/Lang/Str.resx
Normal file
185
src/Lang/Str.resx
Normal file
@ -0,0 +1,185 @@
|
|||||||
|
<?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="InvalidJsonString" xml:space="preserve">
|
||||||
|
<value>剪贴板未包含正确的Json字符串</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="TimeTool" xml:space="preserve">
|
||||||
|
<value>时间同步工具</value>
|
||||||
|
</data>
|
||||||
|
<data name="Ip" xml:space="preserve">
|
||||||
|
<value>IP工具</value>
|
||||||
|
</data>
|
||||||
|
<data name="Json" xml:space="preserve">
|
||||||
|
<value>Json工具</value>
|
||||||
|
</data>
|
||||||
|
<data name="ScreenPixelTool" xml:space="preserve">
|
||||||
|
<value>屏幕坐标颜色选取工具</value>
|
||||||
|
</data>
|
||||||
|
<data name="TextTool" 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="GitOutputEncoding" xml:space="preserve">
|
||||||
|
<value>Git输出编码</value>
|
||||||
|
</data>
|
||||||
|
<data name="MaxRecursionDepth" xml:space="preserve">
|
||||||
|
<value>目录检索深度</value>
|
||||||
|
</data>
|
||||||
|
<data name="FileSearchPattern" xml:space="preserve">
|
||||||
|
<value>文件通配符</value>
|
||||||
|
</data>
|
||||||
|
<data name="KeepSession" 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="ServerTime" 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="GitTool" xml:space="preserve">
|
||||||
|
<value>Git批量操作工具</value>
|
||||||
|
</data>
|
||||||
|
<data name="UseUppercase" xml:space="preserve">
|
||||||
|
<value>使用大写输出</value>
|
||||||
|
</data>
|
||||||
|
<data name="GitArgs" xml:space="preserve">
|
||||||
|
<value>传递给Git的参数</value>
|
||||||
|
</data>
|
||||||
|
<data name="CompressJson" xml:space="preserve">
|
||||||
|
<value>压缩Json文本</value>
|
||||||
|
</data>
|
||||||
|
<data name="FormatJson" xml:space="preserve">
|
||||||
|
<value>格式化Json文本</value>
|
||||||
|
</data>
|
||||||
|
<data name="GeneratorClass" xml:space="preserve">
|
||||||
|
<value>生成实体类</value>
|
||||||
|
</data>
|
||||||
|
<data name="JsonToString" xml:space="preserve">
|
||||||
|
<value>Json文本转义成字符串</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="NtpServerTime" xml:space="preserve">
|
||||||
|
<value>NTP 服务器标准时钟: {0}</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>
|
||||||
|
<data name="ClickCopyColor" xml:space="preserve">
|
||||||
|
<value>单击鼠标左键复制颜色和坐标到剪贴板</value>
|
||||||
|
</data>
|
||||||
|
<data name="PublicIP" xml:space="preserve">
|
||||||
|
<value>Public network ip... </value>
|
||||||
|
</data>
|
||||||
|
<data name="Ok" xml:space="preserve">
|
||||||
|
<value>OK</value>
|
||||||
|
</data>
|
||||||
|
<data name="FindGitReps" xml:space="preserve">
|
||||||
|
<value>查找 "{0}" 下所有git仓库目录... </value>
|
||||||
|
</data>
|
||||||
|
</root>
|
86
src/Lang/Str.tt
Normal file
86
src/Lang/Str.tt
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
<#@ template language="C#" #>
|
||||||
|
<#@ assembly name="System.Xml" #>
|
||||||
|
<#@ output encoding="utf-8" extension="Designer.cs" #>
|
||||||
|
<#@ import namespace="System.Xml" #>
|
||||||
|
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// <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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
<#
|
||||||
|
var xml = new XmlDocument();
|
||||||
|
xml.Load("Str.resx");
|
||||||
|
foreach (XmlNode data in xml.SelectNodes("//root/data")) {
|
||||||
|
#>
|
||||||
|
/// <summary>
|
||||||
|
/// <#= data.SelectSingleNode("value").InnerText #>
|
||||||
|
/// </summary>
|
||||||
|
public static string <#= data.Attributes["name"].Value #> {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("<#= data.Attributes["name"].Value #>", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
<#
|
||||||
|
}
|
||||||
|
#>
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
7
src/Option.cs
Normal file
7
src/Option.cs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
namespace Dot;
|
||||||
|
|
||||||
|
public abstract class OptionBase : IOption
|
||||||
|
{
|
||||||
|
[Option('k', "keep-session", HelpText = nameof(Str.KeepSession), Default = false, ResourceType = typeof(Str))]
|
||||||
|
public virtual bool KeepSession { get; set; }
|
||||||
|
}
|
@ -1,4 +1,5 @@
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using System.Text;
|
||||||
using Dot;
|
using Dot;
|
||||||
|
|
||||||
Type[] LoadVerbs()
|
Type[] LoadVerbs()
|
||||||
@ -10,19 +11,26 @@ Type[] LoadVerbs()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Run(object args)
|
async Task Run(object args)
|
||||||
{
|
{
|
||||||
var tool = ToolsFactory.Create(args as IOption);
|
if (args is not OptionBase option) return;
|
||||||
tool.Run();
|
|
||||||
|
var tool = ToolsFactory.Create(option);
|
||||||
|
await tool.Run();
|
||||||
|
if (option!.KeepSession) {
|
||||||
|
Console.WriteLine();
|
||||||
|
Console.WriteLine(Str.PressAnyKey);
|
||||||
|
Console.ReadKey();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Entry Point
|
// Entry Point
|
||||||
|
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
|
||||||
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);
|
||||||
|
@ -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 : ToolBase<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
21
src/Pwd/Option.cs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
namespace Dot.Pwd;
|
||||||
|
|
||||||
|
[Verb("pwd", HelpText = nameof(Str.RandomPasswordGenerator), ResourceType = typeof(Str))]
|
||||||
|
public class Option : OptionBase
|
||||||
|
{
|
||||||
|
[Flags]
|
||||||
|
public enum GenerateTypes
|
||||||
|
{
|
||||||
|
Number = 0b0001
|
||||||
|
, LowerCaseLetter = 0b0010
|
||||||
|
, UpperCaseLetter = 0b0100
|
||||||
|
, SpecialCharacter = 0b1000
|
||||||
|
}
|
||||||
|
|
||||||
|
[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; }
|
||||||
|
}
|
@ -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; }
|
|
||||||
}
|
|
@ -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; }
|
|
||||||
}
|
|
@ -1,9 +1,9 @@
|
|||||||
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 : ToolBase<Option>, IDisposable
|
||||||
{
|
{
|
||||||
private int _breakCnt;
|
private int _breakCnt;
|
||||||
private bool _disposed;
|
private bool _disposed;
|
||||||
@ -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;
|
int spacesCnt;
|
||||||
|
|
||||||
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
4
src/RmBlank/Option.cs
Normal 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
110
src/RmBom/Main.cs
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
|
||||||
|
namespace Dot.RmBom;
|
||||||
|
|
||||||
|
public sealed class Main : ToolBase<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
4
src/RmBom/Option.cs
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
namespace Dot.RmBom;
|
||||||
|
|
||||||
|
[Verb("rm-bom", HelpText = nameof(Str.TrimUtf8Bom), ResourceType = typeof(Str))]
|
||||||
|
public class Option : DirOption { }
|
@ -5,7 +5,7 @@ using TextCopy;
|
|||||||
|
|
||||||
namespace Dot.Text;
|
namespace Dot.Text;
|
||||||
|
|
||||||
public sealed class Main : Tool<Option>
|
public sealed class Main : ToolBase<Option>
|
||||||
{
|
{
|
||||||
private ref struct Output
|
private ref struct Output
|
||||||
{
|
{
|
||||||
@ -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,20 @@ public sealed class Main : Tool<Option>
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void ParseAndShow(string text)
|
||||||
|
{
|
||||||
|
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 +99,12 @@ 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);
|
|
||||||
PrintOutput(unicodeLittleEndian);
|
|
||||||
PrintOutput(unicodeBigEndian);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,8 +1,8 @@
|
|||||||
namespace Dot.Text;
|
namespace Dot.Text;
|
||||||
|
|
||||||
[Verb("text", HelpText = "文本编码工具")]
|
[Verb("text", HelpText = nameof(Str.TextTool), ResourceType = typeof(Str))]
|
||||||
public class Option : IOption
|
public class Option : OptionBase
|
||||||
{
|
{
|
||||||
[Value(0, MetaName = "文本", HelpText = "要处理的文本,不指定此参数:取剪贴板值")]
|
[Value(0, HelpText = nameof(Str.TextTobeProcessed), ResourceType = typeof(Str))]
|
||||||
public string Text { get; set; }
|
public string Text { get; set; }
|
||||||
}
|
}
|
240
src/Time/Main.cs
Normal file
240
src/Time/Main.cs
Normal file
@ -0,0 +1,240 @@
|
|||||||
|
using System.Diagnostics;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using System.Net.Sockets;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
namespace Dot.Time;
|
||||||
|
|
||||||
|
public sealed class Main : ToolBase<Option>
|
||||||
|
{
|
||||||
|
private record Server
|
||||||
|
{
|
||||||
|
public int ConsoleRowIndex;
|
||||||
|
public TimeSpan Offset;
|
||||||
|
public ServerStatues Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 const string _OUTPUT_TEMP = "{0,-30} {1,20} {2,20}";
|
||||||
|
private static readonly object _lockObj = new();
|
||||||
|
private int _procedCnt;
|
||||||
|
private readonly int _serverCnt;
|
||||||
|
|
||||||
|
private readonly string[] _srvAddr = {
|
||||||
|
"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 readonly Dictionary<string, Server> _srvStatus;
|
||||||
|
private int _successCnt;
|
||||||
|
|
||||||
|
|
||||||
|
public Main(Option opt) : base(opt)
|
||||||
|
{
|
||||||
|
_serverCnt = _srvAddr.Length;
|
||||||
|
var i = 0;
|
||||||
|
_srvStatus = _srvAddr.ToDictionary(
|
||||||
|
x => x, _ => new Server { Status = ServerStatues.Ready, ConsoleRowIndex = ++i });
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void ChangeStatus(KeyValuePair<string, Server> server, ServerStatues status
|
||||||
|
, TimeSpan offset = default)
|
||||||
|
{
|
||||||
|
server.Value.Status = status;
|
||||||
|
server.Value.Offset = offset;
|
||||||
|
DrawTextInConsole(0, server.Value.ConsoleRowIndex
|
||||||
|
, string.Format(_OUTPUT_TEMP, server.Key, server.Value.Status
|
||||||
|
, status == ServerStatues.Succeed ? server.Value.Offset : string.Empty));
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task DrawLoading()
|
||||||
|
{
|
||||||
|
char[] loading = { '-', '\\', '|', '/' };
|
||||||
|
var loadingIndex = 0;
|
||||||
|
while (true) {
|
||||||
|
if (Volatile.Read(ref _procedCnt) == _serverCnt) break;
|
||||||
|
await Task.Delay(100);
|
||||||
|
++loadingIndex;
|
||||||
|
for (var i = 0; i != _serverCnt; ++i)
|
||||||
|
DrawTextInConsole(
|
||||||
|
34, i + 1
|
||||||
|
, _srvStatus[_srvAddr[i]].Status is ServerStatues.Succeed or ServerStatues.Failed
|
||||||
|
? " "
|
||||||
|
: loading[loadingIndex % 4].ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
Debug.WriteLine(Environment.CurrentManagedThreadId + ":" + DateTime.Now.ToString("O"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void DrawTextInConsole(int left, int top, string text)
|
||||||
|
{
|
||||||
|
lock (_lockObj) {
|
||||||
|
Console.SetCursorPosition(left, top);
|
||||||
|
Console.Write(text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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 void PrintTemplate()
|
||||||
|
{
|
||||||
|
Console.Clear();
|
||||||
|
Console.CursorVisible = false;
|
||||||
|
var row = //
|
||||||
|
_srvStatus.Select(x //
|
||||||
|
=> string.Format(_OUTPUT_TEMP, x.Key, x.Value.Status
|
||||||
|
, x.Value.Offset == TimeSpan.Zero ? string.Empty : x.Value.Offset));
|
||||||
|
|
||||||
|
|
||||||
|
Console.WriteLine(_OUTPUT_TEMP, Str.Server, Str.Status, Str.LocalClockOffset);
|
||||||
|
Console.WriteLine(string.Join(Environment.NewLine, row));
|
||||||
|
}
|
||||||
|
|
||||||
|
private ValueTask ServerHandle(KeyValuePair<string, Server> server)
|
||||||
|
{
|
||||||
|
ChangeStatus(server, ServerStatues.Connecting);
|
||||||
|
var offset = GetNtpOffset(server.Key);
|
||||||
|
Interlocked.Increment(ref _procedCnt);
|
||||||
|
|
||||||
|
if (offset == TimeSpan.Zero) {
|
||||||
|
ChangeStatus(server, ServerStatues.Failed);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Interlocked.Increment(ref _successCnt);
|
||||||
|
ChangeStatus(server, ServerStatues.Succeed, offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ValueTask.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[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()
|
||||||
|
{
|
||||||
|
PrintTemplate();
|
||||||
|
var tLoading = DrawLoading();
|
||||||
|
|
||||||
|
|
||||||
|
await Parallel.ForEachAsync(_srvStatus
|
||||||
|
, new ParallelOptions { MaxDegreeOfParallelism = _MAX_DEGREE_OF_PARALLELISM }
|
||||||
|
, (server, _) => ServerHandle(server));
|
||||||
|
|
||||||
|
await tLoading;
|
||||||
|
|
||||||
|
|
||||||
|
var avgOffset = TimeSpan.FromTicks((long)_srvStatus //
|
||||||
|
.Where(x => x.Value.Status == ServerStatues.Succeed)
|
||||||
|
.Average(x => x.Value.Offset.Ticks));
|
||||||
|
|
||||||
|
Console.SetCursorPosition(0, _serverCnt + 1);
|
||||||
|
Console.WriteLine(Str.NtpReceiveDone, _successCnt, _serverCnt, avgOffset.TotalMilliseconds);
|
||||||
|
|
||||||
|
if (!Opt.Sync) {
|
||||||
|
if (!Opt.KeepSession) return;
|
||||||
|
|
||||||
|
var waitObj = new ManualResetEvent(false);
|
||||||
|
var _ = Task.Run(async () => {
|
||||||
|
var top = Console.GetCursorPosition().Top;
|
||||||
|
while (true) {
|
||||||
|
Console.SetCursorPosition(0, top);
|
||||||
|
Console.Write(Str.NtpServerTime, (DateTime.Now - avgOffset).ToString("O"));
|
||||||
|
waitObj.Set();
|
||||||
|
await Task.Delay(100);
|
||||||
|
}
|
||||||
|
// ReSharper disable once FunctionNeverReturns
|
||||||
|
});
|
||||||
|
waitObj.WaitOne();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SetSysteTime(DateTime.Now - avgOffset);
|
||||||
|
Console.WriteLine(Str.LocalTimeSyncDone);
|
||||||
|
}
|
||||||
|
}
|
11
src/Time/Option.cs
Normal file
11
src/Time/Option.cs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
namespace Dot.Time;
|
||||||
|
|
||||||
|
[Verb("time", HelpText = nameof(Str.TimeTool), ResourceType = typeof(Str))]
|
||||||
|
public class Option : OptionBase
|
||||||
|
{
|
||||||
|
[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 = 2000, ResourceType = typeof(Str))]
|
||||||
|
public int Timeout { get; set; }
|
||||||
|
}
|
@ -1,8 +1,8 @@
|
|||||||
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 : ToolBase<Option>, IDisposable
|
||||||
{
|
{
|
||||||
private int _breakCnt;
|
private int _breakCnt;
|
||||||
private bool _disposed;
|
private bool _disposed;
|
||||||
@ -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
4
src/ToLf/Option.cs
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
namespace Dot.ToLf;
|
||||||
|
|
||||||
|
[Verb("tolf", HelpText = nameof(Str.ConvertEndOfLineToLF), ResourceType = typeof(Str))]
|
||||||
|
public class Option : DirOption { }
|
62
src/Tool.cs
62
src/Tool.cs
@ -1,62 +0,0 @@
|
|||||||
namespace Dot;
|
|
||||||
|
|
||||||
public abstract class Tool<TOption> : ITool
|
|
||||||
{
|
|
||||||
protected readonly ProgressBarOptions //
|
|
||||||
DefaultProgressBarOptions = new() {
|
|
||||||
MessageEncodingName = "utf-8"
|
|
||||||
, ProgressBarOnBottom = true
|
|
||||||
, ForegroundColor = ConsoleColor.Yellow
|
|
||||||
, ForegroundColorDone = ConsoleColor.DarkGreen
|
|
||||||
, BackgroundColor = ConsoleColor.DarkGray
|
|
||||||
, BackgroundCharacter = '\u2593'
|
|
||||||
};
|
|
||||||
|
|
||||||
protected virtual TOption Opt { get; set; }
|
|
||||||
|
|
||||||
protected Tool(TOption opt)
|
|
||||||
{
|
|
||||||
Opt = opt;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static IEnumerable<string> EnumerateFiles(string path, string searchPattern)
|
|
||||||
{
|
|
||||||
var fileList = Directory
|
|
||||||
.EnumerateFiles(path, searchPattern
|
|
||||||
, new EnumerationOptions {
|
|
||||||
RecurseSubdirectories = true
|
|
||||||
, AttributesToSkip = FileAttributes.ReparsePoint
|
|
||||||
})
|
|
||||||
.Where(x => !new[] { ".git", "node_modules" }.Any(
|
|
||||||
y => x.Contains(y, StringComparison.OrdinalIgnoreCase)));
|
|
||||||
return fileList;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static void MoveFile(string source, string dest)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
File.Move(source, dest, true);
|
|
||||||
}
|
|
||||||
catch (UnauthorizedAccessException) {
|
|
||||||
File.SetAttributes(dest, new FileInfo(dest).Attributes & ~FileAttributes.ReadOnly);
|
|
||||||
File.Move(source, dest, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static FileStream OpenFileToWrite(string file)
|
|
||||||
{
|
|
||||||
FileStream fsr;
|
|
||||||
try {
|
|
||||||
fsr = new FileStream(file, FileMode.Open, FileAccess.ReadWrite, FileShare.Read);
|
|
||||||
}
|
|
||||||
catch (UnauthorizedAccessException) {
|
|
||||||
File.SetAttributes(file, new FileInfo(file).Attributes & ~FileAttributes.ReadOnly);
|
|
||||||
fsr = new FileStream(file, FileMode.Open, FileAccess.ReadWrite, FileShare.Read);
|
|
||||||
}
|
|
||||||
|
|
||||||
return fsr;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public abstract void Run();
|
|
||||||
}
|
|
108
src/ToolBase.cs
Normal file
108
src/ToolBase.cs
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
namespace Dot;
|
||||||
|
|
||||||
|
public abstract class ToolBase<TOption> : ITool where TOption : OptionBase
|
||||||
|
{
|
||||||
|
// ReSharper disable once StaticMemberInGenericType
|
||||||
|
private static SpinLock _spinlock;
|
||||||
|
|
||||||
|
protected readonly ProgressBarOptions //
|
||||||
|
DefaultProgressBarOptions = new() {
|
||||||
|
MessageEncodingName = "utf-8"
|
||||||
|
, ProgressBarOnBottom = true
|
||||||
|
, ForegroundColor = ConsoleColor.Yellow
|
||||||
|
, ForegroundColorDone = ConsoleColor.DarkGreen
|
||||||
|
, BackgroundColor = ConsoleColor.DarkGray
|
||||||
|
, BackgroundCharacter = '\u2500'
|
||||||
|
, ProgressCharacter = '\u2500'
|
||||||
|
};
|
||||||
|
|
||||||
|
protected TOption Opt { get; }
|
||||||
|
|
||||||
|
protected ToolBase(TOption opt)
|
||||||
|
{
|
||||||
|
Opt = opt;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected static void ConcurrentWrite(int x, int y, string text)
|
||||||
|
{
|
||||||
|
var lockTaken = false;
|
||||||
|
try {
|
||||||
|
_spinlock.Enter(ref lockTaken);
|
||||||
|
Console.SetCursorPosition(x, y);
|
||||||
|
Console.Write(text);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
if (lockTaken) _spinlock.Exit(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static IEnumerable<string> EnumerateFiles(string path, string searchPattern)
|
||||||
|
{
|
||||||
|
var fileList = Directory
|
||||||
|
.EnumerateFiles(path, searchPattern
|
||||||
|
, new EnumerationOptions {
|
||||||
|
RecurseSubdirectories = true
|
||||||
|
, AttributesToSkip = FileAttributes.ReparsePoint
|
||||||
|
})
|
||||||
|
.Where(x => !new[] { ".git", "node_modules" }.Any(
|
||||||
|
y => x.Contains(y, StringComparison.OrdinalIgnoreCase)));
|
||||||
|
return fileList;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static Task LoadingAnimate(int x, int y, out CancellationTokenSource cts)
|
||||||
|
{
|
||||||
|
char[] animateChars = { '-', '\\', '|', '/' };
|
||||||
|
long counter = 0;
|
||||||
|
|
||||||
|
cts = new CancellationTokenSource();
|
||||||
|
var cancelToken = cts.Token;
|
||||||
|
|
||||||
|
return Task.Run(async () => {
|
||||||
|
for (;;) {
|
||||||
|
if (cancelToken.IsCancellationRequested) {
|
||||||
|
ConcurrentWrite(x, y, @" ");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ConcurrentWrite(x, y, animateChars[counter++ % 4].ToString());
|
||||||
|
|
||||||
|
await Task.Delay(100);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static void MoveFile(string source, string dest)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
File.Move(source, dest, true);
|
||||||
|
}
|
||||||
|
catch (UnauthorizedAccessException) {
|
||||||
|
File.SetAttributes(dest, new FileInfo(dest).Attributes & ~FileAttributes.ReadOnly);
|
||||||
|
File.Move(source, dest, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static FileStream OpenFileStream(string file, FileMode mode, FileAccess access
|
||||||
|
, FileShare share = FileShare.Read)
|
||||||
|
{
|
||||||
|
FileStream fsr = null;
|
||||||
|
try {
|
||||||
|
fsr = new FileStream(file, mode, access, share);
|
||||||
|
}
|
||||||
|
catch (UnauthorizedAccessException) {
|
||||||
|
try {
|
||||||
|
File.SetAttributes(file, new FileInfo(file).Attributes & ~FileAttributes.ReadOnly);
|
||||||
|
fsr = new FileStream(file, mode, access, share);
|
||||||
|
}
|
||||||
|
catch (Exception) {
|
||||||
|
// ignored
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (IOException) { }
|
||||||
|
|
||||||
|
return fsr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract Task Run();
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
using Dot.TrimUtf8Bom;
|
using Dot.RmBom;
|
||||||
|
|
||||||
namespace Dot;
|
namespace Dot;
|
||||||
|
|
||||||
@ -7,13 +7,18 @@ 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)
|
||||||
|
, Color.Option o => new Color.Main(o)
|
||||||
|
, IP.Option o => new IP.Main(o)
|
||||||
|
, Git.Option o => new Git.Main(o)
|
||||||
|
, Json.Option o => new Json.Main(o)
|
||||||
|
, _ => throw new ArgumentOutOfRangeException(nameof(option))
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -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);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
@ -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; }
|
|
||||||
}
|
|
@ -2,16 +2,17 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>net7.0</TargetFramework>
|
<TargetFramework>net7.0-windows</TargetFramework>
|
||||||
|
<UseWindowsForms>true</UseWindowsForms>
|
||||||
<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.5</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 +30,28 @@
|
|||||||
<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>
|
||||||
|
|
||||||
|
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
|
||||||
|
<ItemGroup Condition="!Exists('Lang\Str.Designer.cs')">
|
||||||
|
<Compile Include="Lang\Str.Designer.cs"/>
|
||||||
|
</ItemGroup>
|
||||||
|
<Exec Command="dotnet tool restore" StdOutEncoding="utf-8"/>
|
||||||
|
<Exec WorkingDirectory="$(ProjectDir)\Lang" Command="dotnet t4 Str.tt" StdOutEncoding="utf-8"/>
|
||||||
|
</Target>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
Reference in New Issue
Block a user