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; }
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); } }
public static void ReadIsoFolder(DiscFileSystem cdReader, string sIsoPath, string sDestinationRootPath) { try { string[] saFiles = cdReader.GetFiles(sIsoPath); foreach (string sFile in saFiles) { DiscFileInfo dfiIso = cdReader.GetFileInfo(sFile); string sDestinationPath = Path.Combine(sDestinationRootPath, dfiIso.DirectoryName.Substring(0, dfiIso.DirectoryName.Length - 1)); if (!Directory.Exists(sDestinationPath)) { Directory.CreateDirectory(sDestinationPath); } string sDestinationFile = Path.Combine(sDestinationPath, dfiIso.Name); SparseStream streamIsoFile = cdReader.OpenFile(sFile, FileMode.Open); FileStream fsDest = new FileStream(sDestinationFile, FileMode.Create); byte[] baData = new byte[0x4000]; while (true) { int nReadCount = streamIsoFile.Read(baData, 0, baData.Length); if (nReadCount < 1) { break; } else { fsDest.Write(baData, 0, nReadCount); } } streamIsoFile.Close(); fsDest.Close(); } string[] saDirectories = cdReader.GetDirectories(sIsoPath); foreach (string sDirectory in saDirectories) { ReadIsoFolder(cdReader, sDirectory, sDestinationRootPath); } return; } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
/// <summary> /// Gets the names of files in a specified directory matching a specified /// search pattern, using a value to determine whether to search subdirectories. /// </summary> /// <param name="path">The path to search.</param> /// <param name="searchPattern">The search string to match against.</param> /// <param name="searchOption">Indicates whether to search subdirectories.</param> /// <returns>Array of files matching the search pattern.</returns> public override string[] GetFiles(string path, string searchPattern, SearchOption searchOption) { return(_wrapped.GetFiles(path, searchPattern, searchOption)); }
/// <summary> /// Gets the names of files in a specified directory. /// </summary> /// <param name="path">The path to search.</param> /// <returns>Array of files.</returns> public override string[] GetFiles(string path) { return(_wrapped.GetFiles(path)); }
public string[] GetFiles(string path, string searchPattern = "*.*", SearchOption option = SearchOption.AllDirectories) { return(discFs.GetFiles(path, searchPattern, option)); }
/// <summary> /// Gets the names of files in a specified directory. /// </summary> /// <param name="path">The path to search.</param> /// <returns>Array of files.</returns> public override ReaderDirEntry[] GetFiles(string path) { return(_wrapped.GetFiles(path)); }
private static string RedirectISO(string filename) { string _result = null; try { if (!string.IsNullOrEmpty(filename) && File.Exists(filename)) { List <string> _candidates = new List <string>(); // open the ISO file VolumeManager volMgr = new VolumeManager(); volMgr.AddDisk(VirtualDisk.OpenDisk(filename, FileAccess.Read)); VolumeInfo volInfo = null; volInfo = volMgr.GetLogicalVolumes()[0]; DiscUtils.FileSystemInfo fsInfo = FileSystemManager.DetectDefaultFileSystems(volInfo)[0]; using (DiscFileSystem _dfs = fsInfo.Open(volInfo)) { foreach (string _fname in _dfs.GetFiles("", "*.*", SearchOption.AllDirectories)) { string _fileExt = System.IO.Path.GetExtension(_fname).ToLowerInvariant(); if (_fileExt == ".ifo" || _fileExt == ".mpls") { _candidates.Add(_fname); } } double _biggestDuration = 0d; string _tmpBRResult = ""; // select from the candidates the one that has the longest duration (if mpls skip files bigger than 10K) foreach (string _cpath in _candidates) { string _cext = Path.GetExtension(_cpath).ToLowerInvariant(); string _tmp = Helpers.GetUniqueFilename(_cext); using (FileStream _fs = new FileStream(_tmp, FileMode.Create, FileAccess.Write)) { using (Stream source = _dfs.OpenFile(_cpath, FileMode.Open, FileAccess.Read)) { source.CopyTo(_fs); } } // if it is a DVD iso if (_cext == ".ifo") { if (string.Compare(Path.GetFileNameWithoutExtension(_cpath), "video_ts", true) == 0) { File.Delete(_tmp); // skip the menu continue; } // use first ifo that is not the menu FileManager.AddToGarbageFiles(_tmp); _result = _tmp; break; } // if it is a BLURAY iso (choose biggest mpls file) if (_cext == ".mpls") { long _length = new FileInfo(_tmp).Length; if (Path.GetExtension(_cpath).ToLowerInvariant() == ".mpls" && _length > 10 * 1024) { File.Delete(_tmp); continue; // take next one, this is too big and mediainfo will hang } if (GetDurationMilliseconds(_tmp) > _biggestDuration) { // important.. add it to the garbage files //FileManager.AddToGarbageFiles(_tmp); //_result = _tmp; if (!string.IsNullOrEmpty(_tmpBRResult)) { File.Delete(_tmpBRResult); // remove previous winner and remember the current one } _tmpBRResult = _tmp; } else { File.Delete(_tmp); } } } if (string.IsNullOrEmpty(_result) && !string.IsNullOrEmpty(_tmpBRResult)) { FileManager.AddToGarbageFiles(_tmpBRResult); _result = _tmpBRResult; } } } } catch (Exception ex) { Loggy.Logger.DebugException("ISO Processing", ex); } return(_result); }