Beispiel #1
0
            private void ListInternal(IDictionary <string, AssetStorePackageInfo> localPackages, int offset, int limit)
            {
                onOperationStart?.Invoke();

                AssetStoreRestAPI.instance.GetProductIDList(offset, limit, productList =>
                {
                    if (!productList.isValid)
                    {
                        onOperationFinish?.Invoke();
                        onOperationError?.Invoke(new Error(NativeErrorCode.Unknown, productList.errorMessage));
                        return;
                    }

                    var countProduct = productList.list.Count;
                    if (countProduct == 0 || !ApplicationUtil.instance.isUserLoggedIn)
                    {
                        onOperationFinish?.Invoke();
                        return;
                    }

                    foreach (var product in productList.list)
                    {
                        AssetStoreRestAPI.instance.GetProductDetail(product, productDetail =>
                        {
                            AssetStorePackage package;
                            object error;
                            if (!productDetail.TryGetValue("errorMessage", out error))
                            {
                                AssetStorePackageInfo localPackage;
                                if (localPackages.TryGetValue(product.ToString(), out localPackage))
                                {
                                    productDetail["localPath"] = localPackage.packagePath;
                                }
                                else
                                {
                                    productDetail["localPath"] = string.Empty;
                                }

                                package = new AssetStorePackage(product.ToString(), productDetail);
                                if (m_UpdateDetails.ContainsKey(package.uniqueId))
                                {
                                    package.SetState(m_UpdateDetails[package.uniqueId]);
                                }

                                if (package.state == PackageState.Outdated && !string.IsNullOrEmpty(localPackage.packagePath))
                                {
                                    package.m_FirstVersion.localPath = string.Empty;

                                    try
                                    {
                                        var info              = new AssetStorePackageVersion.SpecificVersionInfo();
                                        var item              = Json.Deserialize(localPackage.jsonInfo) as Dictionary <string, object>;
                                        info.versionId        = item["version_id"] as string;
                                        info.versionString    = item["version"] as string;
                                        info.publishedDate    = item["pubdate"] as string;
                                        info.supportedVersion = item["unity_version"] as string;

                                        var installedVersion       = new AssetStorePackageVersion(product.ToString(), productDetail, info);
                                        installedVersion.localPath = localPackage.packagePath;

                                        package.AddVersion(installedVersion);
                                    }
                                    catch (Exception)
                                    {
                                    }
                                }
                            }
                            else
                            {
                                package = new AssetStorePackage(product.ToString(), new Error(NativeErrorCode.Unknown, error as string));
                            }

                            onPackagesChanged?.Invoke(new[] { package });

                            countProduct--;
                            if (countProduct == 0)
                            {
                                onOperationFinish?.Invoke();
                            }
                        });
                    }
                });
            }
            public void Refresh(IEnumerable <IPackage> packages)
            {
                if (packages == null || !packages.Any() || !ApplicationUtil.instance.isUserLoggedIn)
                {
                    return;
                }

                var localInfos    = new Dictionary <string, AssetStorePackageVersion.SpecificVersionInfo>();
                var localPackages = AssetStoreUtils.instance.GetLocalPackageList();

                foreach (var p in localPackages)
                {
                    if (!string.IsNullOrEmpty(p.jsonInfo))
                    {
                        var item = Json.Deserialize(p.jsonInfo) as Dictionary <string, object>;
                        if (item != null && item.ContainsKey("id") && item["id"] is string)
                        {
                            localInfos[(string)item["id"]] = new AssetStorePackageVersion.SpecificVersionInfo
                            {
                                packagePath      = p.packagePath,
                                versionString    = item.ContainsKey("version") && item["version"] is string?(string)item["version"] : string.Empty,
                                versionId        = item.ContainsKey("version_id") && item["version_id"] is string?(string)item["version_id"] : string.Empty,
                                publishedDate    = item.ContainsKey("pubdate") && item["pubdate"] is string?(string)item["pubdate"] : string.Empty,
                                supportedVersion = item.ContainsKey("unity_version") && item["unity_version"] is string?(string)item["unity_version"] : string.Empty
                            };
                        }
                    }
                }

                var updatedPackages = new List <IPackage>();

                foreach (var package in packages)
                {
                    var assetStorePackage = package as AssetStorePackage;
                    if (assetStorePackage == null)
                    {
                        continue;
                    }

                    AssetStorePackageVersion.SpecificVersionInfo localInfo;
                    localInfos.TryGetValue(assetStorePackage.uniqueId, out localInfo);

                    var packageChanged = false;
                    if (localInfo == null)
                    {
                        if (assetStorePackage.installedVersion != null)
                        {
                            assetStorePackage.m_FetchedVersion.localPath = string.Empty;
                            if (assetStorePackage.m_FetchedVersion != assetStorePackage.m_LocalVersion)
                            {
                                assetStorePackage.RemoveVersion(assetStorePackage.m_LocalVersion);
                            }

                            assetStorePackage.SetState(PackageState.UpToDate);
                            packageChanged = true;
                        }
                    }
                    else if (assetStorePackage.installedVersion == null || localInfo.versionString != assetStorePackage.installedVersion.versionString)
                    {
                        if (assetStorePackage.m_FetchedVersion.versionString == localInfo.versionString)
                        {
                            assetStorePackage.m_FetchedVersion.localPath = localInfo.packagePath;
                            if (assetStorePackage.m_LocalVersion != assetStorePackage.m_FetchedVersion)
                            {
                                assetStorePackage.RemoveVersion(assetStorePackage.m_LocalVersion);
                            }

                            assetStorePackage.SetState(PackageState.UpToDate);
                        }
                        else if (assetStorePackage.m_LocalVersion.versionString == localInfo.versionString)
                        {
                            assetStorePackage.m_FetchedVersion.localPath = string.Empty;
                            assetStorePackage.m_LocalVersion.localPath   = localInfo.packagePath;
                            assetStorePackage.SetState(PackageState.Outdated);
                        }
                        else
                        {
                            assetStorePackage.m_FetchedVersion.localPath = string.Empty;
                            assetStorePackage.AddVersion(new AssetStorePackageVersion(assetStorePackage.m_FetchedVersion, localInfo));
                            assetStorePackage.m_LocalVersion.localPath = localInfo.packagePath;
                            assetStorePackage.SetState(PackageState.Outdated);
                        }

                        packageChanged = true;
                    }

                    if (packageChanged)
                    {
                        if (m_UpdateDetails.ContainsKey(assetStorePackage.uniqueId))
                        {
                            m_UpdateDetails[assetStorePackage.uniqueId] = assetStorePackage.state;
                        }

                        updatedPackages.Add(package);
                    }
                }

                if (updatedPackages.Any())
                {
                    onPackagesChanged?.Invoke(updatedPackages);
                }
            }
            public void Refresh(IPackage package)
            {
                if (!ApplicationUtil.instance.isUserLoggedIn)
                {
                    return;
                }

                var assetStorePackage = package as AssetStorePackage;

                if (assetStorePackage == null)
                {
                    return;
                }

                AssetStorePackageVersion.SpecificVersionInfo localInfo = null;
                var localPackage = AssetStoreUtils.instance.GetLocalPackageList().FirstOrDefault(p =>
                {
                    if (!string.IsNullOrEmpty(p.jsonInfo))
                    {
                        var item = Json.Deserialize(p.jsonInfo) as Dictionary <string, object>;
                        if (item != null && item.ContainsKey("id") && item["id"] is string && package.uniqueId == (string)item["id"])
                        {
                            localInfo = new AssetStorePackageVersion.SpecificVersionInfo
                            {
                                versionString    = item.ContainsKey("version") && item["version"] is string?(string)item["version"] : string.Empty,
                                versionId        = item.ContainsKey("version_id") && item["version_id"] is string?(string)item["version_id"] : string.Empty,
                                publishedDate    = item.ContainsKey("pubdate") && item["pubdate"] is string?(string)item["pubdate"] : string.Empty,
                                supportedVersion = item.ContainsKey("unity_version") && item["unity_version"] is string?(string)item["unity_version"] : string.Empty
                            };
                            return(true);
                        }
                    }
                    return(false);
                });

                var packageChanged = false;

                if (localInfo == null)
                {
                    if (assetStorePackage.installedVersion != null)
                    {
                        assetStorePackage.m_FetchedVersion.localPath = string.Empty;
                        if (assetStorePackage.m_FetchedVersion != assetStorePackage.m_LocalVersion)
                        {
                            assetStorePackage.RemoveVersion(assetStorePackage.m_LocalVersion);
                        }

                        assetStorePackage.SetState(PackageState.UpToDate);
                        packageChanged = true;
                    }
                }
                else if (assetStorePackage.installedVersion == null || localInfo.versionString != assetStorePackage.installedVersion.versionString)
                {
                    if (assetStorePackage.m_FetchedVersion.versionString == localInfo.versionString)
                    {
                        assetStorePackage.m_FetchedVersion.localPath = localPackage.packagePath;
                        if (assetStorePackage.m_LocalVersion != assetStorePackage.m_FetchedVersion)
                        {
                            assetStorePackage.RemoveVersion(assetStorePackage.m_LocalVersion);
                        }
                        assetStorePackage.SetState(PackageState.UpToDate);
                    }
                    else if (assetStorePackage.m_LocalVersion.versionString == localInfo.versionString)
                    {
                        assetStorePackage.m_FetchedVersion.localPath = string.Empty;
                        assetStorePackage.m_LocalVersion.localPath   = localPackage.packagePath;
                        assetStorePackage.SetState(PackageState.Outdated);
                    }
                    else
                    {
                        assetStorePackage.m_FetchedVersion.localPath = string.Empty;
                        assetStorePackage.AddVersion(new AssetStorePackageVersion(assetStorePackage.m_FetchedVersion, localInfo));
                        assetStorePackage.m_LocalVersion.localPath = localPackage.packagePath;
                        assetStorePackage.SetState(PackageState.Outdated);
                    }

                    packageChanged = true;
                }

                if (packageChanged)
                {
                    if (m_UpdateDetails.ContainsKey(assetStorePackage.uniqueId))
                    {
                        m_UpdateDetails[assetStorePackage.uniqueId] = assetStorePackage.state;
                    }
                    onPackagesChanged?.Invoke(new[] { package });
                }
            }
            private void FetchDetailsInternal(IEnumerable <long> packageIds, IDictionary <string, AssetStorePackageInfo> localPackages)
            {
                var countProduct = packageIds.Count();

                if (countProduct == 0)
                {
                    return;
                }

                onFetchDetailsStart?.Invoke();

                foreach (var id in packageIds)
                {
                    AssetStoreRestAPI.instance.GetProductDetail(id, productDetail =>
                    {
                        AssetStorePackage package;
                        object error;
                        if (!productDetail.TryGetValue("errorMessage", out error))
                        {
                            AssetStorePackageInfo localPackage;
                            if (localPackages.TryGetValue(id.ToString(), out localPackage))
                            {
                                productDetail["localPath"] = localPackage.packagePath;
                            }
                            else
                            {
                                productDetail["localPath"] = string.Empty;
                            }

                            package = new AssetStorePackage(id.ToString(), productDetail);
                            if (m_UpdateDetails.ContainsKey(package.uniqueId))
                            {
                                package.SetState(m_UpdateDetails[package.uniqueId]);
                            }

                            if (package.state == PackageState.Outdated && !string.IsNullOrEmpty(localPackage.packagePath))
                            {
                                package.m_FetchedVersion.localPath = string.Empty;

                                try
                                {
                                    var info              = new AssetStorePackageVersion.SpecificVersionInfo();
                                    var item              = Json.Deserialize(localPackage.jsonInfo) as Dictionary <string, object>;
                                    info.versionId        = item["version_id"] as string;
                                    info.versionString    = item["version"] as string;
                                    info.publishedDate    = item["pubdate"] as string;
                                    info.supportedVersion = item["unity_version"] as string;

                                    var installedVersion       = new AssetStorePackageVersion(id.ToString(), productDetail, info);
                                    installedVersion.localPath = localPackage.packagePath;

                                    package.AddVersion(installedVersion);
                                }
                                catch (Exception)
                                {
                                }
                            }
                            m_PackageDetailsFetched.Add(id);
                        }
                        else
                        {
                            package = new AssetStorePackage(id.ToString(), new Error(NativeErrorCode.Unknown, error as string));
                        }

                        onPackagesChanged?.Invoke(new[] { package });

                        countProduct--;
                        if (countProduct == 0)
                        {
                            onFetchDetailsFinish?.Invoke();
                        }
                    });
                }
            }