public static DownloadTaskErrorCode FetchByUrl(string url, string destFile, int timeout, out string errMsg) { if (!FileOperate.MakeDir(destFile)) { Common.HobaDebuger.LogWarning(HobaText.Format("[FetchByUrl] MakeDir {0} Failed!", destFile)); } if (FileOperate.IsFileExist(destFile)) { FileOperate.DeleteFile(destFile); } string hostName = UpdateUtility.GetHostName(url); var code = UpdateUtility.GetByUrl( url, hostName, destFile, timeout, //10s null, null, out errMsg); return(code); }
/// <summary> /// 根据ID删除模型中的数据 /// </summary> /// <param name="Info"></param> public void ModelDelete(HXD.ModelField.Model.Model Info) { try { DataSet ds = HXD.DBUtility.SQLHelper.ExecuteDataset("select * from " + Info.TableName + " where id in(" + Info.Temp + ")"); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { for (int c = 0; c < ds.Tables[0].Columns.Count; c++) { if (ds.Tables[0].Rows[i][c].ToString().IndexOf("/") == 0 && ds.Tables[0].Rows[i][c].ToString().Length > 30) { string[] files = ds.Tables[0].Rows[i][c].ToString().Split(','); for (int k = 0; k < files.Length; k++) { if (files[k].IndexOf("/") == 0) { HXD.Common.Utils.DelThumbnail(files[k]); //删除所有缩略图文件 FileOperate.DeleteFile(files[k]); //删除原始文件 } } } if (ds.Tables[0].Rows[i][c].ToString().Length > 30) { FileOperate.GetImgTag(ds.Tables[0].Rows[i][c].ToString());//删除内容中的图片 //FileOperate.DelFiles(ds.Tables[0].Rows[i][c].ToString(), "url", "flv");//删除内容中的Flv } } } SQLHelper.ExecuteNonQuery("ModelDelete", Info.Temp, Info.TableName); } catch { } }
//更新服务器列表 public static UpdateRetCode ParseRoleList(string account, string roleListFile, List <AccountRoleInfo> roleList, List <ServerInfo> testServerList) { try { StreamReader reader = FileOperate.OpenTextFile(roleListFile); if (reader == null) { return(UpdateRetCode.role_list_no_file); } string text = reader.ReadToEnd(); reader.Close(); string ext = Path.GetExtension(roleListFile); if (ext != null && ext.ToLower() == ".json") // Unity官方说 string.Equals效率优于string.Compare { if (!AccountRoleInfo.ParseFromJsonString(account, text, roleList, testServerList)) { return(UpdateRetCode.role_list_parse_err); } } else { FileOperate.DeleteFile(roleListFile); return(UpdateRetCode.role_list_parse_err); } } catch (Exception e) { Common.HobaDebuger.LogErrorFormat("An Exception was raised when ParseRoleList, {0}", e); return(UpdateRetCode.role_list_parse_err); } return(UpdateRetCode.success); }
//从服务器下载 version.txt 到 strGameNewVerFile public DownloadTaskErrorCode FetchServerVersionFile(string url, string hostName, string savedFile, int timeout, out string errMsg) { if (!FileOperate.MakeDir(savedFile)) { LogString(HobaText.Format("[FetchServerVersionFile] MakeDir {0} Failed!", savedFile)); } if (FileOperate.IsFileExist(savedFile)) { FileOperate.DeleteFile(savedFile); } //测试 // int filesize2 = (int)SeasideResearch.LibCurlNet.External.CURL_GetUrlFileSize(url, timeout); // LogString(HobaString.Format("c++ url FileSize: {0}, fileSize: {1}", url, filesize2)); // // int filesize = (int)UpdateUtility.GetUrlFileSizeEx(url, hostName, timeout); // LogString(HobaString.Format("url FileSize: {0}, fileSize: {1}", url, filesize)); var code = UpdateUtility.GetByUrl( url, hostName, savedFile, timeout, //10s null, null, out errMsg); return(code); }
//解析服务器版本信息 public UpdateRetCode TryGetLatestVersionFromServer() { UpdateRetCode code = UpdateRetCode.success; try { StreamReader reader = FileOperate.OpenTextFile(strGameNewVerFile); if (reader == null) { return(UpdateRetCode.patcher_no_ver_file); } if (!m_VersionMan.LoadVersions(reader)) { reader.Close(); code = UpdateRetCode.patcher_invalid_ver_file; FileOperate.DeleteFile(strGameNewVerFile); } else { reader.Close(); } } catch (Exception) { code = UpdateRetCode.patcher_ver_err; } return(code); }
protected void myGrid_ItemCommand(object source, DataGridCommandEventArgs e) { if (e.CommandName == "del") { bll.DeleteNew(Convert.ToInt32(e.CommandArgument)); HiddenField hf_img = e.Item.Cells[7].FindControl("hf_img") as HiddenField; FileOperate.DeleteFile(Server.MapPath("~/" + hf_img.Value)); } PageInit(); }
IEnumerable RequestAccountRoleListCoroutine(string account, Action <bool> callback) { var patcher = Patcher.Instance; if (patcher.AccoutRoleListResult.IsRunning) { Common.HobaDebuger.LogWarning("RequestAccountRoleListCoroutine Start Failed, AccountRoleList Downloading"); yield break; } _AccountRoleInfoList.Clear(); _TestServerInfoList.Clear(); AccountRoleInfo.ResetOrderZoneId(); string url = patcher.strDynamicAccountRoleDir + account; string hostName = patcher.strDynamicServerHostName; string jsonFile = patcher.strAccountRoleListJSON; FileOperate.DeleteFile(jsonFile); //Common.HobaDebuger.LogWarning("Start DownloadAccountListFile"); patcher.DownloadAccountListFile(url, hostName, jsonFile); //开启线程从中心服下载JSON文件 while (patcher.AccoutRoleListResult.IsRunning) { yield return(null); } //Common.HobaDebuger.LogWarning("End DownloadAccountListFile"); patcher.OnDynamicDownloadComplete(); bool isSuccessful = true; var dlCode = patcher.AccoutRoleListResult.ErrorCode; if (dlCode != Downloader.DownloadTaskErrorCode.Success) { // 下载失败 Common.HobaDebuger.LogWarningFormat("DownloadAccountRoleListFile Failed! DownloadTaskErrorCode: {0} {1}", dlCode, patcher.AccoutRoleListResult.ErrMsg); isSuccessful = false; } else { var code = Patcher.ParseRoleList(account, jsonFile, _AccountRoleInfoList, _TestServerInfoList); if (code != UpdateRetCode.success) { // 解析失败 Common.HobaDebuger.LogWarningFormat("Read AccountRoleJson Failed!"); isSuccessful = false; } } if (callback != null) { callback(isSuccessful); } }
protected void btn_del_Click(object sender, EventArgs e) { #region 批量删除 foreach (DataGridItem item in myGrid.Items) { //循环判断是否选中,选中则获取id CheckBox cb = (CheckBox)item.Cells[1].FindControl("chkdg"); if (cb.Checked) { bll.DeleteNew(Convert.ToInt32(item.Cells[0].Text)); HiddenField hf_img = item.Cells[7].FindControl("hf_img") as HiddenField; FileOperate.DeleteFile(Server.MapPath("~/" + hf_img.Value)); } } PageInit(); #endregion }
//更新服务器列表 public static UpdateRetCode ParseServerList(string serverListFile, List <ServerInfo> serverList) { UpdateRetCode code = UpdateRetCode.success; try { StreamReader reader = FileOperate.OpenTextFile(serverListFile); if (reader == null) { return(UpdateRetCode.server_list_no_file); } string text = reader.ReadToEnd(); reader.Close(); string ext = Path.GetExtension(serverListFile); if (ext != null && ext.ToLower() == ".xml") { if (!ServerInfo.ParseFromXmlString(text, serverList)) { code = UpdateRetCode.server_list_parse_err; } } else if (ext != null && ext.ToLower() == ".json") { if (!ServerInfo.ParseFromJsonString(text, serverList)) { code = UpdateRetCode.server_list_parse_err; } } else { code = UpdateRetCode.server_list_parse_err; FileOperate.DeleteFile(serverListFile); } } catch (Exception) { code = UpdateRetCode.server_list_parse_err; } return(code); }
public bool CreateLog(string filename) { string strLogPath = filename; if (FileOperate.IsFileExist(strLogPath)) { FileOperate.DeleteFile(strLogPath); } try { FileOperate.MakeDir(strLogPath); logWriter = File.CreateText(strLogPath); LogWriteLine(string.Format("UpdateLog Created! {0:G}", System.DateTime.Now)); } catch (Exception) { logWriter = null; } return(logWriter != null); }
private bool CreateFile(string filename) { string strLogPath = filename; if (FileOperate.IsFileExist(strLogPath)) { FileOperate.DeleteFile(strLogPath); } try { FileOperate.MakeDir(strLogPath); logWriter = File.CreateText(strLogPath); LogWriteLine("StatisticsInfo Created!"); } catch (Exception) { logWriter = null; } return(logWriter != null); }
public void WritePacking(bool bWrite) { string strFile = strTempWritePackFileName; if (bWrite && UpdateInfo.bWrittingPack == false) { char[] buffer = new char[1] { '0' }; FileOperate.WriteToTextFile(strFile, buffer, 1); } else { if (FileOperate.IsFileExist(strFile)) { FileOperate.DeleteFile(strFile); } } UpdateInfo.bWrittingPack = bWrite; }
IEnumerable RequestServerListCoroutine(Action <bool> callback) { var patcher = Patcher.Instance; if (patcher.ServerListResult.IsRunning) { Common.HobaDebuger.LogWarning("RequestServerListCoroutine Start Failed, ServerList Downloading"); yield break; } _ServerInfoList.Clear(); bool isSuccessful = true; // 先请求JSON { string url = patcher.strDynamicServerDir + UpdateConfig.ServerListRelativePathJSON; string hostName = patcher.strDynamicServerHostName; string jsonFile = patcher.strServerListJSON; FileOperate.DeleteFile(jsonFile); //Common.HobaDebuger.LogWarning("Start DownloadServerListJSONFile"); patcher.DownloadServerListFile(url, hostName, jsonFile); //开启线程从中心服下载JSON文件 while (patcher.ServerListResult.IsRunning) { yield return(null); } var serverListJSON = new List <ServerInfo>(); var dlCode = patcher.ServerListResult.ErrorCode; if (dlCode != Downloader.DownloadTaskErrorCode.Success) { // 下载失败 Common.HobaDebuger.LogWarningFormat("DownloadServerListJSONFile Failed! DownloadTaskErrorCode: {0}", dlCode); isSuccessful = false; } else { var code = Patcher.ParseServerList(jsonFile, serverListJSON); if (code != UpdateRetCode.success) { // 解析失败 Common.HobaDebuger.LogWarningFormat("Read ServerListJson Failed!"); isSuccessful = false; } else { for (int i = 0; i < serverListJSON.Count; ++i) { string strUrl; if (!OSUtility.DNSResolve(2, serverListJSON[i].ip, out strUrl)) { serverListJSON[i].state = 3; Common.HobaDebuger.LogWarningFormat("ServerListJSON DNSResolve Failed! {0}", serverListJSON[i].ip); } else { if (serverListJSON[i].ip != strUrl) { Common.HobaDebuger.LogWarningFormat("ServerListJSON DNSResolve Change {0} To {1}", serverListJSON[i].ip, strUrl); } serverListJSON[i].ip = strUrl; } } } } AddToServerList(serverListJSON); } // 再请求XML { bool customServerList = false; List <ServerInfo> serverListXML = new List <ServerInfo>(); #if UNITY_EDITOR || UNITY_STANDALONE_WIN customServerList = ReadCustomServerListXml(serverListXML); #endif if (customServerList) { // 读取本地 AddToServerList(serverListXML); } else { // 从CDN下载 string url = HobaText.Format("{0}{1}", patcher.strClientServerDir, UpdateConfig.ServerListRelativePathXML); string hostName = patcher.strClientServerHostName; string xmlFile = patcher.strServerListXML; FileOperate.DeleteFile(xmlFile); patcher.DownloadServerListFile(url, hostName, xmlFile); //开启线程从CDN下载XML文件 while (patcher.ServerListResult.IsRunning) { yield return(null); } var dlCode = patcher.ServerListResult.ErrorCode; if (dlCode != Downloader.DownloadTaskErrorCode.Success) { // 下载失败 Common.HobaDebuger.LogWarningFormat("DownloadServerListXMLFile Failed! DownloadTaskErrorCode: {0} {1}", dlCode, patcher.ServerListResult.ErrMsg); isSuccessful = false; } else { var code = Patcher.ParseServerList(xmlFile, serverListXML); if (code != UpdateRetCode.success) { // 解析失败 Common.HobaDebuger.LogWarningFormat("Read ServerListXML Failed!"); isSuccessful = false; } else { for (int i = 0; i < serverListXML.Count; ++i) { string strUrl; if (!OSUtility.DNSResolve(2, serverListXML[i].ip, out strUrl)) { serverListXML[i].state = 3; Common.HobaDebuger.LogWarningFormat("ServerListXML DNSResolve Failed! {0}", serverListXML[i].ip); } else { if (serverListXML[i].ip != strUrl) { Common.HobaDebuger.LogWarningFormat("ServerListXML DNSResolve Change {0} To {1}", serverListXML[i].ip, strUrl); } serverListXML[i].ip = strUrl; } } } } AddToServerList(serverListXML); } } patcher.OnDynamicDownloadComplete(); if (callback != null) { callback(isSuccessful); } }
private IEnumerator DownloadPictureFromUrl(string strFileName, string url, int timeout, DownloadPictureCallback callback) { yield return(new WaitForEndOfFrame()); string strFile = Path.Combine(EntryPoint.Instance.CustomPicDir, strFileName); string contentType = Patcher.GetUrlContentType(url, timeout); int retCode = 0; if (contentType.StartsWith("text/")) { string tmpPath = Path.Combine(EntryPoint.Instance.TmpPath, "tmp.txt"); string errMsg; var code = Patcher.FetchByUrl(url, tmpPath, timeout, out errMsg); if (code == Downloader.DownloadTaskErrorCode.Success) { try { var bytes = File.ReadAllBytes(tmpPath); var chars = System.Text.Encoding.UTF8.GetChars(bytes); string str = new string(chars, 0, chars.Length); retCode = int.Parse(str); } catch (Exception) { retCode = -1; } } else { retCode = -1; } callback(strFileName, retCode, null); } else //下载图片 { UnityWebRequest request = UnityWebRequest.Get(url); string authorizationValue = GameCustomConfigParams.Authorization; request.SetRequestHeader("Authorization", authorizationValue); yield return(request.Send()); int resCode = -1; if (request.responseCode == 200) { var dic = JsonUtility.FromJson <URLResult>(request.downloadHandler.text); url = dic.url; request = UnityWebRequest.Get(url); yield return(request.Send()); if (request.responseCode == 200) { if (!FileOperate.MakeDir(strFile)) { Common.HobaDebuger.LogWarning(HobaText.Format("[FetchByUrl] MakeDir {0} Failed!", strFileName)); } if (FileOperate.IsFileExist(strFile)) { FileOperate.DeleteFile(strFile); } var streamFile = new FileStream(strFile, FileMode.OpenOrCreate); streamFile.Write(request.downloadHandler.data, 0, (int)request.downloadedBytes); streamFile.Close(); //string errMsg; //var code = Patcher.FetchByUrl(url, strFile, timeout, out errMsg); if (dic.resCode == (int)Downloader.DownloadTaskErrorCode.Success) { callback(strFileName, retCode, null); } else { callback(strFileName, retCode, HobaText.Format("{0}, {1}", (int)dic.resCode, url)); } } else { callback(strFileName, retCode, HobaText.Format("{0}, {1}", (int)resCode, url)); } } else { callback(strFileName, retCode, HobaText.Format("{0}, {1}", (int)resCode, url)); } } }
public IEnumerable UpdateAutoCoroutine(ELEMENT_VER verBegin, ELEMENT_VER verLatest) { long packSizeOverAll = m_VersionMan.CalcSize(verBegin, verLatest); if (packSizeOverAll <= 0) { packSizeOverAll = 1; } long packFinishedSize = m_VersionMan.CalcSize(verBegin, m_PackFileVer.VerFrom); int nTotalPack = m_VersionMan.CalcPackCount(verBegin, verLatest); int nCurrentPack = m_VersionMan.CalcPackCount(verBegin, m_PackFileVer.VerTo); GameUpdateMan.Instance.HotUpdateViewer.SetPackageNum(nCurrentPack, nTotalPack); UpdateInfoUtil.SetProgress(UPDATE_PROGRESS.Total, (float)((double)packFinishedSize / (double)packSizeOverAll)); UpdateInfoUtil.SetProgress(UPDATE_PROGRESS.File, 0.0f); UpdateInfoUtil.SetStateString(UPDATE_STATE.UpdateStatus_BeginUpdate); yield return(null); UpdateRetCode ret = UpdateRetCode.success; string strMd5 = this.m_PackFileVer.md5; //要下载的路径 this.strDownloadUPackName = HobaText.Format( "{0}-{1}.jup", this.m_PackFileVer.VerFrom.ToString(), this.m_PackFileVer.VerTo.ToString()); string strDownloadUPack = this.strDownloadPath + this.strDownloadUPackName; //计时 float nStartTime = Time.time; float nLasTime = nStartTime; float nNowTime = nStartTime; //准备下载 using (DownloadMan downloadMan = new DownloadMan(this.strDownloadPath)) //DownloadMan { downloadMan.TaskEndEvent += delegate { this.IsDownloadDone = true; }; int nTryTimes = 0; bool bFileEqual = false; while (!bFileEqual) { if (ret == UpdateRetCode.net_err || ret == UpdateRetCode.io_err || ret == UpdateRetCode.urlarg_error) { ++nTryTimes; //重连次数超过 if (nTryTimes > UpdateConfig.TotalReconnectTime) { ret = UpdateRetCode.connect_fail; break; //这次更新错误,等待选择重试 } //重连,间隔一定时间 do { yield return(new WaitForSeconds(1.0f)); nNowTime = Time.time; }while (nNowTime - nLasTime <= UpdateConfig.ReconnectTime); nLasTime = nNowTime; this.LogString(HobaText.Format("DownloadMan net_err begin retry {0} ... file: {1}", nTryTimes, this.strDownloadUPackName)); } else { nTryTimes = 0; } if (ret == UpdateRetCode.md5_not_match || ret == UpdateRetCode.download_fail) { break; } //如果文件已存在,判断md5 if (FileOperate.IsFileExist(strDownloadUPack)) { yield return(new WaitForSeconds(0.01f)); UpdateInfoUtil.SetProgress(UPDATE_PROGRESS.File, 100.0f); UpdateInfoUtil.SetStateString(UPDATE_STATE.UpdateStatus_CheckingExistPack); yield return(null); //string md5_exist = FileOperate.CalcFileMd5(strDownloadUPack); CalcMd5ThreadInfo calcMd5Info = CalcFileMd5(strDownloadUPack); while (calcMd5Info.IsRunning) { yield return(_ShortWait); } OnCalcMd5Complete(); string md5_exist = calcMd5Info.Md5; if (md5_exist == strMd5) { bFileEqual = true; break; } FileOperate.DeleteFile(strDownloadUPack); //删除旧文件 } //重新开始下载 this.IsDownloadDone = false; if (!FileOperate.MakeDir(strDownloadUPack)) { LogString(HobaText.Format("[UpdateAutoCoroutine] MakeDir {0} Failed!", strDownloadUPack)); } // UpdateInfoUtil.SetProgress(UPDATE_PROGRESS.File, 0.0f); UpdateInfoUtil.SetDownStatusString(0.0f); GameUpdateMan.Instance.HotUpdateViewer.SetDownloadInfo_TextUpate(UpdateInfoUtil.GetStateString(UPDATE_STATE.UpdateString_TextUpdate)); yield return(null); // foreach (var item in FetchPackByUrlCoroutine(downloadMan, // this.strUpdateServerDir1, this.strUpdateServerHostName1, this.strDownloadUPackName, strMd5)) foreach (var item in FetchPackCoroutine(downloadMan, this.strUpdateServerDir1, this.strUpdateServerHostName1, this.strUpdateServerDir2, this.strUpdateServerHostName2, this.strUpdateServerDir3, this.strUpdateServerHostName3, this.strDownloadUPackName, strMd5)) { if (item is UpdateRetCode) { ret = (UpdateRetCode)item; break; } else { yield return(item); } } if (ret != UpdateRetCode.success) { bFileEqual = false; } } if (bFileEqual) { ret = UpdateRetCode.success; } } if (ret == UpdateRetCode.success) //下载成功 { UpdateInfoUtil.bShowWritingPack = true; //设置本地包路径 strLocalPackFileName = strDownloadPath + strDownloadUPackName; UpdateInfoUtil.SetProgress(UPDATE_PROGRESS.File, 0.0f); yield return(null); //打开本地包,更新... //提示正在写包 GameUpdateMan.Instance.HotUpdateViewer.SetInstallInfo(UpdateInfoUtil.GetStateString(UPDATE_STATE.UpdateStatus_WritingPack)); GameUpdateMan.Instance.HotUpdateViewer.SetInstallPercent(-1.0f); foreach (var item in UpdateFileFromPackCoroutine(strLocalPackFileName, verBegin, verLatest)) { if (item is UpdateRetCode) { ret = (UpdateRetCode)item; break; } yield return(item); } //关闭临时包 FileOperate.DeleteFile(this.strLocalPackFileName); this.strLocalPackFileName = ""; UpdateInfoUtil.bShowWritingPack = false; } if (ret == UpdateRetCode.invalid_param) { ret = UpdateRetCode.cancel; yield return(ret); } else if (ret == UpdateRetCode.pack_file_broken || ret == UpdateRetCode.net_err || ret == UpdateRetCode.connect_fail || ret == UpdateRetCode.md5_not_match || ret == UpdateRetCode.io_err || ret == UpdateRetCode.urlarg_error || ret == UpdateRetCode.download_fail) { yield return(ret); } else if (ret != UpdateRetCode.success) { ret = UpdateRetCode.fail; yield return(ret); } //写入本地版本 UpdateInfoUtil.SetVersion(UPDATE_VERSION.Local, this.m_CurrentVersion); yield return(UpdateRetCode.success); }
public IEnumerable UpdateFileFromPackCoroutine(string strPackFile, ELEMENT_VER verBegin, ELEMENT_VER verLatest) { UpdateRetCode code = UpdateRetCode.success; if (this.m_CurrentVersion.IsValid()) { code = GetLocalVersion(); if (code != UpdateRetCode.success) { yield return(UpdateRetCode.element_ver_err); } } UpdateInfoUtil.SetProgress(UPDATE_PROGRESS.File, 0.0f); UpdateInfoUtil.SetWritingPackStatusString(0.0f); //新UI GameUpdateMan.Instance.HotUpdateViewer.SetInstallPercent(-1); yield return(null); //code = DoUpdateFrom7z(strPackFile); foreach (var item in this.DoUpdateFrom7zCoroutine(strPackFile, verBegin, verLatest)) { if (item is UpdateRetCode) { code = (UpdateRetCode)item; break; } yield return(null); } if (code != UpdateRetCode.success) { FileOperate.DeleteFile(strUpdateIncFile); //删除inc.sw文件 } else //更新成功,写新版本 { if (m_currentNewVer < BaseVersion) { code = UpdateRetCode.patcher_version_too_old; } else { ELEMENT_VER newVer = m_currentNewVer; UpdateInfoUtil.SetProgress(UPDATE_PROGRESS.File, 1.0f); //UpdateInfoUtil.SetWritingPackStatusString(1.0f); //新UI //GameUpdateMan.Instance.HotUpdateViewer.SetInstallPercent(1.0f); yield return(null); long sizeAdd = this.m_VersionMan.CalcSize(m_CurrentVersion, m_currentNewVer); UpdateInfoUtil.AddDownloadedSize(sizeAdd); //更新本地版本 SetLocalVersion(newVer); m_CurrentVersion = newVer; VER_PAIR verPair = m_PackFileVer; //更新m_PackFileVer,避免重复下载,下一个版本pair需要FindVersionPair verPair.VerTo = newVer; verPair.VerFrom = newVer; m_PackFileVer = verPair; } } yield return(code); }
public IEnumerable DoUpdateFrom7zCoroutine(string strPack, ELEMENT_VER verBegin, ELEMENT_VER verLatest) { //this.LogString(HobaText.Format("DoUpdateFrom7zCoroutine: {0}, {1}, {2}", strPack, verBegin.ToString(), verLatest.ToString())); UpdateRetCode code = UpdateRetCode.success; SevenZReader reader = new SevenZReader(); if (!reader.Init(strPack)) { code = UpdateRetCode.pack_file_broken; reader.Release(); yield return(code); // } int fileCount = reader.GetFileCount(); if (fileCount > 0) { GameUpdateMan.Instance.HotUpdateViewer.SetInstallProgress(1, fileCount); yield return(null); } FileIncList fileIncList = new FileIncList(); //找到7z包中的版本文件, inc, 得到版本 bool bIncValid = false; for (int iFile = 0; iFile < fileCount; ++iFile) { string name = reader.GetFileName(iFile); // LogString(HobaString.Format("7z pack file: {0}: {1}", iFile, name)); if (name == "") { this.LogString(HobaText.Format("Fail to get file name: {0}", iFile)); code = UpdateRetCode.pack_file_broken; reader.Release(); yield return(code); // } if (!bIncValid && name == "inc") { bIncValid = true; //读取 ExtractPackThreadInfo threadInfo = ExtractFileFrom7zReader(reader, iFile); while (threadInfo.IsRunning) { yield return(_ShortWait); } OnExtractFileComplete(); int dataSize = threadInfo.DataSize; IntPtr pData = threadInfo.Pointer; if (pData == IntPtr.Zero) { this.LogString(HobaText.Format("Fail to extract file name: {0}", iFile)); code = UpdateRetCode.pack_file_broken; reader.Release(); yield return(code); // } //写入 if (!FileOperate.MakeDir(this.strUpdateIncFile)) { LogString(HobaText.Format("[UpdateAutoCoroutine] MakeDir {0} Failed!", this.strUpdateIncFile)); } byte[] pText = new byte[dataSize]; Marshal.Copy(pData, pText, 0, dataSize); char[] text = Encoding.UTF8.GetChars(pText); bool ret = FileOperate.WriteToTextFile(this.strUpdateIncFile, text, text.Length); if (!ret) { this.LogString(HobaText.Format("Fail to write inc file name: %d", iFile)); code = UpdateRetCode.file_write_err; reader.Release(); yield return(code); // } //读取inc内容 code = ReadIncFileList(this.strUpdateIncFile, out fileIncList, out m_currentNewVer); //删除本地inc文件 FileOperate.DeleteFile(this.strUpdateIncFile); } if (bIncValid) { break; } } if (!bIncValid || code != UpdateRetCode.success) //找不到inc文件 { this.LogString("Pack has no list file: " + strPack); code = UpdateRetCode.pack_file_broken; reader.Release(); yield return(code); // } //计算进度 long packSizeOverAll = m_VersionMan.CalcSize(verBegin, verLatest); if (packSizeOverAll <= 0) { packSizeOverAll = 1; } long packFinishedSize = m_VersionMan.CalcSize(verBegin, m_CurrentVersion); long packNextFinishSize = m_VersionMan.CalcSize(verBegin, m_currentNewVer); float fFileProgress = 0.0f; float fTotalProgress = (float)((packFinishedSize + (packNextFinishSize - packFinishedSize) * (double)fFileProgress) / (double)packSizeOverAll); UpdateInfoUtil.SetProgress(UPDATE_PROGRESS.File, fFileProgress); UpdateInfoUtil.SetProgress(UPDATE_PROGRESS.Total, fTotalProgress); //UpdateInfoUtil.SetWritingPackStatusString(fFileProgress); //新UI fileCount = reader.GetFileCount(); if (fileCount > 0) { GameUpdateMan.Instance.HotUpdateViewer.SetInstallProgress(1, fileCount); } else { GameUpdateMan.Instance.HotUpdateViewer.SetInstallPercent(-1.0f); } yield return(null); //读取patch文件列表 for (int iFile = 0; iFile < fileCount; ++iFile) { //新UI GameUpdateMan.Instance.HotUpdateViewer.SetInstallProgress(iFile + 1, fileCount); yield return(null); if (reader.IsDir(iFile)) { continue; } string name = reader.GetFileName(iFile); // LogString(HobaString.Format("7z pack file: {0}: {1}", iFile, name)); if (string.IsNullOrEmpty(name)) { this.LogString(HobaText.Format("Fail to get file name: {0}", iFile)); code = UpdateRetCode.pack_file_broken; reader.Release(); yield return(code); // } if (name == "inc") //skip inc { continue; } string strMd5; if (!fileIncList.GetFileMd5(name, out strMd5)) { this.LogString(HobaText.Format("Fail to get file md5: {0} {1}", iFile, name)); code = UpdateRetCode.pack_file_broken; reader.Release(); yield return(code); // } bool bInPack = PackFunc.IsFileInPack(name); //是否属于指定的包 bool bSameFileExist = false; if (bInPack) //在包里的文件是否和更新文件md5一致,如果是则跳过更新 { if (PackFunc.CalcPackFileMd5(name) == strMd5) { bSameFileExist = true; } } if (bSameFileExist) { //if (iFile % (10 * 3) == 0) { fFileProgress = (float)(iFile + 1) / fileCount; fTotalProgress = (float)(packFinishedSize + (packNextFinishSize - packFinishedSize) * fFileProgress) / packSizeOverAll; UpdateInfoUtil.SetProgress(UPDATE_PROGRESS.File, fFileProgress); UpdateInfoUtil.SetProgress(UPDATE_PROGRESS.Total, fTotalProgress); //UpdateInfoUtil.SetWritingPackStatusString(fFileProgress); GameUpdateMan.Instance.HotUpdateViewer.SetInstallProgress(fileCount, fileCount); yield return(null); } continue; } //读取patch文件 ExtractPackThreadInfo threadInfo = ExtractFileFrom7zReader(reader, iFile); while (threadInfo.IsRunning) { yield return(_ShortWait); } OnExtractFileComplete(); int dataSize = threadInfo.DataSize; IntPtr pData = threadInfo.Pointer; if (pData == IntPtr.Zero) { this.LogString(HobaText.Format("Fail to extract file name: {0}", iFile)); code = UpdateRetCode.pack_file_broken; reader.Release(); yield return(code); // } //检查md5 //string memMd5 = FileOperate.CalcMemMd5(pData, dataSize); CalcMd5ThreadInfo calcMd5Info = CalcMemMd5(pData, dataSize); while (calcMd5Info.IsRunning) { yield return(_ShortWait); } OnCalcMd5Complete(); string memMd5 = calcMd5Info.Md5; if (memMd5 != strMd5) { this.LogString(HobaText.Format("File md5 mismatch: {0} {1}", iFile, name)); code = UpdateRetCode.pack_file_broken; reader.Release(); yield return(code); // } if (dataSize < 4) //不是压缩文件 { this.LogString(HobaText.Format("Compressed file has no header {0} {1}", iFile, name)); code = UpdateRetCode.pack_file_broken; reader.Release(); yield return(code); // } if (bInPack) //add to package { this.WritePacking(true); bool retFlag = PackFunc.AddCompressedDataToPack(name, pData, dataSize); if (!retFlag) { this.LogString(HobaText.Format("Update fail to add file: {0} {1}", iFile, name)); code = UpdateRetCode.pack_file_broken; reader.Release(); yield return(code); // } else { // this.LogString(HobaString.Format("Success to add pack file: {0} {1}", iFile, name)); code = UpdateRetCode.success; } } else //解压,写文件 { //使用更新目录, 将 AssetBundle/<Plaform> 和 AssetBundle/<Plaform>/Update 整合成AssetBundle string actualName; if (PackFunc.IsFileInAssetBundles(name)) { actualName = PackFunc.MakeShortAssetBundlesFileName(name); // this.LogString(HobaString.Format("MakeShortAssetBundlesFileName: {0} {1} TO {2}", iFile, name, actualName)); } else { actualName = name; } UncompressToSepFileThreadInfo uncompressInfo = UncompressToSepFile(actualName, pData, dataSize); while (uncompressInfo.IsRunning) { yield return(_ShortWait); } OnUncompressToSepFileComplete(); bool retFlag = uncompressInfo.RetFlag; if (!retFlag) { this.LogString(HobaText.Format("Update fail to uncompress file: {0} {1}", iFile, actualName)); code = UpdateRetCode.pack_file_broken; reader.Release(); yield return(code); // } else { // this.LogString(HobaString.Format("Success to add sep file: {0} {1}", iFile, name)); code = UpdateRetCode.success; } } } reader.Release(); PackFunc.FlushWritePack(); if (!PackFunc.SaveAndOpenUpdatePack()) { this.LogString(HobaText.Format("PackFunc.SaveAndOpenUpdatePack() Failed!!! {0}", strPack)); } else { this.WritePacking(false); //清除写包标志 } yield return(code); // }