private NodeVirtualFileInfo LocateParentNode(VirtualFilePath Path, out string LastPartName) { Path = Path.GetNormalized(); if (Path.IsAbsolute) { return Root.LocateParentNode(Path.FullPath.Substring(1), out LastPartName); } NodeVirtualFileInfo CurrentDirectory = this; var Parts = Path.GetParts(); if (Parts.Length < 1) { LastPartName = ""; return this; } for (int n = 0; n < Parts.Length - 1; n++) { var Part = Parts[n]; CurrentDirectory = CurrentDirectory.GetChild(Part); if (CurrentDirectory == null || !CurrentDirectory.IsDirectory) throw (new FileNotFoundException("Component '" + Part + "' is not a directory in '" + Path + "'", Path)); } LastPartName = Parts[Parts.Length - 1]; return CurrentDirectory; }
async public Task<VirtualFileInfo> GetFileInfoAsync(VirtualFilePath Path) { await ParseZipOnceAsync(); return await TaskEx.RunPropagatingExceptionsAsync<VirtualFileInfo>(() => { throw new NotImplementedException(); //return default(VirtualFileInfo); }); }
internal NodeVirtualFileInfo Open(VirtualFilePath Path) { string FileName; var ParentDirectory = LocateParentNode(Path, out FileName); if (!ParentDirectory.ContainsChild(FileName)) { throw (new IOException("File '" + Path + "' : '" + FileName + "' doesn't Exist")); } return ParentDirectory.GetChild(FileName); }
async public Task<VirtualFileInfo> GetFileInfoAsync(VirtualFilePath Path) { return await Task.Run(() => { try { return ConvertFileSystemInfoToVirtualFileInfo(new FileInfo(GetAbsolutePathFromRelative(Path))); } catch { return new VirtualFileInfo() { Exists = false, }; } }); }
internal NodeVirtualFileInfo Create(VirtualFilePath Path, VirtualFileType CreateType, bool ErrorIfExists) { string FileName; var ParentDirectory = LocateParentNode(Path, out FileName); if (ParentDirectory.ContainsChild(FileName)) { if (ErrorIfExists) { throw (new IOException("File Already Exists")); } else { return ParentDirectory.GetChild(FileName); } } else { return ParentDirectory.AddChild(FileName, CreateType); } }
async public Task<IEnumerable<VirtualFileInfo>> EnumerateDirectoryAsync(VirtualFilePath Path) { return await TaskEx.RunPropagatingExceptionsAsync(() => { var List = new List<VirtualFileInfo>(); foreach (var FileSystemInfo in new DirectoryInfo(GetAbsolutePathFromRelative(Path)).EnumerateFileSystemInfos()) { List.Add(ConvertFileSystemInfoToVirtualFileInfo(FileSystemInfo)); } return List; }); }
async public Task<IVirtualFileStream> OpenAsync(VirtualFilePath Path, FileMode FileMode, FileAccess FileAccess, FileShare FileShare) { return await TaskEx.RunPropagatingExceptionsAsync(() => { var Stream = File.Open(GetAbsolutePathFromRelative(Path), FileMode, FileAccess, FileShare); return new VirtualFileStream(Stream); }); }
async public Task CreateDirectoryAsync(VirtualFilePath Path, DirectorySecurity DirectorySecurity) { await Task.Yield(); Directory.CreateDirectory(GetAbsolutePathFromRelative(Path), DirectorySecurity); }
public Task CreateDirectoryAsync(VirtualFilePath Path, System.Security.AccessControl.DirectorySecurity DirectorySecurity) { throw new NotImplementedException(); }
async public Task<IEnumerable<VirtualFileInfo>> EnumerateDirectoryAsync(VirtualFilePath Path) { await ParseZipOnceAsync(); throw new NotImplementedException(); }
async public Task<IVirtualFileStream> OpenAsync(VirtualFilePath Path, System.IO.FileMode FileMode, System.IO.FileAccess FileAccess, System.IO.FileShare FileShare) { await ParseZipOnceAsync(); throw new NotImplementedException(); }
async public Task CreateDirectoryAsync(VirtualFilePath Path, System.Security.AccessControl.DirectorySecurity DirectorySecurity) { await Task.Yield(); Root.Create(Path, CreateType: VirtualFileType.Directory, ErrorIfExists: true); }
async public Task<IEnumerable<VirtualFileInfo>> EnumerateDirectoryAsync(VirtualFilePath Path) { await Task.Yield(); return Root.Open(Path).Childs; }
async public Task<IVirtualFileStream> OpenAsync(VirtualFilePath Path, FileMode OpenFileMode, FileAccess FileAccess, FileShare FileShare) { NodeVirtualFileInfo Node; switch (OpenFileMode) { case FileMode.Create: case FileMode.CreateNew: case FileMode.OpenOrCreate: case FileMode.Append: Node = Root.Create(Path, CreateType: VirtualFileType.File, ErrorIfExists: OpenFileMode == FileMode.CreateNew); break; default: case FileMode.Open: case FileMode.Truncate: Node = Root.Open(Path); break; } return await Node.OpenAsync(OpenFileMode, FileAccess, FileShare); }
async public Task<VirtualFileInfo> GetFileInfoAsync(VirtualFilePath Path) { await Task.Yield(); return Root.Open(Path); }