Add Plugins tab, remove WinForms launcher, add BUILD.md
- Add Plugins tab to Avalonia launcher with add/remove plugin DLL management - Plugin paths sync to engine.json for runtime loading - Engine loads plugins from custom DLL paths via EngineSettings - Remove defunct WinForms launcher (RynthCore.App project, MainForm, Program) - Shared source files remain in src/RynthCore.App for Avalonia and Engine - Add BUILD.md with full publish/deploy instructions for all components Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
ccb08ecb4a
commit
36e8208caa
14 changed files with 584 additions and 2233 deletions
100
src/RynthCore.Engine/Plugins/EngineSettings.cs
Normal file
100
src/RynthCore.Engine/Plugins/EngineSettings.cs
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace RynthCore.Engine.Plugins;
|
||||
|
||||
internal static class EngineSettings
|
||||
{
|
||||
private static readonly string SettingsPath = Path.Combine(
|
||||
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
|
||||
"RynthCore",
|
||||
"engine.json");
|
||||
|
||||
private static List<string> _pluginPaths = new();
|
||||
private static bool _loaded;
|
||||
|
||||
public static IReadOnlyList<string> PluginPaths
|
||||
{
|
||||
get
|
||||
{
|
||||
EnsureLoaded();
|
||||
return _pluginPaths;
|
||||
}
|
||||
}
|
||||
|
||||
public static void AddPluginPath(string path)
|
||||
{
|
||||
EnsureLoaded();
|
||||
string full = Path.GetFullPath(path);
|
||||
for (int i = 0; i < _pluginPaths.Count; i++)
|
||||
{
|
||||
if (string.Equals(_pluginPaths[i], full, StringComparison.OrdinalIgnoreCase))
|
||||
return;
|
||||
}
|
||||
_pluginPaths.Add(full);
|
||||
Save();
|
||||
}
|
||||
|
||||
public static void RemovePluginPath(int index)
|
||||
{
|
||||
EnsureLoaded();
|
||||
if (index >= 0 && index < _pluginPaths.Count)
|
||||
{
|
||||
_pluginPaths.RemoveAt(index);
|
||||
Save();
|
||||
}
|
||||
}
|
||||
|
||||
private static void EnsureLoaded()
|
||||
{
|
||||
if (_loaded) return;
|
||||
_loaded = true;
|
||||
|
||||
try
|
||||
{
|
||||
if (!File.Exists(SettingsPath)) return;
|
||||
using var doc = JsonDocument.Parse(File.ReadAllBytes(SettingsPath));
|
||||
if (doc.RootElement.TryGetProperty("PluginPaths", out var arr) &&
|
||||
arr.ValueKind == JsonValueKind.Array)
|
||||
{
|
||||
foreach (var el in arr.EnumerateArray())
|
||||
{
|
||||
string? val = el.GetString();
|
||||
if (!string.IsNullOrWhiteSpace(val))
|
||||
_pluginPaths.Add(val);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
RynthLog.Plugin($"EngineSettings: Failed to load {SettingsPath}: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
private static void Save()
|
||||
{
|
||||
try
|
||||
{
|
||||
string? dir = Path.GetDirectoryName(SettingsPath);
|
||||
if (dir != null) Directory.CreateDirectory(dir);
|
||||
|
||||
using var ms = new MemoryStream();
|
||||
using (var w = new Utf8JsonWriter(ms, new JsonWriterOptions { Indented = true }))
|
||||
{
|
||||
w.WriteStartObject();
|
||||
w.WriteStartArray("PluginPaths");
|
||||
foreach (string p in _pluginPaths)
|
||||
w.WriteStringValue(p);
|
||||
w.WriteEndArray();
|
||||
w.WriteEndObject();
|
||||
}
|
||||
File.WriteAllBytes(SettingsPath, ms.ToArray());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
RynthLog.Plugin($"EngineSettings: Failed to save: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -106,6 +106,12 @@ internal static class PluginLoader
|
|||
}
|
||||
}
|
||||
|
||||
public static LoadedPlugin? LoadSingle(string sourcePath, string shadowRootDir, int generation)
|
||||
{
|
||||
string sessionShadowDir = PrepareShadowDirectory(shadowRootDir, generation);
|
||||
return TryLoad(sourcePath, sessionShadowDir);
|
||||
}
|
||||
|
||||
private static LoadedPlugin? TryLoad(string sourcePath, string sessionShadowDir)
|
||||
{
|
||||
string fileName = Path.GetFileName(sourcePath);
|
||||
|
|
|
|||
|
|
@ -196,6 +196,7 @@ internal static class PluginManager
|
|||
public static IReadOnlyList<LoadedPlugin> Plugins => _plugins;
|
||||
public static bool IsRescanQueued => _rescanRequested;
|
||||
public static string PluginDirectory => _pluginsDir;
|
||||
public static IReadOnlyList<string> ExtraPluginPaths => EngineSettings.PluginPaths;
|
||||
public static bool HasObservedUIInitialized => _uiInitializedObserved;
|
||||
public static bool HasObservedLoginComplete => _loginCompleteObserved;
|
||||
|
||||
|
|
@ -1493,8 +1494,26 @@ internal static class PluginManager
|
|||
private static void LoadPluginsFromDisk()
|
||||
{
|
||||
_loadGeneration++;
|
||||
|
||||
// Default directory
|
||||
var loaded = PluginLoader.LoadAll(_pluginsDir, _shadowRootDir, _loadGeneration);
|
||||
_plugins.AddRange(loaded);
|
||||
|
||||
// Extra DLL paths from engine settings
|
||||
var extraPaths = EngineSettings.PluginPaths;
|
||||
for (int i = 0; i < extraPaths.Count; i++)
|
||||
{
|
||||
string dllPath = extraPaths[i];
|
||||
if (!File.Exists(dllPath))
|
||||
{
|
||||
RynthLog.Plugin($"PluginManager: Extra plugin not found: {dllPath}");
|
||||
continue;
|
||||
}
|
||||
RynthLog.Plugin($"PluginManager: Loading extra plugin: {dllPath}");
|
||||
var plugin = PluginLoader.LoadSingle(dllPath, _shadowRootDir, _loadGeneration);
|
||||
if (plugin != null)
|
||||
_plugins.Add(plugin);
|
||||
}
|
||||
}
|
||||
|
||||
private static void InitializeLoadedPlugins()
|
||||
|
|
|
|||
Loading…
Reference in a new issue