Exemplo n.º 1
0
 private void GetAssetStoreCacheConfig()
 {
     RefreshAssetStoreCachePathConfig(m_AssetStoreCachePathProxy.GetConfig());
 }
Exemplo n.º 2
0
        public void Download(bool resume)
        {
            var config = m_AssetStoreCachePathProxy.GetConfig();

            if (config.status == ConfigStatus.ReadOnly)
            {
                OnErrorMessage("The Assets Cache location is read-only, see configuration in Preferences | Package Manager", -1, UIError.Attribute.IsWarning);
                return;
            }
            if (config.status == ConfigStatus.InvalidPath)
            {
                OnErrorMessage("The Assets Cache location is invalid or inaccessible, see configuration in Preferences | Package Manager", -1, UIError.Attribute.IsWarning);
                return;
            }

            m_State = resume ? DownloadState.ResumeRequested : DownloadState.DownloadRequested;
            var productId = long.Parse(m_ProductId);

            m_AssetStoreRestAPI.GetDownloadDetail(productId, downloadInfo =>
            {
                // if the user requested to abort before receiving the download details, we can simply discard the download info and do nothing
                if (m_State == DownloadState.AbortRequsted)
                {
                    return;
                }

                m_DownloadInfo = downloadInfo;
                if (!downloadInfo.isValid)
                {
                    OnErrorMessage(downloadInfo.errorMessage, downloadInfo.errorCode);
                    return;
                }

                var dest = downloadInfo.destination;

                var publisher   = string.Empty;
                var category    = string.Empty;
                var packageName = string.Empty;

                if (dest.Length >= 1)
                {
                    publisher = dest[0];
                }
                if (dest.Length >= 2)
                {
                    category = dest[1];
                }
                if (dest.Length >= 3)
                {
                    packageName = dest[2];
                }

                var basePath     = m_AssetStoreUtils.BuildBaseDownloadPath(publisher, category);
                m_ProductNewPath = m_AssetStoreUtils.BuildFinalDownloadPath(basePath, packageName);

                var json = m_AssetStoreUtils.CheckDownload(
                    $"{k_AssetStoreDownloadPrefix}{downloadInfo.productId}",
                    downloadInfo.url, dest,
                    downloadInfo.key);

                var resumeOK = false;
                try
                {
                    var current = Json.Deserialize(json) as IDictionary <string, object>;
                    if (current == null)
                    {
                        throw new ArgumentException("Invalid JSON");
                    }

                    var inProgress = current.ContainsKey("in_progress") && (current["in_progress"] is bool?(bool)current["in_progress"] : false);
                    if (inProgress)
                    {
                        if (!isInPause)
                        {
                            m_State = DownloadState.Downloading;
                        }
                        return;
                    }

                    if (current.ContainsKey("download") && current["download"] is IDictionary <string, object> )
                    {
                        var download    = (IDictionary <string, object>)current["download"];
                        var existingUrl = download.ContainsKey("url") ? download["url"] as string : string.Empty;
                        var existingKey = download.ContainsKey("key") ? download["key"] as string : string.Empty;
                        resumeOK        = (existingUrl == downloadInfo.url && existingKey == downloadInfo.key);
                    }
                }
                catch (Exception e)
                {
                    OnErrorMessage(e.Message);
                    return;
                }

                json = $"{{\"download\":{{\"url\":\"{downloadInfo.url}\",\"key\":\"{downloadInfo.key}\"}}}}";
                m_AssetStoreUtils.Download(
                    $"{k_AssetStoreDownloadPrefix}{downloadInfo.productId}",
                    downloadInfo.url,
                    dest,
                    downloadInfo.key,
                    json,
                    resumeOK && resume);

                m_State = DownloadState.Connecting;
            });
        }