Beispiel #1
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));
                }
            }
        }
Beispiel #2
0
            private void OnLocalInfoRemoved(LocalInfo localInfo)
            {
                var fetchedInfo = m_FetchedInfos.Get(localInfo.id);

                if (fetchedInfo == null)
                {
                    return;
                }
                var package = new AssetStorePackage(fetchedInfo, (LocalInfo)null);

                onPackagesChanged?.Invoke(new[] { package });
            }
Beispiel #3
0
            private void RefreshLocalInfos()
            {
                var infos         = AssetStoreUtils.instance.GetLocalPackageList();
                var oldLocalInfos = m_LocalInfos;

                m_LocalInfos = new Dictionary <string, LocalInfo>();
                foreach (var info in infos)
                {
                    var parsedInfo = LocalInfo.ParseLocalInfo(info);
                    var id         = parsedInfo?.id;
                    if (string.IsNullOrEmpty(id))
                    {
                        continue;
                    }

                    var oldInfo = oldLocalInfos.Get(id);
                    if (oldInfo != null)
                    {
                        oldLocalInfos.Remove(oldInfo.id);

                        if (oldInfo.versionId == parsedInfo.versionId &&
                            oldInfo.versionString == parsedInfo.versionString &&
                            oldInfo.packagePath == parsedInfo.packagePath)
                        {
                            m_LocalInfos[id] = oldInfo;
                            continue;
                        }
                    }

                    m_LocalInfos[id] = parsedInfo;
                    OnLocalInfoChanged(parsedInfo);
                }

                foreach (var info in oldLocalInfos.Values)
                {
                    OnLocalInfoRemoved(info);
                }
            }
        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);
        }