mirror of
https://github.com/nsnail/dot.git
synced 2025-04-14 09:32:49 +08:00
parent
2efc7ac76e
commit
247e35484c
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"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -802,4 +802,5 @@ FodyWeavers.xsd
|
||||
|
||||
# User Define
|
||||
build/
|
||||
nuget.config
|
||||
nuget.config
|
||||
*.[Dd]esigner.cs
|
@ -1,6 +1,6 @@
|
||||
namespace Dot.Color;
|
||||
|
||||
public sealed class Main : Tool<Option>
|
||||
public sealed class Main : ToolBase<Option>
|
||||
|
||||
{
|
||||
public Main(Option opt) : base(opt) { }
|
||||
|
@ -1,4 +1,4 @@
|
||||
namespace Dot.Color;
|
||||
|
||||
[Verb("color", HelpText = nameof(Str.ScreenPixelTool), ResourceType = typeof(Str))]
|
||||
public class Option : IOption { }
|
||||
public class Option : OptionBase { }
|
@ -2,48 +2,47 @@ using System.Runtime.InteropServices;
|
||||
|
||||
namespace Dot.Color;
|
||||
|
||||
public static class Win32
|
||||
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;
|
||||
|
||||
|
||||
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();
|
||||
|
||||
|
||||
[DllImport(_USER32_DLL)]
|
||||
public static extern nint CallNextHookEx(nint hhk, int nCode, nint wParam, nint lParam);
|
||||
|
||||
[DllImport(_KERNEL32_DLL)]
|
||||
public static extern nint GetConsoleWindow();
|
||||
[LibraryImport(_USER32_DLL)]
|
||||
internal static partial nint GetDesktopWindow();
|
||||
|
||||
|
||||
[DllImport(_USER32_DLL)]
|
||||
public static extern 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);
|
||||
|
||||
[DllImport(_KERNEL32_DLL, CharSet = CharSet.Unicode)]
|
||||
public static extern nint GetModuleHandle(string lpModuleName);
|
||||
[LibraryImport(_USER32_DLL)]
|
||||
internal static partial nint GetWindowDC(nint hWnd);
|
||||
|
||||
[DllImport(_GDI32_DLL)]
|
||||
public static extern uint GetPixel(nint dc, int x, int y);
|
||||
[LibraryImport(_USER32_DLL)]
|
||||
internal static partial int ReleaseDC(nint hWnd, nint dc);
|
||||
|
||||
[DllImport(_USER32_DLL)]
|
||||
public static extern nint GetWindowDC(nint hWnd);
|
||||
[LibraryImport(_USER32_DLL)]
|
||||
internal static partial nint SetWindowsHookEx(int idHook, LowLevelMouseProc lpfn, nint hMod, uint dwThreadId);
|
||||
|
||||
[DllImport(_USER32_DLL)]
|
||||
public static extern int ReleaseDC(nint hWnd, nint dc);
|
||||
|
||||
[DllImport(_USER32_DLL)]
|
||||
public static extern nint SetWindowsHookEx(int idHook, LowLevelMouseProc lpfn, nint hMod, uint dwThreadId);
|
||||
|
||||
[DllImport(_USER32_DLL)]
|
||||
public static extern bool ShowWindow(nint hWnd, int nCmdShow);
|
||||
|
||||
[DllImport(_USER32_DLL)]
|
||||
[LibraryImport(_USER32_DLL)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static extern bool UnhookWindowsHookEx(nint hhk);
|
||||
internal static partial bool ShowWindow(nint hWnd, int nCmdShow);
|
||||
|
||||
[LibraryImport(_USER32_DLL)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
internal static partial bool UnhookWindowsHookEx(nint hhk);
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
namespace Dot;
|
||||
|
||||
public class DirOption : IOption
|
||||
public class DirOption : OptionBase
|
||||
{
|
||||
[Option('f', "filter", HelpText = nameof(Str.FileSearchPattern), Default = "*.*", ResourceType = typeof(Str))]
|
||||
public string Filter { 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; }
|
||||
}
|
@ -2,7 +2,7 @@ using TextCopy;
|
||||
|
||||
namespace Dot.Guid;
|
||||
|
||||
public sealed class Main : Tool<Option>
|
||||
public sealed class Main : ToolBase<Option>
|
||||
{
|
||||
public Main(Option opt) : base(opt) { }
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
namespace Dot.Guid;
|
||||
|
||||
[Verb("guid", HelpText = nameof(Str.GuidTool), ResourceType = typeof(Str))]
|
||||
public class Option : IOption
|
||||
public class Option : OptionBase
|
||||
{
|
||||
[Option('u', "upper", HelpText = nameof(Str.UseUppercase), Default = false, ResourceType = typeof(Str))]
|
||||
public bool Upper { get; set; } //normal options here
|
||||
|
@ -3,7 +3,7 @@ using System.Net.Sockets;
|
||||
|
||||
namespace Dot.IP;
|
||||
|
||||
public sealed class Main : Tool<Option>
|
||||
public sealed class Main : ToolBase<Option>
|
||||
|
||||
{
|
||||
public Main(Option opt) : base(opt) { }
|
||||
|
@ -1,4 +1,4 @@
|
||||
namespace Dot.IP;
|
||||
|
||||
[Verb("ip", HelpText = nameof(Str.Ip), ResourceType = typeof(Str))]
|
||||
public class Option : IOption { }
|
||||
public class Option : OptionBase { }
|
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; }
|
||||
}
|
395
src/Lang/Str.Designer.cs
generated
395
src/Lang/Str.Designer.cs
generated
@ -1,395 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace Dot.Lang {
|
||||
using System;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A strongly-typed resource class, for looking up localized strings, etc.
|
||||
/// </summary>
|
||||
// This class was auto-generated by the StronglyTypedResourceBuilder
|
||||
// class via a tool like ResGen or Visual Studio.
|
||||
// To add or remove a member, edit your .ResX file then rerun ResGen
|
||||
// with the /str option, or rebuild your VS project.
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
public class Str {
|
||||
|
||||
private static global::System.Resources.ResourceManager resourceMan;
|
||||
|
||||
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||
|
||||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||
internal Str() {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the cached ResourceManager instance used by this class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
public static global::System.Resources.ResourceManager ResourceManager {
|
||||
get {
|
||||
if (object.ReferenceEquals(resourceMan, null)) {
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Dot.Lang.Str", typeof(Str).Assembly);
|
||||
resourceMan = temp;
|
||||
}
|
||||
return resourceMan;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Overrides the current thread's CurrentUICulture property for all
|
||||
/// resource lookups using this strongly typed resource class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
public static global::System.Globalization.CultureInfo Culture {
|
||||
get {
|
||||
return resourceCulture;
|
||||
}
|
||||
set {
|
||||
resourceCulture = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to 单击鼠标左键复制颜色和坐标到剪贴板.
|
||||
/// </summary>
|
||||
public static string ClickCopyColor {
|
||||
get {
|
||||
return ResourceManager.GetString("ClickCopyColor", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to 转换换行符为LF.
|
||||
/// </summary>
|
||||
public static string ConvertEndOfLineToLF {
|
||||
get {
|
||||
return ResourceManager.GetString("ConvertEndOfLineToLF", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to {0}(已复制到剪贴板).
|
||||
/// </summary>
|
||||
public static string Copied {
|
||||
get {
|
||||
return ResourceManager.GetString("Copied", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to 文件通配符.
|
||||
/// </summary>
|
||||
public static string FileSearchPattern {
|
||||
get {
|
||||
return ResourceManager.GetString("FileSearchPattern", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to 要处理的目录路径.
|
||||
/// </summary>
|
||||
public static string FolderPath {
|
||||
get {
|
||||
return ResourceManager.GetString("FolderPath", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to GUID工具.
|
||||
/// </summary>
|
||||
public static string GuidTool {
|
||||
get {
|
||||
return ResourceManager.GetString("GuidTool", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to 输入文本为空.
|
||||
/// </summary>
|
||||
public static string InputTextIsEmpty {
|
||||
get {
|
||||
return ResourceManager.GetString("InputTextIsEmpty", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to IP工具.
|
||||
/// </summary>
|
||||
public static string Ip {
|
||||
get {
|
||||
return ResourceManager.GetString("Ip", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Local clock offset.
|
||||
/// </summary>
|
||||
public static string LocalClockOffset {
|
||||
get {
|
||||
return ResourceManager.GetString("LocalClockOffset", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to {0}, 本机时钟偏移: {1} ms.
|
||||
/// </summary>
|
||||
public static string LocalTimeOffset {
|
||||
get {
|
||||
return ResourceManager.GetString("LocalTimeOffset", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to 本机时间已同步.
|
||||
/// </summary>
|
||||
public static string LocalTimeSyncDone {
|
||||
get {
|
||||
return ResourceManager.GetString("LocalTimeSyncDone", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to 没有需要处理的文件.
|
||||
/// </summary>
|
||||
public static string NoFileToBeProcessed {
|
||||
get {
|
||||
return ResourceManager.GetString("NoFileToBeProcessed", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to {0} 通信中....
|
||||
/// </summary>
|
||||
public static string NtpCalling {
|
||||
get {
|
||||
return ResourceManager.GetString("NtpCalling", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to 成功 {0}/{1} , 本机时钟偏移平均值: {2} ms.
|
||||
/// </summary>
|
||||
public static string NtpReceiveDone {
|
||||
get {
|
||||
return ResourceManager.GetString("NtpReceiveDone", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to {0}/{1} 个 NTP 服务器.
|
||||
/// </summary>
|
||||
public static string NtpServerCount {
|
||||
get {
|
||||
return ResourceManager.GetString("NtpServerCount", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to 指定的路径“{0}”不存在.
|
||||
/// </summary>
|
||||
public static string PathNotFound {
|
||||
get {
|
||||
return ResourceManager.GetString("PathNotFound", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to 按下任意键继续....
|
||||
/// </summary>
|
||||
public static string PressAnyKey {
|
||||
get {
|
||||
return ResourceManager.GetString("PressAnyKey", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Public network ip... .
|
||||
/// </summary>
|
||||
public static string PublicIP {
|
||||
get {
|
||||
return ResourceManager.GetString("PublicIP", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to BitSet 1:[0-9],2:[a-z],4:[A-Z],8:[ascii.0x21-0x2F].
|
||||
/// </summary>
|
||||
public static string PwdGenerateTypes {
|
||||
get {
|
||||
return ResourceManager.GetString("PwdGenerateTypes", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to 密码长度.
|
||||
/// </summary>
|
||||
public static string PwdLength {
|
||||
get {
|
||||
return ResourceManager.GetString("PwdLength", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to 随机密码生成器.
|
||||
/// </summary>
|
||||
public static string RandomPasswordGenerator {
|
||||
get {
|
||||
return ResourceManager.GetString("RandomPasswordGenerator", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to 只读模式(仅做测试,不实际修改).
|
||||
/// </summary>
|
||||
public static string ReadOnly {
|
||||
get {
|
||||
return ResourceManager.GetString("ReadOnly", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to 移除文件尾部换行和空格.
|
||||
/// </summary>
|
||||
public static string RemoveTrailingWhiteSpaces {
|
||||
get {
|
||||
return ResourceManager.GetString("RemoveTrailingWhiteSpaces", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to 屏幕坐标颜色选取工具.
|
||||
/// </summary>
|
||||
public static string ScreenPixelTool {
|
||||
get {
|
||||
return ResourceManager.GetString("ScreenPixelTool", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to 查找文件....
|
||||
/// </summary>
|
||||
public static string SearchingFile {
|
||||
get {
|
||||
return ResourceManager.GetString("SearchingFile", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to {0} 个文件.
|
||||
/// </summary>
|
||||
public static string SearchingFileOK {
|
||||
get {
|
||||
return ResourceManager.GetString("SearchingFileOK", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Server.
|
||||
/// </summary>
|
||||
public static string Server {
|
||||
get {
|
||||
return ResourceManager.GetString("Server", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to 同步本机时间.
|
||||
/// </summary>
|
||||
public static string ServerTime {
|
||||
get {
|
||||
return ResourceManager.GetString("ServerTime", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to 已读取:{0}/{1},处理:{2},跳过:{3}.
|
||||
/// </summary>
|
||||
public static string ShowMessageTemp {
|
||||
get {
|
||||
return ResourceManager.GetString("ShowMessageTemp", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Status.
|
||||
/// </summary>
|
||||
public static string Status {
|
||||
get {
|
||||
return ResourceManager.GetString("Status", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to 同步本机时间.
|
||||
/// </summary>
|
||||
public static string SyncToLocalTime {
|
||||
get {
|
||||
return ResourceManager.GetString("SyncToLocalTime", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to 要处理的文本(默认取取剪贴板值).
|
||||
/// </summary>
|
||||
public static string TextTobeProcessed {
|
||||
get {
|
||||
return ResourceManager.GetString("TextTobeProcessed", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to 文本编码工具.
|
||||
/// </summary>
|
||||
public static string TextTool {
|
||||
get {
|
||||
return ResourceManager.GetString("TextTool", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to 连接NTP服务器超时时间 (毫秒).
|
||||
/// </summary>
|
||||
public static string TimeoutMillSecs {
|
||||
get {
|
||||
return ResourceManager.GetString("TimeoutMillSecs", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to 时间同步工具.
|
||||
/// </summary>
|
||||
public static string TimeTool {
|
||||
get {
|
||||
return ResourceManager.GetString("TimeTool", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to 移除文件的uf8 bom.
|
||||
/// </summary>
|
||||
public static string TrimUtf8Bom {
|
||||
get {
|
||||
return ResourceManager.GetString("TrimUtf8Bom", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to 使用大写输出.
|
||||
/// </summary>
|
||||
public static string UseUppercase {
|
||||
get {
|
||||
return ResourceManager.GetString("UseUppercase", resourceCulture);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -30,7 +30,7 @@
|
||||
<value>The specified path "{0}" does not exist</value>
|
||||
</data>
|
||||
<data name="SearchingFileOK" xml:space="preserve">
|
||||
<value>Find files...OK</value>
|
||||
<value>{0} files</value>
|
||||
</data>
|
||||
<data name="ShowMessageTemp" xml:space="preserve">
|
||||
<value>Read: {0}/{1}, processed: {2}, skipped: {3}</value>
|
||||
@ -131,4 +131,46 @@
|
||||
<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>
|
@ -33,6 +33,9 @@
|
||||
<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>
|
||||
@ -45,6 +48,9 @@
|
||||
<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>
|
||||
@ -54,12 +60,22 @@
|
||||
<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>
|
||||
@ -78,9 +94,27 @@
|
||||
<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>
|
||||
@ -121,6 +155,9 @@
|
||||
<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>
|
||||
@ -139,4 +176,10 @@
|
||||
<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.Text;
|
||||
using Dot;
|
||||
|
||||
Type[] LoadVerbs()
|
||||
@ -12,13 +13,20 @@ Type[] LoadVerbs()
|
||||
|
||||
async Task Run(object args)
|
||||
{
|
||||
var tool = ToolsFactory.Create(args as IOption);
|
||||
if (args is not OptionBase option) return;
|
||||
|
||||
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();
|
||||
|
||||
try {
|
||||
|
@ -3,7 +3,7 @@ using TextCopy;
|
||||
|
||||
namespace Dot.Pwd;
|
||||
|
||||
public sealed class Main : Tool<Option>
|
||||
public sealed class Main : ToolBase<Option>
|
||||
{
|
||||
private readonly char[][] _charTable = {
|
||||
"0123456789".ToCharArray() //
|
||||
|
@ -1,15 +1,15 @@
|
||||
namespace Dot.Pwd;
|
||||
|
||||
[Verb("pwd", HelpText = nameof(Str.RandomPasswordGenerator), ResourceType = typeof(Str))]
|
||||
public class Option : IOption
|
||||
public class Option : OptionBase
|
||||
{
|
||||
[Flags]
|
||||
public enum GenerateTypes
|
||||
{
|
||||
Number = 1
|
||||
, LowerCaseLetter = 2
|
||||
, UpperCaseLetter = 4
|
||||
, SpecialCharacter = 8
|
||||
Number = 0b0001
|
||||
, LowerCaseLetter = 0b0010
|
||||
, UpperCaseLetter = 0b0100
|
||||
, SpecialCharacter = 0b1000
|
||||
}
|
||||
|
||||
[Value(1, Required = true, HelpText = nameof(Str.PwdLength), ResourceType = typeof(Str))]
|
||||
|
@ -3,7 +3,7 @@ using NSExt.Extensions;
|
||||
|
||||
namespace Dot.RmBlank;
|
||||
|
||||
public sealed class Main : Tool<Option>, IDisposable
|
||||
public sealed class Main : ToolBase<Option>, IDisposable
|
||||
{
|
||||
private int _breakCnt;
|
||||
private bool _disposed;
|
||||
|
@ -2,7 +2,7 @@ using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Dot.RmBom;
|
||||
|
||||
public sealed class Main : Tool<Option>, IDisposable
|
||||
public sealed class Main : ToolBase<Option>, IDisposable
|
||||
{
|
||||
private int _breakCnt;
|
||||
private bool _disposed;
|
||||
|
@ -5,7 +5,7 @@ using TextCopy;
|
||||
|
||||
namespace Dot.Text;
|
||||
|
||||
public sealed class Main : Tool<Option>
|
||||
public sealed class Main : ToolBase<Option>
|
||||
{
|
||||
private ref struct Output
|
||||
{
|
||||
@ -66,8 +66,6 @@ public sealed class Main : Tool<Option>
|
||||
|
||||
private static void ParseAndShow(string text)
|
||||
{
|
||||
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
|
||||
|
||||
var ansi = BuildOutput(text, Encoding.GetEncoding("gbk"));
|
||||
var utf8 = BuildOutput(text, Encoding.UTF8);
|
||||
var unicodeLittleEndian = BuildOutput(text, Encoding.Unicode);
|
||||
@ -108,7 +106,5 @@ html-decode: {o.HtmlDecode}
|
||||
|
||||
|
||||
ParseAndShow(Opt.Text);
|
||||
Console.Write(Str.PressAnyKey);
|
||||
Console.ReadKey();
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
namespace Dot.Text;
|
||||
|
||||
[Verb("text", HelpText = nameof(Str.TextTool), ResourceType = typeof(Str))]
|
||||
public class Option : IOption
|
||||
public class Option : OptionBase
|
||||
{
|
||||
[Value(0, HelpText = nameof(Str.TextTobeProcessed), ResourceType = typeof(Str))]
|
||||
public string Text { get; set; }
|
||||
|
@ -5,7 +5,7 @@ using System.Runtime.InteropServices;
|
||||
|
||||
namespace Dot.Time;
|
||||
|
||||
public sealed class Main : Tool<Option>
|
||||
public sealed class Main : ToolBase<Option>
|
||||
{
|
||||
private record Server
|
||||
{
|
||||
@ -217,16 +217,20 @@ public sealed class Main : Tool<Option>
|
||||
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);
|
||||
Console.SetCursorPosition(0, Console.GetCursorPosition().Top);
|
||||
Console.Write(Str.ServerTime, (DateTime.Now - avgOffset).ToString("O"));
|
||||
Console.Write(@", {0}", Str.PressAnyKey);
|
||||
}
|
||||
// ReSharper disable once FunctionNeverReturns
|
||||
});
|
||||
Console.ReadKey();
|
||||
waitObj.WaitOne();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
namespace Dot.Time;
|
||||
|
||||
[Verb("time", HelpText = nameof(Str.TimeTool), ResourceType = typeof(Str))]
|
||||
public class Option : IOption
|
||||
public class Option : OptionBase
|
||||
{
|
||||
[Option('s', "sync", HelpText = nameof(Str.SyncToLocalTime), Default = false, ResourceType = typeof(Str))]
|
||||
public bool Sync { get; set; }
|
||||
|
@ -2,7 +2,7 @@ using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Dot.ToLf;
|
||||
|
||||
public sealed class Main : Tool<Option>, IDisposable
|
||||
public sealed class Main : ToolBase<Option>, IDisposable
|
||||
{
|
||||
private int _breakCnt;
|
||||
private bool _disposed;
|
||||
|
@ -1,7 +1,10 @@
|
||||
namespace Dot;
|
||||
|
||||
public abstract class Tool<TOption> : ITool
|
||||
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"
|
||||
@ -15,11 +18,25 @@ public abstract class Tool<TOption> : ITool
|
||||
|
||||
protected TOption Opt { get; }
|
||||
|
||||
protected Tool(TOption opt)
|
||||
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
|
||||
@ -33,6 +50,28 @@ public abstract class Tool<TOption> : ITool
|
||||
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 {
|
||||
@ -65,6 +104,5 @@ public abstract class Tool<TOption> : ITool
|
||||
return fsr;
|
||||
}
|
||||
|
||||
|
||||
public abstract Task Run();
|
||||
}
|
@ -16,6 +16,8 @@ public static class ToolsFactory
|
||||
, 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))
|
||||
};
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<RootNamespace>Dot</RootNamespace>
|
||||
<AssemblyName>dot</AssemblyName>
|
||||
<Version>1.1.3</Version>
|
||||
<Version>1.1.5</Version>
|
||||
<Authors>nsnail</Authors>
|
||||
<Copyright>Copyright (c) 2022 nsnail</Copyright>
|
||||
<RepositoryUrl>https://github.com/nsnail/dot.git</RepositoryUrl>
|
||||
@ -46,4 +46,12 @@
|
||||
</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>
|
Loading…
x
Reference in New Issue
Block a user