/// <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); } } } }
/// <summary> /// Standard constructor /// </summary> /// <param name="pDrive">The drive</param> public DriveEventArgs(Drive pDrive) : base() { this.Drive = pDrive; }
/// <summary> /// On execute background worker progress changed /// </summary> /// <param name="sender">Sender</param> /// <param name="e">Event arguments</param> private void ExecuteBackgroundWorkerProgressChanged(object sender, ProgressChangedEventArgs e) { if (e.UserState == null) { return; } if (!(e.UserState is FolderIconChangerState)) { return; } FolderIconChangerState lState = (FolderIconChangerState)e.UserState; bool lWaitForIntefaceUpdate = false; switch (lState.ContentType) { case FolderIconChangerStateContentType.Drive: { Drive lDrive = (Drive)lState.Content; this.TriggerOnDrive(lDrive); this.Counters.CurrentlyProcessing = lDrive.ToString(); this.Counters.DrivesProcessed += 1; this.TriggerOnCountersChange(); lWaitForIntefaceUpdate = true; } break; case FolderIconChangerStateContentType.Folder: { Folder lFolder = (Folder)lState.Content; this.TriggerOnFolder(lFolder); this.Counters.CurrentlyProcessing = lFolder.ToString(); this.Counters.FoldersProcessed += 1; this.TriggerOnCountersChange(); lWaitForIntefaceUpdate = true; } break; case FolderIconChangerStateContentType.FolderStatus: { FolderStatus lFolderStatus = (FolderStatus)lState.Content; this.TriggerOnFolderStatus(lFolderStatus); if (lFolderStatus.IconAlreadyOk) { this.Counters.IconsAlreadyOk += 1; } else if (lFolderStatus.IconChanged) { this.Counters.IconsChanged += 1; } this.TriggerOnCountersChange(); lWaitForIntefaceUpdate = true; } break; case FolderIconChangerStateContentType.Error: { this.TriggerOnError((FolderIconsException)lState.Content); this.Counters.Errors += 1; this.TriggerOnCountersChange(); lWaitForIntefaceUpdate = true; } break; } //^^^if (lWaitForIntefaceUpdate) //^^^ Dispatcher.CurrentDispatcher.Invoke(new Action(() => { }), DispatcherPriority.ContextIdle, null); }
/// <summary> /// Standard constructor /// </summary> public FileSystemIterator(FolderIconChanger pFolderIconChanger) { this.FileSystem = pFolderIconChanger.FileSystem; this.Drive = null; }