Skip to content

Commit

Permalink
Create dedicated IPlugin interface for external plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotrekol committed Jun 26, 2018
1 parent 6a1f7f0 commit a11e5b9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
10 changes: 10 additions & 0 deletions StreamCompanionTypes/Interfaces/IPlugin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace StreamCompanionTypes.Interfaces
{
public interface IPlugin : IModule
{
string Description { get; }
string Author { get; }
string Url { get; }
string UpdateUrl { get; }
}
}
1 change: 1 addition & 0 deletions StreamCompanionTypes/StreamCompanionTypes.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
<Compile Include="Interfaces\IModParserGetter.cs" />
<Compile Include="Interfaces\IModule.cs" />
<Compile Include="Interfaces\IMsnGetter.cs" />
<Compile Include="Interfaces\IPlugin.cs" />
<Compile Include="Interfaces\ISaver.cs" />
<Compile Include="Interfaces\ISaveRequester.cs" />
<Compile Include="Interfaces\ISettings.cs" />
Expand Down
9 changes: 5 additions & 4 deletions osu!StreamCompanion/Code/Core/Initializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
using osu_StreamCompanion.Code.Modules.SCGUI;
using osu_StreamCompanion.Code.Modules.Updater;
using osu_StreamCompanion.Code.Windows;
using StreamCompanionTypes;
using StreamCompanionTypes.DataTypes;
using StreamCompanionTypes.Interfaces;

Expand Down Expand Up @@ -153,21 +154,21 @@ public void Start()
}

public string PluginsLocation => Path.Combine(ConfigSaveLocation, "Plugins");
private List<IModule> GetPlugins()
private List<IPlugin> GetPlugins()
{
var files = Directory.GetFiles(PluginsLocation, "*.dll");
List<Assembly> assemblies = new List<Assembly>();
List<IModule> plugins = new List<IModule>();
List<IPlugin> plugins = new List<IPlugin>();

foreach (var file in files)
{
var asm = Assembly.LoadFile(Path.Combine(PluginsLocation, file));
foreach (var type in asm.GetTypes())
{
if (type.GetInterfaces().Contains(typeof(IModule)))
if (type.GetInterfaces().Contains(typeof(IPlugin)))
{
assemblies.Add(asm);
var p = Activator.CreateInstance(type) as IModule;
var p = Activator.CreateInstance(type) as IPlugin;
plugins.Add(p);
}
}
Expand Down

0 comments on commit a11e5b9

Please sign in to comment.