Ejemplo n.º 1
0
        public ABVersionEntry GetEntry(string rABName)
        {
            if (this.Entries == null)
            {
                return(null);
            }
            ABVersionEntry rEntry = null;

            this.Entries.TryGetValue(rABName, out rEntry);
            return(rEntry);
        }
Ejemplo n.º 2
0
        public void AddEntry(LoaderSpace rLoaderSpace, ABVersionEntry rAVEntry)
        {
            ABLoadEntry rABLoadInfo = new ABLoadEntry();

            rABLoadInfo.ABPath = GetABPath_With_Space(rLoaderSpace, rAVEntry.Name);
            rABLoadInfo.ABName = rAVEntry.Name;
            List <string> rDependABs = new List <string>(rAVEntry.Dependencies);

            rABLoadInfo.ABDependNames   = rDependABs.ToArray();
            rABLoadInfo.IsLoading       = false;
            rABLoadInfo.IsLoadCompleted = false;
            rABLoadInfo.CacheAsset      = null;
            rABLoadInfo.RefCount        = 0;

            this.Entries.Add(rAVEntry.Name, rABLoadInfo);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 开始从服务器更新资源
        /// </summary>
        private async Task UpdateResource_Sync()
        {
            GameLoading.Instance.StartLoading("游戏初始化阶段,开始下载更新的资源...");

            // 加载服务器的版本信息文件
            var rServerVersionRequest = await ABVersion.Download(ABPlatform.Instance.GetServerUrl_CurPlatform(ABVersion.ABVersion_File_Bin));

            mServerVersion = rServerVersionRequest.Version;

            if (mServerVersion == null)
            {
                return;
            }

            // 比较两个空间的版本信息
            List <ABVersionEntry> rNeedUpdateEntries = new List <ABVersionEntry>();

            foreach (var rPair in mServerVersion.Entries)
            {
                var rServerAVEntry = rPair.Value;

                if (mPersistentVersion != null)
                {
                    var rPersistentAVEntry = mPersistentVersion.GetEntry(rServerAVEntry.Name);
                    if (rPersistentAVEntry == null || rServerAVEntry.Version > rPersistentAVEntry.Version)
                    {
                        rNeedUpdateEntries.Add(rServerAVEntry);
                    }
                }
                else
                {
                    rNeedUpdateEntries.Add(rServerAVEntry);
                }
            }

            if (mPersistentVersion == null)
            {
                mPersistentVersion         = new ABVersion();
                mPersistentVersion.Entries = new Dict <string, ABVersionEntry>();
            }

            for (int i = 0; i < rNeedUpdateEntries.Count; i++)
            {
                GameLoading.Instance.SetTips(string.Format("游戏初始化阶段,开始下载更新的资源[{0}/{1}]...", i + 1, rNeedUpdateEntries.Count));

                // 下载文件
                var rServerABRequest = await WebRequestAssist.DownloadFile(ABPlatform.Instance.GetServerUrl_CurPlatform(rNeedUpdateEntries[i].Name), GameLoading.Instance.SetLoadingProgress);

                // 写入文件
                string rPersisentFilePath = ABPlatform.Instance.GetPersistentFile_CurPlatform(rNeedUpdateEntries[i].Name);
                UtilTool.WriteAllBytes(rPersisentFilePath, rServerABRequest.Bytes);
                Debug.Log("--- Save ab: " + rPersisentFilePath);

                // 保存修改后的Persistent空间的文件
                var rPersistentAVEntry = mPersistentVersion.GetEntry(rNeedUpdateEntries[i].Name);
                if (rPersistentAVEntry == null)
                {
                    rPersistentAVEntry = new ABVersionEntry();
                    mPersistentVersion.Entries.Add(rNeedUpdateEntries[i].Name, rPersistentAVEntry);
                }
                rPersistentAVEntry.Name         = rNeedUpdateEntries[i].Name;
                rPersistentAVEntry.Size         = rNeedUpdateEntries[i].Size;
                rPersistentAVEntry.Version      = rNeedUpdateEntries[i].Version;
                rPersistentAVEntry.MD5          = rNeedUpdateEntries[i].MD5;
                rPersistentAVEntry.Dependencies = new List <string>(rNeedUpdateEntries[i].Dependencies).ToArray();

                string rPersistentVersionPath    = ABPlatform.Instance.GetPersistentFile_CurPlatform(ABVersion.ABVersion_File_Bin);
                string rPersistentVersionDirPath = Path.GetDirectoryName(rPersistentVersionPath);
                if (!Directory.Exists(rPersistentVersionDirPath))
                {
                    Directory.CreateDirectory(rPersistentVersionDirPath);
                }

                mPersistentVersion.Save(rPersistentVersionPath);
                Debug.Log("--- Save version: " + rPersistentVersionPath);
            }

            // 保存服务器上的MD5文件
            string rPersistentMD5Path = ABPlatform.Instance.GetPersistentFile_CurPlatform(ABVersion.ABVersion_File_MD5);

            UtilTool.WriteAllText(rPersistentMD5Path, mServerMD5);
            Debug.Log("--- Save md5: " + rPersistentMD5Path);

            GameLoading.Instance.Hide();
        }