Mostly Sorting
Video Merge as 4, 5, and 6
This commit is contained in:
@ -242,6 +242,53 @@ public class Compare
|
||||
_ = 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;
|
||||
@ -376,12 +423,6 @@ public class Compare
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void Verify(Models.Configuration configuration)
|
||||
{
|
||||
if (configuration.Spelling is null || !configuration.Spelling.Any())
|
||||
throw new NullReferenceException(nameof(configuration.Spelling));
|
||||
}
|
||||
|
||||
private long LogDelta(long ticks, string? methodName)
|
||||
{
|
||||
long result;
|
||||
@ -391,121 +432,6 @@ public class Compare
|
||||
return result;
|
||||
}
|
||||
|
||||
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 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 void ChangeExtensionFromDeleteToJson(string aPropertySingletonDirectory)
|
||||
{
|
||||
string searchPattern = "*.delete";
|
||||
@ -524,227 +450,6 @@ public class Compare
|
||||
}
|
||||
}
|
||||
|
||||
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 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 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 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;
|
||||
}
|
||||
|
||||
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 ThirdPassToMove(Property.Models.Configuration configuration, Map.Models.MapLogic mapLogic, A_Property propertyLogic, Shared.Models.Container[] containers, string aPropertyContentCollectionDirectory)
|
||||
{
|
||||
if (_Configuration?.PropertyConfiguration is null)
|
||||
@ -865,4 +570,299 @@ public class Compare
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user