public virtual void CheckUpdate(IEnumerable <string> productIds, Action doneCallbackAction = null)
        {
            if (productIds?.Any() != true)
            {
                return;
            }

            m_AssetStoreRestAPI.GetProductUpdateDetail(productIds, updateDetails =>
            {
                if (updateDetails.ContainsKey("errorMessage"))
                {
                    var msg = string.Format(L10n.Tr("[Package Manager Window] Error while getting product update details: {0}"), updateDetails["errorMessage"]);
                    if (updateDetails.ContainsKey("errorCode"))
                    {
                        msg += $" [Error {updateDetails["errorCode"]}";
                    }
                    Debug.Log(msg);
                }
                else
                {
                    // If an asset store package is disabled, we won't get properly update info from the server (the id field will be transformed to something else)
                    // in the past we consider this case as `updateInfo` not checked and that causes the Package Manager to check update indefinitely.
                    // Now we want to mark all packages that we called `CheckUpdate` on as updateInfoFetched to avoid unnecessary calls on disabled packages.
                    foreach (var localInfo in productIds.Select(id => m_AssetStoreCache.GetLocalInfo(id)).Where(info => info != null))
                    {
                        localInfo.updateInfoFetched = true;
                    }

                    var results           = updateDetails.GetList <IDictionary <string, object> >("results") ?? Enumerable.Empty <IDictionary <string, object> >();
                    var updatedLocalInfos = new List <AssetStoreLocalInfo>();
                    foreach (var updateDetail in results)
                    {
                        var id        = updateDetail.GetString("id");
                        var localInfo = m_AssetStoreCache.GetLocalInfo(id);
                        if (localInfo != null)
                        {
                            var newValue = updateDetail.Get("can_update", 0L) != 0L;
                            if (localInfo.canUpdate != newValue)
                            {
                                localInfo.canUpdate = newValue;
                                updatedLocalInfos.Add(localInfo);
                            }
                        }
                    }
                    if (updatedLocalInfos.Any())
                    {
                        OnLocalInfosChanged(updatedLocalInfos, null);
                    }
                    onUpdateChecked?.Invoke(productIds);
                }
                doneCallbackAction?.Invoke();
            });
        }
Exemple #2
0
        public virtual void CheckUpdate(IEnumerable <string> productIds, Action doneCallbackAction = null)
        {
            if (productIds?.Any() != true)
            {
                return;
            }

            m_AssetStoreRestAPI.GetProductUpdateDetail(productIds, updateDetails =>
            {
                if (updateDetails.ContainsKey("errorMessage"))
                {
                    var msg = string.Format(L10n.Tr("[Package Manager Window] Error while getting product update details: {0}"), updateDetails["errorMessage"]);
                    if (updateDetails.ContainsKey("errorCode"))
                    {
                        msg += $" [Error {updateDetails["errorCode"]}";
                    }
                    Debug.Log(msg);
                }
                else
                {
                    var results = updateDetails.GetList <IDictionary <string, object> >("results") ?? Enumerable.Empty <IDictionary <string, object> >();
                    foreach (var updateDetail in results)
                    {
                        var id        = updateDetail.GetString("id");
                        var localInfo = m_AssetStoreCache.GetLocalInfo(id);
                        if (localInfo != null)
                        {
                            localInfo.updateInfoFetched = true;
                            var newValue = updateDetail.Get("can_update", 0L) != 0L;
                            if (localInfo.canUpdate != newValue)
                            {
                                localInfo.canUpdate = newValue;
                                OnLocalInfosChanged(new[] { localInfo }, null);
                            }
                        }
                    }
                    onUpdateChecked?.Invoke(productIds);
                }
                doneCallbackAction?.Invoke();
            });
        }