예제 #1
0
    public void Update()
    {
        if (!m_alive)
        {
            return;
        }

        if (m_OPComplete)
        {
            if (m_opRet == HTTP_OP_RET.succ)
            {
                m_fileBuffStream.Position = 0;
                string md5Code = UpdateUtils.Md5(this.m_fileBuffStream);
                m_fileBuffStream.Position = 0;
                if (!Save(m_fileBuffStream, m_filePath))
                {
                    this.m_opRet          = HTTP_OP_RET.failed;
                    this.m_httpStatusCode = -1;
                    this.m_msg            = "Save File Failed";
                    return;
                }

                if (null != this.m_onProgressHandler)
                {
                    m_onProgressHandler(this.m_url, this.m_filePath, this.m_downloadSize, this.m_totalSize);
                }

                if (null != m_onSuccHandler)
                {
                    m_onSuccHandler(m_url, m_filePath, (int)m_totalSize, md5Code);
                }
            }
            else
            {
                if (m_redirectURL != null)
                {
                    if (null != this.m_onRedirectHandler)
                    {
                        m_onRedirectHandler(m_url, m_filePath, m_redirectURL, m_httpStatusCode, m_msg);
                    }
                }
                else
                {
                    if (null != this.m_onErrorHandler)
                    {
                        m_onErrorHandler(m_url, m_filePath, m_httpStatusCode, m_msg);
                    }
                }
            }

            m_alive = false;
        }
        else
        {
            if (m_opStep == HTTP_OP_STEP.downloading)
            {
                m_updateDeltaTime += Time.deltaTime;
                if (m_updateDeltaTime > 0.5)
                {
                    m_updateDeltaTime = 0;
                    if (null != this.m_onProgressHandler)
                    {
                        m_onProgressHandler(this.m_url, this.m_filePath, this.m_downloadSize, this.m_totalSize);
                    }
                }
            }
        }
    }