public override void PerformStep()
        {
            logger.LogInformation("Fixing cloned OS registry.");

            string vhdFullName = $"{migrationData.VhdFileTemporaryFolder}\\{migrationData.VhdFileName}";

            using (VirtualDiskDecorator disk = this.fileSystemHelper.OpenVhdx(vhdFullName))
            {
                PartitionInfoDecorator clonedPartition = disk.Partitions[0];
                using (Stream partitionStream = clonedPartition.Open())
                {
                    using (DiscFileSystem ntfs = this.fileSystemHelper.OpenNtfsFileSystem(partitionStream))
                    {
                        if (ntfs is NtfsFileSystem)
                        {
                            (ntfs as NtfsFileSystem).NtfsOptions.HideSystemFiles = false;
                            (ntfs as NtfsFileSystem).NtfsOptions.HideHiddenFiles = false;
                        }

                        // removes not necessary files from the image
                        // Remove VSS snapshot files (can be very large)
                        foreach (string filePath in ntfs.GetFiles(@"\System Volume Information", "*{3808876B-C176-4e48-B7AE-04046E6CC752}"))
                        {
                            ntfs.DeleteFile(filePath);
                        }

                        // Remove the page file
                        if (ntfs.FileExists(@"\Pagefile.sys"))
                        {
                            ntfs.DeleteFile(@"\Pagefile.sys");
                        }

                        // Remove the hibernation file
                        if (ntfs.FileExists(@"\hiberfil.sys"))
                        {
                            ntfs.DeleteFile(@"\hiberfil.sys");
                        }

                        using (Stream systemRegistryStream = ntfs.OpenFile(@"windows\system32\config\system", FileMode.Open))
                        {
                            this.fileSystemHelper.ChangeSystemDriveMappingFromRegistry(systemRegistryStream);
                        }
                    }
                }

                if (migrationData.TemporaryVhdFileIsTheFinalOne)
                {
                    char vhdLocationDriveLetter = migrationData.VhdFileTemporaryFolder[0];
                    var  driveInfo = this.fileSystem.DriveInfo.FromDriveName(vhdLocationDriveLetter.ToString() + ":\\");
                    if (driveInfo.AvailableFreeSpace <= disk.Geometry.Capacity)
                    {
                        logger.LogWarning($"The image is located in a drive which has not enough free space for it to expand. If you will not free some space on drive '{driveInfo.Name}' then you will see BSOD when trying to boot from the created image.");
                    }
                }
            }
            return;
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Deletes a file.
 /// </summary>
 /// <param name="path">The path of the file to delete.</param>
 public override void DeleteFile(string path)
 {
     _wrapped.DeleteFile(path);
 }
Ejemplo n.º 3
0
 public void DeleteFile(string path)
 {
     discFs.DeleteFile(path);
 }