示例#1
0
        private void DownloadRemoteBundleMap(Action callback)
        {
            ResourceModule.Instance.DownloadBufferFromServer(SysConf.SQLITE_BUNDLE_MAP, (bundleMapBuffer) =>
            {
                string serverBundleMapInPersistentPath = Path.Combine(PathResolver.ApplicationPersistentDataPath, SysConf.SERVER_SQLITE_BUNDLE_MAP);
                EngineFileUtil.WriteBytesToFile(serverBundleMapInPersistentPath, bundleMapBuffer);

                this.m_remoteBundleIndicesMap = new BundleIndicesMap(serverBundleMapInPersistentPath);

                callback();
            }, (remoteBundleMap) =>
            {
                DownloadRemoteBundleMap(callback);
            });
        }
示例#2
0
        private void DownloadInternal(string assetUrl, bool isSaveTopersistentDataPath)
        {
            if (!assetUrl.StartsWithFast("http://"))
            {
                assetUrl = $"{ SysConf.GAME_RES_URL}/{ assetUrl}";
            }

            this.m_currentRequestCount++;

            HTTPRequest downloadRequest = new HTTPRequest(new Uri(assetUrl), (req, resp) =>
            {
                string downloadedAssetName = Path.GetFileName(req.Uri.AbsolutePath);
                byte[] downloadedBuffer    = new byte[0];
                switch (req.State)
                {
                case HTTPRequestStates.Finished:
                    {
                        if (resp.IsSuccess)
                        {
                            downloadedBuffer = resp.Data;

                            if (isSaveTopersistentDataPath)
                            {
                                string savePath = $"{PathResolver.ApplicationPersistentDataPath}/{downloadedAssetName}";
                                EngineFileUtil.WriteBytesToFile(savePath, resp.Data);
                            }

                            OnDownloadedAsset(downloadedAssetName, downloadedBuffer);
                        }
                        else
                        {
                            Debug.LogWarning(string.Format("Request finished Successfully, but the server sent an error. Status Code: {0}-{1} Message: {2}",
                                                           resp.StatusCode,
                                                           resp.Message,
                                                           resp.DataAsText));
                        }
                    }
                    break;

                case HTTPRequestStates.Error:
                    OnDownloadError(downloadedAssetName, "Request Finished with Error! " + (req.Exception != null ? (req.Exception.Message + "\n" + req.Exception.StackTrace) : "No Exception"));
                    break;

                case HTTPRequestStates.Aborted:
                    OnDownloadError(downloadedAssetName, "Request Aborted!");
                    break;

                case HTTPRequestStates.ConnectionTimedOut:
                    OnDownloadError(downloadedAssetName, "Connection Timed Out!");
                    break;

                case HTTPRequestStates.TimedOut:
                    OnDownloadError(downloadedAssetName, "Processing the request Timed Out!");
                    break;
                }

                m_currentRequestCount--;

                if (this.m_waitingDownloadQueue.Count > 0)
                {
                    DownloadInternal(this.m_waitingDownloadQueue.Dequeue(), isSaveTopersistentDataPath);
                }
                else
                {
                    if (this.m_currentRequestCount == 0)
                    {
                        OnDownloadFinishCallback?.Invoke(this.m_downloadErrorList);
                    }
                }
            });

            downloadRequest.UseStreaming = false;
            downloadRequest.Send();
        }