Moved plugins folder to appdata.

Added config to disable plugins
This commit is contained in:
Alessandro Proto 2023-07-27 20:17:42 +02:00
parent f7d4b728f5
commit 3326d0e73d
3 changed files with 6 additions and 10 deletions

View file

@ -1,5 +1,6 @@
{ {
"EngineMode": 0, "EngineMode": 0,
"SafeMode": false,
"Window": { "Window": {
"Scale": 2 "Scale": 2
}, },

View file

@ -112,7 +112,6 @@ public class Capy64 : Game
private readonly InputManager _inputManager; private readonly InputManager _inputManager;
private RenderTarget2D renderTarget; private RenderTarget2D renderTarget;
private readonly GraphicsDeviceManager _graphics; private readonly GraphicsDeviceManager _graphics;
private IServiceProvider _serviceProvider;
private ulong _totalTicks = 0; private ulong _totalTicks = 0;
private int tickrate = 0; private int tickrate = 0;
private int everyTick => 60 / tickrate; private int everyTick => 60 / tickrate;
@ -122,7 +121,7 @@ public class Capy64 : Game
Instance = this; Instance = this;
_graphics = new GraphicsDeviceManager(this); _graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content"; //Content.RootDirectory = "Content";
IsMouseVisible = true; IsMouseVisible = true;
EventEmitter = new(); EventEmitter = new();
@ -131,11 +130,6 @@ public class Capy64 : Game
Drawing = new(); Drawing = new();
} }
public void ConfigureServices(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
}
public void SetEngineMode(EngineMode mode) public void SetEngineMode(EngineMode mode)
{ {
switch (mode) switch (mode)
@ -265,7 +259,9 @@ public class Capy64 : Game
Audio = new Audio(); Audio = new Audio();
NativePlugins = GetNativePlugins(); NativePlugins = GetNativePlugins();
Plugins = PluginLoader.LoadAllPlugins("plugins", _serviceProvider); var safeMode = Configuration.GetValue("SafeMode", false);
if (!safeMode)
Plugins = PluginLoader.LoadAllPlugins(Path.Combine(AssetsPath, "plugins"));
EventEmitter.RaiseInit(); EventEmitter.RaiseInit();
@ -284,7 +280,6 @@ public class Capy64 : Game
foreach (var type in types) foreach (var type in types)
{ {
var instance = (IComponent)Activator.CreateInstance(type, this); var instance = (IComponent)Activator.CreateInstance(type, this);
//var instance = (IComponent)ActivatorUtilities.CreateInstance(_serviceProvider, type)!;
plugins.Add(instance); plugins.Add(instance);
} }

View file

@ -32,7 +32,7 @@ internal class PluginLoader
return loadContext.LoadFromAssemblyName(new AssemblyName(Path.GetFileNameWithoutExtension(path))); return loadContext.LoadFromAssemblyName(new AssemblyName(Path.GetFileNameWithoutExtension(path)));
} }
public static List<IComponent> LoadAllPlugins(string pluginsPath, IServiceProvider provider) public static List<IComponent> LoadAllPlugins(string pluginsPath)
{ {
if (!Directory.Exists(pluginsPath)) if (!Directory.Exists(pluginsPath))
Directory.CreateDirectory(pluginsPath); Directory.CreateDirectory(pluginsPath);