From 333cae15cd0c1d4e4e44987d25ba267c5f9f2208 Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Sat, 2 Jan 2021 15:23:15 +1000 Subject: [PATCH] Convert IN_* props of jobs to ctor-initialised readonly fields --- src/BizHawk.Client.DiscoHawk/MainDiscoForm.cs | 2 +- src/BizHawk.Emulation.DiscSystem/Disc.cs | 3 +- .../DiscExtensions.cs | 2 +- .../DiscFormats/CCD_format.cs | 2 +- .../DiscFormats/CUE/CUE_Compile.cs | 19 +++--- .../DiscFormats/CUE/CUE_Load.cs | 19 +++--- .../DiscFormats/CUE/CUE_Parse.cs | 21 +++--- .../DiscFormats/MDS_Format.cs | 2 +- .../DiscMountJob.cs | 65 +++++++++++-------- .../DiscoHawkLogic/DiscoHawkLogic.cs | 16 ++--- .../Internal/Jobs/LoadSBIJob.cs | 8 +-- .../Internal/Jobs/Synthesize_A0A1A2_Job.cs | 36 +++++----- ...nthesize_DiscStructure_From_DiscTOC_Job.cs | 14 +++- ...nthesize_DiscTOC_From_RawTOCEntries_Job.cs | 12 +++- 14 files changed, 123 insertions(+), 98 deletions(-) diff --git a/src/BizHawk.Client.DiscoHawk/MainDiscoForm.cs b/src/BizHawk.Client.DiscoHawk/MainDiscoForm.cs index 2cd8d147cf..e3be44274f 100644 --- a/src/BizHawk.Client.DiscoHawk/MainDiscoForm.cs +++ b/src/BizHawk.Client.DiscoHawk/MainDiscoForm.cs @@ -40,7 +40,7 @@ namespace BizHawk.Client.DiscoHawk Cursor = Cursors.WaitCursor; foreach (var file in files) { - var job = new DiscMountJob { IN_FromPath = file }; + var job = new DiscMountJob(fromPath: file); job.Run(); var disc = job.OUT_Disc; if (job.OUT_ErrorLevel) diff --git a/src/BizHawk.Emulation.DiscSystem/Disc.cs b/src/BizHawk.Emulation.DiscSystem/Disc.cs index 2d0642b80a..7034d9d42a 100644 --- a/src/BizHawk.Emulation.DiscSystem/Disc.cs +++ b/src/BizHawk.Emulation.DiscSystem/Disc.cs @@ -23,8 +23,7 @@ namespace BizHawk.Emulation.DiscSystem /// public static Disc LoadAutomagic(string path) { - var job = new DiscMountJob { IN_FromPath = path }; - //job.IN_DiscInterface = DiscInterface.MednaDisc; //TEST + var job = new DiscMountJob(fromPath: path/*, discInterface: DiscInterface.MednaDisc <-- TEST*/); job.Run(); return job.OUT_Disc; } diff --git a/src/BizHawk.Emulation.DiscSystem/DiscExtensions.cs b/src/BizHawk.Emulation.DiscSystem/DiscExtensions.cs index 492db30baa..421e12490b 100644 --- a/src/BizHawk.Emulation.DiscSystem/DiscExtensions.cs +++ b/src/BizHawk.Emulation.DiscSystem/DiscExtensions.cs @@ -16,7 +16,7 @@ namespace BizHawk.Emulation.DiscSystem private static Disc CreateImpl(DiscType? type, string path, Action errorCallback) { //--- load the disc in a context which will let us abort if it's going to take too long - var discMountJob = new DiscMountJob { IN_FromPath = path, IN_SlowLoadAbortThreshold = 8 }; + var discMountJob = new DiscMountJob(fromPath: path, slowLoadAbortThreshold: 8); discMountJob.Run(); var disc = discMountJob.OUT_Disc ?? throw new InvalidOperationException($"Can't find the file specified: {path}"); diff --git a/src/BizHawk.Emulation.DiscSystem/DiscFormats/CCD_format.cs b/src/BizHawk.Emulation.DiscSystem/DiscFormats/CCD_format.cs index 96b2691cce..853ce94dc2 100644 --- a/src/BizHawk.Emulation.DiscSystem/DiscFormats/CCD_format.cs +++ b/src/BizHawk.Emulation.DiscSystem/DiscFormats/CCD_format.cs @@ -570,7 +570,7 @@ namespace BizHawk.Emulation.DiscSystem } //analyze the RAWTocEntries to figure out what type of track track 1 is - var tocSynth = new Synthesize_DiscTOC_From_RawTOCEntries_Job() { Entries = disc.RawTOCEntries }; + var tocSynth = new Synthesize_DiscTOC_From_RawTOCEntries_Job(disc.RawTOCEntries); tocSynth.Run(); //Add sectors for the mandatory track 1 pregap, which isn't stored in the CCD file diff --git a/src/BizHawk.Emulation.DiscSystem/DiscFormats/CUE/CUE_Compile.cs b/src/BizHawk.Emulation.DiscSystem/DiscFormats/CUE/CUE_Compile.cs index c30df45442..9af221d691 100644 --- a/src/BizHawk.Emulation.DiscSystem/DiscFormats/CUE/CUE_Compile.cs +++ b/src/BizHawk.Emulation.DiscSystem/DiscFormats/CUE/CUE_Compile.cs @@ -120,16 +120,17 @@ namespace BizHawk.Emulation.DiscSystem.CUE internal class CompileCueJob : DiscJob { - /// - /// input: the CueFile to analyze - /// - public CUE_File IN_CueFile { private get; set; } + private readonly CUE_File IN_CueFile; - /// - /// The context used for this compiling job - /// TODO - rename something like context - /// - public CUE_Context IN_CueContext { internal get; set; } + internal readonly CUE_Context IN_CueContext; + + /// the CueFile to analyze + /// The context used for this compiling job + public CompileCueJob(CUE_File cueFile, CUE_Context cueContext) + { + IN_CueFile = cueFile; + IN_CueContext = cueContext; + } /// /// output: high level disc info diff --git a/src/BizHawk.Emulation.DiscSystem/DiscFormats/CUE/CUE_Load.cs b/src/BizHawk.Emulation.DiscSystem/DiscFormats/CUE/CUE_Load.cs index 45ac9fe938..38a05cba82 100644 --- a/src/BizHawk.Emulation.DiscSystem/DiscFormats/CUE/CUE_Load.cs +++ b/src/BizHawk.Emulation.DiscSystem/DiscFormats/CUE/CUE_Load.cs @@ -32,10 +32,10 @@ namespace BizHawk.Emulation.DiscSystem.CUE /// internal class LoadCueJob : DiscJob { - /// - /// The results of the compile job, a prerequisite for this - /// - public CompileCueJob IN_CompileJob { private get; set; } + private readonly CompileCueJob IN_CompileJob; + + /// The results of the compile job, a prerequisite for this + public LoadCueJob(CompileCueJob compileJob) => IN_CompileJob = compileJob; /// /// The resulting disc @@ -379,12 +379,11 @@ namespace BizHawk.Emulation.DiscSystem.CUE //add RawTOCEntries A0 A1 A2 to round out the TOC - var TOCMiscInfo = new Synthesize_A0A1A2_Job { - IN_FirstRecordedTrackNumber = IN_CompileJob.OUT_CompiledDiscInfo.FirstRecordedTrackNumber, - IN_LastRecordedTrackNumber = IN_CompileJob.OUT_CompiledDiscInfo.LastRecordedTrackNumber, - IN_Session1Format = IN_CompileJob.OUT_CompiledDiscInfo.SessionFormat, - IN_LeadoutTimestamp = OUT_Disc._Sectors.Count - }; + var TOCMiscInfo = new Synthesize_A0A1A2_Job( + firstRecordedTrackNumber: IN_CompileJob.OUT_CompiledDiscInfo.FirstRecordedTrackNumber, + lastRecordedTrackNumber: IN_CompileJob.OUT_CompiledDiscInfo.LastRecordedTrackNumber, + session1Format: IN_CompileJob.OUT_CompiledDiscInfo.SessionFormat, + leadoutTimestamp: OUT_Disc._Sectors.Count); TOCMiscInfo.Run(OUT_Disc.RawTOCEntries); //TODO - generate leadout, or delegates at least diff --git a/src/BizHawk.Emulation.DiscSystem/DiscFormats/CUE/CUE_Parse.cs b/src/BizHawk.Emulation.DiscSystem/DiscFormats/CUE/CUE_Parse.cs index 111aa42817..374a9d0dcb 100644 --- a/src/BizHawk.Emulation.DiscSystem/DiscFormats/CUE/CUE_Parse.cs +++ b/src/BizHawk.Emulation.DiscSystem/DiscFormats/CUE/CUE_Parse.cs @@ -14,22 +14,23 @@ namespace BizHawk.Emulation.DiscSystem.CUE /// internal class ParseCueJob : DiscJob { - /// - /// input: the cue string to parse - /// - public string IN_CueString { private get; set; } + private readonly string IN_CueString; + + private readonly bool IN_Strict; + + /// the cue string to parse + /// Indicates whether parsing will be strict or lenient + public ParseCueJob(string cueString, bool strict = false) + { + IN_CueString = cueString; + IN_Strict = strict; + } /// /// output: the resulting minimally-processed cue file /// public CUE_File OUT_CueFile { get; private set; } - /// - /// Indicates whether parsing will be strict or lenient - /// - public bool IN_Strict { private get; set; } = false; - - private class CueLineParser { private int index; diff --git a/src/BizHawk.Emulation.DiscSystem/DiscFormats/MDS_Format.cs b/src/BizHawk.Emulation.DiscSystem/DiscFormats/MDS_Format.cs index b77b504633..9cc1039b0e 100644 --- a/src/BizHawk.Emulation.DiscSystem/DiscFormats/MDS_Format.cs +++ b/src/BizHawk.Emulation.DiscSystem/DiscFormats/MDS_Format.cs @@ -709,7 +709,7 @@ namespace BizHawk.Emulation.DiscSystem } //analyze the RAWTocEntries to figure out what type of track track 1 is - var tocSynth = new Synthesize_DiscTOC_From_RawTOCEntries_Job() { Entries = disc.RawTOCEntries }; + var tocSynth = new Synthesize_DiscTOC_From_RawTOCEntries_Job(disc.RawTOCEntries); tocSynth.Run(); // now build the sectors diff --git a/src/BizHawk.Emulation.DiscSystem/DiscMountJob.cs b/src/BizHawk.Emulation.DiscSystem/DiscMountJob.cs index 98ab5f5513..a474d1a114 100644 --- a/src/BizHawk.Emulation.DiscSystem/DiscMountJob.cs +++ b/src/BizHawk.Emulation.DiscSystem/DiscMountJob.cs @@ -11,27 +11,43 @@ namespace BizHawk.Emulation.DiscSystem /// public partial class DiscMountJob : DiscJob { - /// - /// The filename to be loaded - /// - public string IN_FromPath { private get; set; } + private readonly 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 { private get; set; } = 10; + private readonly DiscMountPolicy IN_DiscMountPolicy; - /// - /// Cryptic policies to be used when mounting the disc. - /// - public DiscMountPolicy IN_DiscMountPolicy { private get; set; } = new DiscMountPolicy(); + private readonly DiscInterface IN_DiscInterface; - /// + private readonly int IN_SlowLoadAbortThreshold; + + /// The filename to be loaded + /// Cryptic policies to be used when mounting the disc. + /// /// 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 { private get; set; } = DiscInterface.BizHawk; + /// + /// + /// Slow-loading cues won't finish loading if this threshold is exceeded. + /// Set to 10 to always load a cue + /// + public DiscMountJob(string fromPath, DiscMountPolicy discMountPolicy, DiscInterface discInterface = DiscInterface.BizHawk, int slowLoadAbortThreshold = 10) + { + IN_FromPath = fromPath; + IN_DiscMountPolicy = discMountPolicy; + IN_DiscInterface = discInterface; + IN_SlowLoadAbortThreshold = slowLoadAbortThreshold; + } + + /// The filename to be loaded + /// + /// The interface to be used for loading the disc. + /// Usually you'll want DiscInterface.BizHawk, but others can be used for A/B testing + /// + /// + /// Slow-loading cues won't finish loading if this threshold is exceeded. + /// Set to 10 to always load a cue + /// + public DiscMountJob(string fromPath, DiscInterface discInterface = DiscInterface.BizHawk, int slowLoadAbortThreshold = 10) + : this(fromPath, new(), discInterface, slowLoadAbortThreshold) {} /// /// The resulting disc @@ -64,11 +80,11 @@ namespace BizHawk.Emulation.DiscSystem //generate toc and structure: //1. TOCRaw from RawTOCEntries - var tocSynth = new Synthesize_DiscTOC_From_RawTOCEntries_Job { Entries = OUT_Disc.RawTOCEntries }; + var tocSynth = new Synthesize_DiscTOC_From_RawTOCEntries_Job(OUT_Disc.RawTOCEntries); tocSynth.Run(); OUT_Disc.TOC = tocSynth.Result; //2. Structure from TOCRaw - var structureSynth = new Synthesize_DiscStructure_From_DiscTOC_Job { IN_Disc = OUT_Disc, TOCRaw = OUT_Disc.TOC }; + var structureSynth = new Synthesize_DiscStructure_From_DiscTOC_Job(OUT_Disc, OUT_Disc.TOC); structureSynth.Run(); OUT_Disc.Structure = structureSynth.Result; @@ -89,7 +105,7 @@ namespace BizHawk.Emulation.DiscSystem var sbiPath = Path.ChangeExtension(IN_FromPath, ".sbi"); if (File.Exists(sbiPath) && SBI.SBIFormat.QuickCheckISSBI(sbiPath)) { - var loadSbiJob = new SBI.LoadSBIJob() { IN_Path = sbiPath }; + var loadSbiJob = new SBI.LoadSBIJob(sbiPath); loadSbiJob.Run(); var applySbiJob = new ApplySBIJob(); applySbiJob.Run(OUT_Disc, loadSbiJob.OUT_Data, IN_DiscMountPolicy.SBI_As_Mednafen); @@ -113,8 +129,7 @@ namespace BizHawk.Emulation.DiscSystem if (!cfr.IsHardcodedResolve) cfr.SetBaseDirectory(cueDirPath); // parse the cue file - var parseJob = new ParseCueJob(); - parseJob.IN_CueString = cueContent; + var parseJob = new ParseCueJob(cueContent); var okParse = true; try { @@ -131,11 +146,7 @@ namespace BizHawk.Emulation.DiscSystem // compile the cue file // includes resolving required bin files and finding out what would processing would need to happen in order to load the cue - var compileJob = new CompileCueJob - { - IN_CueContext = cueContext, - IN_CueFile = parseJob.OUT_CueFile - }; + var compileJob = new CompileCueJob(parseJob.OUT_CueFile, cueContext); var okCompile = true; try { @@ -159,7 +170,7 @@ namespace BizHawk.Emulation.DiscSystem } // actually load it all up - var loadJob = new LoadCueJob { IN_CompileJob = compileJob }; + var loadJob = new LoadCueJob(compileJob); loadJob.Run(); //TODO need better handling of log output if (!string.IsNullOrEmpty(loadJob.OUT_Log)) Console.WriteLine(loadJob.OUT_Log); diff --git a/src/BizHawk.Emulation.DiscSystem/DiscoHawkLogic/DiscoHawkLogic.cs b/src/BizHawk.Emulation.DiscSystem/DiscoHawkLogic/DiscoHawkLogic.cs index 520c36966c..95c00b244f 100644 --- a/src/BizHawk.Emulation.DiscSystem/DiscoHawkLogic/DiscoHawkLogic.cs +++ b/src/BizHawk.Emulation.DiscSystem/DiscoHawkLogic/DiscoHawkLogic.cs @@ -27,18 +27,14 @@ namespace BizHawk.Emulation.DiscSystem sw.WriteLine("BEGIN COMPARE: {0}\nSRC {1} vs DST {2}", infile, loadDiscInterface, cmpif); //reload the original disc, with new policies as needed - var dmj = new DiscMountJob - { - IN_DiscInterface = loadDiscInterface, - IN_DiscMountPolicy = new DiscMountPolicy { CUE_PregapContradictionModeA = cmpif != DiscInterface.MednaDisc }, - IN_FromPath = infile - }; - + var dmj = new DiscMountJob( + fromPath: infile, + discMountPolicy: new DiscMountPolicy { CUE_PregapContradictionModeA = cmpif != DiscInterface.MednaDisc }, + discInterface: loadDiscInterface); dmj.Run(); - srcDisc = dmj.OUT_Disc; - var dstDmj = new DiscMountJob { IN_DiscInterface = cmpif, IN_FromPath = infile }; + var dstDmj = new DiscMountJob(fromPath: infile, discInterface: cmpif); dstDmj.Run(); dstDisc = dstDmj.OUT_Disc; @@ -283,7 +279,7 @@ namespace BizHawk.Emulation.DiscSystem } // TODO - write it out - var dmj = new DiscMountJob { IN_DiscInterface = loadDiscInterface, IN_FromPath = infile }; + var dmj = new DiscMountJob(fromPath: infile, discInterface: loadDiscInterface); dmj.Run(); } diff --git a/src/BizHawk.Emulation.DiscSystem/Internal/Jobs/LoadSBIJob.cs b/src/BizHawk.Emulation.DiscSystem/Internal/Jobs/LoadSBIJob.cs index dae9c11846..82d71d3650 100644 --- a/src/BizHawk.Emulation.DiscSystem/Internal/Jobs/LoadSBIJob.cs +++ b/src/BizHawk.Emulation.DiscSystem/Internal/Jobs/LoadSBIJob.cs @@ -10,10 +10,10 @@ namespace BizHawk.Emulation.DiscSystem.SBI /// internal class LoadSBIJob : DiscJob { - /// - /// The file to be loaded - /// - public string IN_Path { private get; set; } + private readonly string IN_Path; + + /// The file to be loaded + public LoadSBIJob(string path) => IN_Path = path; /// /// The resulting interpreted data diff --git a/src/BizHawk.Emulation.DiscSystem/Internal/Jobs/Synthesize_A0A1A2_Job.cs b/src/BizHawk.Emulation.DiscSystem/Internal/Jobs/Synthesize_A0A1A2_Job.cs index 77013e3ad5..a710ff503e 100644 --- a/src/BizHawk.Emulation.DiscSystem/Internal/Jobs/Synthesize_A0A1A2_Job.cs +++ b/src/BizHawk.Emulation.DiscSystem/Internal/Jobs/Synthesize_A0A1A2_Job.cs @@ -11,25 +11,29 @@ namespace BizHawk.Emulation.DiscSystem /// internal class Synthesize_A0A1A2_Job { - /// - /// "First Recorded Track Number" value for TOC (usually 1) - /// - public int IN_FirstRecordedTrackNumber { private get; set; } + private readonly int IN_FirstRecordedTrackNumber; - /// - /// "Last Recorded Track Number" value for TOC - /// - public int IN_LastRecordedTrackNumber { private get; set; } + private readonly int IN_LastRecordedTrackNumber; - /// - /// The absolute timestamp of the lead-out track - /// - public int IN_LeadoutTimestamp { private get; set; } + private readonly SessionFormat IN_Session1Format; - /// - /// The session format for this TOC - /// - public SessionFormat IN_Session1Format { private get; set; } + private readonly int IN_LeadoutTimestamp; + + /// "First Recorded Track Number" value for TOC (usually 1) + /// "Last Recorded Track Number" value for TOC + /// The session format for this TOC + /// The absolute timestamp of the lead-out track + public Synthesize_A0A1A2_Job( + int firstRecordedTrackNumber, + int lastRecordedTrackNumber, + SessionFormat session1Format, + int leadoutTimestamp) + { + IN_FirstRecordedTrackNumber = firstRecordedTrackNumber; + IN_LastRecordedTrackNumber = lastRecordedTrackNumber; + IN_Session1Format = session1Format; + IN_LeadoutTimestamp = leadoutTimestamp; + } /// appends the new entries to the provided list /// is or a non-member diff --git a/src/BizHawk.Emulation.DiscSystem/Internal/Jobs/Synthesize_DiscStructure_From_DiscTOC_Job.cs b/src/BizHawk.Emulation.DiscSystem/Internal/Jobs/Synthesize_DiscStructure_From_DiscTOC_Job.cs index 698c2c98f6..091a932c18 100644 --- a/src/BizHawk.Emulation.DiscSystem/Internal/Jobs/Synthesize_DiscStructure_From_DiscTOC_Job.cs +++ b/src/BizHawk.Emulation.DiscSystem/Internal/Jobs/Synthesize_DiscStructure_From_DiscTOC_Job.cs @@ -4,9 +4,17 @@ namespace BizHawk.Emulation.DiscSystem { internal class Synthesize_DiscStructure_From_DiscTOC_Job { - public Disc IN_Disc { private get; set; } - public DiscTOC TOCRaw; - public DiscStructure Result; + private readonly Disc IN_Disc; + + private readonly DiscTOC TOCRaw; + + public Synthesize_DiscStructure_From_DiscTOC_Job(Disc disc, DiscTOC tocRaw) + { + IN_Disc = disc; + TOCRaw = tocRaw; + } + + public DiscStructure Result { get; private set; } /// first track of is not 1 public void Run() diff --git a/src/BizHawk.Emulation.DiscSystem/Internal/Jobs/Synthesize_DiscTOC_From_RawTOCEntries_Job.cs b/src/BizHawk.Emulation.DiscSystem/Internal/Jobs/Synthesize_DiscTOC_From_RawTOCEntries_Job.cs index e09b4ad5cc..ab8f6320b1 100644 --- a/src/BizHawk.Emulation.DiscSystem/Internal/Jobs/Synthesize_DiscTOC_From_RawTOCEntries_Job.cs +++ b/src/BizHawk.Emulation.DiscSystem/Internal/Jobs/Synthesize_DiscTOC_From_RawTOCEntries_Job.cs @@ -10,9 +10,15 @@ namespace BizHawk.Emulation.DiscSystem /// internal class Synthesize_DiscTOC_From_RawTOCEntries_Job { - public IEnumerable Entries; - public List Log = new List(); - public DiscTOC Result; + private readonly IReadOnlyList Entries; + + public Synthesize_DiscTOC_From_RawTOCEntries_Job(IReadOnlyList entries) => Entries = entries; + + public DiscTOC Result { get; private set; } + + private readonly List Log = new(); + + public IReadOnlyList GetLog() => Log; public void Run() {