Added event to be able to intercept library path creation

This commit is contained in:
Darth Affe 2024-03-22 23:42:15 +01:00
parent 4b8faf24d0
commit 6d6bfe3fc6

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace StableDiffusion.NET;
@ -23,6 +24,12 @@ public static class Backends
#endregion
#region Events
public static event EventHandler<LibraryPathCreatingEventArgs>? LibraryPathCreating;
#endregion
#region Methods
public static bool RegisterBackend(IBackend backend)
@ -40,5 +47,25 @@ public static class Backends
public static bool UnregisterBackend(IBackend backend)
=> CUSTOM_BACKENDS.Remove(backend);
internal static string GetFullPath(string os, string backend, string libName)
{
string path = Path.Combine("runtimes", os, "native", backend, libName);
return OnLibraryPathCreating(path);
}
private static string OnLibraryPathCreating(string path)
{
try
{
LibraryPathCreatingEventArgs args = new(path);
LibraryPathCreating?.Invoke(null, args);
return args.Path;
}
catch
{
return path;
}
}
#endregion
}