2025-03-22 20:12:14 +00:00
|
|
|
using AIStudio.Settings;
|
|
|
|
|
|
|
|
namespace AIStudio.Tools.PluginSystem;
|
|
|
|
|
2025-03-29 17:40:17 +00:00
|
|
|
public static partial class PluginFactory
|
2025-03-22 20:12:14 +00:00
|
|
|
{
|
2025-04-12 19:13:33 +00: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 12:07:22 +00:00
|
|
|
|
2025-04-12 19:13:33 +00: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 17:36:24 +00:00
|
|
|
|
2025-04-12 19:13:33 +00: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 07:50:03 +00:00
|
|
|
public static bool Setup()
|
2025-04-07 17:36:24 +00:00
|
|
|
{
|
2025-04-23 12:07:22 +00:00
|
|
|
if(IS_INITIALIZED)
|
2025-04-24 07:50:03 +00:00
|
|
|
return false;
|
2025-04-23 12:07:22 +00:00
|
|
|
|
2025-04-12 19:13:33 +00:00
|
|
|
DATA_DIR = SettingsManager.DataDirectory!;
|
|
|
|
PLUGINS_ROOT = Path.Join(DATA_DIR, "plugins");
|
|
|
|
INTERNAL_PLUGINS_ROOT = Path.Join(PLUGINS_ROOT, ".internal");
|
|
|
|
|
2025-04-07 17:36:24 +00:00
|
|
|
if (!Directory.Exists(PLUGINS_ROOT))
|
|
|
|
Directory.CreateDirectory(PLUGINS_ROOT);
|
|
|
|
|
|
|
|
HOT_RELOAD_WATCHER = new(PLUGINS_ROOT);
|
2025-04-12 19:13:33 +00:00
|
|
|
IS_INITIALIZED = true;
|
2025-04-24 07:50:03 +00:00
|
|
|
|
|
|
|
return true;
|
2025-04-07 17:36:24 +00:00
|
|
|
}
|
2025-03-29 17:40:17 +00:00
|
|
|
|
2025-03-30 18:34:30 +00:00
|
|
|
public static void Dispose()
|
|
|
|
{
|
2025-04-12 19:13:33 +00:00
|
|
|
if(!IS_INITIALIZED)
|
|
|
|
return;
|
|
|
|
|
2025-03-30 18:34:30 +00:00
|
|
|
HOT_RELOAD_WATCHER.Dispose();
|
|
|
|
}
|
2025-03-22 20:12:14 +00:00
|
|
|
}
|