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
+4 -1
View File
@@ -34,7 +34,10 @@ internal class Loader
return;
}
var files = Directory.GetFiles(_SearchPath, $"*.{_FileExtension}", SearchOption.TopDirectoryOnly);
var installedPlugins = await Application.CurrentApplication.PluginManager.GetInstalledPlugins();
var files = installedPlugins.Select(plugin => plugin.FilePath).ToArray();
//var files = Directory.GetFiles(_SearchPath, $"*.{_FileExtension}", SearchOption.TopDirectoryOnly);
foreach (var file in files)
{
try
+27 -16
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);
+1 -2
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();
}
+2 -2
View File
@@ -20,8 +20,8 @@ public class JsonManager
var str = new MemoryStream();
await JsonSerializer.SerializeAsync(str, Data, typeof(T), new JsonSerializerOptions
{
WriteIndented = true
}
WriteIndented = true,
}
);
await File.WriteAllBytesAsync(file, str.ToArray());
await str.FlushAsync();
+2 -3
View File
@@ -15,7 +15,8 @@ public class PluginOnlineInfo
public List<OnlineDependencyInfo> Dependencies { get; private set; }
public List<OnlineScriptDependencyInfo> ScriptDependencies { get; private set; }
public OSType SupportedOS { get; private set; }
public bool HasDependencies { get; init; }
public bool HasFileDependencies => Dependencies is not null && Dependencies.Count > 0;
public bool HasScriptDependencies => ScriptDependencies is not null && ScriptDependencies.Count > 0;
[JsonConstructor]
public PluginOnlineInfo(string name, PluginVersion version, string description, string downLoadLink, OSType supportedOS, List<OnlineDependencyInfo> dependencies, List<OnlineScriptDependencyInfo> scriptDependencies)
@@ -26,7 +27,6 @@ public class PluginOnlineInfo
DownLoadLink = downLoadLink;
SupportedOS = supportedOS;
Dependencies = dependencies;
HasDependencies = dependencies.Count > 0;
ScriptDependencies = scriptDependencies;
}
@@ -39,7 +39,6 @@ public class PluginOnlineInfo
SupportedOS = supportedOS;
Dependencies = new List<OnlineDependencyInfo>();
ScriptDependencies = new List<OnlineScriptDependencyInfo>();
HasDependencies = false;
}
public static async Task<PluginOnlineInfo> FromRawData(string jsonText)