public IEnumerable <FileEntry> DumpLogicalVolume(LogicalVolumeInfo volume, string parentPath, FileEntry parent = null) { DiscUtils.FileSystemInfo[] fsInfos = null; try { fsInfos = FileSystemManager.DetectFileSystems(volume); } catch (Exception e) { Logger.Debug("Failed to get file systems from logical volume {0} Image {1} ({2}:{3})", volume.Identity, parentPath, e.GetType(), e.Message); } foreach (var fsInfo in fsInfos ?? new DiscUtils.FileSystemInfo[] { }) { using (var fs = fsInfo.Open(volume)) { var diskFiles = fs.GetFiles(fs.Root.FullName, "*.*", SearchOption.AllDirectories).ToList(); foreach (var file in diskFiles) { Stream fileStream = null; DiscFileInfo fi = null; try { fi = fs.GetFileInfo(file); fileStream = fi.OpenRead(); } catch (Exception e) { Logger.Debug(e, "Failed to open {0} in volume {1}", file, volume.Identity); } if (fileStream != null && fi != null) { yield return(FileEntry.FromStream($"{volume.Identity}{Path.DirectorySeparatorChar}{fi.FullName}", fileStream, parent)); } } } } }
private static bool FilesMatch(DiscFileInfo A, DiscFileInfo B) { const int BufferSize = 2048; // arbitrarily chosen buffer size byte[] buffA = new byte[BufferSize]; byte[] buffB = new byte[BufferSize]; lock (A.FileSystem) lock (B.FileSystem) { var fileA = A.OpenRead(); var fileB = B.OpenRead(); int numA, numB; while (fileA.Position < fileA.Length) { numA = fileA.Read(buffA, 0, BufferSize); numB = fileB.Read(buffB, 0, BufferSize); if (numA != numB) { fileA.Close(); fileB.Close(); return(false); } for (int i = 0; i < numA; i++) { if (buffA[i] != buffB[i]) { fileA.Close(); fileB.Close(); return(false); } } } fileA.Close(); fileB.Close(); return(true); } }
public BDROM( string path) { // // Locate BDMV directories. // if ((new FileInfo(path).Attributes & FileAttributes.Directory) != FileAttributes.Directory) { IsImage = true; IoStream = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read); CdReader = new UdfReader(IoStream); } if (!IsImage) { DirectoryBDMV = GetDirectoryBDMV(path); } else { DiscDirectoryBDMV = GetDiscDirectoryBDMV(); } if ((!IsImage && DirectoryBDMV == null) || (IsImage && DiscDirectoryBDMV == null)) { throw new Exception("Unable to locate BD structure."); } if (IsImage) { DiscDirectoryRoot = DiscDirectoryBDMV.Parent; DiscDirectoryBDJO = GetDiscDirectory("BDJO", DiscDirectoryBDMV, 0); DiscDirectoryCLIPINF = GetDiscDirectory("CLIPINF", DiscDirectoryBDMV, 0); DiscDirectoryPLAYLIST = GetDiscDirectory("PLAYLIST", DiscDirectoryBDMV, 0); DiscDirectorySNP = GetDiscDirectory("SNP", DiscDirectoryRoot, 0); DiscDirectorySTREAM = GetDiscDirectory("STREAM", DiscDirectoryBDMV, 0); DiscDirectorySSIF = GetDiscDirectory("SSIF", DiscDirectorySTREAM, 0); DiscDirectoryMETA = GetDiscDirectory("META", DiscDirectoryBDMV, 0); } else { DirectoryRoot = DirectoryBDMV.Parent; DirectoryBDJO = GetDirectory("BDJO", DirectoryBDMV, 0); DirectoryCLIPINF = GetDirectory("CLIPINF", DirectoryBDMV, 0); DirectoryPLAYLIST = GetDirectory("PLAYLIST", DirectoryBDMV, 0); DirectorySNP = GetDirectory("SNP", DirectoryRoot, 0); DirectorySTREAM = GetDirectory("STREAM", DirectoryBDMV, 0); DirectorySSIF = GetDirectory("SSIF", DirectorySTREAM, 0); DirectoryMETA = GetDirectory("META", DirectoryBDMV, 0); } if ((!IsImage & (DirectoryCLIPINF == null || DirectoryPLAYLIST == null)) || (IsImage & (DiscDirectoryCLIPINF == null || DiscDirectoryPLAYLIST == null))) { throw new Exception("Unable to locate BD structure."); } // // Initialize basic disc properties. // if (IsImage) { VolumeLabel = CdReader.VolumeLabel; Size = (ulong)GetDiscDirectorySize(DiscDirectoryRoot); var indexFiles = DiscDirectoryBDMV?.GetFiles(); DiscFileInfo indexFile = null; for (int i = 0; i < indexFiles?.Length; i++) { if (indexFiles[i].Name.ToLower() == "index.bdmv") { indexFile = indexFiles[i]; break; } } if (indexFile != null) { using (var indexStream = indexFile.OpenRead()) { ReadIndexVersion(indexStream); } } if (null != GetDiscDirectory("BDSVM", DiscDirectoryRoot, 0)) { IsBDPlus = true; } if (null != GetDiscDirectory("SLYVM", DiscDirectoryRoot, 0)) { IsBDPlus = true; } if (null != GetDiscDirectory("ANYVM", DiscDirectoryRoot, 0)) { IsBDPlus = true; } if (DiscDirectoryBDJO != null && DiscDirectoryBDJO.GetFiles().Length > 0) { IsBDJava = true; } if (DiscDirectorySNP != null && (DiscDirectorySNP.GetFiles("*.mnv").Length > 0 || DiscDirectorySNP.GetFiles("*.MNV").Length > 0)) { IsPSP = true; } if (DiscDirectorySSIF != null && DiscDirectorySSIF.GetFiles().Length > 0) { Is3D = true; } DiscFileInfo[] discFiles = DiscDirectoryRoot.GetFiles("FilmIndex.xml"); if (discFiles != null && discFiles.Length > 0) { IsDBOX = true; } if (DiscDirectoryMETA != null) { DiscFileInfo[] metaFiles = DiscDirectoryMETA.GetFiles("bdmt_eng.xml", SearchOption.AllDirectories); if (metaFiles != null && metaFiles.Length > 0) { ReadDiscTitle(metaFiles[0].OpenText()); } } // // Initialize file lists. // if (DiscDirectoryPLAYLIST != null) { DiscFileInfo[] files = DiscDirectoryPLAYLIST.GetFiles("*.mpls"); if (files.Length == 0) { files = DiscDirectoryPLAYLIST.GetFiles("*.MPLS"); } foreach (DiscFileInfo file in files) { PlaylistFiles.Add(file.Name.ToUpper(), new TSPlaylistFile(this, file, CdReader)); } } if (DiscDirectorySTREAM != null) { DiscFileInfo[] files = DiscDirectorySTREAM.GetFiles("*.m2ts"); if (files.Length == 0) { files = DiscDirectoryPLAYLIST.GetFiles("*.M2TS"); } foreach (DiscFileInfo file in files) { StreamFiles.Add(file.Name.ToUpper(), new TSStreamFile(file, CdReader)); } } if (DiscDirectoryCLIPINF != null) { DiscFileInfo[] files = DiscDirectoryCLIPINF.GetFiles("*.clpi"); if (files.Length == 0) { files = DiscDirectoryPLAYLIST.GetFiles("*.CLPI"); } foreach (DiscFileInfo file in files) { StreamClipFiles.Add(file.Name.ToUpper(), new TSStreamClipFile(file, CdReader)); } } if (DiscDirectorySSIF != null) { DiscFileInfo[] files = DiscDirectorySSIF.GetFiles("*.ssif"); if (files.Length == 0) { files = DiscDirectorySSIF.GetFiles("*.SSIF"); } foreach (DiscFileInfo file in files) { InterleavedFiles.Add(file.Name.ToUpper(), new TSInterleavedFile(file, CdReader)); } } } else { VolumeLabel = GetVolumeLabel(DirectoryRoot); Size = (ulong)GetDirectorySize(DirectoryRoot); var indexFiles = DirectoryBDMV.GetFiles(); FileInfo indexFile = null; for (int i = 0; i < indexFiles.Length; i++) { if (indexFiles[i].Name.ToLower() == "index.bdmv") { indexFile = indexFiles[i]; break; } } if (indexFile != null) { using (var indexStream = indexFile.OpenRead()) { ReadIndexVersion(indexStream); } } if (null != GetDirectory("BDSVM", DirectoryRoot, 0)) { IsBDPlus = true; } if (null != GetDirectory("SLYVM", DirectoryRoot, 0)) { IsBDPlus = true; } if (null != GetDirectory("ANYVM", DirectoryRoot, 0)) { IsBDPlus = true; } if (DirectoryBDJO != null && DirectoryBDJO.GetFiles().Length > 0) { IsBDJava = true; } if (DirectorySNP != null && (DirectorySNP.GetFiles("*.mnv").Length > 0 || DirectorySNP.GetFiles("*.MNV").Length > 0)) { IsPSP = true; } if (DirectorySSIF != null && DirectorySSIF.GetFiles().Length > 0) { Is3D = true; } if (File.Exists(Path.Combine(DirectoryRoot.FullName, "FilmIndex.xml"))) { IsDBOX = true; } if (DirectoryMETA != null) { FileInfo[] metaFiles = DirectoryMETA.GetFiles("bdmt_eng.xml", SearchOption.AllDirectories); if (metaFiles != null && metaFiles.Length > 0) { ReadDiscTitle(metaFiles[0].OpenText()); } } // // Initialize file lists. // if (DirectoryPLAYLIST != null) { FileInfo[] files = DirectoryPLAYLIST.GetFiles("*.mpls"); if (files.Length == 0) { files = DirectoryPLAYLIST.GetFiles("*.MPLS"); } foreach (FileInfo file in files) { PlaylistFiles.Add( file.Name.ToUpper(), new TSPlaylistFile(this, file)); } } if (DirectorySTREAM != null) { FileInfo[] files = DirectorySTREAM.GetFiles("*.m2ts"); if (files.Length == 0) { files = DirectoryPLAYLIST.GetFiles("*.M2TS"); } foreach (FileInfo file in files) { StreamFiles.Add( file.Name.ToUpper(), new TSStreamFile(file)); } } if (DirectoryCLIPINF != null) { FileInfo[] files = DirectoryCLIPINF.GetFiles("*.clpi"); if (files.Length == 0) { files = DirectoryPLAYLIST.GetFiles("*.CLPI"); } foreach (FileInfo file in files) { StreamClipFiles.Add( file.Name.ToUpper(), new TSStreamClipFile(file)); } } if (DirectorySSIF != null) { FileInfo[] files = DirectorySSIF.GetFiles("*.ssif"); if (files.Length == 0) { files = DirectorySSIF.GetFiles("*.SSIF"); } foreach (FileInfo file in files) { InterleavedFiles.Add( file.Name.ToUpper(), new TSInterleavedFile(file)); } } } }
public override Stream GetStream() => _file.OpenRead();