1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Plugin import - Overwrite existing folder if needed

Plugin import - Enable newly imported plugins straight away
This commit is contained in:
Robert 2021-06-09 22:10:34 +02:00
parent 2179c889a3
commit 496f0e9b74
2 changed files with 15 additions and 7 deletions

View File

@ -529,7 +529,7 @@ namespace Artemis.Core.Services
string targetDirectory = pluginInfo.PreferredPluginDirectory;
if (Directory.Exists(Path.Combine(pluginDirectory.FullName, targetDirectory)))
throw new ArtemisPluginException($"A directory for this plugin already exists {Path.Combine(pluginDirectory.FullName, targetDirectory)}");
Directory.Delete(Path.Combine(pluginDirectory.FullName, targetDirectory), true);
// Extract everything in the same archive directory to the unique plugin directory
DirectoryInfo directoryInfo = new(Path.Combine(pluginDirectory.FullName, targetDirectory));

View File

@ -55,6 +55,7 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins
if (!Items.Contains(pluginSettingsViewModel))
Items.Add(pluginSettingsViewModel);
}
foreach (PluginSettingsViewModel pluginSettingsViewModel in Items.ToList())
{
if (!instances.Contains(pluginSettingsViewModel))
@ -76,21 +77,28 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins
base.OnInitialActivate();
}
public void ImportPlugin()
public async Task ImportPlugin()
{
VistaOpenFileDialog dialog = new();
dialog.Filter = "ZIP files (*.zip)|*.zip";
dialog.Title = "Import Artemis plugin";
VistaOpenFileDialog dialog = new() {Filter = "ZIP files (*.zip)|*.zip", Title = "Import Artemis plugin"};
bool? result = dialog.ShowDialog();
if (result == true)
if (result != true)
return;
// Take the actual import off of the UI thread
await Task.Run(() =>
{
Plugin plugin = _pluginManagementService.ImportPlugin(dialog.FileName);
GetPluginInstances();
SearchPluginInput = plugin.Info.Name;
// Enable it via the VM to enable the prerequisite dialog
PluginSettingsViewModel pluginViewModel = Items.FirstOrDefault(i => i.Plugin == plugin);
if (pluginViewModel is {IsEnabled: false})
pluginViewModel.IsEnabled = true;
_messageService.ShowMessage($"Imported plugin: {plugin.Info.Name}");
}
});
}
public void GetPluginInstances()