public void Start(string root, string fillname, Action <HttpDownload, long> update = null, Action <HttpDownload, bool> finish = null, Action <HttpDownload, enDownloadErrorState> error = null)
 {
     Abort();
     Root            = root;
     LocalName       = fillname;
     IsDone          = false;
     Length          = 0;
     CompleteLength  = 0;
     update_callback = update;
     finish_callback = finish;
     error_callback  = error;
     ErrorCode       = enDownloadErrorState.None;
     m_content       = new DownLoadContent(FullName);
     Download();
 }
 private void OnFinish()
 {
     lock (lock_obj){
         if (m_content != null)
         {
             m_content.State = enDownloadState.Completed;
             m_content.Close();
             m_content = null;
         }
         if (m_httpwebrequest != null)
         {
             m_httpwebrequest.Abort();
             m_httpwebrequest = null;
         }
         IsDone = true;
     }
 }
 private void OnReadCallback(IAsyncResult ar)
 {
     try
     {
         lock (lock_obj){
             DownLoadContent content = ar.AsyncState as DownLoadContent;
             if (content.ResponseStream == null)
             {
                 return;
             }
             int read = content.ResponseStream.EndRead(ar);
             if (read > 0)
             {
                 content.ContentFileStream.Write(content.Buffer, 0, read);
                 content.ContentFileStream.Flush();
                 CompleteLength += read;
                 if (update_callback != null)
                 {
                     update_callback(this, (long)read);
                 }
             }
             else
             {
                 OnFinish();
                 if (finish_callback != null)
                 {
                     finish_callback(this, true);
                 }
                 return;
             }
             BeginRead(OnReadCallback);
         }
     }
     catch (Exception e)
     {
         Debuger.LogError(e.Message);
         OnFailed(enDownloadErrorState.DownloadError);
     }
 }
 private void OnFailed(enDownloadErrorState state)
 {
     lock (lock_obj){
         if (m_content != null)
         {
             m_content.State = enDownloadState.Failed;
             m_content.Close();
             m_content = null;
         }
         if (m_httpwebrequest != null)
         {
             m_httpwebrequest.Abort();
             m_httpwebrequest = null;
         }
         IsDone    = true;
         ErrorCode = state;
         if (error_callback != null)
         {
             error_callback(this, ErrorCode);
         }
     }
 }