diff --git a/RedBookPlayer/Discs/OpticalDiscFactory.cs b/RedBookPlayer/Discs/OpticalDiscFactory.cs index 99d9257..178a87a 100644 --- a/RedBookPlayer/Discs/OpticalDiscFactory.cs +++ b/RedBookPlayer/Discs/OpticalDiscFactory.cs @@ -1,10 +1,44 @@ +using System.IO; using Aaru.CommonTypes.Interfaces; using Aaru.CommonTypes.Metadata; +using Aaru.DiscImages; +using Aaru.Filters; namespace RedBookPlayer.Discs { public static class OpticalDiscFactory { + /// + /// Generate an OpticalDisc from an input path + /// + /// Path to load the image from + /// True if the image should be playable immediately, false otherwise + /// Instantiated OpticalDisc, if possible + public static OpticalDisc GenerateFromPath(string path, bool autoPlay) + { + try + { + // Validate the image exists + if(string.IsNullOrWhiteSpace(path) || !File.Exists(path)) + return null; + + // Load the disc image to memory + // TODO: Assumes Aaruformat right now for all + var image = new AaruFormat(); + var filter = new ZZZNoFilter(); + filter.Open(path); + image.Open(filter); + + // Generate and instantiate the disc + return GenerateFromImage(image, autoPlay); + } + catch + { + // All errors mean an invalid image in some way + return null; + } + } + /// /// Generate an OpticalDisc from an input IOpticalMediaImage /// diff --git a/RedBookPlayer/Hardware/Player.cs b/RedBookPlayer/Hardware/Player.cs index 0733e5a..746729c 100644 --- a/RedBookPlayer/Hardware/Player.cs +++ b/RedBookPlayer/Hardware/Player.cs @@ -1,9 +1,6 @@ using System; using System.ComponentModel; -using System.IO; using Aaru.CommonTypes.Enums; -using Aaru.DiscImages; -using Aaru.Filters; using ReactiveUI; using RedBookPlayer.Discs; @@ -188,32 +185,14 @@ namespace RedBookPlayer.Hardware Initialized = false; _soundOutput = new SoundOutput(); _soundOutput.SetDeEmphasis(false); - _opticalDisc = null; - try - { - // Validate the image exists - if(string.IsNullOrWhiteSpace(path) || !File.Exists(path)) - return; - - // Load the disc image to memory - var image = new AaruFormat(); - var filter = new ZZZNoFilter(); - filter.Open(path); - image.Open(filter); - - // Generate and instantiate the disc - _opticalDisc = OpticalDiscFactory.GenerateFromImage(image, autoPlay); - } - catch - { - // All errors mean an invalid image in some way + // Initalize the disc + _opticalDisc = OpticalDiscFactory.GenerateFromPath(path, autoPlay); + if(_opticalDisc == null || !_opticalDisc.Initialized) return; - } // Add event handling for the optical disc - if(_opticalDisc != null) - _opticalDisc.PropertyChanged += OpticalDiscStateChanged; + _opticalDisc.PropertyChanged += OpticalDiscStateChanged; // Initialize the sound output _soundOutput.Init(_opticalDisc, autoPlay, defaultVolume);