public AssetStorePackage(AssetStorePurchaseInfo purchaseInfo, AssetStoreProductInfo productInfo, UpmPackage package)
        {
            m_Errors    = new List <UIError>();
            m_Progress  = PackageProgress.None;
            m_Type      = PackageType.AssetStore;
            m_Name      = package?.name ?? string.Empty;
            m_ProductId = productInfo?.id.ToString();

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

            m_Labels             = purchaseInfo?.tags;
            m_PurchasedTimeTicks = !string.IsNullOrEmpty(purchaseInfo?.purchasedTime) ? DateTime.Parse(purchaseInfo?.purchasedTime).Ticks : 0;

            m_UpmVersionList = package?.versions as UpmVersionList ?? new UpmVersionList();
            foreach (var version in m_UpmVersionList.Cast <UpmPackageVersion>())
            {
                version.UpdateProductInfo(productInfo);
            }

            if (purchaseInfo == null)
            {
                AddError(new UIError(UIErrorCode.AssetStorePackageError, "Invalid purchase details."));
            }
            if (string.IsNullOrEmpty(productInfo?.id) || string.IsNullOrEmpty(productInfo?.versionId))
            {
                AddError(new UIError(UIErrorCode.AssetStorePackageError, "Invalid product details."));
            }
            else if (string.IsNullOrEmpty(package?.name))
            {
                AddError(new UIError(UIErrorCode.AssetStorePackageError, "Invalid package info."));
            }
        }
            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 productInfo = AssetStoreProductInfo.ParseProductInfo(id.ToString(), productDetail);
                            if (productInfo == null)
                            {
                                package = new AssetStorePackage(id.ToString(), new UIError(UIErrorCode.AssetStoreClientError, "Error parsing product details."));
                            }
                            else
                            {
                                var purchaseInfo   = m_PurchaseInfos.Get(productInfo.id);
                                var oldProductInfo = m_ProductInfos.Get(productInfo.id);
                                if (oldProductInfo == null || oldProductInfo.versionId != productInfo.versionId || oldProductInfo.versionString != productInfo.versionString)
                                {
                                    if (string.IsNullOrEmpty(productInfo.packageName))
                                    {
                                        package = new AssetStorePackage(purchaseInfo, productInfo, m_LocalInfos.Get(productInfo.id));
                                    }
                                    else
                                    {
                                        UpmClient.instance.FetchForProduct(productInfo.id, productInfo.packageName);
                                    }
                                    m_ProductInfos[productInfo.id] = productInfo;
                                }
                            }
                        }
                        else
                        {
                            package = new AssetStorePackage(id.ToString(), new UIError(UIErrorCode.AssetStoreClientError, error));
                        }

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

                        countProduct--;
                        if (countProduct == 0)
                        {
                            onFetchDetailsFinish?.Invoke();
                        }
                    });
                }
            }
        public AssetStorePackage(AssetStorePurchaseInfo purchaseInfo, AssetStoreProductInfo productInfo, AssetStoreLocalInfo localInfo = null)
        {
            m_Errors             = new List <UIError>();
            m_Progress           = PackageProgress.None;
            m_Type               = PackageType.AssetStore;
            m_Name               = string.Empty;
            m_ProductId          = productInfo?.id.ToString();
            m_Images             = productInfo?.images ?? new List <PackageImage>();
            m_Links              = productInfo?.links ?? new List <PackageLink>();
            m_VersionList        = new AssetStoreVersionList();
            m_UpmVersionList     = new UpmVersionList();
            m_Labels             = purchaseInfo?.tags;
            m_PurchasedTimeTicks = !string.IsNullOrEmpty(purchaseInfo?.purchasedTime) ? DateTime.Parse(purchaseInfo?.purchasedTime).Ticks : 0;

            if (purchaseInfo == null)
            {
                AddError(new UIError(UIErrorCode.AssetStorePackageError, "Invalid purchase details."));
            }
            if (string.IsNullOrEmpty(productInfo?.id) || string.IsNullOrEmpty(productInfo?.versionId))
            {
                AddError(new UIError(UIErrorCode.AssetStorePackageError, "Invalid product details."));
            }
            else if (localInfo == null)
            {
                m_VersionList.AddVersion(new AssetStorePackageVersion(productInfo));
            }
            else
            {
                m_VersionList.AddVersion(new AssetStorePackageVersion(productInfo, localInfo));
                if (localInfo.canUpdate && (localInfo.versionId != productInfo.versionId || localInfo.versionString != productInfo.versionString))
                {
                    m_VersionList.AddVersion(new AssetStorePackageVersion(productInfo));
                }
            }
        }
Exemple #4
0
        public virtual void FetchDetails(IEnumerable <long> productIds)
        {
            var countProduct = productIds.Count();

            if (countProduct == 0)
            {
                return;
            }

            onFetchDetailsStart?.Invoke();

            foreach (var id in productIds)
            {
                m_AssetStoreRestAPI.GetProductDetail(id, productDetail =>
                {
                    AssetStorePackage package = null;
                    var error = productDetail.GetString("errorMessage");
                    if (string.IsNullOrEmpty(error))
                    {
                        var productInfo = AssetStoreProductInfo.ParseProductInfo(m_AssetStoreUtils, id.ToString(), productDetail);
                        if (productInfo == null)
                        {
                            package = new AssetStorePackage(m_AssetStoreUtils, m_IOProxy, id.ToString(), new UIError(UIErrorCode.AssetStoreClientError, L10n.Tr("Error parsing product details.")));
                        }
                        else
                        {
                            var oldProductInfo = m_AssetStoreCache.GetProductInfo(productInfo.id);
                            if (oldProductInfo == null || oldProductInfo.versionId != productInfo.versionId || oldProductInfo.versionString != productInfo.versionString)
                            {
                                if (string.IsNullOrEmpty(productInfo.packageName))
                                {
                                    package = new AssetStorePackage(m_AssetStoreUtils, m_IOProxy, m_AssetStoreCache.GetPurchaseInfo(productInfo.id), productInfo, m_AssetStoreCache.GetLocalInfo(productInfo.id));
                                }
                                else
                                {
                                    m_UpmClient.FetchForProduct(productInfo.id, productInfo.packageName);
                                }
                                m_AssetStoreCache.SetProductInfo(productInfo);
                            }
                        }
                    }
                    else
                    {
                        m_AssetStoreCache.RemoveProductInfo(id.ToString());
                        package = new AssetStorePackage(m_AssetStoreUtils, m_IOProxy, id.ToString(), new UIError(UIErrorCode.AssetStoreClientError, error));
                    }

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

                    countProduct--;
                    if (countProduct == 0)
                    {
                        onFetchDetailsFinish?.Invoke();
                    }
                });
            }
        }
Exemple #5
0
        internal void UpdateProductInfo(AssetStoreProductInfo productInfo)
        {
            m_PackageUniqueId = productInfo.id;

            // override version info with product info
            m_DisplayName = productInfo.displayName;
            m_Description = productInfo.description;
        }
        public AssetStorePackage(AssetStorePurchaseInfo purchaseInfo, AssetStoreProductInfo productInfo, AssetStoreLocalInfo localInfo = null)
        {
            m_Errors         = new List <UIError>();
            m_Progress       = PackageProgress.None;
            m_Type           = PackageType.AssetStore;
            m_Name           = string.Empty;
            m_ProductId      = productInfo?.id.ToString();
            m_Images         = productInfo?.images ?? new List <PackageImage>();
            m_Links          = productInfo?.links ?? new List <PackageLink>();
            m_VersionList    = new AssetStoreVersionList();
            m_UpmVersionList = new UpmVersionList();
            m_AssetStoreLink = productInfo?.assetStoreLink.url;

            var firstPublishedDateString = productInfo?.firstPublishedDate ?? string.Empty;

            m_FirstPublishedDateTicks = !string.IsNullOrEmpty(firstPublishedDateString) ? DateTime.Parse(firstPublishedDateString).Ticks : 0;

            m_Labels             = purchaseInfo?.tags;
            m_PurchasedTimeTicks = !string.IsNullOrEmpty(purchaseInfo?.purchasedTime) ? DateTime.Parse(purchaseInfo?.purchasedTime).Ticks : 0;

            if (purchaseInfo == null)
            {
                var errorMessage = ApplicationUtil.instance.GetTranslationForText("Unable to get purchase details because you may not have purchased this package.");
                AddError(new UIError(UIErrorCode.AssetStorePackageError, errorMessage));
            }
            if (string.IsNullOrEmpty(productInfo?.id) || string.IsNullOrEmpty(productInfo?.versionId))
            {
                AddError(new UIError(UIErrorCode.AssetStorePackageError, ApplicationUtil.instance.GetTranslationForText("Invalid product details.")));
            }
            else if (localInfo == null)
            {
                m_VersionList.AddVersion(new AssetStorePackageVersion(productInfo));
            }
            else
            {
                m_VersionList.AddVersion(new AssetStorePackageVersion(productInfo, localInfo));
                if (localInfo.canUpdate && (localInfo.versionId != productInfo.versionId || localInfo.versionString != productInfo.versionString))
                {
                    m_VersionList.AddVersion(new AssetStorePackageVersion(productInfo));
                }
            }
        }
Exemple #7
0
 public void SetProductInfo(AssetStoreProductInfo info)
 {
     m_ProductInfos[info.id] = info;
 }
Exemple #8
0
        public AssetStorePackage(AssetStoreUtils assetStoreUtils, IOProxy ioProxy, AssetStorePurchaseInfo purchaseInfo, AssetStoreProductInfo productInfo, UpmPackage package)
        {
            ResolveDependencies(assetStoreUtils, ioProxy);

            m_Errors    = new List <UIError>();
            m_Progress  = PackageProgress.None;
            m_Type      = PackageType.AssetStore;
            m_Name      = package?.name ?? string.Empty;
            m_ProductId = productInfo?.id.ToString();

            m_Images      = productInfo?.images ?? new List <PackageImage>();
            m_Links       = productInfo?.links ?? new List <PackageLink>();
            m_VersionList = new AssetStoreVersionList(assetStoreUtils, ioProxy);

            m_Labels             = purchaseInfo?.tags;
            m_PurchasedTimeTicks = !string.IsNullOrEmpty(purchaseInfo?.purchasedTime) ? DateTime.Parse(purchaseInfo?.purchasedTime).Ticks : 0;

            m_UpmVersionList = package?.versions as UpmVersionList ?? new UpmVersionList(ioProxy);
            if (productInfo != null)
            {
                foreach (var version in m_UpmVersionList.Cast <UpmPackageVersion>())
                {
                    version.UpdateProductInfo(productInfo);
                }
            }

            m_AssetStoreLink = productInfo?.assetStoreLink.url;

            var firstPublishedDateString = productInfo?.firstPublishedDate ?? string.Empty;

            m_FirstPublishedDateTicks = !string.IsNullOrEmpty(firstPublishedDateString) ? DateTime.Parse(firstPublishedDateString).Ticks : 0;

            if (purchaseInfo == null)
            {
                var errorMessage = L10n.Tr("Unable to get purchase details because you may not have purchased this package.");
                AddError(new UIError(UIErrorCode.AssetStorePackageError, errorMessage));
            }
            if (string.IsNullOrEmpty(productInfo?.id) || string.IsNullOrEmpty(productInfo?.versionId))
            {
                AddError(new UIError(UIErrorCode.AssetStorePackageError, L10n.Tr("Invalid product details.")));
            }
            else if (string.IsNullOrEmpty(package?.name))
            {
                AddError(new UIError(UIErrorCode.AssetStorePackageError, L10n.Tr("Invalid package info.")));
            }
        }
        public AssetStorePackageVersion(AssetStoreProductInfo productInfo, AssetStoreLocalInfo localInfo = null)
        {
            if (productInfo == null)
            {
                throw new ArgumentNullException(nameof(productInfo));
            }

            m_Errors          = new List <UIError>();
            m_Tag             = PackageTag.Downloadable | PackageTag.Importable;
            m_PackageUniqueId = productInfo.id;

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

            m_Category = productInfo.category;

            m_VersionString = localInfo?.versionString ?? productInfo.versionString ?? string.Empty;
            m_VersionId     = localInfo?.versionId ?? productInfo.versionId ?? string.Empty;
            SemVersionParser.TryParse(m_VersionString.Trim(), out m_Version);

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

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

            m_SupportedUnityVersions = new List <SemVersion>();
            if (localInfo != null)
            {
                var simpleVersion = Regex.Replace(localInfo.supportedVersion, @"(?<major>\d+)\.(?<minor>\d+).(?<patch>\d+)[abfp].+", "${major}.${minor}.${patch}");
                SemVersionParser.TryParse(simpleVersion.Trim(), out m_SupportedUnityVersion);
                m_SupportedUnityVersionString = m_SupportedUnityVersion?.ToString();
            }
            else if (productInfo.supportedVersions?.Any() ?? false)
            {
                foreach (var supportedVersion in productInfo.supportedVersions)
                {
                    SemVersion?version;
                    bool       isVersionParsed = SemVersionParser.TryParse(supportedVersion as string, out version);

                    if (isVersionParsed)
                    {
                        m_SupportedUnityVersions.Add((SemVersion)version);
                    }
                }

                m_SupportedUnityVersions.Sort((left, right) => (left).CompareTo(right));
                m_SupportedUnityVersion       = m_SupportedUnityVersions.LastOrDefault();
                m_SupportedUnityVersionString = m_SupportedUnityVersion?.ToString();
            }

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

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

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

            SetLocalPath(localInfo?.packagePath);
        }