public void handle_package_result(PackageResult packageResult, ChocolateyConfiguration config, CommandNameType commandName) { var pkgInfo = _packageInfoService.get_package_information(packageResult.Package); if (config.AllowMultipleVersions) { pkgInfo.IsSideBySide = true; } if (config.Information.PlatformType == PlatformType.Windows) { if (!config.SkipPackageInstallProvider) { var before = _registryService.get_installer_keys(); var powerShellRan = _powershellService.install(config, packageResult); if (powerShellRan) { //todo: prevent reboots } var difference = _registryService.get_differences(before, _registryService.get_installer_keys()); if (difference.RegistryKeys.Count != 0) { //todo v1 - determine the installer type and write it to the snapshot //todo v1 - note keys passed in pkgInfo.RegistrySnapshot = difference; var key = difference.RegistryKeys.FirstOrDefault(); if (key != null && key.HasQuietUninstall) { pkgInfo.HasSilentUninstall = true; } } } if (packageResult.Success) { _shimgenService.install(config, packageResult); } } else { this.Log().Info(ChocolateyLoggers.Important, () => " Skipping Powershell and shimgen portions of the install due to non-Windows."); } _packageInfoService.save_package_information(pkgInfo); ensure_bad_package_path_is_clean(config, packageResult); if (!packageResult.Success) { this.Log().Error(ChocolateyLoggers.Important, "{0} {1} not successful.".format_with(packageResult.Name, commandName.to_string())); handle_unsuccessful_install(config, packageResult); return; } this.Log().Info(ChocolateyLoggers.Important, " {0} has been {1}ed successfully.".format_with(packageResult.Name, commandName.to_string())); }
public void set_pin(IPackageManager packageManager, ChocolateyConfiguration config) { var versionUnspecified = string.IsNullOrWhiteSpace(config.Version); SemanticVersion semanticVersion = versionUnspecified ? null : new SemanticVersion(config.Version); IPackage installedPackage = packageManager.LocalRepository.FindPackage(config.PinCommand.Name, semanticVersion); if (installedPackage == null) { throw new ApplicationException("Unable to find package named '{0}'{1} to pin. Please check to ensure it is installed.".format_with(config.PinCommand.Name, versionUnspecified ? "" : " (version '{0}')".format_with(config.Version))); } var pkgInfo = _packageInfoService.get_package_information(installedPackage); pkgInfo.IsPinned = config.PinCommand.Command == PinCommandType.add; _packageInfoService.save_package_information(pkgInfo); }
public virtual void set_pin(ChocolateyConfiguration config) { var addingAPin = config.PinCommand.Command == PinCommandType.add; var versionUnspecified = string.IsNullOrWhiteSpace(config.Version); List <IPackage> packages = new List <IPackage>(); // package exists in registry var confList = config.deep_copy(); confList.Input = confList.PinCommand.Name; confList.QuietOutput = true; packages = _packageService.list_run(confList).Select(x => x.Package).ToList(); if (packages.Count == 0) { throw new ApplicationException("Unable to find package named '{0}'{1} to pin. Please check to ensure it is installed.".format_with(config.PinCommand.Name, versionUnspecified ? "" : " (version '{0}')".format_with(config.Version))); } foreach (var package in packages) { var pkgInfo = _packageInfoService.get_package_information(package); bool changeMessage = pkgInfo.IsPinned != addingAPin; if (package is RegistryPackage regp) { regp.RegistryKey.IsPinned = addingAPin; _registryService.set_key_values(regp.RegistryKey, nameof(RegistryApplicationKey.IsPinned)); } else { pkgInfo.IsPinned = addingAPin; _packageInfoService.save_package_information(pkgInfo); } if (changeMessage) { this.Log().Warn("Successfully {0} a pin for {1} v{2}.".format_with(addingAPin ? "added" : "removed", pkgInfo.Package.Id, pkgInfo.Package.Version.to_string())); } else { this.Log().Warn(NO_CHANGE_MESSAGE); } } }
public virtual void set_pin(IPackageManager packageManager, ChocolateyConfiguration config) { var addingAPin = config.PinCommand.Command == PinCommandType.add; this.Log().Info("Trying to {0} a pin for {1}".format_with(config.PinCommand.Command.to_string(), config.PinCommand.Name)); var versionUnspecified = string.IsNullOrWhiteSpace(config.Version); SemanticVersion semanticVersion = versionUnspecified ? null : new SemanticVersion(config.Version); IPackage installedPackage = packageManager.LocalRepository.FindPackage(config.PinCommand.Name, semanticVersion); if (installedPackage == null) { var pathResolver = packageManager.PathResolver as ChocolateyPackagePathResolver; if (pathResolver != null) { pathResolver.UseSideBySidePaths = true; installedPackage = packageManager.LocalRepository.FindPackage(config.PinCommand.Name, semanticVersion); } if (installedPackage == null) { throw new ApplicationException("Unable to find package named '{0}'{1} to pin. Please check to ensure it is installed.".format_with(config.PinCommand.Name, versionUnspecified ? "" : " (version '{0}')".format_with(config.Version))); } } var pkgInfo = _packageInfoService.get_package_information(installedPackage); bool changeMessage = pkgInfo.IsPinned != addingAPin; pkgInfo.IsPinned = addingAPin; _packageInfoService.save_package_information(pkgInfo); if (changeMessage) { this.Log().Warn("Successfully {0} a pin for {1} v{2}.".format_with(addingAPin ? "added" : "removed", pkgInfo.Package.Id, pkgInfo.Package.Version.to_string())); } else { this.Log().Warn(NO_CHANGE_MESSAGE); } }
public void handle_package_result(PackageResult packageResult, ChocolateyConfiguration config, CommandNameType commandName) { var pkgInfo = _packageInfoService.get_package_information(packageResult.Package); if (config.AllowMultipleVersions) { pkgInfo.IsSideBySide = true; } if (packageResult.Success && config.Information.PlatformType == PlatformType.Windows) { if (!config.SkipPackageInstallProvider) { var before = _registryService.get_installer_keys(); var powerShellRan = _powershellService.install(config, packageResult); if (powerShellRan) { // we don't care about the exit code if (config.Information.PlatformType == PlatformType.Windows) { CommandExecutor.execute_static("shutdown", "/a", config.CommandExecutionTimeoutSeconds, _fileSystem.get_current_directory(), (s, e) => { }, (s, e) => { }, false); } } var difference = _registryService.get_differences(before, _registryService.get_installer_keys()); if (difference.RegistryKeys.Count != 0) { //todo v1 - determine the installer type and write it to the snapshot //todo v1 - note keys passed in pkgInfo.RegistrySnapshot = difference; var key = difference.RegistryKeys.FirstOrDefault(); if (key != null && key.HasQuietUninstall) { pkgInfo.HasSilentUninstall = true; } } } _configTransformService.run(packageResult, config); pkgInfo.FilesSnapshot = _filesService.capture_package_files(packageResult, config); if (packageResult.Success) { _shimgenService.install(config, packageResult); } } else { if (config.Information.PlatformType != PlatformType.Windows) { this.Log().Info(ChocolateyLoggers.Important, () => " Skipping Powershell and shimgen portions of the install due to non-Windows."); } } if (packageResult.Success) { handle_extension_packages(config, packageResult); } _packageInfoService.save_package_information(pkgInfo); ensure_bad_package_path_is_clean(config, packageResult); if (!packageResult.Success) { this.Log().Error(ChocolateyLoggers.Important, "The {0} of {1} was NOT successful.".format_with(commandName.to_string(), packageResult.Name)); handle_unsuccessful_operation(config, packageResult, movePackageToFailureLocation: true, attemptRollback: true); return; } remove_rollback_if_exists(packageResult); this.Log().Info(ChocolateyLoggers.Important, " The {0} of {1} was successful.".format_with(commandName.to_string(), packageResult.Name)); }