using System; using System.Linq; using System.Text; using System.IO; using System.Collections.Generic; namespace BizHawk.Emulation.DiscSystem { public partial class DiscMountJob : LoggedJob { /// /// The filename to be loaded /// public string IN_FromPath; /// /// Slow-loading cues won't finish loading if this threshold is exceeded. /// Set to 10 to always load a cue /// public int IN_SlowLoadAbortThreshold = 10; /// /// The interface to be used for loading the disc. /// Usually you'll want DiscInterface.BizHawk, but others can be used for A/B testing /// public DiscInterface IN_DiscInterface = DiscInterface.BizHawk; /// /// The resulting disc /// public Disc OUT_Disc; public void Run() { switch (IN_DiscInterface) { case DiscInterface.LibMirage: throw new NotSupportedException("LibMirage not supported yet"); case DiscInterface.BizHawk: RunBizHawk(); break; case DiscInterface.MednaDisc: RunMednaDisc(); break; } FinishLog(); } void RunBizHawk() { string infile = IN_FromPath; string cue_content = null; var cfr = new CUE_Format2.CueFileResolver(); RERUN: var ext = Path.GetExtension(infile).ToLowerInvariant(); if (ext == ".iso") { //make a fake cue file to represent this iso file and rerun it as a cue string filebase = Path.GetFileName(infile); cue_content = string.Format(@" FILE ""{0}"" BINARY TRACK 01 MODE1/2048 INDEX 01 00:00:00", filebase); infile = Path.ChangeExtension(infile, ".cue"); goto RERUN; } if (ext == ".cue") { var cuePath = IN_FromPath; var cue2 = new CUE_Format2(); cue2.Resolver = cfr; if (!cfr.IsHardcodedResolve) cfr.SetBaseDirectory(Path.GetDirectoryName(infile)); //parse the cue file var parseJob = new CUE_Format2.ParseCueJob(); if (cue_content == null) cue_content = File.ReadAllText(cuePath); parseJob.IN_CueString = cue_content; cue2.ParseCueFile(parseJob); if (parseJob.OUT_Log != "") Console.WriteLine(parseJob.OUT_Log); ConcatenateJobLog(parseJob); //resolve required bin files and find out what it's gonna take to load the cue var analyzeJob = new CUE_Format2.AnalyzeCueJob(); analyzeJob.IN_CueFile = parseJob.OUT_CueFile; cue2.AnalyzeCueFile(analyzeJob); if (analyzeJob.OUT_Log != "") Console.WriteLine(analyzeJob.OUT_Log); ConcatenateJobLog(analyzeJob); //check slow loading threshold if (analyzeJob.OUT_LoadTime >= IN_SlowLoadAbortThreshold) { Warn("Loading terminated due to slow load threshold"); goto DONE; } //actually load it all up var loadJob = new CUE_Format2.LoadCueJob(); loadJob.IN_AnalyzeJob = analyzeJob; loadJob.Run(); if (loadJob.OUT_Log != "") Console.WriteLine(loadJob.OUT_Log); ConcatenateJobLog(analyzeJob); OUT_Disc = loadJob.OUT_Disc; //apply SBI if it exists (TODO - for formats other than cue?) var sbiPath = Path.ChangeExtension(IN_FromPath, ".sbi"); if (File.Exists(sbiPath) && SBI.SBIFormat.QuickCheckISSBI(sbiPath)) { var sbiJob = new SBI.LoadSBIJob(); sbiJob.IN_Path = sbiPath; sbiJob.Run(); OUT_Disc.ApplySBI(sbiJob.OUT_Data, true); } } else if (ext == ".ccd") { CCD_Format ccdLoader = new CCD_Format(); OUT_Disc = ccdLoader.LoadCCDToDisc(IN_FromPath); } DONE: ; } } }