private void InitData() { string[] arr = FirstUtil.ReadAllLines(outLocalVersion); foreach (string line in arr) { string[] row = line.Split('='); if (row.Length < 2) { continue; } string value = row[1].Trim(); switch (row[0].Trim()) { case "version": FirstUtil.OutVersion = value; break; } } arr = FirstUtil.ReadAllLines(outLocalGameDefine); foreach (string line in arr) { string[] row = line.Split('='); if (row.Length < 2) { continue; } string value = row[1].Trim(); switch (row[0].Trim()) { case "update_url": #if !UNITY_EDITOR _updateUrl = value; #endif break; case "isAc": _isActiveSDK = value != "FYMM"; break; case "isShowLog": FirstUtil.IsShowLog = (value == "FYMM"); break; case "isPlayMovie": _isPlayMovie = int.Parse(value); break; } } if (_isNewApk && _isPlayMovie == 1) { PlayMovie(); } }
static void _ReadFileList(out Dictionary <string, string> dic, string text) { dic = new Dictionary <string, string>(); foreach (string line in FirstUtil.ReadAllLines(text)) { string[] row = line.Split('\t'); if (row.Length == 2) { dic.Add(row[0], row[1]); } } }
void parseSizeFile(string text) { string[] arr = FirstUtil.ReadAllLines(text); foreach (string line in arr) { string[] row = line.Split('\t'); if (row.Length == 2) { _fielSizeDic.Add(row[0], int.Parse(row[1])); } else if (row.Length == 3) { _fielSizeDic.Add(row[0], int.Parse(row[1])); } } }
void InitCheck(string txt) { string[] allLines = FirstUtil.ReadAllLines(txt); foreach (string line in allLines) { string[] row = line.Split(';'); if (row.Length < 2) { if (line.Contains("updateCustomServer")) { string temp = line.Replace("updateCustomServer,", ""); var arr = temp.Split(','); if (arr.Length > 1) { FirstUtil.NeedToUpdateServerList = new List <int>(); for (int i = 1; i < arr.Length; i++) { FirstUtil.NeedToUpdateServerList.Add(int.Parse(arr[i])); } int selectServerId = PlayerPrefs.GetInt(FirstUtil.SelectServerKey, -1); if (FirstUtil.NeedToUpdateServerList.Contains(selectServerId)) { _updateUrl = arr[0]; //替换掉更新url FirstUtil.IsUrlChange = true; } } } continue; } if (row.Length >= 2) { FirstResource.UpdateUrlDic[row[0]] = row[1]; } if (row.Length >= 3) { FirstResource.ServerListDic[row[0]] = row[2]; } } }
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); } }
//gamedefine 可能会被热更,但是有些变量值是永远不变,所以取包里的值 private void InitLocalInfo() { string[] arr = FirstUtil.ReadAllLines(localGameDefine); foreach (string line in arr) { string[] row = line.Split('='); if (row.Length < 2) { continue; } string value = row[1].Trim(); switch (row[0].Trim()) { case "SDKName": _sdkName = value; FirstUtil.SDKName = value; break; case "id": FirstUtil.ApkId = value; break; case "platform": #if UNITY_ANDROID || UNITY_EDITOR FirstUtil.platform = "Android"; #elif UNITY_IOS FirstUtil.platform = "IOS"; #elif UNITY_STANDALONE FirstUtil.platform = "PC"; #elif UNITY_WEBPLAYER FirstUtil.platform = "WEB"; #endif break; case "update_url": _updateUrl = value; break; case "isShowLog": FirstUtil.IsShowLog = (value == "FYMM"); break; } } arr = FirstUtil.ReadAllLines(localVersion); foreach (string line in arr) { string[] row = line.Split('='); if (row.Length < 2) { continue; } string value = row[1].Trim(); switch (row[0].Trim()) { case "version": FirstUtil.PackVersion = value; break; } } }