protected override bool TriggerAction(IList <IPackageVersion> versions) { var title = string.Format(L10n.Tr("Removing {0} items"), versions.Count); var result = 0; if (!m_PackageManagerPrefs.skipMultiSelectRemoveConfirmation) { var message = L10n.Tr("Are you sure you want to remove these items?"); result = m_Application.DisplayDialogComplex(title, message, L10n.Tr("Remove"), L10n.Tr("Cancel"), L10n.Tr("Never ask")); } // Cancel if (result == 1) { return(false); } // Never ask if (result == 2) { m_PackageManagerPrefs.skipMultiSelectRemoveConfirmation = true; } m_PackageDatabase.Uninstall(versions.Select(v => v.package)); PackageManagerWindowAnalytics.SendEvent("uninstall", packageIds: versions.Select(v => v.uniqueId)); // After a bulk removal, we want to deselect them to avoid installing them back by accident. DeselectVersions(versions); return(true); }
protected override bool TriggerAction(IPackageVersion version) { IPackage[] packageToUninstall = null; if (version.HasTag(PackageTag.Feature)) { var customizedDependencies = m_PackageDatabase.GetCustomizedDependencies(version, true); if (customizedDependencies.Any()) { var packageNameAndVersions = string.Join("\n\u2022 ", customizedDependencies.Select(package => $"{package.displayName} - {package.versions.lifecycleVersion.version}").ToArray()); var title = string.Format(L10n.Tr("Installing {0}"), version.package.GetDescriptor()); var message = customizedDependencies.Length == 1 ? string.Format( L10n.Tr("This {0} includes a package version that is different from what's already installed. Would you like to reset the following package to the required version?\n\u2022 {1}"), version.package.GetDescriptor(), packageNameAndVersions) : string.Format( L10n.Tr("This {0} includes package versions that are different from what are already installed. Would you like to reset the following packages to the required versions?\n\u2022 {1}"), version.package.GetDescriptor(), packageNameAndVersions); var result = m_Application.DisplayDialogComplex("installPackageWithCustomizedDependencies", title, message, L10n.Tr("Install and Reset"), L10n.Tr("Cancel"), L10n.Tr("Install Only")); if (result == 1) // Cancel { return(false); } if (result == 0) // Install and reset { packageToUninstall = customizedDependencies; } } } if (packageToUninstall?.Any() == true) { m_PackageDatabase.InstallAndResetDependencies(version, packageToUninstall); PackageManagerWindowAnalytics.SendEvent("installAndReset", version.uniqueId); } else { m_PackageDatabase.Install(version); var installRecommended = version.package.versions.recommended == version ? "Recommended" : "NonRecommended"; var eventName = $"installNew{installRecommended}"; PackageManagerWindowAnalytics.SendEvent(eventName, version.uniqueId); } return(true); }
protected override bool TriggerAction(IPackageVersion version) { var installedVersion = version.package.versions.installed; var targetVersion = GetTargetVersion(version); if (installedVersion != null && !installedVersion.isDirectDependency && installedVersion != targetVersion) { var featureSetDependents = m_PackageDatabase.GetFeatureDependents(installedVersion); // if the installed version is being used by a Feature Set show the more specific // Feature Set dialog instead of the generic one if (featureSetDependents.Any()) { var message = string.Format(L10n.Tr("Changing a {0} that is part of a feature can lead to errors. Are you sure you want to proceed?"), version.package.GetDescriptor()); if (!m_Application.DisplayDialog(L10n.Tr("Warning"), message, L10n.Tr("Yes"), L10n.Tr("No"))) { return(false); } } else { var message = L10n.Tr("This version of the package is being used by other packages. Upgrading a different version might break your project. Are you sure you want to continue?"); if (!m_Application.DisplayDialog(L10n.Tr("Unity Package Manager"), message, L10n.Tr("Yes"), L10n.Tr("No"))) { return(false); } } } IPackage[] packageToUninstall = null; if (targetVersion.HasTag(PackageTag.Feature)) { var customizedDependencies = m_PackageDatabase.GetCustomizedDependencies(targetVersion, true); if (customizedDependencies.Any()) { var packageNameAndVersions = string.Join("\n\u2022 ", customizedDependencies.Select(package => $"{package.displayName} - {package.versions.lifecycleVersion.version}").ToArray()); var message = customizedDependencies.Length == 1 ? string.Format( L10n.Tr("This {0} includes a package version that is different from what's already installed. Would you like to reset the following package to the required version?\n\u2022 {1}"), version.package.GetDescriptor(), packageNameAndVersions) : string.Format( L10n.Tr("This {0} includes package versions that are different from what are already installed. Would you like to reset the following packages to the required versions?\n\u2022 {1}"), version.package.GetDescriptor(), packageNameAndVersions); var result = m_Application.DisplayDialogComplex(L10n.Tr("Unity Package Manager"), message, L10n.Tr("Install and Reset"), L10n.Tr("Cancel"), L10n.Tr("Install Only")); if (result == 1) // Cancel { return(false); } if (result == 0) // Install and reset { packageToUninstall = customizedDependencies; } } } if (packageToUninstall?.Any() == true) { m_PackageDatabase.InstallAndResetDependencies(targetVersion, packageToUninstall); PackageManagerWindowAnalytics.SendEvent("installAndReset", targetVersion?.uniqueId); } else { m_PackageDatabase.Install(targetVersion); var installRecommended = version.package.versions.recommended == targetVersion ? "Recommended" : "NonRecommended"; var eventName = $"installUpdate{installRecommended}"; PackageManagerWindowAnalytics.SendEvent(eventName, targetVersion?.uniqueId); } return(true); }