mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 11:56:30 +00:00
Removed seperate plugins project since you're always referencing both..
Added more loading logic
This commit is contained in:
1 parent
3db4aab8bc
commit
c22a78cd30
57 files changed
+959
-650
No files matched your search
@@ -1,11 +0,0 @@
|
||||
using Artemis.Plugins.Interfaces;
|
||||
using Artemis.Plugins.Models;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.Plugins.Abstract
|
||||
{
|
||||
public abstract class ModuleViewModel : Screen, IModuleViewModel
|
||||
{
|
||||
public PluginInfo PluginInfo { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
using System;
|
||||
using Artemis.Plugins.Interfaces;
|
||||
|
||||
namespace Artemis.Plugins.Abstract
|
||||
{
|
||||
public abstract class ProfileModule : IModule
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public abstract Type ViewModelType { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public abstract bool ExpandsMainDataModel { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public void LoadPlugin()
|
||||
{
|
||||
// Load and activate the last active profile
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void UnloadPlugin()
|
||||
{
|
||||
// Unload the last active profile
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual void Update(double deltaTime)
|
||||
{
|
||||
// Update the profile
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual void Render(double deltaTime)
|
||||
{
|
||||
// Render the profile
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,10 +9,11 @@
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Artemis.Plugins</RootNamespace>
|
||||
<AssemblyName>Artemis.Plugins</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
|
||||
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<NuGetPackageImportStamp>
|
||||
</NuGetPackageImportStamp>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
@@ -56,6 +57,9 @@
|
||||
<Reference Include="Ninject, Version=3.3.4.0, Culture=neutral, PublicKeyToken=c7192dc5380945e7, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Ninject.3.3.4\lib\net45\Ninject.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="RGB.NET.Core, Version=0.0.1.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\RGB.NET.Core.0.0.1.38\lib\net45\RGB.NET.Core.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Stylet, Version=1.1.21.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Stylet.1.1.21\lib\net45\Stylet.dll</HintPath>
|
||||
</Reference>
|
||||
@@ -113,8 +117,8 @@
|
||||
<Reference Include="System.Threading.Thread, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Threading.Thread.4.3.0\lib\net46\System.Threading.Thread.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.ValueTuple, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.ValueTuple.4.3.0\lib\netstandard1.0\System.ValueTuple.dll</HintPath>
|
||||
<Reference Include="System.ValueTuple, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.ValueTuple.4.4.0\lib\net461\System.ValueTuple.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
@@ -136,17 +140,6 @@
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Abstract\ModuleViewModel.cs" />
|
||||
<Compile Include="Abstract\ProfileModule.cs" />
|
||||
<Compile Include="Exceptions\ArtemisPluginException.cs" />
|
||||
<Compile Include="Interfaces\IDataModelExpansion.cs" />
|
||||
<Compile Include="Interfaces\IDevice.cs" />
|
||||
<Compile Include="Interfaces\ILayerType.cs" />
|
||||
<Compile Include="Interfaces\IModule.cs" />
|
||||
<Compile Include="Interfaces\IModuleDataModel.cs" />
|
||||
<Compile Include="Interfaces\IPlugin.cs" />
|
||||
<Compile Include="Interfaces\IModuleViewModel.cs" />
|
||||
<Compile Include="Models\PluginInfo.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
@@ -157,5 +150,11 @@
|
||||
<Analyzer Include="..\packages\Microsoft.CodeAnalysis.Analyzers.1.1.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.Analyzers.dll" />
|
||||
<Analyzer Include="..\packages\Microsoft.CodeAnalysis.Analyzers.1.1.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Abstract\" />
|
||||
<Folder Include="Exceptions\" />
|
||||
<Folder Include="Interfaces\" />
|
||||
<Folder Include="Models\" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
@@ -1,25 +0,0 @@
|
||||
using System;
|
||||
using Artemis.Plugins.Models;
|
||||
|
||||
namespace Artemis.Plugins.Exceptions
|
||||
{
|
||||
public class ArtemisPluginException : Exception
|
||||
{
|
||||
public ArtemisPluginException(PluginInfo pluginInfo)
|
||||
{
|
||||
PluginInfo = pluginInfo;
|
||||
}
|
||||
|
||||
public ArtemisPluginException(PluginInfo pluginInfo, string message) : base(message)
|
||||
{
|
||||
PluginInfo = pluginInfo;
|
||||
}
|
||||
|
||||
public ArtemisPluginException(PluginInfo pluginInfo, string message, Exception inner) : base(message, inner)
|
||||
{
|
||||
PluginInfo = pluginInfo;
|
||||
}
|
||||
|
||||
public PluginInfo PluginInfo { get; }
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
namespace Artemis.Plugins.Interfaces
|
||||
{
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Allows you to expand the application-wide datamodel
|
||||
/// </summary>
|
||||
public interface IDataModelExpansion : IPlugin
|
||||
{
|
||||
void Update(double deltaTime);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
namespace Artemis.Plugins.Interfaces
|
||||
{
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Allows you to implement your own RGB device
|
||||
/// </summary>
|
||||
public interface IDevice : IPlugin
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
namespace Artemis.Plugins.Interfaces
|
||||
{
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Allows you to create your own layer type
|
||||
/// </summary>
|
||||
public interface ILayerType : IPlugin
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace Artemis.Plugins.Interfaces
|
||||
{
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Allows you to add support for new games/applications
|
||||
/// </summary>
|
||||
public interface IModule : IPlugin
|
||||
{
|
||||
/// <summary>
|
||||
/// The type of this module's view model
|
||||
/// </summary>
|
||||
Type ViewModelType { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Wether or not this module expands upon the main data model. If set to true any data in main data model can be
|
||||
/// accessed by profiles in this module
|
||||
/// </summary>
|
||||
bool ExpandsMainDataModel { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Called each frame when the module must update
|
||||
/// </summary>
|
||||
/// <param name="deltaTime">Time since the last update</param>
|
||||
void Update(double deltaTime);
|
||||
|
||||
/// <summary>
|
||||
/// Called each frame when the module must render
|
||||
/// </summary>
|
||||
/// <param name="deltaTime">Time since the last render</param>
|
||||
void Render(double deltaTime);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
namespace Artemis.Plugins.Interfaces
|
||||
{
|
||||
public interface IModuleDataModel
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
using Artemis.Plugins.Models;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.Plugins.Interfaces
|
||||
{
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Allows you to create a view model for a module
|
||||
/// </summary>
|
||||
public interface IModuleViewModel : IScreen
|
||||
{
|
||||
PluginInfo PluginInfo { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
namespace Artemis.Plugins.Interfaces
|
||||
{
|
||||
/// <summary>
|
||||
/// This is the base plugin type, use the other interfaces such as IModule to create plugins
|
||||
/// </summary>
|
||||
public interface IPlugin
|
||||
{
|
||||
/// <summary>
|
||||
/// Called when the plugin is loaded
|
||||
/// </summary>
|
||||
void LoadPlugin();
|
||||
|
||||
/// <summary>
|
||||
/// Called when the plugin is unloaded
|
||||
/// </summary>
|
||||
void UnloadPlugin();
|
||||
}
|
||||
}
|
||||
@@ -1,121 +0,0 @@
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.Plugins.Exceptions;
|
||||
using Artemis.Plugins.Interfaces;
|
||||
using CSScriptLibrary;
|
||||
using Newtonsoft.Json;
|
||||
using Ninject;
|
||||
|
||||
namespace Artemis.Plugins.Models
|
||||
{
|
||||
public class PluginInfo
|
||||
{
|
||||
private static Assembly _assembly;
|
||||
|
||||
/// <summary>
|
||||
/// The name of the plugin
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The version of the plugin
|
||||
/// </summary>
|
||||
public string Version { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The file implementing IPlugin, loaded on startup
|
||||
/// </summary>
|
||||
public string Main { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The instantiated plugin, available after successful load
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public IPlugin Plugin { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Full path to the plugin's current folder
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public string Folder { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Unloads the plugin and clears the plugin info's internal data
|
||||
/// </summary>
|
||||
public void UnloadPlugin()
|
||||
{
|
||||
Plugin.UnloadPlugin();
|
||||
_assembly = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Load a plugin from a folder
|
||||
/// </summary>
|
||||
/// <param name="kernel">The Ninject kernel to use for DI</param>
|
||||
/// <param name="folder">The folder in which plugin.json is located</param>
|
||||
/// <returns></returns>
|
||||
public static async Task<PluginInfo> FromFolder(IKernel kernel, string folder)
|
||||
{
|
||||
// Make sure the right engine is used
|
||||
CSScript.EvaluatorConfig.Engine = EvaluatorEngine.CodeDom;
|
||||
CSScript.EvaluatorConfig.DebugBuild = true;
|
||||
CSScript.GlobalSettings.SearchDirs = folder;
|
||||
if (!folder.EndsWith("\\"))
|
||||
folder += "\\";
|
||||
if (!File.Exists(folder + "plugin.json"))
|
||||
throw new ArtemisPluginException(null, "Failed to load plugin, no plugin.json found in " + folder);
|
||||
|
||||
var pluginInfo = JsonConvert.DeserializeObject<PluginInfo>(File.ReadAllText(folder + "plugin.json"));
|
||||
pluginInfo.Folder = folder;
|
||||
|
||||
await pluginInfo.CompilePlugin(kernel);
|
||||
return pluginInfo;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compiles the plugin's main CS file and any of it's includes and instantiates it.
|
||||
/// </summary>
|
||||
/// <param name="kernel">The Ninject kernel to use for DI</param>
|
||||
public async Task CompilePlugin(IKernel kernel)
|
||||
{
|
||||
// Load the main script and get the type
|
||||
_assembly = await CSScript.Evaluator.CompileCodeAsync(File.ReadAllText(Folder + Main));
|
||||
|
||||
var pluginType = _assembly.GetTypes().Where(t => typeof(IPlugin).IsAssignableFrom(t)).ToList();
|
||||
if (!pluginType.Any())
|
||||
throw new ArtemisPluginException(this, "Failed to load plugin, no type found that implements IPlugin");
|
||||
if (pluginType.Count > 1)
|
||||
throw new ArtemisPluginException(this, "Failed to load plugin, more than one type found that implements IPlugin");
|
||||
|
||||
// Instantiate the plugin with Ninject
|
||||
Plugin = (IPlugin) kernel.Get(pluginType.First());
|
||||
Plugin.LoadPlugin();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the view model of the module accompanying the provided plugin info
|
||||
/// </summary>
|
||||
/// <param name="kernel">The Ninject kernel to use for DI</param>
|
||||
/// <returns></returns>
|
||||
public IModuleViewModel GetModuleViewModel(IKernel kernel)
|
||||
{
|
||||
// Don't attempt to locave VMs for something other than a module
|
||||
if (Plugin == null)
|
||||
throw new ArtemisPluginException(this, "Cannot locate a view model for this plugin because it's not compiled.");
|
||||
if (!(Plugin is IModule module))
|
||||
throw new ArtemisPluginException(this, "Cannot locate a view model for this plugin as it's not a module.");
|
||||
|
||||
// Get the type from the module
|
||||
var vmType = module.ViewModelType;
|
||||
if (!typeof(IModuleViewModel).IsAssignableFrom(vmType))
|
||||
throw new ArtemisPluginException(this, "ViewModel must implement IModuleViewModel.");
|
||||
|
||||
// Instantiate the ViewModel with Ninject
|
||||
var vm = (IModuleViewModel) kernel.Get(vmType);
|
||||
vm.PluginInfo = this;
|
||||
return vm;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<configuration>
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
@@ -20,8 +19,7 @@
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Security.Cryptography.Primitives" publicKeyToken="b03f5f7f11d50a3a"
|
||||
culture="neutral" />
|
||||
<assemblyIdentity name="System.Security.Cryptography.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
@@ -45,14 +43,17 @@
|
||||
<bindingRedirect oldVersion="0.0.0.0-2.6.0.0" newVersion="2.6.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Microsoft.CodeAnalysis.CSharp.Scripting" publicKeyToken="31bf3856ad364e35"
|
||||
culture="neutral" />
|
||||
<assemblyIdentity name="Microsoft.CodeAnalysis.CSharp.Scripting" publicKeyToken="31bf3856ad364e35" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-2.6.0.0" newVersion="2.6.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Console" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
</configuration>
|
||||
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" /></startup></configuration>
|
||||
@@ -1,5 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<packages>
|
||||
<package id="CS-Script.bin" version="3.28.0.1" targetFramework="net46" />
|
||||
<package id="Microsoft.CodeAnalysis.Analyzers" version="1.1.0" targetFramework="net46" />
|
||||
@@ -10,6 +9,7 @@
|
||||
<package id="Microsoft.CodeAnalysis.Scripting.Common" version="2.6.1" targetFramework="net46" />
|
||||
<package id="Newtonsoft.Json" version="11.0.1" targetFramework="net46" />
|
||||
<package id="Ninject" version="3.3.4" targetFramework="net46" />
|
||||
<package id="RGB.NET.Core" version="0.0.1.38" targetFramework="net461" />
|
||||
<package id="Stylet" version="1.1.21" targetFramework="net46" />
|
||||
<package id="System.AppContext" version="4.3.0" targetFramework="net46" />
|
||||
<package id="System.Collections" version="4.3.0" targetFramework="net46" />
|
||||
@@ -36,10 +36,10 @@
|
||||
<package id="System.Runtime.Extensions" version="4.3.0" targetFramework="net46" />
|
||||
<package id="System.Runtime.InteropServices" version="4.3.0" targetFramework="net46" />
|
||||
<package id="System.Runtime.Numerics" version="4.3.0" targetFramework="net46" />
|
||||
<package id="System.Security.Cryptography.Algorithms" version="4.3.0" targetFramework="net46" />
|
||||
<package id="System.Security.Cryptography.Algorithms" version="4.3.0" targetFramework="net46" requireReinstallation="true" />
|
||||
<package id="System.Security.Cryptography.Encoding" version="4.3.0" targetFramework="net46" />
|
||||
<package id="System.Security.Cryptography.Primitives" version="4.3.0" targetFramework="net46" />
|
||||
<package id="System.Security.Cryptography.X509Certificates" version="4.3.0" targetFramework="net46" />
|
||||
<package id="System.Security.Cryptography.X509Certificates" version="4.3.0" targetFramework="net46" requireReinstallation="true" />
|
||||
<package id="System.Text.Encoding" version="4.3.0" targetFramework="net46" />
|
||||
<package id="System.Text.Encoding.CodePages" version="4.3.0" targetFramework="net46" />
|
||||
<package id="System.Text.Encoding.Extensions" version="4.3.0" targetFramework="net46" />
|
||||
@@ -47,7 +47,7 @@
|
||||
<package id="System.Threading.Tasks" version="4.3.0" targetFramework="net46" />
|
||||
<package id="System.Threading.Tasks.Parallel" version="4.3.0" targetFramework="net46" />
|
||||
<package id="System.Threading.Thread" version="4.3.0" targetFramework="net46" />
|
||||
<package id="System.ValueTuple" version="4.3.0" targetFramework="net46" />
|
||||
<package id="System.ValueTuple" version="4.4.0" targetFramework="net461" />
|
||||
<package id="System.Xml.ReaderWriter" version="4.3.0" targetFramework="net46" />
|
||||
<package id="System.Xml.XDocument" version="4.3.0" targetFramework="net46" />
|
||||
<package id="System.Xml.XmlDocument" version="4.3.0" targetFramework="net46" />
|
||||
|
||||
Reference in new issue
Block a user