Exemplo n.º 1
0
        // CTOR
        public RandomImageFinder()
        {
            _haventSearchedImagesYet = true;
            _searchDirectoryPath     = Environment.CurrentDirectory;
            _imagesCollection        = new ImagesCollection();

            SearchFinishedInternal += CompleteSearch;
        }
Exemplo n.º 2
0
        public RandomImageFinder()
        {
            _haventSearchedImagesYet = true;
            _searchDirectoryPath = Environment.CurrentDirectory;
            _imagesCollection = new ImagesCollection();
            _threadAborted = false;

            SearchFinishedInternal += CompleteSearch;
        }
Exemplo n.º 3
0
        // 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);
            }
        }
Exemplo n.º 4
0
        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);
        }