public async Task InstallPlugin(PluginEntry plugin, IProgress <AsyncProgressEntry> progress = null, CancellationToken cancellation = default(CancellationToken)) { var destination = GetPluginDirectory(plugin.Id); try { plugin.IsInstalling = true; var data = await CmApiProvider.GetDataAsync($"plugins/get/{plugin.Id}", progress, cancellation); if (data == null || cancellation.IsCancellationRequested) { return; } await Task.Run(() => { if (Directory.Exists(destination)) { FileUtils.Recycle(destination); } using (var stream = new MemoryStream(data, false)) using (var archive = new ZipArchive(stream)) { archive.ExtractToDirectory(destination); } }, cancellation); if (cancellation.IsCancellationRequested) { return; } plugin.InstalledVersion = plugin.Version; File.WriteAllText(Path.Combine(destination, ManifestFileName), JsonConvert.SerializeObject(plugin)); if (plugin.IsEnabled) { PluginEnabled?.Invoke(this, new PluginEventArgs { PluginId = plugin.Id }); } } catch (Exception e) when(e.IsCancelled()) { } catch (Exception e) { NonfatalError.Notify(ToolsStrings.Plugins_CannotInstall, e); } finally { plugin.IsInstalling = false; } }
internal void OnPluginEnabled(PluginEntry plugin, bool value) { (value ? PluginEnabled : PluginDisabled)?.Invoke(this, new AppAddonEventHandlerArgs { PluginId = plugin.Id }); }
public void RemoveAddon(PluginEntry plugin) { throw new NotImplementedException(); }