/// <summary> /// Tries to install a plugin from 'path', throws an exception on error. /// </summary> internal static PackageDef InstallPluginPackage(string target, string path) { checkExtension(path); checkFileExists(path); var package = PackageDef.FromPackage(path); var destination = package.IsSystemWide() ? PackageDef.SystemWideInstallationDirectory : target; try { if (Path.GetExtension(path).ToLower().EndsWith("tappackages")) // This is a bundle { var tempDir = Path.GetTempPath(); var bundleFiles = UnpackPackage(path, tempDir); foreach (var file in bundleFiles) { UnpackPackage(file, destination); } } else { UnpackPackage(path, destination); } } catch (Exception e) { log.Error($"Install failed to execute for '{package.Name}'."); tryUninstall(path, package, target); throw new Exception($"Failed to install package '{path}'.", e); } var pi = new PluginInstaller(); if (pi.ExecuteAction(package, "install", false, target) == ActionResult.Error) { log.Error($"Install package action failed to execute for '{package.Name}'."); tryUninstall(path, package, target); throw new Exception($"Failed to install package '{path}'."); } CustomPackageActionHelper.RunCustomActions(package, PackageActionStage.Install, new CustomPackageActionArgs(null, false)); return(package); }
internal bool RunCommand(string command, bool force, bool modifiesPackageFiles) { var verb = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(command.ToLower()) + "ed"; try { if (modifiesPackageFiles) { waitForPackageFilesFree(TapDir, PackagePaths); } if (cancellationToken.IsCancellationRequested) { log.Debug("Received abort while waiting for package files to be unlocked."); return(false); } double progressPercent = 10; OnProgressUpdate((int)progressPercent, ""); PluginInstaller pi = new PluginInstaller(); foreach (string fileName in PackagePaths) { PackageDef pkg = PackageDef.FromXml(fileName); OnProgressUpdate((int)progressPercent, string.Format("Running command '{0}' on '{1}'", command, pkg.Name)); Stopwatch timer = Stopwatch.StartNew(); var res = pi.ExecuteAction(pkg, command, force, TapDir); if (res == ActionResult.Error) { OnProgressUpdate(100, "Done"); return(false); } else if (res == ActionResult.NothingToDo) { log.Info(string.Format("Tried to {0} {1}, but there was nothing to do.", command, pkg.Name)); } else { log.Info(timer, string.Format("{1} {0} version {2}.", pkg.Name, verb, pkg.Version)); } progressPercent += (double)80 / PackagePaths.Count(); } OnProgressUpdate(90, ""); if (DoSleep) { Thread.Sleep(100); } OnProgressUpdate(100, "Done"); Thread.Sleep(50); // Let Eventhandler get the last OnProgressUpdate } catch (Exception ex) { OnError(ex); return(false); } new Installation(TapDir).AnnouncePackageChange(); return(true); }
/// <summary> /// Uninstalls a package. /// </summary> internal static void Uninstall(PackageDef package, string target) { var pi = new PluginInstaller(); pi.ExecuteAction(package, "uninstall", true, target); }