Skip to content

Commit f15139e

Browse files
committed
Add -testplugin commandline switch
1 parent 983aff2 commit f15139e

3 files changed

Lines changed: 41 additions & 6 deletions

File tree

‎Torch.API/ITorchConfig.cs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public interface ITorchConfig
2222
string WaitForPID { get; set; }
2323
string ChatName { get; set; }
2424
string ChatColor { get; set; }
25+
string TestPlugin { get; set; }
2526

2627
bool Save(string path = null);
2728
}

‎Torch.Server/TorchConfig.cs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ public string InstancePath
117117
[Arg("console", "Keeps a separate console window open after the main UI loads.")]
118118
public bool IndependentConsole { get; set; } = false;
119119

120+
[XmlIgnore]
121+
[Arg("testplugin", "Path to a plugin to debug. For development use only.")]
122+
public string TestPlugin { get; set; }
123+
120124
[XmlIgnore]
121125
private string _path;
122126

‎Torch/Plugins/PluginManager.cs‎

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,25 @@ public void LoadPlugins()
121121
{
122122
_log.Info("Loading plugins...");
123123

124+
if (!string.IsNullOrEmpty(Torch.Config.TestPlugin))
125+
{
126+
_log.Info($"Loading plugin for debug at {Torch.Config.TestPlugin}");
127+
128+
foreach (var item in GetLocalPlugins(Torch.Config.TestPlugin, true))
129+
{
130+
_log.Info(item.Path);
131+
LoadPlugin(item);
132+
}
133+
134+
foreach (var plugin in _plugins.Values)
135+
{
136+
plugin.Init(Torch);
137+
}
138+
_log.Info($"Loaded {_plugins.Count} plugins.");
139+
PluginsLoaded?.Invoke(_plugins.Values.AsReadOnly());
140+
return;
141+
}
142+
124143
var pluginItems = GetLocalPlugins(PluginDir);
125144
var pluginsToLoad = new List<PluginItem>();
126145
foreach (var item in pluginItems)
@@ -187,24 +206,35 @@ public void LoadPlugins()
187206
PluginsLoaded?.Invoke(_plugins.Values.AsReadOnly());
188207
}
189208

190-
private List<PluginItem> GetLocalPlugins(string pluginDir)
209+
private List<PluginItem> GetLocalPlugins(string pluginDir, bool debug = false)
191210
{
192211
var firstLoad = Torch.Config.Plugins.Count == 0;
193212

194213
var pluginItems = Directory.EnumerateFiles(pluginDir, "*.zip")
195-
.Union(Directory.EnumerateDirectories(PluginDir));
214+
.Union(Directory.EnumerateDirectories(pluginDir));
215+
if (debug)
216+
pluginItems = pluginItems.Union(new List<string> {pluginDir});
196217
var results = new List<PluginItem>();
197218

198219
foreach (var item in pluginItems)
199220
{
200-
var path = Path.Combine(PluginDir, item);
221+
var path = Path.Combine(pluginDir, item);
201222
var isZip = item.EndsWith(".zip", StringComparison.CurrentCultureIgnoreCase);
202223
var manifest = isZip ? GetManifestFromZip(path) : GetManifestFromDirectory(path);
203224

204225
if (manifest == null)
205226
{
206-
_log.Warn($"Item '{item}' is missing a manifest, skipping.");
207-
continue;
227+
if (!debug)
228+
{
229+
_log.Warn($"Item '{item}' is missing a manifest, skipping.");
230+
continue;
231+
}
232+
manifest = new PluginManifest()
233+
{
234+
Guid = new Guid(),
235+
Version = "0",
236+
Name = "TEST"
237+
};
208238
}
209239

210240
var duplicatePlugin = results.FirstOrDefault(r => r.Manifest.Guid == manifest.Guid);
@@ -215,7 +245,7 @@ private List<PluginItem> GetLocalPlugins(string pluginDir)
215245
continue;
216246
}
217247

218-
if (!Torch.Config.LocalPlugins)
248+
if (!Torch.Config.LocalPlugins && !debug)
219249
{
220250
if (isZip && !Torch.Config.Plugins.Contains(manifest.Guid))
221251
{

0 commit comments

Comments
 (0)