diff --git a/.vscode/launch.json b/.vscode/launch.json index 9e138e9..e9eeead 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -11,6 +11,12 @@ "preLaunchTask": "build", "program": "${workspaceFolder}/bin/Debug/net8.0/win-x64/File-Folder-Helper.dll", "args": [ + "s", + "X", + "F:/0-ISO-A", + "Day-Helper-2025-06-28", + "*.iso", + "F", "s", "X", "D:/5-Other-Small", diff --git a/ADO2025/PI6/Helper-2025-06-28.cs b/ADO2025/PI6/Helper-2025-06-28.cs new file mode 100644 index 0000000..5529661 --- /dev/null +++ b/ADO2025/PI6/Helper-2025-06-28.cs @@ -0,0 +1,89 @@ +using System.Collections.ObjectModel; + +using DiscUtils.Iso9660; + +using Microsoft.Extensions.Logging; + +namespace File_Folder_Helper.ADO2025.PI6; + +internal static partial class Helper20250628 { + + private record Record(string Path, + long Size, + long Ticks); + + internal static void LogIsoInformation(ILogger logger, List args) { + logger.LogInformation(args[0]); + logger.LogInformation(args[1]); + logger.LogInformation(args[2]); + string searchPattern = args[2]; + string sourceDirectory = Path.GetFullPath(args[0].Split('~')[0]); + string[] searchPatternFiles = Directory.GetFiles(sourceDirectory, searchPattern, SearchOption.AllDirectories); + ReadOnlyCollection records = GetRecords(searchPatternFiles); + LogIsoInformation(logger, records, args[3]); + } + + private static ReadOnlyCollection GetRecords(string[] searchPatternFiles) { + List results = []; + Record record; + string[] files; + FileInfo fileInfo; + foreach (string searchPatternFile in searchPatternFiles) { + fileInfo = new(searchPatternFile); + record = new(searchPatternFile, fileInfo.Length, fileInfo.LastWriteTime.Ticks); + results.Add(record); + } + return results.AsReadOnly(); + } + + private static string GetSizeWithSuffix(long value) { + string result; + int i = 0; + string[] SizeSuffixes = ["bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"]; + if (value < 0) { + result = "-" + GetSizeWithSuffix(-value); + } else { + while (Math.Round(value / 1024f) >= 1) { + value /= 1024; + i++; + } + result = string.Format("{0:n1} {1}", value, SizeSuffixes[i]); + } + return result; + } + + private static void LogIsoInformation(ILogger logger, ReadOnlyCollection records, string letter) { + string size; + string[] files; + List messages = []; + Record[] sorted = records.OrderBy(l => l.Ticks).ToArray(); + string directory = Path.Combine(Environment.CurrentDirectory, ".vscode", "helper"); + foreach (Record record in sorted) { + if (string.IsNullOrEmpty(record.Path)) { + using FileStream fileStream = File.OpenRead(record.Path); + CDReader reader = new(fileStream, true); + files = reader.GetFiles("", "*"); + foreach (string _ in files) { + } + } + size = GetSizeWithSuffix(record.Size); + messages.Add($"#; {size}"); + messages.Add($"#; {new DateTime(record.Ticks):yyyy-MM-dd HH:mm:ss.fff}"); + messages.Add($"$driveLetter = \"{letter}:\""); + messages.Add($"$isoImg = \"{record.Path}\""); + messages.Add("$diskImg = Mount-DiskImage -ImagePath $isoImg -NoDriveLetter"); + messages.Add("$volInfo = $diskImg | Get-Volume"); + messages.Add("mountvol $driveLetter $volInfo.UniqueId"); + messages.Add(string.Empty); + } + if (Directory.Exists(directory)) { + File.WriteAllText(Path.Combine(directory, ".lsv"), string.Join(Environment.NewLine, messages)); + } else { + messages.Reverse(); + foreach (string message in messages) { + logger.LogInformation(message); + } + } + } + +} \ No newline at end of file diff --git a/Day/HelperDay.cs b/Day/HelperDay.cs index 5a1bfd0..820c597 100644 --- a/Day/HelperDay.cs +++ b/Day/HelperDay.cs @@ -171,6 +171,8 @@ internal static class HelperDay ADO2025.PI6.Helper20250602.EquipmentAutomationFrameworkCellInstanceStateImageVerbIf(logger, args); else if (args[1] == "Day-Helper-2025-06-18") ADO2025.PI6.Helper20250618.MoveAllButXOfEach(logger, args); + else if (args[1] == "Day-Helper-2025-06-28") + ADO2025.PI6.Helper20250628.LogIsoInformation(logger, args); else throw new Exception(appSettings.Company); }