|
|
|
@ -33,7 +33,7 @@ internal abstract class PersonContainer
|
|
|
|
|
return results;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static List<(long?, Models.PersonContainer)> GetPersonContainersCollections(string personBirthdayFormat, string facesFileNameExtension, char[] chars, string personDisplayDirectory, string personDisplayDirectoryName, string[] personKeyDirectories, int? approximateYears, List<Models.PersonBirthday> collections)
|
|
|
|
|
private static List<(long?, Models.PersonContainer)> GetPersonContainersCollections(string personBirthdayFormat, string facesFileNameExtension, char[] chars, string personDisplayDirectory, string personDisplayDirectoryName, string[] personKeyDirectories, int? approximateYears, Models.PersonBirthday[] personBirthdays)
|
|
|
|
|
{
|
|
|
|
|
List<(long?, Models.PersonContainer)> results = new();
|
|
|
|
|
long personKey;
|
|
|
|
@ -43,7 +43,6 @@ internal abstract class PersonContainer
|
|
|
|
|
string personKeyFormatted;
|
|
|
|
|
Models.PersonBirthday? personBirthday;
|
|
|
|
|
Models.PersonContainer personContainer;
|
|
|
|
|
Models.PersonBirthday[] personBirthdays = collections.OrderByDescending(l => l.Value).ToArray();
|
|
|
|
|
string[] personDisplayDirectoryAllFiles = GetFiles(facesFileNameExtension, personDisplayDirectory);
|
|
|
|
|
foreach (string personKeyDirectory in personKeyDirectories)
|
|
|
|
|
{
|
|
|
|
@ -51,7 +50,11 @@ internal abstract class PersonContainer
|
|
|
|
|
personBirthday = IPersonBirthday.GetPersonBirthday(personBirthdayFormat, personKeyFormatted);
|
|
|
|
|
if (personBirthday is null)
|
|
|
|
|
continue;
|
|
|
|
|
if (!IPersonBirthday.IsCounterPersonBirthday(personBirthday) && ((!personKeyDirectory.Contains('#') && (personDisplayDirectoryName.Contains('~') || personDisplayDirectoryName.Contains('#'))) || (personKeyDirectory.Contains('#') && !personDisplayDirectoryName.Contains('#'))))
|
|
|
|
|
throw new NotSupportedException();
|
|
|
|
|
personKey = personBirthdays[zero].Value.Ticks;
|
|
|
|
|
if (personKey != personBirthdays.OrderByDescending(l => l.Value.Ticks).ToArray()[0].Value.Ticks)
|
|
|
|
|
throw new NotSupportedException();
|
|
|
|
|
segments = personDisplayDirectoryName.Split(chars);
|
|
|
|
|
person = IPerson.GetPerson(personKey, segments);
|
|
|
|
|
personContainer = new(approximateYears, person, personBirthdays, personDisplayDirectoryAllFiles, personDisplayDirectoryName, personKey);
|
|
|
|
@ -68,14 +71,46 @@ internal abstract class PersonContainer
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static string? VerifyAge(string personDisplayDirectory, string minusOne, string personDisplayDirectoryName, int? approximateYears, Models.PersonBirthday[] personBirthdays)
|
|
|
|
|
{
|
|
|
|
|
string? result;
|
|
|
|
|
if (approximateYears is null)
|
|
|
|
|
throw new NotSupportedException();
|
|
|
|
|
if (!personBirthdays.Any())
|
|
|
|
|
throw new NotSupportedException();
|
|
|
|
|
const int zero = 0;
|
|
|
|
|
int? updateApproximateYears;
|
|
|
|
|
DateTime dateTime = DateTime.Now;
|
|
|
|
|
TimeSpan timeSpan = new(personBirthdays[zero].Value.Ticks - dateTime.AddYears(-approximateYears.Value).Ticks);
|
|
|
|
|
if (timeSpan.TotalDays < -356)
|
|
|
|
|
updateApproximateYears = approximateYears.Value + 1;
|
|
|
|
|
else if (timeSpan.TotalDays > 356)
|
|
|
|
|
updateApproximateYears = approximateYears.Value - 1;
|
|
|
|
|
else
|
|
|
|
|
updateApproximateYears = null;
|
|
|
|
|
if (updateApproximateYears is null)
|
|
|
|
|
result = null;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
result = Path.Combine(minusOne, $"{personDisplayDirectoryName.Split('^')[0]}^{updateApproximateYears}");
|
|
|
|
|
if (Directory.Exists(result))
|
|
|
|
|
result = null;
|
|
|
|
|
else
|
|
|
|
|
Directory.Move(personDisplayDirectory, result);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static List<(long?, Models.PersonContainer)> GetPersonContainersGroup(string personBirthdayFormat, string facesFileNameExtension, char[] chars, string[] personDisplayDirectories)
|
|
|
|
|
{
|
|
|
|
|
List<(long?, Models.PersonContainer)> results = new();
|
|
|
|
|
string? minusOne;
|
|
|
|
|
int? approximateYears;
|
|
|
|
|
List<string?> changes = new();
|
|
|
|
|
string[] personKeyDirectories;
|
|
|
|
|
string? personDisplayDirectoryName;
|
|
|
|
|
Models.PersonContainer personContainer;
|
|
|
|
|
List<Models.PersonBirthday> collections;
|
|
|
|
|
Models.PersonBirthday[] personBirthdays;
|
|
|
|
|
foreach (string personDisplayDirectory in personDisplayDirectories)
|
|
|
|
|
{
|
|
|
|
|
personDisplayDirectoryName = Path.GetFileName(personDisplayDirectory);
|
|
|
|
@ -83,15 +118,26 @@ internal abstract class PersonContainer
|
|
|
|
|
continue;
|
|
|
|
|
approximateYears = Age.GetApproximateYears(personDisplayDirectoryName, chars);
|
|
|
|
|
personKeyDirectories = Directory.GetDirectories(personDisplayDirectory, "*", SearchOption.TopDirectoryOnly);
|
|
|
|
|
collections = PersonBirthday.GetPersonBirthdays(personBirthdayFormat, personKeyDirectories, personDisplayDirectory);
|
|
|
|
|
if (collections.Any())
|
|
|
|
|
results.AddRange(GetPersonContainersCollections(personBirthdayFormat, facesFileNameExtension, chars, personDisplayDirectory, personDisplayDirectoryName, personKeyDirectories, approximateYears, collections));
|
|
|
|
|
personBirthdays = PersonBirthday.GetDescendingOrderedPersonBirthdays(personBirthdayFormat, personKeyDirectories, personDisplayDirectory);
|
|
|
|
|
if (personDisplayDirectoryName.Contains('^'))
|
|
|
|
|
{
|
|
|
|
|
minusOne = Path.GetDirectoryName(personDisplayDirectory);
|
|
|
|
|
if (minusOne is null)
|
|
|
|
|
continue;
|
|
|
|
|
changes.Add(VerifyAge(personDisplayDirectory, minusOne, personDisplayDirectoryName, approximateYears, personBirthdays));
|
|
|
|
|
}
|
|
|
|
|
if (changes.Any(l => l is not null))
|
|
|
|
|
continue;
|
|
|
|
|
if (personBirthdays.Any())
|
|
|
|
|
results.AddRange(GetPersonContainersCollections(personBirthdayFormat, facesFileNameExtension, chars, personDisplayDirectory, personDisplayDirectoryName, personKeyDirectories, approximateYears, personBirthdays));
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
personContainer = GetPersonContainer(facesFileNameExtension, personDisplayDirectory, personDisplayDirectoryName, approximateYears);
|
|
|
|
|
results.Add(new(null, personContainer));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (changes.Any(l => l is not null))
|
|
|
|
|
throw new NotImplementedException($"A directory was changed restart to look for more! {string.Join(Environment.NewLine, (from l in changes where l is not null select l).ToArray())}");
|
|
|
|
|
return results;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -138,4 +184,22 @@ internal abstract class PersonContainer
|
|
|
|
|
return results;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal static List<(long?, string)> GetDisplay(string personBirthdayFormat, Models.PersonContainer personContainer)
|
|
|
|
|
{
|
|
|
|
|
List<(long?, string)> results = new();
|
|
|
|
|
string personKeyFormatted;
|
|
|
|
|
Models.PersonContainer pc = personContainer;
|
|
|
|
|
if (pc.Person is null || pc.Key is null || pc.Birthdays is null || !pc.Birthdays.Any())
|
|
|
|
|
results.Add(new(pc.Key, string.Concat('\t', pc.Key, '\t', pc.ApproximateYears, '\t', pc.DisplayDirectoryName)));
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
foreach (Models.PersonBirthday personBirthday in pc.Birthdays)
|
|
|
|
|
{
|
|
|
|
|
personKeyFormatted = IPersonBirthday.GetFormatted(personBirthdayFormat, personBirthday);
|
|
|
|
|
results.Add(new(pc.Key, string.Concat(personKeyFormatted, '\t', pc.Key, '\t', pc.ApproximateYears, '\t', pc.DisplayDirectoryName)));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return results;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|