fix: redirect AppContext.BaseDirectory to server root for FourKit plugins

AppContext.BaseDirectory pointed to the runtime/ subfolder where the
self-contained .NET payload lives, causing plugins that use it for file
paths to write to the wrong directory. Now set to the server exe
directory at startup via AppContext.SetData.

Also adds serverDirectory and dataDirectory properties to ServerPlugin
so plugin authors have convenient access to the server root and a
per-plugin data folder (plugins/<PluginName>/) without needing to
resolve paths manually.
This commit is contained in:
itsRevela
2026-04-10 02:03:44 -05:00
parent d14e46701c
commit 8f41d34325
3 changed files with 37 additions and 3 deletions
+7 -1
View File
@@ -25,9 +25,15 @@ public static partial class FourKitHost
// host exe's directory instead so end users see a top-level plugins/.
string hostExePath = Environment.ProcessPath ?? AppContext.BaseDirectory;
string serverRoot = Path.GetDirectoryName(hostExePath) ?? AppContext.BaseDirectory;
// Redirect AppContext.BaseDirectory to the server root so that
// plugins using AppContext.BaseDirectory get the exe directory
// instead of the runtime/ subfolder.
AppContext.SetData("APP_CONTEXT_BASE_DIRECTORY", serverRoot + Path.DirectorySeparatorChar);
string pluginsDir = Path.Combine(serverRoot, "plugins");
s_loader = new PluginLoader();
s_loader.LoadPlugins(pluginsDir);
s_loader.LoadPlugins(pluginsDir, serverRoot);
s_loader.EnableAll();
ServerLog.Info("fourkit", "Plugin system ready.");