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

@ -129,7 +129,7 @@ public class C_Resize
}
}
private byte[] SaveResizedSubfile3(string subFile, int[] resize, byte[] bytes, FileInfo? fileInfo)
private byte[] SaveResizedSubfile3(string subFile, int[] resize, byte[] bytes, FileHolder? fileHolder)
{
byte[] results;
Bitmap bitmap;
@ -169,19 +169,19 @@ public class C_Resize
default:
break;
}
if (fileInfo is null)
if (fileHolder is null)
results = GetBitmapData(bitmap);
else
{
results = Array.Empty<byte>();
CopyPropertyItems(bytes, propertyItems, bitmap);
bitmap.Save(fileInfo.FullName, _ImageCodecInfo, _EncoderParameters);
bitmap.Save(fileHolder.FullName, _ImageCodecInfo, _EncoderParameters);
}
bitmap.Dispose();
return results;
}
private byte[] SaveResizedSubfile5(string subFile, int[] resize, byte[] bytes, FileInfo? fileInfo)
private byte[] SaveResizedSubfile5(string subFile, int[] resize, byte[] bytes, FileHolder? fileHolder)
{
byte[] results;
Bitmap bitmap;
@ -233,13 +233,13 @@ public class C_Resize
{
using (Graphics graphics = Graphics.FromImage(preRotated))
graphics.DrawImage(bitmap, new Rectangle(0, 0, outputResolutionWidth, outputResolutionHeight), rectangle, GraphicsUnit.Pixel);
if (fileInfo is null)
if (fileHolder is null)
results = GetBitmapData(bitmap);
else
{
results = Array.Empty<byte>();
CopyPropertyItems(bytes, propertyItems, bitmap);
bitmap.Save(fileInfo.FullName, _ImageCodecInfo, _EncoderParameters);
bitmap.Save(fileHolder.FullName, _ImageCodecInfo, _EncoderParameters);
}
}
bitmap.Dispose();
@ -248,7 +248,7 @@ public class C_Resize
#pragma warning restore CA1416
private byte[] SaveResizedSubfile(string subFile, A_Property property, int[] resize, FileInfo? fileInfo)
private byte[] SaveResizedSubfile(string subFile, A_Property property, int[] resize, FileHolder? fileHolder)
{
byte[] results;
string dateTimeFormat = Property.Models.Stateless.A_Property.DateTimeFormat();
@ -258,15 +258,15 @@ public class C_Resize
if (_ASCIIEncoding.GetString(bytes, 0, bytes.Length) != dateTimeValue)
throw new Exception();
if (resize.Length == 3)
results = SaveResizedSubfile3(subFile, resize, bytes, fileInfo);
results = SaveResizedSubfile3(subFile, resize, bytes, fileHolder);
else if (resize.Length == 5)
results = SaveResizedSubfile5(subFile, resize, bytes, fileInfo);
results = SaveResizedSubfile5(subFile, resize, bytes, fileHolder);
else
throw new Exception();
if (fileInfo is not null && false)
if (fileHolder is not null && false)
{
#pragma warning disable CA1416
using Image image = Image.FromFile(fileInfo.FullName);
using Image image = Image.FromFile(fileHolder.FullName);
if (image.PropertyIdList.Contains((int)IExif.Tags.DateTimeDigitized))
{
string value;
@ -287,37 +287,38 @@ public class C_Resize
public byte[] GetResizedBytes(string outputResolution, List<Tuple<string, DateTime>> subFileTuples, PropertyHolder propertyHolder, A_Property property, Dictionary<string, int[]> imageResizes)
{
byte[] results;
if (propertyHolder.ImageFileInfo is null)
throw new Exception($"{propertyHolder.ImageFileInfo} is null!");
if (propertyHolder.ImageFileHolder is null)
throw new Exception($"{propertyHolder.ImageFileHolder} is null!");
if (!imageResizes.ContainsKey(outputResolution))
throw new Exception();
int[] resize = imageResizes[outputResolution];
int outputResolutionWidth = resize[_OutputResolutionWidthIndex];
int outputResolutionHeight = resize[_OutputResolutionHeightIndex];
int outputResolutionOrientation = resize[_OutputResolutionOrientationIndex];
results = SaveResizedSubfile(propertyHolder.ImageFileInfo.FullName, property, resize, fileInfo: null);
results = SaveResizedSubfile(propertyHolder.ImageFileHolder.FullName, property, resize, fileHolder: null);
subFileTuples.Add(new Tuple<string, DateTime>(nameof(C_Resize), DateTime.Now));
return results;
}
public void SaveResizedSubfile(string outputResolution, List<Tuple<string, DateTime>> subFileTuples, PropertyHolder propertyHolder, string original, A_Property property, Dictionary<string, int[]> imageResizes)
{
if (propertyHolder.ImageFileInfo is null)
throw new Exception($"{propertyHolder.ImageFileInfo} is null!");
if (propertyHolder.ResizedFileInfo is null)
throw new Exception($"{propertyHolder.ResizedFileInfo} is null!");
FileInfo fileInfo = propertyHolder.ResizedFileInfo;
if (propertyHolder.ImageFileHolder is null)
throw new Exception($"{propertyHolder.ImageFileHolder} is null!");
if (propertyHolder.ResizedFileHolder is null)
throw new Exception($"{propertyHolder.ResizedFileHolder} is null!");
FileHolder fileHolder = propertyHolder.ResizedFileHolder;
if (!imageResizes.ContainsKey(outputResolution))
throw new Exception();
if (!fileInfo.Exists)
if (!fileHolder.Exists)
{
FileInfo fileInfo = new(fileHolder.FullName);
if (fileInfo.Directory?.Parent is null)
throw new Exception();
string parentCheck = Path.Combine(fileInfo.Directory.Parent.FullName, fileInfo.Name);
if (File.Exists(parentCheck))
{
File.Move(parentCheck, fileInfo.FullName);
fileInfo.Refresh();
propertyHolder.SetResizedFileHolder(FileHolder.Refresh(fileHolder));
}
}
int[] resize = imageResizes[outputResolution];
@ -327,9 +328,9 @@ public class C_Resize
int[] originalCollection = imageResizes[original];
if (outputResolutionWidth == originalCollection[_OutputResolutionWidthIndex] && outputResolutionHeight == originalCollection[_OutputResolutionHeightIndex] && outputResolutionOrientation == originalCollection[_OutputResolutionOrientationIndex])
{
if (!fileInfo.Exists)
if (!fileHolder.Exists)
{
File.Copy(propertyHolder.ImageFileInfo.FullName, fileInfo.FullName);
File.Copy(propertyHolder.ImageFileHolder.FullName, fileHolder.FullName);
subFileTuples.Add(new Tuple<string, DateTime>(nameof(C_Resize), DateTime.Now));
}
}
@ -340,13 +341,13 @@ public class C_Resize
List<DateTime> dateTimes = (from l in subFileTuples where changesFrom.Contains(l.Item1) select l.Item2).ToList();
if (_OverrideForResizeImages)
check = true;
else if (!fileInfo.Exists)
else if (!fileHolder.Exists)
check = true;
else if (dateTimes.Any() && dateTimes.Max() > fileInfo.LastWriteTime)
else if (dateTimes.Any() && dateTimes.Max() > fileHolder.LastWriteTime)
check = true;
if (check)
{
_ = SaveResizedSubfile(propertyHolder.ImageFileInfo.FullName, property, resize, fileInfo);
_ = SaveResizedSubfile(propertyHolder.ImageFileHolder.FullName, property, resize, fileHolder);
subFileTuples.Add(new Tuple<string, DateTime>(nameof(C_Resize), DateTime.Now));
}
}