copy-to-combined-enum-and-index-format (Day-Helper-2025-07-26)
This commit is contained in:
7
.vscode/launch.json
vendored
7
.vscode/launch.json
vendored
@ -11,6 +11,13 @@
|
|||||||
"preLaunchTask": "build",
|
"preLaunchTask": "build",
|
||||||
"program": "${workspaceFolder}/bin/Debug/net8.0/win-x64/File-Folder-Helper.dll",
|
"program": "${workspaceFolder}/bin/Debug/net8.0/win-x64/File-Folder-Helper.dll",
|
||||||
"args": [
|
"args": [
|
||||||
|
"s",
|
||||||
|
"X",
|
||||||
|
"V:/7-Question/Event 2024 Directories-xmp",
|
||||||
|
"Day-Helper-2025-07-26",
|
||||||
|
"L:/Git/AA/Rename/.vscode/.UserSecrets/secrets.json",
|
||||||
|
"*.xmp",
|
||||||
|
"V:/7-Question/Event 2024 Directories-xmp-moved",
|
||||||
"s",
|
"s",
|
||||||
"X",
|
"X",
|
||||||
"V:/1-Images-A/Images-0b793904",
|
"V:/1-Images-A/Images-0b793904",
|
||||||
|
106
ADO2025/PI6/Helper-2025-07-26.cs
Normal file
106
ADO2025/PI6/Helper-2025-07-26.cs
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
using Phares.Shared.Models;
|
||||||
|
using Phares.Shared.Models.Stateless;
|
||||||
|
|
||||||
|
namespace File_Folder_Helper.ADO2025.PI6;
|
||||||
|
|
||||||
|
internal static partial class Helper20250726 {
|
||||||
|
|
||||||
|
private record Settings(ResultSettings? ResultSettings, MetadataSettings? MetadataSettings);
|
||||||
|
|
||||||
|
private record Record(CombinedEnumAndIndex CombinedEnumAndIndex, FilePath FilePath, bool HasFlagHidden);
|
||||||
|
|
||||||
|
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||||
|
[JsonSerializable(typeof(Settings))]
|
||||||
|
private partial class SettingsSourceGenerationContext : JsonSerializerContext {
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static void CopyToCombinedEnumAndIndexFormat(ILogger<Worker> logger, List<string> args) {
|
||||||
|
logger.LogInformation(args[0]);
|
||||||
|
logger.LogInformation(args[1]);
|
||||||
|
logger.LogInformation(args[2]);
|
||||||
|
logger.LogInformation(args[3]);
|
||||||
|
logger.LogInformation(args[4]);
|
||||||
|
string searchPattern = args[3];
|
||||||
|
string jsonFile = Path.GetFullPath(args[2]);
|
||||||
|
if (!File.Exists(jsonFile)) {
|
||||||
|
throw new Exception($"json file doesn't exist! <{jsonFile}>");
|
||||||
|
}
|
||||||
|
string json = File.ReadAllText(jsonFile);
|
||||||
|
string sourceDirectory = Path.GetFullPath(args[0].Split('~')[0]);
|
||||||
|
string destinationDirectory = Path.GetFullPath(args[4].Split('~')[0]);
|
||||||
|
Settings? settings = JsonSerializer.Deserialize(json, SettingsSourceGenerationContext.Default.Settings);
|
||||||
|
if (settings.ResultSettings is null || settings.ResultSettings.ResultAllInOneSubdirectoryLength < 1 || settings.MetadataSettings is null) {
|
||||||
|
throw new Exception(nameof(Settings));
|
||||||
|
}
|
||||||
|
string[] files = Directory.GetFiles(sourceDirectory, searchPattern, SearchOption.AllDirectories);
|
||||||
|
ReadOnlyDictionary<int, ReadOnlyDictionary<byte, ReadOnlyCollection<string>>> keyValuePairs = GetKeyValuePairs(destinationDirectory, settings.ResultSettings);
|
||||||
|
ReadOnlyCollection<Record> records = GetRecords(logger, settings.ResultSettings, settings.MetadataSettings, files);
|
||||||
|
ReadOnlyDictionary<byte, ReadOnlyCollection<string>> keyValues = keyValuePairs.ElementAt(0).Value;
|
||||||
|
CopyToCombinedEnumAndIndexFormat(logger, records, keyValues);
|
||||||
|
Helpers.HelperDeleteEmptyDirectories.DeleteEmptyDirectories(logger, destinationDirectory);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ReadOnlyDictionary<int, ReadOnlyDictionary<byte, ReadOnlyCollection<string>>> GetKeyValuePairs(string destinationDirectory, ResultSettings resultSettings) {
|
||||||
|
Dictionary<int, ReadOnlyDictionary<byte, ReadOnlyCollection<string>>> results = [];
|
||||||
|
ReadOnlyDictionary<int, ReadOnlyDictionary<string, ReadOnlyDictionary<byte, ReadOnlyCollection<string>>>> keyValuePairs = IPath.GetKeyValuePairs(resultSettings, destinationDirectory, [resultSettings.ResultSingleton]);
|
||||||
|
foreach (KeyValuePair<int, ReadOnlyDictionary<string, ReadOnlyDictionary<byte, ReadOnlyCollection<string>>>> keyValuePair in keyValuePairs) {
|
||||||
|
foreach (KeyValuePair<string, ReadOnlyDictionary<byte, ReadOnlyCollection<string>>> keyValue in keyValuePair.Value) {
|
||||||
|
if (keyValue.Key != resultSettings.ResultSingleton)
|
||||||
|
throw new Exception("Never should happen!");
|
||||||
|
results.Add(keyValuePair.Key, keyValue.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return results.AsReadOnly();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ReadOnlyCollection<Record> GetRecords(ILogger<Worker> logger, ResultSettings resultSettings, MetadataSettings metadataSettings, string[] files) {
|
||||||
|
List<Record> results = [];
|
||||||
|
Record record;
|
||||||
|
FileInfo fileInfo;
|
||||||
|
FilePath filePath;
|
||||||
|
bool hasFlagHidden;
|
||||||
|
FileHolder fileHolder;
|
||||||
|
CombinedEnumAndIndex combinedEnumAndIndex;
|
||||||
|
foreach (string file in files) {
|
||||||
|
fileInfo = new(file);
|
||||||
|
fileHolder = FileHolder.Get(fileInfo, id: null);
|
||||||
|
filePath = FilePath.Get(resultSettings, metadataSettings, fileHolder, index: null);
|
||||||
|
if (!filePath.IsIntelligentIdFormat) {
|
||||||
|
logger.LogWarning("<{file}> skipped because of name format!", filePath.Name);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
hasFlagHidden = fileInfo.Attributes.HasFlag(FileAttributes.Hidden);
|
||||||
|
combinedEnumAndIndex = IPath.GetCombinedEnumAndIndex(resultSettings, filePath);
|
||||||
|
record = new(CombinedEnumAndIndex: combinedEnumAndIndex, FilePath: filePath, HasFlagHidden: hasFlagHidden);
|
||||||
|
results.Add(record);
|
||||||
|
}
|
||||||
|
return results.AsReadOnly();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void CopyToCombinedEnumAndIndexFormat(ILogger<Worker> logger, ReadOnlyCollection<Record> records, ReadOnlyDictionary<byte, ReadOnlyCollection<string>> keyValuePairs) {
|
||||||
|
string checkFile;
|
||||||
|
FileInfo fileInfo;
|
||||||
|
FileAttributes fileAttributes;
|
||||||
|
foreach (Record record in records) {
|
||||||
|
checkFile = Path.Combine(keyValuePairs[record.CombinedEnumAndIndex.Enum][record.CombinedEnumAndIndex.Index], record.FilePath.Name);
|
||||||
|
if (File.Exists(checkFile)) {
|
||||||
|
logger.LogWarning("<{file}> skipped because it already exists!", record.FilePath.Name);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
File.Copy(record.FilePath.FullName, checkFile);
|
||||||
|
if (record.HasFlagHidden) {
|
||||||
|
fileInfo = new(checkFile);
|
||||||
|
fileAttributes = fileInfo.Attributes & ~FileAttributes.Hidden;
|
||||||
|
File.SetAttributes(fileInfo.FullName, fileAttributes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -183,6 +183,8 @@ internal static class HelperDay
|
|||||||
ADO2025.PI6.Helper20250710.StripLog(logger, args);
|
ADO2025.PI6.Helper20250710.StripLog(logger, args);
|
||||||
else if (args[1] == "Day-Helper-2025-07-20")
|
else if (args[1] == "Day-Helper-2025-07-20")
|
||||||
ADO2025.PI6.Helper20250720.WriteFaceData(logger, args);
|
ADO2025.PI6.Helper20250720.WriteFaceData(logger, args);
|
||||||
|
else if (args[1] == "Day-Helper-2025-07-26")
|
||||||
|
ADO2025.PI6.Helper20250726.CopyToCombinedEnumAndIndexFormat(logger, args);
|
||||||
else
|
else
|
||||||
throw new Exception(appSettings.Company);
|
throw new Exception(appSettings.Company);
|
||||||
}
|
}
|
||||||
|
@ -16,8 +16,8 @@
|
|||||||
<PackageReference Include="DiscUtils.Iso9660" Version="0.16.13" />
|
<PackageReference Include="DiscUtils.Iso9660" Version="0.16.13" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.1" />
|
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.1" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.1" />
|
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.1" />
|
||||||
<PackageReference Include="Phares.Metadata" Version="8.0.118.14751" />
|
<PackageReference Include="Phares.Metadata" Version="8.0.118.14905" />
|
||||||
<PackageReference Include="Phares.Shared" Version="8.0.118.14751" />
|
<PackageReference Include="Phares.Shared" Version="8.0.118.14905" />
|
||||||
<PackageReference Include="runtime.win-x64.Microsoft.DotNet.ILCompiler" Version="8.0.18" />
|
<PackageReference Include="runtime.win-x64.Microsoft.DotNet.ILCompiler" Version="8.0.18" />
|
||||||
<PackageReference Include="System.Text.Json" Version="9.0.7" />
|
<PackageReference Include="System.Text.Json" Version="9.0.7" />
|
||||||
<PackageReference Include="TextCopy" Version="6.2.1" />
|
<PackageReference Include="TextCopy" Version="6.2.1" />
|
||||||
|
Reference in New Issue
Block a user