Ejemplo n.º 1
0
        /// <summary>
        /// Locates and returns the entry that matches the specified criteria.
        /// Returns null if no matching entry is found.
        /// </summary>
        public FileTableEntry GetEntry(string path, EntryType type)
        {
            // If there's no path, return the root.
            if (path == "")
            {
                return(rootEntry);
            }

            // Split the string, and make sure that it has parts.
            string[] parts = path.Split('\\');
            if (parts.Length == 0)
            {
                return(null);
            }

            // Locate the entry.
            FileTableEntry result = rootEntry;

            for (int x = 0; x < parts.Length; x++)
            {
                List <FileTableEntry> results = result.GetChildren(new NameFilter(parts[x]),
                                                                   new EntryTypeFilter((x < (parts.Length - 1)) ? EntryType.Folder : type));
                if (results.Count < 1)
                {
                    result = null;
                    break;
                }
                result = results[0];
            }
            return(result != rootEntry ? result : null);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates an entry in the file table with the specified path.
        /// </summary>
        /// <param name="path">The complete path of the entry to add.</param>
        /// <param name="entryType">The type of entry to add.</param>
        public FileTableEntry CreateEntry(string path, EntryType entryType)
        {
            //if (path == @"levels\b30\decals-environment\bitmaps\decal fore symb blue b.bitmap")
            //  Debugger.Break();
            // Seperate the path into its different levels.
            string[] parts = path.Split('\\');

            // Locate the corresponsing node for each level of the path.
            // If a level does not exist, create it.
            FileTableEntry result = rootEntry;

            for (int x = 0; x < parts.Length; x++)
            {
                EntryType             currentType   = (x < parts.Length - 1) ? (EntryType.Folder) : entryType;
                List <FileTableEntry> searchResults = result.GetChildren(
                    new NameFilter(parts[x]), new EntryTypeFilter(currentType));
                if (searchResults.Count == 0)
                {
                    // We didn't find this level of the path, so create the node.
                    // Set it to the proper type if it is the last piece, otherwise it's a folder.
                    result = result.AddChild(parts[x], (x < parts.Length - 1) ? EntryType.Folder : entryType);

                    // Add to the table.
                    AddEntryToTable(result);
                }
                else
                {
                    result = searchResults[0];
                }
            }
            return(result);
        }
Ejemplo n.º 3
0
        public virtual string[] GetFolderList(string path)
        {
            // Make sure that the path we are looking in exists.
            FileTableEntry folder = fileTable.GetEntry(path, EntryType.Folder);

            if (folder == null)
            {
                return(new string[0]);
            }

            // Get the results.
            List <FileTableEntry> entries = folder.GetChildren(new EntryTypeFilter(EntryType.Folder));

            return(FileTableEntry.EntriesToPaths(entries.ToArray()));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Writes the entry and all child entries to disk.
        /// </summary>
        protected void WriteEntries(FileTableEntry startEntry)
        {
            // Get a recursive list of all of the child folders that exist beneath this node.
            List <FileTableEntry> folderEntries = startEntry.GetChildren(true, new EntryTypeFilter(EntryType.Folder));

            foreach (FileTableEntry folderEntry in folderEntries)
            {
                // Write the folder entry.
                folderEntry.Save(diskWriter);

                // Write all of the direct child file entry nodes.
                foreach (FileTableEntry fileEntry in folderEntry.GetChildren(new EntryTypeFilter(EntryType.File)))
                {
                    fileEntry.Save(diskWriter);
                }
            }
        }