public VirtualDirectory GetDirectory(string path, string basePath = "", bool createNew = true) { bool created = false; path = GetFullPath(path, basePath); if (string.IsNullOrEmpty(path)) { return(CurrentDirectory); } if (!Directory.Exists(Path.GetFullPath(path)) && createNew) { created = true; Directory.CreateDirectory(Path.GetFullPath(path)); } DirectoryInfo directory = new DirectoryInfo(Path.GetFullPath(path)); VirtualDirectory result = new VirtualDirectory(directory.Name, new DirectoryInfoContentResolver(directory, created, log)); string parentPath = Path.GetDirectoryName(path); if (!string.IsNullOrEmpty(parentPath) && parentPath != path) { VirtualDirectory parent = GetDirectory(parentPath, basePath, createNew); parent.AddEntry(result); result.SetParent(parent); } return(result); }
public VirtualFile GetFile(string path, string basePath = "") { path = path.CleanPath(); basePath = basePath.CleanPath(); VirtualDirectory directory = GetDirectory(Path.GetDirectoryName(path), basePath, false); FileInfo file = new FileInfo(Path.Combine(directory.FullName, Path.GetFileName(path) ?? "")); VirtualFile result = new VirtualFile(file.Name, new FileInfoContentResolver(file, !file.Exists, log)); result.SetParent(directory); directory.AddEntry(result); return(result); }