Add option directory
Allow lower case drive letters
This commit is contained in:
@ -1,7 +1,9 @@
|
||||
using File_Folder_Helper.Helpers;
|
||||
using File_Folder_Helper.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
@ -24,7 +26,7 @@ internal static partial class Helper20240623
|
||||
|
||||
private record Input(long? AfterEpochTotalMilliseconds,
|
||||
string CodeInsiders,
|
||||
string? DestinationDirectory,
|
||||
ReadOnlyCollection<string> DestinationDirectories,
|
||||
string DirectoryFilter,
|
||||
string Done,
|
||||
string IndexFile,
|
||||
@ -379,10 +381,19 @@ internal static partial class Helper20240623
|
||||
string subTasks = args[3].Replace('_', ' ');
|
||||
string codeInsiders = args[4].Replace('_', ' ');
|
||||
string sourceDirectory = Path.GetFullPath(args[0]);
|
||||
string? destinationDirectory = args.Count < 8 ? null : Path.GetFullPath(args[9]);
|
||||
long? afterEpochTotalMilliseconds = args.Count < 9 ? null : long.Parse(args[10]);
|
||||
ReadOnlyCollection<string> tasks = args[6].Split(',').Select(l => l.Replace('_', ' ')).ToArray().AsReadOnly();
|
||||
Input input = new(afterEpochTotalMilliseconds, codeInsiders, destinationDirectory, directoryFilter, done, indexFile, searchPattern, subTasks, sourceDirectory, tasks);
|
||||
string[] tasks = args[6].Split(',').Select(l => l.Replace('_', ' ')).ToArray();
|
||||
long? afterEpochTotalMilliseconds = args.Count < 11 ? null : long.Parse(args[10]);
|
||||
string[] destinationDirectories = args.Count < 10 ? [] : args.Count < 12 ? [Path.GetFullPath(args[9])] : [Path.GetFullPath(args[9]), Path.GetFullPath(args[11])];
|
||||
Input input = new(AfterEpochTotalMilliseconds: afterEpochTotalMilliseconds,
|
||||
CodeInsiders: codeInsiders,
|
||||
DestinationDirectories: destinationDirectories.AsReadOnly(),
|
||||
DirectoryFilter: directoryFilter,
|
||||
Done: done,
|
||||
IndexFile: indexFile,
|
||||
SearchPattern: searchPattern,
|
||||
SubTasks: subTasks,
|
||||
SourceDirectory: sourceDirectory,
|
||||
Tasks: tasks.AsReadOnly());
|
||||
if (input.Tasks[0] != "- [" || input.Tasks[1] != "](")
|
||||
throw new Exception(JsonSerializer.Serialize(input, InputSourceGenerationContext.Default.Input));
|
||||
return input;
|
||||
@ -391,34 +402,39 @@ internal static partial class Helper20240623
|
||||
private static string? MaybeWriteAndGetIndexFile(Input input, Record record, string? checkDirectory)
|
||||
{
|
||||
string? result;
|
||||
if (string.IsNullOrEmpty(checkDirectory) || input.AfterEpochTotalMilliseconds is null || string.IsNullOrEmpty(input.DestinationDirectory) || !checkDirectory.Contains(input.DestinationDirectory))
|
||||
if (string.IsNullOrEmpty(checkDirectory) || input.AfterEpochTotalMilliseconds is null || input.DestinationDirectories.Count == 0)
|
||||
result = null;
|
||||
else
|
||||
{
|
||||
if (record.LineNumber.H1 is null)
|
||||
if (!input.DestinationDirectories.Any(checkDirectory.Contains))
|
||||
result = null;
|
||||
else
|
||||
{
|
||||
string segment = Path.GetFileName(checkDirectory);
|
||||
string h1 = record.LineNumber.Lines[record.LineNumber.H1.Value];
|
||||
DateTime utcEpochDateTime = new(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
||||
long utcEpochTotalMilliseconds = (long)Math.Floor(DateTime.UtcNow.Subtract(utcEpochDateTime).TotalMilliseconds);
|
||||
if (!long.TryParse(segment, out long check) || check < input.AfterEpochTotalMilliseconds || check > utcEpochTotalMilliseconds)
|
||||
if (record.LineNumber.H1 is null)
|
||||
result = null;
|
||||
else
|
||||
{
|
||||
ReadOnlyCollection<H1AndParamCase> h1ParamCaseCollection = GetH1ParamCaseCollection(input, record.LineNumber.Lines);
|
||||
if (h1ParamCaseCollection.Count == 0)
|
||||
string segment = Path.GetFileName(checkDirectory);
|
||||
string h1 = record.LineNumber.Lines[record.LineNumber.H1.Value];
|
||||
DateTime utcEpochDateTime = new(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
||||
long utcEpochTotalMilliseconds = (long)Math.Floor(DateTime.UtcNow.Subtract(utcEpochDateTime).TotalMilliseconds);
|
||||
if (!long.TryParse(segment, out long check) || check < input.AfterEpochTotalMilliseconds || check > utcEpochTotalMilliseconds)
|
||||
result = null;
|
||||
else
|
||||
{
|
||||
DateTime dateTime = utcEpochDateTime.AddMilliseconds(check).ToLocalTime();
|
||||
string seasonName = GetSeasonName(dateTime.DayOfYear);
|
||||
ReadOnlyCollection<string> directoryNames = HelperDirectory.GetDirectoryNames(checkDirectory);
|
||||
if (!directoryNames.Contains(dateTime.Year.ToString()) || !directoryNames.Contains($"{dateTime.Year}-{seasonName}") || !directoryNames.Contains(check.ToString()))
|
||||
ReadOnlyCollection<H1AndParamCase> h1ParamCaseCollection = GetH1ParamCaseCollection(input, record.LineNumber.Lines);
|
||||
if (h1ParamCaseCollection.Count == 0)
|
||||
result = null;
|
||||
else
|
||||
result = WriteAndGetIndexFile(h1, checkDirectory, h1ParamCaseCollection);
|
||||
{
|
||||
DateTime dateTime = utcEpochDateTime.AddMilliseconds(check).ToLocalTime();
|
||||
string seasonName = GetSeasonName(dateTime.DayOfYear);
|
||||
ReadOnlyCollection<string> directoryNames = HelperDirectory.GetDirectoryNames(checkDirectory);
|
||||
if (!directoryNames.Contains(dateTime.Year.ToString()) || !directoryNames.Contains($"{dateTime.Year}-{seasonName}") || !directoryNames.Contains(check.ToString()))
|
||||
result = null;
|
||||
else
|
||||
result = WriteAndGetIndexFile(h1, checkDirectory, h1ParamCaseCollection);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -478,15 +494,16 @@ internal static partial class Helper20240623
|
||||
return result;
|
||||
}
|
||||
|
||||
private static FileInfo GetIndexFileInfo(Input input, Record record, string codeInsidersLine)
|
||||
private static FileInfo GetIndexFileInfo(ILogger<Worker> logger, Input input, Record record, string codeInsidersLine)
|
||||
{
|
||||
FileInfo result;
|
||||
string? indexFile;
|
||||
List<string> results;
|
||||
string? checkDirectory = codeInsidersLine[input.CodeInsiders.Length..^1];
|
||||
string raw = codeInsidersLine[input.CodeInsiders.Length..^1];
|
||||
string checkDirectory = $"{raw[..2].ToUpper()}{raw[2..]}";
|
||||
if (!Directory.Exists(checkDirectory))
|
||||
{
|
||||
if (!string.IsNullOrEmpty(input.DestinationDirectory) && checkDirectory.Contains(input.DestinationDirectory))
|
||||
if (input.DestinationDirectories.Count > 0 && input.DestinationDirectories.Any(checkDirectory.Contains))
|
||||
_ = Directory.CreateDirectory(checkDirectory);
|
||||
}
|
||||
if (!Directory.Exists(checkDirectory))
|
||||
@ -507,6 +524,8 @@ internal static partial class Helper20240623
|
||||
indexFile = MaybeWriteAndGetIndexFile(input, record, checkDirectory);
|
||||
if (!string.IsNullOrEmpty(indexFile))
|
||||
results.Add(indexFile);
|
||||
else
|
||||
logger.LogInformation("<{checkDirectory}>", checkDirectory);
|
||||
}
|
||||
}
|
||||
result = results.Count == 0 ? new(Path.Combine(checkDirectory, input.IndexFile)) : new(results[0]);
|
||||
@ -549,7 +568,7 @@ internal static partial class Helper20240623
|
||||
if (record.StopLine is null)
|
||||
continue;
|
||||
codeInsidersLine = record.LineNumber.Lines[record.CodeInsidersLine.Value];
|
||||
fileInfo = GetIndexFileInfo(input, record, codeInsidersLine);
|
||||
fileInfo = GetIndexFileInfo(logger, input, record, codeInsidersLine);
|
||||
if (!fileInfo.Exists)
|
||||
{
|
||||
checkDirectory = codeInsidersLine[input.CodeInsiders.Length..^1];
|
||||
|
Reference in New Issue
Block a user