write-identifiers (Day-Helper-2025-07-26)
This commit is contained in:
@ -9,15 +9,28 @@ namespace File_Folder_Helper.ADO2025.PI6;
|
||||
|
||||
internal static partial class Helper20250726 {
|
||||
|
||||
private record Helper20250726Settings(ResultSettings? ResultSettings, MetadataSettings? MetadataSettings);
|
||||
private record Helper20250726Identifier(string[] DirectoryNames,
|
||||
string Extension,
|
||||
bool? HasDateTimeOriginal,
|
||||
int Id,
|
||||
long Length,
|
||||
string PaddedId,
|
||||
long Ticks);
|
||||
|
||||
private record Record(CombinedEnumAndIndex CombinedEnumAndIndex, FilePath FilePath, bool HasFlagHidden);
|
||||
private record Record(CombinedEnumAndIndex CombinedEnumAndIndex, FilePath FilePath, bool HasFlagHidden, Helper20250726Identifier? Identifier);
|
||||
|
||||
private record Helper20250726Settings(ResultSettings? ResultSettings, MetadataSettings? MetadataSettings);
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||
[JsonSerializable(typeof(Helper20250726Settings))]
|
||||
private partial class Helper20250726SettingsSourceGenerationContext : JsonSerializerContext {
|
||||
}
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||
[JsonSerializable(typeof(Helper20250726Identifier[]))]
|
||||
private partial class Helper20250726IdentifierCollectionSourceGenerationContext : JsonSerializerContext {
|
||||
}
|
||||
|
||||
internal static void CopyToCombinedEnumAndIndexFormat(ILogger<Worker> logger, List<string> args) {
|
||||
logger.LogInformation(args[0]);
|
||||
logger.LogInformation(args[1]);
|
||||
@ -35,6 +48,7 @@ internal static partial class Helper20250726 {
|
||||
ReadOnlyCollection<Record> records;
|
||||
string json = File.ReadAllText(jsonFile);
|
||||
string destinationDirectoryName = args[6];
|
||||
List<Helper20250726Identifier> identifiers = [];
|
||||
ReadOnlyDictionary<byte, ReadOnlyCollection<string>> keyValues;
|
||||
string sourceDirectory = Path.GetFullPath(args[0].Split('~')[0]);
|
||||
string destinationDirectory = Path.GetFullPath(args[5].Split('~')[0]);
|
||||
@ -51,11 +65,13 @@ internal static partial class Helper20250726 {
|
||||
continue;
|
||||
}
|
||||
logger.LogInformation($"Found {files.Length} {searchPattern} files");
|
||||
keyValuePairs = GetKeyValuePairs(settings.ResultSettings, destinationDirectory, destinationDirectoryName);
|
||||
records = GetRecords(logger, settings.ResultSettings, settings.MetadataSettings, files);
|
||||
keyValuePairs = GetKeyValuePairs(settings.ResultSettings, destinationDirectory, destinationDirectoryName);
|
||||
keyValues = keyValuePairs.ElementAt(0).Value;
|
||||
CopyToCombinedEnumAndIndexFormat(logger, maxSize, records, keyValues);
|
||||
identifiers.AddRange(from l in records where l.Identifier is not null select l.Identifier);
|
||||
}
|
||||
WriteIdentifiers(logger, destinationDirectory, identifiers.AsReadOnly());
|
||||
Helpers.HelperDeleteEmptyDirectories.DeleteEmptyDirectories(logger, destinationDirectory);
|
||||
}
|
||||
|
||||
@ -80,6 +96,7 @@ internal static partial class Helper20250726 {
|
||||
FilePath filePath;
|
||||
bool hasFlagHidden;
|
||||
FileHolder fileHolder;
|
||||
Helper20250726Identifier? identifier;
|
||||
CombinedEnumAndIndex combinedEnumAndIndex;
|
||||
foreach (string file in files) {
|
||||
fileInfo = new(file);
|
||||
@ -90,13 +107,43 @@ internal static partial class Helper20250726 {
|
||||
continue;
|
||||
}
|
||||
hasFlagHidden = fileInfo.Attributes.HasFlag(FileAttributes.Hidden);
|
||||
identifier = GetIdentifier(resultSettings, metadataSettings, filePath);
|
||||
combinedEnumAndIndex = IPath.GetCombinedEnumAndIndex(resultSettings, filePath);
|
||||
record = new(CombinedEnumAndIndex: combinedEnumAndIndex, FilePath: filePath, HasFlagHidden: hasFlagHidden);
|
||||
record = new(CombinedEnumAndIndex: combinedEnumAndIndex, FilePath: filePath, HasFlagHidden: hasFlagHidden, Identifier: identifier);
|
||||
results.Add(record);
|
||||
}
|
||||
return results.AsReadOnly();
|
||||
}
|
||||
|
||||
private static Helper20250726Identifier? GetIdentifier(ResultSettings resultSettings, MetadataSettings metadataSettings, FilePath filePath) {
|
||||
Helper20250726Identifier? result;
|
||||
if (filePath.Id is null) {
|
||||
result = null;
|
||||
} else {
|
||||
string paddedId = IId.GetPaddedId(resultSettings, metadataSettings, filePath, index: null);
|
||||
result = new(DirectoryNames: [],
|
||||
Extension: filePath.ExtensionLowered,
|
||||
HasDateTimeOriginal: filePath.HasDateTimeOriginal,
|
||||
Id: filePath.Id.Value,
|
||||
Length: filePath.Length,
|
||||
PaddedId: paddedId,
|
||||
Ticks: filePath.LastWriteTicks);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void WriteIdentifiers(ILogger<Worker> logger, string destinationDirectory, ReadOnlyCollection<Helper20250726Identifier> identifiers) {
|
||||
Helper20250726Identifier[] results = (from l in identifiers where l is not null orderby l.PaddedId select l).ToArray();
|
||||
string path = Path.Combine(destinationDirectory, ".json");
|
||||
string? oldJson = !File.Exists(path) ? null : File.ReadAllText(path);
|
||||
string json = JsonSerializer.Serialize(results, Helper20250726IdentifierCollectionSourceGenerationContext.Default.Helper20250726IdentifierArray);
|
||||
if (!string.IsNullOrEmpty(oldJson) && oldJson == json) {
|
||||
logger.LogInformation("File {path} is the same", path);
|
||||
} else {
|
||||
File.WriteAllText(path, json);
|
||||
}
|
||||
}
|
||||
|
||||
private static void CopyToCombinedEnumAndIndexFormat(ILogger<Worker> logger, long maxSize, ReadOnlyCollection<Record> records, ReadOnlyDictionary<byte, ReadOnlyCollection<string>> keyValuePairs) {
|
||||
string checkFile;
|
||||
FileInfo fileInfo;
|
||||
|
||||
Reference in New Issue
Block a user