public void SortSubFolders(SortAction sortAction, ref PGFolderComparer defaultcomparer) { PGFolderComparer comparer = PGFolderComparer.GetComparerBySortAction(sortAction, defaultcomparer); SubFolders.Sort(comparer); defaultcomparer = comparer; }
private void FillSubFoldersRecursive(ref PGFolder folder, PGFolderComparer defaultSortingComparer, out List <string> filenames_cache) { filenames_cache = new List <string>(); DirectoryInfo directory = new DirectoryInfo(folder.PhysicalPath); if (!directory.Exists) { throw new DirectoryNotFoundException(string.Format("Directory {0} not found", directory)); } else { //1. READ INFO FILE folder.ReadFolder(); Images.AddRange(folder.Images); //cache images for easy access Comments.AddRange(folder.Comments); //cache comments for easy access. //2. LOAD SUB FOLDERS from disk (RECURSIVE) folder.SubFolders = new List <PGFolder>(); defaultSortingComparer = PGFolderComparer.GetComparerBySortAction(folder.SortAction, defaultSortingComparer); //3. subfolder recursive foreach (DirectoryInfo subDirectory in directory.GetDirectories()) { if (!IsDirectoryIgnored(subDirectory.FullName)) { PGFolder subfolder = new PGFolder() { Name = subDirectory.Name, PhysicalPath = subDirectory.FullName }; subfolder.ParentFolder = folder; List <string> filename_cache_subfolder = new List <string>(); FillSubFoldersRecursive(ref subfolder, defaultSortingComparer, out filename_cache_subfolder); filenames_cache.AddRange(filename_cache_subfolder); folder.SubFolders.Add(subfolder); folder.NumberNestedImages += subfolder.NumberNestedImages; //todo refactor, inside pgfolder. } } //4. Sorting? folder.SortSubFolders(folder.SortAction, ref defaultSortingComparer); AllFolders.Add(folder); //index for faster access filenames_cache.Add(folder.FolderInfoFileLocation()); } //5. WRITE if necessary if (!folder.ExistFolderInfoFile()) { folder.WriteFolderFileInfo(); } }