/// <summary> /// Opens an existing virtual disk. /// </summary> /// <param name="path">The path of the virtual disk to open, can be a URI</param> /// <param name="access">The desired access to the disk</param> /// <param name="user">The user name to use for authentication (if necessary)</param> /// <param name="password">The password to use for authentication (if necessary)</param> /// <returns>The Virtual Disk, or <c>null</c> if an unknown disk format</returns> public static VirtualDisk OpenDisk(string path, FileAccess access, string user, string password) { Uri uri = PathToUri(path); VirtualDisk result = null; VirtualDiskTransport transport; if (!DiskTransports.TryGetValue(uri.Scheme.ToUpperInvariant(), out transport)) { throw new FileNotFoundException(string.Format(CultureInfo.InvariantCulture, "Unable to parse path '{0}'", path), path); } try { transport.Connect(uri, user, password); if (transport.IsRawDisk) { result = transport.OpenDisk(access); } else { string extension = Path.GetExtension(uri.AbsolutePath).ToUpperInvariant(); if (extension.StartsWith(".", StringComparison.Ordinal)) { extension = extension.Substring(1); } VirtualDiskFactory factory; if (ExtensionMap.TryGetValue(extension, out factory)) { result = factory.OpenDisk(transport.GetFileLocator(), transport.GetFileName(), access); } } if (result != null) { result._transport = transport; transport = null; } return(result); } finally { if (transport != null) { transport.Dispose(); } } }
internal static VirtualDiskLayer OpenDiskLayer(FileLocator locator, string path, FileAccess access) { string extension = Path.GetExtension(path).ToUpperInvariant(); if (extension.StartsWith(".", StringComparison.Ordinal)) { extension = extension.Substring(1); } VirtualDiskFactory factory; if (ExtensionMap.TryGetValue(extension, out factory)) { return(factory.OpenDiskLayer(locator, path, access)); } return(null); }
/// <summary> /// Opens an existing virtual disk, possibly from within an existing disk. /// </summary> /// <param name="fs">The file system to open the disk on.</param> /// <param name="path">The path of the virtual disk to open.</param> /// <param name="access">The desired access to the disk.</param> /// <returns>The Virtual Disk, or <c>null</c> if an unknown disk format.</returns> public static VirtualDisk OpenDisk(DiscFileSystem fs, string path, FileAccess access) { if (fs == null) { return(OpenDisk(path, access)); } string extension = Path.GetExtension(path).ToUpperInvariant(); if (extension.StartsWith(".", StringComparison.Ordinal)) { extension = extension.Substring(1); } VirtualDiskFactory factory; if (ExtensionMap.TryGetValue(extension, out factory)) { return(factory.OpenDisk(fs, path, access)); } return(null); }