private void SearchImages() { if (!System.IO.Directory.Exists(_searchDirectoryPath)) { throw new DirectoryDoesNotExistAnymore(_searchDirectoryPath); } _imagesCollection.Clear(); _haventSearchedImagesYet = true; RiseImagesCountChanged(); var searchOptions = new SearchImagesOptions() { IncludeSubdirs = _includeSubdirs }; RiseSearchStarted(); StopSearchInternal(); _searchCancellationTokenSource = new CancellationTokenSource(); object callbackParams = new object[] { _searchDirectoryPath, _imagesCollection, _imageFileMasks, searchOptions, _searchCancellationTokenSource.Token }; _searchTask = Task.Factory.StartNew(SearchDelegate, callbackParams); }
// PRIVATE/INTERNAL METHODS private void Search( string directory, ImagesCollection foundFiles, IReadOnlyCollection <string> fileMasks, SearchImagesOptions searchOptions, CancellationToken ct) { if (_excludeSearchDirectories.Any(exDir => exDir.ToLowerInvariant().Equals(directory.ToLowerInvariant()))) { return; } var images = new List <string>(); try { foreach (var fileMask in fileMasks) { images.AddRange(System.IO.Directory.EnumerateFiles(directory, fileMask, SearchOption.TopDirectoryOnly)); } } catch (SecurityException) { } catch (UnauthorizedAccessException) { } catch (Exception ex) { CrashLogger.Instance.Log("Files enumeration failed in directory " + directory, ex.Message); } foundFiles.AddRange(directory, images); if (!searchOptions.IncludeSubdirs || ct.IsCancellationRequested) { return; } IEnumerable <string> subDirs = new List <string>(); try { subDirs = System.IO.Directory.EnumerateDirectories(directory, "*", SearchOption.TopDirectoryOnly); } catch (SecurityException) { } catch (UnauthorizedAccessException) { } catch (Exception ex) { CrashLogger.Instance.Log("Directory enumeration failed in directory " + directory, ex.Message); } foreach (var subDir in subDirs) { Search(subDir, foundFiles, fileMasks, searchOptions, ct); } }
private void SearchImages() { if (!System.IO.Directory.Exists(_searchDirectoryPath)) { throw new DirectoryDoesNotExistAnymore(_searchDirectoryPath); } _imagesCollection.Clear(); _haventSearchedImagesYet = true; RiseImagesCountChanged(); var searchOptions = new SearchImagesOptions() { IncludeSubdirs = _includeSubdirs }; object callbackParams = new object[] { _searchDirectoryPath, _imagesCollection, _imageFileMasks, searchOptions }; RiseSearchStarted(); AbortThreadInternal(); _threadAborted = false; _searchThread = new Thread(SearchDelegate); _searchThread.Start(callbackParams); }
private void Search(string directory, ImagesCollection foundFiles, IReadOnlyCollection<string> fileMasks, SearchImagesOptions searchOptions) { foreach (var excludeDirectory in _excludeSearchDirectories) if (directory.StartsWith(excludeDirectory)) return; List<string> images = new List<string>(); try { foreach (var fileMask in fileMasks) { images.AddRange(System.IO.Directory.EnumerateFiles(directory, fileMask, SearchOption.TopDirectoryOnly)); } } catch (SecurityException) { } catch (UnauthorizedAccessException) { } catch (Exception ex) { CrashLogger.Instance.Log("Files enumeration failed in directory " + directory, ex.Message); } foundFiles.AddRange(directory, images); if (!searchOptions.IncludeSubdirs) return; IEnumerable<string> subDirs = new List<string>(); try { subDirs = System.IO.Directory.EnumerateDirectories(directory, "*", SearchOption.TopDirectoryOnly); } catch (SecurityException) { } catch (UnauthorizedAccessException) { } catch (Exception ex) { CrashLogger.Instance.Log("Directory enumeration failed in directory " + directory, ex.Message); } foreach (var subDir in subDirs) Search(subDir, foundFiles, fileMasks, searchOptions); }