//找到可以更新的最大资源版本号 public static string FindMaxUpdateResVer(this ServerConfigComponent self, string engine_ver, string channel) { if (string.IsNullOrEmpty(engine_ver) || self.m_resUpdateList == null || !self.m_resUpdateList.TryGetValue(engine_ver, out var resVerList)) { return(null); } if (resVerList == null) { return(null); } var verList = new List <string>(); foreach (var item in resVerList) { verList.Add(item.Key); } verList.Sort((a, b) => { return(-VersionCompare.Compare(a, b)); }); string last_ver = ""; for (int i = 0; i < verList.Count; i++) { var info = resVerList[verList[i]]; if (self.IsStrInList(channel, info.channel) && self.IsInTailNumber(info.update_tailnumber)) { last_ver = verList[i]; break; } } return(last_ver); }
//找到可以更新的最大app版本号 public static string FindMaxUpdateAppVer(this ServerConfigComponent self, string channel) { if (self.m_appUpdateList == null) { return(null); } string last_ver = null; if (self.m_appUpdateList.TryGetValue(channel, out var data)) { foreach (var item in data.app_ver) { if (last_ver == null) { last_ver = item.Key; } else { if (VersionCompare.Compare(item.Key, last_ver) > 0) { last_ver = item.Key; } } } } return(last_ver); }
void InitAppVersion() { string outputPath = Path.Combine(Application.persistentDataPath, "version.txt"); GameUtility.CheckFileAndCreateDirWhenNeeded(outputPath); var persistentAppVersion = GameUtility.SafeReadAllText(outputPath); if (persistentAppVersion == null) { GameUtility.SafeWriteAllText(outputPath, Application.version); return; } Debug.Log(string.Format("app_ver = {0}, persistentAppVersion = {1}", Application.version, persistentAppVersion)); // 如果persistent目录版本app版本低,说明是大版本覆盖安装,清理过时的缓存 if (!string.IsNullOrEmpty(persistentAppVersion) && VersionCompare.Compare(persistentAppVersion, Application.version) < 0) { var path = AssetBundleUtility.GetPersistentDataPath(); GameUtility.SafeDeleteDir(path); var path1 = AssetBundleUtility.GetCatalogDataPath(); GameUtility.SafeDeleteDir(path1); } GameUtility.SafeWriteAllText(outputPath, Application.version); }
//资源更新检查,并根据版本来修改资源cdn地址 public static async ETTask <bool> CheckResUpdate(this UIUpdateView self) { var app_channel = PlatformUtil.GetAppChannel(); var engine_ver = AssetBundleConfig.Instance.EngineVer; var maxVer = ServerConfigComponent.Instance.FindMaxUpdateResVer(engine_ver, app_channel); if (string.IsNullOrEmpty(maxVer)) { Log.Info("CheckResUpdate No Max Ver EngineVer = " + engine_ver + " app_channel " + app_channel); return(false); } var res_ver = AssetBundleConfig.Instance.ResVer; var flag = VersionCompare.Compare(res_ver, maxVer); Log.Info("CheckResUpdate ResVer:{0} maxVer:{1}", res_ver, maxVer); if (flag >= 0) { Log.Info("CheckResUpdate ResVer is Most Max Version, so return; flag = " + flag); return(false); } // 编辑器下不能测试热更,但可以测试下载。 if (Define.IsEditor) { return(false); } //找到最新版本,则设置当前资源存放的cdn地址 var url = ServerConfigComponent.Instance.GetUpdateCdnResUrlByVersion(maxVer); self.m_rescdn_url = url; Log.Info("CheckResUpdate res_cdn_url is " + url); AssetBundleMgr.GetInstance().SetAddressableRemoteResCdnUrl(self.m_rescdn_url); //等一会等addressables的Update回调执行完 await TimerComponent.Instance.WaitAsync(1); //检查更新版本 Log.Info("begin CheckCatalogUpdates"); var catalog = await self.CheckCatalogUpdates(); Log.Info("CheckResUpdate CataLog = " + catalog); //1、先更新catalogs if (!string.IsNullOrEmpty(catalog)) { Log.Info("begin UpdateCatalogs"); var res = await self.UpdateCatalogs(catalog); if (!res) { return(false); } Log.Info("CoCheckResUpdate Update Catalog Success"); } Log.Info("begin GetDownloadSize"); //获取需要更新的大小 var size = await self.GetDownloadSize(); //提示给用户 Log.Info("downloadSize " + size); double size_mb = size / (1024f * 1024f); Log.Info("CheckResUpdate res size_mb is " + size_mb);//不屏蔽 if (size_mb > 0 && size_mb < 0.01) { size_mb = 0.01; } var ct = I18NComponent.Instance.I18NGetParamText("Update_Info", size_mb.ToString("0.00")); var btnState = await self.ShowMsgBoxView(ct, "Global_Btn_Confirm", "Btn_Exit"); if (btnState == self.BTN_CANCEL) { if (self.force_update) { GameUtility.Quit(); return(false); } return(true); } //开始进行更新 self.last_progress = 0; self.SetProgress(0); //2、更新资源 var merge_mode_union = 1; var needdownloadinfo = await self.CheckUpdateContent(merge_mode_union); Log.Info("needdownloadinfo count: ", needdownloadinfo.Count); self.m_needdownloadinfo = SortDownloadInfo(needdownloadinfo); Log.Info("CheckResUpdate DownloadContent begin"); bool result = await self.DownloadContent(); if (!result) { return(false); } Log.Info("CheckResUpdate DownloadContent Success"); return(true); }
async static ETTask <bool> CheckAppUpdate(this UIUpdateView self) { var app_channel = PlatformUtil.GetAppChannel(); var channel_app_update_list = ServerConfigComponent.Instance.GetAppUpdateListByChannel(app_channel); if (channel_app_update_list == null || channel_app_update_list.app_ver == null) { Log.Info("CheckAppUpdate channel_app_update_list or app_ver is nil, so return"); return(false); } var maxVer = ServerConfigComponent.Instance.FindMaxUpdateAppVer(app_channel); if (string.IsNullOrEmpty(maxVer)) { Log.Info("CheckAppUpdate maxVer is nil"); return(false); } var app_ver = Application.version; var flag = VersionCompare.Compare(app_ver, maxVer); Log.Info(string.Format("CoCheckAppUpdate AppVer:{0} maxVer:{1}", app_ver, maxVer)); if (flag >= 0) { Log.Info("CheckAppUpdate AppVer is Most Max Version, so return; flag = " + flag); return(false); } var app_url = channel_app_update_list.app_url; var verInfo = channel_app_update_list.app_ver[app_ver]; Log.Info("CheckAppUpdate app_url = " + app_url); self.force_update = Define.ForceUpdate; if (Define.ForceUpdate)//默认强更 { if (verInfo != null && verInfo.force_update == 0) { self.force_update = false; } } else { if (verInfo != null && verInfo.force_update != 0) { self.force_update = true; } } var cancelBtnText = self.force_update ? "Btn_Exit" : "Btn_Enter_Game"; var content_updata = self.force_update ? "Update_ReDownload" : "Update_SuDownload"; var btnState = await self.ShowMsgBoxView(content_updata, "Global_Btn_Confirm", cancelBtnText); if (btnState == self.BTN_CONFIRM) { GameUtility.OpenURL(app_url); //为了防止切换到网页后回来进入了游戏,所以这里需要继续进入该流程 return(await self.CheckAppUpdate()); } else if (self.force_update) { Log.Info("CheckAppUpdate Need Force Update And User Choose Exit Game!"); GameUtility.Quit(); return(true); } return(false); }