public static VirtualFileSystem GenerateFileSystemFromDirectory1(string realPath) { if (!Directory.Exists(realPath)) { throw new DirectoryNotFoundException($"Directory [{realPath}] not found."); } if (!realPath.EndsWith("\\")) { realPath += "\\"; } var allDirectories = Directory.GetDirectories(realPath, "*", SearchOption.AllDirectories); var allFiles = Directory.GetFiles(realPath, "*.*", SearchOption.AllDirectories); var virtualFileSystem = new VirtualFileSystem(); foreach (var readDirectoryPath in allDirectories) { var virtualDirectoryPath = realPath.ToVirtualPath(readDirectoryPath); virtualFileSystem.AddDirectory(virtualDirectoryPath); } foreach (var realFilePath in allFiles) { var virtualFilePath = realPath.ToVirtualPath(realFilePath); var fileData = File.ReadAllBytes(realFilePath); virtualFileSystem.AddFile(virtualFilePath, new VirtualFileData(fileData)); } return(virtualFileSystem); }
public static VirtualFileSystem GenerateFileSystemFromRealFileSystem(int deep = 2) { var virtualFileSystem = new VirtualFileSystem(); var drives = DriveInfo.GetDrives().Select(x => x.Name); foreach (var drive in drives) { var dirs = GetDirs(drive, deep); dirs.ForEach(d => { if (CanAddDirectory(d)) { virtualFileSystem.AddDirectory(d); foreach (var file in GetFiles(d)) { if (!CanAddFile(file)) { continue; } var info = GetFileData(file); virtualFileSystem.AddFile(file, info); } } }); } return(virtualFileSystem); }
private void PasteContexMenuButton_Click(object sender, EventArgs e) { foreach (var file in _fileToCopyList) { var newFileName = FixPath(file).Replace(FixPath(_folderCopiedFrom), FixPath(CurrentFolderPath.Text)); if (_virtualFileSystem.FileExists(newFileName)) { continue; } if (IsFolder(file)) { if (_copyMode == true) { _virtualFileSystem.AddDirectory(newFileName); } if (_copyMode == false) { new VirtualDirectoryInfo(_virtualFileSystem, file).MoveTo(newFileName); RemoveFolderFromTreeView(file); } AddFolderToTreeView(new VirtualDirectoryInfo(_virtualFileSystem, newFileName)); } else { if (_copyMode == true) { _virtualFileSystem.AddFile(newFileName, _virtualFileSystem.GetFile(file)); } if (_copyMode == false) { new VirtualFileInfo(_virtualFileSystem, file).MoveTo(newFileName); } } } _fileToCopyList.Clear(); _copyMode = null; RefreshButton_Click(null, null); }