public override void Enter(AutoUpdateMgr target) { // 解压 string zipFileMd5 = target.CurrUpdateZipFileMd5; string writePath = target.WritePath; if (string.IsNullOrEmpty(zipFileMd5) || string.IsNullOrEmpty(writePath)) { AutoUpdateMgr.Instance.EndAutoUpdate(); } string zipFileName = string.Format("{0}/{1}", writePath, zipFileMd5); if (!File.Exists(zipFileName)) { target.Error(AutoUpdateErrorType.auError_ResZipVerReq, 0); return; } // 未写完, 解压完要改名,删除冗余的 ZipTools.UnCompress(zipFileMd5); if (m_UnZipTimer == null) { m_UnZipTimer = TimerMgr.Instance.CreateTimer(false, 0, true, true); m_UnZipTimer.AddListener(OnUnZipTimer); } else { m_UnZipTimer.Start(); } }
public override void Enter(AutoUpdateMgr target) { string oldVer = target.LocalResVersion; string newVer = target.CurrServeResrVersion; var updateFile = target.LocalUpdateFile; m_ZipFileName = ZipTools.GetZipFileName(oldVer, newVer); long read = 0; AutoUpdateCfgItem item; m_ZipFileName = string.Format("{0}.zip", m_ZipFileName); bool isSaveUpdateFile = false; if (updateFile.FindItem(m_ZipFileName, out item)) { if (item.isDone) { ToNextState(); return; } read = item.readBytes; } else { item = new AutoUpdateCfgItem(); item.fileContentMd5 = m_ZipFileName; item.isDone = false; item.readBytes = 0; updateFile.AddOrSet(item); isSaveUpdateFile = true; } isSaveUpdateFile = isSaveUpdateFile || updateFile.RemoveDowningZipFiles(m_ZipFileName); if (isSaveUpdateFile) { updateFile.SaveToLastFile(); } string resAddr = target.ResServerAddr; bool isHttps = resAddr.StartsWith("https://", StringComparison.CurrentCultureIgnoreCase); string url; if (isHttps) { url = string.Format("{0}/{1}", resAddr, m_ZipFileName); } else { long tt = DateTime.UtcNow.Ticks; url = string.Format("{0}/{1}?time={2}", resAddr, m_ZipFileName, tt.ToString()); } target.CreateHttpFile(url, read, OnHttpRead, OnHttpError); }
public override void Enter(AutoUpdateMgr target) { // 解压 string zipFileMd5 = target.CurrUpdateZipFileMd5; string writePath = target.WritePath; if (string.IsNullOrEmpty(zipFileMd5) || string.IsNullOrEmpty(writePath)) { AutoUpdateMgr.Instance.EndAutoUpdate(); } string zipFileName = string.Format("{0}/{1}", writePath, zipFileMd5); if (!File.Exists(zipFileName)) { target.Error(AutoUpdateErrorType.auError_ResZipVerReq, 0); return; } // 未写完, 解压完要改名,删除冗余的 ZipTools.UnCompress(zipFileMd5); }
void OnReadEvent(HttpClientResponse response, long totalReadBytes) { if (totalReadBytes >= response.MaxReadBytes) { HttpClientStrResponse r = response as HttpClientStrResponse; string zipVerList = r.Txt; if (string.IsNullOrEmpty(zipVerList)) { AutoUpdateMgr.Instance.CurrUpdateZipFileMd5 = string.Empty; ToNextStatus(); return; } string oldVer = AutoUpdateMgr.Instance.LocalResVersion; string newVer = AutoUpdateMgr.Instance.CurrServeResrVersion; string zipFileName = ZipTools.GetZipFileName(oldVer, newVer); ResListFile zipFiles = new ResListFile(); zipFiles.Load(zipVerList); ResListFile.ResDiffInfo[] diff; if (!zipFiles.FileToDiffInfo(zipFileName, out diff) || diff == null || string.IsNullOrEmpty(diff[0].fileContentMd5) || diff[0].fileSize <= 0) { AutoUpdateMgr.Instance.CurrUpdateZipFileMd5 = string.Empty; ToNextStatus(); return; } AutoUpdateMgr.Instance.UpdateToUpdateTxt(diff); AutoUpdateMgr.Instance.UpdateTotalDownloadBytes(diff); AutoUpdateMgr.Instance.CurrUpdateZipFileMd5 = diff[0].fileContentMd5; ToNextStatus(); } }