Skip to content
Merged
37 changes: 37 additions & 0 deletions OpenPuppet.Plugins/Manager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OpenPuppet.Plugins
{
public static class Manager
{
/// <summary>
/// Installs a plugin from a path, the path can either be a directory
/// or a ZIP file.
/// </summary>
/// <param name="path">The path to directory/ZIP file</param>
public static void InstallPlugin(string path)
{
if (Directory.Exists(path)) InstallPluginDir(path);
else InstallPluginArchive(path);
}

public static async Task InstallPluginAsync(string path)
{
return;
}

static internal void InstallPluginDir(string path)
{

}

static internal void InstallPluginArchive(string path)
{

}
}
}
7 changes: 7 additions & 0 deletions OpenPuppet.Plugins/Metadata.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace OpenPuppet.Plugins
{
public static class Metadata
{

}
}
13 changes: 13 additions & 0 deletions OpenPuppet.Plugins/OpenPuppet.Plugins.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\src\OpenPuppet.DataTypes\OpenPuppet.DataTypes.csproj" />
</ItemGroup>

</Project>
50 changes: 50 additions & 0 deletions OpenPuppet.Plugins/Path.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using OpenPuppet.DataTypes.Plugin;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Runtime.InteropServices.JavaScript.JSType;

namespace OpenPuppet.Plugins
{
public static class Path
{
internal static string? InstallPath
{
get
{
return System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
}
}

public static string? PluginPath
{
get
{
return InstallPath != null ? System.IO.Path.Combine(InstallPath, "Plugins") : null;
}
}

public static string SafePluginName(string name)
{
name = name.ToLower().Replace(' ', '-');
name = Regex.Replace(name, @"[^a-zA-Z0-9]", "");

return name;
}

public static string? GetPluginPath(string name)
{
if (PluginPath == null) return null;
return System.IO.Path.Combine(PluginPath, SafePluginName(name));
}

public static string? GetPluginPath(PluginMetadata metadata)
{
return GetPluginPath(metadata.Name);
}
}
}
12 changes: 12 additions & 0 deletions OpenPuppet.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenPuppet", "src\OpenPuppe
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenPuppet.Tests", "src\OpenPuppet.Tests\OpenPuppet.Tests.csproj", "{E2D6A937-6D8B-43B4-9EA8-6292872C2224}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenPuppet.DataTypes", "src\OpenPuppet.DataTypes\OpenPuppet.DataTypes.csproj", "{E4A8B804-ECED-4140-8B30-66B7842FD863}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenPuppet.Plugins", "OpenPuppet.Plugins\OpenPuppet.Plugins.csproj", "{D1EE7937-72B4-4A1A-9B9B-EF1759027462}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -21,6 +25,14 @@ Global
{E2D6A937-6D8B-43B4-9EA8-6292872C2224}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E2D6A937-6D8B-43B4-9EA8-6292872C2224}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E2D6A937-6D8B-43B4-9EA8-6292872C2224}.Release|Any CPU.Build.0 = Release|Any CPU
{E4A8B804-ECED-4140-8B30-66B7842FD863}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E4A8B804-ECED-4140-8B30-66B7842FD863}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E4A8B804-ECED-4140-8B30-66B7842FD863}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E4A8B804-ECED-4140-8B30-66B7842FD863}.Release|Any CPU.Build.0 = Release|Any CPU
{D1EE7937-72B4-4A1A-9B9B-EF1759027462}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D1EE7937-72B4-4A1A-9B9B-EF1759027462}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D1EE7937-72B4-4A1A-9B9B-EF1759027462}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D1EE7937-72B4-4A1A-9B9B-EF1759027462}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
9 changes: 9 additions & 0 deletions src/OpenPuppet.DataTypes/OpenPuppet.DataTypes.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
31 changes: 31 additions & 0 deletions src/OpenPuppet.DataTypes/Plugin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
namespace OpenPuppet.DataTypes.Plugin
{
/// <summary>
/// Plugin interface
/// </summary>
public interface IPlugin
{
/// <summary>
/// The plugin ID
/// </summary>
public string PluginID { get; set; }

/// <summary>
/// OnInitialized
/// This is called when the plugin is loaded, use this to prepare the plugin
/// </summary>
abstract void OnInitialized();
}

/// <summary>
/// Plugin metadata file
/// </summary>
public class PluginMetadata
{
public string Name { get; set; } = string.Empty;
public string Description { get; set; } = string.Empty;
public string Author { get; set; } = string.Empty;
public string Version { get; set; } = string.Empty;
public string Icon { get; set; } = string.Empty;
}
}
5 changes: 5 additions & 0 deletions src/OpenPuppet.Tests/OpenPuppet.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\OpenPuppet.Plugins\OpenPuppet.Plugins.csproj" />
<ProjectReference Include="..\OpenPuppet.DataTypes\OpenPuppet.DataTypes.csproj" />
</ItemGroup>

<ItemGroup>
<Using Include="Xunit" />
</ItemGroup>
Expand Down
29 changes: 29 additions & 0 deletions src/OpenPuppet.Tests/Plugins/Path.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace OpenPuppet.Tests.Plugins
{
public class Path
{
[Fact]
public void TestPluginName()
{
Assert.NotEqual(
"a-b-c-d",
OpenPuppet.Plugins.Path.SafePluginName(
@"a B
`¦¬!" + '"' + @"@£$%^&*()_+-=[]{};:'@#~,./<>?\| C d"
)
);
}

[Fact]
public void TestPluginPath()
{
Assert.EndsWith(
"a-b-c-d",
OpenPuppet.Plugins.Path.GetPluginPath(
@"a B
`¦¬!" + '"' + @"@£$%^&*()_+-=[]{};:'@#~,./<>?\| C d"
)
);
}
}
}
11 changes: 0 additions & 11 deletions src/OpenPuppet.Tests/UnitTest1.cs

This file was deleted.

2 changes: 2 additions & 0 deletions src/OpenPuppet/OpenPuppet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\OpenPuppet.Plugins\OpenPuppet.Plugins.csproj" />
<ProjectReference Include="..\OpenPuppet.DataTypes\OpenPuppet.DataTypes.csproj" />
<None Update="shaders\vector.fragment.glsl">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
Loading