Updated plugin command to enable branch switching. Updated Script runner

This commit is contained in:
2024-06-06 15:37:33 +03:00
parent de7c65c27b
commit 23961a48b0
8 changed files with 91 additions and 29 deletions

View File

@@ -17,8 +17,8 @@ public class PluginManager
private static readonly string _DefaultPluginsLink = "PluginsList.json";
public string Branch { get; init; }
public string BaseUrl { get; init; }
public string Branch { get; set; }
public string BaseUrl { get; set; }
private string PluginsLink => $"{BaseUrl}/{Branch}/{_DefaultPluginsLink}";
@@ -71,6 +71,13 @@ public class PluginManager
await JsonManager.SaveToJsonFile(Application.CurrentApplication.PluginDatabase,installedPlugins);
}
public async Task ExecutePluginInstallScripts(List<OnlineScriptDependencyInfo> listOfDependencies)
{
string consoleType = OperatingSystem.IsWindows() ? "cmd.exe" : "bash";
foreach(var script in listOfDependencies)
await ServerCom.RunConsoleCommand(consoleType, "/c " + script.ScriptContent);
}
public async Task AppendPluginToDatabase(PluginInfo pluginData)
{
List<PluginInfo> installedPlugins = await JsonManager.ConvertFromJson<List<PluginInfo>>(await File.ReadAllTextAsync(Application.CurrentApplication.PluginDatabase));
@@ -148,7 +155,8 @@ public class PluginManager
{
installProgress?.Report(0f);
int totalSteps = pluginData.HasDependencies ? pluginData.Dependencies.Count + pluginData.ScriptDependencies.Count + 1: 1;
int totalSteps = pluginData.HasFileDependencies ? pluginData.Dependencies.Count + 1: 1;
totalSteps += pluginData.HasScriptDependencies ? pluginData.ScriptDependencies.Count : 0;
float stepProgress = 1f / totalSteps;
@@ -160,26 +168,29 @@ public class PluginManager
await ServerCom.DownloadFileAsync(pluginData.DownLoadLink, $"{Application.CurrentApplication.ApplicationEnvironmentVariables["PluginFolder"]}/{pluginData.Name}.dll", progress);
foreach (var dependency in pluginData.Dependencies)
{
await ServerCom.DownloadFileAsync(dependency.DownloadLink, dependency.DownloadLocation, progress);
currentProgress += stepProgress;
}
if (pluginData.HasFileDependencies)
foreach (var dependency in pluginData.Dependencies)
{
await ServerCom.DownloadFileAsync(dependency.DownloadLink, dependency.DownloadLocation, progress);
currentProgress += stepProgress;
}
foreach(var scriptDependency in pluginData.ScriptDependencies)
{
if (pluginData.HasScriptDependencies)
foreach (var scriptDependency in pluginData.ScriptDependencies)
{
string console = OperatingSystem.IsWindows() ? "cmd" : "bash";
string arguments = OperatingSystem.IsWindows() ? $"/c {scriptDependency.ScriptContent}" : scriptDependency.ScriptContent;
string console = OperatingSystem.IsWindows() ? "start cmd.exe" : "bash";
string arguments = OperatingSystem.IsWindows() ? $"/c {scriptDependency.ScriptContent}" : scriptDependency.ScriptContent;
await ServerCom.RunConsoleCommand(console, arguments);
currentProgress += stepProgress;
}
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);

View File

@@ -76,14 +76,13 @@ public static class ServerCom
return DownloadFileAsync(URl, location, progress, null);
}
public static async Task<string> RunConsoleCommand(string console, string command)
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();
}