Exemplo n.º 1
0
        public AssetStorePackage(FetchedInfo fetchedInfo, UpmPackage package)
        {
            m_Errors    = new List <Error>();
            m_Progress  = PackageProgress.None;
            m_Type      = PackageType.AssetStore;
            m_Name      = package?.name ?? string.Empty;
            m_ProductId = fetchedInfo?.id.ToString();

            m_Images      = fetchedInfo?.images ?? new List <PackageImage>();
            m_Links       = fetchedInfo?.links ?? new List <PackageLink>();
            m_VersionList = new AssetStoreVersionList();

            m_UpmVersionList = package?.versionList as UpmVersionList ?? new UpmVersionList();
            foreach (var version in m_UpmVersionList.all.Cast <UpmPackageVersion>())
            {
                version.UpdateFetchedInfo(fetchedInfo);
            }

            if (string.IsNullOrEmpty(fetchedInfo?.id) || string.IsNullOrEmpty(fetchedInfo?.versionId))
            {
                AddError(new Error(NativeErrorCode.Unknown, "Invalid product details."));
            }
            else if (string.IsNullOrEmpty(package?.name))
            {
                AddError(new Error(NativeErrorCode.Unknown, "Invalid package info."));
            }
        }
Exemplo n.º 2
0
        public AssetStorePackage(FetchedInfo fetchedInfo, LocalInfo localInfo = null)
        {
            m_Errors         = new List <Error>();
            m_Progress       = PackageProgress.None;
            m_Type           = PackageType.AssetStore;
            m_Name           = string.Empty;
            m_ProductId      = fetchedInfo?.id.ToString();
            m_Images         = fetchedInfo?.images ?? new List <PackageImage>();
            m_Links          = fetchedInfo?.links ?? new List <PackageLink>();
            m_VersionList    = new AssetStoreVersionList();
            m_UpmVersionList = new UpmVersionList();

            if (string.IsNullOrEmpty(fetchedInfo?.id) || string.IsNullOrEmpty(fetchedInfo?.versionId))
            {
                AddError(new Error(NativeErrorCode.Unknown, "Invalid product details."));
            }
            else if (localInfo == null)
            {
                m_VersionList.AddVersion(new AssetStorePackageVersion(fetchedInfo));
            }
            else
            {
                m_VersionList.AddVersion(new AssetStorePackageVersion(fetchedInfo, localInfo));
                if (localInfo.canUpdate && (localInfo.versionId != fetchedInfo.versionId || localInfo.versionString != fetchedInfo.versionString))
                {
                    m_VersionList.AddVersion(new AssetStorePackageVersion(fetchedInfo));
                }
            }
        }
Exemplo n.º 3
0
            public void FetchDetails(IEnumerable <long> productIds)
            {
                var countProduct = productIds.Count();

                if (countProduct == 0)
                {
                    return;
                }

                onFetchDetailsStart?.Invoke();

                foreach (var id in productIds)
                {
                    AssetStoreRestAPI.instance.GetProductDetail(id, productDetail =>
                    {
                        AssetStorePackage package = null;
                        var error = productDetail.GetString("errorMessage");
                        if (string.IsNullOrEmpty(error))
                        {
                            var fetchedInfo = FetchedInfo.ParseFetchedInfo(id.ToString(), productDetail);
                            if (fetchedInfo == null)
                            {
                                package = new AssetStorePackage(id.ToString(), new Error(NativeErrorCode.Unknown, "Error parsing product details."));
                            }
                            else
                            {
                                var oldFetchedInfo = m_FetchedInfos.Get(fetchedInfo.id);
                                if (oldFetchedInfo == null || oldFetchedInfo.versionId != fetchedInfo.versionId || oldFetchedInfo.versionString != fetchedInfo.versionString)
                                {
                                    if (string.IsNullOrEmpty(fetchedInfo.packageName))
                                    {
                                        package = new AssetStorePackage(fetchedInfo, m_LocalInfos.Get(fetchedInfo.id));
                                    }
                                    else
                                    {
                                        UpmClient.instance.FetchForProduct(fetchedInfo.id, fetchedInfo.packageName);
                                    }
                                    m_FetchedInfos[fetchedInfo.id] = fetchedInfo;
                                }
                            }
                        }
                        else
                        {
                            package = new AssetStorePackage(id.ToString(), new Error(NativeErrorCode.Unknown, error));
                        }

                        if (package != null)
                        {
                            onPackagesChanged?.Invoke(new[] { package });
                        }

                        countProduct--;
                        if (countProduct == 0)
                        {
                            onFetchDetailsFinish?.Invoke();
                        }
                    });
                }
            }
Exemplo n.º 4
0
        internal void UpdateFetchedInfo(AssetStore.FetchedInfo fetchedInfo)
        {
            m_PackageUniqueId = fetchedInfo.id;

            // override version info with product info
            m_DisplayName = fetchedInfo.displayName;
            m_Description = fetchedInfo.description;
        }
        public AssetStorePackageVersion(FetchedInfo fetchedInfo, LocalInfo localInfo = null)
        {
            if (fetchedInfo == null)
            {
                throw new ArgumentNullException(nameof(fetchedInfo));
            }

            m_Errors          = new List <Error>();
            m_Tag             = PackageTag.Downloadable | PackageTag.Importable;
            m_PackageUniqueId = fetchedInfo.id.ToString();

            m_Description = fetchedInfo.description;
            m_Author      = fetchedInfo.author;
            m_PublisherId = fetchedInfo.publisherId;

            m_Category = fetchedInfo.category;

            m_VersionString = localInfo?.versionString ?? fetchedInfo.versionString ?? string.Empty;
            m_VersionId     = localInfo?.versionId ?? fetchedInfo.versionId ?? string.Empty;
            m_Version       = SemVersion.TryParse(m_VersionString.Trim(), out m_Version) ? m_Version : new SemVersion(0);

            var publishDateString = localInfo?.publishedDate ?? fetchedInfo.publishedDate ?? string.Empty;

            m_PublishedDateTicks = !string.IsNullOrEmpty(publishDateString) ? DateTime.Parse(publishDateString).Ticks : 0;
            m_DisplayName        = !string.IsNullOrEmpty(fetchedInfo.displayName) ? fetchedInfo.displayName : $"Package {m_PackageUniqueId}@{m_VersionId}";

            m_SupportedUnityVersions = new List <SemVersion>();
            if (fetchedInfo.supportedVersions?.Any() ?? false)
            {
                foreach (var supportedVersion in fetchedInfo.supportedVersions)
                {
                    SemVersion version;
                    if (SemVersion.TryParse(supportedVersion as string, out version))
                    {
                        m_SupportedUnityVersions.Add(version);
                    }
                }
                m_SupportedUnityVersions.Sort((left, right) => left.CompareByPrecedence(right));
            }

            if (localInfo != null)
            {
                var simpleVersion = Regex.Replace(localInfo.supportedVersion, @"(?<major>\d+)\.(?<minor>\d+).(?<patch>\d+)[abfp].+", "${major}.${minor}.${patch}");
                SemVersion.TryParse(simpleVersion.Trim(), out m_SupportedUnityVersion);
            }
            else
            {
                m_SupportedUnityVersion = m_SupportedUnityVersions.LastOrDefault();
            }

            m_SizeInfos = new List <PackageSizeInfo>(fetchedInfo.sizeInfos);
            m_SizeInfos.Sort((left, right) => left.supportedUnityVersion.CompareByPrecedence(right.supportedUnityVersion));

            var state = fetchedInfo.state ?? string.Empty;

            if (state.Equals("published", StringComparison.InvariantCultureIgnoreCase))
            {
                m_Tag |= PackageTag.Published;
            }
            else if (state.Equals("deprecated", StringComparison.InvariantCultureIgnoreCase))
            {
                m_Tag |= PackageTag.Deprecated;
            }

            m_LocalPath         = localInfo?.packagePath ?? string.Empty;
            m_IsAvailableOnDisk = !string.IsNullOrEmpty(m_LocalPath) && File.Exists(m_LocalPath);
        }