mirror of
https://github.com/aaru-dps/RedBookPlayer.git
synced 2025-12-16 19:24:41 +00:00
Move all image logic to factory
This commit is contained in:
@@ -1,10 +1,44 @@
|
|||||||
|
using System.IO;
|
||||||
using Aaru.CommonTypes.Interfaces;
|
using Aaru.CommonTypes.Interfaces;
|
||||||
using Aaru.CommonTypes.Metadata;
|
using Aaru.CommonTypes.Metadata;
|
||||||
|
using Aaru.DiscImages;
|
||||||
|
using Aaru.Filters;
|
||||||
|
|
||||||
namespace RedBookPlayer.Discs
|
namespace RedBookPlayer.Discs
|
||||||
{
|
{
|
||||||
public static class OpticalDiscFactory
|
public static class OpticalDiscFactory
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Generate an OpticalDisc from an input path
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="path">Path to load the image from</param>
|
||||||
|
/// <param name="autoPlay">True if the image should be playable immediately, false otherwise</param>
|
||||||
|
/// <returns>Instantiated OpticalDisc, if possible</returns>
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Generate an OpticalDisc from an input IOpticalMediaImage
|
/// Generate an OpticalDisc from an input IOpticalMediaImage
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.IO;
|
|
||||||
using Aaru.CommonTypes.Enums;
|
using Aaru.CommonTypes.Enums;
|
||||||
using Aaru.DiscImages;
|
|
||||||
using Aaru.Filters;
|
|
||||||
using ReactiveUI;
|
using ReactiveUI;
|
||||||
using RedBookPlayer.Discs;
|
using RedBookPlayer.Discs;
|
||||||
|
|
||||||
@@ -188,32 +185,14 @@ namespace RedBookPlayer.Hardware
|
|||||||
Initialized = false;
|
Initialized = false;
|
||||||
_soundOutput = new SoundOutput();
|
_soundOutput = new SoundOutput();
|
||||||
_soundOutput.SetDeEmphasis(false);
|
_soundOutput.SetDeEmphasis(false);
|
||||||
_opticalDisc = null;
|
|
||||||
|
|
||||||
try
|
// Initalize the disc
|
||||||
{
|
_opticalDisc = OpticalDiscFactory.GenerateFromPath(path, autoPlay);
|
||||||
// Validate the image exists
|
if(_opticalDisc == null || !_opticalDisc.Initialized)
|
||||||
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
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
// Add event handling for the optical disc
|
// Add event handling for the optical disc
|
||||||
if(_opticalDisc != null)
|
_opticalDisc.PropertyChanged += OpticalDiscStateChanged;
|
||||||
_opticalDisc.PropertyChanged += OpticalDiscStateChanged;
|
|
||||||
|
|
||||||
// Initialize the sound output
|
// Initialize the sound output
|
||||||
_soundOutput.Init(_opticalDisc, autoPlay, defaultVolume);
|
_soundOutput.Init(_opticalDisc, autoPlay, defaultVolume);
|
||||||
|
|||||||
Reference in New Issue
Block a user