Example #1
0
        public ImageTreeDirectory(DirectoryInfo directory, ImageTreeDirectory parent = null)
        {
            if (!directory.Exists)
            {
                throw new DirectoryNotFoundException("The specified directory does not exist");
            }

            DirectoryInfo = directory;
            Parent        = parent;
        }
Example #2
0
        /// <summary>
        /// Scans the tree to find all images, and all shortcuts to images.
        /// </summary>
        /// <param name="token"></param>
        public void Populate(CancellationToken token)
        {
            ScanStarted?.Invoke(new DirectoryScanInfo {
                Directory = DirectoryInfo
            });

            if (token.IsCancellationRequested)
            {
                return;
            }

            try
            {
                EnsureShortcutUtility();

                List <ImageItem> children = new List <ImageItem>();
                ImageItem        child;

                foreach (var file in DirectoryInfo.EnumerateFilesByExtensions(Constants.IMAGE_FILE_EXTENSIONS_PLUS_LINK))
                {
                    if (token.IsCancellationRequested)
                    {
                        return;
                    }

                    child = new ImageItem(file, ShortcutUtility);

                    if (child.IsImage)
                    {
                        children.Add(child);
                    }
                }

                if (token.IsCancellationRequested)
                {
                    return;
                }

                AddDescendants(children, 0);

                EnsureBlacklist();

                foreach (var subDir in DirectoryInfo.EnumerateDirectories())
                {
                    if (token.IsCancellationRequested)
                    {
                        return;
                    }

                    if (!BlacklistExcludes(subDir.FullName) && !subDir.Attributes.HasFlag(FileAttributes.System))
                    {
                        var subTreeDir = new ImageTreeDirectory(subDir, this)
                        {
                            Blacklist       = Blacklist,
                            ShortcutUtility = ShortcutUtility
                        };

                        subTreeDir.ScanStarted += ScanStarted;
                        subTreeDir.ScanFailed  += ScanFailed;

                        subTreeDir.Populate(token);

                        if (token.IsCancellationRequested)
                        {
                            return;
                        }

                        ChildDirectories.Add(subTreeDir);
                    }
                }

                IsPopulated = true;
            }
            catch (Exception ex)
            {
                ScanFailed?.Invoke(new DirectoryScanInfo {
                    Directory = DirectoryInfo, Exception = ex
                });
            }
        }