From 6d6bfe3fc67568039ec0789bd78ce2b6fca35f49 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Fri, 22 Mar 2024 23:42:15 +0100 Subject: [PATCH] Added event to be able to intercept library path creation --- StableDiffusion.NET/Backends/Backends.cs | 27 ++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/StableDiffusion.NET/Backends/Backends.cs b/StableDiffusion.NET/Backends/Backends.cs index c660ed9..d345f04 100644 --- a/StableDiffusion.NET/Backends/Backends.cs +++ b/StableDiffusion.NET/Backends/Backends.cs @@ -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? 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 } \ No newline at end of file