868 lines
47 KiB
C#
868 lines
47 KiB
C#
using Microsoft.Extensions.Configuration;
|
|
using Phares.Shared;
|
|
using System.Globalization;
|
|
using System.Text.Json;
|
|
using View_by_Distance.Compare.Models;
|
|
using View_by_Distance.Property.Models;
|
|
using View_by_Distance.Shared.Models.Methods;
|
|
using WindowsShortcutFactory;
|
|
|
|
namespace View_by_Distance.Compare;
|
|
|
|
public class Compare
|
|
{
|
|
|
|
private readonly AppSettings _AppSettings;
|
|
private readonly IsEnvironment _IsEnvironment;
|
|
private readonly Models.Configuration _Configuration;
|
|
private readonly List<KeyValuePair<string, string>> _FileKeyValuePairs;
|
|
private readonly List<(string Find, string Replace)> _RenameFindReplace;
|
|
private readonly List<(string Find, string Replace)> _RenameBFindReplace;
|
|
private readonly List<(string Find, string Replace)> _RenameCFindReplace;
|
|
private readonly List<(string Find, string Replace)> _SpellingFindReplace;
|
|
private readonly Dictionary<string, List<Tuple<string, Shared.Models.Property>>> _FilePropertiesKeyValuePairs;
|
|
|
|
public Compare(List<string> args, IsEnvironment isEnvironment, IConfigurationRoot configurationRoot, AppSettings appSettings, string workingDirectory, bool isSilent, IConsole console)
|
|
{
|
|
if (isSilent)
|
|
{ }
|
|
if (console is null)
|
|
{ }
|
|
string renameFrom;
|
|
string renameTo;
|
|
string[] segments;
|
|
_AppSettings = appSettings;
|
|
_RenameFindReplace = new();
|
|
_RenameBFindReplace = new();
|
|
_RenameCFindReplace = new();
|
|
_SpellingFindReplace = new();
|
|
_IsEnvironment = isEnvironment;
|
|
_FileKeyValuePairs = new List<KeyValuePair<string, string>>();
|
|
_FilePropertiesKeyValuePairs = new Dictionary<string, List<Tuple<string, Shared.Models.Property>>>();
|
|
string searchPattern = "*";
|
|
long ticks = DateTime.Now.Ticks;
|
|
List<string> topDirectories = new();
|
|
List<(int g, string sourceDirectory, string[] sourceDirectoryFiles)> groupCollection;
|
|
Property.Models.Configuration propertyConfiguration = Property.Models.Binder.Configuration.Get(isEnvironment, configurationRoot);
|
|
Property.Models.Configuration.Verify(propertyConfiguration, requireExist: true);
|
|
Models.Configuration configuration = Models.Stateless.Configuration.Get(isEnvironment, configurationRoot, workingDirectory, propertyConfiguration);
|
|
Verify(configuration);
|
|
bool reverse = false;
|
|
string outputExtension = ".jpg";
|
|
string eResultsFullGroupDirectory = string.Empty;
|
|
string a2PeopleSingletonDirectory = string.Empty;
|
|
Map.Models.Configuration? mapConfiguration = null;
|
|
Shared.Models.PersonContainer[] personContainers = Array.Empty<Shared.Models.PersonContainer>();
|
|
Map.Models.MapLogic mapLogic = new(_AppSettings.MaxDegreeOfParallelism, propertyConfiguration, mapConfiguration, ticks, personContainers, a2PeopleSingletonDirectory, eResultsFullGroupDirectory);
|
|
A_Property propertyLogic = GetPropertyLogic(reverse, outputExtension, mapLogic);
|
|
foreach (string spelling in configuration.Spelling)
|
|
{
|
|
segments = spelling.Split('|');
|
|
if (segments.Length != 2)
|
|
throw new Exception("Change configuration");
|
|
if (segments[1].Contains(segments[0]))
|
|
throw new Exception($"Change configuration {segments[1]}.Contains({segments[0]})!");
|
|
_SpellingFindReplace.Add(new(segments[0], segments[1]));
|
|
}
|
|
foreach (string rename in configuration.Rename)
|
|
{
|
|
segments = rename.Split('|');
|
|
if (segments.Length is not 2 and not 4)
|
|
throw new Exception("Change configuration");
|
|
renameFrom = Path.Combine(propertyConfiguration.RootDirectory, segments[0]);
|
|
renameTo = Path.Combine(propertyConfiguration.RootDirectory, segments[1]);
|
|
if (renameTo.Contains(renameFrom))
|
|
throw new Exception($"Change configuration {renameTo}.Contains({renameFrom})!");
|
|
_RenameFindReplace.Add(new(renameFrom, renameTo));
|
|
if (segments.Length == 4)
|
|
{
|
|
renameFrom = Path.Combine(propertyConfiguration.RootDirectory, segments[2]);
|
|
renameTo = Path.Combine(propertyConfiguration.RootDirectory, segments[3]);
|
|
if (renameTo.Contains(renameFrom))
|
|
throw new Exception($"Change configuration {renameTo}.Contains({renameFrom})!");
|
|
_RenameFindReplace.Add(new(renameFrom, renameTo));
|
|
}
|
|
}
|
|
foreach (string rename in configuration.RenameB)
|
|
{
|
|
segments = rename.Split('|');
|
|
if (segments.Length is not 2)
|
|
throw new Exception("Change configuration");
|
|
renameFrom = Path.GetFullPath(string.Concat(propertyConfiguration.RootDirectory, segments[0]));
|
|
renameTo = Path.GetFullPath(string.Concat(propertyConfiguration.RootDirectory, segments[1]));
|
|
if (renameTo.Contains(renameFrom))
|
|
throw new Exception($"Change configuration {renameTo}.Contains({renameFrom})!");
|
|
_RenameBFindReplace.Add(new(renameFrom, renameTo));
|
|
}
|
|
for (int i = 0; i < configuration.RenameC.Length; i++)
|
|
{
|
|
renameFrom = Path.GetFullPath(string.Concat(propertyConfiguration.RootDirectory, configuration.RenameC[i]));
|
|
renameTo = Path.Combine(propertyConfiguration.RootDirectory, GetRename(configuration.RenameC[i]));
|
|
if (renameTo.Contains(renameFrom))
|
|
throw new Exception("Change configuration!");
|
|
_RenameCFindReplace.Add(new(renameFrom, renameTo));
|
|
}
|
|
(_, groupCollection) = Property.Models.Stateless.Container.GetGroupCollection(propertyConfiguration.RootDirectory, searchPattern, topDirectories);
|
|
if (appSettings.MaxDegreeOfParallelism < 2)
|
|
ticks = LogDelta(ticks, nameof(Property.Models.Stateless.Container.GetGroupCollection));
|
|
_Logger?.LogInformation($"{nameof(Property.Models.Stateless.Container.GetGroupCollection)} has finished");
|
|
_Configuration = configuration;
|
|
List<string> missingVerifyToSeasonCollection = GetMissingVerifyToSeasonCollection(topDirectories, groupCollection);
|
|
if (missingVerifyToSeasonCollection.Any())
|
|
throw new Exception($"Update configuration with the following {Environment.NewLine} {string.Join(Environment.NewLine, missingVerifyToSeasonCollection)}");
|
|
if (PossiblyRename(topDirectories, groupCollection))
|
|
{
|
|
topDirectories.Clear();
|
|
_ = Shared.Models.Stateless.Methods.IPath.DeleteEmptyDirectories(propertyConfiguration.RootDirectory);
|
|
(_, groupCollection) = Property.Models.Stateless.Container.GetGroupCollection(propertyConfiguration.RootDirectory, searchPattern, topDirectories);
|
|
if (appSettings.MaxDegreeOfParallelism < 2)
|
|
ticks = LogDelta(ticks, nameof(Property.Models.Stateless.Container.GetGroupCollection));
|
|
}
|
|
_Logger?.LogInformation($"{nameof(PossiblyRename)} has finished");
|
|
if (PossiblyRenameB(topDirectories, groupCollection))
|
|
{
|
|
topDirectories.Clear();
|
|
_ = Shared.Models.Stateless.Methods.IPath.DeleteEmptyDirectories(propertyConfiguration.RootDirectory);
|
|
(_, groupCollection) = Property.Models.Stateless.Container.GetGroupCollection(propertyConfiguration.RootDirectory, searchPattern, topDirectories);
|
|
if (appSettings.MaxDegreeOfParallelism < 2)
|
|
ticks = LogDelta(ticks, nameof(Property.Models.Stateless.Container.GetGroupCollection));
|
|
}
|
|
_Logger?.LogInformation($"{nameof(PossiblyRenameB)} has finished");
|
|
if (PossiblyRenameC(topDirectories, groupCollection))
|
|
{
|
|
topDirectories.Clear();
|
|
_ = Shared.Models.Stateless.Methods.IPath.DeleteEmptyDirectories(propertyConfiguration.RootDirectory);
|
|
(_, groupCollection) = Property.Models.Stateless.Container.GetGroupCollection(propertyConfiguration.RootDirectory, searchPattern, topDirectories);
|
|
if (appSettings.MaxDegreeOfParallelism < 2)
|
|
ticks = LogDelta(ticks, nameof(Property.Models.Stateless.Container.GetGroupCollection));
|
|
}
|
|
_Logger?.LogInformation($"{nameof(PossiblyRenameC)} has finished");
|
|
if (PossiblyCorrect(topDirectories, groupCollection))
|
|
{
|
|
topDirectories.Clear();
|
|
_ = Shared.Models.Stateless.Methods.IPath.DeleteEmptyDirectories(propertyConfiguration.RootDirectory);
|
|
(_, groupCollection) = Property.Models.Stateless.Container.GetGroupCollection(propertyConfiguration.RootDirectory, searchPattern, topDirectories);
|
|
if (appSettings.MaxDegreeOfParallelism < 2)
|
|
ticks = LogDelta(ticks, nameof(Property.Models.Stateless.Container.GetGroupCollection));
|
|
}
|
|
_Logger?.LogInformation($"{nameof(PossiblyCorrect)} has finished");
|
|
string[] dbFiles = Directory.GetFiles(propertyConfiguration.RootDirectory, "*.db", SearchOption.AllDirectories);
|
|
foreach (string dbFile in dbFiles)
|
|
File.Delete(dbFile);
|
|
_Logger?.LogInformation("deleting *.db files has finished");
|
|
if (dbFiles.Any())
|
|
{
|
|
topDirectories.Clear();
|
|
_ = Shared.Models.Stateless.Methods.IPath.DeleteEmptyDirectories(propertyConfiguration.RootDirectory);
|
|
(_, groupCollection) = Property.Models.Stateless.Container.GetGroupCollection(propertyConfiguration.RootDirectory, searchPattern, topDirectories);
|
|
if (appSettings.MaxDegreeOfParallelism < 2)
|
|
ticks = LogDelta(ticks, nameof(Property.Models.Stateless.Container.GetGroupCollection));
|
|
}
|
|
if (_IsEnvironment.Development && propertyConfiguration.PopulatePropertyId)
|
|
throw new Exception("Copy keyValuePairs-####.json file");
|
|
(int j, int f, int t, Shared.Models.Container[] containers) = Container.Models.Stateless.Methods.IContainer.GetContainers(propertyConfiguration, propertyLogic);
|
|
if (propertyLogic.ExceptionsDirectories.Any())
|
|
throw new Exception();
|
|
if (propertyConfiguration.PopulatePropertyId && Shared.Models.Stateless.Methods.IProperty.Any(containers))
|
|
{
|
|
propertyLogic.SavePropertyParallelWork(ticks, containers);
|
|
if (appSettings.MaxDegreeOfParallelism < 2)
|
|
ticks = LogDelta(ticks, nameof(A_Property.SavePropertyParallelWork));
|
|
if (propertyLogic.ExceptionsDirectories.Any())
|
|
throw new Exception();
|
|
}
|
|
if (!isSilent)
|
|
{
|
|
_Logger?.LogInformation("First pass completed");
|
|
for (int y = 0; y < int.MaxValue; y++)
|
|
{
|
|
_Logger?.LogInformation("Press \"Y\" key to continue or close console if compare not needed");
|
|
if (Console.ReadKey().Key == ConsoleKey.Y)
|
|
break;
|
|
}
|
|
_Logger?.LogInformation(". . .");
|
|
}
|
|
if (!isSilent)
|
|
{
|
|
string aPropertySingletonDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(propertyConfiguration, nameof(A_Property), "{}");
|
|
if (Directory.Exists(aPropertySingletonDirectory))
|
|
{
|
|
ConsoleKey? consoleKey = null;
|
|
for (int y = 0; y < int.MaxValue; y++)
|
|
{
|
|
_Logger?.LogInformation($"Execute {nameof(ChangeExtensionFromDeleteToJson)} \"Y(es)\" or \"N(o)\"?");
|
|
consoleKey = Console.ReadKey().Key;
|
|
if (consoleKey is ConsoleKey.Y or ConsoleKey.N)
|
|
break;
|
|
}
|
|
_Logger?.LogInformation(". . .");
|
|
if (consoleKey == ConsoleKey.Y)
|
|
ChangeExtensionFromDeleteToJson(aPropertySingletonDirectory);
|
|
}
|
|
}
|
|
if (!isSilent)
|
|
{
|
|
_Logger?.LogInformation("Second pass completed");
|
|
for (int y = 0; y < int.MaxValue; y++)
|
|
{
|
|
_Logger?.LogInformation("Press \"Y\" key to continue or close console if compare not needed");
|
|
if (Console.ReadKey().Key == ConsoleKey.Y)
|
|
break;
|
|
}
|
|
_Logger?.LogInformation(". . .");
|
|
}
|
|
string aPropertyContentCollectionDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(propertyConfiguration, nameof(A_Property), propertyConfiguration.ResultContentCollection);
|
|
ThirdPassToMove(propertyConfiguration, mapLogic, propertyLogic, containers, aPropertyContentCollectionDirectory);
|
|
if (!isSilent)
|
|
{
|
|
_Logger?.LogInformation("Third pass completed");
|
|
for (int y = 0; y < int.MaxValue; y++)
|
|
{
|
|
_Logger?.LogInformation("Press \"Y\" key to continue or close console if compare not needed");
|
|
if (Console.ReadKey().Key == ConsoleKey.Y)
|
|
break;
|
|
}
|
|
_Logger?.LogInformation(". . .");
|
|
}
|
|
FourthPassCreateWindowsShortcuts(propertyConfiguration, mapLogic, propertyLogic, containers, saveToCollection: false, keepAll: false);
|
|
if (!isSilent)
|
|
{
|
|
_Logger?.LogInformation("Fourth pass completed");
|
|
for (int y = 0; y < int.MaxValue; y++)
|
|
{
|
|
_Logger?.LogInformation("Press \"Y\" key to continue or close console if compare not needed");
|
|
if (Console.ReadKey().Key == ConsoleKey.Y)
|
|
break;
|
|
}
|
|
_Logger?.LogInformation(". . .");
|
|
}
|
|
SaveDiffFilesOrSaveLogAndMoveFiles(propertyConfiguration);
|
|
string currentYearDirectory = Path.Combine(propertyConfiguration.RootDirectory, $". {DateTime.Now:yyyy}");
|
|
if (!Directory.Exists(currentYearDirectory))
|
|
_ = Directory.CreateDirectory(currentYearDirectory);
|
|
}
|
|
|
|
private static void Verify(Models.Configuration configuration)
|
|
{
|
|
if (configuration.Spelling is null || !configuration.Spelling.Any())
|
|
throw new NullReferenceException(nameof(configuration.Spelling));
|
|
}
|
|
|
|
private A_Property GetPropertyLogic(bool reverse, string outputExtension, Map.Models.MapLogic mapLogic)
|
|
{
|
|
A_Property result;
|
|
if (_Configuration?.PropertyConfiguration is null)
|
|
throw new NullReferenceException(nameof(_Configuration.PropertyConfiguration));
|
|
result = new(_AppSettings.MaxDegreeOfParallelism, _Configuration.PropertyConfiguration, outputExtension, reverse);
|
|
string fromPrepareForOld = "34720-637858334555170379.tsv";
|
|
string fromPrepareForOldFile = Path.Combine(_Configuration.PropertyConfiguration.RootDirectory, fromPrepareForOld);
|
|
if (File.Exists(fromPrepareForOldFile))
|
|
{
|
|
string[] lines;
|
|
string[] columns;
|
|
List<string> debug = new();
|
|
long ticks = DateTime.Now.Ticks;
|
|
lines = File.ReadAllLines(fromPrepareForOldFile);
|
|
string resultsDirectory = $"{_Configuration.PropertyConfiguration.RootDirectory}-Results";
|
|
int[]? zeros = (from l in mapLogic.IndicesFromNew where l.Value.Any() select l.Value[0]).ToArray();
|
|
lines = (from l in mapLogic.IndicesFromNew select string.Concat(l.Key, '\t', string.Join('\t', l.Value))).ToArray();
|
|
if (!Directory.Exists(resultsDirectory))
|
|
_ = Directory.CreateDirectory(resultsDirectory);
|
|
File.WriteAllLines(Path.Combine(resultsDirectory, $"{ticks}.tsv"), lines);
|
|
string json = JsonSerializer.Serialize(mapLogic.IndicesFromNew, new JsonSerializerOptions { WriteIndented = true });
|
|
File.WriteAllText(Path.Combine(resultsDirectory, $"{ticks}.json"), json);
|
|
foreach (string line in lines)
|
|
{
|
|
columns = line.Split('\t');
|
|
// select $"{l.Index}\t{l.PropertyId}\t{l.RegexResult}\t{new DateTime(l.Ticks):yyyy-MM-dd_HH-mm-ss}\t{l.PropertyTicks}\t{l.RelativeDirectory}\t{l.FileName}"
|
|
if (columns.Length != 7)
|
|
continue;
|
|
if (!int.TryParse(columns[1], out int propertyId))
|
|
continue;
|
|
if (!zeros.Contains(propertyId))
|
|
debug.Add(line);
|
|
else
|
|
debug.Add(propertyId.ToString());
|
|
}
|
|
File.WriteAllLines(Path.Combine(resultsDirectory, $"{ticks}-{fromPrepareForOld}"), debug);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
private string GetRename(string renameA)
|
|
{
|
|
string result;
|
|
int season;
|
|
DateTime dateTime;
|
|
string seasonName;
|
|
string[] pathSegments;
|
|
string[] directorySegments;
|
|
string corrected = renameA[1..];
|
|
if ((from l in _SpellingFindReplace where corrected.Contains(l.Find) select true).Any())
|
|
{
|
|
foreach ((string find, string replace) in _SpellingFindReplace)
|
|
corrected = corrected.Replace(find, replace);
|
|
}
|
|
corrected = corrected.Replace("Back to the hospital", "September 2007").Replace("Birthday", "September 2007").Replace("Aug Sept 09", "Sept 09");
|
|
pathSegments = corrected.Split('/');
|
|
directorySegments = pathSegments[0].Split(' ');
|
|
bool hasZzz = directorySegments.Contains("zzz");
|
|
if (hasZzz)
|
|
{
|
|
corrected = corrected.Replace("zzz ", string.Empty);
|
|
pathSegments = corrected.Split('/');
|
|
directorySegments = pathSegments[0].Split(' ');
|
|
}
|
|
if (pathSegments[^1].Contains('-'))
|
|
{
|
|
directorySegments = pathSegments[^1].Split(' ');
|
|
if (!DateTime.TryParseExact(string.Join(' ', directorySegments.Take(3)), "yyyy-MM-dd", CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTime))
|
|
throw new Exception("l");
|
|
(season, seasonName) = Shared.Models.Stateless.Methods.IProperty.GetSeason(dateTime.DayOfYear);
|
|
result = string.Concat($"={dateTime:yyyy}.{season} {seasonName} ", string.Join(' ', pathSegments[0].Split(' ').Take(2)));
|
|
}
|
|
else if (pathSegments.Length == 1)
|
|
{
|
|
directorySegments = pathSegments[^1].Split(' ');
|
|
if (DateTime.TryParseExact(directorySegments[^1], "yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTime))
|
|
{
|
|
(season, seasonName) = Shared.Models.Stateless.Methods.IProperty.GetSeason(dateTime.DayOfYear);
|
|
result = string.Concat($"={dateTime:yyyy}.{season} {seasonName} ", string.Join(' ', pathSegments[0].Split(' ').Take(2)));
|
|
}
|
|
else
|
|
throw new Exception("1");
|
|
}
|
|
else if (pathSegments.Length == 2)
|
|
{
|
|
directorySegments = pathSegments[^1].Split(' ');
|
|
if (directorySegments.Length == 1)
|
|
{
|
|
directorySegments = pathSegments[0].Split(' ');
|
|
if (DateTime.TryParseExact(directorySegments[^1], "yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTime))
|
|
{
|
|
(season, seasonName) = Shared.Models.Stateless.Methods.IProperty.GetSeason(dateTime.DayOfYear);
|
|
result = string.Concat($"={dateTime:yyyy}.{season} {seasonName} ", string.Join(' ', pathSegments[0].Split(' ').Take(2)));
|
|
}
|
|
else
|
|
throw new Exception("2,1");
|
|
}
|
|
else if (directorySegments.Length == 4)
|
|
{
|
|
directorySegments = pathSegments[0].Split(' ');
|
|
if (DateTime.TryParseExact(directorySegments[^1], "yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTime))
|
|
{
|
|
(season, seasonName) = Shared.Models.Stateless.Methods.IProperty.GetSeason(dateTime.DayOfYear);
|
|
result = string.Concat($"={dateTime:yyyy}.{season} {seasonName} ", string.Join(' ', pathSegments[0].Split(' ').Take(2)));
|
|
}
|
|
else
|
|
throw new Exception("2,4");
|
|
}
|
|
else if (directorySegments.Length == 2)
|
|
{
|
|
if (DateTime.TryParseExact(string.Join(' ', directorySegments.Take(2)), "MMM yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTime))
|
|
{
|
|
(season, seasonName) = Shared.Models.Stateless.Methods.IProperty.GetSeason(dateTime.DayOfYear);
|
|
result = string.Concat($"={dateTime:yyyy}.{season} {seasonName} ", string.Join(' ', pathSegments[0].Split(' ').Take(2)));
|
|
}
|
|
else if (DateTime.TryParseExact(string.Join(' ', directorySegments.Take(2)), "MMM yy", CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTime))
|
|
{
|
|
(season, seasonName) = Shared.Models.Stateless.Methods.IProperty.GetSeason(dateTime.DayOfYear);
|
|
result = string.Concat($"={dateTime:yyyy}.{season} {seasonName} ", string.Join(' ', pathSegments[0].Split(' ').Take(2)));
|
|
}
|
|
else if (DateTime.TryParseExact(string.Concat(directorySegments[0][..3], ' ', directorySegments[1]), "MMM yy", CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTime))
|
|
{
|
|
(season, seasonName) = Shared.Models.Stateless.Methods.IProperty.GetSeason(dateTime.DayOfYear);
|
|
result = string.Concat($"={dateTime:yyyy}.{season} {seasonName} ", string.Join(' ', pathSegments[0].Split(' ').Take(2)));
|
|
}
|
|
else if (DateTime.TryParseExact(string.Join(' ', directorySegments.Take(2)), "MMMM yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTime))
|
|
{
|
|
(season, seasonName) = Shared.Models.Stateless.Methods.IProperty.GetSeason(dateTime.DayOfYear);
|
|
result = string.Concat($"={dateTime:yyyy}.{season} {seasonName} ", string.Join(' ', pathSegments[0].Split(' ').Take(2)));
|
|
}
|
|
else
|
|
throw new Exception("2,2");
|
|
}
|
|
else if (directorySegments.Length == 3)
|
|
{
|
|
if (DateTime.TryParseExact(string.Join(' ', directorySegments.Take(3)), "MMMM dd yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTime))
|
|
{
|
|
(season, seasonName) = Shared.Models.Stateless.Methods.IProperty.GetSeason(dateTime.DayOfYear);
|
|
result = string.Concat($"={dateTime:yyyy}.{season} {seasonName} ", string.Join(' ', pathSegments[0].Split(' ').Take(2)));
|
|
}
|
|
else if (DateTime.TryParseExact(string.Join(' ', directorySegments.Take(3)), "MMMM d yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTime))
|
|
{
|
|
(season, seasonName) = Shared.Models.Stateless.Methods.IProperty.GetSeason(dateTime.DayOfYear);
|
|
result = string.Concat($"={dateTime:yyyy}.{season} {seasonName} ", string.Join(' ', pathSegments[0].Split(' ').Take(2)));
|
|
}
|
|
else
|
|
throw new Exception("2,3");
|
|
}
|
|
else
|
|
throw new Exception("2");
|
|
}
|
|
else if (pathSegments.Length == 3)
|
|
{
|
|
directorySegments = pathSegments[^1].Split(' ');
|
|
if (DateTime.TryParseExact(string.Join(' ', directorySegments.Take(3)), "MMMM dd yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTime))
|
|
{
|
|
(season, seasonName) = Shared.Models.Stateless.Methods.IProperty.GetSeason(dateTime.DayOfYear);
|
|
result = string.Concat($"={dateTime:yyyy}.{season} {seasonName} ", string.Join(' ', pathSegments[0].Split(' ').Take(2)));
|
|
}
|
|
else if (DateTime.TryParseExact(string.Join(' ', directorySegments.Take(3)), "MMMM d yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTime))
|
|
{
|
|
(season, seasonName) = Shared.Models.Stateless.Methods.IProperty.GetSeason(dateTime.DayOfYear);
|
|
result = string.Concat($"={dateTime:yyyy}.{season} {seasonName} ", string.Join(' ', pathSegments[0].Split(' ').Take(2)));
|
|
}
|
|
else
|
|
throw new Exception("3");
|
|
}
|
|
else
|
|
throw new Exception("e");
|
|
if (hasZzz)
|
|
result = string.Concat("zzz ", result);
|
|
return result;
|
|
}
|
|
|
|
private long LogDelta(long ticks, string? methodName)
|
|
{
|
|
long result;
|
|
double delta = new TimeSpan(DateTime.Now.Ticks - ticks).TotalMilliseconds;
|
|
_Log.Debug($"{methodName} took {Math.Floor(delta)} millisecond(s)");
|
|
result = DateTime.Now.Ticks;
|
|
return result;
|
|
}
|
|
|
|
private void ChangeExtensionFromDeleteToJson(string aPropertySingletonDirectory)
|
|
{
|
|
string searchPattern = "*.delete";
|
|
long ticks = DateTime.Now.Ticks;
|
|
List<string> topDirectories = new();
|
|
List<(int g, string sourceDirectory, string[] sourceDirectoryFiles)> groupCollection;
|
|
(_, groupCollection) = Property.Models.Stateless.Container.GetGroupCollection(aPropertySingletonDirectory, searchPattern, topDirectories);
|
|
if (_AppSettings.MaxDegreeOfParallelism < 2)
|
|
ticks = LogDelta(ticks, nameof(Property.Models.Stateless.Container.GetGroupCollection));
|
|
foreach ((int g, string sourceDirectory, string[] sourceDirectoryFiles) in groupCollection)
|
|
{
|
|
if (!topDirectories.Any())
|
|
continue;
|
|
foreach (string sourceDirectoryFile in sourceDirectoryFiles)
|
|
File.Move(sourceDirectoryFile, Path.ChangeExtension(sourceDirectoryFile, ".json"));
|
|
}
|
|
}
|
|
|
|
private void ThirdPassToMove(Property.Models.Configuration configuration, Map.Models.MapLogic mapLogic, A_Property propertyLogic, Shared.Models.Container[] containers, string aPropertyContentCollectionDirectory)
|
|
{
|
|
if (_Configuration?.PropertyConfiguration is null)
|
|
throw new NullReferenceException(nameof(_Configuration.PropertyConfiguration));
|
|
int stay = 0;
|
|
string fileName;
|
|
string id = " - Id";
|
|
string? directoryName;
|
|
ConsoleKey? consoleKey = null;
|
|
long ticks = DateTime.Now.Ticks;
|
|
Shared.Models.Property? property;
|
|
string filteredSourceDirectoryFile;
|
|
List<string> fileStayCollection = new();
|
|
List<string> fileMoveCollection = new();
|
|
List<string> distinctDirectories = new();
|
|
List<KeyValuePair<int, int[]>> valueCollection = new();
|
|
List<Property.Models.DirectoryInfo> directoryInfoCollection = new();
|
|
propertyLogic.SavePropertyParallelWork(ticks, containers);
|
|
if (propertyLogic.ExceptionsDirectories.Any())
|
|
throw new Exception();
|
|
foreach (Property.Models.DirectoryInfo group in directoryInfoCollection)
|
|
{
|
|
for (int i = 0; i < group.PropertyCollection.Length; i++)
|
|
{
|
|
property = group.PropertyCollection[i];
|
|
if (property?.Id is null)
|
|
continue;
|
|
filteredSourceDirectoryFile = group.FilteredSourceDirectoryFiles[i];
|
|
valueCollection.Add(new(property.Id.Value, property.Indices));
|
|
if (!mapLogic.IndicesFromNew.ContainsKey(property.Id.Value))
|
|
stay += 1;
|
|
else if (!fileMoveCollection.Contains(filteredSourceDirectoryFile))
|
|
fileMoveCollection.Add(filteredSourceDirectoryFile);
|
|
}
|
|
}
|
|
string[] lines = (from l in valueCollection select string.Concat(l.Key, '\t', string.Join('\t', l.Value))).ToArray();
|
|
if (!Directory.Exists(aPropertyContentCollectionDirectory))
|
|
_ = Directory.CreateDirectory(aPropertyContentCollectionDirectory);
|
|
File.WriteAllLines(Path.Combine(aPropertyContentCollectionDirectory, $"{ticks}.tsv"), lines);
|
|
string json = JsonSerializer.Serialize(valueCollection, new JsonSerializerOptions { WriteIndented = true });
|
|
File.WriteAllText(Path.Combine(aPropertyContentCollectionDirectory, $"{ticks}.json"), json);
|
|
foreach (string fileMove in fileMoveCollection)
|
|
{
|
|
directoryName = Path.GetDirectoryName(string.Concat(_Configuration.PropertyConfiguration.RootDirectory, id, fileMove[_Configuration.PropertyConfiguration.RootDirectory.Length..]));
|
|
if (string.IsNullOrEmpty(directoryName))
|
|
continue;
|
|
if (!distinctDirectories.Contains(directoryName))
|
|
distinctDirectories.Add(directoryName);
|
|
}
|
|
foreach (string distinctDirectory in distinctDirectories)
|
|
{
|
|
if (!Directory.Exists(distinctDirectory))
|
|
_ = Directory.CreateDirectory(distinctDirectory);
|
|
}
|
|
_Logger?.LogInformation($"{stay} file(s) are staying and {fileMoveCollection.Count} file(s) will be moved");
|
|
for (int y = 0; y < int.MaxValue; y++)
|
|
{
|
|
_Logger?.LogInformation($"Press \"M\" key to {nameof(File.Move)}");
|
|
_Logger?.LogInformation("Press \"End\" key when ready to skip or close console if compare not needed");
|
|
consoleKey = Console.ReadKey().Key;
|
|
if (consoleKey is ConsoleKey.M or ConsoleKey.End)
|
|
break;
|
|
}
|
|
_Logger?.LogInformation(". . .");
|
|
if (consoleKey.HasValue && consoleKey.Value == ConsoleKey.M)
|
|
{
|
|
foreach (string fileMove in fileMoveCollection)
|
|
{
|
|
fileName = string.Concat(_Configuration.PropertyConfiguration.RootDirectory, id, fileMove[_Configuration.PropertyConfiguration.RootDirectory.Length..]);
|
|
File.Move(fileMove, fileName);
|
|
}
|
|
for (int i = 1; i < 4; i++)
|
|
_ = Shared.Models.Stateless.Methods.IPath.DeleteEmptyDirectories(_Configuration.PropertyConfiguration.RootDirectory);
|
|
}
|
|
}
|
|
|
|
private void FourthPassCreateWindowsShortcuts(Property.Models.Configuration configuration, Map.Models.MapLogic mapLogic, A_Property propertyLogic, Shared.Models.Container[] containers, bool saveToCollection, bool keepAll)
|
|
{
|
|
int stay = 0;
|
|
ConsoleKey? consoleKey = null;
|
|
long ticks = DateTime.Now.Ticks;
|
|
Shared.Models.Property? property;
|
|
string filteredSourceDirectoryFile;
|
|
List<string> fileMoveCollection = new();
|
|
List<KeyValuePair<int, int[]>> valueCollection = new();
|
|
(long Ticks, string FilteredSourceDirectoryFile, string PropertyDirectory, int PropertyId)[] collection;
|
|
List<Property.Models.DirectoryInfo> directoryInfoCollection = new();
|
|
propertyLogic.SavePropertyParallelWork(ticks, containers);
|
|
if (propertyLogic.ExceptionsDirectories.Any())
|
|
throw new Exception();
|
|
foreach (Property.Models.DirectoryInfo group in directoryInfoCollection)
|
|
{
|
|
for (int i = 0; i < group.PropertyCollection.Length; i++)
|
|
{
|
|
property = group.PropertyCollection[i];
|
|
if (property?.Id is null)
|
|
continue;
|
|
filteredSourceDirectoryFile = group.FilteredSourceDirectoryFiles[i];
|
|
valueCollection.Add(new(property.Id.Value, property.Indices));
|
|
if (!mapLogic.IndicesFromNew.ContainsKey(property.Id.Value))
|
|
stay += 1;
|
|
else
|
|
fileMoveCollection.Add(filteredSourceDirectoryFile);
|
|
}
|
|
}
|
|
collection = propertyLogic.GetPropertyIds(directoryInfoCollection, saveToCollection);
|
|
_Logger?.LogInformation($"{stay} file(s) are staying and {fileMoveCollection.Count} file(s) will be moved");
|
|
for (int x = 0; x < int.MaxValue; x++)
|
|
{
|
|
_Logger?.LogInformation($"Press \"S\" key to {nameof(CreateWindowsShortcuts)}");
|
|
_Logger?.LogInformation("Press \"End\" key when ready to skip or close console if compare not needed");
|
|
consoleKey = Console.ReadKey().Key;
|
|
if (consoleKey is ConsoleKey.M or ConsoleKey.End)
|
|
break;
|
|
}
|
|
_Logger?.LogInformation(". . .");
|
|
if (consoleKey.HasValue && consoleKey.Value == ConsoleKey.S)
|
|
CreateWindowsShortcuts(collection, keepAll);
|
|
}
|
|
|
|
private void CreateWindowsShortcuts((long Ticks, string FilteredSourceDirectoryFile, string PropertyDirectory, int PropertyId)[] collection, bool keepAll)
|
|
{
|
|
int z = 0;
|
|
string fileName;
|
|
WindowsShortcut windowsShortcut;
|
|
foreach ((long ticks, string filteredSourceDirectoryFile, string propertyDirectory, int propertyId) in collection)
|
|
{
|
|
z += 1;
|
|
if (z % 1000 == 0)
|
|
_Log.Debug($"{z}) Loop {propertyDirectory}");
|
|
if (!keepAll)
|
|
{
|
|
fileName = Path.Combine(propertyDirectory, $"{propertyId}.lnk");
|
|
if (File.Exists(fileName))
|
|
continue;
|
|
}
|
|
else
|
|
{
|
|
fileName = string.Empty;
|
|
for (short c = 65; c < short.MaxValue; c++)
|
|
{
|
|
if (c > 95)
|
|
break;
|
|
fileName = Path.Combine(propertyDirectory, $"{(char)c}", $"{propertyId}.lnk");
|
|
if (File.Exists(fileName))
|
|
continue;
|
|
}
|
|
}
|
|
if (string.IsNullOrEmpty(fileName))
|
|
continue;
|
|
windowsShortcut = new() { Path = filteredSourceDirectoryFile };
|
|
windowsShortcut.Save(fileName);
|
|
windowsShortcut.Dispose();
|
|
}
|
|
}
|
|
|
|
private void SaveDiffFilesOrSaveLogAndMoveFiles(Property.Models.Configuration configuration)
|
|
{
|
|
if (_Configuration?.PropertyConfiguration is null)
|
|
throw new NullReferenceException(nameof(_Configuration.PropertyConfiguration));
|
|
string aPropertySingletonDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(configuration, nameof(A_Property), "{}");
|
|
_Logger?.LogInformation(aPropertySingletonDirectory);
|
|
_Logger?.LogInformation("to");
|
|
_Logger?.LogInformation(_Configuration.DiffPropertyDirectory);
|
|
for (int y = 0; y < int.MaxValue; y++)
|
|
{
|
|
_Logger?.LogInformation("Press \"Y\" key to continue or close console if compare not needed");
|
|
if (Console.ReadKey().Key == ConsoleKey.Y)
|
|
break;
|
|
}
|
|
_Logger?.LogInformation(". . .");
|
|
int loadLessThan = 7;
|
|
string diffRootDirectory;
|
|
ConsoleKey? consoleKey = null;
|
|
List<PropertyCompare.Models.PropertyCompare>? duplicates = null;
|
|
PropertyCompare.Models.PropertyCompare[] diffPropertyCompareCollection;
|
|
if (string.IsNullOrEmpty(_Configuration.DiffPropertyDirectory))
|
|
diffRootDirectory = string.Empty;
|
|
else
|
|
{
|
|
if (!_Configuration.DiffPropertyDirectory.EndsWith("{}"))
|
|
throw new Exception("Invalid directory should end with {}!");
|
|
diffRootDirectory = Shared.Models.Stateless.Methods.IProperty.GetDiffRootDirectory(_Configuration.DiffPropertyDirectory);
|
|
}
|
|
PropertyCompare.Models.PropertyCompareLogic propertyCompareLogic = new(_AppSettings.MaxDegreeOfParallelism, _Configuration.PropertyConfiguration, _SpellingFindReplace, diffRootDirectory);
|
|
if (string.IsNullOrEmpty(_Configuration.DiffPropertyDirectory) || !Directory.Exists(_Configuration.DiffPropertyDirectory))
|
|
diffPropertyCompareCollection = Array.Empty<PropertyCompare.Models.PropertyCompare>();
|
|
else
|
|
{
|
|
diffPropertyCompareCollection = propertyCompareLogic.Get(_Configuration.DiffPropertyDirectory, loadLessThan, duplicates, deleteExtension: false);
|
|
if (!diffPropertyCompareCollection.Any())
|
|
throw new Exception("Invalid directory!");
|
|
}
|
|
string aPropertyCollectionDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(configuration, nameof(A_Property), "[{}]");
|
|
PropertyCompare.Models.PropertyCompare[] propertyCompareCollection = propertyCompareLogic.Get(aPropertySingletonDirectory, loadLessThan, duplicates, deleteExtension: false);
|
|
{
|
|
long ticks = DateTime.Now.Ticks;
|
|
string[] lines = (from l in propertyCompareCollection select l.GetSelect()).ToArray();
|
|
File.WriteAllLines(Path.Join(aPropertyCollectionDirectory, $". . . Ids - {ticks}.txt"), lines);
|
|
string json = JsonSerializer.Serialize(propertyCompareCollection, new JsonSerializerOptions { WriteIndented = true });
|
|
File.WriteAllText(Path.Join(aPropertyCollectionDirectory, $". . . Ids - {ticks}.nosj"), json);
|
|
}
|
|
for (int x = 0; x < int.MaxValue; x++)
|
|
{
|
|
_Logger?.LogInformation($"Press \"D\" key to {nameof(PropertyCompare.Models.PropertyCompareLogic.SaveDiffFiles)}");
|
|
_Logger?.LogInformation($"Press \"M\" key to {nameof(PropertyCompare.Models.PropertyCompareLogic.SaveLogAndMoveFiles)}");
|
|
_Logger?.LogInformation("Press \"End\" key when ready to skip");
|
|
consoleKey = Console.ReadKey().Key;
|
|
if (consoleKey is ConsoleKey.D or ConsoleKey.M or ConsoleKey.End)
|
|
break;
|
|
}
|
|
_Logger?.LogInformation(". . .");
|
|
if (consoleKey.HasValue && consoleKey.Value == ConsoleKey.D)
|
|
propertyCompareLogic.SaveDiffFiles(aPropertyCollectionDirectory, loadLessThan, propertyCompareCollection, diffPropertyCompareCollection);
|
|
else if (consoleKey.HasValue && consoleKey.Value == ConsoleKey.M)
|
|
{
|
|
for (int x = 0; x < int.MaxValue; x++)
|
|
{
|
|
_Logger?.LogInformation($"Press \"0 - {loadLessThan}\" key when ready to continue");
|
|
_Logger?.LogInformation("Press \"End\" key when ready to skip");
|
|
consoleKey = Console.ReadKey().Key;
|
|
if (consoleKey.Value is ConsoleKey.D0 or ConsoleKey.D1 or ConsoleKey.D2 or ConsoleKey.D3 or ConsoleKey.D4 or ConsoleKey.D5 or ConsoleKey.D6 or ConsoleKey.End)
|
|
break;
|
|
}
|
|
_Logger?.LogInformation(". . .");
|
|
int i = int.Parse(consoleKey.Value.ToString()[1..]);
|
|
propertyCompareLogic.SaveLogAndMoveFiles(aPropertyCollectionDirectory, loadLessThan, propertyCompareCollection, diffPropertyCompareCollection, i);
|
|
}
|
|
}
|
|
|
|
private bool PossiblyRename(List<string> topDirectories, List<(int g, string sourceDirectory, string[] sourceDirectoryFiles)> groupCollection)
|
|
{
|
|
bool result = false;
|
|
string replaceFile;
|
|
string replaceDirectory;
|
|
int remainingDirectories = 0;
|
|
IEnumerable<(string Find, string Replace)>? found;
|
|
foreach ((int g, string sourceDirectory, string[] sourceDirectoryFiles) in groupCollection)
|
|
{
|
|
if (!topDirectories.Any())
|
|
continue;
|
|
found = from l in _RenameFindReplace where sourceDirectory == l.Find select l;
|
|
if (!found.Any())
|
|
continue;
|
|
if (!result)
|
|
result = true;
|
|
replaceDirectory = found.First().Replace;
|
|
if (!Directory.Exists(replaceDirectory))
|
|
Directory.Move(sourceDirectory, replaceDirectory);
|
|
else
|
|
{
|
|
if (Directory.EnumerateDirectories(sourceDirectory).Any())
|
|
remainingDirectories += 1;
|
|
else
|
|
{
|
|
foreach (string sourceDirectoryFile in sourceDirectoryFiles)
|
|
{
|
|
replaceFile = Path.Combine(replaceDirectory, Path.GetFileName(sourceDirectoryFile));
|
|
if (File.Exists(replaceFile))
|
|
{
|
|
if (replaceFile.EndsWith(".jpg", ignoreCase: true, CultureInfo.CurrentCulture))
|
|
replaceFile = Path.Combine(replaceDirectory, Path.ChangeExtension(sourceDirectoryFile, ".jpeg"));
|
|
else if (replaceFile.EndsWith(".jpeg", ignoreCase: true, CultureInfo.CurrentCulture))
|
|
replaceFile = Path.Combine(replaceDirectory, Path.ChangeExtension(sourceDirectoryFile, ".jpg"));
|
|
}
|
|
if (File.Exists(replaceFile))
|
|
continue;
|
|
File.Move(sourceDirectoryFile, replaceFile);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
private bool PossiblyCorrect(List<string> topDirectories, List<(int g, string sourceDirectory, string[] sourceDirectoryFiles)> groupCollection)
|
|
{
|
|
if (_Configuration?.PropertyConfiguration is null)
|
|
throw new NullReferenceException(nameof(_Configuration.PropertyConfiguration));
|
|
bool result = false;
|
|
string corrected;
|
|
string correctedMoveTo;
|
|
string? correctedDirectory;
|
|
string filteredSourceDirectoryFile;
|
|
string[] filteredSourceDirectoryFiles;
|
|
(string Find, string Replace) findReplace;
|
|
IEnumerable<(string Find, string Replace)>? found;
|
|
foreach ((int g, string sourceDirectory, string[] sourceDirectoryFiles) in groupCollection)
|
|
{
|
|
if (!topDirectories.Any())
|
|
continue;
|
|
filteredSourceDirectoryFiles = (from l in sourceDirectoryFiles where !_Configuration.PropertyConfiguration.IgnoreExtensions.Contains(Path.GetExtension(l)) select l).ToArray();
|
|
if (!filteredSourceDirectoryFiles.Any())
|
|
continue;
|
|
for (int i = 0; i < filteredSourceDirectoryFiles.Length; i++)
|
|
{
|
|
found = null;
|
|
for (int z = 0; z < int.MaxValue; z++)
|
|
{
|
|
filteredSourceDirectoryFile = filteredSourceDirectoryFiles[i];
|
|
found = from l in _SpellingFindReplace where filteredSourceDirectoryFile.Contains(l.Find) select l;
|
|
if (!found.Any())
|
|
break;
|
|
findReplace = found.First();
|
|
corrected = filteredSourceDirectoryFile.Replace(findReplace.Find, findReplace.Replace);
|
|
correctedDirectory = Path.GetDirectoryName(corrected);
|
|
if (string.IsNullOrEmpty(correctedDirectory))
|
|
break;
|
|
correctedMoveTo = Path.Combine(correctedDirectory, Path.GetFileName(corrected));
|
|
if (File.Exists(correctedMoveTo))
|
|
break;
|
|
if (!Directory.Exists(correctedDirectory))
|
|
_ = Directory.CreateDirectory(correctedDirectory);
|
|
if (!result)
|
|
result = true;
|
|
File.Move(filteredSourceDirectoryFile, correctedMoveTo);
|
|
filteredSourceDirectoryFiles[i] = corrected;
|
|
}
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
private bool PossiblyRenameB(List<string> topDirectories, List<(int g, string sourceDirectory, string[] sourceDirectoryFiles)> groupCollection)
|
|
{
|
|
bool result = false;
|
|
string replaceFile;
|
|
string replaceDirectory;
|
|
IEnumerable<(string Find, string Replace)>? found;
|
|
foreach ((int g, string sourceDirectory, string[] sourceDirectoryFiles) in groupCollection)
|
|
{
|
|
if (!topDirectories.Any())
|
|
continue;
|
|
found = from l in _RenameBFindReplace where sourceDirectory == l.Find select l;
|
|
if (!found.Any())
|
|
continue;
|
|
if (!result)
|
|
result = true;
|
|
replaceDirectory = found.First().Replace;
|
|
if (!Directory.Exists(replaceDirectory))
|
|
_ = Directory.CreateDirectory(replaceDirectory);
|
|
foreach (string sourceDirectoryFile in sourceDirectoryFiles)
|
|
{
|
|
replaceFile = Path.Combine(replaceDirectory, Path.GetFileName(sourceDirectoryFile));
|
|
if (File.Exists(replaceFile))
|
|
{
|
|
if (replaceFile.EndsWith(".jpg", ignoreCase: true, CultureInfo.CurrentCulture))
|
|
replaceFile = Path.Combine(replaceDirectory, Path.ChangeExtension(sourceDirectoryFile, ".jpeg"));
|
|
else if (replaceFile.EndsWith(".jpeg", ignoreCase: true, CultureInfo.CurrentCulture))
|
|
replaceFile = Path.Combine(replaceDirectory, Path.ChangeExtension(sourceDirectoryFile, ".jpg"));
|
|
}
|
|
if (File.Exists(replaceFile))
|
|
continue;
|
|
File.Move(sourceDirectoryFile, replaceFile);
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
private bool PossiblyRenameC(List<string> topDirectories, List<(int g, string sourceDirectory, string[] sourceDirectoryFiles)> groupCollection)
|
|
{
|
|
bool result = false;
|
|
string replaceFile;
|
|
string replaceDirectory;
|
|
IEnumerable<(string Find, string Replace)>? found;
|
|
foreach ((int g, string sourceDirectory, string[] sourceDirectoryFiles) in groupCollection)
|
|
{
|
|
if (!topDirectories.Any())
|
|
continue;
|
|
found = from l in _RenameCFindReplace where sourceDirectory == l.Find select l;
|
|
if (!found.Any())
|
|
continue;
|
|
if (!result)
|
|
result = true;
|
|
replaceDirectory = found.First().Replace;
|
|
if (!Directory.Exists(replaceDirectory))
|
|
_ = Directory.CreateDirectory(replaceDirectory);
|
|
foreach (string sourceDirectoryFile in sourceDirectoryFiles)
|
|
{
|
|
replaceFile = Path.Combine(replaceDirectory, Path.GetFileName(sourceDirectoryFile));
|
|
if (File.Exists(replaceFile))
|
|
{
|
|
if (replaceFile.EndsWith(".jpg", ignoreCase: true, CultureInfo.CurrentCulture))
|
|
replaceFile = Path.Combine(replaceDirectory, Path.ChangeExtension(sourceDirectoryFile, ".jpeg"));
|
|
else if (replaceFile.EndsWith(".jpeg", ignoreCase: true, CultureInfo.CurrentCulture))
|
|
replaceFile = Path.Combine(replaceDirectory, Path.ChangeExtension(sourceDirectoryFile, ".jpg"));
|
|
}
|
|
if (File.Exists(replaceFile))
|
|
continue;
|
|
File.Move(sourceDirectoryFile, replaceFile);
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
private List<string> GetMissingVerifyToSeasonCollection(List<string> _, List<(int g, string sourceDirectory, string[] sourceDirectoryFiles)> groupCollection)
|
|
{
|
|
if (_Configuration?.PropertyConfiguration is null)
|
|
throw new NullReferenceException(nameof(_Configuration.PropertyConfiguration));
|
|
List<string> results = new();
|
|
string check;
|
|
foreach ((int _, string sourceDirectory, string[] _) in groupCollection)
|
|
{
|
|
if (sourceDirectory == _Configuration.PropertyConfiguration.RootDirectory)
|
|
continue;
|
|
check = sourceDirectory[(_Configuration.PropertyConfiguration.RootDirectory.Length + 1)..];
|
|
if (check[0] is '=' || check.StartsWith("zzz ="))
|
|
{
|
|
if (!_Configuration.PropertyConfiguration.VerifyToSeason.Contains(check))
|
|
results.Add(check);
|
|
}
|
|
}
|
|
return results;
|
|
}
|
|
|
|
} |