示例#1
0
        internal void UpdateProductInfo(AssetStoreProductInfo productInfo)
        {
            m_PackageUniqueId = productInfo.id;
            m_PublishNotes    = productInfo.publishNotes;

            // override version info with product info
            m_DisplayName = productInfo.displayName;
            m_Description = productInfo.description;
        }
示例#2
0
        public virtual void FetchDetail(long productId, Action <IPackage> doneCallbackAction = null)
        {
            m_AssetStoreRestAPI.GetProductDetail(productId, productDetail =>
            {
                IPackage package = null;
                var error        = productDetail.GetString("errorMessage");
                var idString     = productId.ToString();
                if (string.IsNullOrEmpty(error))
                {
                    var productInfo = AssetStoreProductInfo.ParseProductInfo(m_AssetStoreUtils, idString, productDetail);
                    if (productInfo == null)
                    {
                        package = new AssetStorePackage(m_AssetStoreUtils, m_IOProxy, idString, new UIError(UIErrorCode.AssetStoreClientError, L10n.Tr("Error parsing product details.")));
                    }
                    else
                    {
                        var oldProductInfo = m_AssetStoreCache.GetProductInfo(idString);
                        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(idString), productInfo, m_AssetStoreCache.GetLocalInfo(idString));
                            }
                            else
                            {
                                m_UpmClient.FetchForProduct(idString, productInfo.packageName);
                            }
                            m_AssetStoreCache.SetProductInfo(productInfo);
                        }
                    }
                }
                else
                {
                    var purchaseInfo = m_AssetStoreCache.GetPurchaseInfo(idString);
                    m_AssetStoreCache.RemoveProductInfo(idString);
                    var uiError = new UIError(UIErrorCode.AssetStoreClientError, error);
                    package     = new PlaceholderPackage(idString, purchaseInfo?.displayName ?? string.Empty, PackageType.AssetStore, PackageTag.Downloadable, PackageProgress.None, uiError);
                }

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

                doneCallbackAction?.Invoke(package);
            });
        }
示例#3
0
        public AssetStorePackage(AssetStoreUtils assetStoreUtils, IOProxy ioProxy, AssetStorePurchaseInfo purchaseInfo, AssetStoreProductInfo productInfo, AssetStoreLocalInfo localInfo = null)
        {
            ResolveDependencies(assetStoreUtils, ioProxy);

            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(assetStoreUtils, ioProxy);
            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;
            m_IsHidden           = purchaseInfo?.isHidden == true;

            if (string.IsNullOrEmpty(productInfo?.id) || string.IsNullOrEmpty(productInfo?.versionId))
            {
                AddError(new UIError(UIErrorCode.AssetStorePackageError, L10n.Tr("Invalid product details.")));
            }
            else
            {
                // The version we get from the product info the latest on the server
                // The version we get from the localInfo is the version publisher set when uploading the .unitypackage file
                // The publisher could update the version on the server but NOT upload a new .unitypackage file, that will
                // result in a case where localInfo and productInfo have different version numbers but no update is available
                // Because of this, we prefer showing version from the server (even when localInfo version is different)
                // and we only want to show the localInfo version when `localInfo.canUpdate` is set to true
                var latestVersion = new AssetStorePackageVersion(assetStoreUtils, ioProxy, productInfo);
                if (localInfo != null)
                {
                    if (localInfo.canUpdate)
                    {
                        m_VersionList.AddVersion(new AssetStorePackageVersion(assetStoreUtils, ioProxy, productInfo, localInfo));
                    }
                    else
                    {
                        latestVersion.SetLocalPath(localInfo.packagePath);
                        if (localInfo.canDowngrade)
                        {
                            var warningMessage = string.Format(k_IncompatibleWarningMessage, localInfo.supportedVersion);
                            AddError(new UIError(UIErrorCode.AssetStorePackageError, warningMessage, UIError.Attribute.IsWarning));
                        }
                    }
                }
                m_VersionList.AddVersion(latestVersion);
            }

            LinkPackageAndVersions();
        }
示例#4
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_IsHidden           = purchaseInfo?.isHidden == true;
            m_PurchasedTimeTicks = !string.IsNullOrEmpty(purchaseInfo?.purchasedTime) ? DateTime.Parse(purchaseInfo?.purchasedTime).Ticks : 0;

            m_UpmVersionList = package?.versions as UpmVersionList ?? new UpmVersionList();
            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)
            {
                AddError(new UIError(UIErrorCode.AssetStorePackageError, L10n.Tr("Unable to get asset purchase details because you may not have purchased this package.")));
            }
            if (string.IsNullOrEmpty(productInfo?.id) || string.IsNullOrEmpty(productInfo?.versionId))
            {
                AddError(new UIError(UIErrorCode.AssetStorePackageError, L10n.Tr("Unable to retrieve asset product details.")));
            }
            else if (string.IsNullOrEmpty(package?.name))
            {
                AddError(new UIError(UIErrorCode.AssetStorePackageError, L10n.Tr("Unable to retrieve asset package info.")));
            }

            LinkPackageAndVersions();
        }
示例#5
0
        public AssetStorePackageVersion(AssetStoreUtils assetStoreUtils, IOProxy ioProxy, AssetStoreProductInfo productInfo, AssetStoreLocalInfo localInfo = null)
        {
            if (productInfo == null)
            {
                throw new ArgumentNullException(nameof(productInfo));
            }

            ResolveDependencies(assetStoreUtils, ioProxy);

            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_PublishNotes = localInfo?.publishNotes ?? productInfo.publishNotes ?? string.Empty;

            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, 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;
            }
            else if (state.Equals("disabled", StringComparison.InvariantCultureIgnoreCase))
            {
                m_Tag |= PackageTag.Disabled;
            }

            SetLocalPath(localInfo?.packagePath);
        }
 public virtual void SetProductInfo(AssetStoreProductInfo info)
 {
     m_ProductInfos[info.id] = info;
 }