Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
fc4449f515 |
2
.vscode/launch.json
vendored
2
.vscode/launch.json
vendored
@ -13,7 +13,7 @@
|
|||||||
"args": [
|
"args": [
|
||||||
"s",
|
"s",
|
||||||
"X",
|
"X",
|
||||||
"D:/0-ISO-A",
|
"F:/0-ISO-A",
|
||||||
"Day-Helper-2025-06-28",
|
"Day-Helper-2025-06-28",
|
||||||
"*.iso",
|
"*.iso",
|
||||||
"F",
|
"F",
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using DiscUtils;
|
using System.Collections.ObjectModel;
|
||||||
|
|
||||||
using DiscUtils.Iso9660;
|
using DiscUtils.Iso9660;
|
||||||
|
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
@ -7,40 +8,81 @@ namespace File_Folder_Helper.ADO2025.PI6;
|
|||||||
|
|
||||||
internal static partial class Helper20250628 {
|
internal static partial class Helper20250628 {
|
||||||
|
|
||||||
private record File(long LastWriteTicks,
|
private record Record(string Path,
|
||||||
long Length,
|
long Size,
|
||||||
string RelativePath);
|
long Ticks);
|
||||||
|
|
||||||
internal static void LogInformation(ILogger<Worker> logger, List<string> args) {
|
internal static void LogIsoInformation(ILogger<Worker> logger, List<string> args) {
|
||||||
logger.LogInformation(args[0]);
|
logger.LogInformation(args[0]);
|
||||||
logger.LogInformation(args[1]);
|
logger.LogInformation(args[1]);
|
||||||
logger.LogInformation(args[2]);
|
logger.LogInformation(args[2]);
|
||||||
string searchPattern = args[2];
|
string searchPattern = args[2];
|
||||||
string sourceDirectory = Path.GetFullPath(args[0].Split('~')[0]);
|
string sourceDirectory = Path.GetFullPath(args[0].Split('~')[0]);
|
||||||
string[] searchPatternFiles = Directory.GetFiles(sourceDirectory, searchPattern, SearchOption.AllDirectories);
|
string[] searchPatternFiles = Directory.GetFiles(sourceDirectory, searchPattern, SearchOption.AllDirectories);
|
||||||
LogInformation(logger, searchPatternFiles, args[3]);
|
ReadOnlyCollection<Record> records = GetRecords(searchPatternFiles);
|
||||||
|
LogIsoInformation(logger, records, args[3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void LogInformation(ILogger<Worker> logger, string[] searchPatternFiles, string letter) {
|
private static ReadOnlyCollection<Record> GetRecords(string[] searchPatternFiles) {
|
||||||
File file;
|
List<Record> results = [];
|
||||||
|
Record record;
|
||||||
string[] files;
|
string[] files;
|
||||||
DiscFileInfo discFileInfo;
|
FileInfo fileInfo;
|
||||||
foreach (string searchPatternFile in searchPatternFiles) {
|
foreach (string searchPatternFile in searchPatternFiles) {
|
||||||
if (string.IsNullOrEmpty(searchPatternFile)) {
|
fileInfo = new(searchPatternFile);
|
||||||
using FileStream fileStream = System.IO.File.OpenRead(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<Worker> logger, ReadOnlyCollection<Record> records, string letter) {
|
||||||
|
string size;
|
||||||
|
string[] files;
|
||||||
|
List<string> 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);
|
CDReader reader = new(fileStream, true);
|
||||||
files = reader.GetFiles("", "*");
|
files = reader.GetFiles("", "*");
|
||||||
foreach (string f in files) {
|
foreach (string _ in files) {
|
||||||
discFileInfo = reader.GetFileInfo(f);
|
|
||||||
file = new(LastWriteTicks: discFileInfo.LastWriteTime.Ticks, Length: discFileInfo.Length, RelativePath: f);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
logger.LogInformation("mountvol $driveLetter $volInfo.UniqueId");
|
size = GetSizeWithSuffix(record.Size);
|
||||||
logger.LogInformation("$volInfo = $diskImg | Get-Volume");
|
messages.Add($"#; {size}");
|
||||||
logger.LogInformation("$diskImg = Mount-DiskImage -ImagePath $isoImg -NoDriveLetter");
|
messages.Add($"#; {new DateTime(record.Ticks):yyyy-MM-dd HH:mm:ss.fff}");
|
||||||
logger.LogInformation($"$driveLetter = \"{letter}:\"");
|
messages.Add($"$driveLetter = \"{letter}:\"");
|
||||||
logger.LogInformation($"$isoImg = \"{searchPatternFile}\"");
|
messages.Add($"$isoImg = \"{record.Path}\"");
|
||||||
logger.LogInformation(string.Empty);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,7 +172,7 @@ internal static class HelperDay
|
|||||||
else if (args[1] == "Day-Helper-2025-06-18")
|
else if (args[1] == "Day-Helper-2025-06-18")
|
||||||
ADO2025.PI6.Helper20250618.MoveAllButXOfEach(logger, args);
|
ADO2025.PI6.Helper20250618.MoveAllButXOfEach(logger, args);
|
||||||
else if (args[1] == "Day-Helper-2025-06-28")
|
else if (args[1] == "Day-Helper-2025-06-28")
|
||||||
ADO2025.PI6.Helper20250628.LogInformation(logger, args);
|
ADO2025.PI6.Helper20250628.LogIsoInformation(logger, args);
|
||||||
else
|
else
|
||||||
throw new Exception(appSettings.Company);
|
throw new Exception(appSettings.Company);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user