2025-03-22 21:12:14 +01:00
|
|
|
using AIStudio.Settings;
|
|
|
|
|
|
|
|
|
|
namespace AIStudio.Tools.PluginSystem;
|
|
|
|
|
|
2025-03-29 18:40:17 +01:00
|
|
|
public static partial class PluginFactory
|
2025-03-22 21:12:14 +01:00
|
|
|
{
|
2025-04-12 21:13:33 +02:00
|
|
|
private static readonly ILogger LOG = Program.LOGGER_FACTORY.CreateLogger(nameof(PluginFactory));
|
|
|
|
|
private static readonly SettingsManager SETTINGS_MANAGER = Program.SERVICE_PROVIDER.GetRequiredService<SettingsManager>();
|
2025-04-23 14:07:22 +02:00
|
|
|
|
2025-04-12 21:13:33 +02:00
|
|
|
private static bool IS_INITIALIZED;
|
|
|
|
|
private static string DATA_DIR = string.Empty;
|
|
|
|
|
private static string PLUGINS_ROOT = string.Empty;
|
|
|
|
|
private static string INTERNAL_PLUGINS_ROOT = string.Empty;
|
|
|
|
|
private static FileSystemWatcher HOT_RELOAD_WATCHER = null!;
|
|
|
|
|
private static ILanguagePlugin BASE_LANGUAGE_PLUGIN = NoPluginLanguage.INSTANCE;
|
|
|
|
|
|
|
|
|
|
public static ILanguagePlugin BaseLanguage => BASE_LANGUAGE_PLUGIN;
|
2025-04-07 19:36:24 +02:00
|
|
|
|
2025-04-12 21:13:33 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// Set up the plugin factory. We will read the data directory from the settings manager.
|
|
|
|
|
/// Afterward, we will create the plugins directory and the internal plugin directory.
|
|
|
|
|
/// </summary>
|
2025-04-24 09:50:03 +02:00
|
|
|
public static bool Setup()
|
2025-04-07 19:36:24 +02:00
|
|
|
{
|
2025-04-23 14:07:22 +02:00
|
|
|
if(IS_INITIALIZED)
|
2025-04-24 09:50:03 +02:00
|
|
|
return false;
|
2025-04-23 14:07:22 +02:00
|
|
|
|
2025-04-12 21:13:33 +02:00
|
|
|
DATA_DIR = SettingsManager.DataDirectory!;
|
|
|
|
|
PLUGINS_ROOT = Path.Join(DATA_DIR, "plugins");
|
|
|
|
|
INTERNAL_PLUGINS_ROOT = Path.Join(PLUGINS_ROOT, ".internal");
|
|
|
|
|
|
2025-04-07 19:36:24 +02:00
|
|
|
if (!Directory.Exists(PLUGINS_ROOT))
|
|
|
|
|
Directory.CreateDirectory(PLUGINS_ROOT);
|
|
|
|
|
|
|
|
|
|
HOT_RELOAD_WATCHER = new(PLUGINS_ROOT);
|
2025-04-12 21:13:33 +02:00
|
|
|
IS_INITIALIZED = true;
|
2025-04-24 09:50:03 +02:00
|
|
|
|
|
|
|
|
return true;
|
2025-04-07 19:36:24 +02:00
|
|
|
}
|
2025-03-29 18:40:17 +01:00
|
|
|
|
2025-03-30 20:34:30 +02:00
|
|
|
public static void Dispose()
|
|
|
|
|
{
|
2025-04-12 21:13:33 +02:00
|
|
|
if(!IS_INITIALIZED)
|
|
|
|
|
return;
|
|
|
|
|
|
2025-03-30 20:34:30 +02:00
|
|
|
HOT_RELOAD_WATCHER.Dispose();
|
|
|
|
|
}
|
2025-03-22 21:12:14 +01:00
|
|
|
}
|