Redesigned the DiscordBotCore by splitting it into multiple projects. Created a WebUI and preparing to remove the DiscordBot application

This commit is contained in:
2025-04-04 22:07:30 +03:00
parent 62ba5ec63d
commit a4afb28f36
2290 changed files with 76694 additions and 17052 deletions
+16 -11
View File
@@ -1,18 +1,23 @@
using System.Runtime.InteropServices;
using System.Net.Mime;
using System.Runtime.InteropServices;
using DiscordBotCore;
using DiscordBotCore.Logging;
using DiscordBotCore.Others;
using DiscordBotCore.Utilities;
namespace CppCompatibilityModule.Extern
{
public sealed class ExternLibrary
{
private readonly ILogger _Logger;
public string LibraryPath { get; init; }
public IntPtr LibraryHandle { get; private set; }
public ExternLibrary(string libraryPath)
public ExternLibrary(ILogger logger, string libraryPath)
{
LibraryPath = libraryPath;
LibraryHandle = IntPtr.Zero;
_Logger = logger;
}
public Result InitializeLibrary()
@@ -22,7 +27,7 @@ namespace CppCompatibilityModule.Extern
return Result.Success();
}
Application.CurrentApplication.Logger.Log($"Loading library {LibraryPath}");
_Logger.Log($"Loading library {LibraryPath}");
if(!NativeLibrary.TryLoad(LibraryPath, out IntPtr hModule))
@@ -30,7 +35,7 @@ namespace CppCompatibilityModule.Extern
return Result.Failure(new DllNotFoundException($"Unable to load library {LibraryPath}"));
}
Application.CurrentApplication.Logger.Log($"Library {LibraryPath} loaded successfully [{hModule}]");
_Logger.Log($"Library {LibraryPath} loaded successfully [{hModule}]");
LibraryHandle = hModule;
@@ -47,7 +52,7 @@ namespace CppCompatibilityModule.Extern
NativeLibrary.Free(LibraryHandle);
LibraryHandle = IntPtr.Zero;
Application.CurrentApplication.Logger.Log($"Library {LibraryPath} freed successfully");
_Logger.Log($"Library {LibraryPath} freed successfully");
}
private IntPtr GetFunctionPointer(string functionName)
@@ -69,11 +74,11 @@ namespace CppCompatibilityModule.Extern
{
IntPtr functionPointer = GetFunctionPointer(methodName);
Application.CurrentApplication.Logger.Log($"Function pointer for {methodName} obtained successfully [address: {functionPointer}]");
_Logger.Log($"Function pointer for {methodName} obtained successfully [address: {functionPointer}]");
T result = (T)Marshal.GetDelegateForFunctionPointer(functionPointer, typeof(T));
Application.CurrentApplication.Logger.Log($"Delegate for {methodName} created successfully");
_Logger.Log($"Delegate for {methodName} created successfully");
return result;
}
@@ -82,7 +87,7 @@ namespace CppCompatibilityModule.Extern
{
IntPtr functionPointer = Marshal.GetFunctionPointerForDelegate(functionDelegate);
Application.CurrentApplication.Logger.Log($"Function pointer for delegate {functionDelegate.Method.Name} obtained successfully [address: {functionPointer}]");
_Logger.Log($"Function pointer for delegate {functionDelegate.Method.Name} obtained successfully [address: {functionPointer}]");
return functionPointer;
}
@@ -107,7 +112,7 @@ namespace CppCompatibilityModule.Extern
var result = setterDelegate.DynamicInvoke(executableFunctionPtr);
Application.CurrentApplication.Logger.Log($"Function {setterExternFunctionName} bound to local action successfully");
_Logger.Log($"Function {setterExternFunctionName} bound to local action successfully");
return result;
}
@@ -118,7 +123,7 @@ namespace CppCompatibilityModule.Extern
functionDelegate(ref parameter);
Application.CurrentApplication.Logger.Log($"Function {methodName} called successfully with parameter");
_Logger.Log($"Function {methodName} called successfully with parameter");
}
public void CallFunction(string methodName)
@@ -127,7 +132,7 @@ namespace CppCompatibilityModule.Extern
functionDelegate();
Application.CurrentApplication.Logger.Log($"Function {methodName} called successfully");
_Logger.Log($"Function {methodName} called successfully");
}
}
}
@@ -1,4 +1,5 @@
using DiscordBotCore;
using DiscordBotCore.Logging;
using DiscordBotCore.Others;
namespace CppCompatibilityModule.Extern;
@@ -7,11 +8,13 @@ public class ExternalApplication
{
public Guid ApplicationId { get; private set; }
private readonly ExternLibrary _ExternLibrary;
private readonly ILogger _Logger;
private ExternalApplication(Guid applicationGuid, ExternLibrary library)
private ExternalApplication(ILogger logger, Guid applicationGuid, ExternLibrary library)
{
this.ApplicationId = applicationGuid;
this._ExternLibrary = library;
this._Logger = logger;
}
internal void CallFunction(string methodName, ref object parameter)
@@ -39,15 +42,15 @@ public class ExternalApplication
_ExternLibrary.FreeLibrary();
}
public static ExternalApplication? CreateFromDllFile(string dllFilePath)
public static ExternalApplication? CreateFromDllFile(ILogger logger, string dllFilePath)
{
ExternLibrary library = new ExternLibrary(dllFilePath);
ExternLibrary library = new ExternLibrary(logger, dllFilePath);
var result = library.InitializeLibrary();
return result.Match<ExternalApplication?>(
() => new ExternalApplication(Guid.NewGuid(), library),
() => new ExternalApplication(logger, Guid.NewGuid(), library),
(ex) => {
Application.CurrentApplication.Logger.Log(ex.Message, LogType.Error);
logger.Log(ex.Message, LogType.Error);
library.FreeLibrary();
return null;
});