Exemplo n.º 1
0
        private void OnPostDiff(BundleIndicesMap.BundleMapDiffResult diffResult)
        {
            for (int i = 0; i < diffResult.ObsoleteBundleIndexList.Count; ++i)
            {
                BundleIndexItemInfo obsoleteBundleInfo = diffResult.ObsoleteBundleIndexList[i];
                string bundleInPersistent;
                if (EngineFileUtil.IsExistInPersistentDataPath(obsoleteBundleInfo.BundleHashName, out bundleInPersistent))
                {
                    File.Delete(bundleInPersistent);
                }
            }

            ResourceMgr.Instance.BundleMap.DeleteBundleList(diffResult.ObsoleteBundleIndexList);

            diffResult.ObsoleteBundleIndexList.Clear();

            //已经下载但没写入bundlemap的资源
            for (int i = 0; i < diffResult.DirtyBundleIndexList.Count; ++i)
            {
                BundleIndexItemInfo dirtyBundleItemInfo = diffResult.DirtyBundleIndexList[i];

                string bundleInPersistent;
                if (EngineFileUtil.IsExistInPersistentDataPath(dirtyBundleItemInfo.BundleHashName, out bundleInPersistent))
                {
                    //OnDownloadedAsset(dirtyBundleItemInfo.BundleHashName, null);

                    ResourceMgr.Instance.BundleMap.AddBundleIndicesByTransaction(dirtyBundleItemInfo.BundleName, dirtyBundleItemInfo.BundleHash, dirtyBundleItemInfo.BundleDependencyArray, dirtyBundleItemInfo.BundleAssetsArray, dirtyBundleItemInfo.BundleSize);

                    diffResult.DirtyBundleIndexList.RemoveAt(i);
                }
            }

            m_downloadIndexDict.Clear();
            RegisterDownloadBundleList(diffResult.DirtyBundleIndexList);
        }
Exemplo n.º 2
0
 private void SyncBuildinBundlemap()
 {
     if (!EngineFileUtil.CopyFromStreamingAssetsToPersistentPath(SysConf.SQLITE_BUNDLE_MAP, SysConf.SQLITE_BUNDLE_MAP))
     {
         Debug.LogError("streaming assets bundlemap not found");
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// 删除过期的资源
        /// </summary>
        /// <param name="obsoleteBundles"></param>
        private void RemoveObsoleteBundle(List <BundleIndexItemInfo> obsoleteBundles)
        {
            for (int i = 0; i < obsoleteBundles.Count; ++i)
            {
                string obsoleteBundlePath;
                if (EngineFileUtil.IsExistInPersistentDataPath(obsoleteBundles[i].BundleHashName, out obsoleteBundlePath))
                {
                    File.Delete(obsoleteBundlePath);
                }
            }

            bundleMapLocal.DeleteBundleList(obsoleteBundles);
        }
Exemplo n.º 4
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);
            });
        }
Exemplo n.º 5
0
        public List <BundleIndexItemInfo> GetDynamicBundleIndexItemListByAssets(List <string> assetNameList)
        {
            if (RemoteBundleIndicesMap == null && DiffResult == null)
            {
                return(null);
            }

            List <BundleIndexItemInfo> dynamicBundleList = new List <BundleIndexItemInfo>();

            for (int i = assetNameList.Count - 1; i >= 0; --i)
            {
                string assetName = assetNameList[i];
                BundleIndexItemInfo dynamicBundleIndexItemInfo;
                dynamicBundleIndexItemInfo = DiffResult.GetAppendBundleItemInfoByBundleName(assetName);
                if (dynamicBundleIndexItemInfo != null)
                {
                    string dynamicBundlePath;
                    if (!EngineFileUtil.IsExistInPersistentDataPath(dynamicBundleIndexItemInfo.BundleHashName, out dynamicBundlePath))
                    {
                        dynamicBundleList.Add(dynamicBundleIndexItemInfo);
                    }
                    else
                    {
                        //OnDownloadedAsset(dynamicBundleIndexItemInfo.BundleHashName, null);
                        ResourceMgr.Instance.BundleMap.AddBundleIndicesByTransaction(dynamicBundleIndexItemInfo.BundleName, dynamicBundleIndexItemInfo.BundleHash, dynamicBundleIndexItemInfo.BundleDependencyArray, dynamicBundleIndexItemInfo.BundleAssetsArray, dynamicBundleIndexItemInfo.BundleSize);
                    }

                    assetNameList.Remove(assetName);
                }
            }

            List <BundleIndexItemInfo> assetBelongBundleList = RemoteBundleIndicesMap.GetBundleItemInfoListByAssetsList(assetNameList);

            for (int i = 0; i < assetBelongBundleList.Count; ++i)
            {
                BundleIndexItemInfo bundleItemInfo = DiffResult.GetAppendBundleItemInfoByBundleName(assetBelongBundleList[i].BundleName);
                if (bundleItemInfo != null)
                {
                    dynamicBundleList.Add(bundleItemInfo);
                }
            }

            return(dynamicBundleList);
        }
Exemplo n.º 6
0
        public bool Create(string path)
        {
            _name      = Path.GetFileName(path);
            _finalName = string.Empty;
            Size       = (int)EngineFileUtil.GetFileLength(path);
            MD5        = string.Empty;
            FileStream fs = new FileStream(path, FileMode.Open);

            if (null != fs)
            {
                MD5 = SysUtil.GetMD5Str(fs);
                fs.Close();
            }
            if (MD5 == string.Empty)
            {
                return(false);
            }
            return(true);
        }
Exemplo n.º 7
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();
        }