public bool CheckVersion(string xml) { XmlDocument doc = new XmlDocument(); if (doc == null) { return(false); } doc.LoadXml(xml); XmlElement ele = doc.DocumentElement; if (ele == null) { return(false); } XmlNode nodeVer = ele.SelectSingleNode("Net"); if (nodeVer == null) { return(false); } string resftp = nodeVer.Attributes["resftp"].Value; string runftp = nodeVer.Attributes["runftp"].Value; string clientUrl = nodeVer.Attributes["clienturl"].Value; if (nodeVer.Attributes["ftpport"] != null) { ServerSetting.ResFtpPort = ushort.Parse(nodeVer.Attributes["ftpport"].Value); } ServerSetting.SetRunFTP(runftp); ServerSetting.ServerList.Clear(); for (int i = 0; i < nodeVer.ChildNodes.Count; ++i) { XmlNode node = nodeVer.ChildNodes[i]; if (node.Name == "IP") { ServerIPData sid = new ServerIPData(); sid.IP = node.FirstChild.Value; sid.Port = ushort.Parse(node.Attributes["port"].Value); ServerSetting.ServerList.Add(sid); } else if (node.Name == "FTP") { ServerIPData rfd = new ServerIPData(); rfd.IP = node.FirstChild.Value; rfd.Port = ushort.Parse(node.Attributes["port"].Value); rfd.ISP = byte.Parse(node.Attributes["dx"].Value); m_ResFtpList.Add(rfd); } } ServerSetting.SERVICES_URL = "";// ele.SelectSingleNode("Services").FirstChild.Value; XmlNode reporterNode = ele.SelectSingleNode("Reporter"); if (reporterNode != null) { ServerSetting.ReporterIP = reporterNode.FirstChild.Value; ServerSetting.ReporterPort = ushort.Parse(reporterNode.Attributes["port"].Value); } XmlNode ShareNode = ele.SelectSingleNode("Share"); if (ShareNode != null) { string wxid = "", wxpwd = "", sinaid = "", sinapwd = "", qqid = "", qqpwd = ""; XmlNode xn = ShareNode.ChildNodes[0]; if (xn != null) { wxid = xn.Attributes["id"].Value; wxpwd = xn.Attributes["pwd"].Value; } xn = ShareNode.ChildNodes[1]; if (xn != null) { sinaid = xn.Attributes["id"].Value; sinapwd = xn.Attributes["pwd"].Value; } xn = ShareNode.ChildNodes[2]; if (xn != null) { qqid = xn.Attributes["id"].Value; qqpwd = xn.Attributes["pwd"].Value; } NativeInterface.InitShare(wxid, wxpwd, sinaid, sinapwd, qqid, qqpwd); xn = ShareNode.ChildNodes[3]; if (xn != null) { ServerSetting.ShareWebUrl = xn.Attributes["weburl"].Value; ServerSetting.ShareTxt = xn.Attributes["txt"].Value; ServerSetting.ShareImgUrl = xn.Attributes["imgurl"].Value; } } //读取现有的资源,进行比较 XmlNode clientNode = ele.SelectSingleNode("Client"); string clientVer = clientNode.FirstChild.Value;; uint clientCrc = uint.Parse(clientNode.Attributes["crc"].Value); uint clientSize = uint.Parse(clientNode.Attributes["size"].Value); if (clientNode.Attributes["resver"] != null) { ServerSetting.RES_VERSION = uint.Parse(clientNode.Attributes["resver"].Value); } if (clientNode.Attributes["ping"] != null) { ServerSetting.SHOW_PING = uint.Parse(clientNode.Attributes["ping"].Value) != 0; } if (clientNode.Attributes["extrabtn"] != null) { ServerSetting.ShowExtraBtn = uint.Parse(clientNode.Attributes["extrabtn"].Value) != 0; } if (clientNode.Attributes["ftp_newftp"] != null) { FTPClient.USE_NEW_FTP = byte.Parse(clientNode.Attributes["ftp_newftp"].Value); } if (clientNode.Attributes["showgame"] != null) { ServerSetting.ShowGame = byte.Parse(clientNode.Attributes["showgame"].Value) != 0; } if (clientNode.Attributes["ftp_chunkcount"] != null) { FTPClient.MAX_CHUNK_COUNT = byte.Parse(clientNode.Attributes["ftp_chunkcount"].Value); } if (clientNode.Attributes["ftp_chunksize"] != null) { FTPClient.CHUNK_SIZE = int.Parse(clientNode.Attributes["ftp_chunksize"].Value); } if (clientNode.Attributes["thirdbtn"] != null) { ServerSetting.ShowHallThirdBtn = int.Parse(clientNode.Attributes["thirdbtn"].Value) != 0; } if (clientNode.Attributes["exchange"] != null) { ServerSetting.ShowExchange = int.Parse(clientNode.Attributes["exchange"].Value) != 0; } if (clientNode.Attributes["showjbp"] != null) { ServerSetting.ShowJBP = int.Parse(clientNode.Attributes["showjbp"].Value) != 0; } if (clientNode.Attributes["showmatch"] != null) { ServerSetting.ShowMatch = int.Parse(clientNode.Attributes["showmatch"].Value) != 0; } if (clientNode.Attributes["showthirdlogin"] != null) { ServerSetting.ShowThirdLoginBtn = int.Parse(clientNode.Attributes["showthirdlogin"].Value) != 0; } m_State = UpdateState.UPDATE_COMPLETE; //检查客户端版本号 if (clientVer == null) { return(false); } uint ver = Utility.VersionToUint(clientVer); if (ver > ServerSetting.ClientVer) { //clientUrl = ReplaceFTPAddress(clientUrl); //版本更新 if (RuntimeInfo.GetPlatform() == GamePlatformType.Android) { if (CheckClientFile(clientCrc)) { //文件已经下载完成。 //NativeInterface.DownNewClientVersion(GetClientPath()); } else { //下载资源文件 DownResData drd = new DownResData(); drd.ResType = ResType.MAX; drd.ResUrl = clientUrl; drd.ResCrc = clientCrc; drd.ResSize = clientSize; m_DownList.Add(drd); m_State = UpdateState.UPDATE_DOWNLOAD_RES; m_AllDownloadBytes += clientSize; } m_bNewClient = true; } else if (RuntimeInfo.GetPlatform() == GamePlatformType.Windows) { m_WinSizeList = new int[5]; for (int i = 0; i < 5; ++i) { string str = "winsize" + (i + 1).ToString(); if (clientNode.Attributes[str] != null) { m_WinSizeList[i] = int.Parse(clientNode.Attributes[str].Value); } } DownResData drd = new DownResData(); drd.ResType = ResType.MAX; drd.ResUrl = clientUrl; drd.ResCrc = clientCrc; drd.ResSize = clientSize; m_DownList.Add(drd); m_State = UpdateState.UPDATE_DOWNLOAD_RES; m_AllDownloadBytes += clientSize; m_bNewClient = true; } else { NativeInterface.DownNewClientVersion(clientUrl); m_State = UpdateState.UPDATE_NEW_CLIENT; return(true); } } for (int i = 0; i < (int)ResManager.RES_NUM; ++i) { ResType rt = (ResType)i; XmlNode node = ele.SelectSingleNode(rt.ToString()); DownResData vd = new DownResData(); vd.ResCrc = uint.Parse(node.Attributes["crc"].Value); vd.ResUnzipSize = uint.Parse(node.Attributes["unzipsize"].Value); if (ResManager.Instance.VersionMgr.CheckVerAndCrc(rt, vd.ResCrc, vd.ResUnzipSize)) { //下载资源文件 vd.ResType = rt; vd.ResUrl = resftp + node.Attributes["url"].Value; vd.ResSize = uint.Parse(node.Attributes["size"].Value); m_DownList.Add(vd); m_AllDownloadBytes += vd.ResSize; } } //保存当前的RES_VERSION if (m_DownList.Count > 0) { m_State = UpdateState.UPDATE_DOWNLOAD_RES; return(true); } else { return(true); } }
public void Update(float delta) { if (m_bError) { NativeInterface.ShowMsgAndExit("res_save_error", 109); return; } if (m_ActiveDown != null) { if (m_ActiveDown.Type == DownloadType.DOWNLOAD_MULTI_FILE && m_ActiveDown.DownloadBytes != 0) { } else { m_UpdateUI.SetIsQueue(m_ActiveDown.IsQueue, m_ActiveDown.Type == DownloadType.DOWNLOAD_CHECK_VER); } if (m_ActiveDown.IsQueue) { m_UpdateTick = Utility.GetTickCount(); } } switch (m_State) { case UpdateState.UPDATE_CHECK_LOCALVER: CheckLocalFile(); break; case UpdateState.UPDATE_UNZIPING_FILE: CheckUnzipping(); break; case UpdateState.UPDATE_INIT: m_UpdateTick = Utility.GetTickCount(); string ftpurl = RuntimeInfo.GetFTPVersionURL(); m_ActiveDown = FTPClient.Instance.AddDownload(DownloadType.DOWNLOAD_CHECK_VER, ftpurl, null); m_State = UpdateState.UPDATE_DOWNLOAD_VERSION; break; case UpdateState.UPDATE_DOWNLOAD_VERSION: if (m_ActiveDown.IsOK) { m_RetryCount = 0; string xml = m_ActiveDown.Text; m_ActiveDown = null; if (!CheckVersion(xml)) { NativeInterface.ShowMsgAndExit("update_error", 101); } } else if (m_ActiveDown.HasError) { //出错了 if (++m_RetryCount > MAX_RETRY_COUNT) { NativeInterface.ShowMsgAndExit("res_connect_error", 102); } else { m_State = UpdateState.UPDATE_INIT; m_ActiveDown = null; } } else { if (m_ActiveDown.IsQueue == false && Utility.GetTickCount() - m_UpdateTick > UPDATE_VERSION_TIME_OUT) { NativeInterface.ShowMsgAndExit("res_connect_error", 103); } } break; case UpdateState.UPDATE_DOWNLOAD_RES: if (m_ActiveDown == null) { if (m_DownList.Count > 0) { m_DownloadBytes = 0; m_UpdateTick = Utility.GetTickCount(); m_UpdateUI.BeginDown(ResType.FishRes); m_ActiveDown = FTPClient.Instance.AddMultiResDownload(DownloadType.DOWNLOAD_MULTI_FILE, m_ResFtpList, m_DownList); m_RecvFileCount = m_DownList.Count; m_DownList.Clear(); } else { m_State = UpdateState.UPDATE_COMPLETE; } } else if (m_ActiveDown.IsOK) { m_RetryCount = 0; m_CurrentDownloadBytes += m_ActiveDown.DownloadBytes; m_DownloadBytes = 0; //m_ThreadList.AddItem(m_ActiveDown); SaveDownloadData(m_ActiveDown); m_ActiveDown = null; } else if (m_ActiveDown.HasError) { NativeInterface.ShowMsgAndExit("update_error", 105); } else { if (m_ActiveDown.IsQueue) { //排队中 } else if (m_DownloadBytes != m_ActiveDown.DownloadBytes) { m_DownloadBytes = m_ActiveDown.DownloadBytes; m_UpdateTick = Utility.GetTickCount(); MultiFileDownData mfdd = (MultiFileDownData)m_ActiveDown.Data; if (mfdd.OutsideRecvIndex < mfdd.RecvCount) { SaveDownloadData(m_ActiveDown); } } else if (Utility.GetTickCount() - m_UpdateTick > UPDATE_RES_TIME_OUT) { NativeInterface.ShowMsgAndExit("update_error", 106); } } break; case UpdateState.UPDATE_COMPLETE: //if (m_DownloadCompletionCount != m_DownloadOrgCount) //{ // m_UpdateUI.SetUnzipping(); // return; //} //更新完成,进入下一个逻辑 if (m_SaveCount != m_RecvFileCount) { return; } if (m_bNewClient) { if (RuntimeInfo.GetPlatform() == GamePlatformType.Android) { NativeInterface.DownNewClientVersion(GetClientPath()); } else if (RuntimeInfo.GetPlatform() == GamePlatformType.Windows) { NativeInterface.ShowMsgAndExit("update_restart", 0); } else { NativeInterface.DownNewClientVersion(m_NewClientURL); } } else { LogicManager.Instance.Forward(null); } break; case UpdateState.UPDATE_NEW_CLIENT: LogicManager.Instance.Shutdown(); break; } }