/// <summary>
        /// On click 'Update package' callback.
        /// </summary>
        public void UpdateClick()
        {
            Debug.Log(kHeader, "[UpdateClick]");
            var selectedPackage = GetSelectedPackage();

            if (selectedPackage.source == PackageSource.Git)
            {
                string packageId = selectedPackage.packageId;
                string url       = PackageUtils.GetRepoUrl(packageId);
#if UNITY_2019_3_OR_NEWER
                string refName = GetSelectedVersion().packageInfo.git.revision;
#else
                string refName       = GetSelectedVersion().VersionId.Split('@')[1];
                var    originRefName = refName;

                // Find correct reference (branch or tag) name.
                while (!AvailableVersions.GetVersions(selectedPackage.name, url).Any(x => x.refName == refName))
                {
                    var index = refName.IndexOf('-');
                    if (index < 0 || refName.Length < 1)
                    {
                        throw new Exception($"Cannot install '{packageId}'. The branch or tag is not found in repository.");
                    }
                    refName = refName.Substring(index + 1);
                }
#endif
                PackageUtils.UninstallPackage(selectedPackage.name);
                PackageUtils.InstallPackage(selectedPackage.name, url, refName);
            }
            else
            {
                packageDetails.UpdateClick();
            }
        }
        void onClick_FindVersions()
        {
            root.SetEnabled(false);
            EnableVersionContainer(false);

            var repoUrl = GetRepoUrl(repoUrlText.value, subDirText.value);

            AvailableVersions.Clear(repoUrl: repoUrl);
            AvailableVersionExtensions.UpdateAvailableVersions(repoUrl: repoUrl, callback: exitCode =>
            {
                bool success = exitCode == 0;
                root.SetEnabled(true);
                EnableVersionContainer(success);
                findVersionsError.visible = !success;
            });
        }
        static void OnResultCreated(string file)
        {
            if (string.IsNullOrEmpty(file) || Path.GetExtension(file) != ".json" || !File.Exists(file))
            {
                return;
            }


            try
            {
                var text = File.ReadAllText(file, System.Text.Encoding.UTF8);
                AvailableVersions.AddVersions(JsonUtility.FromJson <ResultInfo>(text).versions);
                File.Delete(file);
            }
            catch (Exception ex)
            {
                Debug.Exception(kHeader, ex);
            }
        }
Example #4
0
        /// <summary>
        /// Update all infomations of git packages.
        /// </summary>
        public static void UpdateGitPackageVersions()
        {
            bool changed = false;

            // Start update task.
            foreach (var package in PackageExtensions.GetGitPackages())
            {
                var pInfo    = package.GetInstalledVersion().GetPackageInfo();
                var repoUrl  = PackageUtils.GetRepoUrl(pInfo.packageId);
                var versions = AvailableVersions.GetVersions(package.GetName(), repoUrl);
                Debug.Log(kHeader, $"[UpdateGitPackageVersions] {pInfo.packageId} => {package.GetName()}, {repoUrl}, {versions.Count()}");
                changed = UpdatePackageVersions(package, versions) | changed;
            }

            if (changed)
            {
                UpdatePackageCollection();
            }
        }
        void onClick_SelectVersions()
        {
            var menu = new GenericMenu();

            GenericMenu.MenuFunction2 callback = (v) =>
            {
                var version = v as AvailableVersion;
                currentVersion           = version;
                versionSelectButton.text = version.refNameText;
                EnablePackageContainer(true, version.packageName);
            };

            var repoUrl = GetRepoUrl(repoUrlText.value, subDirText.value);

            foreach (var version in AvailableVersions.GetVersions(repoUrl: repoUrl).OrderByDescending(v => v.version))
            {
                var text = version.refNameText;
                menu.AddItem(new GUIContent(text), versionSelectButton.text == text, callback, version);
            }

            menu.DropDown(versionSelectButton.worldBound);
        }