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); }
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(); } }