示例#1
0
 protected BblLibraryNode(BblLibraryNode node) // copy constructor
 {
     Root   = node.Root;
     Parent = node.Parent;
     LoadInfo(node);
     _children = node.Children;
 }
示例#2
0
        public bool DeleteFile(string path)
        {
            FileInfoEx     f          = new FileInfoEx(path);
            BblLibraryNode parentNode = FindChild(f.Parent);
            BblLibraryNode node       = null;

            if (parentNode?.Children != null)
            {
                foreach (var n in parentNode.Children)
                {
                    if (n.Path == path)
                    {
                        node = n;
                        break;
                    }
                }
            }
            if (parentNode != null && parentNode is BblBookDirectory)
            {
                return(parentNode.DeleteChildFile(f));
            }
            else if (node != null)
            {
                node.OnFileSystemEntryDeleted();
            }
            return(false);
        }
示例#3
0
        public virtual BblLibraryNode AddChildFile(FileInfoEx info)
        {
            if (info.Parent.FullName != Path)
            {
                return(null);
            }
            if (IsArchiveFileExtension(info.Extension) || IsPDF(info.Extension))
            {
                BblLibraryNode b = null;
                if (IsArchiveFileExtension(info.Extension))
                {
                    b = new BblBookArchive(Root, this, info);
                }
                else if (IsPDF(info.Extension))
                {
                    b = new BblBookPdf(Root, this, info);
                }
                AddChild(b);
                return(b);
            }
            else if (IsImageFileExtension(info.Extension) && !IsBook && IsFolder && (_children == null || _children.Count == 0))
            {
                Root.AddPromotable(this);
            }

            return(null);
        }
示例#4
0
        public bool DeleteDirectory(string path)
        {
            DirectoryInfoEx d    = new DirectoryInfoEx(path);
            BblLibraryNode  node = FindChild(d);

            if (node != null)
            {
                node.OnFileSystemEntryDeleted();
            }
            return(false);
        }
示例#5
0
 private void AddChild(BblLibraryNode child)
 {
     lock (_lock)
     {
         if (_children == null)
         {
             _children = new List <BblLibraryNode>();
         }
         _children.Add(child);
     }
 }
示例#6
0
        public BblLibraryNode AddDirectory(string path)
        {
            BblLibraryNode  node   = null;
            DirectoryInfoEx d      = new DirectoryInfoEx(path);
            BblLibraryNode  parent = FindChild(d.Parent);

            if (parent != null)
            {
                node = parent.AddChildDirectory(d);
            }
            return(null);
        }
示例#7
0
 public virtual bool DeleteChild(BblLibraryNode n)
 {
     lock (_lock)
     {
         bool retval = _children.Remove(n);
         if (_children.Count == 0)
         {
             _children = null;
         }
         return(retval);
     }
 }
示例#8
0
        public BblLibraryNode RenameDirectory(string newPath, string oldPath)
        {
            DirectoryInfoEx d    = new DirectoryInfoEx(newPath);
            DirectoryInfoEx old  = new DirectoryInfoEx(oldPath);
            BblLibraryNode  node = FindChild(old);

            if (node != null)
            {
                return(node.OnFileSystemEntryRenamed(d));
            }
            return(null);
        }
示例#9
0
        public BblLibraryNode AddFile(string path)
        {
            FileInfoEx     f      = new FileInfoEx(path);
            var            ext    = f.Extension;
            BblLibraryNode parent = FindChild(f.Parent);

            if (parent != null)
            {
                var n = parent.AddChildFile(f);
                return(n);
            }
            return(null);
        }
示例#10
0
 protected void LoadInfo(BblLibraryNode info)
 {
     lock (_lock)
     {
         Path           = info.Path;
         Name           = info.Name;
         Attributes     = info.Attributes;
         CreationTime   = info.CreationTime;
         LastAccessTime = info.LastAccessTime;
         LastWriteTime  = info.LastWriteTime;
         Length         = (info.IsFolder) ? 0 : info.Length;
     }
 }
示例#11
0
 public BblLibraryNode AddChildDirectory(DirectoryInfoEx info)
 {
     if (IsBblBookDirectoryExtension(System.IO.Path.GetExtension(info.FullName)))
     {
         return(new BblBookDirectory(Root, this, info));
     }
     else
     {
         BblLibraryNode node = new BblLibraryNode(Root, this, info);
         node.Inflate();
         AddChild(node);
         return(node);
     }
 }
示例#12
0
 private void ReplaceChild(BblLibraryNode oldChild, BblLibraryNode newChild)
 {
     lock (_lock)
     {
         int idx = _children.IndexOf(oldChild);
         if (idx == -1)
         {
             throw new Exception("Replaced Child Not Found in BblLibraryNode.ReplaceChild");
         }
         else
         {
             _children[idx] = newChild;
         }
     }
 }
示例#13
0
        /// <summary>
        /// Swap constructor, takes a generic BblLibraryNode (normal directory, not book) that is to be replaced with a BblBook
        /// Happens when the node for an empty directory is promoted to book status because there's now an image in it.
        /// </summary>
        protected BblBook(BblLibraryNode node, BookType type) : base(node)
        {
            Type = type;
            BblBook b = node as BblBook;

            if (b != null)
            {
                Root.OnBookOperation(new BookOperationData(this, BookOperations.Replace, node as BblBook));
                Index  = b.Index;
                _pages = b._pages;
            }
            else
            {
                Root.OnBookOperation(new BookOperationData(this, BookOperations.Add, null));
                Index = Root.BookIndex++;
                Root.BookCount++;
            }
        }
示例#14
0
        //promotables are folders containing images and devoid of the .book extension
        //They could be promoted to BblBookDirectory status when ProcessPromotables is called
        //by renaming them, adding the .book extension.
        public void AddPromotable(BblLibraryNode n)
        {
            //filter out any special folder or folder within the path of an environment variable
            //as those cannot be renamed without f*****g something up.
            foreach (string env in Environment.GetEnvironmentVariables().Values)
            {
                if (env.ToLowerInvariant().Contains(n.Path.ToLowerInvariant()))
                {
                    return;
                }
            }

            foreach (Environment.SpecialFolder folder_type in Enum.GetValues(typeof(Environment.SpecialFolder)))
            {
                if (Environment.GetFolderPath(folder_type).ToLowerInvariant().Contains(n.Path.ToLowerInvariant()))
                {
                    return;
                }
            }

            lock (_lock) { _promotables.Add(n); }
        }
示例#15
0
 public BblBookPdf(BblLibraryRootNode root, BblLibraryNode parent, WIN32_FIND_DATA findData) : base(root, parent, findData, BookType.Pdf)
 {
 }
示例#16
0
 protected BblLibraryNode(BblLibraryRootNode root, BblLibraryNode parent, FileSystemInfoEx info)
 {
     Root   = root;
     Parent = parent;
     LoadInfo(info);
 }
示例#17
0
 protected BblLibraryNode(BblLibraryRootNode root, BblLibraryNode parent, WIN32_FIND_DATA findData)
 {
     Root   = root;
     Parent = parent;
     LoadInfo(parent.Path, findData);
 }
示例#18
0
        /// <summary>
        /// Build the pathstack required to run the FindChild method
        /// </summary>
        protected static Stack <FileSystemInfoEx> BuildPathStack(FileSystemInfoEx path, BblLibraryNode root)
        {
            Stack <FileSystemInfoEx> pathstack = new Stack <FileSystemInfoEx>();

            if (path.FullName == root.Path)
            {
                pathstack.Push(path);
                return(pathstack);
            }

            while (path != null)
            {
                pathstack.Push(path);
                try { path = path.Parent; }
                catch { return(null); }

                if (path.FullName == root.Path)
                {
                    return(pathstack);
                }
                else if (path == null)
                {
                    return(null);
                }
            }
            return(null);
        }
示例#19
0
 public BblBookArchive(BblLibraryRootNode root, BblLibraryNode parent, WIN32_FIND_DATA findData) : base(root, parent, findData, BookType.Archive)
 {
 }
示例#20
0
 protected BblBook(BblLibraryRootNode root, BblLibraryNode parent, FileSystemInfoEx info, BookType type) : base(root, parent, info)
 {
     Initialize(type);
 }
示例#21
0
 public BblBookDirectory(BblLibraryRootNode root, BblLibraryNode parent, FileSystemInfoEx info) : base(root, parent, info, BookType.Directory)
 {
 }
示例#22
0
 public BblBookArchive(BblLibraryRootNode root, BblLibraryNode parent, FileSystemInfoEx info) : base(root, parent, info, BookType.Archive)
 {
 }
示例#23
0
 public BblBookDirectory(BblLibraryRootNode root, BblLibraryNode parent, WIN32_FIND_DATA findData) : base(root, parent, findData, BookType.Directory)
 {
 }
示例#24
0
 public BblBookDirectory(BblLibraryNode swap) : base(swap, BookType.Directory)
 {
 }
示例#25
0
 protected bool _demoted; //book has no pages or BblBookDirectory renamed with no .book extension
 protected BblBook(BblLibraryRootNode root, BblLibraryNode parent, WIN32_FIND_DATA findData, BookType type) : base(root, parent, findData)
 {
     Initialize(type);
 }
示例#26
0
 public BblBookPdf(BblLibraryRootNode root, BblLibraryNode parent, FileSystemInfoEx info) : base(root, parent, info, BookType.Pdf)
 {
 }