示例#1
0
        private void CreateFolderContexMenuButton_Click(object sender, EventArgs e)
        {
            var newFolderPath = JoinPath(CurrentFolderPath.Text, "New folder");

            _virtualFileSystem.AddDirectory(newFolderPath);
            AddFolderToTreeView(new VirtualDirectoryInfo(_virtualFileSystem, newFolderPath));
            RefreshButton_Click(null, null);
        }
示例#2
0
        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);
        }
示例#3
0
        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);
        }