Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################
* text=auto

###############################################################################
# Set default behavior for command prompt diff.
#
# This is need for earlier builds of msysgit that does not have it on by
# default for csharp files.
# Note: This is only used by command line
###############################################################################
#*.cs diff=csharp

###############################################################################
# Set the merge driver for project and solution files
#
# Merging from the command prompt will add diff markers to the files if there
# are conflicts (Merging from VS is not affected by the settings below, in VS
# the diff markers are never inserted). Diff markers may cause the following
# file extensions to fail to load in VS. An alternative would be to treat
# these files as binary and thus will always conflict and require user
# intervention with every merge. To do so, just uncomment the entries below
###############################################################################
#*.sln merge=binary
#*.csproj merge=binary
#*.vbproj merge=binary
#*.vcxproj merge=binary
#*.vcproj merge=binary
#*.dbproj merge=binary
#*.fsproj merge=binary
#*.lsproj merge=binary
#*.wixproj merge=binary
#*.modelproj merge=binary
#*.sqlproj merge=binary
#*.wwaproj merge=binary

###############################################################################
# behavior for image files
#
# image files are treated as binary by default.
###############################################################################
#*.jpg binary
#*.png binary
#*.gif binary

###############################################################################
# diff behavior for common document formats
#
# Convert binary document formats to text before diffing them. This feature
# is only available from the command line. Turn it on by uncommenting the
# entries below.
###############################################################################
#*.doc diff=astextplain
#*.DOC diff=astextplain
#*.docx diff=astextplain
#*.DOCX diff=astextplain
#*.dot diff=astextplain
#*.DOT diff=astextplain
#*.pdf diff=astextplain
#*.PDF diff=astextplain
#*.rtf diff=astextplain
#*.RTF diff=astextplain
23 changes: 23 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
build
bin
obj
packages
Migrations
_gsdata_
_ReSharper*
TestResults
app_data
nuget.config
*.suo
*.user
*.log
*.pubxml
*.publish.xml
.svn
.vs
*.dbmdl
*.jfm
*.exe
.idea
node_modules
dist
4 changes: 4 additions & 0 deletions .tgitconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[hook "startcommit"]
cmdline = code-format.cmd
wait = true
show = true
7 changes: 7 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project>
<PropertyGroup>
<BaseOutputPath>../build/temp/bin</BaseOutputPath>
<BaseIntermediateOutputPath>../build/temp/obj</BaseIntermediateOutputPath>
<MSBuildProjectExtensionsPath>../build/temp/obj</MSBuildProjectExtensionsPath>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# dot
功能全面的实用工具-程序员的瑞士军刀
功能全面的实用工具-程序员的瑞士军刀
3 changes: 3 additions & 0 deletions build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dotnet build
dotnet publish -c Release -r win-x64 --sc -p:PublishSingleFile=true -o ./build/win-x64
rm -r ./build/temp
3 changes: 3 additions & 0 deletions code-format.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dot trim-utf8-bom
dot remove-whitespace
dot convert-lf
22 changes: 22 additions & 0 deletions dot.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "dot", "src\dot.csproj", "{E7608D54-4A3B-4B4B-ADA0-7852987CA21F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E7608D54-4A3B-4B4B-ADA0-7852987CA21F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E7608D54-4A3B-4B4B-ADA0-7852987CA21F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E7608D54-4A3B-4B4B-ADA0-7852987CA21F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E7608D54-4A3B-4B4B-ADA0-7852987CA21F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
45 changes: 45 additions & 0 deletions dot.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<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">
<s:String x:Key="/Default/CodeStyle/CSharpFileLayoutPatterns/Pattern/@EntryValue">&lt;?xml version="1.0" encoding="utf-16"?&gt;
&lt;Patterns xmlns="urn:schemas-jetbrains-com:member-reordering-patterns"&gt;
&lt;TypePattern&gt;
&lt;Entry&gt;
&lt;Entry.SortBy&gt;
&lt;Kind&gt;
&lt;Kind.Order&gt;
&lt;DeclarationKind&gt;Interface&lt;/DeclarationKind&gt;
&lt;DeclarationKind&gt;Class&lt;/DeclarationKind&gt;
&lt;DeclarationKind&gt;Enum&lt;/DeclarationKind&gt;
&lt;DeclarationKind&gt;Struct&lt;/DeclarationKind&gt;
&lt;DeclarationKind&gt;Delegate&lt;/DeclarationKind&gt;
&lt;DeclarationKind&gt;Event&lt;/DeclarationKind&gt;
&lt;DeclarationKind&gt;Constant&lt;/DeclarationKind&gt;
&lt;DeclarationKind&gt;Field&lt;/DeclarationKind&gt;
&lt;DeclarationKind&gt;Property&lt;/DeclarationKind&gt;
&lt;DeclarationKind&gt;Constructor&lt;/DeclarationKind&gt;
&lt;DeclarationKind&gt;Destructor&lt;/DeclarationKind&gt;
&lt;DeclarationKind&gt;Indexer&lt;/DeclarationKind&gt;
&lt;DeclarationKind&gt;Method&lt;/DeclarationKind&gt;
&lt;/Kind.Order&gt;
&lt;/Kind&gt;
&lt;Access&gt;
&lt;Access.Order&gt;
&lt;AccessModifier&gt;Private&lt;/AccessModifier&gt;
&lt;AccessModifier&gt;PrivateProtected&lt;/AccessModifier&gt;
&lt;AccessModifier&gt;Protected&lt;/AccessModifier&gt;
&lt;AccessModifier&gt;ProtectedInternal&lt;/AccessModifier&gt;
&lt;AccessModifier&gt;Internal&lt;/AccessModifier&gt;
&lt;AccessModifier&gt;Public&lt;/AccessModifier&gt;
&lt;/Access.Order&gt;
&lt;/Access&gt;
&lt;Name /&gt;
&lt;/Entry.SortBy&gt;
&lt;/Entry&gt;
&lt;/TypePattern&gt;
&lt;/Patterns&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=Constants/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AA_BB" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateConstants/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="_" Suffix="" Style="AA_BB" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateStaticReadonly/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=StaticReadonly/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<s:Boolean x:Key="/Default/ReSpeller/ReSpellerEnabled/@EntryValue">False</s:Boolean>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=TooWideLocalVariableScope/@EntryIndexedValue">HINT</s:String>
</wpf:ResourceDictionary>
1 change: 1 addition & 0 deletions git-clean.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
git reset --hard | git clean -d -fx .
41 changes: 41 additions & 0 deletions src/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
[*]
indent_style = space
indent_size = 4
tab_width = 4


# 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
113 changes: 113 additions & 0 deletions src/Convert2Lf/Main.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
using System.Diagnostics.CodeAnalysis;

namespace Dot.Convert2Lf;

public sealed class Main : Tool<Option>, IDisposable
{
private int _breakCnt;
private bool _disposed;
private static readonly object _lockObj = new();
private int _procedCnt;
private int _replaceCnt;
private ChildProgressBar _step2Bar;
private int _totalCnt;
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 FileHandle(string file)
{
_step2Bar.Tick();
ShowMessage(1, 0, 0);

var tmpFile = $"{file}.tmp";
var isReplaced = false;
var isBin = false;
int data;

using (var fsr = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) {
using var fsw = new FileStream(tmpFile, FileMode.OpenOrCreate, FileAccess.Write);

while ((data = fsr.ReadByte()) != -1) {
switch (data) {
case 0x0d when fsr.ReadByte() == 0x0a: // crlf windows
fsw.WriteByte(0x0a);
isReplaced = true;
continue;
case 0x0d: //cr macos
fsw.WriteByte(0x0a);
fsr.Seek(-1, SeekOrigin.Current);
isReplaced = true;
continue;
case 0x00 or 0xff: //非文本文件
isBin = true;
break;
default:
fsw.WriteByte((byte)data);
continue;
}

break;
}
}


if (isReplaced && !isBin) {
MoveFile(tmpFile, file);

ShowMessage(0, 1, 0);
}
else {
File.Delete(tmpFile);
ShowMessage(0, 0, 1);
}
}


private void ShowMessage(int procedCnt, int replaceCnt, int breakCnt)
{
lock (_lockObj) {
_procedCnt += procedCnt;
_replaceCnt += replaceCnt;
_breakCnt += breakCnt;
_step2Bar.Message = $"已处理:{_procedCnt}/{_totalCnt},替换:{_replaceCnt},跳过:{_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}”不存在");


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, FileHandle);
}
}
11 changes: 11 additions & 0 deletions src/Convert2Lf/Option.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
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; }
}
2 changes: 2 additions & 0 deletions src/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
global using ShellProgressBar;
global using CommandLine;
17 changes: 17 additions & 0 deletions src/Guid/Main.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using TextCopy;

namespace Dot.Guid;

public sealed class Main : Tool<Option>
{
public Main(Option opt) : base(opt) { }


public override void Run()
{
var guid = System.Guid.NewGuid().ToString();
if (Opt.Upper) guid = guid.ToUpper();
ClipboardService.SetText(guid);
Console.WriteLine($"已复制到剪贴板:{guid}");
}
}
8 changes: 8 additions & 0 deletions src/Guid/Option.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Dot.Guid;

[Verb("guid", HelpText = "GUID工具")]
public class Option : IOption
{
[Option('u', "upper", HelpText = "大写", Default = false)]
public bool Upper { get; set; } //normal options here
}
Loading