/// <summary> /// Adds a file to the pigg file collection. /// </summary> /// <param name="FileName">The name of the pigg file to add to the /// collection.</param> /// <param name="Overwrite">Whether to overwrite the file if it already /// exists within the collection.</param> /// <returns>And AddFileResult that indicates the result of trying to add /// the file to the pigg file collection.</returns> /// <remarks>The collection of pigg files is contained in a Dictionary /// object. This is so that there will be no duplicate files in the /// collection. Using this version of the AddFile function, one can /// specify whether or not it is desired to overwrite the file if it is /// already in the collection. Either way, if the file exists, /// AddFileResult.FileExists will be returned.</remarks> public AddFileResult AddFile(string FileName, bool Overwrite) { if (m_root == null) { m_root = new PiggNode(); } if (!File.Exists(FileName)) { return(AddFileResult.InvalidFile); } else { FileInfo info = new FileInfo(FileName); if (m_filelist.ContainsKey(info.FullName)) { if (Overwrite == true) { m_filelist.Remove(info.FullName); m_filelist[info.FullName] = new PiggFile(info.FullName, m_root); } return(AddFileResult.FileExists); } else { m_filelist[info.FullName] = new PiggFile(info.FullName, m_root); return(AddFileResult.OK); } } }
/// <summary> /// Initializes a directory node with the given parameters. /// </summary> /// <param name="Name">Name of the directory node.</param> /// <param name="Parent">Parent node of the directory. If the node is a /// root node, Parent returns null.</param> /// <remarks>By default, Initialize sets all members to some reasonable /// default value, such as zero. For the DateTime timestamp, it is set /// to the minimum DateTime available (midnight Jan. 1, 1 AD). Non- /// default values should be set after the Initialize function is called. /// </remarks> private void Initialize(string Name, PiggNode Parent) { this.Name = Name; this.Parent = Parent; Parent.AddLeaf(this); m_pigg_references = new List <PiggLeafInfo>(); }
/// <summary> /// Initializes a new PiggDirectory object with the given name and parent /// directory. /// </summary> /// <param name="Name">Name of PiggNode object.</param> /// <param name="Parent">Parent of the PiggNode object.</param> /// <param name="Level">Depth of node in PiggNode tree.</param> private void Initialize(string Name, PiggNode Parent, int Level) { this.Name = Name; this.Parent = Parent; this.Level = Level; this.LeafMap = new Dictionary <string, PiggLeaf>(); this.SubnodeMap = new Dictionary <string, PiggNode>(); this.FilerefMap = new Dictionary <string, PiggFile>(); }
/// <summary> /// Adds a Pigg node as a subnode of this node. /// </summary> /// <param name="Node">Pigg node to add as a subnode to this node. If a /// node already exists with the name of the node, the existing node is /// returned instead.</param> /// <returns>The Pigg node added.</returns> public PiggNode AddNode(PiggNode Node) { if (this.SubnodeMap.ContainsKey(Node.Name)) { return(this.SubnodeMap[Node.Name]); } this.SubnodeMap[Node.Name] = Node; Node.Parent = this; return(this.SubnodeMap[Node.Name]); }
/// <summary> /// Adds to the amount of storage this node is holding. /// </summary> /// <param name="Bytes">Number of bytes to add to storage.</param> internal void AddCapacity(long Bytes) { this.Capacity += Bytes; PiggNode walker = this; while (walker != null) { walker.TotalCapacity += Bytes; walker.TotalLeafCount++; walker = walker.Parent; } }
/// <summary> /// Add a leaf as a child to the PiggNode tree. /// </summary> /// <param name="Parent">Root of the PiggNode tree.</param> /// <param name="FullPath">Full path name of the PiggLeaf object.</param> /// <returns></returns> public static PiggLeaf AddLeaf(PiggNode Parent, string FullPath) { string path = System.IO.Path.GetDirectoryName(FullPath); string leaf = System.IO.Path.GetFileName(FullPath); // If a null parent was passed in, create a default root node. if (Parent == null) { Parent = new PiggNode(); } return(new PiggLeaf(leaf, Parent.AddPath(path))); }
/// <summary> /// Creates a PiggNode path structure, ensuring that all elements along /// the path exist. /// </summary> /// <param name="Path">Path structure to create.</param> /// <returns></returns> public PiggNode AddPath(string Path) { string path = System.IO.Path.GetDirectoryName(Path); string leaf = System.IO.Path.GetFileName(Path); PiggNode parent = path == "" ? this : this.AddPath(path); if (!parent.SubnodeMap.ContainsKey(leaf)) { parent.SubnodeMap[leaf] = new PiggNode(leaf, parent); } return(parent.SubnodeMap[leaf]); }
/// <summary> /// Creates a new subnode of this node. /// </summary> /// <param name="Name">The name of the new subnode. If the subnode /// already exists, it is not overwritten.</param> /// <returns>The new subnode, or if the subnode already existed, the /// existing subnode.</returns> public PiggNode Subnode(string Name) { if (this.SubnodeMap.ContainsKey(Name)) { return(this.SubnodeMap[Name]); } else { PiggNode new_node = new PiggNode(Name, this); this.SubnodeMap.Add(Name, new_node); return(new_node); } }
/// <summary> /// Creates and initializes a new PiggDirectory object with the given name /// and parent directory. /// </summary> /// <param name="Name">Name of the directory object.</param> /// <param name="Parent">Parent directory of the directory object.</param> public PiggNode(string Name, PiggNode Parent) { Initialize(Name, Parent, Parent.Level + 1); }
/// <summary> /// Adds a PiggLeaf object to the tree at the specified path. /// </summary> /// <param name="Leaf">Leaf to add to the PiggNode tree.</param> /// <param name="Path">Path to the PiggNode object to which the PiggLeaf /// should be added.</param> /// <returns>The PiggLeaf object added.</returns> public PiggLeaf AddLeaf(PiggLeaf Leaf, string Path) { PiggNode parent = this.AddPath(Path); return(parent.AddLeaf(Leaf)); }
/// <summary> /// Initializes a pigg file collection. /// </summary> private void Initialize() { m_filelist = new Dictionary <string, PiggFile>(); m_root = new PiggNode(); }
/// <summary> /// Creates a PiggLeaf that is a subnode of a PiggNode object. /// </summary> /// <param name="Name">Name of the PiggLeaf object.</param> /// <param name="Parent">PiggNode that is the parent node of this PiggLeaf /// object.</param> public PiggLeaf(string Name, PiggNode Parent) { Initialize(Name, Parent); }