CSharpMethodLine
This commit is contained in:
parent
3c86acdbda
commit
a9d0f67227
File diff suppressed because it is too large
Load Diff
@ -1,4 +1,4 @@
|
|||||||
using Humanizer;
|
using Humanizer;
|
||||||
using ShellProgressBar;
|
using ShellProgressBar;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
@ -13,9 +13,207 @@ namespace View_by_Distance.Map.Models;
|
|||||||
public partial class MapLogic : Shared.Models.Methods.IMapLogic
|
public partial class MapLogic : Shared.Models.Methods.IMapLogic
|
||||||
{
|
{
|
||||||
|
|
||||||
|
private bool IsUsed(bool ignoreXMatches, int id, ReadOnlyDictionary<int, ReadOnlyCollection<PersonContainer>>? wholePercentagesToPersonContainers, int wholePercentages)
|
||||||
|
{
|
||||||
|
bool result;
|
||||||
|
List<int>? wholePercentagesCollection;
|
||||||
|
ReadOnlyCollection<PersonContainer>? personContainers;
|
||||||
|
result = _SkipCollection.TryGetValue(id, out wholePercentagesCollection) && wholePercentagesCollection.Contains(wholePercentages);
|
||||||
|
if (!result && wholePercentagesToPersonContainers is not null)
|
||||||
|
if (wholePercentagesToPersonContainers.TryGetValue(wholePercentages, out personContainers))
|
||||||
|
if (!ignoreXMatches || !personContainers.Any(l => IPerson.IsDefaultName(l)))
|
||||||
|
result = true;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsUsed(bool ignoreXMatches, int id, ReadOnlyDictionary<int, ReadOnlyCollection<PersonContainer>>? wholePercentagesToPersonContainers, MappingFromLocation mappingFromLocation) =>
|
||||||
|
IsUsed(ignoreXMatches, id, wholePercentagesToPersonContainers, mappingFromLocation.WholePercentages);
|
||||||
|
|
||||||
[GeneratedRegex("[\\\\,\\/,\\:,\\*,\\?,\\\",\\<,\\>,\\|]")]
|
[GeneratedRegex("[\\\\,\\/,\\:,\\*,\\?,\\\",\\<,\\>,\\|]")]
|
||||||
private static partial Regex FileSystemSafe();
|
private static partial Regex FileSystemSafe();
|
||||||
|
|
||||||
|
public void SaveContainers(bool saveIndividually, int? updated, List<SaveContainer> saveContainers)
|
||||||
|
{
|
||||||
|
if (_Configuration is null)
|
||||||
|
throw new NullReferenceException(nameof(_Configuration));
|
||||||
|
string fileName;
|
||||||
|
string checkFile;
|
||||||
|
string sourceFile;
|
||||||
|
List<string> distinct = new();
|
||||||
|
WindowsShortcut windowsShortcut;
|
||||||
|
string[] directories = (from l in saveContainers select l.Directory).Distinct().ToArray();
|
||||||
|
int totalSeconds = (int)Math.Floor(new TimeSpan(DateTime.Now.Ticks - _Ticks).TotalSeconds);
|
||||||
|
string message;
|
||||||
|
if (updated is null)
|
||||||
|
message = $") {saveContainers.Count:000} save(s) - {totalSeconds} total second(s)";
|
||||||
|
else
|
||||||
|
message = $") {saveContainers.Count:000} save(s) - {updated} Updated - {totalSeconds} total second(s)";
|
||||||
|
ProgressBarOptions options = new() { ProgressCharacter = '─', ProgressBarOnBottom = true, DisableBottomPercentage = true };
|
||||||
|
foreach (string directory in directories)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(directory))
|
||||||
|
continue;
|
||||||
|
if (!Directory.Exists(directory))
|
||||||
|
_ = Directory.CreateDirectory(directory);
|
||||||
|
}
|
||||||
|
using ProgressBar progressBar = new(saveContainers.Count, message, options);
|
||||||
|
foreach (SaveContainer saveContainer in saveContainers)
|
||||||
|
{
|
||||||
|
progressBar.Tick();
|
||||||
|
if (string.IsNullOrEmpty(saveContainer.Directory) || string.IsNullOrEmpty(saveContainer.CheckFile) || saveContainer.FaceFileHolder is null)
|
||||||
|
continue;
|
||||||
|
if (saveContainer.FacePartsFileHolder is null && saveContainer.HiddenFaceFileHolder is null && saveContainer.ResizedFileHolder is null)
|
||||||
|
{
|
||||||
|
checkFile = saveContainer.CheckFile;
|
||||||
|
sourceFile = saveContainer.FaceFileHolder.FullName;
|
||||||
|
}
|
||||||
|
else if (!saveContainer.FaceFileHolder.Exists && saveContainer.ResizedFileHolder is not null && saveContainer.ResizedFileHolder.Exists)
|
||||||
|
{
|
||||||
|
checkFile = saveContainer.CheckFile;
|
||||||
|
sourceFile = saveContainer.ResizedFileHolder.FullName;
|
||||||
|
}
|
||||||
|
else if (saveContainer.FaceFileHolder.Exists)
|
||||||
|
{
|
||||||
|
sourceFile = saveContainer.FaceFileHolder.FullName;
|
||||||
|
checkFile = $"{saveContainer.CheckFile}{_Configuration.FacesFileNameExtension}";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
continue;
|
||||||
|
if (saveIndividually)
|
||||||
|
{
|
||||||
|
fileName = Path.GetFileName(checkFile);
|
||||||
|
if (distinct.Contains(fileName))
|
||||||
|
continue;
|
||||||
|
distinct.Add(fileName);
|
||||||
|
}
|
||||||
|
if (File.Exists(checkFile))
|
||||||
|
continue;
|
||||||
|
File.Copy(sourceFile, checkFile);
|
||||||
|
if (saveIndividually)
|
||||||
|
continue;
|
||||||
|
if (saveContainer.MakeAllHidden)
|
||||||
|
File.SetAttributes(checkFile, FileAttributes.Hidden);
|
||||||
|
if (saveContainer.HiddenFaceFileHolder is not null && saveContainer.HiddenFaceFileHolder.Exists)
|
||||||
|
{
|
||||||
|
sourceFile = saveContainer.HiddenFaceFileHolder.FullName;
|
||||||
|
checkFile = $"{saveContainer.CheckFile}{_Configuration.FacesHiddenFileNameExtension}";
|
||||||
|
}
|
||||||
|
else if (saveContainer.FacePartsFileHolder is not null && saveContainer.FacePartsFileHolder.Exists)
|
||||||
|
{
|
||||||
|
sourceFile = saveContainer.FacePartsFileHolder.FullName;
|
||||||
|
checkFile = $"{saveContainer.CheckFile}{_Configuration.FacePartsFileNameExtension}";
|
||||||
|
}
|
||||||
|
if (File.Exists(checkFile))
|
||||||
|
continue;
|
||||||
|
File.Copy(sourceFile, checkFile);
|
||||||
|
if (saveContainer.MakeAllHidden)
|
||||||
|
File.SetAttributes(checkFile, FileAttributes.Hidden);
|
||||||
|
}
|
||||||
|
if (updated is null)
|
||||||
|
foreach (SaveContainer saveContainer in saveContainers)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(saveContainer.Directory) || string.IsNullOrEmpty(saveContainer.CheckFile) || saveContainer.ResizedFileHolder is null || !saveContainer.ResizedFileHolder.Exists)
|
||||||
|
continue;
|
||||||
|
checkFile = saveContainer.CheckFile;
|
||||||
|
sourceFile = saveContainer.ResizedFileHolder.FullName;
|
||||||
|
if (File.Exists(checkFile))
|
||||||
|
continue;
|
||||||
|
File.Copy(sourceFile, checkFile);
|
||||||
|
if (saveContainer.MakeAllHidden)
|
||||||
|
File.SetAttributes(checkFile, FileAttributes.Hidden);
|
||||||
|
}
|
||||||
|
foreach (SaveContainer saveContainer in saveContainers)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(saveContainer.Directory) || string.IsNullOrEmpty(saveContainer.ShortcutFile) || saveContainer.ResizedFileHolder is null || !saveContainer.ResizedFileHolder.Exists)
|
||||||
|
continue;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string description = saveContainer.FaceFileHolder is not null ? saveContainer.FaceFileHolder.Name : string.Empty;
|
||||||
|
windowsShortcut = new() { Path = saveContainer.ResizedFileHolder.FullName, Description = description };
|
||||||
|
windowsShortcut.Save(saveContainer.ShortcutFile);
|
||||||
|
windowsShortcut.Dispose();
|
||||||
|
if (saveContainer.MakeAllHidden)
|
||||||
|
File.SetAttributes(saveContainer.ShortcutFile, FileAttributes.Hidden);
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{ }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<SaveShortcutsForOutputResolutions> GetCollectionForSaveShortcutsForOutputResolutionsPreMapLogic(string eDistanceContentDirectory, ReadOnlyDictionary<long, List<int>> personKeyToIds, ReadOnlyCollection<Mapping> mappingCollection)
|
||||||
|
{
|
||||||
|
List<SaveShortcutsForOutputResolutions> results = new();
|
||||||
|
if (_Configuration is null)
|
||||||
|
throw new NullReferenceException(nameof(_Configuration));
|
||||||
|
int season;
|
||||||
|
long personKey;
|
||||||
|
string fileName;
|
||||||
|
string directory;
|
||||||
|
string weekOfYear;
|
||||||
|
DateTime dateTime;
|
||||||
|
string description;
|
||||||
|
string directoryName;
|
||||||
|
List<long>? personKeys;
|
||||||
|
string personKeyFormatted;
|
||||||
|
Calendar calendar = new CultureInfo("en-US").Calendar;
|
||||||
|
ReadOnlyDictionary<int, List<long>> idToPersonKeys = Stateless.Methods.IMapLogic.GetIdToPersonKeys(personKeyToIds);
|
||||||
|
foreach (Mapping mapping in mappingCollection)
|
||||||
|
{
|
||||||
|
dateTime = mapping.MappingFromItem.GetDateTimeOriginalThenMinimumDateTime();
|
||||||
|
description = mapping.MappingFromLocation is null ? mapping.MappingFromItem.Id.ToString() : mapping.MappingFromLocation.DeterministicHashCodeKey;
|
||||||
|
(season, _) = IProperty.GetSeason(dateTime.DayOfYear);
|
||||||
|
weekOfYear = calendar.GetWeekOfYear(dateTime, CalendarWeekRule.FirstDay, DayOfWeek.Sunday).ToString("00");
|
||||||
|
directory = Path.Combine($"{eDistanceContentDirectory}---", "Date Shortcuts", $"{dateTime.Year}.{season}-MM{dateTime.Month:00}-WW{weekOfYear}");
|
||||||
|
fileName = Path.Combine(directory, $"{mapping.MappingFromItem.ImageFileHolder.Name}.lnk");
|
||||||
|
results.Add(new(mapping.MappingFromItem.ImageFileHolder.FullName, directory, dateTime, fileName, description, MakeAllHidden: false));
|
||||||
|
if (mapping.MappingFromItem.ImageFileHolder.DirectoryName is null)
|
||||||
|
continue;
|
||||||
|
directoryName = Path.GetFileName(mapping.MappingFromItem.ImageFileHolder.DirectoryName);
|
||||||
|
if (!string.IsNullOrEmpty(mapping.MappingFromItem.Model) && !string.IsNullOrEmpty(mapping.MappingFromItem.Model.Trim()))
|
||||||
|
{
|
||||||
|
// Remove-Item -LiteralPath "\\?\D:\Tmp\a\EX-Z70 "
|
||||||
|
directory = Path.Combine($"{eDistanceContentDirectory}---", "Model Shortcuts", FileSystemSafe().Replace(mapping.MappingFromItem.Model.Trim(), "_"), directoryName);
|
||||||
|
fileName = Path.Combine(directory, $"{mapping.MappingFromItem.ImageFileHolder.Name}.lnk");
|
||||||
|
results.Add(new(mapping.MappingFromItem.ImageFileHolder.FullName, directory, dateTime, fileName, description, MakeAllHidden: false));
|
||||||
|
}
|
||||||
|
if (mapping.MappingFromPerson is null)
|
||||||
|
continue;
|
||||||
|
if (!idToPersonKeys.TryGetValue(mapping.MappingFromItem.Id, out personKeys))
|
||||||
|
continue;
|
||||||
|
personKey = mapping.MappingFromPerson.PersonBirthday.Value.Ticks;
|
||||||
|
if (!personKeys.Contains(mapping.MappingFromPerson.PersonBirthday.Value.Ticks))
|
||||||
|
continue;
|
||||||
|
personKeyFormatted = IPersonBirthday.GetFormatted(_Configuration.PersonBirthdayFormat, mapping.MappingFromPerson.PersonBirthday);
|
||||||
|
directory = Path.Combine($"{eDistanceContentDirectory}---", "Person Key Shortcuts", personKeyFormatted, directoryName);
|
||||||
|
fileName = Path.Combine(directory, $"{mapping.MappingFromItem.ImageFileHolder.Name}.lnk");
|
||||||
|
results.Add(new(mapping.MappingFromItem.ImageFileHolder.FullName, directory, mapping.MappingFromItem.GetDateTimeOriginalThenMinimumDateTime(), fileName, description, MakeAllHidden: false));
|
||||||
|
if (IPerson.IsDefaultName(mapping.MappingFromPerson))
|
||||||
|
continue;
|
||||||
|
directory = Path.Combine($"{eDistanceContentDirectory}---", "Name Shortcuts", mapping.MappingFromPerson.DisplayDirectoryName, directoryName);
|
||||||
|
fileName = Path.Combine(directory, $"{mapping.MappingFromItem.ImageFileHolder.Name}.lnk");
|
||||||
|
results.Add(new(mapping.MappingFromItem.ImageFileHolder.FullName, directory, mapping.MappingFromItem.GetDateTimeOriginalThenMinimumDateTime(), fileName, description, MakeAllHidden: false));
|
||||||
|
}
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LookForAbandoned(Property.Models.Configuration propertyConfiguration, List<int> distinctFilteredIds)
|
||||||
|
{
|
||||||
|
List<string> renameCollection = new();
|
||||||
|
foreach (KeyValuePair<int, List<LocationContainer<MetadataExtractor.Directory>>> keyValuePair in _IdToLocationContainers)
|
||||||
|
{
|
||||||
|
if (distinctFilteredIds.Contains(keyValuePair.Key))
|
||||||
|
continue;
|
||||||
|
foreach (LocationContainer<MetadataExtractor.Directory> locationContainer in keyValuePair.Value)
|
||||||
|
{
|
||||||
|
if (locationContainer.File.Contains('!'))
|
||||||
|
continue;
|
||||||
|
renameCollection.Add(locationContainer.File);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (renameCollection.Count > 0)
|
||||||
|
IDirectory.MoveFiles(renameCollection, propertyConfiguration.ResultContent, "(abd)");
|
||||||
|
}
|
||||||
|
|
||||||
private readonly long _Ticks;
|
private readonly long _Ticks;
|
||||||
private readonly Serilog.ILogger? _Log;
|
private readonly Serilog.ILogger? _Log;
|
||||||
private readonly Configuration? _Configuration;
|
private readonly Configuration? _Configuration;
|
||||||
@ -236,114 +434,6 @@ public partial class MapLogic : Shared.Models.Methods.IMapLogic
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SaveContainers(bool saveIndividually, int? updated, List<SaveContainer> saveContainers)
|
|
||||||
{
|
|
||||||
if (_Configuration is null)
|
|
||||||
throw new NullReferenceException(nameof(_Configuration));
|
|
||||||
string fileName;
|
|
||||||
string checkFile;
|
|
||||||
string sourceFile;
|
|
||||||
List<string> distinct = new();
|
|
||||||
WindowsShortcut windowsShortcut;
|
|
||||||
string[] directories = (from l in saveContainers select l.Directory).Distinct().ToArray();
|
|
||||||
int totalSeconds = (int)Math.Floor(new TimeSpan(DateTime.Now.Ticks - _Ticks).TotalSeconds);
|
|
||||||
string message;
|
|
||||||
if (updated is null)
|
|
||||||
message = $") {saveContainers.Count:000} save(s) - {totalSeconds} total second(s)";
|
|
||||||
else
|
|
||||||
message = $") {saveContainers.Count:000} save(s) - {updated} Updated - {totalSeconds} total second(s)";
|
|
||||||
ProgressBarOptions options = new() { ProgressCharacter = '─', ProgressBarOnBottom = true, DisableBottomPercentage = true };
|
|
||||||
foreach (string directory in directories)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(directory))
|
|
||||||
continue;
|
|
||||||
if (!Directory.Exists(directory))
|
|
||||||
_ = Directory.CreateDirectory(directory);
|
|
||||||
}
|
|
||||||
using ProgressBar progressBar = new(saveContainers.Count, message, options);
|
|
||||||
foreach (SaveContainer saveContainer in saveContainers)
|
|
||||||
{
|
|
||||||
progressBar.Tick();
|
|
||||||
if (string.IsNullOrEmpty(saveContainer.Directory) || string.IsNullOrEmpty(saveContainer.CheckFile) || saveContainer.FaceFileHolder is null)
|
|
||||||
continue;
|
|
||||||
if (saveContainer.FacePartsFileHolder is null && saveContainer.HiddenFaceFileHolder is null && saveContainer.ResizedFileHolder is null)
|
|
||||||
{
|
|
||||||
checkFile = saveContainer.CheckFile;
|
|
||||||
sourceFile = saveContainer.FaceFileHolder.FullName;
|
|
||||||
}
|
|
||||||
else if (!saveContainer.FaceFileHolder.Exists && saveContainer.ResizedFileHolder is not null && saveContainer.ResizedFileHolder.Exists)
|
|
||||||
{
|
|
||||||
checkFile = saveContainer.CheckFile;
|
|
||||||
sourceFile = saveContainer.ResizedFileHolder.FullName;
|
|
||||||
}
|
|
||||||
else if (saveContainer.FaceFileHolder.Exists)
|
|
||||||
{
|
|
||||||
sourceFile = saveContainer.FaceFileHolder.FullName;
|
|
||||||
checkFile = $"{saveContainer.CheckFile}{_Configuration.FacesFileNameExtension}";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
continue;
|
|
||||||
if (saveIndividually)
|
|
||||||
{
|
|
||||||
fileName = Path.GetFileName(checkFile);
|
|
||||||
if (distinct.Contains(fileName))
|
|
||||||
continue;
|
|
||||||
distinct.Add(fileName);
|
|
||||||
}
|
|
||||||
if (File.Exists(checkFile))
|
|
||||||
continue;
|
|
||||||
File.Copy(sourceFile, checkFile);
|
|
||||||
if (saveIndividually)
|
|
||||||
continue;
|
|
||||||
if (saveContainer.MakeAllHidden)
|
|
||||||
File.SetAttributes(checkFile, FileAttributes.Hidden);
|
|
||||||
if (saveContainer.HiddenFaceFileHolder is not null && saveContainer.HiddenFaceFileHolder.Exists)
|
|
||||||
{
|
|
||||||
sourceFile = saveContainer.HiddenFaceFileHolder.FullName;
|
|
||||||
checkFile = $"{saveContainer.CheckFile}{_Configuration.FacesHiddenFileNameExtension}";
|
|
||||||
}
|
|
||||||
else if (saveContainer.FacePartsFileHolder is not null && saveContainer.FacePartsFileHolder.Exists)
|
|
||||||
{
|
|
||||||
sourceFile = saveContainer.FacePartsFileHolder.FullName;
|
|
||||||
checkFile = $"{saveContainer.CheckFile}{_Configuration.FacePartsFileNameExtension}";
|
|
||||||
}
|
|
||||||
if (File.Exists(checkFile))
|
|
||||||
continue;
|
|
||||||
File.Copy(sourceFile, checkFile);
|
|
||||||
if (saveContainer.MakeAllHidden)
|
|
||||||
File.SetAttributes(checkFile, FileAttributes.Hidden);
|
|
||||||
}
|
|
||||||
if (updated is null)
|
|
||||||
foreach (SaveContainer saveContainer in saveContainers)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(saveContainer.Directory) || string.IsNullOrEmpty(saveContainer.CheckFile) || saveContainer.ResizedFileHolder is null || !saveContainer.ResizedFileHolder.Exists)
|
|
||||||
continue;
|
|
||||||
checkFile = saveContainer.CheckFile;
|
|
||||||
sourceFile = saveContainer.ResizedFileHolder.FullName;
|
|
||||||
if (File.Exists(checkFile))
|
|
||||||
continue;
|
|
||||||
File.Copy(sourceFile, checkFile);
|
|
||||||
if (saveContainer.MakeAllHidden)
|
|
||||||
File.SetAttributes(checkFile, FileAttributes.Hidden);
|
|
||||||
}
|
|
||||||
foreach (SaveContainer saveContainer in saveContainers)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(saveContainer.Directory) || string.IsNullOrEmpty(saveContainer.ShortcutFile) || saveContainer.ResizedFileHolder is null || !saveContainer.ResizedFileHolder.Exists)
|
|
||||||
continue;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
string description = saveContainer.FaceFileHolder is not null ? saveContainer.FaceFileHolder.Name : string.Empty;
|
|
||||||
windowsShortcut = new() { Path = saveContainer.ResizedFileHolder.FullName, Description = description };
|
|
||||||
windowsShortcut.Save(saveContainer.ShortcutFile);
|
|
||||||
windowsShortcut.Dispose();
|
|
||||||
if (saveContainer.MakeAllHidden)
|
|
||||||
File.SetAttributes(saveContainer.ShortcutFile, FileAttributes.Hidden);
|
|
||||||
}
|
|
||||||
catch (Exception)
|
|
||||||
{ }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private SaveContainer? GetMatchSaveContainer(string dFacesContentDirectory, string d2FacePartsContentDirectory, string directory, Mapping mapping)
|
private SaveContainer? GetMatchSaveContainer(string dFacesContentDirectory, string d2FacePartsContentDirectory, string directory, Mapping mapping)
|
||||||
{
|
{
|
||||||
if (_Configuration is null)
|
if (_Configuration is null)
|
||||||
@ -900,62 +990,6 @@ public partial class MapLogic : Shared.Models.Methods.IMapLogic
|
|||||||
SaveContainers(saveIndividually, null, saveContainers);
|
SaveContainers(saveIndividually, null, saveContainers);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<SaveShortcutsForOutputResolutions> GetCollectionForSaveShortcutsForOutputResolutionsPreMapLogic(string eDistanceContentDirectory, ReadOnlyDictionary<long, List<int>> personKeyToIds, ReadOnlyCollection<Mapping> mappingCollection)
|
|
||||||
{
|
|
||||||
List<SaveShortcutsForOutputResolutions> results = new();
|
|
||||||
if (_Configuration is null)
|
|
||||||
throw new NullReferenceException(nameof(_Configuration));
|
|
||||||
int season;
|
|
||||||
long personKey;
|
|
||||||
string fileName;
|
|
||||||
string directory;
|
|
||||||
string weekOfYear;
|
|
||||||
DateTime dateTime;
|
|
||||||
string description;
|
|
||||||
string directoryName;
|
|
||||||
List<long>? personKeys;
|
|
||||||
string personKeyFormatted;
|
|
||||||
Calendar calendar = new CultureInfo("en-US").Calendar;
|
|
||||||
ReadOnlyDictionary<int, List<long>> idToPersonKeys = Stateless.Methods.IMapLogic.GetIdToPersonKeys(personKeyToIds);
|
|
||||||
foreach (Mapping mapping in mappingCollection)
|
|
||||||
{
|
|
||||||
dateTime = mapping.MappingFromItem.GetDateTimeOriginalThenMinimumDateTime();
|
|
||||||
description = mapping.MappingFromLocation is null ? mapping.MappingFromItem.Id.ToString() : mapping.MappingFromLocation.DeterministicHashCodeKey;
|
|
||||||
(season, _) = IProperty.GetSeason(dateTime.DayOfYear);
|
|
||||||
weekOfYear = calendar.GetWeekOfYear(dateTime, CalendarWeekRule.FirstDay, DayOfWeek.Sunday).ToString("00");
|
|
||||||
directory = Path.Combine($"{eDistanceContentDirectory}---", "Date Shortcuts", $"{dateTime.Year}.{season}-MM{dateTime.Month:00}-WW{weekOfYear}");
|
|
||||||
fileName = Path.Combine(directory, $"{mapping.MappingFromItem.ImageFileHolder.Name}.lnk");
|
|
||||||
results.Add(new(mapping.MappingFromItem.ImageFileHolder.FullName, directory, dateTime, fileName, description, MakeAllHidden: false));
|
|
||||||
if (mapping.MappingFromItem.ImageFileHolder.DirectoryName is null)
|
|
||||||
continue;
|
|
||||||
directoryName = Path.GetFileName(mapping.MappingFromItem.ImageFileHolder.DirectoryName);
|
|
||||||
if (!string.IsNullOrEmpty(mapping.MappingFromItem.Model) && !string.IsNullOrEmpty(mapping.MappingFromItem.Model.Trim()))
|
|
||||||
{
|
|
||||||
// Remove-Item -LiteralPath "\\?\D:\Tmp\a\EX-Z70 "
|
|
||||||
directory = Path.Combine($"{eDistanceContentDirectory}---", "Model Shortcuts", FileSystemSafe().Replace(mapping.MappingFromItem.Model.Trim(), "_"), directoryName);
|
|
||||||
fileName = Path.Combine(directory, $"{mapping.MappingFromItem.ImageFileHolder.Name}.lnk");
|
|
||||||
results.Add(new(mapping.MappingFromItem.ImageFileHolder.FullName, directory, dateTime, fileName, description, MakeAllHidden: false));
|
|
||||||
}
|
|
||||||
if (mapping.MappingFromPerson is null)
|
|
||||||
continue;
|
|
||||||
if (!idToPersonKeys.TryGetValue(mapping.MappingFromItem.Id, out personKeys))
|
|
||||||
continue;
|
|
||||||
personKey = mapping.MappingFromPerson.PersonBirthday.Value.Ticks;
|
|
||||||
if (!personKeys.Contains(mapping.MappingFromPerson.PersonBirthday.Value.Ticks))
|
|
||||||
continue;
|
|
||||||
personKeyFormatted = IPersonBirthday.GetFormatted(_Configuration.PersonBirthdayFormat, mapping.MappingFromPerson.PersonBirthday);
|
|
||||||
directory = Path.Combine($"{eDistanceContentDirectory}---", "Person Key Shortcuts", personKeyFormatted, directoryName);
|
|
||||||
fileName = Path.Combine(directory, $"{mapping.MappingFromItem.ImageFileHolder.Name}.lnk");
|
|
||||||
results.Add(new(mapping.MappingFromItem.ImageFileHolder.FullName, directory, mapping.MappingFromItem.GetDateTimeOriginalThenMinimumDateTime(), fileName, description, MakeAllHidden: false));
|
|
||||||
if (IPerson.IsDefaultName(mapping.MappingFromPerson))
|
|
||||||
continue;
|
|
||||||
directory = Path.Combine($"{eDistanceContentDirectory}---", "Name Shortcuts", mapping.MappingFromPerson.DisplayDirectoryName, directoryName);
|
|
||||||
fileName = Path.Combine(directory, $"{mapping.MappingFromItem.ImageFileHolder.Name}.lnk");
|
|
||||||
results.Add(new(mapping.MappingFromItem.ImageFileHolder.FullName, directory, mapping.MappingFromItem.GetDateTimeOriginalThenMinimumDateTime(), fileName, description, MakeAllHidden: false));
|
|
||||||
}
|
|
||||||
return results;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SaveShortcutsForOutputResolutionsPreMapLogic(string eDistanceContentDirectory, ReadOnlyDictionary<long, List<int>> personKeyToIds, ReadOnlyCollection<Mapping> mappingCollection)
|
public void SaveShortcutsForOutputResolutionsPreMapLogic(string eDistanceContentDirectory, ReadOnlyDictionary<long, List<int>> personKeyToIds, ReadOnlyCollection<Mapping> mappingCollection)
|
||||||
{
|
{
|
||||||
string hiddenFile;
|
string hiddenFile;
|
||||||
@ -1138,22 +1172,6 @@ public partial class MapLogic : Shared.Models.Methods.IMapLogic
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool IsUsed(bool ignoreXMatches, int id, ReadOnlyDictionary<int, ReadOnlyCollection<PersonContainer>>? wholePercentagesToPersonContainers, int wholePercentages)
|
|
||||||
{
|
|
||||||
bool result;
|
|
||||||
List<int>? wholePercentagesCollection;
|
|
||||||
ReadOnlyCollection<PersonContainer>? personContainers;
|
|
||||||
result = _SkipCollection.TryGetValue(id, out wholePercentagesCollection) && wholePercentagesCollection.Contains(wholePercentages);
|
|
||||||
if (!result && wholePercentagesToPersonContainers is not null)
|
|
||||||
if (wholePercentagesToPersonContainers.TryGetValue(wholePercentages, out personContainers))
|
|
||||||
if (!ignoreXMatches || !personContainers.Any(l => IPerson.IsDefaultName(l)))
|
|
||||||
result = true;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool IsUsed(bool ignoreXMatches, int id, ReadOnlyDictionary<int, ReadOnlyCollection<PersonContainer>>? wholePercentagesToPersonContainers, MappingFromLocation mappingFromLocation) =>
|
|
||||||
IsUsed(ignoreXMatches, id, wholePercentagesToPersonContainers, mappingFromLocation.WholePercentages);
|
|
||||||
|
|
||||||
public bool InSkipCollection(int id, MappingFromLocation mappingFromLocation) =>
|
public bool InSkipCollection(int id, MappingFromLocation mappingFromLocation) =>
|
||||||
_SkipCollection.TryGetValue(id, out List<int>? wholePercentagesCollection) && wholePercentagesCollection.Contains(mappingFromLocation.WholePercentages);
|
_SkipCollection.TryGetValue(id, out List<int>? wholePercentagesCollection) && wholePercentagesCollection.Contains(mappingFromLocation.WholePercentages);
|
||||||
|
|
||||||
@ -1189,24 +1207,6 @@ public partial class MapLogic : Shared.Models.Methods.IMapLogic
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LookForAbandoned(Property.Models.Configuration propertyConfiguration, List<int> distinctFilteredIds)
|
|
||||||
{
|
|
||||||
List<string> renameCollection = new();
|
|
||||||
foreach (KeyValuePair<int, List<LocationContainer<MetadataExtractor.Directory>>> keyValuePair in _IdToLocationContainers)
|
|
||||||
{
|
|
||||||
if (distinctFilteredIds.Contains(keyValuePair.Key))
|
|
||||||
continue;
|
|
||||||
foreach (LocationContainer<MetadataExtractor.Directory> locationContainer in keyValuePair.Value)
|
|
||||||
{
|
|
||||||
if (locationContainer.File.Contains('!'))
|
|
||||||
continue;
|
|
||||||
renameCollection.Add(locationContainer.File);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (renameCollection.Count > 0)
|
|
||||||
IDirectory.MoveFiles(renameCollection, propertyConfiguration.ResultContent, "(abd)");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void LookForAbandoned(Property.Models.Configuration propertyConfiguration, string bResultsFullGroupDirectory, Container[] containers, string cResultsFullGroupDirectory, string dResultsFullGroupDirectory, string d2ResultsFullGroupDirectory)
|
public void LookForAbandoned(Property.Models.Configuration propertyConfiguration, string bResultsFullGroupDirectory, Container[] containers, string cResultsFullGroupDirectory, string dResultsFullGroupDirectory, string d2ResultsFullGroupDirectory)
|
||||||
{
|
{
|
||||||
string[] directories;
|
string[] directories;
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,4 +1,4 @@
|
|||||||
using ShellProgressBar;
|
using ShellProgressBar;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using View_by_Distance.Property.Models.Stateless;
|
using View_by_Distance.Property.Models.Stateless;
|
||||||
@ -176,6 +176,21 @@ public class A_Property
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetAngleBracketCollection(string aResultsFullGroupDirectory, string sourceDirectory, bool anyNullOrNoIsUniqueFileName = true)
|
||||||
|
{
|
||||||
|
_AngleBracketCollection.Clear();
|
||||||
|
if (!anyNullOrNoIsUniqueFileName)
|
||||||
|
_AngleBracketCollection.AddRange(new[] { Path.Combine(aResultsFullGroupDirectory, "<>") });
|
||||||
|
else
|
||||||
|
_AngleBracketCollection.AddRange(IResult.GetDirectoryInfoCollection(_PropertyConfiguration,
|
||||||
|
sourceDirectory,
|
||||||
|
aResultsFullGroupDirectory,
|
||||||
|
contentDescription: string.Empty,
|
||||||
|
singletonDescription: "Properties for each image",
|
||||||
|
collectionDescription: string.Empty,
|
||||||
|
converted: false));
|
||||||
|
}
|
||||||
|
|
||||||
private void SavePropertyParallelForWork(Shared.Models.Methods.IMetadata<MetadataExtractor.Directory> metadata, string sourceDirectory, List<Tuple<string, DateTime>> sourceDirectoryFileTuples, List<Tuple<string, DateTime>> sourceDirectoryChanges, Item item)
|
private void SavePropertyParallelForWork(Shared.Models.Methods.IMetadata<MetadataExtractor.Directory> metadata, string sourceDirectory, List<Tuple<string, DateTime>> sourceDirectoryFileTuples, List<Tuple<string, DateTime>> sourceDirectoryChanges, Item item)
|
||||||
{
|
{
|
||||||
Shared.Models.Property property;
|
Shared.Models.Property property;
|
||||||
@ -194,6 +209,18 @@ public class A_Property
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void SetAngleBracketCollection(string sourceDirectory, bool anyNullOrNoIsUniqueFileName)
|
||||||
|
{
|
||||||
|
_AngleBracketCollection.Clear();
|
||||||
|
string aResultsFullGroupDirectory = IResult.GetResultsFullGroupDirectory(_PropertyConfiguration,
|
||||||
|
nameof(A_Property),
|
||||||
|
string.Empty,
|
||||||
|
includeResizeGroup: false,
|
||||||
|
includeModel: false,
|
||||||
|
includePredictorModel: false);
|
||||||
|
SetAngleBracketCollection(aResultsFullGroupDirectory, sourceDirectory, anyNullOrNoIsUniqueFileName);
|
||||||
|
}
|
||||||
|
|
||||||
private void SavePropertyParallelWork(int maxDegreeOfParallelism, Shared.Models.Methods.IMetadata<MetadataExtractor.Directory> metadata, List<Exception> exceptions, List<Tuple<string, DateTime>> sourceDirectoryChanges, Container container, List<Item> items, string message)
|
private void SavePropertyParallelWork(int maxDegreeOfParallelism, Shared.Models.Methods.IMetadata<MetadataExtractor.Directory> metadata, List<Exception> exceptions, List<Tuple<string, DateTime>> sourceDirectoryChanges, Container container, List<Item> items, string message)
|
||||||
{
|
{
|
||||||
List<Tuple<string, DateTime>> sourceDirectoryFileTuples = new();
|
List<Tuple<string, DateTime>> sourceDirectoryFileTuples = new();
|
||||||
@ -223,33 +250,6 @@ public class A_Property
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetAngleBracketCollection(string aResultsFullGroupDirectory, string sourceDirectory, bool anyNullOrNoIsUniqueFileName = true)
|
|
||||||
{
|
|
||||||
_AngleBracketCollection.Clear();
|
|
||||||
if (!anyNullOrNoIsUniqueFileName)
|
|
||||||
_AngleBracketCollection.AddRange(new[] { Path.Combine(aResultsFullGroupDirectory, "<>") });
|
|
||||||
else
|
|
||||||
_AngleBracketCollection.AddRange(IResult.GetDirectoryInfoCollection(_PropertyConfiguration,
|
|
||||||
sourceDirectory,
|
|
||||||
aResultsFullGroupDirectory,
|
|
||||||
contentDescription: string.Empty,
|
|
||||||
singletonDescription: "Properties for each image",
|
|
||||||
collectionDescription: string.Empty,
|
|
||||||
converted: false));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void SetAngleBracketCollection(string sourceDirectory, bool anyNullOrNoIsUniqueFileName)
|
|
||||||
{
|
|
||||||
_AngleBracketCollection.Clear();
|
|
||||||
string aResultsFullGroupDirectory = IResult.GetResultsFullGroupDirectory(_PropertyConfiguration,
|
|
||||||
nameof(A_Property),
|
|
||||||
string.Empty,
|
|
||||||
includeResizeGroup: false,
|
|
||||||
includeModel: false,
|
|
||||||
includePredictorModel: false);
|
|
||||||
SetAngleBracketCollection(aResultsFullGroupDirectory, sourceDirectory, anyNullOrNoIsUniqueFileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SavePropertyParallelWork(long ticks, Shared.Models.Methods.IMetadata<MetadataExtractor.Directory> metadata, int t, Container[] containers)
|
public void SavePropertyParallelWork(long ticks, Shared.Models.Methods.IMetadata<MetadataExtractor.Directory> metadata, int t, Container[] containers)
|
||||||
{
|
{
|
||||||
if (_Log is null)
|
if (_Log is null)
|
||||||
|
@ -15,83 +15,12 @@ namespace View_by_Distance.Property.Models.Stateless;
|
|||||||
internal class Property
|
internal class Property
|
||||||
{
|
{
|
||||||
|
|
||||||
internal static int GetDeterministicHashCode(byte[] value)
|
private static List<DateTime> GetDateTimes(DateTime dateTimeFromName, DateTime?[] dateTimes)
|
||||||
{
|
{
|
||||||
int result;
|
List<DateTime> results = new() { dateTimeFromName };
|
||||||
unchecked
|
foreach (DateTime? dateTime in dateTimes)
|
||||||
{
|
{
|
||||||
int hash1 = (5381 << 16) + 5381;
|
if (dateTime is null)
|
||||||
int hash2 = hash1;
|
|
||||||
for (int i = 0; i < value.Length; i += 2)
|
|
||||||
{
|
|
||||||
hash1 = ((hash1 << 5) + hash1) ^ value[i];
|
|
||||||
if (i == value.Length - 1)
|
|
||||||
break;
|
|
||||||
hash2 = ((hash2 << 5) + hash2) ^ value[i + 1];
|
|
||||||
}
|
|
||||||
result = hash1 + (hash2 * 1566083941);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
#pragma warning disable CA1416
|
|
||||||
|
|
||||||
internal static PropertyItem GetPropertyItem(ConstructorInfo constructorInfo, int id, short type, string value)
|
|
||||||
{
|
|
||||||
PropertyItem result = (PropertyItem)constructorInfo.Invoke(null);
|
|
||||||
int length;
|
|
||||||
byte[] bytes;
|
|
||||||
if (type == 2)
|
|
||||||
{
|
|
||||||
bytes = GetBytes(value);
|
|
||||||
length = value.Length + 1;
|
|
||||||
}
|
|
||||||
else if (type == 1)
|
|
||||||
{
|
|
||||||
bytes = Encoding.Unicode.GetBytes($"{value}\0");
|
|
||||||
length = bytes.Length;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
throw new NotSupportedException();
|
|
||||||
result.Id = id;
|
|
||||||
result.Len = length;
|
|
||||||
result.Type = type;
|
|
||||||
result.Value = bytes;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
#pragma warning restore CA1416
|
|
||||||
|
|
||||||
internal static byte[] GetBytes(string value)
|
|
||||||
{
|
|
||||||
byte[] results = new byte[value.Length + 1];
|
|
||||||
for (int i = 0; i < value.Length; i++)
|
|
||||||
results[i] = (byte)value[i];
|
|
||||||
results[value.Length] = 0x00;
|
|
||||||
return results;
|
|
||||||
}
|
|
||||||
|
|
||||||
internal static DateTime? GetDateTime(string dateTimeFormat, string? value)
|
|
||||||
{
|
|
||||||
DateTime? result;
|
|
||||||
string alternateFormat = "ddd MMM dd HH:mm:ss yyyy";
|
|
||||||
if (value is not null && DateTime.TryParse(value, out DateTime dateTime))
|
|
||||||
result = dateTime;
|
|
||||||
else if (value is not null && value.Length == dateTimeFormat.Length && DateTime.TryParseExact(value, dateTimeFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTime))
|
|
||||||
result = dateTime;
|
|
||||||
else if (value is not null && value.Length == alternateFormat.Length && DateTime.TryParseExact(value, alternateFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTime))
|
|
||||||
result = dateTime;
|
|
||||||
else
|
|
||||||
result = null;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static List<DateTime> GetDateTimes(DateTime?[] metadataDateTimes)
|
|
||||||
{
|
|
||||||
List<DateTime> results = new();
|
|
||||||
foreach (DateTime? dateTime in metadataDateTimes)
|
|
||||||
{
|
|
||||||
if (dateTime is null || results.Contains(dateTime.Value))
|
|
||||||
continue;
|
continue;
|
||||||
results.Add(dateTime.Value);
|
results.Add(dateTime.Value);
|
||||||
}
|
}
|
||||||
@ -135,20 +64,15 @@ internal class Property
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<DateTime> GetDateTimes(DateTime dateTimeFromName, DateTime?[] dateTimes)
|
internal static byte[] GetBytes(string value)
|
||||||
{
|
{
|
||||||
List<DateTime> results = new() { dateTimeFromName };
|
byte[] results = new byte[value.Length + 1];
|
||||||
foreach (DateTime? dateTime in dateTimes)
|
for (int i = 0; i < value.Length; i++)
|
||||||
{
|
results[i] = (byte)value[i];
|
||||||
if (dateTime is null)
|
results[value.Length] = 0x00;
|
||||||
continue;
|
|
||||||
results.Add(dateTime.Value);
|
|
||||||
}
|
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma warning disable CA1416
|
|
||||||
|
|
||||||
internal static DateTime? GetDateTimeFromName(FileHolder fileHolder)
|
internal static DateTime? GetDateTimeFromName(FileHolder fileHolder)
|
||||||
{
|
{
|
||||||
DateTime? result = null;
|
DateTime? result = null;
|
||||||
@ -200,6 +124,82 @@ internal class Property
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static List<DateTime> GetDateTimes(DateTime?[] metadataDateTimes)
|
||||||
|
{
|
||||||
|
List<DateTime> results = new();
|
||||||
|
foreach (DateTime? dateTime in metadataDateTimes)
|
||||||
|
{
|
||||||
|
if (dateTime is null || results.Contains(dateTime.Value))
|
||||||
|
continue;
|
||||||
|
results.Add(dateTime.Value);
|
||||||
|
}
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static int GetDeterministicHashCode(byte[] value)
|
||||||
|
{
|
||||||
|
int result;
|
||||||
|
unchecked
|
||||||
|
{
|
||||||
|
int hash1 = (5381 << 16) + 5381;
|
||||||
|
int hash2 = hash1;
|
||||||
|
for (int i = 0; i < value.Length; i += 2)
|
||||||
|
{
|
||||||
|
hash1 = ((hash1 << 5) + hash1) ^ value[i];
|
||||||
|
if (i == value.Length - 1)
|
||||||
|
break;
|
||||||
|
hash2 = ((hash2 << 5) + hash2) ^ value[i + 1];
|
||||||
|
}
|
||||||
|
result = hash1 + (hash2 * 1566083941);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma warning disable CA1416
|
||||||
|
|
||||||
|
internal static PropertyItem GetPropertyItem(ConstructorInfo constructorInfo, int id, short type, string value)
|
||||||
|
{
|
||||||
|
PropertyItem result = (PropertyItem)constructorInfo.Invoke(null);
|
||||||
|
int length;
|
||||||
|
byte[] bytes;
|
||||||
|
if (type == 2)
|
||||||
|
{
|
||||||
|
bytes = GetBytes(value);
|
||||||
|
length = value.Length + 1;
|
||||||
|
}
|
||||||
|
else if (type == 1)
|
||||||
|
{
|
||||||
|
bytes = Encoding.Unicode.GetBytes($"{value}\0");
|
||||||
|
length = bytes.Length;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
throw new NotSupportedException();
|
||||||
|
result.Id = id;
|
||||||
|
result.Len = length;
|
||||||
|
result.Type = type;
|
||||||
|
result.Value = bytes;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma warning restore CA1416
|
||||||
|
|
||||||
|
internal static DateTime? GetDateTime(string dateTimeFormat, string? value)
|
||||||
|
{
|
||||||
|
DateTime? result;
|
||||||
|
string alternateFormat = "ddd MMM dd HH:mm:ss yyyy";
|
||||||
|
if (value is not null && DateTime.TryParse(value, out DateTime dateTime))
|
||||||
|
result = dateTime;
|
||||||
|
else if (value is not null && value.Length == dateTimeFormat.Length && DateTime.TryParseExact(value, dateTimeFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTime))
|
||||||
|
result = dateTime;
|
||||||
|
else if (value is not null && value.Length == alternateFormat.Length && DateTime.TryParseExact(value, alternateFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTime))
|
||||||
|
result = dateTime;
|
||||||
|
else
|
||||||
|
result = null;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma warning disable CA1416
|
||||||
|
|
||||||
internal static (string?, DateTime[], Shared.Models.Property) GetProperty(bool populateId, IMetadata<MetadataExtractor.Directory>? metadata, FileHolder fileHolder, Shared.Models.Property? property, bool isIgnoreExtension, bool isValidImageFormatExtension, int? id, ASCIIEncoding asciiEncoding)
|
internal static (string?, DateTime[], Shared.Models.Property) GetProperty(bool populateId, IMetadata<MetadataExtractor.Directory>? metadata, FileHolder fileHolder, Shared.Models.Property? property, bool isIgnoreExtension, bool isValidImageFormatExtension, int? id, ASCIIEncoding asciiEncoding)
|
||||||
{
|
{
|
||||||
Shared.Models.Property result;
|
Shared.Models.Property result;
|
||||||
|
@ -5,16 +5,10 @@ namespace View_by_Distance.Property.Models.Stateless;
|
|||||||
internal class Result
|
internal class Result
|
||||||
{
|
{
|
||||||
|
|
||||||
internal static string GetRelativePath(Shared.Models.Properties.IPropertyConfiguration propertyConfiguration, string path)
|
internal static string GetResultsDateGroupDirectory(Shared.Models.Properties.IPropertyConfiguration propertyConfiguration, string description, string jsonGroup)
|
||||||
{
|
{
|
||||||
string result = Shared.Models.Stateless.Methods.IPath.GetRelativePath(path, propertyConfiguration.RootDirectory.Length);
|
string result = Path.Combine(GetResultsDateGroupDirectory(propertyConfiguration, description), jsonGroup);
|
||||||
return result;
|
if (!Directory.Exists(result))
|
||||||
}
|
|
||||||
|
|
||||||
internal static string GetResultsGroupDirectory(Shared.Models.Properties.IPropertyConfiguration propertyConfiguration, string description, bool create)
|
|
||||||
{
|
|
||||||
string result = Path.Combine($"{propertyConfiguration.RootDirectory}-Results", description.Replace('_', ')'));
|
|
||||||
if (create && !Directory.Exists(result))
|
|
||||||
_ = Directory.CreateDirectory(result);
|
_ = Directory.CreateDirectory(result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -27,40 +21,9 @@ internal class Result
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static string GetResultsDateGroupDirectory(Shared.Models.Properties.IPropertyConfiguration propertyConfiguration, string description, string jsonGroup)
|
internal static string GetRelativePath(Shared.Models.Properties.IPropertyConfiguration propertyConfiguration, string path)
|
||||||
{
|
{
|
||||||
string result = Path.Combine(GetResultsDateGroupDirectory(propertyConfiguration, description), jsonGroup);
|
string result = Shared.Models.Stateless.Methods.IPath.GetRelativePath(path, propertyConfiguration.RootDirectory.Length);
|
||||||
if (!Directory.Exists(result))
|
|
||||||
_ = Directory.CreateDirectory(result);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
internal static string GetResultsFullGroupDirectory(Shared.Models.Properties.IPropertyConfiguration propertyConfiguration, string description, string outputResolution, bool includeResizeGroup, bool includeModel, bool includePredictorModel)
|
|
||||||
{
|
|
||||||
string result = GetResultsDateGroupDirectory(propertyConfiguration, description);
|
|
||||||
if (includeResizeGroup)
|
|
||||||
result = Path.Combine(result, outputResolution);
|
|
||||||
if (includeModel && includePredictorModel)
|
|
||||||
{
|
|
||||||
string modelName;
|
|
||||||
string predictorModelName;
|
|
||||||
if (propertyConfiguration.ModelName is null)
|
|
||||||
modelName = Model.Hog.ToString();
|
|
||||||
else
|
|
||||||
modelName = propertyConfiguration.ModelName;
|
|
||||||
if (propertyConfiguration.PredictorModelName is null)
|
|
||||||
predictorModelName = PredictorModel.Large.ToString();
|
|
||||||
else
|
|
||||||
predictorModelName = propertyConfiguration.PredictorModelName;
|
|
||||||
string dateGroupDirectory = string.Concat(outputResolution.Replace(" ", string.Empty), "-", modelName, "-", predictorModelName, "-", propertyConfiguration.NumberOfJitters, "-", propertyConfiguration.NumberOfTimesToUpsample);
|
|
||||||
result = Path.Combine(result, dateGroupDirectory);
|
|
||||||
}
|
|
||||||
else if (includeModel)
|
|
||||||
throw new Exception();
|
|
||||||
else if (includePredictorModel)
|
|
||||||
throw new Exception();
|
|
||||||
if (!Directory.Exists(result))
|
|
||||||
_ = Directory.CreateDirectory(result);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,6 +74,35 @@ internal class Result
|
|||||||
_ = Directory.CreateDirectory(checkDirectory);
|
_ = Directory.CreateDirectory(checkDirectory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static string GetResultsFullGroupDirectory(Shared.Models.Properties.IPropertyConfiguration propertyConfiguration, string description, string outputResolution, bool includeResizeGroup, bool includeModel, bool includePredictorModel)
|
||||||
|
{
|
||||||
|
string result = GetResultsDateGroupDirectory(propertyConfiguration, description);
|
||||||
|
if (includeResizeGroup)
|
||||||
|
result = Path.Combine(result, outputResolution);
|
||||||
|
if (includeModel && includePredictorModel)
|
||||||
|
{
|
||||||
|
string modelName;
|
||||||
|
string predictorModelName;
|
||||||
|
if (propertyConfiguration.ModelName is null)
|
||||||
|
modelName = Model.Hog.ToString();
|
||||||
|
else
|
||||||
|
modelName = propertyConfiguration.ModelName;
|
||||||
|
if (propertyConfiguration.PredictorModelName is null)
|
||||||
|
predictorModelName = PredictorModel.Large.ToString();
|
||||||
|
else
|
||||||
|
predictorModelName = propertyConfiguration.PredictorModelName;
|
||||||
|
string dateGroupDirectory = string.Concat(outputResolution.Replace(" ", string.Empty), "-", modelName, "-", predictorModelName, "-", propertyConfiguration.NumberOfJitters, "-", propertyConfiguration.NumberOfTimesToUpsample);
|
||||||
|
result = Path.Combine(result, dateGroupDirectory);
|
||||||
|
}
|
||||||
|
else if (includeModel)
|
||||||
|
throw new Exception();
|
||||||
|
else if (includePredictorModel)
|
||||||
|
throw new Exception();
|
||||||
|
if (!Directory.Exists(result))
|
||||||
|
_ = Directory.CreateDirectory(result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
internal static List<string> GetDirectoryInfoCollection(Shared.Models.Properties.IPropertyConfiguration propertyConfiguration, string sourceDirectory, string dateGroupDirectory, string contentDescription, string singletonDescription, string collectionDescription, bool converted)
|
internal static List<string> GetDirectoryInfoCollection(Shared.Models.Properties.IPropertyConfiguration propertyConfiguration, string sourceDirectory, string dateGroupDirectory, string contentDescription, string singletonDescription, string collectionDescription, bool converted)
|
||||||
{
|
{
|
||||||
List<string> results = new();
|
List<string> results = new();
|
||||||
@ -126,6 +118,14 @@ internal class Result
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static string GetResultsGroupDirectory(Shared.Models.Properties.IPropertyConfiguration propertyConfiguration, string description, bool create)
|
||||||
|
{
|
||||||
|
string result = Path.Combine($"{propertyConfiguration.RootDirectory}-Results", description.Replace('_', ')'));
|
||||||
|
if (create && !Directory.Exists(result))
|
||||||
|
_ = Directory.CreateDirectory(result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
internal static List<string> GetDirectoryInfoCollection(Shared.Models.Properties.IPropertyConfiguration propertyConfiguration, string sourceDirectory, string description, string outputResolution, bool includeResizeGroup, bool includeModel, bool includePredictorModel, string contentDescription, string singletonDescription, string collectionDescription)
|
internal static List<string> GetDirectoryInfoCollection(Shared.Models.Properties.IPropertyConfiguration propertyConfiguration, string sourceDirectory, string description, string outputResolution, bool includeResizeGroup, bool includeModel, bool includePredictorModel, string contentDescription, string singletonDescription, string collectionDescription)
|
||||||
{
|
{
|
||||||
List<string> results;
|
List<string> results;
|
||||||
|
220
Rename/Rename.cs
220
Rename/Rename.cs
@ -1,4 +1,4 @@
|
|||||||
using CliWrap;
|
using CliWrap;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Phares.Shared;
|
using Phares.Shared;
|
||||||
using Serilog;
|
using Serilog;
|
||||||
@ -72,6 +72,115 @@ public class Rename
|
|||||||
throw new NullReferenceException(nameof(_PropertyConfiguration));
|
throw new NullReferenceException(nameof(_PropertyConfiguration));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<string> RenameFilesInDirectories(ILogger log)
|
||||||
|
{
|
||||||
|
List<string> results = new();
|
||||||
|
string message;
|
||||||
|
bool nefPresentCheck;
|
||||||
|
bool nefPresent = false;
|
||||||
|
ProgressBar progressBar;
|
||||||
|
List<Record> records = new();
|
||||||
|
const string fileSearchFilter = "*";
|
||||||
|
int offset = IDirectory.GetOffset();
|
||||||
|
const bool useCeilingAverage = false;
|
||||||
|
const string directorySearchFilter = "*";
|
||||||
|
List<string> distinctDirectories = new();
|
||||||
|
B_Metadata metadata = new(_PropertyConfiguration);
|
||||||
|
List<(FileHolder, string, string)> toDoCollection = new();
|
||||||
|
List<(FileHolder, string)> verifiedToDoCollection = new();
|
||||||
|
ProgressBarOptions options = new() { ProgressCharacter = '─', ProgressBarOnBottom = true, DisableBottomPercentage = true };
|
||||||
|
List<string[]> filesCollection = IDirectory.GetFilesCollection(_PropertyConfiguration.RootDirectory, directorySearchFilter, fileSearchFilter, useCeilingAverage);
|
||||||
|
int count = filesCollection.Select(l => l.Length).Sum();
|
||||||
|
foreach (string[] files in filesCollection)
|
||||||
|
{
|
||||||
|
if (!files.Any())
|
||||||
|
continue;
|
||||||
|
// foreach (string files[i] in files)
|
||||||
|
// {
|
||||||
|
// if (!files[i].EndsWith(".del"))
|
||||||
|
// continue;
|
||||||
|
// File.Move(files[i], files[i][..^4]);
|
||||||
|
// }
|
||||||
|
// continue;
|
||||||
|
distinctDirectories.Clear();
|
||||||
|
if (_AppSettings.RenameUndo)
|
||||||
|
{
|
||||||
|
message = $") Undo renaming files for <{files.FirstOrDefault()}>";
|
||||||
|
progressBar = new(files.Length, message, options);
|
||||||
|
toDoCollection.AddRange(GetRenameUndoToDoCollection(progressBar, files));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
message = $"{records.Count:00000}) Gathering records for files next to <{files.FirstOrDefault()}>";
|
||||||
|
progressBar = new(files.Length, message, options);
|
||||||
|
nefPresentCheck = files.Any(l => l.EndsWith(".NEF"));
|
||||||
|
if (!nefPresentCheck)
|
||||||
|
records.AddRange(GetRecords(metadata, offset + records.Count, progressBar, files));
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!nefPresent)
|
||||||
|
nefPresent = true;
|
||||||
|
records.AddRange(GetRecords(metadata, offset + records.Count, progressBar, (from l in files where l.EndsWith(".JPG") select l).ToArray()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
progressBar.Dispose();
|
||||||
|
}
|
||||||
|
if (records.Any())
|
||||||
|
{
|
||||||
|
int intMinValueLength = int.MinValue.ToString().Length;
|
||||||
|
foreach (Record record in records)
|
||||||
|
{
|
||||||
|
if (record.Id is null)
|
||||||
|
continue;
|
||||||
|
if (intMinValueLength < record.Id.Value.ToString().Length)
|
||||||
|
throw new NotSupportedException();
|
||||||
|
}
|
||||||
|
message = $"{intMinValueLength}) comparing records";
|
||||||
|
progressBar = new(records.Count, message, options);
|
||||||
|
toDoCollection.AddRange(GetToDoCollection(progressBar, nefPresent, records, intMinValueLength));
|
||||||
|
progressBar.Dispose();
|
||||||
|
}
|
||||||
|
foreach ((FileHolder fileHolder, string directory, string to) in toDoCollection)
|
||||||
|
{
|
||||||
|
if (distinctDirectories.Contains(directory))
|
||||||
|
continue;
|
||||||
|
distinctDirectories.Add(directory);
|
||||||
|
}
|
||||||
|
foreach (string distinctDirectory in distinctDirectories)
|
||||||
|
{
|
||||||
|
if (!Directory.Exists(distinctDirectory))
|
||||||
|
_ = Directory.CreateDirectory(distinctDirectory);
|
||||||
|
}
|
||||||
|
foreach ((FileHolder fileHolder, string directory, string to) in toDoCollection)
|
||||||
|
{
|
||||||
|
if (File.Exists(to))
|
||||||
|
continue;
|
||||||
|
verifiedToDoCollection.Add(new(fileHolder, to));
|
||||||
|
File.WriteAllText($"{to}.paddedId", $"{to}{Environment.NewLine}{fileHolder.FullName}");
|
||||||
|
}
|
||||||
|
ConsoleKey? consoleKey = null;
|
||||||
|
log.Information($"Ready to Move {verifiedToDoCollection.Count} files[i](s)?");
|
||||||
|
for (int y = 0; y < int.MaxValue; y++)
|
||||||
|
{
|
||||||
|
log.Information("Press \"Y\" key to move files[i](s), \"N\" key to log files[i](s) or close console to not move files");
|
||||||
|
consoleKey = System.Console.ReadKey().Key;
|
||||||
|
if (consoleKey is ConsoleKey.Y or ConsoleKey.N)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
log.Information(". . .");
|
||||||
|
if (consoleKey is null || consoleKey.Value != ConsoleKey.Y)
|
||||||
|
log.Information("Nothing moved!");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
message = ") Renaming files";
|
||||||
|
progressBar = new(count, message, options);
|
||||||
|
results.AddRange(Move(progressBar, verifiedToDoCollection));
|
||||||
|
progressBar.Dispose();
|
||||||
|
log.Information("Done Moving");
|
||||||
|
}
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
private static List<(FileHolder, string, string)> GetRenameUndoToDoCollection(ProgressBar progressBar, string[] files)
|
private static List<(FileHolder, string, string)> GetRenameUndoToDoCollection(ProgressBar progressBar, string[] files)
|
||||||
{
|
{
|
||||||
List<(FileHolder, string, string)> results = new();
|
List<(FileHolder, string, string)> results = new();
|
||||||
@ -335,113 +444,4 @@ public class Rename
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<string> RenameFilesInDirectories(ILogger log)
|
|
||||||
{
|
|
||||||
List<string> results = new();
|
|
||||||
string message;
|
|
||||||
bool nefPresentCheck;
|
|
||||||
bool nefPresent = false;
|
|
||||||
ProgressBar progressBar;
|
|
||||||
List<Record> records = new();
|
|
||||||
const string fileSearchFilter = "*";
|
|
||||||
int offset = IDirectory.GetOffset();
|
|
||||||
const bool useCeilingAverage = false;
|
|
||||||
const string directorySearchFilter = "*";
|
|
||||||
List<string> distinctDirectories = new();
|
|
||||||
B_Metadata metadata = new(_PropertyConfiguration);
|
|
||||||
List<(FileHolder, string, string)> toDoCollection = new();
|
|
||||||
List<(FileHolder, string)> verifiedToDoCollection = new();
|
|
||||||
ProgressBarOptions options = new() { ProgressCharacter = '─', ProgressBarOnBottom = true, DisableBottomPercentage = true };
|
|
||||||
List<string[]> filesCollection = IDirectory.GetFilesCollection(_PropertyConfiguration.RootDirectory, directorySearchFilter, fileSearchFilter, useCeilingAverage);
|
|
||||||
int count = filesCollection.Select(l => l.Length).Sum();
|
|
||||||
foreach (string[] files in filesCollection)
|
|
||||||
{
|
|
||||||
if (!files.Any())
|
|
||||||
continue;
|
|
||||||
// foreach (string files[i] in files)
|
|
||||||
// {
|
|
||||||
// if (!files[i].EndsWith(".del"))
|
|
||||||
// continue;
|
|
||||||
// File.Move(files[i], files[i][..^4]);
|
|
||||||
// }
|
|
||||||
// continue;
|
|
||||||
distinctDirectories.Clear();
|
|
||||||
if (_AppSettings.RenameUndo)
|
|
||||||
{
|
|
||||||
message = $") Undo renaming files for <{files.FirstOrDefault()}>";
|
|
||||||
progressBar = new(files.Length, message, options);
|
|
||||||
toDoCollection.AddRange(GetRenameUndoToDoCollection(progressBar, files));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
message = $"{records.Count:00000}) Gathering records for files next to <{files.FirstOrDefault()}>";
|
|
||||||
progressBar = new(files.Length, message, options);
|
|
||||||
nefPresentCheck = files.Any(l => l.EndsWith(".NEF"));
|
|
||||||
if (!nefPresentCheck)
|
|
||||||
records.AddRange(GetRecords(metadata, offset + records.Count, progressBar, files));
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (!nefPresent)
|
|
||||||
nefPresent = true;
|
|
||||||
records.AddRange(GetRecords(metadata, offset + records.Count, progressBar, (from l in files where l.EndsWith(".JPG") select l).ToArray()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
progressBar.Dispose();
|
|
||||||
}
|
|
||||||
if (records.Any())
|
|
||||||
{
|
|
||||||
int intMinValueLength = int.MinValue.ToString().Length;
|
|
||||||
foreach (Record record in records)
|
|
||||||
{
|
|
||||||
if (record.Id is null)
|
|
||||||
continue;
|
|
||||||
if (intMinValueLength < record.Id.Value.ToString().Length)
|
|
||||||
throw new NotSupportedException();
|
|
||||||
}
|
|
||||||
message = $"{intMinValueLength}) comparing records";
|
|
||||||
progressBar = new(records.Count, message, options);
|
|
||||||
toDoCollection.AddRange(GetToDoCollection(progressBar, nefPresent, records, intMinValueLength));
|
|
||||||
progressBar.Dispose();
|
|
||||||
}
|
|
||||||
foreach ((FileHolder fileHolder, string directory, string to) in toDoCollection)
|
|
||||||
{
|
|
||||||
if (distinctDirectories.Contains(directory))
|
|
||||||
continue;
|
|
||||||
distinctDirectories.Add(directory);
|
|
||||||
}
|
|
||||||
foreach (string distinctDirectory in distinctDirectories)
|
|
||||||
{
|
|
||||||
if (!Directory.Exists(distinctDirectory))
|
|
||||||
_ = Directory.CreateDirectory(distinctDirectory);
|
|
||||||
}
|
|
||||||
foreach ((FileHolder fileHolder, string directory, string to) in toDoCollection)
|
|
||||||
{
|
|
||||||
if (File.Exists(to))
|
|
||||||
continue;
|
|
||||||
verifiedToDoCollection.Add(new(fileHolder, to));
|
|
||||||
File.WriteAllText($"{to}.paddedId", $"{to}{Environment.NewLine}{fileHolder.FullName}");
|
|
||||||
}
|
|
||||||
ConsoleKey? consoleKey = null;
|
|
||||||
log.Information($"Ready to Move {verifiedToDoCollection.Count} files[i](s)?");
|
|
||||||
for (int y = 0; y < int.MaxValue; y++)
|
|
||||||
{
|
|
||||||
log.Information("Press \"Y\" key to move files[i](s), \"N\" key to log files[i](s) or close console to not move files");
|
|
||||||
consoleKey = System.Console.ReadKey().Key;
|
|
||||||
if (consoleKey is ConsoleKey.Y or ConsoleKey.N)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
log.Information(". . .");
|
|
||||||
if (consoleKey is null || consoleKey.Value != ConsoleKey.Y)
|
|
||||||
log.Information("Nothing moved!");
|
|
||||||
else
|
|
||||||
{
|
|
||||||
message = ") Renaming files";
|
|
||||||
progressBar = new(count, message, options);
|
|
||||||
results.AddRange(Move(progressBar, verifiedToDoCollection));
|
|
||||||
progressBar.Dispose();
|
|
||||||
log.Information("Done Moving");
|
|
||||||
}
|
|
||||||
return results;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user