Updated plugin installation
This commit is contained in:
@@ -192,7 +192,7 @@ internal static class PluginMethods
|
||||
await Parallel.ForEachAsync(downloadTasks, options, async (tuple, token) =>
|
||||
{
|
||||
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);
|
||||
}
|
||||
);
|
||||
|
||||
@@ -6,6 +6,7 @@ using System.Reflection;
|
||||
|
||||
namespace DiscordBot;
|
||||
|
||||
|
||||
public static class Entry
|
||||
{
|
||||
/// <summary>
|
||||
@@ -58,7 +59,7 @@ public static class Entry
|
||||
static Assembly LoadFromSameFolder(object sender, ResolveEventArgs args)
|
||||
{
|
||||
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");
|
||||
if (!File.Exists(assemblyPath))
|
||||
return null;
|
||||
|
||||
@@ -9,6 +9,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using DiscordBotCore.Others.Exceptions;
|
||||
|
||||
|
||||
namespace DiscordBotCore
|
||||
@@ -120,5 +121,19 @@ namespace DiscordBotCore
|
||||
}
|
||||
|
||||
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 CheckForUpdates();
|
||||
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 pluginName, string dependencyName);
|
||||
Task<List<PluginInfo>> GetInstalledPlugins();
|
||||
Task<PluginOnlineInfo?> GetPluginDataByName(string pluginName);
|
||||
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));
|
||||
foreach (var dependency in pluginData.ListOfExecutableDependencies)
|
||||
{
|
||||
pluginData.ListOfExecutableDependencies[dependency.Key] = GenerateDependencyLocation(pluginData.PluginName, dependency.Value);
|
||||
pluginData.ListOfExecutableDependencies[dependency.Key] = dependency.Value;
|
||||
}
|
||||
|
||||
installedPlugins.Add(pluginData);
|
||||
@@ -175,16 +175,37 @@ public class PluginManager : IPluginManager
|
||||
|
||||
foreach (var plugin in installedPlugins)
|
||||
{
|
||||
if (plugin.ListOfExecutableDependencies.ContainsKey(dependencyName))
|
||||
return plugin.ListOfExecutableDependencies[dependencyName];
|
||||
if (plugin.ListOfExecutableDependencies.TryGetValue(dependencyName, out var dependencyPath))
|
||||
{
|
||||
string relativePath = GenerateDependencyRelativePath(plugin.PluginName, dependencyPath);
|
||||
return relativePath;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public string GenerateDependencyLocation(string pluginName, string dependencyName)
|
||||
public async Task<string?> GetDependencyLocation(string dependencyName, string pluginName)
|
||||
{
|
||||
return Path.Combine(Environment.CurrentDirectory, $"Libraries/{pluginName}/{dependencyName}");
|
||||
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;
|
||||
}
|
||||
|
||||
public string GenerateDependencyRelativePath(string pluginName, string dependencyPath)
|
||||
{
|
||||
string relative = $"./Libraries/{pluginName}/{dependencyPath}";
|
||||
return relative;
|
||||
}
|
||||
|
||||
public async Task InstallPlugin(PluginOnlineInfo pluginData, IProgress<float>? installProgress)
|
||||
@@ -208,7 +229,7 @@ public class PluginManager : IPluginManager
|
||||
if (pluginData.HasFileDependencies)
|
||||
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);
|
||||
|
||||
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