Пример #1
0
        internal static string GenerateUniquePackageDisplayName(string displayName)
        {
            displayName = Regex.Replace(displayName, $@"[{Regex.Escape(EditorUtility.GetInvalidFilenameChars())}]", "_");
            var allPackagesDisplayNames = PackageInfo.GetAll().Where(info => info.type != "module").Select(info => info.displayName);

            return(FindUnique(displayName, allPackagesDisplayNames, " "));
        }
Пример #2
0
            public string GetVersionToUpgradeTo(PackageInfo packageInfo)
            {
                string newVersion;

                switch (UpdateType)
                {
                case PackageUpdateType.Verified:
                {
                    newVersion =
                                                        #if UNITY_2019_3_OR_NEWER
                        packageInfo.versions.verified;
                                                        #else
                        packageInfo.versions.recommended;
                                                #endif
                    if (string.IsNullOrEmpty(newVersion))
                    {
                        newVersion = packageInfo.versions.latestCompatible;
                    }
                    break;
                }

                case PackageUpdateType.Latest:
                    newVersion = packageInfo.versions.latestCompatible;
                    break;

                default:
                    throw new NotImplementedException($"{UpdateType} has not been implemented.");
                }

                return(newVersion);
            }
        public static void UpdatePackage()
        {
            float progress = 0F;

            PackageInfo info = PackageInfo.FindForAssembly(typeof(NativePackageUpdate).Assembly);

            RemoveRequest removeRequest = Client.Remove(info.packageId);

            while (!removeRequest.IsCompleted)
            {
                EditorUtility.DisplayProgressBar(_titleLabel, _infoLabel, Mathf.Clamp(progress += 0.01F, 0F, .5F));
                Thread.Sleep(100);
            }
            EditorUtility.DisplayProgressBar(_titleLabel, _infoLabel, .5F);

            AddRequest addRequest = Client.Add(info.packageId);

            while (!addRequest.IsCompleted)
            {
                EditorUtility.DisplayProgressBar(_titleLabel, _infoLabel, Mathf.Clamp(progress += 0.01F, .5F, 1F));
                Thread.Sleep(100);
            }
            EditorUtility.DisplayProgressBar(_titleLabel, _infoLabel, 1F);
            Thread.Sleep(100);

            EditorUtility.ClearProgressBar();
        }
        /// <summary>
        /// Called by the Package Manager UI when the package selection changed.
        /// </summary>
        /// <param name="packageInfo">The newly selected package information (can be null)</param>
        public void OnPackageSelectionChange(PackageInfo packageInfo)
        {
            if (packageInfo == null)
            {
                return;
            }

            Debug.Log(kHeader, $"OnPackageSelectionChange {packageInfo.packageId}");
            if (packageInfo.source == PackageSource.Git)
            {
                // Show remove button for git package.
                var removeButton = root.Q <Button>("remove");
                UIUtils.SetElementDisplay(removeButton, true);
                removeButton.SetEnabled(true);

                // Show git tag.
                var tagGit = root.Q("tag-git");
                UIUtils.SetElementDisplay(tagGit, true);
            }

            // Show hosting service logo.
            var hostButton = root.Q <Button>("hostButton");

            if (hostButton != null)
            {
                hostButton.style.backgroundImage = GetHostLogo(packageInfo.packageId);
                hostButton.visible = packageInfo.source == PackageSource.Git;
            }
        }
Пример #5
0
        void ExtractCurrentXiaomiPackageInfo(RequestQueueItem request)
        {
            ListRequest currentPackageListRequest = (ListRequest)request.Request;

            if (currentPackageListRequest.Status == StatusCode.Success)
            {
                System.Console.WriteLine("Current xiaomi package version is " +
                                         (string.IsNullOrEmpty(currentXiaomiPackageVersion)
                        ? "empty"
                        : currentXiaomiPackageVersion));

                if (currentPackageListRequest.IsCompleted && string.IsNullOrEmpty(currentXiaomiPackageVersion))
                {
                    PackageManager.PackageInfo info = currentPackageListRequest.Result.FirstOrDefault(p => p.name == xiaomiPackageName);
                    if (info != null)
                    {
                        currentXiaomiPackageVersion = info.version;
                    }
                    if (!string.IsNullOrEmpty(currentXiaomiPackageVersion))
                    {
                        xiaomiPackageInstalled = true;
                    }
                }
                currentVersionInitialized = true;
            }
            else
            {
                System.Console.WriteLine(currentPackageListRequest + " failed with error: " +
                                         currentPackageListRequest.Error);
            }
        }
Пример #6
0
        /// <summary>
        /// Called by the Package Manager UI when the package selection changed.
        /// </summary>
        /// <param name="packageInfo">The newly selected package information (can be null)</param>
        public void OnPackageSelectionChange(PackageInfo packageInfo)
        {
            InitializeUI();
            if (!initialized || packageInfo == null)
            {
                return;
            }

            if (packageInfo.source == PackageSource.Git)
            {
                // Show remove button for git package.
                var removeButton = root.Q <Button>("remove");
                UIUtils.SetElementDisplay(removeButton, true);
                removeButton.SetEnabled(true);

                // Show git tag.
                var tagGit = root.Q("tag-git");
                UIUtils.SetElementDisplay(tagGit, true);
            }

            // Show hosting service logo.
            var host       = Settings.GetHostData(packageInfo.packageId);
            var hostButton = root.Q <Button>("hostButton");

            hostButton.style.backgroundImage = host.Logo;
            hostButton.visible = packageInfo.source == PackageSource.Git;
        }
Пример #7
0
 /// <summary>
 /// Called by the Package Manager UI when a package is added or updated.
 /// </summary>
 /// <param name="packageInfo">The package information</param>
 public void OnPackageAddedOrUpdated(PackageInfo packageInfo)
 {
     if (_detailControls != null)
     {
         _detailControls.SetEnabled(true);
     }
 }
        public string GetLatestVersion(UnityEditor.PackageManager.PackageInfo info)
        {
            if (info.source == PackageSource.Git)
            {
                return(info.packageId);
            }
            else
            {
                string latest = "";

#if UNITY_2019_1_OR_NEWER
                if (string.IsNullOrEmpty(info.versions.verified))
                {
                    latest = info.versions.latestCompatible;
                }
                else
                {
                    latest = info.versions.verified;
                }
#else
                latest = info.versions.latestCompatible;
#endif

                return(latest);
            }
        }
Пример #9
0
 /// <summary>
 /// Called by the Package Manager UI when a package is removed.
 /// </summary>
 /// <param name="packageInfo">The package information</param>
 public void OnPackageRemoved(PackageInfo packageInfo)
 {
     if (_detailControls != null)
     {
         _detailControls.SetEnabled(true);
     }
 }
Пример #10
0
        static void RunGetVersion(
            PackageManager.Requests.ListRequest listRequest,
            Action <string> onGetVersionCompleted)
        {
            EditorDispatcher.Dispatch(() =>
            {
                if (!listRequest.IsCompleted)
                {
                    RunGetVersion(listRequest, onGetVersionCompleted);
                    return;
                }

                string pluginVersion = string.Empty;

                if (listRequest.Status == PackageManager.StatusCode.Success &&
                    listRequest.Result != null)
                {
                    PackageManager.PackageInfo collabPackage = listRequest.Result
                                                               .FirstOrDefault(package => package.name == mCollabPackageName);

                    if (collabPackage != null)
                    {
                        pluginVersion = collabPackage.version;
                    }
                }

                onGetVersionCompleted.Invoke(pluginVersion);
            });
        }
Пример #11
0
        private static void CheckVersion(UnityEditor.PackageManager.PackageInfo p)
        {
            SRP_VERSION = p.version.Replace("-preview", string.Empty);
            curVersion  = new System.Version(SRP_VERSION);

            LATEST_COMPATIBLE_VERSION = latestVersion.ToString();
            latestVersion             = new System.Version(p.versions.latestCompatible);

            MIN_SRP_VERSION = minVersion.ToString();

            //Within range of minimum and maximum versions
            if (curVersion >= minVersion && curVersion <= maxVersion)
            {
                VersionStatus = Version.Compatible;
            }
            //Outside range of compatible versions
            if (curVersion < minVersion || curVersion > maxVersion)
            {
                VersionStatus = Version.Incompatible;
            }
            if (curVersion < minVersion)
            {
                VersionStatus = Version.Outdated;
            }

            //HDRP isn't supported from 2018.3+ and will not be
            if (p.name == HDRP_PACKAGE_ID)
            {
                VersionStatus = Version.Incompatible;
            }

#if SCPE_DEV
            Debug.Log("<b>SRP Installation</b> " + p.name + " " + SRP_VERSION + " Installed (" + VersionStatus + ")");
#endif
        }
Пример #12
0
 private string SanitizePackageId(UnityEditor.PackageManager.PackageInfo packageInfo)
 {
     if (packageInfo.source == UnityEditor.PackageManager.PackageSource.Registry)
     {
         return(packageInfo.packageId);
     }
     return(packageInfo.name + "@" + Enum.GetName(typeof(UnityEditor.PackageManager.PackageSource), packageInfo.source).ToLower());
 }
        private void TryGetXrsdkRevisionDate(PackageInfo oculusXrsdkPckg)
        {
#if OCULUS_SDK
            XrsdkRevisionDate =
                oculusXrsdkPckg.datePublished != null ?
                ((DateTime)oculusXrsdkPckg.datePublished).ToString("s", DateTimeFormatInfo.InvariantInfo) : "unavailable";
#endif
        }
Пример #14
0
        private static bool IsVersionInstalledOrSupported(PackageInfo packageInfo, string version)
        {
            List <string> packageVersions = packageInfo.versions.all.ToList();

            int currentVersion = packageVersions.IndexOf(packageInfo.version);
            int targetVersion  = packageVersions.IndexOf(version);

            return(currentVersion >= targetVersion);
        }
Пример #15
0
 public void OnPackageSelectionChange(UnityEditor.PackageManager.PackageInfo packageInfo)
 {
     if (packageInfo == this.packageInfo)
     {
         return;
     }
     this.packageInfo = packageInfo;
     this.packagePath = System.IO.Path.GetFullPath(packageInfo.assetPath);
 }
Пример #16
0
 public void OnPackageRemoved(PackageInfo packageInfo)
 {
     CheckList(exist => { existUPMTool = exist; if (exist)
                          {
                              HideButton();
                          }
                          else
                          {
                              ShowButton();
                          } });
 }
Пример #17
0
        public static bool CanGenerateResolver(string assetPath)
        {
            if (File.Exists(assetPath))
            {
                PackageInfo packageInfo = PackageInfo.FindForAssetPath(assetPath);

                return(packageInfo == null || packageInfo.source == PackageSource.Embedded);
            }

            return(false);
        }
Пример #18
0
 private void HandleRegisryURP(UnityEditor.PackageManager.PackageInfo package)
 {
     if (GUILayout.Button("Apply Grass Shaders to URP"))
     {
         string targetPath = "Packages/" + Path.GetFileName(package.resolvedPath);
         AssetsManager.CopyDirectory(package.resolvedPath, targetPath);
         string destFilePath = targetPath + "/Shaders/Terrain/WavingGrassPasses.hlsl";
         CopyUrpTemplatFile(destFilePath);
         AssetDatabase.Refresh();
     }
 }
Пример #19
0
 public void OnPackageSelectionChange(PackageInfo packageInfo)
 {
     if (!existUPMTool && packageInfo.displayName == DisplayName)
     {
         ShowButton();
     }
     else
     {
         HideButton();
     }
 }
Пример #20
0
        internal static AssetDescriptor CreateInstanceFromPackageInfo(PackageInfo info)
        {
            AssetDescriptor desc = ScriptableObject.CreateInstance <AssetDescriptor>();

            desc.name             = info.displayName;
            desc.id               = info.packageId;
            desc.unityPackagePath = info.assetPath;
            desc.packageType      = AssetDescriptor.PackageType.Package;

            return(desc);
        }
        public static bool ShouldFormat(FormatContext formatContext, NPath pathToFormat)
        {
            // files only please
            if (!pathToFormat.FileExists())
            {
                return(false);
            }

            var fullPath = Path.GetFullPath(pathToFormat).ToNPath();

            var libraryFolder = formatContext.BaseDir.Combine("Library");

            // ignore files under Library folder (for instance files under Library/PackageCache are Git/npm cached packages, whence immutable)
            if (fullPath.IsChildOf(libraryFolder))
            {
                return(false);
            }

            if (!fullPath.IsChildOf(formatContext.BaseDir))
            {
#if UNITY_2019_2_OR_NEWER
                // Ignore any file that is not a child of the project root or a local package (which can live anywhere in the file system)
                var p = PackageInfo.FindForAssetPath(pathToFormat.ToString(SlashMode.Forward));
                if (p == null || p.source != PackageSource.Local)
                {
                    return(false);
                }
#else
                // can't find the package source of a given asset path until 2019.2
                return(false);
#endif
            }

            if (lastFormattedAssets != null && lastFormattedAssets.TryGetValue(fullPath, out var lastTimestamp))
            {
                var currentTimeStamp = File.GetLastWriteTime(fullPath).Ticks;

                // if timestamp is different, format (user may have reverted some changes through a VCS which resets the timestamp).
                var shouldFormat = lastTimestamp != currentTimeStamp;
                LogFormatDecision(fullPath, shouldFormat, formatContext.Logger, lastTimestamp, currentTimeStamp);

                if (!shouldFormat)
                {
                    return(false);
                }
                return(shouldFormat);
            }

            return(true);
        }
Пример #22
0
//----------------------------------------------------------------------------------------------------------------------

        static void OnPackagesRegistered(PackageRegistrationEventArgs packageRegistrationEventArgs)
        {
            PackageInfo curPackage = packageRegistrationEventArgs.removed.FindPackage(StreamingImageSequenceConstants.PACKAGE_NAME);

            if (null == curPackage)
            {
                curPackage = packageRegistrationEventArgs.changedTo.FindPackage(StreamingImageSequenceConstants.PACKAGE_NAME);
            }

            if (null == curPackage)
            {
                return;
            }
            EditorRestartMessageNotifier.RequestNotificationOnLoad(curPackage);
        }
Пример #23
0
    //Add latest version of WindowsMR package with blocklist for more version control
    static void AddLatestCompatibleVersion(UnityEditor.PackageManager.PackageInfo packageInfo)
    {
        if (packageInfo == null)
        {
            Debug.LogErrorFormat("Unable to set latest package version for package '{0}'.", WINDOWS_MR_PACKAGE_NAME);
            return;
        }

        var compatibleVersions = packageInfo.versions.compatible.Except(sBlockList);
        var latestCompatible   = compatibleVersions.Select(versionString => new Version(versionString)).Max();

        var versionedPackageName = string.Format("{0}@{1}", WINDOWS_MR_PACKAGE_NAME, latestCompatible);

        Client.Add(versionedPackageName);
    }
Пример #24
0
        private static void UpdatePackageVersion(UnityEditor.PackageManager.PackageInfo package, string version)
        {
            if (package.version != version)
            {
                string manifest = Path.Combine(package.resolvedPath, "package.json");
                if (File.Exists(manifest))
                {
                    JObject jManifest = JObject.Parse(File.ReadAllText(manifest));
                    jManifest["version"] = version;

                    File.WriteAllText(manifest, jManifest.ToString());

                    Debug.Log("Updated group version for " + package.displayName);
                }
            }
        }
Пример #25
0
        private static bool IsPackageInstalled(string package, string version)
        {
            if (IsPackageInstalled(package))
            {
                if (string.IsNullOrEmpty(version))
                {
                    return(true);
                }

                PackageInfo packageInfo = Packages.First(pi => pi.name == package);

                return(IsVersionInstalledOrSupported(packageInfo, version));
            }

            return(false);
        }
Пример #26
0
        private static string GenerateUniqueSanitizedPackageName(string organization, string name, string defaultName)
        {
            var sanitizedOrganization = SanitizeName(organization, k_DefaultOrganizationName, @"[^a-zA-Z\-_\d]", "").ToLower(CultureInfo.InvariantCulture);
            var sanitizedName         = SanitizeName(name, defaultName, @"[^a-zA-Z\-_\d]", "").ToLower(CultureInfo.InvariantCulture);

            var packageName = "com." + sanitizedOrganization + "." + sanitizedName;

            if (packageName.Length > k_MaxPackageNameLength)
            {
                packageName = packageName.Substring(0, k_MaxPackageNameLength);
            }

            packageName = packageName.TrimEnd('.');
            var allPackagesNames = PackageInfo.GetAll().Select(info => info.name);

            return(FindUnique(packageName, allPackagesNames));
        }
Пример #27
0
 private void HandleEmbeddedURP(UnityEditor.PackageManager.PackageInfo package)
 {
     EditorGUILayout.LabelField("URP Grass is applied.");
     if (GUILayout.Button("Reapply Grass Shaders to URP"))
     {
         string destFilePath = package.resolvedPath + "/Shaders/Terrain/WavingGrassPasses.hlsl";
         CopyUrpTemplatFile(destFilePath);
         AssetDatabase.Refresh();
     }
     if (GUILayout.Button("Reset URP"))
     {
         string targetPath = "Library/PackageCache/" + Path.GetFileName(package.resolvedPath);
         AssetsManager.CopyDirectory(package.resolvedPath, targetPath);
         Directory.Delete(package.resolvedPath, true);
         AssetDatabase.Refresh();
     }
 }
Пример #28
0
        public IEnumerator GetPackageInfo(string packageName)
        {
            pi = null;
            var op = Client.List();

            while (!op.IsCompleted)
            {
                yield return(null);
            }

            if (op.Status == StatusCode.Success)
            {
                pi = op.Result.FirstOrDefault(x => x.name == packageName);
            }

            Assert.IsNotNull(pi, string.Format("{0} is not installed.", packageName));
        }
        private void AddRegistryPackage(UnityEditor.PackageManager.PackageInfo info)
        {
            try
            {
                SemVer latestVersion  = SemVer.Parse(GetLatestVersion(info));
                SemVer currentVersion = SemVer.Parse(info.version);

                if (currentVersion < latestVersion)
                {
                    UpgradeablePackages.Add(info);
                }
            }
            catch (System.Exception)
            {
                Debug.LogError("Invalid version for package " + info.displayName + ". Current: " + info.version + ", Latest: " + GetLatestVersion(info));
            }
        }
Пример #30
0
        /// <summary>
        /// Called by the Package Manager UI when the package selection changed.
        /// </summary>
        /// <param name="packageInfo">The newly selected package information (can be null)</param>
        public void OnPackageSelectionChange(PackageInfo packageInfo)
        {
            InitializeUI();
            if (!_initialized || packageInfo == null || _packageInfo == packageInfo)
            {
                return;
            }

            _packageInfo = packageInfo;

            var isGit = packageInfo.source == PackageSource.Git;

            UIUtils.SetElementDisplay(_gitDetailActoins, isGit);
            UIUtils.SetElementDisplay(_originalDetailActions, !isGit);
            UIUtils.SetElementDisplay(_detailControls.Q("", "popupField"), !isGit);
            UIUtils.SetElementDisplay(_updateButton, isGit);
            UIUtils.SetElementDisplay(_versionPopup, isGit);
            UIUtils.SetElementDisplay(_originalAddButton, false);
            UIUtils.SetElementDisplay(_addButton, true);

            if (isGit)
            {
                _updateButton.text = "Update to";
                _versionPopup.SetEnabled(false);
                _updateButton.SetEnabled(false);
                GitUtils.GetRefs(PackageUtils.GetRepoHttpUrl(_packageInfo.packageId), _refs, () =>
                {
                    _updateButton.SetEnabled(_currentRefName != _selectedRefName);
                    _versionPopup.SetEnabled(true);
                });

                SetVersion(_currentRefName);
                EditorApplication.delayCall += () =>
                {
                    UIUtils.SetElementDisplay(_detailControls.Q("updateCombo"), true);
                    UIUtils.SetElementDisplay(_detailControls.Q("remove"), true);
                    _detailControls.Q("remove").SetEnabled(true);
                }
                ;
                _currentHostData = Settings.GetHostData(_packageInfo.packageId);

                _hostingIcon.tooltip = "View on " + _currentHostData.Name;
                _hostingIcon.style.backgroundImage = EditorGUIUtility.isProSkin ? _currentHostData.LogoLight : _currentHostData.LogoDark;
            }
        }