Exemplo n.º 1
0
 public SDownloadEventResult(DownloadEventType eventType, SDownloadFileResult fileResult, SGameUpdaterDownloadConfig info, string error)
 {
     this.error      = error;
     this.info       = info;
     this.fileResult = fileResult;
     this.eventType  = eventType;
 }
Exemplo n.º 2
0
 private void OnProgress(SDownloadFileResult result)
 {
     if (m_downloadCallback.Progress != null)
     {
         m_downloadCallback.Progress(m_currentConfig.fileName, result);
     }
 }
Exemplo n.º 3
0
 private void DownloadFileCallback(object obj)
 {
     m_handler = new HttpDownloadFileHandler(m_currParams.download_url,
                                             m_currParams.localPath_url);
     m_handler.Progress = result => m_fileResult = result;
     m_request          = WebRequest.Create(m_currParams.download_url) as HttpWebRequest;
     m_request.Timeout  = m_currParams.timeout;
     m_request.AddRange(m_handler.DownloadedLength); //断点续传关键点
     m_request.Proxy = WebRequest.DefaultWebProxy;
     try
     {
         m_response = m_request.GetResponse() as HttpWebResponse;
         m_handler.ReceiveContentLength((int)m_response.ContentLength);
         byte[] buffer = new byte[1024];
         using (Stream stream = m_response.GetResponseStream())
         {
             int dataLength = stream.Read(buffer, 0, buffer.Length);
             while (dataLength > 0)
             {
                 if (m_isStop || m_handler.ReceiveData(buffer, dataLength) == false)
                 {
                     return;
                 }
                 dataLength = stream.Read(buffer, 0, buffer.Length);
             }
         }
         m_handler.Dispose();
         m_eventQueue.Enqueue(new SWebDownloadEvent(DownloadEventType.OneComplete,
                                                    (int)m_response.StatusCode));
     }
     catch (WebException e)
     {
         int code = 0;
         m_response = e.Response as HttpWebResponse;
         if (m_response != null)
         {
             code = (int)m_response.StatusCode;
         }
         m_handler.Dispose();
         m_eventQueue.Enqueue(new SWebDownloadEvent(DownloadEventType.OneComplete, code));
     }
     finally
     {
         if (m_response != null)
         {
             m_response.Close();
         }
         m_request.Abort();
         m_fileResult = new SDownloadFileResult();
     }
 }
Exemplo n.º 4
0
 public void DownloadFile(string download_url, string localPath_url, int timeout,
                          Action <SDownloadFileResult> progress,
                          Action <int> complete)
 {
     m_eventQueue.Clear();
     m_currParams.download_url  = download_url;
     m_currParams.localPath_url = localPath_url;
     m_currParams.timeout       = timeout;
     m_currParams.OnProgress    = progress;
     m_currParams.OnComplete    = complete;
     m_fileResult = new SDownloadFileResult();
     ThreadPool.SetMaxThreads(5, 5);
     ThreadPool.QueueUserWorkItem(new WaitCallback(DownloadFileCallback), null);
 }