mirror of
https://github.com/nsnail/dot.git
synced 2025-06-17 21:13:21 +08:00
<feat> + tolf: 写入文件信息统计
This commit is contained in:
parent
62fef5b30b
commit
a77ba1966b
@ -8,4 +8,5 @@ var path = Directory.GetFiles(@".idea", "workspace.xml", SearchOption.AllDirecto
|
||||
""";
|
||||
var content = File.ReadAllText(path);
|
||||
content = content.Replace(findStr, replaceStr);
|
||||
Console.WriteLine(content);
|
||||
File.WriteAllText(path, content);
|
@ -1,3 +1,3 @@
|
||||
dot rm-bom
|
||||
dot rm-blank
|
||||
dot tolf
|
||||
dot rm-bom -w
|
||||
dot rm-blank -w
|
||||
dot tolf -w
|
@ -9,6 +9,6 @@ public class DirOption : OptionBase
|
||||
public string Path { get; set; }
|
||||
|
||||
|
||||
[Option('r', "readonly", HelpText = nameof(Str.ReadOnly), Default = false, ResourceType = typeof(Str))]
|
||||
public bool ReadOnly { get; set; }
|
||||
[Option('w', "write", HelpText = nameof(Str.WriteMode), Default = false, ResourceType = typeof(Str))]
|
||||
public bool WriteMode { get; set; }
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?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="">
|
||||
@ -74,9 +74,6 @@
|
||||
<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>
|
||||
@ -173,4 +170,22 @@
|
||||
<data name="JsonToString" xml:space="preserve">
|
||||
<value>Json text escaped into a string</value>
|
||||
</data>
|
||||
<data name="WriteMode" xml:space="preserve">
|
||||
<value>Enable write mode</value>
|
||||
</data>
|
||||
<data name="ExerciseMode" xml:space="preserve">
|
||||
<value>Read-only mode, the file will not be modified in real time!</value>
|
||||
</data>
|
||||
<data name="Read" xml:space="preserve">
|
||||
<value>read</value>
|
||||
</data>
|
||||
<data name="Write" xml:space="preserve">
|
||||
<value>write</value>
|
||||
</data>
|
||||
<data name="Break" xml:space="preserve">
|
||||
<value>skip</value>
|
||||
</data>
|
||||
<data name="WriteFileStats" xml:space="preserve">
|
||||
<value>Write statistics</value>
|
||||
</data>
|
||||
</root>
|
@ -137,8 +137,8 @@
|
||||
<data name="PressAnyKey" xml:space="preserve">
|
||||
<value>按下任意键继续...</value>
|
||||
</data>
|
||||
<data name="ReadOnly" xml:space="preserve">
|
||||
<value>只读模式(仅做测试,不实际修改)</value>
|
||||
<data name="WriteMode" xml:space="preserve">
|
||||
<value>启用写入模式</value>
|
||||
</data>
|
||||
<data name="NoFileToBeProcessed" xml:space="preserve">
|
||||
<value>没有需要处理的文件</value>
|
||||
@ -183,7 +183,7 @@
|
||||
<value>查找 "{0}" 下所有git仓库目录... </value>
|
||||
</data>
|
||||
<data name="ExerciseMode" xml:space="preserve">
|
||||
<value>演习模式, 不会真实修改文件!</value>
|
||||
<value>只读模式, 不会真实修改文件!</value>
|
||||
</data>
|
||||
<data name="Read" xml:space="preserve">
|
||||
<value>读取</value>
|
||||
@ -196,4 +196,7 @@
|
||||
<data name="Break" xml:space="preserve">
|
||||
<value>跳过</value>
|
||||
</data>
|
||||
<data name="WriteFileStats" xml:space="preserve">
|
||||
<value>写入统计</value>
|
||||
</data>
|
||||
</root>
|
@ -35,7 +35,7 @@ public sealed class Main : ToolBase<Option>, IDisposable
|
||||
|
||||
await using var fsrw = OpenFileStream(file, FileMode.Open, FileAccess.ReadWrite);
|
||||
|
||||
if (Opt.ReadOnly) { //测试,只读模式
|
||||
if (!Opt.WriteMode) { //测试,只读模式
|
||||
ShowMessage(0, 1, 0);
|
||||
return;
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ public sealed class Main : ToolBase<Option>, IDisposable
|
||||
var tmpFile = $"{file}.tmp";
|
||||
bool isReplaced;
|
||||
await using (var fsr = OpenFileStream(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) {
|
||||
if (Opt.ReadOnly) { //测试,只读模式
|
||||
if (!Opt.WriteMode) { //测试,只读模式
|
||||
ShowMessage(0, 1, 0);
|
||||
return;
|
||||
}
|
||||
|
@ -1,16 +1,19 @@
|
||||
using System.Collections.Concurrent;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Spectre.Console;
|
||||
using Panel = Spectre.Console.Panel;
|
||||
|
||||
namespace Dot.ToLf;
|
||||
|
||||
public sealed class Main : ToolBase<Option>
|
||||
{
|
||||
private int _breakCnt;
|
||||
private ProgressTask _fileTask;
|
||||
private static readonly object _lockObj = new();
|
||||
private long _procedCnt;
|
||||
private int _replaceCnt;
|
||||
private int _totalCnt;
|
||||
private int _breakCnt;
|
||||
private ProgressTask _fileTask;
|
||||
private static readonly object _lockObj = new();
|
||||
private long _procedCnt;
|
||||
private int _replaceCnt;
|
||||
private readonly ConcurrentDictionary<string, int> _replacedStats = new();
|
||||
private int _totalCnt;
|
||||
|
||||
public Main(Option opt) : base(opt)
|
||||
{
|
||||
@ -28,11 +31,6 @@ public sealed class Main : ToolBase<Option>
|
||||
int data;
|
||||
|
||||
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;
|
||||
@ -66,13 +64,16 @@ public sealed class Main : ToolBase<Option>
|
||||
|
||||
|
||||
if (isReplaced && !isBin) {
|
||||
MoveFile(tmpFile, file);
|
||||
if (Opt.WriteMode) //测试,只读模式
|
||||
MoveFile(tmpFile, file);
|
||||
ShowMessage(0, 1, 0);
|
||||
_replacedStats.AddOrUpdate(Path.GetExtension(file), 1, (_, oldValue) => oldValue + 1);
|
||||
}
|
||||
else {
|
||||
File.Delete(tmpFile);
|
||||
ShowMessage(0, 0, 1);
|
||||
}
|
||||
|
||||
File.Delete(tmpFile);
|
||||
}
|
||||
|
||||
|
||||
@ -92,7 +93,7 @@ public sealed class Main : ToolBase<Option>
|
||||
[SuppressMessage("ReSharper", "PossibleMultipleEnumeration")]
|
||||
public override async Task Run()
|
||||
{
|
||||
if (Opt.ReadOnly) AnsiConsole.MarkupLine("[gray]{0}[/]", Str.ExerciseMode);
|
||||
if (!Opt.WriteMode) AnsiConsole.MarkupLine("[gray]{0}[/]", Str.ExerciseMode);
|
||||
IEnumerable<string> fileList;
|
||||
await AnsiConsole.Progress()
|
||||
.Columns(new ProgressBarColumn() //
|
||||
@ -113,5 +114,12 @@ public sealed class Main : ToolBase<Option>
|
||||
_fileTask.StartTask();
|
||||
await Parallel.ForEachAsync(fileList, FileHandle);
|
||||
});
|
||||
|
||||
var grid = new Grid().AddColumn(new GridColumn().NoWrap().PadRight(16))
|
||||
.AddColumn(new GridColumn().Alignment(Justify.Right));
|
||||
|
||||
foreach (var kv in _replacedStats) grid.AddRow(kv.Key, kv.Value.ToString());
|
||||
|
||||
AnsiConsole.Write(new Panel(grid).Header(Str.WriteFileStats));
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user