private bool CheckMediaType(ScannedFileInfo scannedFile) { bool bRel = true; if (null == scannedFile) { return(false); } scannedFile.Category = GetFileCategory(scannedFile.File); if (scannedFile.Category == FileCategory.Unknown) { bRel = false; } return(bRel); }
private void ScanFilesInDirectory(DirectoryInfo directoryInfo, ref IList <ScannedFileInfo> searchedFiles) { if (null == directoryInfo || !directoryInfo.Exists) { return; } NewFoldersToMonitor.Add(directoryInfo); IList <ScannedFileInfo> fileList = new List <ScannedFileInfo>(); try { FileSystemInfo[] fileSystemInfos = directoryInfo.GetFileSystemInfos(); for (int i = 0; i < fileSystemInfos.Length; i++) { if (IsCancel) { break; } FileSystemInfo fileSystemInfo = fileSystemInfos[i]; if (null == fileSystemInfo) { continue; } if (fileSystemInfo is DirectoryInfo) { ScanFilesInDirectory(fileSystemInfo as DirectoryInfo, ref searchedFiles); } else { FileInfo fileInfo = fileSystemInfo as FileInfo; if (null != fileInfo) { ScannedFileInfo scannedFileInfo = new ScannedFileInfo() { File = fileInfo }; if (CheckMediaType(scannedFileInfo)) { //searchedFiles.Add(scannedFileInfo); fileList.Add(scannedFileInfo); NotifyEvent(new FileScannerProcessEventArgs(ProcessType.InProcess, InnerType.OneFileScanned) { CurrentFile = scannedFileInfo }); } } } } } catch (Exception e) { NLogger.LogHelper.UILogger.Debug("ScanFilesInDirectory", e); } finally { ((List <ScannedFileInfo>)searchedFiles).AddRange(fileList); NotifyEvent(new FileScannerProcessEventArgs(ProcessType.InProcess, InnerType.OneDirectoryScanned) { CurrentDir = directoryInfo, Files = fileList }); } }