Ejemplo n.º 1
0
        protected override bool TriggerAction(IPackageVersion version)
        {
            var packagesToUninstall = m_PackageDatabase.GetCustomizedDependencies(version, true);

            if (!packagesToUninstall.Any())
            {
                return(false);
            }

            var packageNameAndVersions = string.Join("\n\u2022 ",
                                                     packagesToUninstall.Select(package => $"{package.displayName} - {package.versions.lifecycleVersion.version}").ToArray());
            var message = packagesToUninstall.Length == 1 ?
                          string.Format(
                L10n.Tr("Are you sure you want to reset this {0}?\nThe following included package will reset to the required version:\n\u2022 {1}"),
                version.package.GetDescriptor(), packageNameAndVersions) :
                          string.Format(
                L10n.Tr("Are you sure you want to reset this {0}?\nThe following included packages will reset to their required versions:\n\u2022 {1}"),
                version.package.GetDescriptor(), packageNameAndVersions);

            if (!m_Application.DisplayDialog(L10n.Tr("Unity Package Manager"), message, L10n.Tr("Continue"), L10n.Tr("Cancel")))
            {
                return(false);
            }

            m_PageManager.SetPackagesUserUnlockedState(packagesToUninstall.Select(p => p.uniqueId), false);
            m_PackageDatabase.ResetDependencies(version, packagesToUninstall);

            PackageManagerWindowAnalytics.SendEvent("reset", version?.uniqueId);
            return(true);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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);
        }