Updated API for plugins to work with database from remote. Added PluginRepository and removed Installation Scripts
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using DiscordBotCore.Plugin;
|
||||
|
||||
namespace DiscordBotCore.Interfaces.PluginManagement;
|
||||
|
||||
public interface IPluginRepository
|
||||
{
|
||||
public Task<List<OnlinePlugin>> GetAllPlugins();
|
||||
|
||||
public Task<OnlinePlugin?> GetPluginById(int pluginId);
|
||||
public Task<OnlinePlugin?> GetPluginByName(string pluginName);
|
||||
|
||||
public Task<List<OnlineDependencyInfo>> GetDependenciesForPlugin(int pluginId);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace DiscordBotCore.Interfaces.PluginManagement;
|
||||
|
||||
public interface IPluginRepositoryConfiguration
|
||||
{
|
||||
public string BaseUrl { get; }
|
||||
|
||||
public string PluginRepositoryLocation { get; }
|
||||
public string DependenciesRepositoryLocation { get; }
|
||||
|
||||
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using DiscordBotCore.Plugin;
|
||||
|
||||
namespace DiscordBotCore.Interfaces.PluginManager
|
||||
{
|
||||
public interface IPluginManager
|
||||
{
|
||||
public string BaseUrl { get; set; }
|
||||
public string Branch { get; set; }
|
||||
Task AppendPluginToDatabase(PluginInfo pluginData);
|
||||
Task CheckForUpdates();
|
||||
Task ExecutePluginInstallScripts(List<OnlineScriptDependencyInfo> listOfDependencies);
|
||||
string GenerateDependencyRelativePath(string pluginName, string dependencyPath);
|
||||
Task<string?> GetDependencyLocation(string dependencyName);
|
||||
Task<string?> GetDependencyLocation(string pluginName, string dependencyName);
|
||||
Task<List<PluginInfo>> GetInstalledPlugins();
|
||||
Task<PluginOnlineInfo?> GetPluginDataByName(string pluginName);
|
||||
Task<List<PluginOnlineInfo>?> GetPluginsList();
|
||||
Task InstallPlugin(PluginOnlineInfo pluginData, IProgress<float>? installProgress);
|
||||
Task<bool> IsPluginInstalled(string pluginName);
|
||||
Task<bool> MarkPluginToUninstall(string pluginName);
|
||||
Task RemovePluginFromDatabase(string pluginName);
|
||||
Task UninstallMarkedPlugins();
|
||||
Task SetEnabledStatus(string pluginName, bool status);
|
||||
}
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
namespace DiscordBotCore.Interfaces.Updater
|
||||
{
|
||||
public class AppVersion : IVersion
|
||||
{
|
||||
public static readonly AppVersion CurrentAppVersion = new AppVersion(Assembly.GetEntryAssembly().GetName().Version.ToString());
|
||||
|
||||
public int Major { get; set; }
|
||||
public int Minor { get; set; }
|
||||
public int Patch { get; set; }
|
||||
public int PatchVersion { get; set; }
|
||||
|
||||
private readonly char _Separator = '.';
|
||||
|
||||
public AppVersion(string versionAsString)
|
||||
{
|
||||
string[] versionParts = versionAsString.Split(_Separator);
|
||||
|
||||
if (versionParts.Length != 4)
|
||||
{
|
||||
throw new ArgumentException("Invalid version string");
|
||||
}
|
||||
|
||||
Major = int.Parse(versionParts[0]);
|
||||
Minor = int.Parse(versionParts[1]);
|
||||
Patch = int.Parse(versionParts[2]);
|
||||
PatchVersion = int.Parse(versionParts[3]);
|
||||
}
|
||||
|
||||
public bool IsNewerThan(IVersion version)
|
||||
{
|
||||
if (Major > version.Major)
|
||||
return true;
|
||||
|
||||
if (Major == version.Major && Minor > version.Minor)
|
||||
return true;
|
||||
|
||||
if (Major == version.Major && Minor == version.Minor && Patch > version.Patch)
|
||||
return true;
|
||||
|
||||
if (Major == version.Major && Minor == version.Minor && Patch == version.Patch && PatchVersion > version.PatchVersion)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool IsOlderThan(IVersion version)
|
||||
{
|
||||
if (Major < version.Major)
|
||||
return true;
|
||||
|
||||
if (Major == version.Major && Minor < version.Minor)
|
||||
return true;
|
||||
|
||||
if (Major == version.Major && Minor == version.Minor && Patch < version.Patch)
|
||||
return true;
|
||||
|
||||
if (Major == version.Major && Minor == version.Minor && Patch == version.Patch && PatchVersion < version.PatchVersion)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool IsEqualTo(IVersion version)
|
||||
{
|
||||
return Major == version.Major && Minor == version.Minor && Patch == version.Patch && PatchVersion == version.PatchVersion;
|
||||
}
|
||||
|
||||
public string ToShortString()
|
||||
{
|
||||
return $"{Major}.{Minor}.{Patch}.{PatchVersion}";
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return ToShortString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
namespace DiscordBotCore.Interfaces.Updater;
|
||||
|
||||
public interface IVersion
|
||||
{
|
||||
public int Major { get; }
|
||||
public int Minor { get; }
|
||||
public int Patch { get; }
|
||||
public int PatchVersion => 0;
|
||||
|
||||
public bool IsNewerThan(IVersion version);
|
||||
|
||||
public bool IsOlderThan(IVersion version);
|
||||
|
||||
public bool IsEqualTo(IVersion version);
|
||||
|
||||
public string ToShortString();
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace DiscordBotCore.Interfaces.Updater;
|
||||
|
||||
public abstract class Version: IVersion
|
||||
{
|
||||
public int Major { get; }
|
||||
public int Minor { get; }
|
||||
public int Patch { get; }
|
||||
|
||||
protected readonly char _Separator = '.';
|
||||
|
||||
protected Version(int major, int minor, int patch)
|
||||
{
|
||||
Major = major;
|
||||
Minor = minor;
|
||||
Patch = patch;
|
||||
}
|
||||
|
||||
protected Version(string versionAsString)
|
||||
{
|
||||
string[] versionParts = versionAsString.Split(_Separator);
|
||||
|
||||
if (versionParts.Length != 3)
|
||||
{
|
||||
throw new ArgumentException("Invalid version string");
|
||||
}
|
||||
|
||||
Major = int.Parse(versionParts[0]);
|
||||
Minor = int.Parse(versionParts[1]);
|
||||
Patch = int.Parse(versionParts[2]);
|
||||
}
|
||||
|
||||
public bool IsNewerThan(IVersion version)
|
||||
{
|
||||
if (Major > version.Major)
|
||||
return true;
|
||||
|
||||
if (Major == version.Major && Minor > version.Minor)
|
||||
return true;
|
||||
|
||||
if (Major == version.Major && Minor == version.Minor && Patch > version.Patch)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool IsOlderThan(IVersion version)
|
||||
{
|
||||
if (Major < version.Major)
|
||||
return true;
|
||||
|
||||
if (Major == version.Major && Minor < version.Minor)
|
||||
return true;
|
||||
|
||||
if (Major == version.Major && Minor == version.Minor && Patch < version.Patch)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool IsEqualTo(IVersion version)
|
||||
{
|
||||
return Major == version.Major && Minor == version.Minor && Patch == version.Patch;
|
||||
}
|
||||
|
||||
public string ToShortString()
|
||||
{
|
||||
return $"{Major}.{Minor}.{Patch}";
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return ToShortString();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user