public FileSystemResult <IObject> ResolveSynchronous(string path) { try { // Allow either and convert to OS desired later if (path.StartsWith("\\\\") || path.StartsWith("//")) { int idx = path.IndexOf(System.IO.Path.DirectorySeparatorChar, 2); if (idx >= 0) { idx = path.IndexOf(System.IO.Path.DirectorySeparatorChar, idx + 1); if (idx < 0) { idx = path.Length; } } else { idx = path.Length; } string share = path.Substring(0, idx); if (!Directory.Exists(share)) { return(new FileSystemResult <IObject>("Not found")); } if (!FS.Directories.Any(a => a.FullName.Equals(share, StringComparison.InvariantCultureIgnoreCase))) { FS.AddUncPath(share); } } } catch (Exception e) { // Last ditch effort to catch errors, this needs to always succeed. return(new FileSystemResult <IObject>(e.Message)); } if (File.Exists(path) || Directory.Exists(path)) { FileAttributes attr = File.GetAttributes(path); // It's a directory if ((attr & FileAttributes.Directory) == FileAttributes.Directory) { return(new FileSystemResult <IObject>(new LocalDirectory(new DirectoryInfo(path), FS))); } // It's a file return(new FileSystemResult <IObject>(new LocalFile(new FileInfo(path), FS))); } return(new FileSystemResult <IObject>("Not found")); }
public async Task <FileSystemResult <IObject> > ResolveAsync(string path) { try { // Allow either and convert to OS desired later if (path.StartsWith("\\\\") || path.StartsWith("//")) { int idx = path.IndexOf(System.IO.Path.DirectorySeparatorChar, 2); if (idx >= 0) { idx = path.IndexOf(System.IO.Path.DirectorySeparatorChar, idx + 1); if (idx < 0) { idx = path.Length; } } else { idx = path.Length; } string share = path.Substring(0, idx); if (!Directory.Exists(share)) { return(new FileSystemResult <IObject>("Not found")); } if (FS.Directories.All(a => !a.FullName.Equals(share, StringComparison.InvariantCultureIgnoreCase))) { FS.AddUncPath(share); } path = path.Replace(share, share.Replace('\\', '*')); path = path.Replace(share, share.Replace('/', '*')); } } catch (Exception e) { // Last ditch effort to catch errors, this needs to always succeed. return(new FileSystemResult <IObject>(e.Message)); } return(await Refs.ObjectFromPath(this, path)); }