2011-10-24 11:38:10 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
using CUETools.Codecs;
|
|
|
|
|
|
using CUETools.Compression;
|
|
|
|
|
|
using CUETools.Ripper;
|
|
|
|
|
|
|
|
|
|
|
|
namespace CUETools.Processor
|
|
|
|
|
|
{
|
|
|
|
|
|
public static class CUEProcessorPlugins
|
|
|
|
|
|
{
|
2018-03-25 17:24:27 -04:00
|
|
|
|
public static List<IAudioEncoderSettings> encs;
|
|
|
|
|
|
public static List<IAudioDecoderSettings> decs;
|
2011-10-24 11:38:10 +00:00
|
|
|
|
public static List<Type> arcp;
|
|
|
|
|
|
public static List<string> arcp_fmt;
|
|
|
|
|
|
public static Type hdcd;
|
|
|
|
|
|
public static Type ripper;
|
|
|
|
|
|
|
|
|
|
|
|
static CUEProcessorPlugins()
|
|
|
|
|
|
{
|
2018-03-25 17:24:27 -04:00
|
|
|
|
encs = new List<IAudioEncoderSettings>();
|
|
|
|
|
|
decs = new List<IAudioDecoderSettings>();
|
2011-10-24 11:38:10 +00:00
|
|
|
|
arcp = new List<Type>();
|
|
|
|
|
|
arcp_fmt = new List<string>();
|
|
|
|
|
|
|
2018-03-24 12:15:49 -04:00
|
|
|
|
encs.Add(new Codecs.WAV.EncoderSettings());
|
|
|
|
|
|
decs.Add(new Codecs.WAV.DecoderSettings());
|
2011-10-24 11:38:10 +00:00
|
|
|
|
|
|
|
|
|
|
//ApplicationSecurityInfo asi = new ApplicationSecurityInfo(AppDomain.CurrentDomain.ActivationContext);
|
|
|
|
|
|
//string arch = asi.ApplicationId.ProcessorArchitecture;
|
|
|
|
|
|
//ActivationContext is null most of the time :(
|
|
|
|
|
|
|
2018-03-11 18:42:41 -04:00
|
|
|
|
string plugins_path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "plugins");
|
2011-10-24 11:38:10 +00:00
|
|
|
|
if (Directory.Exists(plugins_path))
|
2018-03-11 18:42:41 -04:00
|
|
|
|
{
|
2011-10-24 11:38:10 +00:00
|
|
|
|
AddPluginDirectory(plugins_path);
|
2018-03-11 18:42:41 -04:00
|
|
|
|
string arch = Type.GetType("Mono.Runtime", false) != null ? "mono" : Marshal.SizeOf(typeof(IntPtr)) == 8 ? "x64" : "win32";
|
|
|
|
|
|
plugins_path = Path.Combine(plugins_path, arch);
|
|
|
|
|
|
if (Directory.Exists(plugins_path))
|
|
|
|
|
|
AddPluginDirectory(plugins_path);
|
|
|
|
|
|
}
|
2011-10-24 11:38:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static void AddPluginDirectory(string plugins_path)
|
|
|
|
|
|
{
|
2018-02-18 11:05:48 -05:00
|
|
|
|
foreach (string plugin_path in Directory.GetFiles(plugins_path, "CUETools.*.dll", SearchOption.TopDirectoryOnly))
|
2011-10-24 11:38:10 +00:00
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
AddPlugin(plugin_path);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
System.Diagnostics.Trace.WriteLine(ex.Message);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static void AddPlugin(string plugin_path)
|
|
|
|
|
|
{
|
|
|
|
|
|
AssemblyName name = AssemblyName.GetAssemblyName(plugin_path);
|
2018-03-11 17:07:48 -04:00
|
|
|
|
Assembly assembly = Assembly.Load(name);
|
2011-10-24 11:38:10 +00:00
|
|
|
|
System.Diagnostics.Trace.WriteLine("Loaded " + assembly.FullName);
|
|
|
|
|
|
foreach (Type type in assembly.GetExportedTypes())
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2018-03-24 12:15:49 -04:00
|
|
|
|
if (!type.IsClass || type.IsAbstract) continue;
|
2018-03-25 17:24:27 -04:00
|
|
|
|
if (type.GetInterface(typeof(IAudioDecoderSettings).Name) != null)
|
2011-10-24 11:38:10 +00:00
|
|
|
|
{
|
2018-03-25 17:24:27 -04:00
|
|
|
|
decs.Add(Activator.CreateInstance(type) as IAudioDecoderSettings);
|
2011-10-24 11:38:10 +00:00
|
|
|
|
}
|
2018-03-25 17:24:27 -04:00
|
|
|
|
if (type.GetInterface(typeof(IAudioEncoderSettings).Name) != null)
|
2011-10-24 11:38:10 +00:00
|
|
|
|
{
|
2018-03-25 17:24:27 -04:00
|
|
|
|
encs.Add(Activator.CreateInstance(type) as IAudioEncoderSettings);
|
2011-10-24 11:38:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
CompressionProviderClass archclass = Attribute.GetCustomAttribute(type, typeof(CompressionProviderClass)) as CompressionProviderClass;
|
|
|
|
|
|
if (archclass != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
arcp.Add(type);
|
|
|
|
|
|
if (!arcp_fmt.Contains(archclass.Extension))
|
|
|
|
|
|
arcp_fmt.Add(archclass.Extension);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (type.Name == "HDCDDotNet")
|
|
|
|
|
|
{
|
|
|
|
|
|
hdcd = type;
|
|
|
|
|
|
}
|
2018-03-24 12:15:49 -04:00
|
|
|
|
if (type.GetInterface(typeof(ICDRipper).Name) != null)
|
2011-10-24 11:38:10 +00:00
|
|
|
|
{
|
|
|
|
|
|
ripper = type;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
System.Diagnostics.Trace.WriteLine(ex.Message);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|