HelperVSCodePossibleExtension and
Person Title
This commit is contained in:
1186
.vscode/HelperMarkdown.cs
vendored
Normal file
1186
.vscode/HelperMarkdown.cs
vendored
Normal file
File diff suppressed because it is too large
Load Diff
@ -10,6 +10,73 @@ internal static partial class HelperCreateNoteFiles
|
||||
[GeneratedRegex("[^a-z0-9-]")]
|
||||
private static partial Regex AlphaNumOnly();
|
||||
|
||||
private static string? GetTags(string tagsText)
|
||||
{
|
||||
string? result;
|
||||
StringBuilder stringBuilder = new();
|
||||
if (string.IsNullOrEmpty(tagsText))
|
||||
result = null;
|
||||
else
|
||||
{
|
||||
string[] segments;
|
||||
_ = stringBuilder.AppendLine("tags:");
|
||||
string[] tags = tagsText.Split(';', StringSplitOptions.RemoveEmptyEntries);
|
||||
foreach (string tag in tags)
|
||||
{
|
||||
segments = tag.Split(':');
|
||||
_ = stringBuilder.AppendLine($"- '{segments.First()}'");
|
||||
}
|
||||
result = stringBuilder.ToString().Trim();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static string? GetLinks(string type, string linksText)
|
||||
{
|
||||
string? result;
|
||||
StringBuilder stringBuilder = new();
|
||||
if (!string.IsNullOrEmpty(linksText))
|
||||
result = null;
|
||||
else
|
||||
{
|
||||
string linkLower;
|
||||
string[] segments;
|
||||
string[] links = linksText.Split(';', StringSplitOptions.RemoveEmptyEntries);
|
||||
foreach (string link in links)
|
||||
{
|
||||
segments = link.Split(':');
|
||||
linkLower = AlphaNumOnly().Replace(segments.First().Trim().ToLower(), "-").Replace("--", "-");
|
||||
if (segments.Length == 1)
|
||||
_ = stringBuilder.AppendLine($"- [[{type}/{linkLower}]]");
|
||||
else if (segments.Length == 2)
|
||||
_ = stringBuilder.AppendLine($"- [{type}/{linkLower}]({segments.Last()})");
|
||||
else
|
||||
continue;
|
||||
}
|
||||
result = stringBuilder.ToString().Trim();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static string? GetAttributes(string[] columns, string[]? headerColumns, int expectedCount)
|
||||
{
|
||||
string? result;
|
||||
if (headerColumns is null || columns.Length <= expectedCount)
|
||||
result = null;
|
||||
else
|
||||
{
|
||||
StringBuilder stringBuilder = new();
|
||||
for (int j = expectedCount; j < columns.Length; j++)
|
||||
{
|
||||
if (headerColumns.Length <= j)
|
||||
continue;
|
||||
_ = stringBuilder.AppendLine($"{headerColumns[j].Trim()}: '{columns[j].Trim()}'");
|
||||
}
|
||||
result = stringBuilder.ToString().Trim();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void CleanExistingFiles(string directory, long ticks)
|
||||
{
|
||||
string check;
|
||||
@ -100,73 +167,6 @@ internal static partial class HelperCreateNoteFiles
|
||||
}
|
||||
}
|
||||
|
||||
private static string? GetTags(string tagsText)
|
||||
{
|
||||
string? result;
|
||||
StringBuilder stringBuilder = new();
|
||||
if (string.IsNullOrEmpty(tagsText))
|
||||
result = null;
|
||||
else
|
||||
{
|
||||
string[] segments;
|
||||
_ = stringBuilder.AppendLine("tags:");
|
||||
string[] tags = tagsText.Split(';', StringSplitOptions.RemoveEmptyEntries);
|
||||
foreach (string tag in tags)
|
||||
{
|
||||
segments = tag.Split(':');
|
||||
_ = stringBuilder.AppendLine($"- '{segments.First()}'");
|
||||
}
|
||||
result = stringBuilder.ToString().Trim();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static string? GetLinks(string type, string linksText)
|
||||
{
|
||||
string? result;
|
||||
StringBuilder stringBuilder = new();
|
||||
if (!string.IsNullOrEmpty(linksText))
|
||||
result = null;
|
||||
else
|
||||
{
|
||||
string linkLower;
|
||||
string[] segments;
|
||||
string[] links = linksText.Split(';', StringSplitOptions.RemoveEmptyEntries);
|
||||
foreach (string link in links)
|
||||
{
|
||||
segments = link.Split(':');
|
||||
linkLower = AlphaNumOnly().Replace(segments.First().Trim().ToLower(), "-").Replace("--", "-");
|
||||
if (segments.Length == 1)
|
||||
_ = stringBuilder.AppendLine($"- [[{type}/{linkLower}]]");
|
||||
else if (segments.Length == 2)
|
||||
_ = stringBuilder.AppendLine($"- [{type}/{linkLower}]({segments.Last()})");
|
||||
else
|
||||
continue;
|
||||
}
|
||||
result = stringBuilder.ToString().Trim();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static string? GetAttributes(string[] columns, string[]? headerColumns, int expectedCount)
|
||||
{
|
||||
string? result;
|
||||
if (headerColumns is null || columns.Length <= expectedCount)
|
||||
result = null;
|
||||
else
|
||||
{
|
||||
StringBuilder stringBuilder = new();
|
||||
for (int j = expectedCount; j < columns.Length; j++)
|
||||
{
|
||||
if (headerColumns.Length <= j)
|
||||
continue;
|
||||
_ = stringBuilder.AppendLine($"{headerColumns[j].Trim()}: '{columns[j].Trim()}'");
|
||||
}
|
||||
result = stringBuilder.ToString().Trim();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void CreateImportFiles(long ticks, List<string> importFiles)
|
||||
{
|
||||
bool csv;
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -14,6 +14,44 @@ internal static partial class HelperKanbanMetadata
|
||||
[GeneratedRegex("[\\s!?.,@:;|\\\\/\"'`£$%\\^&*{}[\\]()<>~#+\\-=_¬]+")]
|
||||
private static partial Regex InvalidCharacter();
|
||||
|
||||
private static void TestParamCases()
|
||||
{
|
||||
if (GetParamCase("PascalCase") != "pascal-case")
|
||||
throw new Exception("PascalCase");
|
||||
if (GetParamCase("camelCase") != "camel-case")
|
||||
throw new Exception("camelCase");
|
||||
if (GetParamCase("snake_case") != "snake-case")
|
||||
throw new Exception("snake_case");
|
||||
if (GetParamCase("No Case") != "no-case")
|
||||
throw new Exception("No Case");
|
||||
if (GetParamCase("With 2 numbers 3") != "with-2-numbers-3")
|
||||
throw new Exception("With 2 numbers 3");
|
||||
if (GetParamCase("Multiple spaces") != "multiple-spaces")
|
||||
throw new Exception("Multiple spaces");
|
||||
if (GetParamCase("Tab\tCharacter") != "tab-character")
|
||||
throw new Exception("Tab\tCharacter");
|
||||
if (GetParamCase("New\nLine") != "new-line")
|
||||
throw new Exception("New\nLine");
|
||||
if (GetParamCase("Punctuation, Characters") != "punctuation-characters")
|
||||
throw new Exception("Punctuation, Characters");
|
||||
if (GetParamCase("M!o?r.e, @p:u;n|c\\t/u\"a\'t`i£o$n% ^c&h*a{r}a[c]t(e)r<s> ~l#i+k-e= _t¬hese") != "m-o-r-e-p-u-n-c-t-u-a-t-i-o-n-c-h-a-r-a-c-t-e-r-s-l-i-k-e-t-hese")
|
||||
throw new Exception("M!o?r.e, @p:u;n|c\\t/u\"a\'t`i£o$n% ^c&h*a{r}a[c]t(e)r<s> ~l#i+k-e= _t¬hese");
|
||||
if (GetParamCase("This string ends with punctuation!") != "this-string-ends-with-punctuation")
|
||||
throw new Exception("This string ends with punctuation!");
|
||||
if (GetParamCase("?This string starts with punctuation") != "this-string-starts-with-punctuation")
|
||||
throw new Exception("?This string starts with punctuation");
|
||||
if (GetParamCase("#This string has punctuation at both ends&") != "this-string-has-punctuation-at-both-ends")
|
||||
throw new Exception("#This string has punctuation at both ends&");
|
||||
if (GetParamCase("軟件 測試") != "軟件-測試")
|
||||
throw new Exception("軟件 測試");
|
||||
if (GetParamCase("実験 試し") != "実験-試し")
|
||||
throw new Exception("実験 試し");
|
||||
if (GetParamCase("יקספּערמענאַל פּרובירן") != "יקספּערמענאַל-פּרובירן")
|
||||
throw new Exception("יקספּערמענאַל פּרובירן");
|
||||
if (GetParamCase("я надеюсь, что это сработает") != "я-надеюсь-что-это-сработает")
|
||||
throw new Exception("я надеюсь, что это сработает");
|
||||
}
|
||||
|
||||
private static List<(int, int, string, FileInfo)> GetCollectionFromIndex(string sourceDirectory, string[] lines)
|
||||
{
|
||||
List<(int, int, string, FileInfo)> results = new();
|
||||
@ -58,44 +96,6 @@ internal static partial class HelperKanbanMetadata
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void TestParamCases()
|
||||
{
|
||||
if (GetParamCase("PascalCase") != "pascal-case")
|
||||
throw new Exception("PascalCase");
|
||||
if (GetParamCase("camelCase") != "camel-case")
|
||||
throw new Exception("camelCase");
|
||||
if (GetParamCase("snake_case") != "snake-case")
|
||||
throw new Exception("snake_case");
|
||||
if (GetParamCase("No Case") != "no-case")
|
||||
throw new Exception("No Case");
|
||||
if (GetParamCase("With 2 numbers 3") != "with-2-numbers-3")
|
||||
throw new Exception("With 2 numbers 3");
|
||||
if (GetParamCase("Multiple spaces") != "multiple-spaces")
|
||||
throw new Exception("Multiple spaces");
|
||||
if (GetParamCase("Tab\tCharacter") != "tab-character")
|
||||
throw new Exception("Tab\tCharacter");
|
||||
if (GetParamCase("New\nLine") != "new-line")
|
||||
throw new Exception("New\nLine");
|
||||
if (GetParamCase("Punctuation, Characters") != "punctuation-characters")
|
||||
throw new Exception("Punctuation, Characters");
|
||||
if (GetParamCase("M!o?r.e, @p:u;n|c\\t/u\"a\'t`i£o$n% ^c&h*a{r}a[c]t(e)r<s> ~l#i+k-e= _t¬hese") != "m-o-r-e-p-u-n-c-t-u-a-t-i-o-n-c-h-a-r-a-c-t-e-r-s-l-i-k-e-t-hese")
|
||||
throw new Exception("M!o?r.e, @p:u;n|c\\t/u\"a\'t`i£o$n% ^c&h*a{r}a[c]t(e)r<s> ~l#i+k-e= _t¬hese");
|
||||
if (GetParamCase("This string ends with punctuation!") != "this-string-ends-with-punctuation")
|
||||
throw new Exception("This string ends with punctuation!");
|
||||
if (GetParamCase("?This string starts with punctuation") != "this-string-starts-with-punctuation")
|
||||
throw new Exception("?This string starts with punctuation");
|
||||
if (GetParamCase("#This string has punctuation at both ends&") != "this-string-has-punctuation-at-both-ends")
|
||||
throw new Exception("#This string has punctuation at both ends&");
|
||||
if (GetParamCase("軟件 測試") != "軟件-測試")
|
||||
throw new Exception("軟件 測試");
|
||||
if (GetParamCase("実験 試し") != "実験-試し")
|
||||
throw new Exception("実験 試し");
|
||||
if (GetParamCase("יקספּערמענאַל פּרובירן") != "יקספּערמענאַל-פּרובירן")
|
||||
throw new Exception("יקספּערמענאַל פּרובירן");
|
||||
if (GetParamCase("я надеюсь, что это сработает") != "я-надеюсь-что-это-сработает")
|
||||
throw new Exception("я надеюсь, что это сработает");
|
||||
}
|
||||
|
||||
internal static void SetMetadata(ILogger log, AppSettings appSettings, string sourceDirectory)
|
||||
{
|
||||
bool? match;
|
||||
|
File diff suppressed because it is too large
Load Diff
274
Helpers/HelperVSCodePossibleExtension.cs
Normal file
274
Helpers/HelperVSCodePossibleExtension.cs
Normal file
@ -0,0 +1,274 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace File_Folder_Helper.Helpers;
|
||||
|
||||
internal static partial class HelperVSCodePossibleExtension
|
||||
{
|
||||
|
||||
private record Method(string Name,
|
||||
int ParameterCount,
|
||||
int StartLine,
|
||||
int EndLine,
|
||||
int FirstUsedLine);
|
||||
|
||||
[GeneratedRegex(@"(?<method>[A-Z]{1}[A-Za-z_0-9]*)\(")]
|
||||
private static partial Regex CSharpMethodName();
|
||||
|
||||
[GeneratedRegex(@"\s[a-zA-Z_]*,")]
|
||||
private static partial Regex CSharpParameter();
|
||||
|
||||
[GeneratedRegex(@"\b(public|private|internal|protected)\s\b(static)?\s?\b(partial)?\s?\b(async)?\s?[[\]<,>?a-zA-Z()\s]*\s[A-Z]{1}[a-zA-Z_]+\(.*\)")]
|
||||
private static partial Regex CSharpMethodLine();
|
||||
|
||||
private static string? GetName(string line)
|
||||
{
|
||||
string? result;
|
||||
Match match = CSharpMethodName().Match(line);
|
||||
if (!match.Success)
|
||||
result = null;
|
||||
else
|
||||
result = match.Groups["method"].Value;
|
||||
return result;
|
||||
}
|
||||
|
||||
private static int GetStartLine(string[] lines, int i)
|
||||
{
|
||||
int result = i;
|
||||
string line;
|
||||
for (int j = i - 1; j > -1; j--)
|
||||
{
|
||||
line = lines[j].Trim();
|
||||
if (!line.StartsWith('[') && !line.StartsWith("/// "))
|
||||
break;
|
||||
result--;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static int GetParameterCount(string line, string search)
|
||||
{
|
||||
int result;
|
||||
string after = line.Split(search)[^1];
|
||||
if (after.StartsWith(')'))
|
||||
result = 0;
|
||||
else
|
||||
{
|
||||
string[] segments = CSharpParameter().Split(after);
|
||||
result = segments.Length;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static int GetLineBlockCount(string line, bool isLinq)
|
||||
{
|
||||
int result = 0;
|
||||
bool ignore = false;
|
||||
for (int i = 0; i < line.Length; i++)
|
||||
{
|
||||
if (line[i] == '\'')
|
||||
i++;
|
||||
else if (!isLinq && !ignore && line[i] == '{')
|
||||
result++;
|
||||
else if (!isLinq && !ignore && line[i] == '}')
|
||||
result--;
|
||||
else if (isLinq && !ignore && line[i] == ';')
|
||||
result--;
|
||||
else if (i > 0 && line[i] == '"' && line[i - 1] != '\\')
|
||||
ignore = !ignore;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static int? GetFirstUsedLine(string[] lines, int i, string search, string searchNot, string searchWrap, int parameterCount)
|
||||
{
|
||||
int? result = null;
|
||||
string[] segments;
|
||||
string[] afterSegments;
|
||||
string lastSegmentBeforeDot;
|
||||
for (int j = 0; j < lines.Length; j++)
|
||||
{
|
||||
if (j == i)
|
||||
continue;
|
||||
segments = lines[j].Split(search);
|
||||
if (segments.Length == 1)
|
||||
{
|
||||
segments = lines[j].Split(searchNot);
|
||||
if (segments.Length == 1)
|
||||
{
|
||||
segments = lines[j].Split(searchWrap);
|
||||
if (segments.Length == 1)
|
||||
continue;
|
||||
}
|
||||
}
|
||||
lastSegmentBeforeDot = segments[^1].Split(").")[0];
|
||||
if (parameterCount == 0)
|
||||
{
|
||||
if (lastSegmentBeforeDot.Contains(','))
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
afterSegments = lastSegmentBeforeDot.Split(',');
|
||||
if (afterSegments.Length != parameterCount)
|
||||
continue;
|
||||
}
|
||||
result = j;
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static ReadOnlyCollection<int> GetMethodLines(ReadOnlyCollection<Method> methods)
|
||||
{
|
||||
List<int> results = new();
|
||||
foreach (Method method in methods)
|
||||
{
|
||||
for (int i = method.StartLine; i < method.EndLine + 1; i++)
|
||||
results.Add(i);
|
||||
}
|
||||
return new(results);
|
||||
}
|
||||
|
||||
private static ReadOnlyCollection<Method> GetMethods(string cSharpFile, ILogger<Worker> logger, string[] lines)
|
||||
{
|
||||
List<Method> results = new();
|
||||
int blocks;
|
||||
bool isLinq;
|
||||
int endLine;
|
||||
string line;
|
||||
string? name;
|
||||
int startLine;
|
||||
string search;
|
||||
string innerLine;
|
||||
string searchNot;
|
||||
string searchWrap;
|
||||
int parameterCount;
|
||||
int? firstUsedLine;
|
||||
string lineSegmentFirst;
|
||||
for (int i = 0; i < lines.Length; i++)
|
||||
{
|
||||
line = lines[i].Trim();
|
||||
if (string.IsNullOrEmpty(line))
|
||||
continue;
|
||||
if (line.Length < 5)
|
||||
continue;
|
||||
if (line.EndsWith(','))
|
||||
continue;
|
||||
if (!CSharpMethodLine().Match(line).Success)
|
||||
continue;
|
||||
name = GetName(line);
|
||||
search = $" {name}(";
|
||||
searchNot = $"!{name}(";
|
||||
searchWrap = $"({name}(";
|
||||
if (string.IsNullOrEmpty(name))
|
||||
continue;
|
||||
blocks = 0;
|
||||
startLine = GetStartLine(lines, i);
|
||||
parameterCount = GetParameterCount(line, search);
|
||||
isLinq = lines[i + 1].Trim() != "{";
|
||||
if (isLinq)
|
||||
blocks++;
|
||||
for (int j = i + 1; j < lines.Length; j++)
|
||||
{
|
||||
innerLine = lines[j].Trim();
|
||||
if (isLinq && string.IsNullOrEmpty(innerLine))
|
||||
{
|
||||
if (line.EndsWith(';'))
|
||||
blocks--;
|
||||
}
|
||||
blocks += GetLineBlockCount(innerLine, isLinq);
|
||||
if (blocks == 0)
|
||||
{
|
||||
endLine = j;
|
||||
if (lines.Length > j + 1 && string.IsNullOrEmpty(lines[j + 1].Trim()))
|
||||
endLine++;
|
||||
firstUsedLine = GetFirstUsedLine(lines, i, search, searchNot, searchWrap, parameterCount);
|
||||
if (firstUsedLine is null)
|
||||
{
|
||||
lineSegmentFirst = line.Split(search)[0];
|
||||
if (!lines[i - 1].Trim().StartsWith("[Obsolete"))
|
||||
{
|
||||
if (lineSegmentFirst.StartsWith("private"))
|
||||
logger.LogWarning("<{cSharpFileName}> {name} with {parameterCount} parameter(s) <{line}>", Path.GetFileName(cSharpFile), name, parameterCount, lineSegmentFirst);
|
||||
else
|
||||
logger.LogInformation("<{cSharpFileName}> {name} with {parameterCount} parameter(s) <{line}>", Path.GetFileName(cSharpFile), name, parameterCount, lineSegmentFirst);
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (j > lines.Length - 2)
|
||||
throw new Exception();
|
||||
results.Add(new(name, parameterCount, startLine, endLine, firstUsedLine.Value));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return new(results.OrderBy(l => l.FirstUsedLine).ToArray());
|
||||
}
|
||||
|
||||
private static bool WriteAllLines(string cSharpFile, string[] lines, ReadOnlyCollection<Method> methods)
|
||||
{
|
||||
bool result;
|
||||
List<string> results = new();
|
||||
ReadOnlyCollection<int> methodLines = GetMethodLines(methods);
|
||||
int minMethodLines = methodLines.Min();
|
||||
for (int i = 0; i < minMethodLines; i++)
|
||||
results.Add(lines[i]);
|
||||
foreach (Method method in methods)
|
||||
{
|
||||
for (int i = method.StartLine; i < method.EndLine + 1; i++)
|
||||
results.Add(lines[i]);
|
||||
}
|
||||
for (int i = minMethodLines; i < lines.Length; i++)
|
||||
{
|
||||
if (methodLines.Contains(i))
|
||||
continue;
|
||||
results.Add(lines[i]);
|
||||
}
|
||||
string text = File.ReadAllText(cSharpFile);
|
||||
string join = string.Join(Environment.NewLine, results);
|
||||
if (join == text)
|
||||
result = false;
|
||||
else
|
||||
{
|
||||
result = true;
|
||||
File.WriteAllText(cSharpFile, join);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static bool SortFile(ILogger<Worker> logger, string cSharpFile, string[] lines)
|
||||
{
|
||||
bool result;
|
||||
ReadOnlyCollection<Method> methods = GetMethods(cSharpFile, logger, lines);
|
||||
if (methods.Count == 0)
|
||||
result = false;
|
||||
else
|
||||
result = WriteAllLines(cSharpFile, lines, methods);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static void Sort(ILogger<Worker> logger, List<string> args)
|
||||
{
|
||||
bool result = false;
|
||||
bool check;
|
||||
string[] lines;
|
||||
long ticks = DateTime.Now.Ticks;
|
||||
logger.LogInformation("{ticks}", ticks);
|
||||
string[] cSharpFiles = Directory.GetFiles(args[0], "*.cs", SearchOption.TopDirectoryOnly);
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
foreach (string cSharpFile in cSharpFiles)
|
||||
{
|
||||
lines = File.ReadAllLines(cSharpFile);
|
||||
check = SortFile(logger, cSharpFile, lines);
|
||||
if (check && !result)
|
||||
result = true;
|
||||
}
|
||||
if (!result)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -11,6 +11,91 @@ internal static partial class HelperZipFilesByDate
|
||||
[GeneratedRegex("[a-zA-Z0-9]{1,}")]
|
||||
private static partial Regex LowerAlphaAlphaAndNumber();
|
||||
|
||||
private static bool SetDateFromZipEntry(ILogger log, string[] zipFiles, string keyFile, string keyFileB, string keyFileC)
|
||||
{
|
||||
bool result = false;
|
||||
string[] files;
|
||||
string checkFile;
|
||||
FileInfo fileInfo;
|
||||
string? zipDirectory;
|
||||
DateTimeOffset? dateTimeOffset;
|
||||
foreach (string zipFile in zipFiles)
|
||||
try
|
||||
{
|
||||
dateTimeOffset = null;
|
||||
fileInfo = new(zipFile);
|
||||
using ZipArchive zip = ZipFile.Open(zipFile, ZipArchiveMode.Read);
|
||||
foreach (ZipArchiveEntry zipArchiveEntry in zip.Entries)
|
||||
{
|
||||
if (!zipArchiveEntry.Name.EndsWith(keyFile))
|
||||
continue;
|
||||
dateTimeOffset = zipArchiveEntry.LastWriteTime;
|
||||
break;
|
||||
}
|
||||
zipDirectory = Path.GetDirectoryName(zipFile);
|
||||
if (dateTimeOffset is null || zipDirectory is null)
|
||||
continue;
|
||||
if (fileInfo.LastWriteTime != dateTimeOffset.Value.LocalDateTime)
|
||||
{
|
||||
File.SetLastWriteTime(fileInfo.FullName, dateTimeOffset.Value.LocalDateTime);
|
||||
if (!result)
|
||||
result = true;
|
||||
}
|
||||
files = Directory.GetFiles(zipDirectory, $"*{keyFile}", SearchOption.TopDirectoryOnly);
|
||||
foreach (string file in files)
|
||||
{
|
||||
fileInfo = new(file);
|
||||
if (fileInfo.LastWriteTime != dateTimeOffset.Value.LocalDateTime)
|
||||
{
|
||||
File.SetLastWriteTime(fileInfo.FullName, dateTimeOffset.Value.LocalDateTime);
|
||||
if (!result)
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
if (string.IsNullOrEmpty(keyFileB))
|
||||
continue;
|
||||
files = Directory.GetFiles(zipDirectory, keyFileB, SearchOption.TopDirectoryOnly);
|
||||
foreach (string file in files)
|
||||
{
|
||||
fileInfo = new(file);
|
||||
if (fileInfo.LastWriteTime != dateTimeOffset.Value.LocalDateTime)
|
||||
{
|
||||
File.SetLastWriteTime(fileInfo.FullName, dateTimeOffset.Value.LocalDateTime);
|
||||
if (!result)
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
if (string.IsNullOrEmpty(keyFileC))
|
||||
continue;
|
||||
files = Directory.GetFiles(zipDirectory, keyFileC, SearchOption.TopDirectoryOnly);
|
||||
foreach (string file in files)
|
||||
{
|
||||
fileInfo = new(file);
|
||||
if (fileInfo.LastWriteTime != dateTimeOffset.Value.LocalDateTime)
|
||||
{
|
||||
File.SetLastWriteTime(fileInfo.FullName, dateTimeOffset.Value.LocalDateTime);
|
||||
if (!result)
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
log.LogInformation("<{zipFile}> is invalid!", zipFile);
|
||||
checkFile = string.Concat(zipFile, ".err");
|
||||
for (int e = 0; e < short.MaxValue; e++)
|
||||
{
|
||||
if (!File.Exists(checkFile))
|
||||
break;
|
||||
checkFile = string.Concat(checkFile, e);
|
||||
}
|
||||
try
|
||||
{ File.Move(zipFile, checkFile); }
|
||||
catch (Exception) { log.LogInformation("<{zipFile}> couldn't be moved!", zipFile); }
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static bool ZipFilesByDate(ILogger log, string sourceDirectory, SearchOption searchOption = SearchOption.TopDirectoryOnly, string dayFormat = "")
|
||||
{
|
||||
bool result = false;
|
||||
@ -152,91 +237,6 @@ internal static partial class HelperZipFilesByDate
|
||||
return result;
|
||||
}
|
||||
|
||||
private static bool SetDateFromZipEntry(ILogger log, string[] zipFiles, string keyFile, string keyFileB, string keyFileC)
|
||||
{
|
||||
bool result = false;
|
||||
string[] files;
|
||||
string checkFile;
|
||||
FileInfo fileInfo;
|
||||
string? zipDirectory;
|
||||
DateTimeOffset? dateTimeOffset;
|
||||
foreach (string zipFile in zipFiles)
|
||||
try
|
||||
{
|
||||
dateTimeOffset = null;
|
||||
fileInfo = new(zipFile);
|
||||
using ZipArchive zip = ZipFile.Open(zipFile, ZipArchiveMode.Read);
|
||||
foreach (ZipArchiveEntry zipArchiveEntry in zip.Entries)
|
||||
{
|
||||
if (!zipArchiveEntry.Name.EndsWith(keyFile))
|
||||
continue;
|
||||
dateTimeOffset = zipArchiveEntry.LastWriteTime;
|
||||
break;
|
||||
}
|
||||
zipDirectory = Path.GetDirectoryName(zipFile);
|
||||
if (dateTimeOffset is null || zipDirectory is null)
|
||||
continue;
|
||||
if (fileInfo.LastWriteTime != dateTimeOffset.Value.LocalDateTime)
|
||||
{
|
||||
File.SetLastWriteTime(fileInfo.FullName, dateTimeOffset.Value.LocalDateTime);
|
||||
if (!result)
|
||||
result = true;
|
||||
}
|
||||
files = Directory.GetFiles(zipDirectory, $"*{keyFile}", SearchOption.TopDirectoryOnly);
|
||||
foreach (string file in files)
|
||||
{
|
||||
fileInfo = new(file);
|
||||
if (fileInfo.LastWriteTime != dateTimeOffset.Value.LocalDateTime)
|
||||
{
|
||||
File.SetLastWriteTime(fileInfo.FullName, dateTimeOffset.Value.LocalDateTime);
|
||||
if (!result)
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
if (string.IsNullOrEmpty(keyFileB))
|
||||
continue;
|
||||
files = Directory.GetFiles(zipDirectory, keyFileB, SearchOption.TopDirectoryOnly);
|
||||
foreach (string file in files)
|
||||
{
|
||||
fileInfo = new(file);
|
||||
if (fileInfo.LastWriteTime != dateTimeOffset.Value.LocalDateTime)
|
||||
{
|
||||
File.SetLastWriteTime(fileInfo.FullName, dateTimeOffset.Value.LocalDateTime);
|
||||
if (!result)
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
if (string.IsNullOrEmpty(keyFileC))
|
||||
continue;
|
||||
files = Directory.GetFiles(zipDirectory, keyFileC, SearchOption.TopDirectoryOnly);
|
||||
foreach (string file in files)
|
||||
{
|
||||
fileInfo = new(file);
|
||||
if (fileInfo.LastWriteTime != dateTimeOffset.Value.LocalDateTime)
|
||||
{
|
||||
File.SetLastWriteTime(fileInfo.FullName, dateTimeOffset.Value.LocalDateTime);
|
||||
if (!result)
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
log.LogInformation("<{zipFile}> is invalid!", zipFile);
|
||||
checkFile = string.Concat(zipFile, ".err");
|
||||
for (int e = 0; e < short.MaxValue; e++)
|
||||
{
|
||||
if (!File.Exists(checkFile))
|
||||
break;
|
||||
checkFile = string.Concat(checkFile, e);
|
||||
}
|
||||
try
|
||||
{ File.Move(zipFile, checkFile); }
|
||||
catch (Exception) { log.LogInformation("<{zipFile}> couldn't be moved!", zipFile); }
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static bool SetDateFromZipEntryForNuspec(ILogger log, string[] files) =>
|
||||
SetDateFromZipEntry(log, files, ".nuspec", "icon", "readme");
|
||||
|
||||
|
@ -9,6 +9,7 @@ public record AppSettings(string Company,
|
||||
string[] ExcludeSchemes,
|
||||
string PersonBirthdayFormat,
|
||||
char[] PersonCharacters,
|
||||
char[] PersonTitleFilters,
|
||||
string WorkingDirectoryName)
|
||||
{
|
||||
|
||||
|
@ -13,6 +13,7 @@ public class AppSettings
|
||||
public string[]? ExcludeSchemes { get; set; }
|
||||
public string? PersonBirthdayFormat { get; set; }
|
||||
public string? PersonCharacters { get; set; }
|
||||
public string? PersonTitleFilters { get; set; }
|
||||
public string? WorkingDirectoryName { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
@ -36,6 +37,8 @@ public class AppSettings
|
||||
throw new NullReferenceException(nameof(appSettings.PersonBirthdayFormat));
|
||||
if (appSettings?.PersonCharacters is null)
|
||||
throw new NullReferenceException(nameof(appSettings.PersonCharacters));
|
||||
if (appSettings?.PersonTitleFilters is null)
|
||||
throw new NullReferenceException(nameof(appSettings.PersonTitleFilters));
|
||||
if (appSettings?.WorkingDirectoryName is null)
|
||||
throw new NullReferenceException(nameof(appSettings.WorkingDirectoryName));
|
||||
result = new(
|
||||
@ -45,6 +48,7 @@ public class AppSettings
|
||||
appSettings.ExcludeSchemes,
|
||||
appSettings.PersonBirthdayFormat,
|
||||
appSettings.PersonCharacters.ToArray(),
|
||||
appSettings.PersonTitleFilters.ToArray(),
|
||||
appSettings.WorkingDirectoryName
|
||||
);
|
||||
return result;
|
||||
|
@ -8,6 +8,7 @@ public record Person(long Id,
|
||||
char? Sex,
|
||||
string? UId,
|
||||
Birth? Birth,
|
||||
string? Title,
|
||||
Death? Death,
|
||||
Change? Change,
|
||||
string[] Lines)
|
||||
|
12
Worker.cs
12
Worker.cs
@ -43,6 +43,7 @@ public class Worker : BackgroundService
|
||||
ConsoleKey.S,
|
||||
ConsoleKey.T,
|
||||
ConsoleKey.U,
|
||||
ConsoleKey.V,
|
||||
ConsoleKey.Z,
|
||||
ConsoleKey.Delete
|
||||
};
|
||||
@ -94,15 +95,23 @@ public class Worker : BackgroundService
|
||||
_Logger.LogInformation("F) Clipboard (All Directories and File Name Without Extension),");
|
||||
_Logger.LogInformation("G) Genealogical Data Communication");
|
||||
_Logger.LogInformation("H) Hardcoded file search and sort,");
|
||||
// I
|
||||
_Logger.LogInformation("J) Set Date from Json Entry");
|
||||
_Logger.LogInformation("K) Kanban support");
|
||||
_Logger.LogInformation("L) Log Merge (APC Log [0-9(8)]_*.log),");
|
||||
_Logger.LogInformation("N) Create Note Files,");
|
||||
_Logger.LogInformation("M) Markdown Wiki Link Verification,");
|
||||
// O
|
||||
// P
|
||||
// Q
|
||||
_Logger.LogInformation("R) Rename to old, copy, delete old");
|
||||
_Logger.LogInformation("S) Set Date from Zip Entry");
|
||||
_Logger.LogInformation("T) Too long rename");
|
||||
_Logger.LogInformation("U) Links for Hugo");
|
||||
_Logger.LogInformation("V) VSCode Hope Sort");
|
||||
// W
|
||||
// X
|
||||
// Y
|
||||
_Logger.LogInformation("Z) Zip file(s) by date,");
|
||||
_Logger.LogInformation("Delete) Delete empty directories,");
|
||||
consoleKey = Console.ReadKey().Key;
|
||||
@ -153,6 +162,9 @@ public class Worker : BackgroundService
|
||||
case ConsoleKey.U:
|
||||
Helpers.HelperMarkdown.MarkdownConvertLinksForHugo(_AppSettings, _Logger, _Args);
|
||||
break;
|
||||
case ConsoleKey.V:
|
||||
Helpers.HelperVSCodePossibleExtension.Sort(_Logger, _Args);
|
||||
break;
|
||||
case ConsoleKey.Z:
|
||||
_ = Helpers.HelperZipFilesByDate.ZipFilesByDate(_Logger, _Args[0]);
|
||||
break;
|
||||
|
Reference in New Issue
Block a user