Add -testplugin commandline switch
This commit is contained in:
@@ -22,6 +22,7 @@ namespace Torch
|
|||||||
string WaitForPID { get; set; }
|
string WaitForPID { get; set; }
|
||||||
string ChatName { get; set; }
|
string ChatName { get; set; }
|
||||||
string ChatColor { get; set; }
|
string ChatColor { get; set; }
|
||||||
|
string TestPlugin { get; set; }
|
||||||
|
|
||||||
bool Save(string path = null);
|
bool Save(string path = null);
|
||||||
}
|
}
|
||||||
|
@@ -117,6 +117,10 @@ namespace Torch.Server
|
|||||||
[Arg("console", "Keeps a separate console window open after the main UI loads.")]
|
[Arg("console", "Keeps a separate console window open after the main UI loads.")]
|
||||||
public bool IndependentConsole { get; set; } = false;
|
public bool IndependentConsole { get; set; } = false;
|
||||||
|
|
||||||
|
[XmlIgnore]
|
||||||
|
[Arg("testplugin", "Path to a plugin to debug. For development use only.")]
|
||||||
|
public string TestPlugin { get; set; }
|
||||||
|
|
||||||
[XmlIgnore]
|
[XmlIgnore]
|
||||||
private string _path;
|
private string _path;
|
||||||
|
|
||||||
|
@@ -121,6 +121,25 @@ namespace Torch.Managers
|
|||||||
{
|
{
|
||||||
_log.Info("Loading plugins...");
|
_log.Info("Loading plugins...");
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(Torch.Config.TestPlugin))
|
||||||
|
{
|
||||||
|
_log.Info($"Loading plugin for debug at {Torch.Config.TestPlugin}");
|
||||||
|
|
||||||
|
foreach (var item in GetLocalPlugins(Torch.Config.TestPlugin, true))
|
||||||
|
{
|
||||||
|
_log.Info(item.Path);
|
||||||
|
LoadPlugin(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var plugin in _plugins.Values)
|
||||||
|
{
|
||||||
|
plugin.Init(Torch);
|
||||||
|
}
|
||||||
|
_log.Info($"Loaded {_plugins.Count} plugins.");
|
||||||
|
PluginsLoaded?.Invoke(_plugins.Values.AsReadOnly());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var pluginItems = GetLocalPlugins(PluginDir);
|
var pluginItems = GetLocalPlugins(PluginDir);
|
||||||
var pluginsToLoad = new List<PluginItem>();
|
var pluginsToLoad = new List<PluginItem>();
|
||||||
foreach (var item in pluginItems)
|
foreach (var item in pluginItems)
|
||||||
@@ -187,24 +206,35 @@ namespace Torch.Managers
|
|||||||
PluginsLoaded?.Invoke(_plugins.Values.AsReadOnly());
|
PluginsLoaded?.Invoke(_plugins.Values.AsReadOnly());
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<PluginItem> GetLocalPlugins(string pluginDir)
|
private List<PluginItem> GetLocalPlugins(string pluginDir, bool debug = false)
|
||||||
{
|
{
|
||||||
var firstLoad = Torch.Config.Plugins.Count == 0;
|
var firstLoad = Torch.Config.Plugins.Count == 0;
|
||||||
|
|
||||||
var pluginItems = Directory.EnumerateFiles(pluginDir, "*.zip")
|
var pluginItems = Directory.EnumerateFiles(pluginDir, "*.zip")
|
||||||
.Union(Directory.EnumerateDirectories(PluginDir));
|
.Union(Directory.EnumerateDirectories(pluginDir));
|
||||||
|
if (debug)
|
||||||
|
pluginItems = pluginItems.Union(new List<string> {pluginDir});
|
||||||
var results = new List<PluginItem>();
|
var results = new List<PluginItem>();
|
||||||
|
|
||||||
foreach (var item in pluginItems)
|
foreach (var item in pluginItems)
|
||||||
{
|
{
|
||||||
var path = Path.Combine(PluginDir, item);
|
var path = Path.Combine(pluginDir, item);
|
||||||
var isZip = item.EndsWith(".zip", StringComparison.CurrentCultureIgnoreCase);
|
var isZip = item.EndsWith(".zip", StringComparison.CurrentCultureIgnoreCase);
|
||||||
var manifest = isZip ? GetManifestFromZip(path) : GetManifestFromDirectory(path);
|
var manifest = isZip ? GetManifestFromZip(path) : GetManifestFromDirectory(path);
|
||||||
|
|
||||||
if (manifest == null)
|
if (manifest == null)
|
||||||
{
|
{
|
||||||
_log.Warn($"Item '{item}' is missing a manifest, skipping.");
|
if (!debug)
|
||||||
continue;
|
{
|
||||||
|
_log.Warn($"Item '{item}' is missing a manifest, skipping.");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
manifest = new PluginManifest()
|
||||||
|
{
|
||||||
|
Guid = new Guid(),
|
||||||
|
Version = "0",
|
||||||
|
Name = "TEST"
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
var duplicatePlugin = results.FirstOrDefault(r => r.Manifest.Guid == manifest.Guid);
|
var duplicatePlugin = results.FirstOrDefault(r => r.Manifest.Guid == manifest.Guid);
|
||||||
@@ -215,7 +245,7 @@ namespace Torch.Managers
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Torch.Config.LocalPlugins)
|
if (!Torch.Config.LocalPlugins && !debug)
|
||||||
{
|
{
|
||||||
if (isZip && !Torch.Config.Plugins.Contains(manifest.Guid))
|
if (isZip && !Torch.Config.Plugins.Contains(manifest.Guid))
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user