Simplified GetDirectoryInfoCollection

This commit is contained in:
2022-08-14 10:42:28 -07:00
parent 0392de1920
commit b756859b61
12 changed files with 556 additions and 360 deletions

View File

@ -284,13 +284,15 @@ public class C_Resize
return results;
}
public byte[] GetResizedBytes(string outputResolution, List<Tuple<string, DateTime>> subFileTuples, Item item, A_Property property, Dictionary<string, int[]> imageResizes)
public byte[] GetResizedBytes(string outputResolution, string cResultsFullGroupDirectory, List<Tuple<string, DateTime>> subFileTuples, Item item, A_Property property, Dictionary<string, int[]> imageResizes)
{
byte[] results;
if (item.ImageFileHolder is null)
throw new NullReferenceException(nameof(item.ImageFileHolder));
if (!imageResizes.ContainsKey(outputResolution))
throw new Exception();
if (string.IsNullOrEmpty(cResultsFullGroupDirectory))
throw new NullReferenceException(nameof(cResultsFullGroupDirectory));
int[] resize = imageResizes[outputResolution];
int outputResolutionWidth = resize[_OutputResolutionWidthIndex];
int outputResolutionHeight = resize[_OutputResolutionHeightIndex];
@ -300,12 +302,14 @@ public class C_Resize
return results;
}
public void SaveResizedSubfile(string outputResolution, List<Tuple<string, DateTime>> subFileTuples, Item item, string original, A_Property property, Dictionary<string, int[]> imageResizes)
public void SaveResizedSubfile(string outputResolution, string cResultsFullGroupDirectory, List<Tuple<string, DateTime>> subFileTuples, Item item, string original, A_Property property, Dictionary<string, int[]> imageResizes)
{
if (item.ImageFileHolder is null)
throw new NullReferenceException(nameof(item.ImageFileHolder));
if (item.ResizedFileHolder is null)
throw new NullReferenceException(nameof(item.ResizedFileHolder));
if (string.IsNullOrEmpty(cResultsFullGroupDirectory))
throw new NullReferenceException(nameof(cResultsFullGroupDirectory));
FileHolder fileHolder = item.ResizedFileHolder;
if (!imageResizes.ContainsKey(outputResolution))
throw new Exception();
@ -422,24 +426,42 @@ public class C_Resize
return results;
}
public Dictionary<string, int[]> GetResizeKeyValuePairs(List<Tuple<string, DateTime>> subFileTuples, List<string> parseExceptions, string original, List<KeyValuePair<string, string>> metadataCollection, A_Property property, Item item)
public Dictionary<string, int[]> GetResizeKeyValuePairs(string cResultsFullGroupDirectory, List<Tuple<string, DateTime>> subFileTuples, List<string> parseExceptions, string original, List<KeyValuePair<string, string>> metadataCollection, A_Property property, Item item)
{
Dictionary<string, int[]> results;
if (item.Property?.Id is null)
throw new NullReferenceException(nameof(item.Property.Id));
if (item.ImageFileHolder is null)
throw new NullReferenceException(nameof(item.ImageFileHolder));
if (string.IsNullOrEmpty(cResultsFullGroupDirectory))
throw new NullReferenceException(nameof(cResultsFullGroupDirectory));
string json;
string[] changesFrom = new string[] { nameof(A_Property), nameof(B_Metadata) };
List<DateTime> dateTimes = (from l in subFileTuples where changesFrom.Contains(l.Item1) select l.Item2).ToList();
FileInfo fileInfo = new(Path.Combine(AngleBracketCollection[0].Replace("<>", "{}"), string.Concat(item.ImageFileHolder.NameWithoutExtension, ".json")));
if (!fileInfo.Exists)
string cResizeSingletonFile = Path.Combine(cResultsFullGroupDirectory, "{}", "_ _ _", $"{item.Property.Id.Value}{item.ImageFileHolder.ExtensionLowered}.json");
if (fileInfo.Exists)
{
if (fileInfo.Directory?.Parent is null)
throw new Exception();
string parentCheck = Path.Combine(fileInfo.Directory.Parent.FullName, fileInfo.Name);
if (File.Exists(parentCheck))
if (!File.Exists(cResizeSingletonFile))
{
File.Move(parentCheck, fileInfo.FullName);
fileInfo.Refresh();
fileInfo.MoveTo(cResizeSingletonFile);
fileInfo = new(cResizeSingletonFile);
}
}
else
{
if (File.Exists(cResizeSingletonFile))
fileInfo = new(cResizeSingletonFile);
else
{
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();
}
}
}
if (_ForceResizeLastWriteTimeToCreationTime && !fileInfo.Exists && File.Exists(Path.ChangeExtension(fileInfo.FullName, ".delete")))