mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Move cuetools.net codec locally.
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace CUETools.Codecs
|
||||
{
|
||||
[JsonObject(MemberSerialization.OptIn)]
|
||||
public class AudioDecoderSettingsViewModel : INotifyPropertyChanged
|
||||
{
|
||||
[JsonProperty]
|
||||
public IAudioDecoderSettings Settings = null;
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
[JsonConstructor]
|
||||
private AudioDecoderSettingsViewModel()
|
||||
{
|
||||
}
|
||||
|
||||
public AudioDecoderSettingsViewModel(IAudioDecoderSettings settings)
|
||||
{
|
||||
this.Settings = settings;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
|
||||
public string FullName => Name + " [" + Extension + "]";
|
||||
|
||||
public string Path
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Settings is CommandLine.DecoderSettings)
|
||||
return (Settings as CommandLine.DecoderSettings).Path;
|
||||
return "";
|
||||
}
|
||||
set
|
||||
{
|
||||
if (Settings is CommandLine.DecoderSettings)
|
||||
(Settings as CommandLine.DecoderSettings).Path = value;
|
||||
else throw new InvalidOperationException();
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Path"));
|
||||
}
|
||||
}
|
||||
public string Parameters
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Settings is CommandLine.DecoderSettings)
|
||||
return (Settings as CommandLine.DecoderSettings).Parameters;
|
||||
return "";
|
||||
}
|
||||
set
|
||||
{
|
||||
if (Settings is CommandLine.DecoderSettings)
|
||||
(Settings as CommandLine.DecoderSettings).Parameters = value;
|
||||
else throw new InvalidOperationException();
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Parameters"));
|
||||
}
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get => Settings.Name;
|
||||
set
|
||||
{
|
||||
if (Settings is CommandLine.DecoderSettings)
|
||||
(Settings as CommandLine.DecoderSettings).Name = value;
|
||||
else throw new InvalidOperationException();
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Name"));
|
||||
}
|
||||
}
|
||||
|
||||
public string Extension
|
||||
{
|
||||
get => Settings.Extension;
|
||||
set
|
||||
{
|
||||
if (Settings is CommandLine.DecoderSettings)
|
||||
(Settings as CommandLine.DecoderSettings).Extension = value;
|
||||
else throw new InvalidOperationException();
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Extension"));
|
||||
}
|
||||
}
|
||||
|
||||
public string DotExtension => "." + Extension;
|
||||
|
||||
public bool CanBeDeleted => Settings is CommandLine.DecoderSettings;
|
||||
|
||||
public bool IsValid =>
|
||||
(Settings != null)
|
||||
&& (Settings is CommandLine.DecoderSettings ? (Settings as CommandLine.DecoderSettings).Path != "" : true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace CUETools.Codecs
|
||||
{
|
||||
[JsonObject(MemberSerialization.OptIn)]
|
||||
public class AudioEncoderSettingsViewModel : INotifyPropertyChanged
|
||||
{
|
||||
[JsonProperty]
|
||||
public IAudioEncoderSettings Settings = null;
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
[JsonConstructor]
|
||||
private AudioEncoderSettingsViewModel()
|
||||
{
|
||||
}
|
||||
|
||||
public AudioEncoderSettingsViewModel(IAudioEncoderSettings settings)
|
||||
{
|
||||
this.Settings = settings;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
|
||||
public string FullName => Name + " [" + Extension + "]";
|
||||
|
||||
public string Path
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Settings is CommandLine.EncoderSettings)
|
||||
return (Settings as CommandLine.EncoderSettings).Path;
|
||||
return "";
|
||||
}
|
||||
set
|
||||
{
|
||||
var settings = this.Settings as CommandLine.EncoderSettings;
|
||||
if (settings == null) throw new InvalidOperationException();
|
||||
settings.Path = value;
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Path"));
|
||||
}
|
||||
}
|
||||
|
||||
public string Parameters
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Settings is CommandLine.EncoderSettings)
|
||||
return (Settings as CommandLine.EncoderSettings).Parameters;
|
||||
return "";
|
||||
}
|
||||
set
|
||||
{
|
||||
var settings = this.Settings as CommandLine.EncoderSettings;
|
||||
if (settings == null) throw new InvalidOperationException();
|
||||
settings.Parameters = value;
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Parameters"));
|
||||
}
|
||||
}
|
||||
|
||||
public bool Lossless
|
||||
{
|
||||
get => Settings.Lossless;
|
||||
set
|
||||
{
|
||||
var settings = this.Settings as CommandLine.EncoderSettings;
|
||||
if (settings == null) throw new InvalidOperationException();
|
||||
settings.Lossless = value;
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Lossless"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public string Name
|
||||
{
|
||||
get => Settings.Name;
|
||||
set
|
||||
{
|
||||
var settings = this.Settings as CommandLine.EncoderSettings;
|
||||
if (settings == null) throw new InvalidOperationException();
|
||||
settings.Name = value;
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Name"));
|
||||
}
|
||||
}
|
||||
|
||||
public string Extension
|
||||
{
|
||||
get => Settings.Extension;
|
||||
set
|
||||
{
|
||||
var settings = this.Settings as CommandLine.EncoderSettings;
|
||||
if (settings == null) throw new InvalidOperationException();
|
||||
settings.Extension = value;
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Extension"));
|
||||
}
|
||||
}
|
||||
|
||||
public string DotExtension => "." + Extension;
|
||||
|
||||
public string SupportedModes
|
||||
{
|
||||
get => Settings.SupportedModes;
|
||||
set
|
||||
{
|
||||
var settings = this.Settings as CommandLine.EncoderSettings;
|
||||
if (settings == null) throw new InvalidOperationException();
|
||||
settings.SupportedModes = value;
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("SupportedModes"));
|
||||
}
|
||||
}
|
||||
|
||||
public int EncoderModeIndex
|
||||
{
|
||||
get
|
||||
{
|
||||
string[] modes = this.SupportedModes.Split(' ');
|
||||
if (modes == null || modes.Length < 2)
|
||||
return -1;
|
||||
for (int i = 0; i < modes.Length; i++)
|
||||
if (modes[i] == this.Settings.EncoderMode)
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
public bool CanBeDeleted => Settings is CommandLine.EncoderSettings;
|
||||
|
||||
public bool IsValid =>
|
||||
(Settings != null)
|
||||
&& (Settings is CommandLine.EncoderSettings ? (Settings as CommandLine.EncoderSettings).Path != "" : true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace CUETools.Codecs
|
||||
{
|
||||
public class DecoderListViewModel : BindingList<AudioDecoderSettingsViewModel>
|
||||
{
|
||||
private List<IAudioDecoderSettings> model;
|
||||
|
||||
public DecoderListViewModel(List<IAudioDecoderSettings> model)
|
||||
: base()
|
||||
{
|
||||
this.model = model;
|
||||
model.ForEach(item => Add(new AudioDecoderSettingsViewModel(item)));
|
||||
AddingNew += OnAddingNew;
|
||||
}
|
||||
|
||||
private void OnAddingNew(object sender, AddingNewEventArgs e)
|
||||
{
|
||||
var item = new CommandLine.DecoderSettings("new", "wav", "", "");
|
||||
model.Add(item);
|
||||
e.NewObject = new AudioDecoderSettingsViewModel(item);
|
||||
}
|
||||
|
||||
public bool TryGetValue(string extension, string name, out AudioDecoderSettingsViewModel result)
|
||||
{
|
||||
foreach (AudioDecoderSettingsViewModel udc in this)
|
||||
{
|
||||
if (udc.Settings.Extension == extension && udc.Settings.Name == name)
|
||||
{
|
||||
result = udc;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
result = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
public AudioDecoderSettingsViewModel GetDefault(string extension)
|
||||
{
|
||||
AudioDecoderSettingsViewModel result = null;
|
||||
foreach (AudioDecoderSettingsViewModel udc in this)
|
||||
{
|
||||
if (udc.Settings.Extension == extension && (result == null || result.Settings.Priority < udc.Settings.Priority))
|
||||
{
|
||||
result = udc;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace CUETools.Codecs
|
||||
{
|
||||
public class EncoderListViewModel : BindingList<AudioEncoderSettingsViewModel>
|
||||
{
|
||||
private List<IAudioEncoderSettings> model;
|
||||
|
||||
public EncoderListViewModel(List<IAudioEncoderSettings> model)
|
||||
: base()
|
||||
{
|
||||
this.model = model;
|
||||
model.ForEach(item => Add(new AudioEncoderSettingsViewModel(item)));
|
||||
AddingNew += OnAddingNew;
|
||||
}
|
||||
|
||||
private void OnAddingNew(object sender, AddingNewEventArgs e)
|
||||
{
|
||||
var item = new CommandLine.EncoderSettings("new", "wav", true, "", "", "", "");
|
||||
model.Add(item);
|
||||
e.NewObject = new AudioEncoderSettingsViewModel(item);
|
||||
}
|
||||
|
||||
public bool TryGetValue(string extension, bool lossless, string name, out AudioEncoderSettingsViewModel result)
|
||||
{
|
||||
//result = this.Where(udc => udc.settings.Extension == extension && udc.settings.Lossless == lossless && udc.settings.Name == name).First();
|
||||
foreach (AudioEncoderSettingsViewModel udc in this)
|
||||
{
|
||||
if (udc.Settings.Extension == extension && udc.Settings.Lossless == lossless && udc.Settings.Name == name)
|
||||
{
|
||||
result = udc;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
result = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
public AudioEncoderSettingsViewModel GetDefault(string extension, bool lossless)
|
||||
{
|
||||
AudioEncoderSettingsViewModel result = null;
|
||||
foreach (AudioEncoderSettingsViewModel udc in this)
|
||||
{
|
||||
if (udc.Settings.Extension == extension && udc.Settings.Lossless == lossless && (result == null || result.Settings.Priority < udc.Settings.Priority))
|
||||
{
|
||||
result = udc;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user