/// <summary> /// Initializes a new instance of the Disk class. /// </summary> /// <param name="fileSystem">The file system containing the disk.</param> /// <param name="path">The file system relative path to the disk.</param> /// <param name="access">The access requested to the disk.</param> public Disk(DiscFileSystem fileSystem, string path, FileAccess access) { _path = path; FileLocator fileLocator = new DiscFileLocator(fileSystem, Utilities.GetDirectoryFromPath(path)); _files = new List<ThinkAway.Tuple<VirtualDiskLayer, Ownership>>(); _files.Add(new ThinkAway.Tuple<VirtualDiskLayer, Ownership>(new DiskImageFile(fileLocator, Utilities.GetFileFromPath(path), access), Ownership.Dispose)); ResolveFileChain(); }
internal DiscFileSystemInfo(DiscFileSystem fileSystem, string path) { if (path == null) { throw new ArgumentNullException("path"); } _fileSystem = fileSystem; _path = path.Trim('\\'); }
/// <summary> /// Creates a new virtual disk as a thin clone of an existing disk. /// </summary> /// <param name="fileSystem">The file system to contain the disk</param> /// <param name="path">The path to the new disk.</param> /// <param name="type">The type of disk to create</param> /// <param name="parentPath">The path to the parent disk.</param> /// <returns>The new disk.</returns> public static Disk InitializeDifferencing(DiscFileSystem fileSystem, string path, DiskCreateType type, string parentPath) { return new Disk(DiskImageFile.InitializeDifferencing(fileSystem, path, type, parentPath), Ownership.Dispose); }
/// <summary> /// Create a new differencing disk, possibly within an existing disk. /// </summary> /// <param name="fileSystem">The file system to create the disk on</param> /// <param name="path">The path (or URI) for the disk to create</param> /// <returns>The newly created disk</returns> public override VirtualDisk CreateDifferencingDisk(DiscFileSystem fileSystem, string path) { throw new NotSupportedException("Differencing disks not supported by XVA format"); }
/// <summary> /// Creates a new virtual disk at the specified path. /// </summary> /// <param name="fileSystem">The file system to create the VMDK on</param> /// <param name="path">The name of the VMDK to create.</param> /// <param name="capacity">The desired capacity of the new disk</param> /// <param name="createType">The type of virtual disk to create</param> /// <param name="adapterType">The type of disk adapter used with the disk</param> /// <returns>The newly created disk image</returns> public static DiskImageFile Initialize(DiscFileSystem fileSystem, string path, long capacity, DiskCreateType createType, DiskAdapterType adapterType) { DiskParameters diskParams = new DiskParameters(); diskParams.Capacity = capacity; diskParams.CreateType = createType; diskParams.AdapterType = adapterType; return Initialize(fileSystem, path, diskParams); }
/// <summary> /// Create a new differencing disk, possibly within an existing disk. /// </summary> /// <param name="fileSystem">The file system to create the disk on</param> /// <param name="path">The path (or URI) for the disk to create</param> /// <returns>The newly created disk</returns> public abstract VirtualDisk CreateDifferencingDisk(DiscFileSystem fileSystem, string path);
private void DoCopyFile(DiscFileSystem srcFs, string srcPath, DiscFileSystem destFs, string destPath) { IWindowsFileSystem destWindowsFs = destFs as IWindowsFileSystem; IWindowsFileSystem srcWindowsFs = srcFs as IWindowsFileSystem; using (Stream src = srcFs.OpenFile(srcPath, FileMode.Open, FileAccess.Read)) using (Stream dest = destFs.OpenFile(destPath, FileMode.Create, FileAccess.ReadWrite)) { dest.SetLength(src.Length); byte[] buffer = new byte[1024 * 1024]; int numRead = src.Read(buffer, 0, buffer.Length); while (numRead > 0) { dest.Write(buffer, 0, numRead); numRead = src.Read(buffer, 0, buffer.Length); } } if (srcWindowsFs != null && destWindowsFs != null) { if ((srcWindowsFs.GetAttributes(srcPath) & FileAttributes.ReparsePoint) != 0) { destWindowsFs.SetReparsePoint(destPath, srcWindowsFs.GetReparsePoint(srcPath)); } var sd = srcWindowsFs.GetSecurity(srcPath); if(sd != null) { destWindowsFs.SetSecurity(destPath, sd); } } destFs.SetAttributes(destPath, srcFs.GetAttributes(srcPath)); destFs.SetCreationTimeUtc(destPath, srcFs.GetCreationTimeUtc(srcPath)); }
/// <summary> /// Initializes a new instance of the VfsFileSystemFacade class. /// </summary> /// <param name="toWrap">The actual file system instance.</param> protected VfsFileSystemFacade(DiscFileSystem toWrap) { _wrapped = toWrap; }
/// <summary> /// Creates a new virtual disk as a thin clone of an existing disk. /// </summary> /// <param name="fileSystem">The file system to contain the disk</param> /// <param name="path">The path to the new disk.</param> /// <param name="type">The type of disk to create</param> /// <param name="parentPath">The path to the parent disk.</param> /// <returns>The new disk.</returns> public static Disk InitializeDifferencing(DiscFileSystem fileSystem, string path, DiskCreateType type, string parentPath) { return(new Disk(DiskImageFile.InitializeDifferencing(fileSystem, path, type, parentPath), Ownership.Dispose)); }
public StreamWrapper(DiscFileSystem fileSystem, string path, FileAccess access) { _fileSystem = fileSystem; _path = path; _access = access; }
private object FindItemByPath(string path, bool preferFs, bool readOnly) { FileAccess fileAccess = readOnly ? FileAccess.Read : FileAccess.ReadWrite; string diskPath; string relPath; int mountSepIdx = path.IndexOf('!'); if (mountSepIdx < 0) { diskPath = path; relPath = ""; } else { diskPath = path.Substring(0, mountSepIdx); relPath = path.Substring(mountSepIdx + 1); } VirtualDisk disk = Disk; if (disk == null) { OnDemandVirtualDisk odvd = new OnDemandVirtualDisk(Utilities.DenormalizePath(diskPath), fileAccess); if (odvd.IsValid) { disk = odvd; ShowSlowDiskWarning(); } else { return(null); } } List <string> pathElems = new List <string>(relPath.Split(new string[] { @"\" }, StringSplitOptions.RemoveEmptyEntries)); if (pathElems.Count == 0) { return(disk); } VolumeInfo volInfo = null; VolumeManager volMgr = DriveInfo != null ? DriveInfo.VolumeManager : new VolumeManager(disk); LogicalVolumeInfo[] volumes = volMgr.GetLogicalVolumes(); string volNumStr = pathElems[0].StartsWith("Volume", StringComparison.OrdinalIgnoreCase) ? pathElems[0].Substring(6) : null; int volNum; if (int.TryParse(volNumStr, out volNum) || volNum < 0 || volNum >= volumes.Length) { volInfo = volumes[volNum]; } else { volInfo = volMgr.GetVolume(Utilities.DenormalizePath(pathElems[0])); } pathElems.RemoveAt(0); if (volInfo == null || (pathElems.Count == 0 && !preferFs)) { return(volInfo); } bool disposeFs; DiscFileSystem fs = GetFileSystem(volInfo, out disposeFs); try { if (fs == null) { return(null); } // Special marker in the path - disambiguates the root folder from the volume // containing it. By this point it's done it's job (we didn't return volInfo), // so we just remove it. if (pathElems.Count > 0 && pathElems[0] == "$Root") { pathElems.RemoveAt(0); } string fsPath = string.Join(@"\", pathElems.ToArray()); if (fs.DirectoryExists(fsPath)) { return(fs.GetDirectoryInfo(fsPath)); } else if (fs.FileExists(fsPath)) { return(fs.GetFileInfo(fsPath)); } } finally { if (disposeFs && fs != null) { fs.Dispose(); } } return(null); }
public VirtualDisk OpenDisk(DiscFileSystem fileSystem, string path, FileAccess access) { return(OpenDisk(new DiscFileLocator(fileSystem, @"\"), path, access)); }
public void Parent_Root(NewFileSystemDelegate fsFactory) { DiscFileSystem fs = fsFactory(); Assert.Null(fs.Root.Parent); }
public void GetDirectories_BadPath(NewFileSystemDelegate fsFactory) { DiscFileSystem fs = fsFactory(); Assert.Throws <DirectoryNotFoundException>(() => fs.GetDirectories(@"\baddir")); }
public void DeleteRoot(NewFileSystemDelegate fsFactory) { DiscFileSystem fs = fsFactory(); Assert.Throws <IOException>(() => fs.Root.Delete()); }
protected override void DoRun() { DiscUtils.FileSystems.SetupHelper.SetupFileSystems(); Console.OutputEncoding = Encoding.UTF8; List <VirtualDisk> disks = new List <VirtualDisk>(); foreach (var path in _inFiles.Values) { VirtualDisk disk = VirtualDisk.OpenDisk(path, _diskType.IsPresent ? _diskType.Value : null, FileAccess.Read, UserName, Password); disks.Add(disk); Console.WriteLine(); Console.WriteLine("DISK: " + path); Console.WriteLine(); Console.WriteLine(" Capacity: {0:X16}", disk.Capacity); Console.WriteLine(" Geometry: {0}", disk.Geometry); Console.WriteLine(" BIOS Geometry: {0}", disk.BiosGeometry); Console.WriteLine(" Signature: {0:X8}", disk.Signature); if (disk.IsPartitioned) { Console.WriteLine(" GUID: {0}", disk.Partitions.DiskGuid); } Console.WriteLine(); if (!_hideExtents.IsPresent) { Console.WriteLine(); Console.WriteLine(" Stored Extents"); Console.WriteLine(); foreach (var extent in disk.Content.Extents) { Console.WriteLine(" {0:X16} - {1:X16}", extent.Start, extent.Start + extent.Length); } Console.WriteLine(); } if (_showBootCode.IsPresent) { Console.WriteLine(); Console.WriteLine(" Master Boot Record (MBR)"); Console.WriteLine(); try { byte[] mbr = new byte[512]; disk.Content.Position = 0; disk.Content.Read(mbr, 0, 512); HexDump.Generate(mbr, Console.Out); } catch (Exception e) { Console.WriteLine(e.ToString()); } Console.WriteLine(); } Console.WriteLine(); Console.WriteLine(" Partitions"); Console.WriteLine(); if (disk.IsPartitioned) { Console.WriteLine(" T Start (bytes) End (bytes) Type"); Console.WriteLine(" == ================ ================ =================="); foreach (var partition in disk.Partitions.Partitions) { Console.WriteLine(" {0:X2} {1:X16} {2:X16} {3}", partition.BiosType, partition.FirstSector * disk.SectorSize, (partition.LastSector + 1) * disk.SectorSize, partition.TypeAsString); BiosPartitionInfo bpi = partition as BiosPartitionInfo; if (bpi != null) { Console.WriteLine(" {0,-16} {1}", bpi.Start.ToString(), bpi.End.ToString()); Console.WriteLine(); } } } else { Console.WriteLine(" No partitions"); Console.WriteLine(); } } Console.WriteLine(); Console.WriteLine(); Console.WriteLine("VOLUMES"); Console.WriteLine(); VolumeManager volMgr = new VolumeManager(); foreach (var disk in disks) { volMgr.AddDisk(disk); } try { Console.WriteLine(); Console.WriteLine(" Physical Volumes"); Console.WriteLine(); foreach (var vol in volMgr.GetPhysicalVolumes()) { Console.WriteLine(" " + vol.Identity); Console.WriteLine(" Type: " + vol.VolumeType); Console.WriteLine(" BIOS Type: " + vol.BiosType.ToString("X2") + " [" + BiosPartitionTypes.ToString(vol.BiosType) + "]"); Console.WriteLine(" Size: " + vol.Length); Console.WriteLine(" Disk Id: " + vol.DiskIdentity); Console.WriteLine(" Disk Sig: " + vol.DiskSignature.ToString("X8")); Console.WriteLine(" Partition: " + vol.PartitionIdentity); Console.WriteLine(" Disk Geometry: " + vol.PhysicalGeometry); Console.WriteLine(" BIOS Geometry: " + vol.BiosGeometry); Console.WriteLine(" First Sector: " + vol.PhysicalStartSector); Console.WriteLine(); } } catch (Exception e) { Console.WriteLine(e.ToString()); } try { Console.WriteLine(); Console.WriteLine(" Logical Volumes"); Console.WriteLine(); foreach (var vol in volMgr.GetLogicalVolumes()) { Console.WriteLine(" " + vol.Identity); Console.WriteLine(" BIOS Type: " + vol.BiosType.ToString("X2") + " [" + BiosPartitionTypes.ToString(vol.BiosType) + "]"); Console.WriteLine(" Status: " + vol.Status); Console.WriteLine(" Size: " + vol.Length); Console.WriteLine(" Disk Geometry: " + vol.PhysicalGeometry); Console.WriteLine(" BIOS Geometry: " + vol.BiosGeometry); Console.WriteLine(" First Sector: " + vol.PhysicalStartSector); if (vol.Status == LogicalVolumeStatus.Failed) { Console.WriteLine(" File Systems: <unknown - failed volume>"); Console.WriteLine(); continue; } DiscUtils.FileSystemInfo[] fileSystemInfos = FileSystemManager.DetectFileSystems(vol); Console.WriteLine(" File Systems: " + string.Join <DiscUtils.FileSystemInfo>(", ", fileSystemInfos)); Console.WriteLine(); if (_showVolContent.IsPresent) { Console.WriteLine(" Binary Contents..."); try { using (Stream s = vol.Open()) { HexDump.Generate(s, Console.Out); } } catch (Exception e) { Console.WriteLine(e.ToString()); } Console.WriteLine(); } if (_showBootCode.IsPresent) { foreach (var fsi in fileSystemInfos) { Console.WriteLine(" Boot Code: {0}", fsi.Name); try { using (DiscFileSystem fs = fsi.Open(vol, FileSystemParameters)) { byte[] bootCode = fs.ReadBootCode(); if (bootCode != null) { HexDump.Generate(bootCode, Console.Out); } else { Console.WriteLine(" <file system reports no boot code>"); } } } catch (Exception e) { Console.WriteLine(" Unable to show boot code: " + e.Message); } Console.WriteLine(); } } if (_showFiles.IsPresent) { foreach (var fsi in fileSystemInfos) { using (DiscFileSystem fs = fsi.Open(vol, FileSystemParameters)) { Console.WriteLine(" {0} Volume Label: {1}", fsi.Name, fs.VolumeLabel); Console.WriteLine(" Files ({0})...", fsi.Name); ShowDir(fs.Root, 6); } Console.WriteLine(); } } } } catch (Exception e) { Console.WriteLine(e.ToString()); } try { bool foundDynDisk = false; DynamicDiskManager dynDiskManager = new DynamicDiskManager(); foreach (var disk in disks) { if (DynamicDiskManager.IsDynamicDisk(disk)) { dynDiskManager.Add(disk); foundDynDisk = true; } } if (foundDynDisk) { Console.WriteLine(); Console.WriteLine(" Logical Disk Manager Info"); Console.WriteLine(); dynDiskManager.Dump(Console.Out, " "); } } catch (Exception e) { Console.WriteLine(e.ToString()); } if (_showContent.IsPresent) { foreach (var path in _inFiles.Values) { VirtualDisk disk = VirtualDisk.OpenDisk(path, FileAccess.Read, UserName, Password); Console.WriteLine(); Console.WriteLine("DISK CONTENTS ({0})", path); Console.WriteLine(); HexDump.Generate(disk.Content, Console.Out); Console.WriteLine(); } } }
public OnDemandVirtualDisk(DiscFileSystem fileSystem, string path, FileAccess access) { _fileSystem = fileSystem; _path = path; _access = access; }
/// <summary> /// Create a new differencing disk, possibly within an existing disk. /// </summary> /// <param name="fileSystem">The file system to create the disk on.</param> /// <param name="path">The path (or URI) for the disk to create.</param> /// <returns>The newly created disk.</returns> public override VirtualDisk CreateDifferencingDisk(DiscFileSystem fileSystem, string path) { throw new NotImplementedException("Differencing disks not implemented for the VDI format"); }
/// <summary> /// Initializes a new instance of the VfsFileSystemFacade class. /// </summary> /// <param name="toWrap">The actual file system instance</param> internal VfsFileSystemFacade(DiscFileSystem toWrap) { _wrapped = toWrap; }
/// <summary> /// Not supported for Optical Discs. /// </summary> /// <param name="fileSystem">The file system to create the disc on</param> /// <param name="path">The path (or URI) for the disk to create</param> /// <returns>Not Applicable</returns> public override VirtualDisk CreateDifferencingDisk(DiscFileSystem fileSystem, string path) { throw new NotSupportedException("Differencing disks not supported for optical disks"); }
public void Delete_NoFile(NewFileSystemDelegate fsFactory) { DiscFileSystem fs = fsFactory(); Assert.Throws <FileNotFoundException>(() => fs.GetFileInfo("foo.txt").Delete()); }
/// <summary> /// Create a new virtual disk, possibly within an existing disk. /// </summary> /// <param name="fileSystem">The file system to create the disk on</param> /// <param name="type">The type of disk to create (see <see cref="SupportedDiskTypes"/>)</param> /// <param name="variant">The variant of the type to create (see <see cref="GetSupportedDiskVariants"/>)</param> /// <param name="path">The path (or URI) for the disk to create</param> /// <param name="capacity">The capacity of the new disk</param> /// <param name="geometry">The geometry of the new disk (or null).</param> /// <param name="parameters">Untyped parameters controlling the creation process (TBD)</param> /// <returns>The newly created disk</returns> public static VirtualDisk CreateDisk(DiscFileSystem fileSystem, string type, string variant, string path, long capacity, Geometry geometry, Dictionary<string, string> parameters) { VirtualDiskFactory factory = TypeMap[type]; VirtualDiskParameters diskParams = new VirtualDiskParameters() { AdapterType = GenericDiskAdapterType.Scsi, Capacity = capacity, Geometry = geometry, }; if (parameters != null) { foreach (var key in parameters.Keys) { diskParams.ExtendedParameters[key] = parameters[key]; } } return factory.CreateDisk(new DiscFileLocator(fileSystem, Utilities.GetDirectoryFromPath(path)), variant.ToLowerInvariant(), Utilities.GetFileFromPath(path), diskParams); }
public void Equals(NewFileSystemDelegate fsFactory) { DiscFileSystem fs = fsFactory(); Assert.Equal(fs.GetFileInfo("foo.txt"), fs.GetFileInfo("foo.txt")); }
public VirtualDisk OpenDisk(DiscFileSystem fileSystem, string path, FileAccess access) { return OpenDisk(new DiscFileLocator(fileSystem, @"\"), path, access); }
public override VirtualDisk CreateDifferencingDisk(DiscFileSystem fileSystem, string path) { using (VirtualDisk disk = OpenDisk()) { return disk.CreateDifferencingDisk(fileSystem, path); } }
/// <summary> /// Create a new differencing disk, possibly within an existing disk. /// </summary> /// <param name="fileSystem">The file system to create the disk on</param> /// <param name="path">The path (or URI) for the disk to create</param> /// <returns>The newly created disk</returns> public override VirtualDisk CreateDifferencingDisk(DiscFileSystem fileSystem, string path) { FileLocator locator = new DiscFileLocator(fileSystem, Utilities.GetDirectoryFromPath(path)); DiskImageFile file = _files[0].First.CreateDifferencing(locator, Utilities.GetFileFromPath(path)); return new Disk(file, Ownership.Dispose); }
public StreamWrapper(DiscFileSystem fileSystem, string path, FileAccess access) { _fileSystem = fileSystem; _path = path; _access = access; }
/// <summary> /// Creates a new instance from a file on a file system. /// </summary> /// <param name="fileSystem">The file system containing the disk.</param> /// <param name="path">The file system relative path to the disk.</param> /// <param name="access">The access requested to the disk.</param> public Disk(DiscFileSystem fileSystem, string path, FileAccess access) { FileLocator fileLocator = new DiscFileLocator(fileSystem, Path.GetDirectoryName(path)); DiskImageFile file = new DiskImageFile(fileLocator, Path.GetFileName(path), access); _files = new List<Tuple<DiskImageFile, Ownership>>(); _files.Add(new Tuple<DiskImageFile, Ownership>(file, Ownership.Dispose)); ResolveFileChain(); }
public OnDemandVirtualDisk(DiscFileSystem fileSystem, string path, FileAccess access) { _fileSystem = fileSystem; _path = path; _access = access; }
/// <summary> /// Create a new differencing disk, possibly within an existing disk. /// </summary> /// <param name="fileSystem">The file system to create the disk on</param> /// <param name="path">The path (or URI) for the disk to create</param> /// <returns>The newly created disk</returns> public override VirtualDisk CreateDifferencingDisk(DiscFileSystem fileSystem, string path) { return InitializeDifferencing(fileSystem, path, DiffDiskCreateType(_files[0].First), _path); }
/// <summary> /// Initializes a new instance of the <see cref="DiscFsFileLocator"/> class. /// </summary> /// <param name="root">The root path.</param> /// <param name="create">The create function.</param> protected DiscFsFileLocator(string root, Func <Stream, DiscFileSystem> create) { this.fileStream = File.OpenRead(root); this.disc = create(this.fileStream); }
/// <summary> /// Creates a new virtual disk at the specified path. /// </summary> /// <param name="fileSystem">The file system to create the disk on.</param> /// <param name="path">The name of the VMDK to create.</param> /// <param name="parameters">The desired parameters for the new disk.</param> /// <returns>The newly created disk image</returns> public static DiskImageFile Initialize(DiscFileSystem fileSystem, string path, DiskParameters parameters) { FileLocator locator = new DiscFileLocator(fileSystem, Path.GetDirectoryName(path)); return(Initialize(locator, Path.GetFileName(path), parameters)); }
/// <summary> /// Initializes a new instance of the <see cref="DiscFsFileLocator"/> class. /// </summary> /// <param name="root">A stream.</param> /// <param name="create">The create function.</param> protected DiscFsFileLocator(Stream root, Func <Stream, DiscFileSystem> create) { this.disc = create(root); }
/// <summary> /// Creates a new virtual disk at the specified location on a file system. /// </summary> /// <param name="fileSystem">The file system to contain the disk</param> /// <param name="path">The file system path to the disk</param> /// <param name="capacity">The desired capacity of the new disk</param> /// <param name="type">The type of virtual disk to create</param> /// <param name="adapterType">The type of virtual disk adapter</param> /// <returns>The newly created disk image</returns> public static Disk Initialize(DiscFileSystem fileSystem, string path, long capacity, DiskCreateType type, DiskAdapterType adapterType) { return(new Disk(DiskImageFile.Initialize(fileSystem, path, capacity, type, adapterType), Ownership.Dispose)); }
public DiscFileLocator(DiscFileSystem fileSystem, string basePath) { _fileSystem = fileSystem; _basePath = basePath; }
/// <summary> /// Create a new differencing disk, possibly within an existing disk. /// </summary> /// <param name="fileSystem">The file system to create the disk on</param> /// <param name="path">The path (or URI) for the disk to create</param> /// <returns>The newly created disk</returns> public override VirtualDisk CreateDifferencingDisk(DiscFileSystem fileSystem, string path) { return(InitializeDifferencing(fileSystem, path, DiffDiskCreateType(_files[0].First.CreateType), _path)); }
/// <summary> /// Initializes a new instance of the DiscDirectoryInfo class. /// </summary> /// <param name="fileSystem">The file system the directory info relates to</param> /// <param name="path">The path within the file system of the directory</param> internal DiscDirectoryInfo(DiscFileSystem fileSystem, string path) : base(fileSystem, path) { }
public FileSystemHandler(Core core) { this.core = core; discFs = core.discFs; }
/// <summary> /// Create a new differencing disk, possibly within an existing disk. /// </summary> /// <param name="fileSystem">The file system to create the disk on</param> /// <param name="path">The path (or URI) for the disk to create</param> /// <returns>The newly created disk</returns> public override VirtualDisk CreateDifferencingDisk(DiscFileSystem fileSystem, string path) { throw new NotSupportedException(); }
/// <summary> /// Create a new differencing disk, possibly within an existing disk. /// </summary> /// <param name="fileSystem">The file system to create the disk on.</param> /// <param name="path">The path (or URI) for the disk to create.</param> /// <returns>The newly created disk.</returns> public override VirtualDisk CreateDifferencingDisk(DiscFileSystem fileSystem, string path) { throw new NotSupportedException(); }
private static void DiffPart(DiscFileSystem PartA, DiscFileSystem PartB, DiscFileSystem Output, ComparisonStyle Style = ComparisonStyle.DateTimeOnly, CopyQueue WriteQueue = null) { if (PartA == null) { throw new ArgumentNullException("PartA"); } if (PartB == null) { throw new ArgumentNullException("PartB"); } if (Output == null) { throw new ArgumentNullException("Output"); } if (PartA is NtfsFileSystem) { ((NtfsFileSystem)PartA).NtfsOptions.HideHiddenFiles = false; ((NtfsFileSystem)PartA).NtfsOptions.HideSystemFiles = false; } if (PartB is NtfsFileSystem) { ((NtfsFileSystem)PartB).NtfsOptions.HideHiddenFiles = false; ((NtfsFileSystem)PartB).NtfsOptions.HideSystemFiles = false; } if (Output is NtfsFileSystem) { ((NtfsFileSystem)Output).NtfsOptions.HideHiddenFiles = false; ((NtfsFileSystem)Output).NtfsOptions.HideSystemFiles = false; } if (WriteQueue == null) { WriteQueue = new CopyQueue(); } var RootA = PartA.Root; var RootB = PartB.Root; var OutRoot = Output.Root; var OutFileRoot = Output.GetDirectoryInfo(RootFiles); if (!OutFileRoot.Exists) { OutFileRoot.Create(); } CompareTree(RootA, RootB, OutFileRoot, WriteQueue, Style); WriteQueue.Go(); // Now handle registry files (if any) ParallelQuery <DiscFileInfo> Ofiles; lock (OutFileRoot.FileSystem) Ofiles = OutFileRoot.GetFiles("*.*", SearchOption.AllDirectories).AsParallel(); Ofiles = Ofiles.Where(dfi => SystemRegistryFiles.Contains(dfi.FullName, StringComparer.CurrentCultureIgnoreCase)); foreach (var file in Ofiles) { var A = PartA.GetFileInfo(file.FullName.Substring(RootFiles.Length + 1)); if (!A.Exists) { file.FileSystem.MoveFile(file.FullName, String.Concat(RootSystemRegistry, A.FullName)); continue; } //else MemoryStream SideA = new MemoryStream(); using (var tmp = A.OpenRead()) tmp.CopyTo(SideA); MemoryStream SideB = new MemoryStream(); using (var tmp = file.OpenRead()) tmp.CopyTo(SideB); var comp = new RegistryComparison(SideA, SideB, RegistryComparison.Side.B); comp.DoCompare(); var diff = new RegDiff(comp, RegistryComparison.Side.B); var outFile = Output.GetFileInfo(Path.Combine(RootSystemRegistry, file.FullName)); if (!outFile.Directory.Exists) { outFile.Directory.Create(); } using (var OUT = outFile.Open(outFile.Exists ? FileMode.Truncate : FileMode.CreateNew, FileAccess.ReadWrite)) diff.WriteToStream(OUT); file.Delete(); // remove this file from the set of file to copy and overwrite } lock (OutFileRoot.FileSystem) Ofiles = OutFileRoot.GetFiles("*.*", SearchOption.AllDirectories).AsParallel(); Ofiles = Ofiles.Where(dfi => UserRegisrtyFiles.IsMatch(dfi.FullName)); foreach (var file in Ofiles) { var match = UserRegisrtyFiles.Match(file.FullName); var A = PartA.GetFileInfo(file.FullName.Substring(RootFiles.Length + 1)); if (!A.Exists) { file.FileSystem.MoveFile(file.FullName, Path.Combine(RootUserRegistry, match.Groups["user"].Value, A.Name)); continue; } //else MemoryStream SideA = new MemoryStream(); using (var tmp = A.OpenRead()) tmp.CopyTo(SideA); MemoryStream SideB = new MemoryStream(); using (var tmp = file.OpenRead()) tmp.CopyTo(SideB); var comp = new RegistryComparison(SideA, SideB, RegistryComparison.Side.B); comp.DoCompare(); var diff = new RegDiff(comp, RegistryComparison.Side.B); var outFile = Output.GetFileInfo(Path.Combine(RootUserRegistry, match.Groups["user"].Value, file.FullName)); if (!outFile.Directory.Exists) { outFile.Directory.Create(); } using (var OUT = outFile.Open(outFile.Exists ? FileMode.Truncate : FileMode.CreateNew, FileAccess.ReadWrite)) diff.WriteToStream(OUT); file.Delete(); // remove this file from the set of file to copy and overwrite } }
private void DoCopyDirectory(DiscFileSystem srcFs, string srcPath, DiscFileSystem destFs, string destPath) { IWindowsFileSystem destWindowsFs = destFs as IWindowsFileSystem; IWindowsFileSystem srcWindowsFs = srcFs as IWindowsFileSystem; destFs.CreateDirectory(destPath); if (srcWindowsFs != null && destWindowsFs != null) { if ((srcWindowsFs.GetAttributes(srcPath) & FileAttributes.ReparsePoint) != 0) { destWindowsFs.SetReparsePoint(destPath, srcWindowsFs.GetReparsePoint(srcPath)); } destWindowsFs.SetSecurity(destPath, srcWindowsFs.GetSecurity(srcPath)); } destFs.SetAttributes(destPath, srcFs.GetAttributes(srcPath)); }
private static bool IsBDJava(DiscFileSystem fs) { return(HasFiles(fs.Directories.BDJO)); }
private void DoRecursiveCopy(DiscFileSystem srcFs, string srcPath, DiscFileSystem destFs, string destPath) { foreach (var dir in srcFs.GetDirectories(srcPath)) { string srcDirPath = Path.Combine(srcPath, dir); string destDirPath = Path.Combine(destPath, dir); DoCopyDirectory(srcFs, srcDirPath, destFs, destDirPath); DoRecursiveCopy(srcFs, srcDirPath, destFs, destDirPath); } foreach (var file in srcFs.GetFiles(srcPath)) { string srcFilePath = Path.Combine(srcPath, file); string destFilePath = Path.Combine(destPath, file); DoCopyFile(srcFs, srcFilePath, destFs, destFilePath); } }
private static bool Is3D(DiscFileSystem fs) { return(HasFiles(fs.Directories.SSIF)); }
/// <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; }
private static bool IsDbox(DiscFileSystem fs) { return(File.Exists(Path.Combine(fs.Directories.Root.FullName, "FilmIndex.xml"))); }
/// <summary> /// Creates a new virtual disk at the specified path. /// </summary> /// <param name="fileSystem">The file system to create the disk on.</param> /// <param name="path">The name of the VMDK to create.</param> /// <param name="parameters">The desired parameters for the new disk.</param> /// <returns>The newly created disk image</returns> public static DiskImageFile Initialize(DiscFileSystem fileSystem, string path, DiskParameters parameters) { FileLocator locator = new DiscFileLocator(fileSystem, Utilities.GetDirectoryFromPath(path)); return Initialize(locator, Utilities.GetFileFromPath(path), parameters); }
private static bool IsDCopy(DiscFileSystem fs) { return(HasFiles(fs.Directories.DCOPY)); }
/// <summary> /// Creates a new virtual disk at the specified path. /// </summary> /// <param name="fileSystem">The file system to create the disk on.</param> /// <param name="path">The name of the VMDK to create.</param> /// <param name="parameters">The desired parameters for the new disk.</param> /// <returns>The newly created disk image</returns> public static DiskImageFile Initialize(DiscFileSystem fileSystem, string path, DiskParameters parameters) { FileLocator locator = new DiscFileLocator(fileSystem, Path.GetDirectoryName(path)); return Initialize(locator, Path.GetFileName(path), parameters); }
private static bool IsPSP(DiscFileSystem fs) { return(fs.Directories.SNP != null && (HasFiles(fs.Directories.SNP, "*.mnv") || HasFiles(fs.Directories.SNP, "*.MNV"))); }
/// <summary> /// Creates a new virtual disk that is a linked clone of an existing disk. /// </summary> /// <param name="fileSystem">The file system to create the VMDK on</param> /// <param name="path">The path to the new disk</param> /// <param name="type">The type of the new disk</param> /// <param name="parent">The disk to clone</param> /// <returns>The new virtual disk</returns> public static DiskImageFile InitializeDifferencing(DiscFileSystem fileSystem, string path, DiskCreateType type, string parent) { if (type != DiskCreateType.MonolithicSparse && type != DiskCreateType.TwoGbMaxExtentSparse && type != DiskCreateType.VmfsSparse) { throw new ArgumentException("Differencing disks must be sparse", "type"); } string basePath = Path.GetDirectoryName(path); FileLocator locator = new DiscFileLocator(fileSystem, basePath); FileLocator parentLocator = locator.GetRelativeLocator(Path.GetDirectoryName(parent)); using (DiskImageFile parentFile = new DiskImageFile(parentLocator, Path.GetFileName(parent), FileAccess.Read)) { DescriptorFile baseDescriptor = CreateDifferencingDiskDescriptor(type, parentFile, parent); return DoInitialize(locator, Path.GetFileName(path), parentFile.Capacity, type, baseDescriptor); } }
private static DirectoryInfo GetAACSDirectory(DiscFileSystem fs) { return(fs.Directories.ANY ?? GetDirectory("AACS", fs.Directories.MAKEMKV) ?? GetDirectory("AACS", fs.Directories.Root)); }
/// <summary> /// Initializes a new instance of the Disk class. Differencing disks are supported. /// </summary> /// <param name="fileSystem">The file system containing the disk.</param> /// <param name="path">The file system relative path to the disk.</param> /// <param name="access">The access requested to the disk.</param> public Disk(DiscFileSystem fileSystem, string path, FileAccess access) { FileLocator fileLocator = new DiscFileLocator(fileSystem, Utilities.GetDirectoryFromPath(path)); DiskImageFile file = new DiskImageFile(fileLocator, Utilities.GetFileFromPath(path), access); _files = new List<DiscUtils.Tuple<DiskImageFile, Ownership>>(); _files.Add(new DiscUtils.Tuple<DiskImageFile, Ownership>(file, Ownership.Dispose)); ResolveFileChain(); }
private static DirectoryInfo GetDCopyDirectory(DiscFileSystem fs) { var dir = new DirectoryInfo(Path.Combine(fs.Directories.Root.FullName, "DCOPY")); return(dir.Exists ? dir : null); }
/// <summary> /// Create a new differencing disk, possibly within an existing disk. /// </summary> /// <param name="fileSystem">The file system to create the disk on</param> /// <param name="path">The path (or URI) for the disk to create</param> /// <returns>The newly created disk</returns> public override VirtualDisk CreateDifferencingDisk(DiscFileSystem fileSystem, string path) { throw new NotImplementedException("Differencing disks not implemented for the VDI format"); }
/// <summary> /// Creates a new virtual disk at the specified location on a file system. /// </summary> /// <param name="fileSystem">The file system to contain the disk</param> /// <param name="path">The file system path to the disk</param> /// <param name="capacity">The desired capacity of the new disk</param> /// <param name="type">The type of virtual disk to create</param> /// <param name="adapterType">The type of virtual disk adapter</param> /// <returns>The newly created disk image</returns> public static Disk Initialize(DiscFileSystem fileSystem, string path, long capacity, DiskCreateType type, DiskAdapterType adapterType) { return new Disk(DiskImageFile.Initialize(fileSystem, path, capacity, type, adapterType), Ownership.Dispose); }