/// <summary>Uninstall <paramref name="pluginInstance" />. The plugin will be stopped if it is running.</summary> /// <param name="pluginInstance">The plugin to be uninstalled</param> /// <returns></returns> /// <exception cref="ArgumentNullException"></exception> /// <exception cref="ArgumentException"> /// When <paramref name="pluginInstance" /> is a Development /// plugin /// </exception> public async Task <bool> UninstallPluginAsync(TPluginInstance pluginInstance) { if (pluginInstance == null) { throw new ArgumentNullException(nameof(pluginInstance)); } if (pluginInstance.IsDevelopment) { throw new ArgumentException($"Cannot uninstall a development plugin"); } if (await StopPlugin(pluginInstance) == false) { LogAdapter.Warning($"Failed to stop plugin {pluginInstance.Package.Id}, aborting uninstallation."); return(false); } bool success; using (await pluginInstance.Lock.LockAsync()) using (await PMLock.WriterLockAsync()) { success = await PackageManager.UninstallAsync(pluginInstance.Package); if (success) { AllPluginsInternal.Remove(pluginInstance); } } return(success); }
/// <summary> /// Attempts to update plugin <paramref name="packageId" />. If no /// <paramref name="version" /> is specified, the latest available version will be installed. /// </summary> /// <param name="packageId">The plugin package id to update</param> /// <param name="version">Optional version to install</param> /// <param name="allowPrereleaseVersions">Whether to include pre-release versions</param> /// <param name="cancellationToken"></param> /// <returns>Success of operation</returns> /// <exception cref="ArgumentException"><paramref name="packageId" /> is empty</exception> /// <exception cref="ArgumentException">Plugin <paramref name="packageId" /> is not installed</exception> /// <exception cref="ArgumentNullException"></exception> public async Task <bool> UpdatePluginAsync( string packageId, NuGetVersion version = null, bool allowPrereleaseVersions = false, CancellationToken cancellationToken = default) { var pluginInstance = AllPlugins.FirstOrDefault(pi => pi.Package.Id == packageId); if (await StopPlugin(pluginInstance) == false) { LogAdapter.Warning($"Failed to stop plugin {packageId}, aborting update."); return(false); } using (await PMLock.WriterLockAsync()) { var success = await PackageManager.UpdateAsync( packageId, version, allowPrereleaseVersions, cancellationToken); UISynchronizationContext.Send(() => PackageManager.FindInstalledPluginById(packageId)?.RaiseVersionChanged()); return(success); } }