/// <summary> /// 解析版本文件 /// </summary> /// <param name="txt"></param> /// <param name="versionFile"></param> public static void ParseVersionFile(string txt, ref VersionFileModel versionFile) { string[] content = txt.Split('\n'); if (content != null) { if (versionFile == null) { versionFile = new VersionFileModel(); } for (int i = 0; i < content.Length - 1; i++) { if (!string.IsNullOrEmpty(content[i])) { string[] kvp = content[i].Split(','); if (kvp == null || kvp.Length < 3) { Debug.LogError("Can not parse last update file with content " + content[i]); return; } versionFile.FilesDic[kvp[0]] = new VersionFileInfo(kvp[1], Convert.ToInt32(kvp[2])); } } versionFile.ResVersion = Convert.ToInt32(content[content.Length - 1]); } }
/// <summary> /// 转换版本文件为String /// </summary> /// <param name="versionFile"></param> /// <returns></returns> public static string ConvertVersionFileToString(VersionFileModel versionFile) { StringBuilder sb = new StringBuilder(); foreach (KeyValuePair <string, VersionFileInfo> pair in versionFile.FilesDic) { string content = string.Format("{0},{1},{2}\n", pair.Key, pair.Value.md5, pair.Value.version); sb.Append(content); } sb.Append(versionFile.ResVersion); return(sb.ToString()); }
/// <summary> /// 加载版本文件 /// </summary> /// <returns></returns> private static VersionFileModel LoadDiffVersionFile() { s_versionFile = new VersionFileModel(); if (File.Exists(s_versionDiffFilePath)) { try { string content = File.ReadAllText(s_versionDiffFilePath); FileHelper.ParseVersionFile(content, ref s_versionFile); } catch (Exception ex) { throw new Exception("Load UpdateFile Error:" + ex.Message); } } return(s_versionFile); }
/// <summary> /// 下载文件 /// </summary> /// <param name="index"></param> /// <param name="delay"></param> private void DownloadUpdateFiles(int index, float delay = -1) { if (index >= m_needUpdateFileList.Count) { //下载完所有更新文件之后,写入新的updateFile m_versionFileOnClient = m_versionFileOnServer; WriteVersionFile(); return; } Debug.Log("Begin download update files " + m_needUpdateFileList[index]); int version = m_versionFileOnServer.FilesDic[m_needUpdateFileList[index]].version; string downloadUrl = string.Format("{0}/{1}/{2}", m_serverResult.DownloadBaseUrl, version, m_needUpdateFileList[index]); DownloadMgr.Instance.Download(downloadUrl, OnUpdateFileDownloadFinised); }