Exemplo n.º 1
0
            public void AbortDownloadPackageAsync(long productID, Action <DownloadResult> doneCallbackAction = null)
            {
                var ret = new DownloadResult();

                AssetStoreRestAPI.instance.GetDownloadDetail(productID, downloadInformation =>
                {
                    if (!downloadInformation.isValid)
                    {
                        ret.downloadState = DownloadProgress.State.Error;
                        ret.errorMessage  = downloadInformation.errorMessage;
                        doneCallbackAction?.Invoke(ret);
                        return;
                    }

                    string[] dest     = { downloadInformation.publisherName, downloadInformation.categoryName, downloadInformation.packageName };
                    var res           = AssetStoreUtils.instance.AbortDownload($"content__{productID}", dest);
                    ret.downloadState = res ? DownloadProgress.State.Aborted : DownloadProgress.State.Error;
                    if (!res)
                    {
                        ret.errorMessage = "Cannot abort download.";
                    }

                    doneCallbackAction?.Invoke(ret);
                });
            }
Exemplo n.º 2
0
            private void AbortDownloadPackageInternal(string productID, Action <DownloadResult> doneCallbackAction = null)
            {
                var ret = new DownloadResult();

                var downloadInfo = m_DownloadInformations.FirstOrDefault(d => d.productId == productID);

                if (downloadInfo != null)
                {
                    var res = AssetStoreUtils.instance.AbortDownload($"content__{productID}", downloadInfo.destination);
                    ret.downloadState = res ? DownloadProgress.State.Aborted : DownloadProgress.State.Error;
                    if (!res)
                    {
                        ret.errorMessage = "Cannot abort download.";
                    }
                    doneCallbackAction?.Invoke(ret);

                    ClearDownloadInformation(downloadInfo.productId);
                }
            }
Exemplo n.º 3
0
            public void DownloadUnityPackageAsync(long productID, Action <DownloadResult> doneCallbackAction = null)
            {
                AssetStoreRestAPI.instance.GetDownloadDetail(productID, downloadInfo =>
                {
                    var ret = new DownloadResult();
                    if (!downloadInfo.isValid)
                    {
                        ret.downloadState = DownloadProgress.State.Error;
                        ret.errorMessage  = downloadInfo.errorMessage;
                        doneCallbackAction?.Invoke(ret);
                        return;
                    }

                    var dest = downloadInfo.destination;

                    var json = AssetStoreUtils.instance.CheckDownload(
                        $"content__{downloadInfo.productId}",
                        downloadInfo.url, dest,
                        downloadInfo.key);

                    var resumeOK = false;
                    try
                    {
                        json = Regex.Replace(json, "\"url\":(?<url>\"?[^,]+\"?),\"", "\"url\":\"${url}\",\"");
                        json = Regex.Replace(json, "\"key\":(?<key>\"?[0-9a-zA-Z]*\"?)\\}", "\"key\":\"${key}\"}");
                        json = Regex.Replace(json, "\"+(?<value>[^\"]+)\"+", "\"${value}\"");

                        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)
                        {
                            ret.downloadState = DownloadProgress.State.InProgress;
                            doneCallbackAction?.Invoke(ret);
                            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)
                    {
                        ret.downloadState = DownloadProgress.State.Error;
                        ret.errorMessage  = e.Message;
                        doneCallbackAction?.Invoke(ret);
                        return;
                    }

                    json = $"{{\"download\":{{\"url\":\"{downloadInfo.url}\",\"key\":\"{downloadInfo.key}\"}}}}";
                    AssetStoreUtils.instance.Download(
                        $"content__{downloadInfo.productId}",
                        downloadInfo.url,
                        dest,
                        downloadInfo.key,
                        json,
                        resumeOK);

                    m_DownloadInformations.Add(downloadInfo);

                    ret.downloadState = DownloadProgress.State.Started;
                    doneCallbackAction?.Invoke(ret);
                });
            }