protected BblLibraryNode(BblLibraryNode node) // copy constructor { Root = node.Root; Parent = node.Parent; LoadInfo(node); _children = node.Children; }
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); }
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); }
public bool DeleteDirectory(string path) { DirectoryInfoEx d = new DirectoryInfoEx(path); BblLibraryNode node = FindChild(d); if (node != null) { node.OnFileSystemEntryDeleted(); } return(false); }
private void AddChild(BblLibraryNode child) { lock (_lock) { if (_children == null) { _children = new List <BblLibraryNode>(); } _children.Add(child); } }
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); }
public virtual bool DeleteChild(BblLibraryNode n) { lock (_lock) { bool retval = _children.Remove(n); if (_children.Count == 0) { _children = null; } return(retval); } }
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); }
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); }
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; } }
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); } }
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; } } }
/// <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++; } }
//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); } }
public BblBookPdf(BblLibraryRootNode root, BblLibraryNode parent, WIN32_FIND_DATA findData) : base(root, parent, findData, BookType.Pdf) { }
protected BblLibraryNode(BblLibraryRootNode root, BblLibraryNode parent, FileSystemInfoEx info) { Root = root; Parent = parent; LoadInfo(info); }
protected BblLibraryNode(BblLibraryRootNode root, BblLibraryNode parent, WIN32_FIND_DATA findData) { Root = root; Parent = parent; LoadInfo(parent.Path, findData); }
/// <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); }
public BblBookArchive(BblLibraryRootNode root, BblLibraryNode parent, WIN32_FIND_DATA findData) : base(root, parent, findData, BookType.Archive) { }
protected BblBook(BblLibraryRootNode root, BblLibraryNode parent, FileSystemInfoEx info, BookType type) : base(root, parent, info) { Initialize(type); }
public BblBookDirectory(BblLibraryRootNode root, BblLibraryNode parent, FileSystemInfoEx info) : base(root, parent, info, BookType.Directory) { }
public BblBookArchive(BblLibraryRootNode root, BblLibraryNode parent, FileSystemInfoEx info) : base(root, parent, info, BookType.Archive) { }
public BblBookDirectory(BblLibraryRootNode root, BblLibraryNode parent, WIN32_FIND_DATA findData) : base(root, parent, findData, BookType.Directory) { }
public BblBookDirectory(BblLibraryNode swap) : base(swap, BookType.Directory) { }
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); }
public BblBookPdf(BblLibraryRootNode root, BblLibraryNode parent, FileSystemInfoEx info) : base(root, parent, info, BookType.Pdf) { }