Beispiel #1
0
        /// <summary>
        /// Adds a child FSO to this treenode.
        /// This function supports pathing, so you can add a file with directory names!
        ///
        /// Directories are created if not existing already
        ///
        /// Such as: root/subDir/SubSubDir/file.name
        /// </summary>
        public RAFInMemoryFileSystemObject AddToTree(RAFFSOType type, string name)
        {
            string[] dirNames = name.Replace("\\", "/").Split("/");

            RAFInMemoryFileSystemObject currentNode = this;

            //Traverse FS Tree to the directory containing our file
            for (int i = 0; i < dirNames.Length - 1; i++)
            {
                RAFInMemoryFileSystemObject childNode = currentNode.GetChildFSO(dirNames[i]);

                if (childNode == null)
                {
                    childNode = currentNode.AddChildFSO(RAFFSOType.DIRECTORY, dirNames[i]);
                }

                currentNode = childNode;
            }

            //Add the childnode to our tree..
            return(currentNode.AddChildFSO(RAFFSOType.FILE, dirNames.Last()));
        }