Save Grouped Face Encodings
This commit is contained in:
@ -503,42 +503,47 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
|
||||
SaveFaces(faceCollection, resizedFileInfo, imageFiles);
|
||||
}
|
||||
|
||||
internal void SaveShortcuts(Property.Models.Configuration configuration, string[] juliePhares, Model model, PredictorModel predictorModel, PropertyLogic propertyLogic, Dictionary<string, List<Person>> peopleCollection, string outputResolution, PropertyHolder[] filteredPropertyHolderCollection, List<A_Property> propertyCollection, List<List<D_Face>> faceCollections)
|
||||
internal static List<(PropertyHolder, (string, D_Face?, (string, string, string, string))[])> GetCollection(Property.Models.Configuration configuration, Model model, PredictorModel predictorModel, PropertyLogic propertyLogic, Dictionary<string, List<Person>> peopleCollection, string outputResolution, PropertyHolder[] filteredPropertyHolderCollection, List<List<D_Face>> faceCollections)
|
||||
{
|
||||
List<(PropertyHolder, (string, D_Face?, (string, string, string, string))[])> results = new();
|
||||
string[] keys;
|
||||
string fileName;
|
||||
string fullName;
|
||||
string personKey;
|
||||
string directory;
|
||||
bool? isWrongYear;
|
||||
FileInfo fileInfo;
|
||||
TimeSpan timeSpan;
|
||||
string copyFileName;
|
||||
DateTime? birthDate;
|
||||
string copyDirectory;
|
||||
string? relativePath;
|
||||
string isWrongYearFlag;
|
||||
string shortcutFileName;
|
||||
string subDirectoryName;
|
||||
DateTime minimumDateTime;
|
||||
List<int> indices = new();
|
||||
List<D_Face> faceCollection;
|
||||
PropertyHolder propertyHolder;
|
||||
WindowsShortcut windowsShortcut;
|
||||
const string pattern = @"[\\,\/,\:,\*,\?,\"",\<,\>,\|]";
|
||||
List<(string, D_Face?, (string, string, string, string))> collection;
|
||||
string dFacesContentDirectory = Path.Combine(Property.Models.Stateless.IResult.GetResultsFullGroupDirectory(configuration, model, predictorModel, nameof(D_Face), outputResolution, includeResizeGroup: true, includeModel: true, includePredictorModel: true), "(_)");
|
||||
for (int i = 0; i < filteredPropertyHolderCollection.Length; i++)
|
||||
{
|
||||
indices.Clear();
|
||||
personKey = string.Empty;
|
||||
copyFileName = string.Empty;
|
||||
copyDirectory = string.Empty;
|
||||
propertyHolder = filteredPropertyHolderCollection[i];
|
||||
if (propertyHolder.ImageFileInfo is null)
|
||||
continue;
|
||||
fileInfo = propertyHolder.ImageFileInfo;
|
||||
relativePath = Path.GetDirectoryName($"C:{propertyHolder.RelativePath}");
|
||||
if (string.IsNullOrEmpty(relativePath) || relativePath.Length < 3)
|
||||
continue;
|
||||
if (propertyHolder.Property?.Id is null || propertyHolder.MinimumDateTime is null || propertyHolder.ResizedFileInfo is null)
|
||||
continue;
|
||||
collection = new();
|
||||
if (!propertyLogic.NamedFaceInfoDeterministicHashCodeIndices.ContainsKey(propertyHolder.Property.Id.Value))
|
||||
{
|
||||
faceCollection = new();
|
||||
directory = Path.Combine(dFacesContentDirectory, $"Unnamed{relativePath[2..]}");
|
||||
}
|
||||
else
|
||||
{
|
||||
faceCollection = faceCollections[i];
|
||||
@ -555,6 +560,7 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
|
||||
directory = Path.Combine(dFacesContentDirectory, $"Many{relativePath[2..]}", subDirectoryName);
|
||||
else
|
||||
{
|
||||
indices.Add(0);
|
||||
personKey = keys[0];
|
||||
if (isWrongYear is not null && !isWrongYear.Value && personKey[..2] is "19" or "20")
|
||||
{
|
||||
@ -570,38 +576,69 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
|
||||
}
|
||||
}
|
||||
}
|
||||
directory = Path.Combine(dFacesContentDirectory, "Named Shortcuts", personKey, subDirectoryName);
|
||||
if (juliePhares.Contains(personKey))
|
||||
copyDirectory = Path.Combine(dFacesContentDirectory, "Named Images", personKey, subDirectoryName);
|
||||
directory = Path.Combine(dFacesContentDirectory, "Shortcuts", personKey, subDirectoryName);
|
||||
copyDirectory = Path.Combine(dFacesContentDirectory, "Images", personKey, subDirectoryName);
|
||||
copyFileName = Path.Combine(copyDirectory, $"{propertyHolder.Property.Id.Value}{propertyHolder.ResizedFileInfo.Extension}");
|
||||
}
|
||||
}
|
||||
if (!Directory.Exists(directory))
|
||||
shortcutFileName = Path.Combine(directory, $"{propertyHolder.Property.Id.Value}.lnk");
|
||||
if (string.IsNullOrEmpty(personKey) || !indices.Any())
|
||||
collection.Add(new(personKey, null, (directory, copyDirectory, copyFileName, shortcutFileName)));
|
||||
else
|
||||
{
|
||||
_ = Directory.CreateDirectory(directory);
|
||||
if (!string.IsNullOrEmpty(personKey) && peopleCollection.ContainsKey(personKey))
|
||||
foreach (int index in indices)
|
||||
collection.Add(new(personKey, faceCollection[index], (directory, copyDirectory, copyFileName, shortcutFileName)));
|
||||
}
|
||||
results.Add(new(propertyHolder, collection.ToArray()));
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
internal static void SaveShortcuts(string[] juliePhares, Dictionary<string, List<Person>> peopleCollection, List<(PropertyHolder, (string, D_Face?, (string Directory, string CopyDirectory, string CopyFileName, string ShortcutFileName))[])> collections)
|
||||
{
|
||||
Person person;
|
||||
string fileName;
|
||||
string fullName;
|
||||
WindowsShortcut windowsShortcut;
|
||||
const string pattern = @"[\\,\/,\:,\*,\?,\"",\<,\>,\|]";
|
||||
foreach ((PropertyHolder propertyHolder, (string personKey, D_Face? face, (string, string, string, string))[] collection) in collections)
|
||||
{
|
||||
if (collection.Length != 1)
|
||||
continue;
|
||||
foreach ((string personKey, D_Face? face, (string directory, string copyDirectory, string copyFileName, string shortcutFileName)) in collection)
|
||||
{
|
||||
if (string.IsNullOrEmpty(personKey))
|
||||
continue;
|
||||
if (propertyHolder.Property?.Id is null || propertyHolder.ImageFileInfo is null || propertyHolder.MinimumDateTime is null || propertyHolder.ResizedFileInfo is null)
|
||||
continue;
|
||||
if (!Directory.Exists(directory))
|
||||
{
|
||||
Person person = peopleCollection[personKey][0];
|
||||
fullName = Regex.Replace($"{Shared.Models.Stateless.Methods.IPersonName.GetFullName(person.Name)}.txt", pattern, string.Empty);
|
||||
File.WriteAllText(Path.Combine(directory, fullName), string.Empty);
|
||||
_ = Directory.CreateDirectory(directory);
|
||||
if (!string.IsNullOrEmpty(personKey) && peopleCollection.ContainsKey(personKey))
|
||||
{
|
||||
person = peopleCollection[personKey][0];
|
||||
fullName = Regex.Replace($"{Shared.Models.Stateless.Methods.IPersonName.GetFullName(person.Name)}.txt", pattern, string.Empty);
|
||||
File.WriteAllText(Path.Combine(directory, fullName), string.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!string.IsNullOrEmpty(copyDirectory))
|
||||
{
|
||||
if (!Directory.Exists(copyDirectory))
|
||||
_ = Directory.CreateDirectory(copyDirectory);
|
||||
fileName = Path.Combine(copyDirectory, $"{propertyHolder.Property.Id.Value}{propertyHolder.ResizedFileInfo.Extension}");
|
||||
if (juliePhares.Contains(personKey) && !string.IsNullOrEmpty(copyDirectory))
|
||||
{
|
||||
if (!Directory.Exists(copyDirectory))
|
||||
_ = Directory.CreateDirectory(copyDirectory);
|
||||
fileName = Path.Combine(copyDirectory, $"{propertyHolder.Property.Id.Value}{propertyHolder.ResizedFileInfo.Extension}");
|
||||
if (!File.Exists(fileName))
|
||||
File.Copy(propertyHolder.ResizedFileInfo.FullName, fileName);
|
||||
}
|
||||
fileName = Path.Combine(directory, $"{propertyHolder.Property.Id.Value}.lnk");
|
||||
if (File.Exists(fileName))
|
||||
continue;
|
||||
windowsShortcut = new() { Path = propertyHolder.ImageFileInfo.FullName };
|
||||
windowsShortcut.Save(fileName);
|
||||
windowsShortcut.Dispose();
|
||||
if (!File.Exists(fileName))
|
||||
File.Copy(propertyHolder.ResizedFileInfo.FullName, fileName);
|
||||
continue;
|
||||
File.SetLastWriteTime(fileName, propertyHolder.MinimumDateTime.Value);
|
||||
}
|
||||
fileName = Path.Combine(directory, $"{propertyHolder.Property.Id.Value}.lnk");
|
||||
if (File.Exists(fileName))
|
||||
continue;
|
||||
windowsShortcut = new() { Path = fileInfo.FullName };
|
||||
windowsShortcut.Save(fileName);
|
||||
windowsShortcut.Dispose();
|
||||
if (!File.Exists(fileName))
|
||||
continue;
|
||||
File.SetLastWriteTime(fileName, propertyHolder.MinimumDateTime.Value);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user