コード例 #1
0
 public void RequestMemoryAsync(MemoryQuest memory_quest, MemoryLoadCallbackFunc callback)
 {
     if (AppConst.UseUpdatOriModeReal && AppConst.UseUpdatOriThreadMode)
     {
         if (this.m_thread == null)
         {
             this.m_thread = new Thread(new ThreadStart(this.OnThreadUpdate));
             this.m_thread.Start();
         }
         DownloadData data = new DownloadData();
         data.callback     = callback;
         data.memory_quest = memory_quest;
         //如果没有传save_path,则默认是下载byte[]数据
         if (string.IsNullOrEmpty(memory_quest.save_path))
         {
             data.IsFile = false;
         }
         else
         {
             data.IsFile = true;
         }
         Queue <DownloadData> request_list = ResRequest.m_request_list;
         lock (request_list)
         {
             ResRequest.m_request_list.Enqueue(data);
         }
     }
     else
     {
         MonoHelper.StartCoroutine(this.LoadToMemoryAsyncImpl(memory_quest, callback));
     }
 }
コード例 #2
0
        public override void OnStateEnter(GameState pCurState)
        {
            string backup_url = GameConfig.Instance["ResUrl"];

            if (CheckUpdateService.Instance.backupUrlState == BackUpUrlState.RUN)
            {
                backup_url = GameConfig.Instance["BackUpUrl"];
            }
            string      remote_cfg_url = backup_url + GameConfig.Instance["ConfigUrl"] + "?v=" + Util.GetTimeStamp();
            MemoryQuest memory_quest   = new MemoryQuest();

            memory_quest.RelativePath = remote_cfg_url;
            string server_config = GameConfig.Instance["GetServerConfig"];

            BusinessManager.Instance.SendMessage(ModuleDef.LaunchModule, "SendMessageCommand", "UpdateMessage");
            MemoryLoadCallbackFunc delay_func = delegate(bool is_suc, byte[] buffer)
            {
                bool load_state = false;
                if (is_suc)
                {
                    load_state = true;
                    if (!GameConfig.Instance.LoadRemoteConfig(buffer))
                    {
                        load_state = false;
                    }
                    else
                    {
                        //使用新的Cnd地址
                        string new_cdn_url = GameConfig.Instance.GetValue("NewCdnUrl");
                        if (new_cdn_url != null && new_cdn_url != "")
                        {
                            CheckUpdateService.Instance.backupUrlState = BackUpUrlState.NEW;
                            CheckUpdateService.Instance.ToUpdateConfigState();
                            return;
                        }
                        if (CheckUpdateService.Instance.backupUrlState == BackUpUrlState.RUN)
                        {
                            CheckUpdateService.Instance.backupUrlState = BackUpUrlState.None;
                            string url = GameConfig.Instance.GetValue("BackUpUrl");
                            GameConfig.Instance.SetValue("ResUrl", url);
                        }
                        this.m_finish_state = true;
                    }
                }
                if (!load_state)
                {
                    this.RetryLoadConfig();
                }
            };

            ResRequest.Instance.RequestMemoryAsync(memory_quest, delay_func);
        }
コード例 #3
0
 private void DownloadDataCompleted(MemoryLoadCallbackFunc callback, DownloadDataCompletedEventArgs e)
 {
     if (e != null && e.Error != null)
     {
         LogMgr.Log(e.Error.ToString());
         callback(false, null);
     }
     else
     {
         callback(true, e.Result);
     }
     this.m_download_state = false;
 }
コード例 #4
0
        private void DownloadFileCompleted(MemoryLoadCallbackFunc callback, AsyncCompletedEventArgs e)
        {
            bool flag = e != null && e.Error != null;

            if (flag)
            {
                LogMgr.Log(e.Error.ToString());
                callback(false, null);
            }
            else
            {
                callback(true, null);
            }
            this.m_download_state = false;
        }
コード例 #5
0
        public void DownLoadVersionFileAndCheck()
        {
            bool ignoreUpdateState = AppConst.IgnoreUpdateState;

            if (ignoreUpdateState)
            {
                this.m_version_file_check_state = true;
            }
            else
            {
                string version_file               = GameConfig.Instance["Md5FileName"];
                string version_file_url           = string.Format("{0}{1}", this.m_http_path, version_file);
                string local_path                 = string.Format("{0}{1}", AppUtil.DataPath, version_file);
                MemoryLoadCallbackFunc delay_func = delegate(bool is_suc, byte[] buffer)
                {
                    if (is_suc)
                    {
                        LogMgr.Log("download version file Success");
                        this.ParseVersionFile(buffer);
                    }
                    else
                    {
                        LogMgr.Log("request version file error {0}", version_file_url);
                    }
                };
                MemoryQuest memory_quest = new MemoryQuest();
                string      patchs       = GameConfig.Instance.GetValue("PatchFileName");
                if (Application.platform == RuntimePlatform.Android)
                {
                    string androidpatchs = GameConfig.Instance.GetValue("AndroidPatchFileName");
                    version_file_url = version_file_url.Replace(patchs, androidpatchs);
                }
                else
                {
                    if (Application.platform == RuntimePlatform.IPhonePlayer)
                    {
                        string iospatchs = GameConfig.Instance.GetValue("IosPatchFileName");
                        version_file_url = version_file_url.Replace(patchs, iospatchs);
                    }
                }
                memory_quest.RelativePath = string.Format("{0}?v={1}", version_file_url, Util.GetTimeStamp());
                LogMgr.Log("download file:{0}", memory_quest.RelativePath);
                ResRequest.Instance.RequestMemoryAsync(memory_quest, delay_func);
            }
        }
コード例 #6
0
        public void InitSqlite(bool update_version)
        {
            string          res_work_path = AppUtil.DataPath;                    // c:/luaframework/
            string          http_str      = m_http_path + m_remote_version_file; //http://192.168.7.223/patchs/xxx_head.cymzq
            RuntimePlatform platform      = Application.platform;

            if (platform == RuntimePlatform.IPhonePlayer)
            {
                http_str = http_str.Replace("patchs", "patchsIos");
            }
            else if (platform == RuntimePlatform.Android)
            {
                http_str = http_str.Replace("patchs", "patchsAndroid");
            }

            string path = res_work_path + m_remote_version_file;//c:/luaframework/patchs/xxx_head.cymzq

            m_main_sqlite = new Sqlite3tool();
            string real_db_path = res_work_path + m_real_db_file;//c:/luaframework/patchs/xxx_main.sydb

            if (m_main_sqlite.OpenOrCreateDb(real_db_path))
            {
                Debug.Log("SqliteFilePack@InitSqlite: OpenOrCreateDb succeed");
                if (update_version)
                {
                    MemoryLoadCallbackFunc delay_func = delegate(bool is_suc, byte[] buffer)
                    {
                        if (is_suc)
                        {
                            Util.Log("PackResult.Success");
                            Pathtool.DeleteToFile(path);
                            bool flag2 = Pathtool.SaveDataToFile(path, buffer);
                            if (flag2)
                            {
                                Sqlite3tool.OpenCyMzq(path, ref this.m_remote_version);
                                this.m_result = PackResult.Success;
                                LogMgr.Log("OpenCyMzq {0}", path);
                            }
                        }
                        else
                        {
                            LogMgr.Log("PackResult.Faild");
                            this.m_result = PackResult.Faild;
                            LogMgr.LogError(string.Format("init sqlite error {0}", path));
                        }
                    };
                    MemoryQuest memory_quest = new MemoryQuest();
                    memory_quest.RelativePath = http_str + "?v=" + Util.GetTimeStamp();
                    LogMgr.Log("download file:{0}", memory_quest.RelativePath);
                    ResRequest.Instance.RequestMemoryAsync(memory_quest, delay_func);
                }
                else
                {
                    Sqlite3tool.OpenCyMzq(path, ref this.m_remote_version);
                    m_result = PackResult.Success;
                    Debug.Log("OpenCyMzq " + path);
                }
            }
            else
            {
                m_main_sqlite.CloseDb();
                Debug.Log("OpenOrCreateDb error");
            }
        }
コード例 #7
0
        private void UpdateInfosLoading()
        {
            int count = this.m_update_infos.Count;

            if (this.m_loadind_map.Count < this.m_max_count && count > 0 && !this.m_stop_update_state)
            {
                UpdateInfo info = this.m_update_infos[count - 1];
                this.m_update_infos.RemoveAt(count - 1);
                MemoryLoadCallbackFunc delay_func = delegate(bool is_suc, byte[] buffer)
                {
                    bool flag3 = this.m_loadind_map.ContainsKey(info.file_path);
                    if (flag3)
                    {
                        this.m_loadind_map.Remove(info.file_path);
                    }
                    if (is_suc)
                    {
                        bool state = true;
                        bool flag4 = info.func != null;
                        if (flag4)
                        {
                            bool flag5 = !AppConst.UseUpdatOriModeReal;
                            if (flag5)
                            {
                                state = info.func(buffer);
                            }
                            else
                            {
                                state = false;
                                string file_path = info.file_path;
                                byte[] buffs;
                                bool   dataToFile = Pathtool.GetDataToFile(file_path, out buffs);
                                if (dataToFile)
                                {
                                    state = info.func(buffs);
                                }
                                buffs = null;
                            }
                        }
                        string md5_exit = GameConfig.Instance.GetValue("OpenMd5ErrorExitState");
                        bool   flag7    = state || md5_exit.Equals("0");
                        if (flag7)
                        {
                            this.m_loaded_count++;
                            this.m_lase_update_size += (float)info.file_size;
                            this.m_cur_update_size  += (float)info.file_size;
                            bool flag8 = this.m_last_download_time == 0f;
                            if (flag8)
                            {
                                this.m_download_speed     = 100f;
                                this.m_last_download_time = Time.time;
                            }
                            else
                            {
                                float pass_time = Time.time - this.m_last_download_time;
                                bool  flag9     = pass_time > 1f;
                                if (flag9)
                                {
                                    this.m_last_download_time = Time.time;
                                    this.m_download_speed     = this.m_lase_update_size / pass_time;
                                    this.m_lase_update_size   = 0f;
                                }
                            }
                        }
                        else
                        {
                            LogMgr.Log("download md5 error {0}", info.file_path);
                            bool random_state = info.random_state;
                            if (random_state)
                            {
                                this.m_stop_update_state = true;
                                string md5_error = GameConfig.Instance.GetValue("UpdateFileMd5ErrorMsg");
                                BusinessManager.Instance.SendMessage(ModuleDef.LaunchModule, "SendMessageCommand", "UPDATE_RES_MD5_ERROR", md5_error);
                            }
                            else
                            {
                                LogMgr.Log("md5 check error {0}", info.file_path);
                                info.count = 0;
                                string[] array = info.http_str.Split(new char[]
                                {
                                    '?'
                                });
                                bool flag10 = array.Length != 0;
                                if (flag10)
                                {
                                    string new_httpstr = array[0] + "?v=" + Util.GetTimeStamp();
                                    info.http_str       = new_httpstr;
                                    info.random_state   = true;
                                    info.www            = null;
                                    info.request        = null;
                                    info.download_again = true;
                                    this.m_update_infos.Add(info);
                                }
                            }
                        }
                    }
                    else
                    {
                        info.www            = null;
                        info.request        = null;
                        info.download_again = true;
                        bool flag11 = info.count < 3;
                        if (flag11)
                        {
                            info.count++;
                            this.m_update_infos.Add(info);
                        }
                        else
                        {
                            info.count = 0;
                            this.m_update_infos.Add(info);
                        }
                        LogMgr.Log("download again {0}", info.file_path);
                    }
                };
                MemoryQuest memory_quest = new MemoryQuest();
                memory_quest.RelativePath = info.http_str;
                memory_quest.timeout      = AppConst.UpdateFileTimeout;
                if (AppConst.UseUpdatOriModeReal)
                {
                    memory_quest.save_path = info.file_path;
                }
                if (info.download_again)
                {
                    memory_quest.timeout = AppConst.UpdateFileTimeout * 4;
                }
                if (AppConst.OpenDownloadLog)
                {
                    LogMgr.Log("res start update, res path:{0}", info.http_str);
                }
                ResRequest.Instance.RequestMemoryAsync(memory_quest, delay_func);
                if (memory_quest.Www != null)
                {
                    info.www = (memory_quest.Www as WWW);
                }
                else
                {
                    info.request = memory_quest.request;
                }
                this.m_loadind_map.Add(info.file_path, info);
            }
        }
コード例 #8
0
        private IEnumerator LoadToMemoryAsyncImpl(MemoryQuest memory_quest, MemoryLoadCallbackFunc callback)
        {
            bool openDownloadLog = AppConst.OpenDownloadLog;

            if (openDownloadLog)
            {
                LogMgr.Log("update file, url:{0},", memory_quest.RelativePath);
            }
            bool useUpdateNewMode = AppConst.UseUpdateNewMode;

            if (useUpdateNewMode)
            {
                UnityWebRequest webRequest = UnityWebRequest.Get(memory_quest.RelativePath);
                memory_quest.request = webRequest;
                webRequest.timeout   = memory_quest.timeout;
                yield return(webRequest.SendWebRequest());

                bool flag = webRequest.isNetworkError || webRequest.isHttpError || webRequest.downloadHandler == null || webRequest.downloadHandler.data == null;
                if (flag)
                {
                    LogMgr.Log("res request error occurr, res url:{0}, error:{1}, responseCode:{2}, downloadProgress:{3},isNetworkError:{4}, isHttpError:{5}",
                               memory_quest.RelativePath,
                               webRequest.error,
                               webRequest.responseCode,
                               webRequest.downloadProgress,
                               webRequest.isNetworkError,
                               webRequest.isHttpError
                               );
                    callback(false, null);
                }
                else
                {
                    callback(true, webRequest.downloadHandler.data);
                }
                bool useDeleteRequestMode = AppConst.UseDeleteRequestMode;
                if (useDeleteRequestMode)
                {
                    UnityWebRequest.Delete(memory_quest.RelativePath);
                }
                webRequest.Dispose();
                webRequest = null;
                webRequest = null;
            }
            else
            {
                bool useUpdatOriModeReal = AppConst.UseUpdatOriModeReal;
                if (useUpdatOriModeReal)
                {
                    ProgressEventProxyUpdate pro_event_proxy = new ProgressEventProxyUpdate();
                    pro_event_proxy.FileCompleteMethod = new Action <MemoryLoadCallbackFunc, AsyncCompletedEventArgs>(this.DownloadFileCompleted);
                    pro_event_proxy.CallBack           = callback;
                    WebClient client = new WebClient();
                    client.DownloadFileCompleted += pro_event_proxy.DownloadFileCompleted;
                    string save_path = memory_quest.save_path;
                    client.DownloadFileAsync(new Uri(memory_quest.RelativePath), save_path);
                    pro_event_proxy = null;
                    client          = null;
                    save_path       = null;
                }
                else
                {
                    WWW www = new WWW(memory_quest.RelativePath);
                    memory_quest.Www = www;
                    yield return(www);

                    bool flag3 = !string.IsNullOrEmpty(www.error) || www.bytes == null;
                    if (flag3)
                    {
                        LogMgr.Log("res request error occurr, res url:{0}, error:{1}", memory_quest.RelativePath, www.error);
                        callback(false, null);
                    }
                    else
                    {
                        byte[] bytes = www.bytes;
                        callback(true, bytes);
                        bytes = null;
                    }
                    www.Dispose();
                    www = null;
                    www = null;
                }
            }
            yield break;
        }