Пример #1
0
        /// <summary>
        /// Processing a folder
        /// </summary>
        /// <param name="pBackgroundWorker">Background worker</param>
        /// <param name="pDrive">Drive</param>
        /// <param name="pDirectoryInfo">The directory info</param>
        /// <param name="pParentFolderStatus">Parent folder status</param>
        /// <param name="pDepth">Depth</param>
        /// <param name="pSubFolderDepth">Sub-folder depth</param>
        protected void ProcessFolder(BackgroundWorker pBackgroundWorker, Drive pDrive, DirectoryInfo pDirectoryInfo,
                                     FolderStatus pParentFolderStatus, int pDepth, int pSubFolderDepth)
        {
            if (!FolderIconChanger.FolderIsToBeProcessed(pDirectoryInfo))
            {
                return;
            }

            pBackgroundWorker.ReportProgress(0, new FolderIconChangerState(FolderIconChangerStateContentType.Folder,
                                                                           new Folder()
            {
                Name = pDirectoryInfo.FullName
            }));

            string       lFolderPath           = FileSystemToolkit.GetPathWithoutDrive(pDirectoryInfo.FullName);
            string       lFolderPathIdentifier = FileSystemToolkit.GetPathIdentifier(lFolderPath);
            Folder       lFolder       = pDrive.Folders.FirstOrDefault <Folder>(pFolder => FileSystemToolkit.GetPathIdentifier(pFolder.Name) == lFolderPathIdentifier);
            FolderStatus lFolderStatus = new FolderStatus(pDirectoryInfo.FullName);

            if (pDepth == 0)
            {
                lFolderStatus.SubFolderProcessing = SubFolderProcessing.Icons;
                lFolderStatus.SubFolderDepth      = 1;
            }
            if (lFolder != null)
            {
                lFolderStatus.Icon = lFolder.Icon;
                lFolderStatus.SubFolderProcessing = lFolder.SubFolderProcessing;
                lFolderStatus.SubFolderDepth      = lFolder.SubFolderDepth;
                pSubFolderDepth = 0;
            }
            else if (pParentFolderStatus != null)
            {
                if (pParentFolderStatus.SubFolderProcessing == SubFolderProcessing.SameIcon)
                {
                    lFolderStatus.Icon     = pParentFolderStatus.Icon;
                    lFolderStatus.IconPath = pParentFolderStatus.IconPath;
                }
                lFolderStatus.SubFolderProcessing = pParentFolderStatus.SubFolderProcessing;
                lFolderStatus.SubFolderDepth      = pParentFolderStatus.SubFolderDepth;
            }

            if (lFolderStatus.Icon.Length == 0)
            {
                lFolderStatus.Icon     = pDirectoryInfo.Name.Trim().ToLower().Replace(" ", "");
                lFolderStatus.IconPath = string.Empty;
            }
            if (pDepth > 0)
            {
                this.ChangeFolderIcon(pBackgroundWorker, pDirectoryInfo, lFolderStatus);
            }

            string lSubFoldersPattern       = lFolderPathIdentifier + @"\";
            bool   lProcessAllSubFolders    = ((lFolderStatus.ProcessSubFolders) && ((lFolderStatus.SubFolderDepth < 0) || (lFolderStatus.SubFolderDepth > pSubFolderDepth)));
            bool   lProcessSomeSubFolders   = ((lProcessAllSubFolders) || (pDrive.Folders.Any <Folder>(pFolder => pFolder.Name.Trim().ToLower().StartsWith(lSubFoldersPattern))));
            bool   lProcessSubFolder        = false;
            string lSubFolderPathIdentifier = string.Empty;

            if ((lProcessAllSubFolders) || (lProcessSomeSubFolders))
            {
                foreach (DirectoryInfo lSubDirectoryInfo in pDirectoryInfo.GetDirectories())
                {
                    lProcessSubFolder = lProcessAllSubFolders;
                    if (!lProcessSubFolder)
                    {
                        lSubFolderPathIdentifier = FileSystemToolkit.GetPathIdentifier(FileSystemToolkit.GetPathWithoutDrive(lSubDirectoryInfo.FullName));
                        lProcessSubFolder        = (pDrive.Folders.FirstOrDefault <Folder>(pFolder => FileSystemToolkit.GetPathIdentifier(pFolder.Name) == lSubFolderPathIdentifier) != null);
                    }
                    if (lProcessSubFolder)
                    {
                        this.ProcessFolder(pBackgroundWorker, pDrive, lSubDirectoryInfo, lFolderStatus, pDepth + 1, pSubFolderDepth + 1);
                    }
                }
            }
        }