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

@ -78,25 +78,43 @@ public class B_Metadata
return results;
}
public (int, List<KeyValuePair<string, string>>) GetMetadataCollection(List<Tuple<string, DateTime>> subFileTuples, List<string> parseExceptions, Property.Models.Item item)
public (int, List<KeyValuePair<string, string>>) GetMetadataCollection(string bResultsFullGroupDirectory, List<Tuple<string, DateTime>> subFileTuples, List<string> parseExceptions, Property.Models.Item item)
{
List<KeyValuePair<string, string>> results = new();
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(bResultsFullGroupDirectory))
throw new NullReferenceException(nameof(bResultsFullGroupDirectory));
Dictionary<string, List<KeyValuePair<string, string>>>? dictionary;
string json = string.Empty;
string[] changesFrom = Array.Empty<string>();
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 bMetadataSingletonFile = Path.Combine(bResultsFullGroupDirectory, "{}", "_ _ _", $"{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(bMetadataSingletonFile))
{
File.Move(parentCheck, fileInfo.FullName);
fileInfo.Refresh();
fileInfo.MoveTo(bMetadataSingletonFile);
fileInfo = new(bMetadataSingletonFile);
}
}
else
{
if (File.Exists(bMetadataSingletonFile))
fileInfo = new(bMetadataSingletonFile);
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 (_ForceMetadataLastWriteTimeToCreationTime && !fileInfo.Exists && File.Exists(Path.ChangeExtension(fileInfo.FullName, ".delete")))