diff --git a/DiscordBotCore.PluginManagement/Models/LocalPlugin.cs b/DiscordBotCore.PluginManagement/Models/LocalPlugin.cs index 5d81bb0..6fa03d8 100644 --- a/DiscordBotCore.PluginManagement/Models/LocalPlugin.cs +++ b/DiscordBotCore.PluginManagement/Models/LocalPlugin.cs @@ -39,7 +39,7 @@ public class LocalPlugin public static LocalPlugin FromOnlineInfo(OnlinePlugin plugin, List dependencies, string downloadLocation) { LocalPlugin localPlugin = new LocalPlugin( - plugin.PluginName, plugin.LatestVersion, downloadLocation, + plugin.Name, plugin.Version, downloadLocation, dependencies.Where(dependency => dependency.IsExecutable) .ToDictionary(dependency => dependency.DependencyName, dependency => dependency.DownloadLocation) ); diff --git a/DiscordBotCore.PluginManagement/Models/OnlinePlugin.cs b/DiscordBotCore.PluginManagement/Models/OnlinePlugin.cs index 9acc3cf..b6815e7 100644 --- a/DiscordBotCore.PluginManagement/Models/OnlinePlugin.cs +++ b/DiscordBotCore.PluginManagement/Models/OnlinePlugin.cs @@ -4,24 +4,26 @@ namespace DiscordBotCore.PluginManagement.Models; public class OnlinePlugin { - public int PluginId { get; private set; } - public string PluginName { get; private set; } - public string PluginDescription { get; private set; } - public string LatestVersion { get; private set; } - public string PluginAuthor { get; private set; } - public string PluginLink { get; private set; } + public int Id { get; private set; } + public string Name { get; private set; } + public string Description { get; private set; } + public string Version { get; private set; } + public string Author { get; private set; } + public string DownloadLink { get; private set; } public int OperatingSystem { get; private set; } + public bool IsApproved { get; private set; } [JsonConstructor] - public OnlinePlugin(int pluginId, string pluginName, string pluginDescription, string latestVersion, - string pluginAuthor, string pluginLink, int operatingSystem) + public OnlinePlugin(int id, string name, string description, string version, + string author, string downloadLink, int operatingSystem, bool isApproved) { - PluginId = pluginId; - PluginName = pluginName; - PluginDescription = pluginDescription; - LatestVersion = latestVersion; - PluginAuthor = pluginAuthor; - PluginLink = pluginLink; + Id = id; + Name = name; + Description = description; + Version = version; + Author = author; + DownloadLink = downloadLink; OperatingSystem = operatingSystem; + IsApproved = isApproved; } } \ No newline at end of file diff --git a/DiscordBotCore.PluginManagement/PluginManager.cs b/DiscordBotCore.PluginManagement/PluginManager.cs index ecaf47d..262abf5 100644 --- a/DiscordBotCore.PluginManagement/PluginManager.cs +++ b/DiscordBotCore.PluginManagement/PluginManager.cs @@ -88,7 +88,14 @@ public sealed class PluginManager : IPluginManager string? pluginDatabaseFile = _Configuration.Get("PluginDatabase"); if (pluginDatabaseFile is null) { - throw new Exception("Plugin database file not found"); + _Logger.Log("Plugin database file path is not present in the config file", this, LogType.Warning); + return []; + } + + if (!File.Exists(pluginDatabaseFile)) + { + _Logger.Log("Plugin database file not found", this, LogType.Warning); + return []; } return await JsonManager.ConvertFromJson>(await File.ReadAllTextAsync(pluginDatabaseFile)); @@ -189,31 +196,31 @@ public sealed class PluginManager : IPluginManager public async Task InstallPlugin(OnlinePlugin plugin, IProgress progress) { - List dependencies = await _PluginRepository.GetDependenciesForPlugin(plugin.PluginId); + List dependencies = await _PluginRepository.GetDependenciesForPlugin(plugin.Id); string? pluginsFolder = _Configuration.Get("PluginFolder"); if (pluginsFolder is null) { throw new Exception("Plugin folder not found"); } - string downloadLocation = $"{pluginsFolder}/{plugin.PluginName}.dll"; + string downloadLocation = $"{pluginsFolder}/{plugin.Name}.dll"; InstallationProgressIndicator installationProgressIndicator = new InstallationProgressIndicator(); IProgress downloadProgress = new Progress(fileProgress => { - installationProgressIndicator.SetProgress(plugin.PluginName, fileProgress); + installationProgressIndicator.SetProgress(plugin.Name, fileProgress); progress.Report(installationProgressIndicator); }); - FileDownloader fileDownloader = new FileDownloader(plugin.PluginLink, downloadLocation); + FileDownloader fileDownloader = new FileDownloader(plugin.DownloadLink, downloadLocation); await fileDownloader.DownloadFile(downloadProgress.Report); ParallelDownloadExecutor executor = new ParallelDownloadExecutor(); foreach (var dependency in dependencies) { - string dependencyLocation = GenerateDependencyRelativePath(plugin.PluginName, dependency.DownloadLocation); + string dependencyLocation = GenerateDependencyRelativePath(plugin.Name, dependency.DownloadLocation); Action dependencyProgress = new Action(fileProgress => { installationProgressIndicator.SetProgress(dependency.DependencyName, fileProgress); @@ -228,17 +235,17 @@ public sealed class PluginManager : IPluginManager public async Task, List>> GatherInstallDataForPlugin(OnlinePlugin plugin) { - List dependencies = await _PluginRepository.GetDependenciesForPlugin(plugin.PluginId); + List dependencies = await _PluginRepository.GetDependenciesForPlugin(plugin.Id); string? pluginsFolder = _Configuration.Get("PluginFolder"); if (pluginsFolder is null) { throw new Exception("Plugin folder not found"); } - string downloadLocation = $"{pluginsFolder}/{plugin.PluginName}.dll"; - var downloads = new Dictionary { { downloadLocation, plugin.PluginLink } }; + string downloadLocation = $"{pluginsFolder}/{plugin.Name}.dll"; + var downloads = new Dictionary { { downloadLocation, plugin.DownloadLink } }; foreach(var dependency in dependencies) { - string dependencyLocation = GenerateDependencyRelativePath(plugin.PluginName, dependency.DownloadLocation); + string dependencyLocation = GenerateDependencyRelativePath(plugin.Name, dependency.DownloadLocation); downloads.Add(dependencyLocation, dependency.DownloadLink); } diff --git a/WebUI/Controllers/PluginsController.cs b/WebUI/Controllers/PluginsController.cs index 9734147..6b042f8 100644 --- a/WebUI/Controllers/PluginsController.cs +++ b/WebUI/Controllers/PluginsController.cs @@ -27,12 +27,43 @@ public class PluginsController : Controller foreach (var plugin in plugins) { OnlinePluginViewModel pluginViewModel = new OnlinePluginViewModel(); - pluginViewModel.Name = plugin.PluginName; - pluginViewModel.Description = plugin.PluginDescription; - pluginViewModel.Author = plugin.PluginAuthor; - pluginViewModel.Version = plugin.LatestVersion; - pluginViewModel.DownloadUrl = plugin.PluginLink; + pluginViewModel.Name = plugin.Name; + pluginViewModel.Description = plugin.Description; + pluginViewModel.Author = plugin.Author; + pluginViewModel.Version = plugin.Version; + pluginViewModel.DownloadUrl = plugin.DownloadLink; + + pluginViewModels.Add(pluginViewModel); } + return View(pluginViewModels); } + + [HttpGet] + public async Task InstalledPlugins() + { + _logger.Log("Getting plugins page", this); + var plugins = await _pluginManager.GetInstalledPlugins(); + _logger.Log($"{plugins.Count} Plugins loaded", this); + List pluginViewModels = new List(); + foreach (var plugin in plugins) + { + InstalledPluginViewModel pluginViewModel = new InstalledPluginViewModel(); + pluginViewModel.Name = plugin.PluginName; + pluginViewModel.Version = plugin.PluginVersion; + pluginViewModel.IsOfflineAdded = plugin.IsOfflineAdded; + + pluginViewModels.Add(pluginViewModel); + } + + return View(pluginViewModels); + } + + [HttpPost] + public async Task DeletePlugin(string pluginName) + { + _logger.Log($"Deleting plugin {pluginName}", this); + //TODO: Implement delete plugin + return RedirectToAction("InstalledPlugins"); + } } \ No newline at end of file diff --git a/WebUI/Controllers/SettingsController.cs b/WebUI/Controllers/SettingsController.cs index 69025b9..5caf36f 100644 --- a/WebUI/Controllers/SettingsController.cs +++ b/WebUI/Controllers/SettingsController.cs @@ -23,7 +23,7 @@ public class SettingsController : Controller { Token = _configuration.Get("token", string.Empty), Prefix = _configuration.Get("prefix", string.Empty), - ServerIds = _configuration.Get>("serverIds", new List()), + ServerIds = _configuration.Get>("ServerIds", new List()), }; return View(model); diff --git a/WebUI/Models/InstalledPluginViewModel.cs b/WebUI/Models/InstalledPluginViewModel.cs new file mode 100644 index 0000000..51b318a --- /dev/null +++ b/WebUI/Models/InstalledPluginViewModel.cs @@ -0,0 +1,8 @@ +namespace WebUI.Models; + +public class InstalledPluginViewModel +{ + public string Name { get; set; } + public string Version { get; set; } + public bool IsOfflineAdded { get; set; } +} \ No newline at end of file diff --git a/WebUI/Program.cs b/WebUI/Program.cs index 669a21c..e045fdd 100644 --- a/WebUI/Program.cs +++ b/WebUI/Program.cs @@ -136,7 +136,7 @@ builder.Services.AddSingleton(sp => IConfiguration configuration = sp.GetRequiredService(); Directory.CreateDirectory(configuration.Get("PluginFolder", defaultPluginFolder)); - string pluginDatabaseFile = configuration.Get("PluginDatabaseFile", defaultPluginDatabaseFile); + string pluginDatabaseFile = configuration.Get("PluginDatabase", defaultPluginDatabaseFile); Directory.CreateDirectory(new FileInfo(pluginDatabaseFile).DirectoryName); IPluginManager pluginManager = new PluginManager(pluginRepository, logger, configuration); diff --git a/WebUI/Views/Plugins/InstalledPlugins.cshtml b/WebUI/Views/Plugins/InstalledPlugins.cshtml new file mode 100644 index 0000000..f7a6e62 --- /dev/null +++ b/WebUI/Views/Plugins/InstalledPlugins.cshtml @@ -0,0 +1,32 @@ +@model List + +@{ + ViewData["Title"] = "Installed Plugins"; +} + +

@ViewData["Title"]

+ + + + + + + + + + + @foreach (var plugin in Model) + { + + + + + + } + +
NameVersionActions
@plugin.Name@plugin.Version +
+ +
+ +
\ No newline at end of file diff --git a/WebUI/Views/Shared/_Layout.cshtml b/WebUI/Views/Shared/_Layout.cshtml index 7199e8b..7b464aa 100644 --- a/WebUI/Views/Shared/_Layout.cshtml +++ b/WebUI/Views/Shared/_Layout.cshtml @@ -20,10 +20,13 @@