From 8f5059d53ed9b8c0977076533beb508bd1f87795 Mon Sep 17 00:00:00 2001 From: zeromus Date: Wed, 16 Sep 2015 14:27:28 -0500 Subject: [PATCH] discsystem - handle some errors that werent handled before --- BizHawk.Client.Common/RomLoader.cs | 6 +++--- .../DiscFormats/CUE/CUE_Compile.cs | 7 +++++++ BizHawk.Emulation.DiscSystem/DiscJob.cs | 4 ++++ BizHawk.Emulation.DiscSystem/DiscMountJob.cs | 16 +++++++++++----- 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/BizHawk.Client.Common/RomLoader.cs b/BizHawk.Client.Common/RomLoader.cs index 7bce2f288b..096632fec1 100644 --- a/BizHawk.Client.Common/RomLoader.cs +++ b/BizHawk.Client.Common/RomLoader.cs @@ -270,7 +270,7 @@ namespace BizHawk.Client.Common } if (discMountJob.OUT_ErrorLevel) - throw new InvalidOperationException(discMountJob.OUT_Log); + throw new InvalidOperationException("\r\n" + discMountJob.OUT_Log); if(disc == null) throw new InvalidOperationException("Can't load one of the files specified in the M3U"); @@ -329,7 +329,7 @@ namespace BizHawk.Client.Common } if (discMountJob.OUT_ErrorLevel) - throw new InvalidOperationException(discMountJob.OUT_Log); + throw new InvalidOperationException("\r\n" + discMountJob.OUT_Log); var disc = discMountJob.OUT_Disc; //----------- @@ -465,7 +465,7 @@ namespace BizHawk.Client.Common } if (discMountJob.OUT_ErrorLevel) - throw new InvalidOperationException(discMountJob.OUT_Log); + throw new InvalidOperationException("\r\n" + discMountJob.OUT_Log); if (disc == null) throw new InvalidOperationException("Can't load one of the files specified in the M3U"); diff --git a/BizHawk.Emulation.DiscSystem/DiscFormats/CUE/CUE_Compile.cs b/BizHawk.Emulation.DiscSystem/DiscFormats/CUE/CUE_Compile.cs index 39217582e3..fc6448d9af 100644 --- a/BizHawk.Emulation.DiscSystem/DiscFormats/CUE/CUE_Compile.cs +++ b/BizHawk.Emulation.DiscSystem/DiscFormats/CUE/CUE_Compile.cs @@ -365,6 +365,13 @@ namespace BizHawk.Emulation.DiscSystem.CUE void OpenTrack(CUE_File.Command.TRACK trackCommand) { + //assert that a file is open + if(curr_file == null) + { + Error("Track command encountered with no active file"); + throw new DiscJobAbortException(); + } + curr_track = new CompiledCueTrack(); //spill cdtext data into this track diff --git a/BizHawk.Emulation.DiscSystem/DiscJob.cs b/BizHawk.Emulation.DiscSystem/DiscJob.cs index d96dc5be30..4762673977 100644 --- a/BizHawk.Emulation.DiscSystem/DiscJob.cs +++ b/BizHawk.Emulation.DiscSystem/DiscJob.cs @@ -55,4 +55,8 @@ namespace BizHawk.Emulation.DiscSystem swLog.Write(job.OUT_Log); } } + + class DiscJobAbortException : Exception + { + }; } \ No newline at end of file diff --git a/BizHawk.Emulation.DiscSystem/DiscMountJob.cs b/BizHawk.Emulation.DiscSystem/DiscMountJob.cs index 2207ec45df..dab08a7dbf 100644 --- a/BizHawk.Emulation.DiscSystem/DiscMountJob.cs +++ b/BizHawk.Emulation.DiscSystem/DiscMountJob.cs @@ -126,6 +126,8 @@ namespace BizHawk.Emulation.DiscSystem } if (ext == ".cue") { + //TODO - major renovation of error handling needed + //TODO - make sure code is designed so no matter what happens, a disc is disposed in case of errors. //perhaps the CUE_Format2 (once renamed to something like Context) can handle that var cuePath = IN_FromPath; @@ -140,21 +142,25 @@ namespace BizHawk.Emulation.DiscSystem if (cue_content == null) cue_content = File.ReadAllText(cuePath); parseJob.IN_CueString = cue_content; - parseJob.Run(parseJob); - //TODO - need better handling of log output + bool okParse = true; + try { parseJob.Run(parseJob); } + catch (DiscJobAbortException) { okParse = false; parseJob.FinishLog(); } if (!string.IsNullOrEmpty(parseJob.OUT_Log)) Console.WriteLine(parseJob.OUT_Log); ConcatenateJobLog(parseJob); + if (!okParse) + goto DONE; //compile the cue file: //includes this work: resolve required bin files and find out what it's gonna take to load the cue var compileJob = new CompileCueJob(); compileJob.IN_CueContext = cueContext; compileJob.IN_CueFile = parseJob.OUT_CueFile; - compileJob.Run(); - //TODO - need better handling of log output + bool okCompile = true; + try { compileJob.Run(); } + catch (DiscJobAbortException) { okCompile = false; compileJob.FinishLog(); } if (!string.IsNullOrEmpty(compileJob.OUT_Log)) Console.WriteLine(compileJob.OUT_Log); ConcatenateJobLog(compileJob); - if (compileJob.OUT_ErrorLevel) + if (!okCompile || compileJob.OUT_ErrorLevel) goto DONE; //check slow loading threshold