private NtObjectContainerEntry GetEntry(NtObjectContainer dir, string path) { int last_slash = path.LastIndexOf('\\'); if (last_slash != -1) { path = path.Substring(last_slash + 1); } return(dir.GetEntry(path)); }
private void AddMatches(NtObjectContainer root, string base_path, IEnumerable <string> remaining, List <string> matches) { string current_entry = remaining.First(); bool is_leaf = remaining.Count() == 1; List <NtObjectContainerEntry> matching_entries = new List <NtObjectContainerEntry>(); if (root.QueryAccessGranted) { // If this is not a leaf point we don't care about non-directory entries. NtObjectContainerEntry[] dir_infos = root.Query().Where(d => is_leaf || d.IsDirectory).ToArray(); foreach (var dir_info in dir_infos) { if (dir_info.Name.Equals(current_entry, StringComparison.OrdinalIgnoreCase)) { matching_entries.Add(dir_info); break; } } // If we didn't find an explicit match then see if it's a glob. if (matching_entries.Count == 0 && PSUtils.HasGlobChars(current_entry)) { Regex globber = PSUtils.GlobToRegex(current_entry, false); foreach (var dir_info in dir_infos) { if (globber.IsMatch(dir_info.Name)) { matching_entries.Add(dir_info); } } } } // Nothing matched. if (matching_entries.Count == 0) { return; } // We've reached the end of the road. if (is_leaf) { foreach (var dir_info in matching_entries) { string full_path = base_path + dir_info.Name; _item_cache[full_path] = GetDrive().DirectoryRoot.CreateEntry(PSPathToNT(full_path), dir_info.Name, dir_info.NtTypeName); matches.Add(full_path); } } else { foreach (var entry in matching_entries) { using (var dir = root.OpenForQuery(entry.Name, false)) { if (!dir.IsSuccess) { continue; } AddMatches(dir.Result, base_path + entry.Name + @"\", remaining.Skip(1), matches); } } } }