@ -1,9 +1,11 @@
using Humanizer ;
using ShellProgressBar ;
using System.Buffers ;
using System.Collections.ObjectModel ;
using System.Globalization ;
using System.Text.Json ;
using System.Text.RegularExpressions ;
using View_by_Distance.Map.Models.Stateless.Methods ;
using View_by_Distance.Shared.Models ;
using View_by_Distance.Shared.Models.Stateless.Methods ;
using WindowsShortcutFactory ;
@ -13,26 +15,10 @@ namespace View_by_Distance.Map.Models;
public partial class MapLogic : Shared . Models . Methods . IMapLogic
{
private bool IsUsed ( bool ignoreXMatches , int id , ReadOnlyDictionary < int , ReadOnlyCollection < PersonContainer > > ? wholePercentagesToPersonContainers , int wholePercentages )
{
bool result ;
List < int > ? wholePercentagesCollection ;
ReadOnlyCollection < PersonContainer > ? personContainers ;
result = _SkipCollection . TryGetValue ( id , out wholePercentagesCollection ) & & wholePercentagesCollection . Contains ( wholePercentages ) ;
if ( ! result & & wholePercentagesToPersonContainers is not null )
if ( wholePercentagesToPersonContainers . TryGetValue ( wholePercentages , out personContainers ) )
if ( ! ignoreXMatches | | ! personContainers . Any ( l = > IPerson . IsDefaultName ( l ) ) )
result = true ;
return result ;
}
public bool IsUsed ( bool ignoreXMatches , int id , ReadOnlyDictionary < int , ReadOnlyCollection < PersonContainer > > ? wholePercentagesToPersonContainers , MappingFromLocation mappingFromLocation ) = >
IsUsed ( ignoreXMatches , id , wholePercentagesToPersonContainers , mappingFromLocation . WholePercentages ) ;
[GeneratedRegex("[\\\\,\\/,\\:,\\*,\\?,\\\",\\<,\\>,\\|] ")]
private static partial Regex FileSystemSafe ( ) ;
public void SaveContainers ( bool saveIndividually , int? updated , List < SaveContainer > saveContainers )
public void SaveContainers ( int? updated , List < SaveContainer > saveContainers )
{
if ( _Configuration is null )
throw new NullReferenceException ( nameof ( _Configuration ) ) ;
@ -79,7 +65,7 @@ public partial class MapLogic : Shared.Models.Methods.IMapLogic
}
else
continue ;
if ( s aveIndividually)
if ( _Configuration . S aveIndividually)
{
fileName = Path . GetFileName ( checkFile ) ;
if ( distinct . Contains ( fileName ) )
@ -89,7 +75,7 @@ public partial class MapLogic : Shared.Models.Methods.IMapLogic
if ( File . Exists ( checkFile ) )
continue ;
File . Copy ( sourceFile , checkFile ) ;
if ( s aveIndividually)
if ( _Configuration . S aveIndividually)
continue ;
if ( saveContainer . MakeAllHidden )
File . SetAttributes ( checkFile , FileAttributes . Hidden ) ;
@ -148,7 +134,6 @@ public partial class MapLogic : Shared.Models.Methods.IMapLogic
if ( _Configuration is null )
throw new NullReferenceException ( nameof ( _Configuration ) ) ;
int season ;
long personKey ;
string fileName ;
string directory ;
string weekOfYear ;
@ -158,7 +143,7 @@ public partial class MapLogic : Shared.Models.Methods.IMapLogic
List < long > ? personKeys ;
string personKeyFormatted ;
Calendar calendar = new CultureInfo ( "en-US" ) . Calendar ;
ReadOnlyDictionary < int , List < long > > idToPersonKeys = Stateless . Methods . IMapLogic. GetIdToPersonKeys ( personKeyToIds ) ;
ReadOnlyDictionary < int , List < long > > idToPersonKeys = IMapLogic . GetIdToPersonKeys ( personKeyToIds ) ;
foreach ( Mapping mapping in mappingCollection )
{
dateTime = mapping . MappingFromItem . GetDateTimeOriginalThenMinimumDateTime ( ) ;
@ -182,10 +167,9 @@ public partial class MapLogic : Shared.Models.Methods.IMapLogic
continue ;
if ( ! idToPersonKeys . TryGetValue ( mapping . MappingFromItem . Id , out personKeys ) )
continue ;
personKey = mapping . MappingFromPerson . PersonBirthday . Value . Ticks ;
if ( ! personKeys . Contains ( mapping . MappingFromPerson . PersonBirthday . Value . Ticks ) )
if ( ! personKeys . Contains ( mapping . MappingFromPerson . PersonKey ) )
continue ;
personKeyFormatted = IPersonBirthday . GetFormatted ( _Configuration . PersonBirthdayFormat , mapping . MappingFromPerson . PersonBirthda y ) ;
personKeyFormatted = IPersonBirthday . GetFormatted ( _Configuration . PersonBirthdayFormat , mapping . MappingFromPerson . PersonKe y ) ;
directory = Path . Combine ( $"{eDistanceContentDirectory}---" , "Person Key Shortcuts" , personKeyFormatted , directoryName ) ;
fileName = Path . Combine ( directory , $"{mapping.MappingFromItem.ImageFileHolder.Name}.lnk" ) ;
results . Add ( new ( mapping . MappingFromItem . ImageFileHolder . FullName , directory , mapping . MappingFromItem . GetDateTimeOriginalThenMinimumDateTime ( ) , fileName , description , MakeAllHidden : false ) ) ;
@ -399,45 +383,32 @@ public partial class MapLogic : Shared.Models.Methods.IMapLogic
return new ( result , wholePercentagesToPersonContainers ) ;
}
public int UpdateMappingFromPerson ( ReadOnlyCollection < string > ? locationContainersFiles , ReadOnlyDictionary< int , ReadOnlyCollection < PersonContainer > > ? wholePercentagesToPersonContainers , Mapping mapping )
public int UpdateMappingFromPerson ( ReadOnlyDictionary < int , ReadOnlyCollection < PersonContainer > > ? wholePercentagesToPersonContainers , Mapping mapping )
{
int result = 0 ;
long personKey ;
const int zero = 0 ;
string mappingSegmentB ;
PersonBirthday personBirthday ;
ReadOnlyCollection < PersonContainer > ? personContainers ;
for ( int i = 1 ; i < 2 ; i + + )
if ( mapping . MappingFromLocation is not null )
{
if ( mapping . MappingFromLocation is null )
continue ;
if ( wholePercentagesToPersonContainers is null )
{
if ( mapping . MappingFromFilter . InSkipCollection is not null & & mapping . MappingFromFilter . InSkipCollection . Value )
continue ;
result + = 1 ;
continue ;
}
if ( ! wholePercentagesToPersonContainers . TryGetValue ( mapping . MappingFromLocation . WholePercentages , out personContainers ) )
else
{
if ( mapping . MappingFromFilter . InSkipCollection is not null & & mapping . MappingFromFilter . InSkipCollection . Value )
c ontinue ;
result + = 1 ;
continue ;
}
foreach ( PersonContainer p ersonContainer in personContainers )
{
if ( personContainer . Key is null | | p ersonContainer . Birthdays is null | | personContainer . Birthdays . Length = = 0 )
c ontinu e;
personBirthday = personContainer . Birthdays [ zero ] ;
personKey = personBirthday . Value . Ticks ;
mappingSegmentB = Stateless . MapLogic . GetMappingSegmentB ( _Ticks , personBirthday , personC onta iner . ApproximateYears , mapping . MappingFromItem ) ;
if ( locationContainersFiles is null )
if ( mapping . MappingFromPerson is null | | mapping . MappingFromPerson . LocationContainersFiles . Count = = 0 )
locationContainersFiles = new ( Array . Empty < string > ( ) ) ;
else
locationContainersFiles = mapping . MappingFromPerson . LocationContainersFiles ;
mapping . UpdateMappingFromPerson ( locationContainersFiles , personContainer . ApproximateYears , personContainer . DisplayDirectoryName , personBirthday , mappingSegmentB ) ;
ReadOnlyCollection < PersonContainer > ? personContainers ;
if ( ! wholePercentagesToPersonContainers . TryGetValue ( mapping . MappingFromLocation . WholePercentages , out personC onta iners ) )
result + = 1 ;
else
{
const int z ero = 0 ;
string mappingSegmentB ;
P ersonBirthday person Birthday;
foreach ( PersonC onta iner personContainer in personContainers )
{
if ( personContainer . Key is null | | personContainer . Birthdays is null | | personContainer . Birthdays . Length = = 0 )
c ontinu e ;
personBirthday = personContainer . Birthdays [ zero ] ;
mappingSegmentB = Stateless . MapLogic . Get MappingSegmentB ( _Ticks , personBirthday , personContainer . ApproximateYears , mapping . MappingFromItem ) ;
mapping . UpdateMappingFromPerson ( personContainer . ApproximateYears , personContai ner . DisplayDirectoryName , personContainer . Key . Value , mappingSegmentB ) ;
}
}
}
}
return result ;
@ -498,6 +469,55 @@ public partial class MapLogic : Shared.Models.Methods.IMapLogic
return ( ticks , directory ) ;
}
private static bool PreAndPostContinue ( Configuration configuration , ReadOnlyDictionary < int , ReadOnlyDictionary < int , Mapping > > idToWholePercentagesToMapping , Sorting sorting , Mapping mapping , Mapping keyMapping )
{
bool result = true ;
if ( result & & mapping . MappingFromFilterPre . InSkipCollection is not null & & mapping . MappingFromFilterPre . InSkipCollection . Value )
result = false ;
if ( result & & mapping . MappingFromFilterPre . IsFocusModel is not null & & ! mapping . MappingFromFilterPre . IsFocusModel . Value )
result = false ;
if ( result & & mapping . MappingFromFilterPre . IsFocusRelativePath is not null & & ! mapping . MappingFromFilterPre . IsFocusRelativePath . Value )
result = false ;
if ( result & & mapping . MappingFromFilterPost . InSkipCollection is not null & & mapping . MappingFromFilterPost . InSkipCollection . Value )
result = false ;
if ( result & & mapping . MappingFromFilterPost . IsFocusPerson is not null & & ! mapping . MappingFromFilterPost . IsFocusPerson . Value )
result = false ;
if ( result & & keyMapping . MappingFromFilterPost . CanReMap is not null & & ! configuration . ReMap )
result = false ;
if ( result & & keyMapping . MappingFromFilterPost . CanReMap is not null & & ( ! keyMapping . MappingFromFilterPost . CanReMap . Value | | ( mapping . MappingFromPerson is not null & & IPerson . IsDefaultName ( mapping . MappingFromPerson . DisplayDirectoryName ) ) ) )
result = false ;
if ( result & & keyMapping . MappingFromFilterPost . InSkipCollection is not null & & keyMapping . MappingFromFilterPost . InSkipCollection . Value )
result = false ;
if ( result & & keyMapping . MappingFromFilterPost . IsFocusPerson is not null & & keyMapping . MappingFromFilterPost . IsFocusPerson . Value )
result = false ;
return result ;
}
private ( string? , long? , string ) Get ( Configuration configuration , bool saveIndividually , string by , Mapping question , int padLeft )
{
long? ticks ;
string? directory ;
string personDirectory ;
if ( question . MappingFromPerson is null )
{
( ticks , directory ) = GetDirectory ( configuration , saveIndividually , padLeft , question . SegmentC , by , question . MappingFromItem ) ;
personDirectory = directory is null ? string . Empty : Path . Combine ( directory , $"X+{ticks}" ) ;
}
else
{
ticks = null ;
string personKeyFormatted = IPersonBirthday . GetFormatted ( configuration . PersonBirthdayFormat , question . MappingFromPerson . PersonKey ) ;
if ( string . IsNullOrEmpty ( question . SegmentC ) )
directory = Path . Combine ( _EDistanceContentTicksDirectory , by , personKeyFormatted , question . MappingFromPerson . SegmentB ) ;
else if ( saveIndividually )
directory = Path . Combine ( _EDistanceContentTicksDirectory , by , question . SegmentC . PadLeft ( padLeft , '0' ) , personKeyFormatted , question . MappingFromPerson . SegmentB ) ;
else
directory = Path . Combine ( _EDistanceContentTicksDirectory , by , personKeyFormatted , question . MappingFromPerson . SegmentB , question . SegmentC ) ;
personDirectory = Path . Combine ( directory , question . MappingFromPerson . DisplayDirectoryName , "lnk" ) ;
}
return ( directory , ticks , personDirectory ) ;
}
private List < SaveContainer > GetSaveContainers ( string dFacesContentDirectory , string d2FacePartsContentDirectory , string d2FacePartsContentCollectionDirectory , ReadOnlyCollection < Mapping > mappingCollection , ReadOnlyDictionary < int , ReadOnlyDictionary < int , Mapping > > idToWholePercentagesToMapping , ReadOnlyDictionary < long , List < int > > personKeyToIds , int? useFiltersCounter , bool saveMapped , bool saveIndividually , bool sortingContainersAny )
{
if ( _Configuration is null )
@ -506,20 +526,17 @@ public partial class MapLogic : Shared.Models.Methods.IMapLogic
string by ;
long? ticks ;
List < int > ? ids ;
long personKey ;
bool isByMapping ;
bool isBySorting ;
Sorting ? sorting ;
string checkFile ;
string? directory ;
Mapping ? question ;
string shortcutFile ;
Mapping ? keyMapping ;
string facesDirectory ;
string? directoryName ;
string personDirectory ;
FileHolder faceFileHolder ;
string facePartsDirectory ;
string personKeyFormatted ;
List < int > distinct = new ( ) ;
SaveContainer ? saveContainer ;
FileHolder facePartsFileHolder ;
FileHolder hiddenFaceFileHolder ;
@ -530,82 +547,62 @@ public partial class MapLogic : Shared.Models.Methods.IMapLogic
{
if ( mapping . MappingFromLocation is null )
continue ;
directoryName = Path . GetDirectoryName ( mapping . MappingFromItem . RelativePath ) ;
if ( directoryName is null )
throw new N otSupportedException ( ) ;
if ( mapping . MappingFromFilter . InSkipCollection is not null & & mapping . MappingFromFilter . InSkipCollection . Val ue)
if ( mapping . MappingFromFilterPre . InSkipCollection is not null & & mapping . MappingFromFilterPre . InSkipCollection . Value )
continue ;
if ( mapping . MappingFromFilterPre . IsFocusModel is n ot null & & ! mapping . MappingFromFilterPre . IsFocusModel . Value )
contin ue ;
if ( mapping . MappingFromFilterPre . IsFocusRelativePath is not null & & ! mapping . MappingFromFilterPre . IsFocusRelativePath . Value )
continue ;
if ( mapping . MappingFromFilterPost . InSkipCollection is not null & & mapping . MappingFromFilterPost . InSkipCollection . Value )
continue ;
if ( mapping . MappingFromFilterPost . IsFocusPerson is not null & & ! mapping . MappingFromFilterPost . IsFocusPerson . Value )
continue ;
( by , isByMapping , isBySorting ) = Stateless . MapLogic . Get ( useFiltersCounter , saveIndividually , sortingContainersAny , forceSingleImageHumanized , mapping ) ;
if ( isByMapping & & ! saveMapped )
continue ;
if ( mapping . MappingFromPerson is null )
{
if ( ! _Configuration . SaveSortingWithoutPerson )
continue ;
if ( mapping . SortingContainer is null )
{
if ( sortingContainersAny )
continue ;
mapping . UpdateMappingFromUnknownPerson ( saveIndividually , new ( mapping , new ( mapping , mapping . MappingFromLocation ) ) ) ;
if ( mapping . SortingContainer is null )
continue ;
}
if ( distinct . Contains ( mapping . MappingFromItem . Id ) )
continue ;
if ( distinct . Contains ( mapping . SortingContainer . Sorting . Id ) )
continue ;
( ticks , directory ) = GetDirectory ( _Configuration , saveIndividually , padLeft , mapping . SegmentC , by , mapping . MappingFromItem ) ;
if ( ticks is null | | string . IsNullOrEmpty ( directory ) )
continue ;
personDirectory = Path . Combine ( directory , $"X+{ticks}" ) ;
if ( saveIndividually )
{
directory = Path . Combine ( directory , mapping . MappingFromItem . Id . ToString ( ) ) ;
results . Add ( new ( Path . Combine ( directory , $"X+{ticks}" ) ) ) ;
}
distinct . Add ( mapping . MappingFromItem . Id ) ;
distinct . Add ( mapping . SortingContainer . Sorting . Id ) ;
}
if ( ! isBySorting | | mapping . SortingContainer is null )
( sorting , question ) = ( null , null ) ;
else
{
if ( string . IsNullOrEmpty ( mapping . MappingFromPerson . SegmentB ) )
sorting = mapping . SortingContainer . Sorting ;
if ( ! idToWholePercentagesToMapping . TryGetValue ( sorting . Id , out wholePercentagesToMapping ) )
throw new NotSupportedException ( ) ;
if ( string . IsNullOrEmpty ( mapp ing. MappingFromPerson . DisplayDirectoryName ) )
if ( ! wholePercentagesToMapping . TryGetValue ( sort ing. WholePercentages , out question ) )
throw new NotSupportedException ( ) ;
personKey = mapping . MappingFromPerson . PersonBirthday . Value . Ticks ;
personKeyFormatted = IPersonBirthday . GetFormatted ( _Configuration . PersonBirthdayFormat , mapping . MappingFromPerson . PersonBirthday ) ;
if ( string . IsNullOrEmpty ( mapping . SegmentC ) )
directory = Path . Combine ( _EDistanceContentTicks Directory , by , personKeyFormatted , mapping . MappingFromPerson . SegmentB ) ;
else if ( saveIndividually )
directory = Path . Combine ( _EDistanceContentTicksDirectory , by , mapping . SegmentC . PadLeft ( padLeft , '0' ) , personKeyFormatted , mapping . MappingFromPerson . SegmentB ) ;
else
directory = Path . Combine ( _EDistanceContentTicksDirectory , by , personKeyFormatted , mapping . MappingFromPerson . SegmentB , mapping . SegmentC ) ;
if ( isByMapping )
personDirectory = Path . Combine ( directory , mapping . MappingFromPerson . DisplayDirectoryName ) ;
else if ( mapping . By is not null )
personDirectory = Path . Combine ( directory , mapping . MappingFromPerson . DisplayDirectoryName , "lnk" ) ;
else
personDirectory = Path . Combine ( directory , mapping . MappingFromPerson . DisplayDirectoryName [ . . 1 ] , "lnk" ) ;
if ( ! PreAndPostContinue ( _Configuration , idToWholePercentagesToMapping , sorting , mapping , question ) )
continue ;
}
( directory , ticks , person Directory) = Get ( _Configuration , saveIndividually , by , mapping , padLeft ) ;
if ( string . IsNullOrEmpty ( directory ) )
throw new NotSupportedException ( ) ;
if ( mapping . MappingFromPerson is not null )
{
if ( saveIndividually )
{
directory = Path . Combine ( directory , mapping . MappingFromItem . Id . ToString ( ) ) ;
results . Add ( new ( Path . Combine ( directory , mapping . MappingFromPerson . DisplayDirectoryName ) ) ) ;
}
if ( isByMapping & & personKeyToIds . TryGetValue ( p ersonKey, out ids ) )
if ( isByMapping & & personKeyToIds . TryGetValue ( mapping . MappingFromPerson . P ersonKey, out ids ) )
results . Add ( new ( Path . Combine ( directory , mapping . MappingFromPerson . DisplayDirectoryName , $"{ids.Count} Face(s)" ) ) ) ;
}
results . Add ( new ( personDirectory ) ) ;
if ( ! isBySorting | | mapping . SortingContainer is null )
keyMapping = null ;
else
{
if ( ! idToWholePercentagesToMapping . TryGetValue ( mapping . SortingContainer . Sorting . Id , out wholePercentagesToMapping ) )
if ( ! _Configuration . SaveSortingWithoutPerson )
continue ;
if ( ! wholePercentagesToMapping . TryGetValue ( mapping . SortingContainer . Sorting . WholePercentages , out keyMapping ) )
if ( ticks is null )
continue ;
if ( keyMapping . MappingFromLocation is nu ll)
if ( saveIndividua lly )
{
directory = Path . Combine ( directory , mapping . MappingFromItem . Id . ToString ( ) ) ;
results . Add ( new ( Path . Combine ( directory , $"X+{ticks}" ) ) ) ;
}
}
results . Add ( new ( personDirectory ) ) ;
if ( question is not null )
{
if ( question . MappingFromLocation is null )
continue ;
if ( saveIndividually & & keyMapping . MappingFromLocation . WholePercentages = = mapping . MappingFromLocation . WholePercentages )
if ( saveIndividually & & question . MappingFromLocation . WholePercentages = = mapping . MappingFromLocation . WholePercentages )
results . Add ( new ( Path . Combine ( directory , "Maybe" ) ) ) ;
}
facesDirectory = Stateless . MapLogic . GetFacesDirectory ( _PropertyConfiguration , dFacesContentDirectory , mapping . MappingFromItem ) ;
@ -633,43 +630,12 @@ public partial class MapLogic : Shared.Models.Methods.IMapLogic
hiddenFaceFileHolder = new ( Path . Combine ( facesDirectory , $"{mapping.MappingFromLocation.DeterministicHashCodeKey}{mapping.MappingFromItem.ImageFileHolder.ExtensionLowered}{_Configuration.FacesHiddenFileNameExtension}" ) ) ;
facePartsFileHolder = new ( Path . Combine ( facePartsDirectory , $"{mapping.MappingFromLocation.DeterministicHashCodeKey}{mapping.MappingFromItem.ImageFileHolder.ExtensionLowered}{_Configuration.FacePartsFileNameExtension}" ) ) ;
saveContainer = new ( checkFile , directory , faceFileHolder , hiddenFaceFileHolder , facePartsFileHolder , mapping . MappingFromItem . ResizedFileHolder , shortcutFile ) ;
if ( ! isByMapping & & mapping . By is not null & & mapping . MappingFromPerson ? . LocationContainersFiles . Count > 0 & & IPerson . IsDefaultName ( mapping . MappingFromPerson ) )
results . Add ( new ( Path . GetDirectoryName ( personDirectory ) ? ? personDirectory , mapping . MappingFromPerson . LocationContainersFiles [ 0 ] ) ) ;
}
results . Add ( saveContainer ) ;
if ( ! isBySorting | | mapping . SortingContainer is null | | keyMapping is null )
continue ;
if ( ! saveIndividually & & isBySorting & & mapping . MappingFromPerson is null )
{
saveContainer = GetMatchSaveContainer ( dFacesContentDirectory , d2FacePartsContentDirectory , directory , keyMapping ) ;
if ( saveContainer is not null )
results . Add ( saveContainer ) ;
}
if ( ! saveIndividually )
saveContainer = Stateless . MapLogic . GetDebugSaveContainer ( directory , mapping . MappingFromPerson , mapping . SortingContainer , keyMapping ) ;
else
{
( saveContainer , SaveContainer ? extraSaveContainer ) = Stateless . MapLogic . GetContainers ( _Configuration . FacesFileNameExtension , _Configuration . FacePartsFileNameExtension , _PropertyConfiguration , dFacesContentDirectory , d2FacePartsContentCollectionDirectory , directory , mapping . SortingContainer , keyMapping ) ;
if ( saveContainer is null | | extraSaveContainer is null )
continue ;
results . Add ( extraSaveContainer ) ;
}
results . Add ( saveContainer ) ;
}
return results ;
}
public List < SaveContainer > GetSaveContainers ( bool saveIndividually , string dFacesContentDirectory , string d2FacePartsContentDirectory , string d2FacePartsContentCollectionDirectory , ReadOnlyCollection < Mapping > mappingCollection , ReadOnlyDictionary < int , ReadOnlyDictionary < int , Mapping > > idToWholePercentagesToMapping , int? useFiltersCounter , bool sortingContainersAny )
{
if ( _Configuration is null )
throw new NullReferenceException ( nameof ( _Configuration ) ) ;
List < SaveContainer > results ;
bool saveMapped = false ;
ReadOnlyDictionary < long , List < int > > personKeyToIds = new ( new Dictionary < long , List < int > > ( ) ) ;
results = GetSaveContainers ( dFacesContentDirectory , d2FacePartsContentDirectory , d2FacePartsContentCollectionDirectory , mappingCollection , idToWholePercentagesToMapping , personKeyToIds , useFiltersCounter , saveMapped , saveIndividually , sortingContainersAny ) ;
return results ;
}
public void SaveMapped ( string dFacesContentDirectory , string d2FacePartsContentDirectory , string d2FacePartsContentCollectionDirectory , ReadOnlyDictionary < long , List < int > > personKeyToIds , ReadOnlyCollection < Mapping > mappingCollection , ReadOnlyDictionary < int , ReadOnlyDictionary < int , Mapping > > idToWholePercentagesToMapping )
{
if ( _Configuration is null )
@ -677,42 +643,55 @@ public partial class MapLogic : Shared.Models.Methods.IMapLogic
int? updated = null ;
bool saveMapped = true ;
int? useFiltersCounter = null ;
bool saveIndividually = false ;
string mappingDirectory = Path . Combine ( _EDistanceContentTicksDirectory , nameof ( Shared . Models . Stateless . IMapLogic . Mapping ) ) ;
List < SaveContainer > saveContainers = GetSaveContainers ( dFacesContentDirectory , d2FacePartsContentDirectory , d2FacePartsContentCollectionDirectory , mappingCollection , idToWholePercentagesToMapping , personKeyToIds , useFiltersCounter , saveMapped , sortingContainersAny : true , saveIndividually : false ) ;
SaveContainers ( saveIndividually , updated, saveContainers ) ;
SaveContainers ( updated , saveContainers ) ;
if ( ! string . IsNullOrEmpty ( _EDistanceContentTicksDirectory ) & & Directory . Exists ( mappingDirectory ) )
Stateless . MapLogic . SaveMappingShortcuts ( mappingDirectory ) ;
}
public List < Sorting > GetSortingCollection ( int i , FaceDistance faceDistanceEncoding , Face face , List < FaceDistance > faceDistanceLengths )
public List < Sorting > GetSortingCollection ( int i , Face face , FaceDistance faceDistanceEncoding , List < FaceDistance > faceDistanceLengths )
{
if ( _Configuration is null )
throw new NullReferenceException ( nameof ( _Configuration ) ) ;
List < Sorting > results = new ( ) ;
Sorting sorting ;
FaceDistance faceDistanceLength ;
List < int > ? wholePercentagesCollection ;
bool skipNotSkipCollectionAny = _SkipNotSkipCollection . Count > 0 ;
for ( int j = 0 ; j < faceDistanceLengths . Count ; j + + )
{
if ( faceDistanceEncoding . WholePercentages is null )
throw new NotSupportedException ( ) ;
if ( face . Mapping ? . MappingFromFilter is null )
if ( face . Mapping ? . MappingFromFilterPost is null )
throw new NotSupportedException ( ) ;
if ( j = = i )
continue ;
if ( faceDistanceEncoding . Id is not null & & _SkipCollection . TryGetValue ( faceDistanceEncoding . Id . Value , out wholePercentagesCollection ) & & wholePercentagesCollection . Conta ins ( faceDistanceEncoding . WholePercentages . Value ) )
continue ;
if ( faceDistanceEncoding . Id is not null & & skipNotSkipCollectionAny & & ( ! _SkipNotSkipCollection . TryGetValue ( faceDistanceEncoding . Id . Value , out wholePercentagesCollection ) | | ! wholePercentagesCollection . Contains ( faceDistanceEncoding . WholePercentages . Value ) ) )
continue ;
if ( face . Mapping . MappingFromFilter . IsUsed is not null & & face . Mapping . MappingFromFilter . IsUsed . Value )
continue ;
if ( face. Mapping . MappingFromFilterPre . InSkipCollection is not null & & face . Mapp ing . MappingFromFilterPre . InSkipCollection . Value )
throw new NotSupportedException ( nameof ( Shared . Models . Methods . IDistance < object > ) ) ;
if ( face. Mapping . MappingFromFilterPre . IsFocusModel is not null & & face . Mapping . MappingFromFilterPre . IsFocusModel . Value )
throw new NotSupportedException ( nameof ( Shared . Models . Methods . IDistance < object > ) ) ;
if ( face . Mapping . MappingFromFilterPre . IsFocusRelativePath is not null & & face . Mapping . MappingFromFilterPre . IsFocusRelativePath . Value )
throw new NotSupportedException ( nameof ( Shared . Models . Methods . IDistance < object > ) ) ;
if ( face . Mapping . MappingFromFilterPost . InSkipCollection is not null & & face . Mapping . MappingFromFilterPost . InSkipCollection . Value )
throw new NotSupportedException ( nameof ( Shared . Models . Methods . IDistance < object > ) ) ;
if ( face . Mapping . MappingFromFilterPost . IsFocusPerson is not null & & ! face . Mapping . MappingFromFilterPost . IsFocusPerson . Value )
throw new NotSupportedException ( nameof ( Shared . Models . Methods . IDistance < object > ) ) ;
if ( face . Mapping . MappingFromFilterPost . InSkipCollection is not null & & face . Mapping . MappingFromFilterPost . InSkipCollection . Value )
throw new NotSupportedException ( nameof ( Shared . Models . Methods . IDistance < object > ) ) ;
faceDistanceLength = faceDistanceLengths [ j ] ;
if ( faceDistanceLength . WholePercentages is null | | faceDistanceLength . Length is null )
throw new NotSupportedException ( ) ;
if ( faceDistanceLength . Length = = 0 )
continue ;
if ( faceDistanceLength . MappingFromFilterPost is null )
throw new NotSupportedException ( ) ;
if ( faceDistanceLength . MappingFromFilterPost . CanReMap is not null & & ! _Configuration . ReMap )
continue ;
if ( faceDistanceLength . MappingFromFilterPost . CanReMap is not null & & ! faceDistanceLength . MappingFromFilterPost . CanReMap . Value )
continue ;
if ( faceDistanceLength . MappingFromFilterPost . InSkipCollection is not null & & faceDistanceLength . MappingFromFilterPost . InSkipCollection . Value )
continue ;
if ( faceDistanceLength . MappingFromFilterPost . IsFocusPerson is not null & & ! faceDistanceLength . MappingFromFilterPost . IsFocusPerson . Value )
continue ;
sorting = ISorting . Get ( _Configuration . FaceDistancePermyriad , faceDistanceEncoding , faceDistanceLength ) ;
if ( sorting . DistancePermyriad = = 0 )
continue ;
@ -727,7 +706,49 @@ public partial class MapLogic : Shared.Models.Methods.IMapLogic
return results ;
}
public int UpdateFromSortingContainers ( bool saveIndividuall y, ReadOnlyDictionary < int , ReadOnlyDictionary < int , Mapping > > idToWholePercentagesToMapping , Shared . Models . Methods . IDistanceLimits distanceLimits , SortingContainer [ ] sortingContainers )
public int UpdateFromSortingContainers ( string dFacesContentDirectory , string d2FacePartsContentDirectory , string d2FacePartsContentCollectionDirector y, ReadOnlyDictionary < int , ReadOnlyDictionary < int , Mapping > > idToWholePercentagesToMapping , ReadOnlyCollection < SortingContainer > sortingContainers )
{
if ( _Configuration is null )
throw new NullReferenceException ( nameof ( _Configuration ) ) ;
int result = 0 ;
string key ;
string segmentB ;
string? segmentC ;
string personKeyFormatted ;
MappingFromPerson mappingFromPerson ;
Dictionary < string , int > keyToCount = new ( ) ;
foreach ( SortingContainer sortingContainer in sortingContainers )
{
if ( sortingContainer . Question is null )
throw new NotSupportedException ( ) ;
if ( sortingContainer . Source . MappingFromPerson is null )
{
sortingContainer . Question . UpdateMappingFromUnknownPerson ( _Configuration . SaveIndividually , sortingContainer ) ;
result + = 1 ;
}
else
{
mappingFromPerson = sortingContainer . Source . MappingFromPerson ;
personKeyFormatted = IPersonBirthday . GetFormatted ( _Configuration . PersonBirthdayFormat , mappingFromPerson . PersonKey ) ;
segmentB = IMapLogic . GetDecade ( sortingContainer . Question . MappingFromItem ) ;
key = string . Concat ( personKeyFormatted , '\t' , segmentB ) ;
if ( ! keyToCount . ContainsKey ( key ) )
keyToCount . Add ( key , new ( ) ) ;
if ( ! keyToCount . ContainsKey ( key ) )
keyToCount . Add ( key , 0 ) ;
keyToCount [ key ] + + ;
if ( ! _Configuration . SaveIndividually & & keyToCount [ key ] < _Configuration . SortingMaximumPerKey )
segmentC = null ;
else
segmentC = sortingContainer . Sorting . DistancePermyriad . ToString ( ) ;
sortingContainer . Question . UpdateMappingFromPerson ( mappingFromPerson . ApproximateYears , mappingFromPerson . DisplayDirectoryName , mappingFromPerson . PersonKey , segmentB , segmentC , sortingContainer ) ;
result + = 1 ;
}
}
return result ;
}
public List < SaveContainer > GetSaveContainers ( string dFacesContentDirectory , string d2FacePartsContentDirectory , string d2FacePartsContentCollectionDirectory , ReadOnlyDictionary < int , ReadOnlyDictionary < int , Mapping > > idToWholePercentagesToMapping , Shared . Models . Methods . IDistanceLimits distanceLimits , int? useFiltersCounter , ReadOnlyCollection < SortingContainer > sortingContainers )
{
if ( _Configuration is null )
throw new NullReferenceException ( nameof ( _Configuration ) ) ;
@ -736,91 +757,173 @@ public partial class MapLogic : Shared.Models.Methods.IMapLogic
string counts = distanceLimits . GetCounts ( ) ;
_ = Directory . CreateDirectory ( Path . Combine ( _EDistanceContentTicksDirectory , counts ) ) ;
}
int result = 0 ;
string ke y;
Mapping ? mapping ;
const int zero = 0 ;
string mappingSegmentB ;
string personKeyFormatted ;
PersonBirthday personBirthda y;
List < int > ? w holePercentagesCollectionForA ;
List < int > ? wholePercentagesCollectionF orB ;
Dictionary < string , int > keyToCount = new ( ) ;
Dictionary < string , string > keyToSegmentC = new ( ) ;
ReadOnlyCollection < PersonContainer > ? personContainers ;
ReadOnlyDictionary < int , Mapping > ? wholePercentagesToMapping ;
Dictionary < int , List < int > > idToWholePercentagesCollectionForA = new ( ) ;
Dictionary < int , List < int > > idToWholePercentagesCollectionForB = new ( ) ;
int totalSeconds = ( int ) Math . Floor ( new TimeSpan ( DateTime . Now . Ticks - _Ticks ) . TotalSeconds ) ;
ReadOnlyDictionary < int , ReadOnlyCollection < PersonContainer > > ? wholePercentagesToPersonContainers ;
string message = $") {sortingContainers.Length:000} Update From Sorting Container(s) - {totalSeconds} total second(s)" ;
ProgressBarOptions options = new ( ) { ProgressCharacter = '─' , ProgressBarOnBottom = true , DisableBottomPercentage = true } ;
using ProgressBar progressBar = new ( sortingContainers . Length , message , options ) ;
List < SaveContainer > results = new ( ) ;
string b y;
long? ticks ;
bool isBySorting ;
string checkFile ;
Mapping ? question ;
string? director y;
string s hortcutFile ;
string facesDirect ory ;
string personDirectory ;
bool isCounterPersonYear ;
string facePartsDirectory ;
FileHolder ? faceFileHolder ;
SaveContainer ? saveContainer ;
FileHolder ? facePartsFileHolder ;
FileHolder ? hiddenFaceFileHolder ;
int padLeft = _Configuration . FaceDistancePermyriad . ToString ( ) . Length ;
string forceSingleImageHumanized = nameof ( Shared . Models . Stateless . IMapLogic . ForceSingleImage ) . Humanize ( LetterCasing . Title ) ;
foreach ( SortingContainer sortingContainer in sortingContainers )
{
progressBar . Tick ( ) ;
if ( sortingContainer . Mapping ? . MappingFromLocation is null )
if ( sortingContainer . Question is null )
throw new NotSupportedException ( ) ;
if ( ! idToWholePercentagesCollectionForA . TryGetValue ( sortingContainer . Mapping . MappingFromItem . Id , out wholePercentagesCollectionForA ) )
isCounterPersonYear = sortingContainer . Source . MappingFromPerson is not null & & IPersonBirthday . IsCounterPersonYear ( sortingContainer . Source . MappingFromPerson . PersonKey ) ;
( by , _ , isBySorting ) = Stateless . MapLogic . Get ( useFiltersCounter , _Configuration . SaveIndividually , sortingContainers . Count > 0 , forceSingleImageHumanized , sortingContainer . Question ) ;
question = sortingContainer . Question . MappingFromPerson is null ? sortingContainer . Source : sortingContainer . Question ;
if ( question is null )
throw new NotSupportedException ( ) ;
if ( question . MappingFromLocation is null )
continue ;
( directory , ticks , personDirectory ) = Get ( _Configuration , _Configuration . SaveIndividually , by , question , padLeft ) ;
if ( string . IsNullOrEmpty ( directory ) )
throw new NotSupportedException ( ) ;
if ( question . MappingFromPerson is not null )
{
idToWholePercentagesCollectionForA . Add ( sortingContainer . Mapping . MappingFromItem . Id , new ( ) ) ;
if ( ! idToWholePercentagesCollectionForA . TryGetValue ( sortingContainer . Mapping . MappingFromItem . Id , out wholePercentagesCollectionForA ) )
throw new Exception ( ) ;
}
if ( ! idToWholePercentagesCollectionForB . TryGetValue ( sortingContainer . Mapping . MappingFromItem . Id , out wholePercentagesCollectionForB ) )
{
idToWholePercentagesCollectionForB . Add ( sortingContainer . Mapping . MappingFromItem . Id , new ( ) ) ;
if ( ! idToWholePercentagesCollectionForB . TryGetValue ( sortingContainer . Mapping . MappingFromItem . Id , out wholePercentagesCollectionForB ) )
throw new Exception ( ) ;
}
if ( ! _IdThenWholePercentagesToPersonContainers . TryGetValue ( sortingContainer . Sorting . Id , out wholePercentagesToPersonContainers ) | | ! wholePercentagesToPersonContainers . TryGetValue ( sortingContainer . Sorting . WholePercentages , out personContainers ) )
{
if ( ! _Configuration . SaveSortingWithoutPerson )
continue ;
if ( wholePercentagesCollectionForA . Contains ( sortingContainer . Mapping . MappingFromLocation . WholePercentages ) )
continue ;
sortingContainer . Mapping . UpdateMappingFromUnknownPerson ( saveIndividually , sortingContainer ) ;
wholePercentagesCollectionForA . Add ( sortingContainer . Mapping . MappingFromLocation . WholePercentages ) ;
result + = 1 ;
if ( _Configuration . SaveIndividually )
{
directory = Path . Combine ( directory , question . MappingFromItem . Id . ToString ( ) ) ;
results . Add ( new ( Path . Combine ( directory , question . MappingFromPerson . DisplayDirectoryName ) ) ) ;
}
}
else
{
if ( wholePercentagesCollectionForB . Contains ( sortingContainer . Mapping . MappingFromLocation . WholePercentages ) )
if ( ! _ Configuration . SaveSortingWithoutPerson )
throw new NotSupportedException ( ) ;
if ( ticks is null )
continue ;
foreach ( PersonContainer personContainer in personContainers )
if ( _Configuration . SaveIndividually )
{
if ( personContainer . Key is null | | personConta iner . B irthdays is null | | personContainer . Birthdays . Length = = 0 )
continue ;
personBirthday = personContainer . Birthdays [ zero ] ;
personKeyFormatted = IPersonBirthday . GetFormatted ( _Configuration . PersonBirthdayFormat , personBirthday ) ;
mappingSegmentB = Stateless . MapLogic . GetMappingSegmentB ( _Ticks , personBirthday , personContainer . ApproximateYears , sortingContainer . Mapping . MappingFromItem ) ;
key = string . Concat ( personKeyFormatted , '\t' , mappingSegmentB ) ;
if ( ! keyToCount . ContainsKey ( key ) )
keyToCount . Add ( key , new ( ) ) ;
if ( ! keyToCount . ContainsKey ( key ) )
keyToCount . Add ( key , 0 ) ;
if ( ! keyToSegmentC . ContainsKey ( key ) )
keyToSegmentC . Add ( key , string . Empty ) ;
keyToCount [ key ] + + ;
if ( saveIndividually | | keyToCount [ key ] > _Configuration . SortingMaximumPerKey )
{
keyToCount [ key ] = 0 ;
keyToSegmentC [ key ] = sortingContainer . Sorting . DistancePermyriad . ToString ( ) ;
}
if ( ! idToWholePercentagesToMapping . TryGetValue ( sortingContainer . Sorting . Id , out wholePercentagesToMapping ) )
continue ;
if ( ! wholePercentagesToMapping . TryGetValue ( sortingContainer . Sorting . WholePercentages , out mapping ) )
continue ;
if ( mapping . MappingFromPerson is null )
continue ;
sortingContainer . Mapping . UpdateMappingFromPerson ( personContainer . ApproximateYears , personContainer . DisplayDirectoryName , personBirthday , mappingSegmentB , keyToSegmentC [ key ] , sortingContainer , mapping . MappingFromPerson . LocationContainersFiles ) ;
wholePercentagesCollectionForB . Add ( sortingContainer . Mapping . MappingFromLocation . WholePercentages ) ;
result + = 1 ;
break ;
directory = Path . Comb ine( d irectory , question . MappingFromItem . Id . ToString ( ) ) ;
results . Add ( new ( Path . Combine ( directory , $"X+{ticks}" ) ) ) ;
}
}
results . Add ( new ( personDirectory ) ) ;
if ( _Configuration . SaveIndividually & & question . MappingFromLocation . WholePercentages = = question . MappingFromLocation . WholePercentages )
results . Add ( new ( Path . Combine ( directory , "Maybe" ) ) ) ;
facesDirectory = Stateless . MapLogic . GetFacesDirectory ( _PropertyConfiguration , dFacesContentDirectory , question . MappingFromItem ) ;
faceFileHolder = new ( Path . Combine ( facesDirectory , $"{question.MappingFromLocation.DeterministicHashCodeKey}{question.MappingFromItem.ImageFileHolder.ExtensionLowered}{_Configuration.FacesFileNameExtension}" ) ) ;
facePartsDirectory = Stateless . MapLogic . GetFacePartsDirectory ( _PropertyConfiguration , d2FacePartsContentDirectory , question . MappingFromItem ) ;
shortcutFile = Path . Combine ( personDirectory , $"{question.MappingFromLocation.DeterministicHashCodeKey}{question.MappingFromItem.ImageFileHolder.ExtensionLowered}.lnk" ) ;
checkFile = Path . Combine ( directory , $"{question.MappingFromLocation.DeterministicHashCodeKey}{question.MappingFromItem.ImageFileHolder.ExtensionLowered}" ) ;
hiddenFaceFileHolder = new ( Path . Combine ( facesDirectory , $"{question.MappingFromLocation.DeterministicHashCodeKey}{question.MappingFromItem.ImageFileHolder.ExtensionLowered}{_Configuration.FacesHiddenFileNameExtension}" ) ) ;
facePartsFileHolder = new ( Path . Combine ( facePartsDirectory , $"{question.MappingFromLocation.DeterministicHashCodeKey}{question.MappingFromItem.ImageFileHolder.ExtensionLowered}{_Configuration.FacePartsFileNameExtension}" ) ) ;
saveContainer = new ( checkFile , directory , faceFileHolder , hiddenFaceFileHolder , facePartsFileHolder , question . MappingFromItem . ResizedFileHolder , shortcutFile ) ;
results . Add ( saveContainer ) ;
if ( ! _Configuration . SaveIndividually & & isBySorting & & question . MappingFromPerson is null )
{
saveContainer = GetMatchSaveContainer ( dFacesContentDirectory , d2FacePartsContentDirectory , directory , question ) ;
if ( saveContainer is not null )
results . Add ( saveContainer ) ;
}
if ( ! _Configuration . SaveIndividually )
saveContainer = Stateless . MapLogic . GetDebugSaveContainer ( sortingContainer , directory , question ) ;
else
{
( saveContainer , SaveContainer ? extraSaveContainer ) = Stateless . MapLogic . GetContainers ( _Configuration . FacesFileNameExtension , _Configuration . FacePartsFileNameExtension , _PropertyConfiguration , dFacesContentDirectory , d2FacePartsContentCollectionDirectory , directory , question ) ;
if ( saveContainer is null | | extraSaveContainer is null )
continue ;
results . Add ( extraSaveContainer ) ;
}
results . Add ( saveContainer ) ;
}
return result ;
return results ;
}
public ReadOnlyCollection < SortingContainer > GetFilterSortingContainers ( string dFacesContentDirectory , string d2FacePartsContentDirectory , string d2FacePartsContentCollectionDirectory , ReadOnlyDictionary < int , ReadOnlyDictionary < int , Mapping > > idToWholePercentagesToMapping , Shared . Models . Methods . IDistanceLimits distanceLimits , ReadOnlyCollection < SortingContainer > sortingContainers )
{
if ( _Configuration is null )
throw new NullReferenceException ( nameof ( _Configuration ) ) ;
if ( distanceLimits is not null )
{
string counts = distanceLimits . GetCounts ( ) ;
_ = Directory . CreateDirectory ( Path . Combine ( _EDistanceContentTicksDirectory , counts ) ) ;
}
List < SortingContainer > results = new ( ) ;
Sorting sorting ;
Mapping ? keyMapping ;
List < int > ? wholePercentagesCollection ;
MappingFromFilterPre mappingFromFilterPre ;
Dictionary < string , int > keyToCount = new ( ) ;
MappingFromFilterPost mappingFromFilterPost ;
ReadOnlyCollection < PersonContainer > ? personContainers ;
ReadOnlyDictionary < int , Mapping > ? wholePercentagesToMapping ;
Dictionary < int , List < int > > idToWholePercentagesCollection = new ( ) ;
int totalSeconds = ( int ) Math . Floor ( new TimeSpan ( DateTime . Now . Ticks - _Ticks ) . TotalSeconds ) ;
ReadOnlyDictionary < int , ReadOnlyCollection < PersonContainer > > ? wholePercentagesToPersonContainers ;
string message = $") {sortingContainers.Count:000} Filter Sorting Container(s) - {totalSeconds} total second(s)" ;
ProgressBarOptions options = new ( ) { ProgressCharacter = '─' , ProgressBarOnBottom = true , DisableBottomPercentage = true } ;
using ProgressBar progressBar = new ( sortingContainers . Count , message , options ) ;
foreach ( SortingContainer sortingContainer in sortingContainers )
{
progressBar . Tick ( ) ;
if ( sortingContainer . Source ? . MappingFromLocation is null )
throw new NotSupportedException ( ) ;
mappingFromFilterPre = sortingContainer . Source . MappingFromFilterPre ;
mappingFromFilterPost = sortingContainer . Source . MappingFromFilterPost ;
if ( sortingContainer . Source . MappingFromFilterPre . InSkipCollection is not null & & sortingContainer . Source . MappingFromFilterPre . InSkipCollection . Value )
throw new NotSupportedException ( nameof ( GetSortingCollection ) ) ;
if ( sortingContainer . Source . MappingFromFilterPre . IsFocusModel is not null & & sortingContainer . Source . MappingFromFilterPre . IsFocusModel . Value )
throw new NotSupportedException ( nameof ( GetSortingCollection ) ) ;
if ( sortingContainer . Source . MappingFromFilterPre . IsFocusRelativePath is not null & & sortingContainer . Source . MappingFromFilterPre . IsFocusRelativePath . Value )
throw new NotSupportedException ( nameof ( GetSortingCollection ) ) ;
if ( sortingContainer . Source . MappingFromFilterPost . InSkipCollection is not null & & sortingContainer . Source . MappingFromFilterPost . InSkipCollection . Value )
throw new NotSupportedException ( nameof ( GetSortingCollection ) ) ;
if ( sortingContainer . Source . MappingFromFilterPost . InSkipCollection is not null & & sortingContainer . Source . MappingFromFilterPost . InSkipCollection . Value )
throw new NotSupportedException ( nameof ( GetSortingCollection ) ) ;
if ( sortingContainer . Source . MappingFromFilterPost . IsFocusPerson is not null & & ! sortingContainer . Source . MappingFromFilterPost . IsFocusPerson . Value )
throw new NotSupportedException ( nameof ( GetSortingCollection ) ) ;
sorting = sortingContainer . Sorting ;
if ( ! idToWholePercentagesToMapping . TryGetValue ( sorting . Id , out wholePercentagesToMapping ) )
throw new NotSupportedException ( ) ;
if ( ! wholePercentagesToMapping . TryGetValue ( sorting . WholePercentages , out keyMapping ) )
throw new NotSupportedException ( ) ;
if ( keyMapping . MappingFromFilterPost . CanReMap is not null & & ! _Configuration . ReMap )
throw new NotSupportedException ( nameof ( GetSortingCollection ) ) ;
if ( keyMapping . MappingFromFilterPost . CanReMap is not null & & ! keyMapping . MappingFromFilterPost . CanReMap . Value )
throw new NotSupportedException ( nameof ( GetSortingCollection ) ) ;
if ( ! PreAndPostContinue ( _Configuration , idToWholePercentagesToMapping , sorting , sortingContainer . Source , keyMapping ) )
continue ;
if ( ! idToWholePercentagesCollection . TryGetValue ( sorting . Id , out wholePercentagesCollection ) )
{
idToWholePercentagesCollection . Add ( sorting . Id , new ( ) ) ;
if ( ! idToWholePercentagesCollection . TryGetValue ( sorting . Id , out wholePercentagesCollection ) )
throw new Exception ( ) ;
}
if ( sortingContainer . Source . MappingFromPerson is null )
{
if ( ! _Configuration . SaveSortingWithoutPerson )
continue ;
if ( wholePercentagesCollection . Contains ( sorting . WholePercentages ) )
continue ;
keyMapping . UpdateMappingFromUnknownPerson ( _Configuration . SaveIndividually , sortingContainer ) ;
wholePercentagesCollection . Add ( sorting . WholePercentages ) ;
results . Add ( new ( keyMapping , sortingContainer . Sorting , sortingContainer . Source ) ) ;
}
else
{
if ( wholePercentagesCollection . Contains ( sorting . WholePercentages ) )
continue ;
if ( keyMapping . MappingFromFilterPost . CanReMap is not null & & ( IPerson . IsDefaultName ( sortingContainer . Source . MappingFromPerson . DisplayDirectoryName ) | | _IdThenWholePercentagesToPersonContainers . TryGetValue ( sorting . Id , out wholePercentagesToPersonContainers ) & & wholePercentagesToPersonContainers . TryGetValue ( sorting . WholePercentages , out personContainers ) & & personContainers . Any ( l = > l . Key = = sortingContainer . Source . MappingFromPerson . PersonKey ) ) )
continue ;
if ( sortingContainer . Source . MappingFromPerson is null )
throw new NotSupportedException ( ) ;
wholePercentagesCollection . Add ( sorting . WholePercentages ) ;
results . Add ( new ( keyMapping , sortingContainer . Sorting , sortingContainer . Source ) ) ;
}
}
return new ( results ) ;
}
private ( string , PersonBirthday ? ) GetPersonBirthday ( string [ ] directoryNames )
@ -950,7 +1053,7 @@ public partial class MapLogic : Shared.Models.Methods.IMapLogic
throw new NotSupportedException ( ) ;
if ( string . IsNullOrEmpty ( mapping . MappingFromPerson . DisplayDirectoryName ) )
throw new NotSupportedException ( ) ;
personKeyFormatted = IPersonBirthday . GetFormatted ( _Configuration . PersonBirthdayFormat , mapping . MappingFromPerson . PersonBirthda y ) ;
personKeyFormatted = IPersonBirthday . GetFormatted ( _Configuration . PersonBirthdayFormat , mapping . MappingFromPerson . PersonKe y ) ;
if ( personKeyFormatted = = "1501-04-10_00" )
continue ;
if ( ! personKeyFormattedCollection . Contains ( personKeyFormatted ) )
@ -985,7 +1088,6 @@ public partial class MapLogic : Shared.Models.Methods.IMapLogic
if ( _Configuration is null )
throw new NullReferenceException ( nameof ( _Configuration ) ) ;
SaveContainer ? saveContainer ;
bool saveIndividually = false ;
List < SaveContainer > saveContainers = new ( ) ;
( int , FileHolder , int , string , string , string , string ) [ ] collection = GetCollectionForSaveFilteredOriginalImagesFromJLinks ( jLinks , a2PeopleContentDirectory , personContainers , mappingCollection , personKeyToIds ) ;
foreach ( ( int id , FileHolder imageFileHolder , int approximateYears , string personKeyFormatted , string directory , string personDirectory , string checkFile ) in collection )
@ -995,7 +1097,7 @@ public partial class MapLogic : Shared.Models.Methods.IMapLogic
saveContainer = new ( imageFileHolder , checkFile , directory ) ;
saveContainers . Add ( saveContainer ) ;
}
SaveContainers ( saveIndividually , null , saveContainers ) ;
SaveContainers ( null , saveContainers ) ;
}
public void SaveShortcutsForOutputResolutionsPreMapLogic ( string eDistanceContentDirectory , ReadOnlyDictionary < long , List < int > > personKeyToIds , ReadOnlyCollection < Mapping > mappingCollection )
@ -1041,7 +1143,6 @@ public partial class MapLogic : Shared.Models.Methods.IMapLogic
{
if ( _Configuration is null )
throw new NullReferenceException ( nameof ( _Configuration ) ) ;
long personKey ;
string fileName ;
string fullName ;
string directory ;
@ -1109,18 +1210,17 @@ public partial class MapLogic : Shared.Models.Methods.IMapLogic
throw new NotSupportedException ( ) ;
if ( string . IsNullOrEmpty ( mapping . MappingFromPerson . DisplayDirectoryName ) )
throw new NotSupportedException ( ) ;
personKeyFormatted = IPersonBirthday . GetFormatted ( _Configuration . PersonBirthdayFormat , mapping . MappingFromPerson . PersonBirthda y ) ;
personKey = mapping . MappingFromPerson . PersonBirthday . Value . Ticks ;
personKeyFormatted = IPersonBirthday . GetFormatted ( _Configuration . PersonBirthdayFormat , mapping . MappingFromPerson . PersonKe y ) ;
if ( mapping . MappingFromItem . ContainerDateTimes . Length > 0 & & ! distinct . Contains ( mapping . MappingFromItem . ResizedFileHolder . DirectoryName ) )
{
distinct . Add ( mapping . MappingFromItem . ResizedFileHolder . DirectoryName ) ;
directoriesAndDateTimes . Add ( new ( mapping . MappingFromItem . ResizedFileHolder . DirectoryName , mapping . MappingFromItem . ContainerDateTimes ) ) ;
}
directory = Path . Combine ( mapping . MappingFromItem . ResizedFileHolder . DirectoryName , $"{_PropertyConfiguration.ResultAllInOne}Shortcuts" , personKeyFormatted ) ;
if ( ! personKeyToIds . ContainsKey ( p ersonKey) )
if ( ! personKeyToIds . ContainsKey ( mapping . MappingFromPerson . P ersonKey) )
personDirectory = Path . Combine ( directory , mapping . MappingFromPerson . DisplayDirectoryName ) ;
else
personDirectory = Path . Combine ( directory , mapping . MappingFromPerson . DisplayDirectoryName , $"{personKeyToIds[p ersonKey].Count} Face(s)" ) ;
personDirectory = Path . Combine ( directory , mapping . MappingFromPerson . DisplayDirectoryName , $"{personKeyToIds[mapping.MappingFromPerson.P ersonKey].Count} Face(s)" ) ;
fileName = Path . Combine ( directory , $"{mapping.MappingFromItem.ResizedFileHolder.Name}.lnk" ) ;
collection . Add ( new ( mapping . MappingFromItem . ResizedFileHolder . FullName , personDirectory , mapping . MappingFromItem . GetDateTimeOriginalThenMinimumDateTime ( ) , fileName , mapping . MappingFromLocation ? . DeterministicHashCodeKey , MakeAllHidden : false ) ) ;
}
@ -1215,38 +1315,6 @@ public partial class MapLogic : Shared.Models.Methods.IMapLogic
return result ;
}
public bool? IsFocusPersonOld ( int? skipPersonWithMoreThen , List < ( string Directory , long PersonKey ) > jLinkResolvedDirectories , ReadOnlyDictionary < int , ReadOnlyCollection < PersonContainer > > ? wholePercentagesToPersonContainers , MappingFromLocation mappingFromLocation )
{
bool? result ;
ReadOnlyCollection < PersonContainer > ? personContainers ;
if ( skipPersonWithMoreThen is null & & jLinkResolvedDirectories . Count = = 0 )
result = null ;
else if ( wholePercentagesToPersonContainers is null )
result = null ;
else if ( ! wholePercentagesToPersonContainers . TryGetValue ( mappingFromLocation . WholePercentages , out personContainers ) )
result = null ;
else
{
result = false ;
foreach ( PersonContainer personContainer in personContainers )
{
if ( personContainer . Key is null )
continue ;
if ( skipPersonWithMoreThen is not null & & _PersonKeyToCount . TryGetValue ( personContainer . Key . Value , out int count ) & & count > 2 & & count < skipPersonWithMoreThen . Value )
{
result = true ;
break ;
}
if ( jLinkResolvedDirectories . Any ( l = > personContainer . Key . Value = = l . PersonKey ) )
{
result = true ;
break ;
}
}
}
return result ;
}
public void LookForAbandoned ( Property . Models . Configuration propertyConfiguration , string bResultsFullGroupDirectory , Container [ ] containers , string cResultsFullGroupDirectory , string dResultsFullGroupDirectory , string d2ResultsFullGroupDirectory )
{
string [ ] directories ;