person-key-to-immich-import birthday json (Day-Helper-2024-05-18)
csharp_prefer_braces = true
This commit is contained in:
@ -72,27 +72,31 @@ internal static partial class Helper20241217 {
|
||||
string sourceDirectory = Path.GetFullPath(args[0]);
|
||||
string? snap2HyperTextMarkupLanguage = args.Count < 6 ? null : Path.GetFullPath(args[5]);
|
||||
logger.LogInformation("Searching <{sourceDirectory}> with search pattern {searchPattern}", args[0], searchPattern);
|
||||
if (Debugger.IsAttached)
|
||||
if (Debugger.IsAttached) {
|
||||
Verify(searchPattern, ignoreFileNames);
|
||||
}
|
||||
for (int i = 1; i < 3; i++) {
|
||||
if (i == 1) {
|
||||
searchPatternFiles = Directory.EnumerateFiles(sourceDirectory, searchPattern, new EnumerationOptions { IgnoreInaccessible = true, RecurseSubdirectories = true });
|
||||
} else if (i == 2) {
|
||||
searchPatternFiles = Directory.GetFiles(sourceDirectory, searchPattern, SearchOption.AllDirectories);
|
||||
} else
|
||||
} else {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
records = GetRecords(sourceDirectory, destination, searchPatternFiles);
|
||||
foreach (Record record in records) {
|
||||
if (record.Job is null || string.IsNullOrEmpty(record.Job.Extension))
|
||||
if (record.Job is null || string.IsNullOrEmpty(record.Job.Extension)) {
|
||||
continue;
|
||||
}
|
||||
logger.LogInformation("Searching <{directory}>", record.SourceDirectory);
|
||||
files = GetFiles(searchPattern, ignoreFileNames, record);
|
||||
jobNew = GetJob(searchPattern, ignoreFileNames, record, files);
|
||||
json = JsonSerializer.Serialize(jobNew, JobSourceGenerationContext.Default.Job);
|
||||
areTheyTheSame = GetAreTheyTheSame(logger, searchPattern, ignoreFileNames, record, jobNew);
|
||||
if (snap2HyperTextMarkupLanguage is not null && System.IO.File.Exists(snap2HyperTextMarkupLanguage)) {
|
||||
if (!areTheyTheSame || (areTheyTheSame && !System.IO.File.Exists(record.Snap2HyperTextMarkupLanguage)))
|
||||
if (!areTheyTheSame || (areTheyTheSame && !System.IO.File.Exists(record.Snap2HyperTextMarkupLanguage))) {
|
||||
WriteSnap2HyperTextMarkupLanguage(logger, snap2HyperTextMarkupLanguage, record);
|
||||
}
|
||||
}
|
||||
if (areTheyTheSame) {
|
||||
WriteAllText(record.Path, json);
|
||||
@ -115,8 +119,9 @@ internal static partial class Helper20241217 {
|
||||
new(null, new ServerMessageBlock("\\\\mesfs.infineon.com\\EC_APC\\DEV", true))
|
||||
];
|
||||
string directory = Path.Combine(Environment.CurrentDirectory, ".vscode", "helper");
|
||||
if (!Directory.Exists(directory))
|
||||
if (!Directory.Exists(directory)) {
|
||||
_ = Directory.CreateDirectory(directory);
|
||||
}
|
||||
string path = Path.Combine(directory, "verify.json");
|
||||
ReadOnlyCollection<File> files = GetFiles(directory, searchPattern, ignoreFileNames);
|
||||
ReadOnlyCollection<File> collection = GetFilteredFiles(searchPattern, ignoreFileNames, files);
|
||||
@ -137,15 +142,19 @@ internal static partial class Helper20241217 {
|
||||
List<File> results = [];
|
||||
string fileName;
|
||||
foreach (File file in files) {
|
||||
if (file.RelativePath == searchPattern)
|
||||
if (file.RelativePath == searchPattern) {
|
||||
continue;
|
||||
}
|
||||
fileName = Path.GetFileName(file.RelativePath);
|
||||
if (fileName == searchPattern)
|
||||
if (fileName == searchPattern) {
|
||||
throw new Exception("Found nested file!");
|
||||
if (ignoreFileNames.Any(l => l == fileName))
|
||||
}
|
||||
if (ignoreFileNames.Any(l => l == fileName)) {
|
||||
continue;
|
||||
if (file.Length == 0)
|
||||
}
|
||||
if (file.Length == 0) {
|
||||
continue;
|
||||
}
|
||||
results.Add(file);
|
||||
}
|
||||
return results.AsReadOnly();
|
||||
@ -170,10 +179,11 @@ internal static partial class Helper20241217 {
|
||||
}
|
||||
json = System.IO.File.ReadAllText(file);
|
||||
snap2HyperTextMarkupLanguage = Path.Combine(sourceDirectory, ".html");
|
||||
if (string.IsNullOrEmpty(json) || json is "{}" or "[]")
|
||||
if (string.IsNullOrEmpty(json) || json is "{}" or "[]") {
|
||||
job = null;
|
||||
else
|
||||
} else {
|
||||
job = JsonSerializer.Deserialize(json, JobSourceGenerationContext.Default.Job);
|
||||
}
|
||||
job ??= new(AlternatePath: null,
|
||||
Directory: directory,
|
||||
Extension: ".iso",
|
||||
@ -183,8 +193,9 @@ internal static partial class Helper20241217 {
|
||||
Keep: 3,
|
||||
Targets: []);
|
||||
destinationDirectory = $"{destination}{sourceDirectory[2..]}";
|
||||
if (!Directory.Exists(destinationDirectory))
|
||||
if (!Directory.Exists(destinationDirectory)) {
|
||||
_ = Directory.CreateDirectory(destinationDirectory);
|
||||
}
|
||||
record = new(DestinationDirectory: destinationDirectory,
|
||||
DirectoryName: directoryName,
|
||||
Job: job,
|
||||
@ -195,21 +206,6 @@ internal static partial class Helper20241217 {
|
||||
}
|
||||
}
|
||||
|
||||
private static void WriteSnap2HyperTextMarkupLanguage(ILogger<Worker> logger, string snap2HyperTextMarkupLanguage, Record record) {
|
||||
string title = Path.GetFileName(record.SourceDirectory);
|
||||
ProcessStartInfo processStartInfo = new() {
|
||||
Arguments = $"-path:\"{record.SourceDirectory}\" -outfile:\"{record.Snap2HyperTextMarkupLanguage}\" -title:\"{title}\" -hidden -silent",
|
||||
FileName = snap2HyperTextMarkupLanguage,
|
||||
RedirectStandardError = true,
|
||||
RedirectStandardInput = true,
|
||||
RedirectStandardOutput = true,
|
||||
WorkingDirectory = record.SourceDirectory
|
||||
};
|
||||
Process? process = Process.Start(processStartInfo) ?? throw new Exception("Process should not be null.");
|
||||
process.WaitForExit();
|
||||
logger.LogInformation($"Snap2HyperTextMarkupLanguage: {process.StandardOutput.ReadToEnd()}{Environment.NewLine}{process.StandardError.ReadToEnd()}{Environment.NewLine}{process.ExitCode}");
|
||||
}
|
||||
|
||||
private static ReadOnlyCollection<File> GetFiles(string directory, string searchPattern, string[] ignoreFileNames) {
|
||||
List<File> results = [];
|
||||
File file;
|
||||
@ -217,15 +213,19 @@ internal static partial class Helper20241217 {
|
||||
string[] files = Directory.GetFiles(directory, "*", SearchOption.AllDirectories);
|
||||
FileInfo[] fileInfoCollection = files.Select(l => new FileInfo(l)).ToArray();
|
||||
foreach (FileInfo fileInfo in fileInfoCollection) {
|
||||
if (fileInfo.Name == searchPattern)
|
||||
if (fileInfo.Name == searchPattern) {
|
||||
continue;
|
||||
if (ignoreFileNames.Any(l => l == fileInfo.Name))
|
||||
}
|
||||
if (ignoreFileNames.Any(l => l == fileInfo.Name)) {
|
||||
continue;
|
||||
if (!string.IsNullOrEmpty(fileInfo.LinkTarget))
|
||||
}
|
||||
if (!string.IsNullOrEmpty(fileInfo.LinkTarget)) {
|
||||
continue;
|
||||
}
|
||||
relativePath = Path.GetRelativePath(directory, fileInfo.FullName).Replace(';', '_');
|
||||
if (relativePath.StartsWith(".."))
|
||||
if (relativePath.StartsWith("..")) {
|
||||
relativePath = relativePath[3..];
|
||||
}
|
||||
file = new(LastWriteTicks: fileInfo.LastWriteTime.Ticks, Length: fileInfo.Length, RelativePath: relativePath);
|
||||
results.Add(file);
|
||||
}
|
||||
@ -264,9 +264,9 @@ internal static partial class Helper20241217 {
|
||||
} else {
|
||||
string jsonNew = JsonSerializer.Serialize(jobNew.Files, FilesSourceGenerationContext.Default.FileArray);
|
||||
string jsonOld = JsonSerializer.Serialize(collection.ToArray(), FilesSourceGenerationContext.Default.FileArray);
|
||||
if (jsonNew == jsonOld)
|
||||
if (jsonNew == jsonOld) {
|
||||
result = true;
|
||||
else {
|
||||
} else {
|
||||
result = false;
|
||||
if (Debugger.IsAttached) {
|
||||
WriteAllText(Path.Combine(Environment.CurrentDirectory, ".vscode", "helper", "old.json"), jsonOld);
|
||||
@ -279,25 +279,43 @@ internal static partial class Helper20241217 {
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void WriteSnap2HyperTextMarkupLanguage(ILogger<Worker> logger, string snap2HyperTextMarkupLanguage, Record record) {
|
||||
string title = Path.GetFileName(record.SourceDirectory);
|
||||
ProcessStartInfo processStartInfo = new() {
|
||||
Arguments = $"-path:\"{record.SourceDirectory}\" -outfile:\"{record.Snap2HyperTextMarkupLanguage}\" -title:\"{title}\" -hidden -silent",
|
||||
FileName = snap2HyperTextMarkupLanguage,
|
||||
RedirectStandardError = true,
|
||||
RedirectStandardInput = true,
|
||||
RedirectStandardOutput = true,
|
||||
WorkingDirectory = record.SourceDirectory
|
||||
};
|
||||
Process? process = Process.Start(processStartInfo) ?? throw new Exception("Process should not be null.");
|
||||
process.WaitForExit();
|
||||
logger.LogInformation($"Snap2HyperTextMarkupLanguage: {process.StandardOutput.ReadToEnd()}{Environment.NewLine}{process.StandardError.ReadToEnd()}{Environment.NewLine}{process.ExitCode}");
|
||||
}
|
||||
|
||||
private static void WriteAllText(string path, string text) {
|
||||
string check = !System.IO.File.Exists(path) ? string.Empty : System.IO.File.ReadAllText(path);
|
||||
if (check != text)
|
||||
if (check != text) {
|
||||
System.IO.File.WriteAllText(path, text);
|
||||
}
|
||||
}
|
||||
|
||||
private static void WritePassedExtension(Record record, ReadOnlyCollection<File> files, string directoryName, string path) {
|
||||
if (record.Job.Extension.Equals(".iso", StringComparison.OrdinalIgnoreCase))
|
||||
if (record.Job.Extension.Equals(".iso", StringComparison.OrdinalIgnoreCase)) {
|
||||
WriteISO(record, files, path, directoryName);
|
||||
else if (record.Job.Extension.Equals(".zip", StringComparison.OrdinalIgnoreCase))
|
||||
} else if (record.Job.Extension.Equals(".zip", StringComparison.OrdinalIgnoreCase)) {
|
||||
WriteZIP(record, files, path);
|
||||
else
|
||||
} else {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
private static void WriteISO(Record record, ReadOnlyCollection<File> files, string path, string directoryName) {
|
||||
CDBuilder builder = new() { UseJoliet = true, VolumeIdentifier = directoryName.Length < 25 ? directoryName : directoryName[..25] };
|
||||
foreach (File file in files)
|
||||
foreach (File file in files) {
|
||||
_ = builder.AddFile(file.RelativePath, Path.Combine(record.SourceDirectory, file.RelativePath));
|
||||
}
|
||||
builder.Build(path);
|
||||
}
|
||||
|
||||
@ -307,21 +325,24 @@ internal static partial class Helper20241217 {
|
||||
List<string> directoryEntries = [];
|
||||
foreach (File file in files) {
|
||||
directoryEntry = Path.GetDirectoryName(file.RelativePath) ?? throw new Exception();
|
||||
if (!directoryEntries.Contains(directoryEntry))
|
||||
if (!directoryEntries.Contains(directoryEntry)) {
|
||||
continue;
|
||||
}
|
||||
directoryEntries.Add(directoryEntry);
|
||||
_ = zip.CreateEntry(file.RelativePath);
|
||||
}
|
||||
foreach (File file in files)
|
||||
foreach (File file in files) {
|
||||
_ = zip.CreateEntryFromFile(Path.Combine(record.SourceDirectory, file.RelativePath), file.RelativePath);
|
||||
}
|
||||
}
|
||||
|
||||
private static void WriteAllText(Record record, string text, string path) {
|
||||
WriteAllText(record.Path, text);
|
||||
System.IO.File.Copy(record.Path, $"{path}.json");
|
||||
string checkFile = Path.Combine(record.SourceDirectory, ".html");
|
||||
if (System.IO.File.Exists(checkFile))
|
||||
if (System.IO.File.Exists(checkFile)) {
|
||||
System.IO.File.Copy(checkFile, $"{path}.html");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user