IEnumerator CheckUpdate() { IsStopUpdate = false; WriteLog("CheckUpdate" + _isActiveSDK); if (_isActiveSDK) { FirstPlatform.CheckUpdate(_sdkName); } yield break; }
IEnumerator WorkerFunction() { bool test = false; #if UNITY_EDITOR if (test) { if (load != null) { load.ShowAlert(123.45, OnConfirm, OnCancel); } yield break; } else { ProcessPercent = 100; _updateOk = true; Debug.Log("下载完成"); yield break; } #endif if (string.IsNullOrEmpty(_updateUrl)) { _updateOk = true; yield break; } yield return(BeginDownLoad(_updateUrl + "check.txt?id=" + (DateTime.Now.ToFileTime() / 10), 2)); string buf2 = EndDownLoadTxt(); if (string.IsNullOrEmpty(buf2) == false) { InitCheck(buf2); FirstResource.ResourceKey = FirstUtil.ApkId + "_" + FirstUtil.PackVersion; if (FirstResource.UpdateUrlDic.ContainsKey(FirstResource.ResourceKey)) { _updateUrl = FirstResource.UpdateUrlDic[FirstResource.ResourceKey]; } } FirstUtil.UpdateUrl = _updateUrl; // DateTime.ToFileTime()以100毫秒为单位。此处只取秒数。 // 用户获取此文件最新版本精确到1秒。cdn服务器理论上每小时最大产生3600个文件缓存。 yield return(BeginDownLoad(_updateUrl + "SecondVersion.txt?id=" + (DateTime.Now.ToFileTime() / 10), 2)); _secondVersion = EndDownLoadTxt(); yield return(BeginDownLoad(_updateUrl + "version.txt?id=" + (DateTime.Now.ToFileTime() / 10), 2)); string buf = EndDownLoadTxt(); if (string.IsNullOrEmpty(buf)) { _infoTips = FirstLang.FIRST_MSG_4; _updateOk = true; yield break; } if (_sdkName.Contains("IOS")) { yield return(BeginDownLoad(_updateUrl + _sdkName + "_apkversion.txt?id=" + (DateTime.Now.ToFileTime() / 10), 2)); string tempVerStr = EndDownLoadTxt(); if (string.IsNullOrEmpty(tempVerStr) == false) { _serverSdkVersion = FirstUtil.ReadAllLines(tempVerStr)[0]; int compareResult = String.Compare(_serverSdkVersion, FirstUtil.PackVersion, StringComparison.Ordinal); // 直接字符串比较,和运营保持规则一致 WriteLog("CheckAPKVersion - _localVersion:{0} _serverVersion:{1} Compare:{2}", FirstUtil.PackVersion, _serverSdkVersion, compareResult); if (compareResult > 0) { yield return(BeginDownLoad(_updateUrl + _sdkName + "_apkurl.txt?id=" + (DateTime.Now.ToFileTime() / 10), 2)); tempVerStr = EndDownLoadTxt(); if (string.IsNullOrEmpty(tempVerStr) == false) { FirstUtil.ApkUrl = FirstUtil.ReadAllLines(tempVerStr)[0]; FirstPlatform.ShowAlert(FirstLang.FIRST_MSG_15, FirstLang.FIRST_MSG_16, FirstLang.FIRST_MSG_18, FirstLang.FIRST_MSG_17, "1"); _infoTips = FirstLang.FIRST_MSG_19; ProcessPercent = 100; //apk需要更新 yield break; } } } } string svrVer = FirstUtil.ReadAllLines(buf)[0]; svrVer = svrVer.Trim(); FirstRecordMsg.game_version = svrVer; string myVer = FirstUtil.OutVersion ?? FirstUtil.PackVersion; int cmp = String.Compare(svrVer, myVer, StringComparison.Ordinal); // 直接字符串比较,和运营保持规则一致 WriteLog("CheckVer - MyVer:{0} ServerVer:{1} Compare:{2}", myVer, svrVer, cmp); if (cmp == 0 || svrVer == "0") //版本号不等需要更新 { ProcessPercent = 100; _updateOk = true; yield break; } foreach (object o in DownloadUpdate(svrVer)) { if (o == null) { yield break; } yield return(o); } }