void OnHttpRead(HttpClientResponse response, long totalRead) { FileThreadInfo info = response.UserData as FileThreadInfo; if (info != null && m_Data != null && info.fileIdx >= 0) { AutoUpdateCfgItem item = m_Data[info.fileIdx]; long delta = totalRead - response.ReadBytes; if (delta > 0) { double curM = AutoUpdateMgr.Instance.CurDownM; curM += ((double)delta) / ((double)1024 * 1024); AutoUpdateMgr.Instance.CurDownM = curM; item.readBytes += delta; float process; double maxM = AutoUpdateMgr.Instance.TotalDownM; if (maxM > float.Epsilon) { process = (float)(curM / maxM); if (process > 1f) { process = 1f; } } else { process = 0f; } AutoUpdateMgr.Instance.DownProcess = process; } if (totalRead >= response.MaxReadBytes) { item.isDone = true; } m_Data[info.fileIdx] = item; lock (m_Lock) { AutoUpdateMgr.Instance.DownloadUpdateToUpdateTxt(item); } if (totalRead >= response.MaxReadBytes) { lock (m_Lock) { info.Reset(); } StartNextDown(); } } }
// 只是关闭下载线程 public void Stop() { lock (m_Lock) { if (m_Clients != null) { for (int i = 0; i < m_Clients.Length; ++i) { FileThreadInfo client = m_Clients[i]; client.Reset(); } } } FileIdx = -1; HasDownError = false; }
public HttpClientThreadFileStream(AutoUpdateCfgItem[] data, int maxThreadCnt = 5) { m_Data = data; if (maxThreadCnt > 0) { lock (m_Lock) { m_Clients = new FileThreadInfo[maxThreadCnt]; for (int i = 0; i < m_Clients.Length; ++i) { FileThreadInfo info = new FileThreadInfo(); info.Reset(); m_Clients[i] = info; } } } }
void OnHttpError(HttpClientResponse response, int status) { FileThreadInfo info = response.UserData as FileThreadInfo; if (info != null && info.fileIdx >= 0) { lock (m_Lock) { if (m_Data != null && m_Data.Length > 0) { var item = m_Data[info.fileIdx]; UnityEngine.Debug.LogErrorFormat("[downloadFileErr]{0} download: {1:D} isOk: {2}", item.fileContentMd5, item.readBytes, item.isDone.ToString()); } info.Reset(); } } HasDownError = true; StartNextDown(); }