private void DownloadDiffZip(DiffApkInfo serverInfo, string zipFileName, string jsonFileName, long offset = 0)
        {
            var target = ApkUpdateMonitor.GetInstance();

            if (offset <= 0)
            {
                offset = 0;
                // 写入localZipInfo到文件
                localDiffZipInfo localInfo = new localDiffZipInfo();
                localInfo.Name = serverInfo.DiffName;
                localInfo.Md5  = serverInfo.DiffZipMd5;
                target.SaveLocalDiffZipInfo(jsonFileName, localInfo);
            }
            Clear();

            string url = target.Inter.Get_Http_DiffZipUrl();

            if (string.IsNullOrEmpty(url))
            {
                target.OnError(ApkUpdateState.CheckLocalNewZip, ApkUpdateError.Get_Server_DiffZip_Url_Error);
                return;
            }
            url = string.Format("{0}/{1}.zip", url, serverInfo.DiffZipMd5);
            HttpClientFileStream stream = new HttpClientFileStream(zipFileName, offset, 1024 * 4);

            m_Http = HttpHelper.OpenUrl <HttpClientFileStream>(url, stream, OnHttpEnd);
        }
        void DoUpdate()
        {
            if (m_IsError)
            {
                return;
            }

            if (m_DownList == null || m_WaitList == null || m_WaitList.Count <= 0 || m_DownList.Count <= 0)
            {
                return;
            }

            var node = m_DownList.First;

            while (node != null)
            {
                var next = node.Next;
                if (node.Value.IsCanUse)
                {
                    AutoUpdateCfgItem item;
                    if (GetNextDownload(out item))
                    {
                        node.Value.item = item;
                        // Get Http
                        string url = string.Format("{0}/{1}/{2}", AutoUpdateMgr.Instance.ResServerAddr,
                                                   AutoUpdateMgr.Instance.CurrServeResrVersion,
                                                   item.fileContentMd5);

                        // 原来下载过直接跳过
                        double m    = ((double)item.readBytes) / ((double)(1024 * 1024));
                        double curM = AutoUpdateMgr.Instance.CurDownM;
                        curM += m;
                        AutoUpdateMgr.Instance.CurDownM = curM;

                        DoUpdateDownProcess();

                        //AutoUpdateMgr.Instance.CreateHttpFile(url, item.readBytes, OnHttpRead, OnHttpError);
                        int    bufSize  = AutoUpdateMgr.Instance.HttpFileBufSize;
                        string fileName = string.Format("{0}/{1}", AutoUpdateMgr.Instance.WritePath, item.fileContentMd5);
                        var    listener = new HttpClientFileStream(fileName, item.readBytes, bufSize);
                        listener.UserData = node.Value;
                        var http = HttpHelper.OpenUrl <HttpClientFileStream>(url, listener, OnItemHttpEnd, OnItemHttpProcess);
                        node.Value.http = http;
                    }
                    else
                    {
                        m_DownList.Remove(node);
                    }
                }

                node = next;
            }
        }
Exemplo n.º 3
0
        // 新的下载文件接口
        internal void CreateHttpFile(string url, long process, Action <HttpClient, HttpListenerStatus> onEnd, Action <HttpClient> onProcess)
        {
            if (string.IsNullOrEmpty(m_WritePath) || string.IsNullOrEmpty(url))
            {
                return;
            }
            string fileName    = Path.GetFileName(url);
            string dstFileName = string.Format("{0}/{1}", m_WritePath, fileName);

            HttpRelease();
            HttpClientFileStream response = new HttpClientFileStream(dstFileName, process, m_HttpFileBufSize);

            lock (m_Lock)
            {
                m_HttpClient = HttpHelper.OpenUrl <HttpClientFileStream>(url, response, onEnd, onProcess, m_HttpConnectTimeOut);
            }
        }
Exemplo n.º 4
0
        internal HttpClient CreateHttpFile(string url, long process, Action <HttpClientResponse, long> OnReadEvt,
                                           Action <HttpClientResponse, int> OnErrorEvt)
        {
            if (string.IsNullOrEmpty(m_WritePath))
            {
                return(null);
            }
            string fileName    = Path.GetFileName(url);
            string dstFileName = string.Format("{0}/{1}", m_WritePath, fileName);

            HttpRelease();
            HttpClientFileStream response = new HttpClientFileStream(dstFileName, process, m_HttpFileBufSize);

            response.OnReadEvt  = OnReadEvt;
            response.OnErrorEvt = OnErrorEvt;
            lock (m_Lock) {
                m_HttpClient = new HttpClient(url, response, process, m_HttpConnectTimeOut);
            }
            return(m_HttpClient);
        }
Exemplo n.º 5
0
    void OnGUI()
    {
        if (GUI.Button(new Rect(100, 100, 100, 50), "检查更新"))
        {
            //AutoUpdateMgr.Instance.StartAutoUpdate(m_downloadUrl, 10, 64 * 1024);
            //AutoUpdateMgr.Instance.OnError = OnDownError;
            //AutoUpdateMgr.Instance.OnStateChanged = OnDownStateChanged;
            var stream = new HttpClientFileStream(Utils.FilePathMgr.GetInstance().WritePath + "/Android-1.5.0.0.zip", 0, 64 * 1024);
            if (m_Client != null)
            {
                m_Client.Dispose();
                m_Client = null;
            }
            m_Client = HttpHelper.OpenUrl("https://patch.cgm.beanfun.com/cgm/update/Android/Android-1.5.0.0.zip", stream, OnDownEnd, OnDownProcess, 30, 30);
        }

        //float process = AutoUpdateMgr.Instance.DownProcess * 100f;
        GUI.Label(new Rect(100, 150, 100, 20), StringHelper.Format("下载进度: {0:D}", (int)process));

        //string downStr = StringHelper.Format("{0}/{1}", AutoUpdateMgr.Instance.CurDownM, AutoUpdateMgr.Instance.CurDownM, AutoUpdateMgr.Instance.TotalDownM);
        string downStr = StringHelper.Format("{0}/{1}", read, maxRead);

        GUI.Label(new Rect(100, 170, 100, 20), downStr);
    }
        // 新的下载接口(都是主线程)
        void OnHttpProcess(HttpClient client)
        {
            HttpClientFileStream fileStream = client.Listener as HttpClientFileStream;
            AutoUpdateCfgItem    item       = m_Items[m_Curr];
            long oldReadBytes = item.readBytes;

            item.readBytes = fileStream.StartPos + fileStream.ReadBytes;
            long delta = item.readBytes - oldReadBytes;

            if (delta > 0)
            {
                double curM = AutoUpdateMgr.Instance.CurDownM;
                curM += ((double)delta) / ((double)1024 * 1024);
                AutoUpdateMgr.Instance.CurDownM = curM;
            }
            if (fileStream.ReadBytes >= fileStream.MaxReadBytes)
            {
                item.isDone = true;
            }
            m_Items[m_Curr] = item;
            AutoUpdateMgr.Instance.DownloadUpdateToUpdateTxt(item);

            DoUpdateDownProcess();
        }