
using System.Reflection;

using MpvNet.Extensions;

namespace MpvNet;

public class ExtensionLoader
{
    public event Action<Exception>? UnhandledException;

    readonly List<object?> _refs = [];

    void LoadDll(string path)
    {
        if (!File.Exists(path))
            return;

        try
        {
            Assembly asm = Assembly.LoadFile(path);
            var type = asm.GetTypes().Where(typeof(IExtension).IsAssignableFrom).First();
            _refs.Add(Activator.CreateInstance(type));
        }
        catch (Exception ex)
        {
            UnhandledException?.Invoke(ex);
        }
    }

    public void LoadFolder(string path)
    {
        if (Directory.Exists(path))
        {
            foreach (string dir in Directory.GetDirectories(path))
            {
                LoadDll(dir.Separator + Path.GetFileName(dir) + ".dll");
            }
        }
    }
}

public interface IExtension
{
}
