Updated plugin installation
This commit is contained in:
@@ -192,7 +192,7 @@ internal static class PluginMethods
|
|||||||
await Parallel.ForEachAsync(downloadTasks, options, async (tuple, token) =>
|
await Parallel.ForEachAsync(downloadTasks, options, async (tuple, token) =>
|
||||||
{
|
{
|
||||||
tuple.Item1.IsIndeterminate = false;
|
tuple.Item1.IsIndeterminate = false;
|
||||||
string downloadLocation = Application.CurrentApplication.PluginManager.GenerateDependencyLocation(pluginName, tuple.Item4);
|
string downloadLocation = Application.CurrentApplication.PluginManager.GenerateDependencyRelativePath(pluginName, tuple.Item4);
|
||||||
await ServerCom.DownloadFileAsync(tuple.Item3, downloadLocation, tuple.Item2);
|
await ServerCom.DownloadFileAsync(tuple.Item3, downloadLocation, tuple.Item2);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ using System.Reflection;
|
|||||||
|
|
||||||
namespace DiscordBot;
|
namespace DiscordBot;
|
||||||
|
|
||||||
|
|
||||||
public static class Entry
|
public static class Entry
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -58,7 +59,7 @@ public static class Entry
|
|||||||
static Assembly LoadFromSameFolder(object sender, ResolveEventArgs args)
|
static Assembly LoadFromSameFolder(object sender, ResolveEventArgs args)
|
||||||
{
|
{
|
||||||
string requestingAssembly = args.RequestingAssembly?.GetName().Name;
|
string requestingAssembly = args.RequestingAssembly?.GetName().Name;
|
||||||
var folderPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, $"Libraries\\{requestingAssembly}");
|
var folderPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, $"Libraries/{requestingAssembly}");
|
||||||
var assemblyPath = Path.Combine(folderPath, new AssemblyName(args.Name).Name + ".dll");
|
var assemblyPath = Path.Combine(folderPath, new AssemblyName(args.Name).Name + ".dll");
|
||||||
if (!File.Exists(assemblyPath))
|
if (!File.Exists(assemblyPath))
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -9,8 +9,9 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using DiscordBotCore.Others.Exceptions;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace DiscordBotCore
|
namespace DiscordBotCore
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -120,5 +121,19 @@ namespace DiscordBotCore
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static string GetPluginFullPath() => _PluginsFolder;
|
public static string GetPluginFullPath() => _PluginsFolder;
|
||||||
|
|
||||||
|
public static async Task<string> GetPluginDependencyPath(string dependencyName, string? pluginName = null)
|
||||||
|
{
|
||||||
|
string? dependencyLocation;
|
||||||
|
if(pluginName is null)
|
||||||
|
dependencyLocation = await Application.CurrentApplication.PluginManager.GetDependencyLocation(dependencyName);
|
||||||
|
else
|
||||||
|
dependencyLocation = await Application.CurrentApplication.PluginManager.GetDependencyLocation(dependencyName, pluginName);
|
||||||
|
|
||||||
|
if(dependencyLocation is null)
|
||||||
|
throw new DependencyNotFoundException($"Dependency {dependencyName} not found", pluginName);
|
||||||
|
|
||||||
|
return dependencyLocation;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,8 +13,9 @@ namespace DiscordBotCore.Interfaces.PluginManager
|
|||||||
Task AppendPluginToDatabase(PluginInfo pluginData);
|
Task AppendPluginToDatabase(PluginInfo pluginData);
|
||||||
Task CheckForUpdates();
|
Task CheckForUpdates();
|
||||||
Task ExecutePluginInstallScripts(List<OnlineScriptDependencyInfo> listOfDependencies);
|
Task ExecutePluginInstallScripts(List<OnlineScriptDependencyInfo> listOfDependencies);
|
||||||
string GenerateDependencyLocation(string pluginName, string dependencyName);
|
string GenerateDependencyRelativePath(string pluginName, string dependencyPath);
|
||||||
Task<string?> GetDependencyLocation(string dependencyName);
|
Task<string?> GetDependencyLocation(string dependencyName);
|
||||||
|
Task<string?> GetDependencyLocation(string pluginName, string dependencyName);
|
||||||
Task<List<PluginInfo>> GetInstalledPlugins();
|
Task<List<PluginInfo>> GetInstalledPlugins();
|
||||||
Task<PluginOnlineInfo?> GetPluginDataByName(string pluginName);
|
Task<PluginOnlineInfo?> GetPluginDataByName(string pluginName);
|
||||||
Task<List<PluginOnlineInfo>?> GetPluginsList();
|
Task<List<PluginOnlineInfo>?> GetPluginsList();
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ public class PluginManager : IPluginManager
|
|||||||
List<PluginInfo> installedPlugins = await JsonManager.ConvertFromJson<List<PluginInfo>>(await File.ReadAllTextAsync(Application.CurrentApplication.PluginDatabase));
|
List<PluginInfo> installedPlugins = await JsonManager.ConvertFromJson<List<PluginInfo>>(await File.ReadAllTextAsync(Application.CurrentApplication.PluginDatabase));
|
||||||
foreach (var dependency in pluginData.ListOfExecutableDependencies)
|
foreach (var dependency in pluginData.ListOfExecutableDependencies)
|
||||||
{
|
{
|
||||||
pluginData.ListOfExecutableDependencies[dependency.Key] = GenerateDependencyLocation(pluginData.PluginName, dependency.Value);
|
pluginData.ListOfExecutableDependencies[dependency.Key] = dependency.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
installedPlugins.Add(pluginData);
|
installedPlugins.Add(pluginData);
|
||||||
@@ -175,16 +175,37 @@ public class PluginManager : IPluginManager
|
|||||||
|
|
||||||
foreach (var plugin in installedPlugins)
|
foreach (var plugin in installedPlugins)
|
||||||
{
|
{
|
||||||
if (plugin.ListOfExecutableDependencies.ContainsKey(dependencyName))
|
if (plugin.ListOfExecutableDependencies.TryGetValue(dependencyName, out var dependencyPath))
|
||||||
return plugin.ListOfExecutableDependencies[dependencyName];
|
{
|
||||||
|
string relativePath = GenerateDependencyRelativePath(plugin.PluginName, dependencyPath);
|
||||||
|
return relativePath;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<string?> GetDependencyLocation(string dependencyName, string pluginName)
|
||||||
|
{
|
||||||
|
List<PluginInfo> installedPlugins = await GetInstalledPlugins();
|
||||||
|
|
||||||
|
foreach (var plugin in installedPlugins)
|
||||||
|
{
|
||||||
|
if (plugin.PluginName == pluginName && plugin.ListOfExecutableDependencies.ContainsKey(dependencyName))
|
||||||
|
{
|
||||||
|
string dependencyPath = plugin.ListOfExecutableDependencies[dependencyName];
|
||||||
|
string relativePath = GenerateDependencyRelativePath(pluginName, dependencyPath);
|
||||||
|
return relativePath;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GenerateDependencyLocation(string pluginName, string dependencyName)
|
public string GenerateDependencyRelativePath(string pluginName, string dependencyPath)
|
||||||
{
|
{
|
||||||
return Path.Combine(Environment.CurrentDirectory, $"Libraries/{pluginName}/{dependencyName}");
|
string relative = $"./Libraries/{pluginName}/{dependencyPath}";
|
||||||
|
return relative;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task InstallPlugin(PluginOnlineInfo pluginData, IProgress<float>? installProgress)
|
public async Task InstallPlugin(PluginOnlineInfo pluginData, IProgress<float>? installProgress)
|
||||||
@@ -208,7 +229,7 @@ public class PluginManager : IPluginManager
|
|||||||
if (pluginData.HasFileDependencies)
|
if (pluginData.HasFileDependencies)
|
||||||
foreach (var dependency in pluginData.Dependencies)
|
foreach (var dependency in pluginData.Dependencies)
|
||||||
{
|
{
|
||||||
string dependencyLocation = GenerateDependencyLocation(pluginData.Name, dependency.DownloadLocation);
|
string dependencyLocation = GenerateDependencyRelativePath(pluginData.Name, dependency.DownloadLocation);
|
||||||
await ServerCom.DownloadFileAsync(dependency.DownloadLink, dependencyLocation, progress);
|
await ServerCom.DownloadFileAsync(dependency.DownloadLink, dependencyLocation, progress);
|
||||||
|
|
||||||
currentProgress += stepProgress;
|
currentProgress += stepProgress;
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace DiscordBotCore.Others.Exceptions;
|
||||||
|
|
||||||
|
public class DependencyNotFoundException : Exception
|
||||||
|
{
|
||||||
|
private string PluginName { get; set; }
|
||||||
|
public DependencyNotFoundException(string message): base(message)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public DependencyNotFoundException(string message, string pluginName): base(message)
|
||||||
|
{
|
||||||
|
this.PluginName = pluginName;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user