Beispiel #1
0
        void OnExtractDownloadFile(List <object> evParams, Action <NotiData> func)
        {
            var dataPath = evParams[0] as string;
            var dataName = evParams[1] as string;
            var buffer   = evParams[2] as byte[];

            try
            {
                using (var decompressor = new ZstdNet.Decompressor())
                {
                    var path  = dataPath + dataName;
                    var bytes = decompressor.Unwrap(buffer);
                    if (File.Exists(path))
                    {
                        File.Delete(path);
                    }
                    File.WriteAllBytes(path, bytes);
                    NotiData data = new NotiData(NotiConst.DOWNLOAD_EXTRACT, dataName, path);
                    if (func != null)
                    {
                        func(data);                //回调逻辑层
                    }
                }
            }
            catch (Exception e)
            {
                NotiData data = new NotiData(NotiConst.DOWNLOAD_EXTRACT_FAILED, dataName, e.Message);
                if (func != null)
                {
                    func(data);                //回调逻辑层
                }
            }
        }
        private void ProgressChanged(object sender, DownloadProgressChangedEventArgs e)
        {
            string param = string.Empty;
            double num   = (double)e.BytesReceived / 1024.0 / this.sw.Elapsed.TotalSeconds;

            if (num > 1024.0)
            {
                param = string.Format("{0} mb/s", (num / 1024.0).ToString("0.00"));
            }
            else
            {
                param = string.Format("{0} kb/s", num.ToString("0.00"));
            }
            NotiData data = new NotiData("UpdateProgress", param, e.ProgressPercentage);

            if (this.m_SyncEvent != null)
            {
                this.m_SyncEvent(data);
            }
            if (e.ProgressPercentage == 100 && e.BytesReceived == e.TotalBytesToReceive)
            {
                this.sw.Reset();
                data = new NotiData("UpdateDownload", this.currDownFile, null);
                if (this.m_SyncEvent != null)
                {
                    this.m_SyncEvent(data);
                }
            }
        }
        private void ProgressChanged(object sender, DownloadProgressChangedEventArgs e)
        {
            //UnityEngine.Debug.Log(e.ProgressPercentage);

            /*
             * UnityEngine.Debug.Log(string.Format("{0} MB's / {1} MB's",
             *  (e.BytesReceived / 1024d / 1024d).ToString("0.00"),
             *  (e.TotalBytesToReceive / 1024d / 1024d).ToString("0.00")));
             */
            //float value = (float)e.ProgressPercentage / 100f;

            string   value = string.Format("{0} kb/s", (e.BytesReceived / 1024d / sw.Elapsed.TotalSeconds).ToString("0.00"));
            NotiData data  = new NotiData(NotiConst.UPDATE_PROGRESS, value);

            if (m_SyncEvent != null)
            {
                m_SyncEvent(data);
            }

            if (e.ProgressPercentage == 100 && e.BytesReceived == e.TotalBytesToReceive)
            {
                sw.Reset();

                data = new NotiData(NotiConst.UPDATE_DOWNLOAD, currDownFile);
                if (m_SyncEvent != null)
                {
                    m_SyncEvent(data);
                }
            }
        }
        private void OnDownloadFile(List <object> evParams)
        {
            string uriString = evParams[0].ToString();

            this.currDownFile = evParams[1].ToString();
            try
            {
                using (WebClient webClient = new WebClient())
                {
                    this.sw.Start();
                    webClient.Proxy = null;
                    if (ServicePointManager.DefaultConnectionLimit != 500)
                    {
                        ServicePointManager.DefaultConnectionLimit = 500;
                    }
                    webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(this.ProgressChanged);
                    webClient.DownloadFileCompleted   += new AsyncCompletedEventHandler(this.FileDownloaded);
                    webClient.DownloadFileAsync(new Uri(uriString), this.currDownFile);
                }
            }
            catch (Exception ex)
            {
                NotiData data = new NotiData("UpdateFailed", this.currDownFile, ex.Message);
                if (this.m_SyncEvent != null)
                {
                    this.m_SyncEvent(data);
                }
                this.sw.Reset();
            }
        }
Beispiel #5
0
 /// <summary>
 /// 通知事件
 /// </summary>
 /// <param name="state"></param>
 private void OnSyncEvent(NotiData data)
 {
     if (this.func != null)
     {
         func(data);                                              //回调逻辑层
     }
     Facade.Instance.SendNotification(data.evName, data.evParam); //通知View层
 }
 private void OnSyncEvent(NotiData data)
 {
     if (this.func != null)
     {
         this.func(data);
     }
     base.facade.SendMessageCommand(data.evName, data.evParam);
 }
 /// <summary>
 /// 通知事件
 /// </summary>
 /// <param name="state"></param>
 private void OnSyncEvent(NotiData data)
 {
     if (this.func != null)
     {
         func(data);                                       //回调逻辑层
     }
     facade.SendMessageCommand(data.evName, data.evParam); //通知View层
 }
        private void FileCompleteListener(object sender, ScanEventArgs e)
        {
            NotiData data = new NotiData("ExtractFinishedOne", e.Name, null);

            if (this.m_SyncEvent != null)
            {
                this.m_SyncEvent(data);
            }
        }
        private void ProgressChangeListener(object sender, ProgressEventArgs e)
        {
            NotiData data = new NotiData("ExtractProgress", e.PercentComplete, null);

            if (this.m_SyncEvent != null)
            {
                this.m_SyncEvent(data);
            }
        }
Beispiel #10
0
        private void ProgressChanged(object sender, DownloadProgressChangedEventArgs e)
        {
            if (null == m_loadingLengthDic)
            {
                m_loadingLengthDic = new Dictionary <WebClient, long>();
            }

            float totalLength = (GameManager.Instance.TotalUpdateLength * 1f) / 1024;

            //totalLength = (float)Math.Round((double)totalLength, 4);
            string speed = (e.BytesReceived / 1024d / sw.Elapsed.TotalSeconds).ToString("0.00");

            WebClient web = sender as WebClient;

            m_loadingLengthDic[web] = e.BytesReceived;

            string value;
            float  haveByteLen = LoadingLength;
            float  haveLen     = LoadingLength * 1f / 1024f;

            LoadingProgress = haveByteLen / GameManager.Instance.TotalUpdateLength;

            if (totalLength >= 1024)
            {
                totalLength /= 1024;
                haveLen     /= 1024;
                value        = string.Format("本次更新总计:{0}M/{1}M 速度{2} kb/s", haveLen.ToString("0.00"), totalLength.ToString("0.00"), speed);
            }
            else
            {
                value = string.Format("本次更新总计:{0}kb/{1}kb 速度{2} kb/s", haveLen.ToString("0.00"), totalLength.ToString("0.00"), speed);
            }

            GameManager.loadingstr = value;
            NotiData data = new NotiData(NotificationID.UPDATE_PROGRESS, value);

            if (m_SyncEvent != null)
            {
                m_SyncEvent(data);
            }

            if (e.ProgressPercentage == 100 && e.BytesReceived == e.TotalBytesToReceive)
            {
                sw.Reset();

                data = new NotiData(NotificationID.UPDATE_DOWNLOAD, currDownFile);
                if (m_SyncEvent != null)
                {
                    m_SyncEvent(data);
                }
            }

            if (haveByteLen == GameManager.Instance.TotalUpdateLength)
            {
                m_loadingLengthDic = null;
            }
        }
Beispiel #11
0
        /// <summary>
        /// 调用方法
        /// </summary>
        void OnExtractFile(List <object> evParams)
        {
            UnityEngine.Debug.LogWarning("Thread evParams: >>" + evParams.Count);

            ///------------------通知更新面板解压完成--------------------
            NotiData data = new NotiData(NotificationID.UPDATE_DOWNLOAD, null);

            if (m_SyncEvent != null)
            {
                m_SyncEvent(data);
            }
        }
        /// <summary>
        /// 调用方法
        /// </summary>
        void OnExtractFile(List <object> evParams)
        {
            Debugger.LogWarning("Thread evParams: >>" + evParams.Count);

            ///------------------通知更新面板解压完成--------------------
            NotiData data = new NotiData(NotiConst.UPDATE_DOWNLOAD, null);

            if (m_SyncEvent != null)
            {
                m_SyncEvent(data);
            }
        }
 private void FileDownloaded(object sender, AsyncCompletedEventArgs e)
 {
     if (e.Error != null)
     {
         NotiData data = new NotiData("UpdateFailed", this.currDownFile, e.Error.Message);
         if (this.m_SyncEvent != null)
         {
             this.m_SyncEvent(data);
         }
         this.sw.Reset();
     }
 }
Beispiel #14
0
        /// <summary>
        /// 线程完成
        /// </summary>
        /// <param name="data"></param>
        void OnThreadCompleted(NotiData data)
        {
            switch (data.evName)
            {
            case NotiConst.UPDATE_EXTRACT:      //解压一个完成
                //
                break;

            case NotiConst.UPDATE_DOWNLOAD:     //下载一个完成
                downloadFiles.Add(data.evParam.ToString());
                break;
            }
        }
Beispiel #15
0
 /// <summary>
 /// 线程完成
 /// </summary>
 /// <param name="data"></param>
 void OnThreadCompleted(NotiData data)
 {
     switch (data.evName)
     {
     case NotiConst.UPDATE_DOWNLOAD:     //下载一个完成
         downloadedFiles.Add(data.evParam.ToString());
         facade.SendMessageCommand(NotiConst.UPDATE_DOWNLOAD_PROGRESS, downloadedFiles.Count * 1.0f / needDownloadFiles.Count);
         if (downloadedFiles.Count == needDownloadFiles.Count)      //下载完成
         {
             facade.SendMessageCommand(NotiConst.UPDATE_DOWNLOAD_FINISH);
         }
         break;
     }
 }
        private void ExtractProgressChanged(long fileSize, long processSize, string outFile)
        {
            NotiData data = new NotiData("ExtractProgress", (double)processSize / (double)fileSize, null);

            if (this.m_SyncEvent != null)
            {
                this.m_SyncEvent(data);
            }
            if (fileSize == processSize)
            {
                data = new NotiData("UpdateExtract", outFile, null);
                if (this.m_SyncEvent != null)
                {
                    this.m_SyncEvent(data);
                }
            }
        }
Beispiel #17
0
        /// <summary>
        /// 线程完成
        /// </summary>
        /// <param name="data"></param>
        void OnThreadCompleted(NotiData data)
        {
            switch (data.evName)
            {
            case NotiConst.UPDATE_EXTRACT:      //解压一个完成
                //
                break;

            case NotiConst.UPDATE_PROGRESS:
                facade.SendMessageCommand(NotiConst.UPDATE_MESSAGE, data.evParam.ToString());
                break;

            case NotiConst.UPDATE_DOWNLOAD:     //下载一个完成
                downloadFiles.Add(data.evParam.ToString());
                break;
            }
        }
Beispiel #18
0
        private void ProgressChanged(object sender, DownloadProgressChangedEventArgs e)
        {
            string   param        = string.Format("{0}|{1}", e.BytesReceived, e.TotalBytesToReceive);
            NotiData progressData = new NotiData("UpdateDownloadProgress", param);

            Loom.QueueOnMainThread(delegate
            {
                this.m_SyncEvent(progressData);
            });
            if (e.ProgressPercentage == 100 && e.BytesReceived == e.TotalBytesToReceive)
            {
                NotiData completeData = new NotiData("UpdateDownloadComplete", this.currDownFile);
                Loom.QueueOnMainThread(delegate
                {
                    this.m_SyncEvent(completeData);
                });
            }
        }
 private void OnExtractFile(List <object> evParams)
 {
     if (evParams.Count == 2)
     {
         try
         {
             string zipFileName     = evParams[0] as string;
             string targetDirectory = evParams[1] as string;
             if (this.fzEvents == null)
             {
                 this.fzEvents = new FastZipEvents();
                 FastZipEvents expr_42 = this.fzEvents;
                 expr_42.CompletedFile = (CompletedFileHandler)Delegate.Combine(expr_42.CompletedFile, new CompletedFileHandler(this.FileCompleteListener));
                 FastZipEvents expr_69 = this.fzEvents;
                 expr_69.Progress = (ProgressHandler)Delegate.Combine(expr_69.Progress, new ProgressHandler(this.ProgressChangeListener));
             }
             if (this.fz == null)
             {
                 this.fz = new FastZip(this.fzEvents);
             }
             this.fz.ExtractZip(zipFileName, targetDirectory, null);
         }
         catch (Exception ex)
         {
             NotiData data = new NotiData("ExtractFailed", ex.Message, null);
             if (this.m_SyncEvent != null)
             {
                 this.m_SyncEvent(data);
             }
         }
     }
     else
     {
         string   text  = "Invalid parameter count in extract zip file";
         NotiData data2 = new NotiData("ExtractFailed", text, null);
         if (this.m_SyncEvent != null)
         {
             this.m_SyncEvent(data2);
         }
         Debug.LogError(text);
     }
 }
Beispiel #20
0
        private void ProgressChanged(object sender, DownloadProgressChangedEventArgs e)
        {
            string   value = string.Format("{0} kb/s", (e.BytesReceived / 1024d / sw.Elapsed.TotalSeconds).ToString("0.00"));
            NotiData data  = new NotiData(NotiConst.UPDATE_PROGRESS, value);

            if (m_SyncEvent != null)
            {
                m_SyncEvent(data);
            }

            if (e.ProgressPercentage == 100 && e.BytesReceived == e.TotalBytesToReceive)
            {
                sw.Reset();

                data = new NotiData(NotiConst.UPDATE_DOWNLOAD, currDownFile);
                if (m_SyncEvent != null)
                {
                    m_SyncEvent(data);
                }
            }
        }
Beispiel #21
0
        /// <summary>
        /// 线程完成
        /// </summary>
        /// <param name="data"></param>
        void OnThreadCompleted(NotiData data)
        {
            switch (data.evName)
            {
            case NotiConst.UPDATE_EXTRACT:      //解压一个完成
                                                //
                break;

            case NotiConst.UPDATE_PROGRESS:
                // txtInfo.text = "正在下载更新(" + data.evParam.ToString() + ")";
                Debug.Log(data.evParam.ToString());
                break;

            case NotiConst.UPDATE_BYTES:
                bytesLoaded += (int)data.evParam;
                Debug.Log(bytesLoaded);
                break;

            case NotiConst.UPDATE_DOWNLOAD:     //下载一个完成
                downloadFiles.Add(data.evParam.ToString());
                break;
            }
        }
Beispiel #22
0
        /// <summary>
        /// 线程完成
        /// </summary>
        /// <param name="data"></param>
        void OnThreadCompleted(NotiData data)
        {
            switch (data.evName)
            {
            case NotiConst.DOWNLOAD_EXTRACT:
            {
                var key = data.evParam.ToString();
                if (downloadCheckDatas.ContainsKey(key) && data.extParam != null)
                {
                    var  fileMd5 = MD5.ComputeHashString(data.extParam.ToString());
                    bool success = false;
                    if (fileMd5 != downloadCheckDatas[key])
                    {
                        if (!downloadErrorFiles.Contains(key))
                        {
                            downloadErrorFiles.Add(key);
                        }
                    }
                    else
                    {
                        if (downloadErrorFiles.Contains(key))
                        {
                            downloadErrorFiles.Remove(key);
                        }
                        downloadCheckDatas.Remove(key);
                        success = true;
                    }
                    Loom.DispatchToMainThread(() =>
                        {
                            if (success)
                            {
                                Debugger.Log("[0]Download Success: {0}", key);
                                if (beginPackDownload)
                                {
                                    Util.CallMethod("Game", "OnOnePackFileDownload", key);
                                }
                                SetMd5(key, fileMd5);
                            }
                        });
                }
                extractFiles.Remove(key);
            }
            break;

            case NotiConst.DOWNLOAD_EXTRACT_FAILED:
            {
                var key = data.evParam.ToString();
                extractFiles.Remove(key);
                var message = data.extParam.ToString();
                Loom.DispatchToMainThread(() =>
                    {
                        packDownloadJumpedCount++;
                        Debugger.LogError("Download extract error! {0}", data.extParam.ToString());
                        if (message.Contains("disk full", StringComparison.OrdinalIgnoreCase))
                        {
                            MessageBox.Show(string.Format("{0},{1}", LanguageTips.BACKGROUND_DOWNLOADING_ERROR, LanguageTips.DISK_FULL));
                        }
                    });
            }
            break;
            }
        }