public override bool DetectROM(string inputPath, out string titleID, out uint regionID) { regionID = 0; using (FileStream isoStream = File.Open(inputPath, FileMode.Open)) { if (!CDReader.Detect(isoStream)) { titleID = null; return(false); } else { CDReader cd = new CDReader(isoStream, true); titleID = null; bool confirm = false; if (cd.FileExists(@"UMD_DATA.BIN")) { using (StreamReader sr = new StreamReader(cd.OpenFile(@"UMD_DATA.BIN", FileMode.Open))) { titleID = sr.ReadLine().Substring(0, 10); } confirm = true; } cd.Dispose(); return(confirm); } } }
public static string DetectPs2Sku(FileInfo isofile) { Stream isoStream; if (isBinFile(isofile)) { isoStream = new RawCdRomStream(isofile); } else { isoStream = isofile.OpenRead(); } if (!CDReader.Detect(isoStream)) { return(null); } CDReader cdReader = new CDReader(isoStream, false, true); if (!cdReader.FileExists("SYSTEM.CNF")) { cdReader.Dispose(); isoStream.Dispose(); return(null); } SparseStream systemCnfStream = cdReader.OpenFile("SYSTEM.CNF", FileMode.Open, FileAccess.Read); StreamReader systemCnfReader = new StreamReader(systemCnfStream, Encoding.ASCII); string boot2 = null; while (!systemCnfReader.EndOfStream) { boot2 = systemCnfReader.ReadLine(); if (boot2.ToUpperInvariant().StartsWith("BOOT")) { break; } } systemCnfReader.Dispose(); systemCnfStream.Dispose(); while (boot2.Contains("\\")) { boot2 = boot2.Substring(1); } if (boot2.EndsWith(";1")) { boot2 = boot2.Substring(0, boot2.Length - 2); } cdReader.Dispose(); isoStream.Dispose(); return(boot2); }
public override bool DetectROM(string inputPath, out string titleID, out uint regionID) { bool found = false; titleID = null; regionID = 0; using (FileStream isoStream = File.Open(inputPath, FileMode.Open)) { CDReader cd; FileStream tempbin = null; if (Path.GetExtension(inputPath).ToLower() == ".bin") // PS1 CD image { FileStream binconvout = new FileStream(ModLoaderGlobals.BaseDirectory + "binconvout.iso", FileMode.Create, FileAccess.Write); PSX2ISO.Run(isoStream, binconvout); binconvout.Close(); tempbin = new FileStream(ModLoaderGlobals.BaseDirectory + "binconvout.iso", FileMode.Open, FileAccess.Read); cd = new CDReader(tempbin, true); } else if (!CDReader.Detect(isoStream)) { return(false); } else { cd = new CDReader(isoStream, true); } if (cd.FileExists(@"SYSTEM.CNF")) { using (StreamReader sr = new StreamReader(cd.OpenFile(@"SYSTEM.CNF", FileMode.Open))) { titleID = sr.ReadLine(); found = (titleID.Contains("BOOT ") || titleID.Contains("BOOT=")); } } else { found = false; } cd.Dispose(); if (tempbin != null) { tempbin.Dispose(); File.Delete(ModLoaderGlobals.BaseDirectory + "binconvout.iso"); } } if (!found) { titleID = null; } return(found); }
} // selected extract public bool Valid_Iso(Stream fs) { if (CDReader.Detect(fs)) { return(true); } else { MessageBox.Show("Invalid ISO!"); return(false); } }
public override FileSystemInfo[] Detect(Stream stream, VolumeInfo volume) { List <FileSystemInfo> detected = new List <FileSystemInfo>(); if (UdfReader.Detect(stream)) { detected.Add(new VfsFileSystemInfo("UDF", "OSTA Universal Disk Format (UDF)", OpenUdf)); } if (CDReader.Detect(stream)) { detected.Add(new VfsFileSystemInfo("ISO9660", "ISO 9660 (CD-ROM)", OpenIso)); } return(detected.ToArray()); }
public static IFileSystem GetFileSystem(Stream underlayingStream) { // Try UDF access first; if that doesn't work, try iso9660 try { if (!UdfReader.Detect(underlayingStream)) { throw new ArgumentException("The given stream does not contain a valid UDF filesystem"); } return(new UdfReader(underlayingStream)); } catch { if (!CDReader.Detect(underlayingStream)) { throw new ArgumentException("The given stream does neither contain a valid UDF nor a valid ISO9660 filesystem"); } return(new CDReader(underlayingStream, true, true)); } }
public static void CopyFilesfromISO(string isoName, string baseDirectory) { using (FileStream isoStream = File.OpenRead(isoName)) { if (UdfReader.Detect(isoStream)) { using (UdfReader iso = new UdfReader(isoStream)) { DoCopyFilesfromISO(iso, baseDirectory); } } else if (CDReader.Detect(isoStream)) { using (CDReader iso = new CDReader(isoStream, true)) { DoCopyFilesfromISO(iso, baseDirectory); } } } }
public static void Gather(Media medium, Stream infile) { string failed = ""; XboxISOFileSource xboxIso = XboxISOFileSource.TryOpen(infile); if (xboxIso != null) { XDvdFsFileSystemEntry xdvdfs = xboxIso.GetFileSystem(); Gather(medium, xdvdfs, null); infile.Dispose(); return; } failed += "XDVDFS\n"; if (CDReader.Detect(infile)) { CDReader cdReader = new CDReader(infile, true, false); Gather(medium, cdReader.Root, null); infile.Dispose(); return; } failed += "ISO9660\n"; if (UdfReader.Detect(infile)) { UdfReader udfReader = new UdfReader(infile); if (udfReader != null) { try { Gather(medium, udfReader.Root, null); return; } catch (Exception) { AzusaContext.GetInstance().DatabaseDriver.ForgetFilesystemContents(medium.Id); } } } failed += "UDF\n"; if (FatFileSystem.Detect(infile)) { FatFileSystem fat = new FatFileSystem(infile); Gather(medium, fat.Root, null); infile.Dispose(); return; } failed += "FAT32\n"; if (infile.Length < 3200) { FileStream fileStream = infile as FileStream; if (fileStream != null) { fileStream.Dispose(); FileInfo fi = new FileInfo(fileStream.Name); Stream gdRomStream = GDROMReader.BuildGdRomStream(fi); if (CDReader.Detect(gdRomStream)) { CDReader cdReader = new CDReader(gdRomStream, true, false); Gather(medium, cdReader.Root, null); infile.Dispose(); return; } } } failed += "GD-ROM\n"; infile.Position = 0; byte[] firstSector = new byte[2352]; if (infile.Read(firstSector, 0, firstSector.Length) == firstSector.Length) { byte[] firstSectorSync = new byte[cdromSyncBytes.Length]; Array.Copy(firstSector, firstSectorSync, cdromSyncBytes.Length); if (memcmp(cdromSyncBytes, firstSectorSync)) { byte mode = firstSector[15]; if (mode == 1 || mode == 2) { infile.Position = 0; RawCdRomStream rawCdRomStream = new RawCdRomStream(infile); Gather(medium, rawCdRomStream); return; } } } failed += "RAW CD-ROM"; MessageBox.Show("Konnte kein Dateisystem erkennen. Versucht wurden:" + failed); }
private void tv_root_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e) { int index = e.Node.Index; int afs_sig = 5457473; int afs_count = 0; tv_root.SelectedNode = null; // if file exists.. if (File.Exists(Img.Image_Path)) { // open file stream using (FileStream fs = new FileStream(Img.Image_Path, FileMode.Open)) { // if valid iso.. if (CDReader.Detect(fs)) { Img.Read_Image = new CDReader(fs, true, true); Img.Root_FSys_Info = Img.Read_Image.Root.GetFileSystemInfos(); Img.Selected_Volume = Img.Root_FSys_Info[index].FullName; // this lbl_VolSel.Text = Img.Selected_Volume; // Img.Volume_Index = Img.Volume_Box.FindStringExact(Img.Selected_Volume); // Img.Volume_Box.SelectedIndex = Img.Volume_Index; // MessageBox.Show(MainForm.Img.Selected_Volume.ToString()); // open selected File for further parsing.. Stream memStream = Img.Read_Image.OpenFile(Img.Root_FSys_Info[index].FullName, FileMode.Open); BinaryReader br = new BinaryReader(memStream); memStream.Seek(0, SeekOrigin.Begin); if (br.ReadInt32() == afs_sig && Img.Root_FSys_Info[index].Extension == "AFS") { // MessageBox.Show("Valid Afs Archive..", "Valid", MessageBoxButtons.OK, MessageBoxIcon.Information); AFSIO.afs_parse(memStream, br, 0, AFS_LV, ProgressBar00, false, lbl_relativeOffset, Lbl_FCount, lbl_stats); } else if (Img.Root_FSys_Info[index].Name == "DATA.BIN") { AFSIO.data_bin_parse(memStream, br, AFS_LV, ProgressBar00, Lbl_FCount, lbl_stats); } else if (br.ReadInt32() != afs_sig) { MessageBox.Show("Invalid Afs Archive..", "Invalid", MessageBoxButtons.OK, MessageBoxIcon.Error); fs.Close(); br.Close(); } } } } }
/// <summary> /// Detects whether a stream is an iso disc. /// </summary> /// <param name="root">A stream.</param> /// <returns>A boolean.</returns> public static bool IsIsoFile(Stream root) { return(CDReader.Detect(root)); }