// 开始更新 private void StartHotUpdate() { // 初始化数据 _updateSetting = null; _updateConfig = null; _latest = null; _latestVersion = null; _updateList = null; _updateSize = 0; _downloadedSize = 0; _downloader = null; _updateStatus = STATUS_WORK; StartCoroutine(HotUpdate()); }
// 2.读取最新更新配置文件 private IEnumerator DownloadUpdateSetting() { if (string.IsNullOrEmpty(_updateConfig.url)) { yield break; } string url = _updateConfig.url + "?spm=" + GetRandomValue() + "&channel_id=" + ExtSDK.GetChannelID() + "&p=" + GameConfig.PLATFORM + "&v=" + GameConfig.VERSION; // Debug.Log("Updater.DownloadUpdateSetting " + url); string text = null; for (int i = 0; i < DOWNLOAD_RETRY_TIMES; i++) { WWW downloader = new WWW(url); yield return(downloader); if (downloader.error == null) { text = downloader.text; break; } yield return(new WaitForSeconds(DOWNLOAD_RETRY_DELAY)); // Debug.Log("Updater.DownloadUpdateSetting try agin"); } if (string.IsNullOrEmpty(text)) { yield break; } try { char[] _LINE_SEPARATORS = { '\r', '\n' }; string[] lines = text.Split(_LINE_SEPARATORS, StringSplitOptions.RemoveEmptyEntries); _updateSetting = new UpdateSetting(); _updateSetting.resUrl = lines[0]; _updateSetting.svrUrl = lines[1]; _updateSetting.giftUrl = lines[2]; _updateSetting.eventUrl = lines[3]; for (int i = 4; i < lines.Length; ++i) { if (string.IsNullOrEmpty(lines[i])) { continue; } string[] cols = lines[i].Split(','); VersionStatus vs = new VersionStatus(); vs.version = VersionHelper.StringToCode(cols[0]); if (vs.version == 0) { continue; } vs.platform = cols[1].Trim(); vs.status = int.Parse(cols[2]); _updateSetting.versions.Add(vs); } } catch (Exception e) { Debug.Log("DownloadUpdateSetting: " + e.Message); _updateSetting = null; } }