@@ -29,10 +29,11 @@ public class FolderItem : FileItemBase {
2929 /// Always use the list modification methods to add or remove from the list. This is important
3030 /// because they account for if <see cref="FileItemBase.EmptyChildren"/> is being used.
3131 /// </summary>
32- protected volatile List < FileItemBase > children = EmptyChildren ;
33-
34- /// <summary>Gets the number of files this folder contains.</summary>
35- public override sealed int FileCount { get ; protected set ; }
32+ protected volatile List < FileItemBase > children = EmptyChildren ;
33+ private volatile FolderItem _fileCollection ;
34+
35+ /// <summary>Gets the number of files this folder contains.</summary>
36+ public override sealed int FileCount { get ; protected set ; }
3637 /// <summary>Gets the number of directories this folder contains.</summary>
3738 public override sealed int SubdirCount { get ; protected set ; }
3839
@@ -311,13 +312,7 @@ private bool IsStoringOneContainer {
311312 public FolderItem GetFileCollection ( ) {
312313 if ( Type == FileItemType . FileCollection )
313314 return this ;
314- int count = children . Count ;
315- for ( int i = 0 ; i < count ; i ++ ) {
316- FileItemBase child = children [ i ] ;
317- if ( child . Type == FileItemType . FileCollection )
318- return ( FolderItem ) child ;
319- }
320- return null ;
315+ return _fileCollection ;
321316 }
322317
323318 /// <summary>Gets the first file in this folder.</summary>
@@ -425,8 +420,8 @@ public void AddItem(FileItemBase item) {
425420 /// <param name="firstFile">
426421 /// The container's first file. Keep track of this when scanning this directory.
427422 /// </param>
428- public void AddItem ( FileItemBase item , ref FolderItem fileCollection , ref FileItem firstFile ) {
429- if ( Type == FileItemType . FileCollection )
423+ public void AddItem ( FileItemBase item , ref FolderItem fileCollection , ref FileItem firstFile ) {
424+ if ( Type == FileItemType . FileCollection )
430425 throw new InvalidOperationException ( $ "Cannot call { nameof ( AddItem ) } from a File Collection!") ;
431426
432427 // We know we're adding an item to children, make sure it's setup
@@ -452,9 +447,10 @@ public void AddItem(FileItemBase item, ref FolderItem fileCollection, ref FileIt
452447 else if ( IsStoringContainers ) {
453448 // We've hit our limit of only one visible file when a
454449 // folder is storing non-files. Move to FileCollection.
455- fileCollection = new FolderItem ( ) ;
456- Remove ( firstFile ) ;
457- Add ( fileCollection ) ;
450+ fileCollection = new FolderItem ( ) ;
451+ _fileCollection = fileCollection ;
452+ Remove ( firstFile ) ;
453+ Add ( fileCollection ) ;
458454 fileCollection . Add ( firstFile ) ;
459455 fileCollection . Add ( item ) ;
460456 fileCollection . Invalidate ( ) ;
@@ -495,6 +491,7 @@ public void AddItem(FileItemBase item, ref FolderItem fileCollection, ref FileIt
495491 // Setup file collection if the folder needs to store a container item
496492 Debug . Assert ( fileCollection == null ) ;
497493 fileCollection = new FolderItem ( ) ;
494+ _fileCollection = fileCollection ;
498495 List < FileItemBase > files = ClearAndGetFiles ( ) ;
499496 Add ( fileCollection ) ;
500497 fileCollection . AddRange ( files ) ;
@@ -701,8 +698,11 @@ private void ClearFileCollectionItems() {
701698 protected void Add ( FileItemBase item ) {
702699 //EnsureChildren();
703700 int index = children . Count ;
704- children . Add ( item ) ;
705- item . Parent = this ;
701+ if ( item . Type == FileItemType . FileCollection && _fileCollection == null )
702+ Console . WriteLine ( ) ;
703+
704+ children . Add ( item ) ;
705+ item . Parent = this ;
706706 if ( IsWatched )
707707 RaiseChanged ( FileItemAction . ChildrenAdded , item , index ) ;
708708 }
@@ -926,11 +926,15 @@ private protected bool ValidateImpl(bool force) {
926926 if ( IsFileType ) {
927927 DirectoryInfo directoryInfo = new DirectoryInfo ( FullName ) ;
928928 // Use the directory's LastWriteTime when empty
929- LastWriteTimeUtc = directoryInfo . LastWriteTimeUtc ;
929+ LastWriteTimeUtc = directoryInfo . LastWriteTimeUtc ;
930+ LastAccessTimeUtc = directoryInfo . LastAccessTimeUtc ;
931+ CreationTimeUtc = directoryInfo . CreationTimeUtc ;
930932 }
931933 else {
932- LastWriteTimeUtc = DateTime . MinValue ;
933- }
934+ LastWriteTimeUtc = DateTime . MinValue ;
935+ LastAccessTimeUtc = DateTime . MinValue ;
936+ CreationTimeUtc = DateTime . MinValue ;
937+ }
934938 if ( IsWatched )
935939 RaiseChanged ( FileItemAction . ValidatedSortOrder ) ;
936940 IsValidating = false ;
@@ -939,9 +943,11 @@ private protected bool ValidateImpl(bool force) {
939943
940944 // True, if any of the sort orders that can change, have changed
941945 bool sortOrderChanged = false ;
942- long oldSize = Size ;
943- DateTime oldLastChangeTime = LastWriteTimeUtc ;
944- bool thisIsDone = IsDone ;
946+ long oldSize = Size ;
947+ DateTime oldLastChangeTime = LastWriteTimeUtc ;
948+ DateTime oldLastAccessTimeUtc = LastAccessTimeUtc ;
949+ DateTime oldCreationTimeUtc = CreationTimeUtc ;
950+ bool thisIsDone = IsDone ;
945951 bool isDone = true ;
946952
947953 lock ( children ) {
@@ -973,7 +979,9 @@ private protected bool ValidateImpl(bool force) {
973979 Size += child . Size ;
974980 //LastAccessTime = Max(LastAccessTime, child.LastAccessTime);
975981 LastWriteTimeUtc = MaxDateTime ( LastWriteTimeUtc , child . LastWriteTimeUtc ) ;
976- if ( child . Type == FileItemType . File || child . Type == FileItemType . FreeSpace ) {
982+ LastAccessTimeUtc = MaxDateTime ( LastAccessTimeUtc , child . LastAccessTimeUtc ) ;
983+ CreationTimeUtc = MaxDateTime ( CreationTimeUtc , child . CreationTimeUtc ) ;
984+ if ( child . Type == FileItemType . File || child . Type == FileItemType . FreeSpace ) {
977985 FileCount ++ ;
978986 }
979987 else {
@@ -1004,7 +1012,7 @@ private protected bool ValidateImpl(bool force) {
10041012 else
10051013 RaiseChanged ( FileItemAction . Validated ) ;
10061014 }
1007- return sortOrderChanged || ( oldLastChangeTime != LastWriteTimeUtc ) ;
1015+ return sortOrderChanged || ( oldLastChangeTime != LastWriteTimeUtc ) || ( oldLastAccessTimeUtc != LastAccessTimeUtc ) || ( oldCreationTimeUtc != CreationTimeUtc ) ;
10081016 }
10091017
10101018 /// <summary>Fully validates the file item tree and prepares it for use.</summary>
0 commit comments