Fixed Install/Remove plugin page in UI

This commit is contained in:
2024-05-26 02:05:06 +03:00
parent 5345515512
commit d3dd29f4bf
4 changed files with 72 additions and 14 deletions

View File

@@ -165,6 +165,12 @@ public class PluginManager
await ServerCom.DownloadFileAsync(dependency.DownloadLink, dependency.DownloadLocation, progress);
currentProgress += stepProgress;
}
PluginInfo pluginInfo = new PluginInfo(pluginData.Name,
pluginData.Version,
pluginData.Dependencies.Select(dep => dep.DownloadLocation).ToList());
await AppendPluginToDatabase(pluginInfo);
}

View File

@@ -23,6 +23,7 @@ public class InternalActionManager
if (loadedActions == null)
return;
foreach (var action in loadedActions)
Actions.TryAdd(action.ActionName, action);

View File

@@ -29,32 +29,45 @@
private void InitializeComponent()
{
dataGridView1 = new DataGridView();
labelInstalling = new Label();
((System.ComponentModel.ISupportInitialize)dataGridView1).BeginInit();
SuspendLayout();
//
// dataGridView1
//
dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView1.Dock = DockStyle.Fill;
dataGridView1.Dock = DockStyle.Top;
dataGridView1.Location = new Point(0, 0);
dataGridView1.Name = "dataGridView1";
dataGridView1.Size = new Size(800, 450);
dataGridView1.Size = new Size(800, 438);
dataGridView1.TabIndex = 0;
//
// labelInstalling
//
labelInstalling.AutoSize = true;
labelInstalling.Location = new Point(0, 441);
labelInstalling.Name = "labelInstalling";
labelInstalling.Size = new Size(67, 15);
labelInstalling.TabIndex = 1;
labelInstalling.Text = "Installing ...";
//
// PluginListWindow
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
ClientSize = new Size(800, 457);
Controls.Add(labelInstalling);
Controls.Add(dataGridView1);
Name = "PluginListWindow";
Text = "PluginListWindow";
((System.ComponentModel.ISupportInitialize)dataGridView1).EndInit();
ResumeLayout(false);
PerformLayout();
}
#endregion
private DataGridView dataGridView1;
private Label labelInstalling;
}
}

View File

@@ -1,4 +1,5 @@
using DiscordBotCore.Online;
using DiscordBotCore.Loaders;
using DiscordBotCore.Online;
namespace DiscordBotUI_Windows.WindowsForms
{
@@ -13,6 +14,8 @@ namespace DiscordBotUI_Windows.WindowsForms
private async Task PluginListWindowLoad()
{
labelInstalling.Visible = false;
var listOfPlugins = await DiscordBotCore.Application.CurrentApplication.PluginManager.GetPluginsList();
dataGridView1.Rows.Clear();
dataGridView1.Columns.Clear();
@@ -30,21 +33,56 @@ namespace DiscordBotUI_Windows.WindowsForms
bool isInstalled = await DiscordBotCore.Application.CurrentApplication.PluginManager.IsPluginInstalled(plugin.Name);
string isInstalledMessage = isInstalled ? "Installed" : "Not Installed";
int rowIndex = dataGridView1.Rows.Add(plugin.Name, plugin.Description, plugin.HasDependencies, plugin.Version, isInstalledMessage);
dataGridView1.Rows[rowIndex].Cells["Install"] = (new DataGridViewButtonCell()
dataGridView1.Rows[rowIndex].Cells["Install"] = new DataGridViewButtonCell()
{
Value = isInstalled ? "Installed" : "Install",
Value = isInstalled ? "Remove" : "Install",
Style = { BackColor = isInstalled ? System.Drawing.Color.LightGray : default }
});
if(isInstalled)
{
dataGridView1.Rows[rowIndex].Cells["Install"].Style.BackColor = System.Drawing.Color.LightGray;
};
}
dataGridView1.ReadOnly = true;
dataGridView1.CellContentClick += async (sender, e) =>
{
var senderGrid = (DataGridView)sender;
if (e.ColumnIndex == 5 && e.RowIndex >= 0)
{
var pluginName = (string)senderGrid.Rows[e.RowIndex].Cells["Name"].Value;
var isInstalled = (string)senderGrid.Rows[e.RowIndex].Cells["Install"].Value == "Remove";
if (isInstalled)
{
await DiscordBotCore.Application.CurrentApplication.PluginManager.MarkPluginToUninstall(pluginName);
dataGridView1.Rows[e.RowIndex].Cells["Install"] = new DataGridViewButtonCell()
{
Value = "Install",
Style = { BackColor = default }
};
}
else
{
labelInstalling.Visible = true;
labelInstalling.Text = "Installing " + pluginName;
var result = await DiscordBotCore.Application.CurrentApplication.PluginManager.GetPluginDataByName(pluginName);
await DiscordBotCore.Application.CurrentApplication.PluginManager.InstallPlugin(result!, null);
labelInstalling.Visible = false;
dataGridView1.Rows[e.RowIndex].Cells["Install"] = new DataGridViewButtonCell()
{
Value = "Remove",
Style = { BackColor = System.Drawing.Color.LightGray }
};
}
}
dataGridView1.Refresh();
dataGridView1.Update();
dataGridView1.ReadOnly = true;
};
}
}
}