Added FileHolder

This commit is contained in:
2022-08-08 19:23:48 -07:00
parent daf5f428b9
commit 3aeab88384
15 changed files with 448 additions and 288 deletions

View File

@ -219,7 +219,7 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
return result;
}
private static void SaveFaces(List<D_Face> faceCollection, FileInfo resizedFileInfo, List<string> imageFiles)
private static void SaveFaces(List<D_Face> faceCollection, FileHolder resizedFileHolder, List<string> imageFiles)
{
int width;
int height;
@ -227,7 +227,7 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
Location location;
Bitmap preRotated;
Rectangle rectangle;
using Bitmap source = new(resizedFileInfo.FullName);
using Bitmap source = new(resizedFileHolder.FullName);
for (int i = 0; i < faceCollection.Count; i++)
{
if (!faceCollection[i].Populated || faceCollection[i]?.Location is null)
@ -251,7 +251,7 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
}
}
private List<D_Face> GetFaces(FileInfo resizedFileInfo, PropertyHolder propertyHolder, A_Property property, int outputResolutionWidth, int outputResolutionHeight, int outputResolutionOrientation, string facesDirectory)
private List<D_Face> GetFaces(FileHolder resizedFileHolder, PropertyHolder propertyHolder, A_Property property, int outputResolutionWidth, int outputResolutionHeight, int outputResolutionOrientation, string facesDirectory)
{
List<D_Face> results = new();
if (_Configuration.PaddingLoops is null)
@ -262,10 +262,10 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
throw new ArgumentNullException(nameof(_Configuration.NumberOfTimesToUpsample));
List<Location> locations;
FaceRecognitionDotNet.Image? unknownImage = null;
if (resizedFileInfo.Exists)
if (resizedFileHolder.Exists)
{
try
{ unknownImage = FaceRecognition.LoadImageFile(resizedFileInfo.FullName); }
{ unknownImage = FaceRecognition.LoadImageFile(resizedFileHolder.FullName); }
catch (Exception) { }
}
if (unknownImage is null)
@ -410,7 +410,7 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
_Populated = populated;
}
internal List<D_Face> GetFaces(Property.Models.Configuration configuration, string outputResolution, List<Tuple<string, DateTime>> subFileTuples, List<string> parseExceptions, PropertyHolder propertyHolder, A_Property property, FileInfo resizedFileInfo, int outputResolutionWidth, int outputResolutionHeight, int outputResolutionOrientation)
internal List<D_Face> GetFaces(Property.Models.Configuration configuration, string outputResolution, List<Tuple<string, DateTime>> subFileTuples, List<string> parseExceptions, PropertyHolder propertyHolder, A_Property property, FileHolder resizedFileHolder, int outputResolutionWidth, int outputResolutionHeight, int outputResolutionOrientation)
{
List<D_Face>? results;
if (_Configuration.PropertiesChangedForFaces is null)
@ -419,8 +419,8 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
D_Face face;
bool checkForOutputResolutionChange = false;
string[] changesFrom = new string[] { nameof(A_Property), nameof(B_Metadata), nameof(C_Resize) };
string facesDirectory = Path.Combine(AngleBracketCollection[0].Replace("<>", "()"), propertyHolder.ImageFileNameWithoutExtension);
List<DateTime> dateTimes = (from l in subFileTuples where changesFrom.Contains(l.Item1) select l.Item2).ToList();
string facesDirectory = Path.Combine(AngleBracketCollection[0].Replace("<>", "()"), propertyHolder.ImageFileNameWithoutExtension);
FileInfo fileInfo = new(Path.Combine(AngleBracketCollection[0].Replace("<>", "[]"), $"{propertyHolder.ImageFileNameWithoutExtension}.json"));
if (!fileInfo.Exists)
{
@ -473,7 +473,7 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
}
else if (results is null)
{
results = GetFaces(resizedFileInfo, propertyHolder, property, outputResolutionWidth, outputResolutionHeight, outputResolutionOrientation, facesDirectory);
results = GetFaces(resizedFileHolder, propertyHolder, property, outputResolutionWidth, outputResolutionHeight, outputResolutionOrientation, facesDirectory);
json = JsonSerializer.Serialize(results, _WriteIndentedJsonSerializerOptions);
bool updateDateWhenMatches = dateTimes.Any() && fileInfo.Exists && dateTimes.Max() > fileInfo.LastWriteTime;
DateTime? dateTime = !updateDateWhenMatches ? null : dateTimes.Max();
@ -487,8 +487,8 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
{
if (_Configuration.OverrideForFaceImages is null)
throw new Exception();
if (propertyHolder.ResizedFileInfo is null)
throw new Exception($"{propertyHolder.ResizedFileInfo} is null!");
if (propertyHolder.ResizedFileHolder is null)
throw new Exception($"{propertyHolder.ResizedFileHolder} is null!");
FileInfo fileInfo;
bool check = false;
string parentCheck;
@ -524,7 +524,7 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
check = true;
}
if (check)
SaveFaces(faceCollection, propertyHolder.ResizedFileInfo, imageFiles);
SaveFaces(faceCollection, propertyHolder.ResizedFileHolder, imageFiles);
}
internal static void SaveShortcuts(Property.Models.Configuration configuration, Model? model, PredictorModel? predictorModel, string[] juliePhares, long ticks, Dictionary<string, List<Person>> peopleCollection, PropertyLogic propertyLogic, string outputResolution, PropertyHolder[] filteredPropertyHolderCollection)
@ -544,7 +544,7 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
{
if (string.IsNullOrEmpty(personKey))
continue;
if (propertyHolder.Property?.Id is null || propertyHolder.ImageFileInfo is null || propertyHolder.MinimumDateTime is null || propertyHolder.ResizedFileInfo is null)
if (propertyHolder.Property?.Id is null || propertyHolder.ImageFileHolder is null || propertyHolder.MinimumDateTime is null || propertyHolder.ResizedFileHolder is null)
continue;
if (!Directory.Exists(directory))
{
@ -560,14 +560,14 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
{
if (!Directory.Exists(copyDirectory))
_ = Directory.CreateDirectory(copyDirectory);
fileName = Path.Combine(copyDirectory, $"{propertyHolder.Property.Id.Value}{propertyHolder.ResizedFileInfo.Extension}");
fileName = Path.Combine(copyDirectory, $"{propertyHolder.Property.Id.Value}{propertyHolder.ResizedFileHolder.Extension}");
if (!File.Exists(fileName))
File.Copy(propertyHolder.ResizedFileInfo.FullName, fileName);
File.Copy(propertyHolder.ResizedFileHolder.FullName, fileName);
}
fileName = Path.Combine(directory, $"{propertyHolder.Property.Id.Value}.lnk");
if (File.Exists(fileName))
continue;
windowsShortcut = new() { Path = propertyHolder.ImageFileInfo.FullName };
windowsShortcut = new() { Path = propertyHolder.ImageFileHolder.FullName };
windowsShortcut.Save(fileName);
windowsShortcut.Dispose();
if (!File.Exists(fileName))