From 9afc7360b9db0f0f9d0b10cd772459b43f26c95c Mon Sep 17 00:00:00 2001 From: Mike Phares Date: Fri, 13 Dec 2024 22:18:34 -0700 Subject: [PATCH] Not tested --- .vscode/launch.json | 11 ++++++++ ADO2024/PI2/Helper-2024-06-23.cs | 47 ++++++++++++++++++++++++++------ 2 files changed, 50 insertions(+), 8 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index acaa183..efebb01 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -11,6 +11,17 @@ "preLaunchTask": "build", "program": "${workspaceFolder}/bin/Debug/net8.0/win-x64/File-Folder-Helper.dll", "args": [ + "s", + "X", + "D:/5-Other-Small/Kanban/DEP08CEPIEPSILON", + "Day-Helper-2024-06-23", + "*.md", + "## Sub-tasks", + "code-insiders", + "index.md", + "- [,](", + "## Done", + ".kan", "s", "X", "L:/Git/Linux-Ubuntu-Server/etc/nginx/include", diff --git a/ADO2024/PI2/Helper-2024-06-23.cs b/ADO2024/PI2/Helper-2024-06-23.cs index ce67cf5..9587d5e 100644 --- a/ADO2024/PI2/Helper-2024-06-23.cs +++ b/ADO2024/PI2/Helper-2024-06-23.cs @@ -1,3 +1,4 @@ +using File_Folder_Helper.Helpers; using Microsoft.Extensions.Logging; using System.Collections.ObjectModel; @@ -9,14 +10,32 @@ internal static partial class Helper20240623 private record SubTaskLine(string Text, bool Done, long? Ticks, int? Line); private record Record(int? CodeInsidersLine, string File, string[] Lines, int? StopLine, int? SubTasksLine); - private static List GetRecords(string sourceDirectory, string searchPattern, string codeInsiders, string subTasks) + private static List GetRecords(string sourceDirectory, string searchPattern, string codeInsiders, string subTasks, string directoryFilter) { List results = []; int? stopLine; string[] lines; int? subTasksLine; int? codeInsidersLine; - string[] files = Directory.GetFiles(sourceDirectory, searchPattern, SearchOption.AllDirectories); + ReadOnlyCollection directoryNames = HelperDirectory.GetDirectoryNames(sourceDirectory); + if (!directoryNames.Any(l => l.StartsWith(directoryFilter, StringComparison.CurrentCultureIgnoreCase))) + { + string directoryName; + string[] checkDirectories = Directory.GetDirectories(sourceDirectory, "*", SearchOption.TopDirectoryOnly); + foreach (string checkDirectory in checkDirectories) + { + directoryName = Path.GetFileName(checkDirectory); + if (directoryName.StartsWith(directoryFilter, StringComparison.CurrentCultureIgnoreCase)) + { + sourceDirectory = checkDirectory; + break; + } + } + } + string[] subDirectories = Directory.GetDirectories(sourceDirectory, "*", SearchOption.TopDirectoryOnly); + List files = Directory.GetFiles(sourceDirectory, searchPattern, SearchOption.TopDirectoryOnly).ToList(); + foreach (string subDirectory in subDirectories) + files.AddRange(Directory.GetFiles(subDirectory, searchPattern, SearchOption.TopDirectoryOnly)); foreach (string file in files) { stopLine = null; @@ -60,6 +79,7 @@ internal static partial class Helper20240623 string line; bool doneValue; string? h1 = null; + SubTaskLine subTaskLine; bool foundSubTasks = false; int tasksZeroLength = tasks[0].Length; string[] lines = File.ReadAllLines(fileInfo.FullName); @@ -75,13 +95,18 @@ internal static partial class Helper20240623 if (line.Length <= tasksZeroLength || !line.StartsWith(tasks[0]) || line[tasksZeroLength] is not ' ' and not 'x' || line[tasksZeroLength + 1] != ']') continue; doneValue = foundDone is not null && foundDone.Value; - results.Add(new($" {line}", doneValue, fileInfo.LastWriteTime.Ticks, i)); + subTaskLine = new($" {line}", doneValue, fileInfo.LastWriteTime.Ticks, i); + results.Add(subTaskLine); } doneValue = foundDone is not null && foundDone.Value; if (h1 is null) - results.Add(new(fallbackLine, doneValue, fileInfo.LastWriteTime.Ticks, Line: null)); + subTaskLine = new(fallbackLine, doneValue, fileInfo.LastWriteTime.Ticks, Line: null); else - results.Add(new(foundDone is null || !foundDone.Value ? $"- [ ] {fileInfo.LastWriteTime.Ticks} ~~~ {h1}" : $"- [x] {fileInfo.LastWriteTime.Ticks} ~~~ {h1}", doneValue, fileInfo.LastWriteTime.Ticks, Line: 0)); + { + fallbackLine = foundDone is null || !foundDone.Value ? $"- [ ] {fileInfo.LastWriteTime.Ticks} ~~~ {h1}" : $"- [x] {fileInfo.LastWriteTime.Ticks} ~~~ {h1}"; + subTaskLine = new(fallbackLine, doneValue, fileInfo.LastWriteTime.Ticks, Line: 0); + } + results.Add(subTaskLine); return new(results); } @@ -99,6 +124,7 @@ internal static partial class Helper20240623 string checkDirectory; string done = args[7]; List indexFiles; + SubTaskLine subTaskLine; string subTasks = args[3]; List oldLines = []; string indexFile = args[5]; @@ -109,7 +135,7 @@ internal static partial class Helper20240623 List allSubTaskLines = []; ReadOnlyCollection subTaskLines; string sourceDirectory = Path.GetFullPath(args[0]); - List records = GetRecords(sourceDirectory, searchPattern, codeInsiders, subTasks); + List records = GetRecords(sourceDirectory, searchPattern, codeInsiders, subTasks, directoryFilter); foreach (Record record in from l in records orderby l.SubTasksLine is null, l.CodeInsidersLine is null select l) { if (record.SubTasksLine is null) @@ -164,8 +190,13 @@ internal static partial class Helper20240623 continue; } subTaskLines = GetSubTasks(subTasks, tasks, doneValue, fallbackLine, fileInfo); - for (int j = subTaskLines.Count - 1; j >= 0; j--) - allSubTaskLines.Add(subTaskLines[j]); + if (subTaskLines.Count > 0) + { + subTaskLine = new($"", false, null, null); + allSubTaskLines.Add(subTaskLine); + for (int j = subTaskLines.Count - 1; j >= 0; j--) + allSubTaskLines.Add(subTaskLines[j]); + } } if (allSubTaskLines.Count == 0) continue;