cleaning up PluginManager (phase 1)
This commit is contained in:
@@ -29,7 +29,7 @@ public class PluginsManager
|
||||
/// The method to load all plugins
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<List<string[]>> ListAvailablePlugins()
|
||||
public async Task<List<string[]>> GetAvailablePlugins()
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -40,16 +40,12 @@ public class PluginsManager
|
||||
var op = Functions.GetOperatingSystem();
|
||||
|
||||
var len = lines.Length;
|
||||
string[] titles = { "Name", "Description", "Type", "Version" };
|
||||
data.Add(new[] { "-", "-", "-", "-" });
|
||||
data.Add(titles);
|
||||
data.Add(new[] { "-", "-", "-", "-" });
|
||||
for (var i = 0; i < len; i++)
|
||||
{
|
||||
if (lines[i].Length <= 2)
|
||||
continue;
|
||||
var content = lines[i].Split(',');
|
||||
var display = new string[titles.Length];
|
||||
var display = new string[4]; // 4 columns
|
||||
if (op == OperatingSystem.WINDOWS)
|
||||
{
|
||||
if (content[4].Contains("Windows"))
|
||||
@@ -80,14 +76,11 @@ public class PluginsManager
|
||||
|
||||
data.Add(new[] { "-", "-", "-", "-" });
|
||||
|
||||
Utilities.FormatAndAlignTable(data, TableFormat.CENTER_EACH_COLUMN_BASED);
|
||||
|
||||
return data;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Logger.WriteLine("Failed to execute command: listplugs\nReason: " + exception.Message);
|
||||
Logger.WriteErrFile(exception.ToString());
|
||||
Config.Logger.Log("Failed to execute command: listplugs\nReason: " + exception.Message, this, TextType.ERROR);
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -120,8 +113,7 @@ public class PluginsManager
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Logger.WriteLine("Failed to execute command: listplugs\nReason: " + exception.Message);
|
||||
Logger.WriteErrFile(exception.ToString());
|
||||
Config.Logger.Log("Failed to execute command: listplugs\nReason: " + exception.Message, this, TextType.ERROR);
|
||||
}
|
||||
|
||||
return new string[] { null!, null!, null! };
|
||||
|
||||
@@ -33,7 +33,7 @@ public static class ServerCom
|
||||
/// <param name="progress">The <see cref="IProgress{T}" /> to track the download</param>
|
||||
/// <returns></returns>
|
||||
public static async Task DownloadFileAsync(string URL, string location, IProgress<float> progress,
|
||||
IProgress<long>? downloadedBytes = null)
|
||||
IProgress<long>? downloadedBytes)
|
||||
{
|
||||
using (var client = new HttpClient())
|
||||
{
|
||||
@@ -46,47 +46,9 @@ public static class ServerCom
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Download file from url
|
||||
/// </summary>
|
||||
/// <param name="URL">The url to the file</param>
|
||||
/// <param name="location">The location where to store the downloaded data</param>
|
||||
/// <returns></returns>
|
||||
public static async Task DownloadFileAsync(string URL, string location)
|
||||
public static async Task DownloadFileAsync(string URl, string location, IProgress<float> progress)
|
||||
{
|
||||
var isDownloading = true;
|
||||
float c_progress = 0;
|
||||
|
||||
var pbar = new Utilities.ProgressBar(ProgressBarType.NORMAL) { Max = 100f, NoColor = true };
|
||||
|
||||
IProgress<float> progress = new Progress<float>(percent => { c_progress = percent; });
|
||||
|
||||
|
||||
var updateProgressBarTask = new Task(() =>
|
||||
{
|
||||
while (isDownloading)
|
||||
{
|
||||
pbar.Update(c_progress);
|
||||
if (c_progress == 100f)
|
||||
break;
|
||||
Thread.Sleep(500);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
new Thread(updateProgressBarTask.Start).Start();
|
||||
await DownloadFileAsync(URL, location, progress);
|
||||
|
||||
|
||||
c_progress = pbar.Max;
|
||||
pbar.Update(100f);
|
||||
isDownloading = false;
|
||||
}
|
||||
|
||||
public static async Task DownloadFileNoProgressAsync(string URL, string location)
|
||||
{
|
||||
IProgress<float> progress = new Progress<float>();
|
||||
await DownloadFileAsync(URL, location, progress);
|
||||
await DownloadFileAsync(URl, location, progress, null);
|
||||
}
|
||||
|
||||
public static async Task<VersionString?> GetVersionOfPackageFromWeb(string pakName)
|
||||
|
||||
Reference in New Issue
Block a user