From de7c65c27b53e5fa0ae04960e9411d11406c78d9 Mon Sep 17 00:00:00 2001 From: Andrei Tudor Date: Thu, 6 Jun 2024 00:39:44 +0300 Subject: [PATCH] Run install scripts --- DiscordBotCore/Online/PluginManager.cs | 18 +++++++++++++++--- DiscordBotCore/Online/ServerCom.cs | 12 ++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/DiscordBotCore/Online/PluginManager.cs b/DiscordBotCore/Online/PluginManager.cs index 2479f05..22d6bf1 100644 --- a/DiscordBotCore/Online/PluginManager.cs +++ b/DiscordBotCore/Online/PluginManager.cs @@ -148,7 +148,7 @@ public class PluginManager { installProgress?.Report(0f); - int totalSteps = pluginData.HasDependencies ? pluginData.Dependencies.Count + 1 : 1; + int totalSteps = pluginData.HasDependencies ? pluginData.Dependencies.Count + pluginData.ScriptDependencies.Count + 1: 1; float stepProgress = 1f / totalSteps; @@ -166,9 +166,21 @@ public class PluginManager currentProgress += stepProgress; } - PluginInfo pluginInfo = new PluginInfo(pluginData.Name, + foreach(var scriptDependency in pluginData.ScriptDependencies) + { + + string console = OperatingSystem.IsWindows() ? "cmd" : "bash"; + string arguments = OperatingSystem.IsWindows() ? $"/c {scriptDependency.ScriptContent}" : scriptDependency.ScriptContent; + + await ServerCom.RunConsoleCommand(console, arguments); + currentProgress += stepProgress; + } + + PluginInfo pluginInfo = new PluginInfo( + pluginData.Name, pluginData.Version, - pluginData.Dependencies.Select(dep => dep.DownloadLocation).ToList()); + pluginData.Dependencies.Select(dep => dep.DownloadLocation).ToList() + ); await AppendPluginToDatabase(pluginInfo); } diff --git a/DiscordBotCore/Online/ServerCom.cs b/DiscordBotCore/Online/ServerCom.cs index eef3f81..42aa117 100644 --- a/DiscordBotCore/Online/ServerCom.cs +++ b/DiscordBotCore/Online/ServerCom.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Linq; using System.Net.Http; @@ -75,4 +76,15 @@ public static class ServerCom return DownloadFileAsync(URl, location, progress, null); } + public static async Task RunConsoleCommand(string console, string command) + { + Process process = new(); + process.StartInfo.FileName = console; + process.StartInfo.Arguments = command; + process.Start(); + await process.WaitForExitAsync(); + return await process.StandardOutput.ReadToEndAsync(); + + } + }