Esempio n. 1
0
        public static bool CheckMd5(string path, string file_md5, bool full = false)
        {
            byte[] buffs;
            bool   dataToFile = Pathtool.GetDataToFile(path, out buffs);

            if (dataToFile)
            {
                string md5temp = Md5Helper.Md5Buffer(buffs);
                string md5     = md5temp;
                if (!full)
                {
                    md5 = md5temp.Remove(8);
                }
                if (md5.Equals(file_md5))
                {
                    return(true);
                }
                bool openDownloadLog = AppConst.OpenDownloadLog;
                if (openDownloadLog)
                {
                    Debug.Log(string.Format("res md5 not same, res path:{0},self md5:{1},check md5:{2}", path, md5, file_md5));
                }
            }
            else
            {
                bool openDownloadLog2 = AppConst.OpenDownloadLog;
                if (openDownloadLog2)
                {
                    Debug.Log(string.Format("res md5 not same, res path not exist:{0}", path));
                }
            }
            return(false);
        }
Esempio n. 2
0
 public static bool SaveDataToFile(string path, byte[] buffer)
 {
     if (path.IndexOf(AppConst.StreamingAssets) != -1 && AppConst.UpdateMode)
     {
         if (File.Exists(path))
         {
             File.Delete(path);
         }
         if (Directory.Exists(path))
         {
             Directory.Delete(path);
         }
     }
     if ((!File.Exists(path) && path.IndexOf(AppConst.StreamingAssets) == -1) || !AppConst.UpdateMode)
     {
         Pathtool.CreatePath(path);
     }
     try
     {
         FileStream fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write);
         fs.Write(buffer, 0, buffer.Length);
         fs.Close();
     }
     catch (Exception ex)
     {
         LogMgr.LogError("Can't create local resource" + path);
         return(false);
     }
     return(true);
 }
Esempio n. 3
0
        public static void DeleteToFile(string path)
        {
            bool flag = File.Exists(path);

            if (flag)
            {
                File.Delete(path);
                Pathtool.CreatePath(path);
            }
        }
Esempio n. 4
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");
            }
        }
Esempio n. 5
0
        public float CheckUpdateList(List <UpdateInfo> update_infos)
        {
            if (m_main_sqlite != null && !AppConst.IgnoreUpdateState)
            {
                #region -检查所有文件的version,md5,移除本地db中远程版本没有的文件
                string            res_work_path   = AppUtil.DataPath;//c:/luaframework/
                List <DbFileInfo> delete_infolist = m_main_sqlite.CacheFileList();
                int index = 0;
                while (index < delete_infolist.Count)
                {
                    DbFileInfo old_dbinfo = delete_infolist[index];
                    DbFileInfo new_dbInfo;
                    if (this.m_remote_version.TryGetValue(old_dbinfo.file_name, out new_dbInfo))
                    {
                        bool   is_need_new = false;
                        string file_path   = new_dbInfo.file_name;
                        if (m_ignore_str.Count != 0)
                        {
                            foreach (string item in m_ignore_str)
                            {
                                file_path = file_path.Replace(item, "");
                            }
                        }
                        string full_path = res_work_path + file_path;
                        if (new_dbInfo.version != old_dbinfo.version)
                        {
                            is_need_new = true;
                            if (AppConst.OpenDownloadLog)
                            {
                                Debug.Log(string.Format("res version is not new , need updata::{0},{1},{2},", full_path, new_dbInfo.version, old_dbinfo.version));
                            }
                        }
                        else
                        {
                            if (!Util.CheckMd5(full_path, new_dbInfo.file_md5, false))
                            {
                                if (this.m_zip_state && Util.AssetBundleExists(full_path))
                                {
                                    is_need_new = false;
                                }
                                else
                                {
                                    is_need_new = true;
                                    if (AppConst.OpenDownloadLog)
                                    {
                                        Debug.Log(string.Format("res md5 is not new , need updata::{0},{1},", full_path, new_dbInfo.file_md5));
                                    }
                                }
                            }
                        }
                        if (!is_need_new)
                        {
                            this.m_remote_version.Remove(old_dbinfo.file_name);
                        }
                        delete_infolist.RemoveAt(index);
                    }
                    else
                    {
                        index++;
                    }
                }
                DeleteFileInfoList(delete_infolist);//移除本地db中远程版本没有的文件
                #endregion

                #region -处理剩下需要更新的必要资源信息
                float update_size = 0f;
                foreach (KeyValuePair <string, DbFileInfo> item in this.m_remote_version)
                {
                    DbFileInfo info            = item.Value;
                    string     local_file_name = info.file_name;
                    if (this.m_ignore_str.Count != 0)
                    {
                        foreach (string str in this.m_ignore_str)
                        {
                            local_file_name = local_file_name.Replace(str, "");
                        }
                    }
                    string     path         = res_work_path + local_file_name;
                    UpdateInfo update_info  = new UpdateInfo();
                    int        file_version = ResUpdateManager.Instance.GetFileVersion(info.file_name);
                    string     file_name    = info.file_name;
                    if (this.m_zip_dir.Equals(""))
                    {
                        file_name = file_name.Remove(0, 1);
                    }
                    update_info.http_str = string.Concat(new object[]
                    {
                        this.m_http_path,
                        this.m_zip_dir,
                        file_name,
                        this.m_zip_ext,
                        "?v=",
                        file_version
                    });
                    update_info.file_path = path;
                    update_info.count     = 0;
                    update_info.func      = delegate(byte[] buffer)
                    {
                        Pathtool.DeleteToFile(path);
                        byte[] new_data = buffer;
                        if (this.m_zip_state)
                        {
                            new_data = ZlibStream.UncompressBuffer(buffer);
                        }
                        bool result2;
                        if (Pathtool.SaveDataToFile(path, new_data))
                        {
                            string md5;
                            if (this.m_zip_state)
                            {
                                md5 = Md5Helper.Md5Buffer(buffer);
                            }
                            else
                            {
                                md5 = Md5Helper.Md5Buffer(new_data);
                            }
                            if (!info.file_md5.Equals(md5.Remove(8)))
                            {
                                result2 = false;
                            }
                            else
                            {
                                info.file_md5 = md5;
                                this.m_main_sqlite.ReplaceFileInfoToDb(info);
                                result2 = true;
                            }
                        }
                        else
                        {
                            result2 = false;
                        }
                        return(result2);
                    };

                    int file_size;
                    if (this.m_zip_state)
                    {
                        file_size = info.data_len / 10 / 1024;
                    }
                    else
                    {
                        file_size = info.data_len / 1024;
                    }
                    update_info.file_size = file_size;
                    update_infos.Add(update_info);
                    update_size += (float)file_size;
                }
                #endregion
                return(update_size);
            }
            return(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);
            }
        }
        public IEnumerator CheckVersionFile()
        {
            string dataPath         = AppUtil.DataPath;
            string resPath          = AppUtil.AppContentPath();
            bool   hight_res_update = false;
            int    num;
            WWW    www = null;

            for (int index = 0; index < m_pack_name.Count; index = num)
            {
                #region -解压版本文件到持久化路径下
                string pack_name       = m_pack_name[index];
                string db_file         = GetVersionFile(pack_name, true);                    //patchs/assets_main.sydb
                string version_file    = GetVersionFile(pack_name, false);                   //patchs/assets_head.cymzq
                string patch_file_name = GameConfig.Instance["PatchFileName"];               //patchs
                string patchs_path     = string.Format("{0}{1}", dataPath, patch_file_name); //c:/luaframework/patchs
                if (!Directory.Exists(patchs_path))
                {
                    Pathtool.CreatePath(patchs_path);
                }
                string db_path          = string.Format("{0}{1}", dataPath, db_file);      //c:/luaframework/patchs/assets_main.sydb
                string version_path     = string.Format("{0}{1}", dataPath, version_file); //c:/luaframework/patchs/assets_head.cymzq
                string src_db_path      = string.Format("{0}{1}", resPath, db_file);       //G:/Workspace/github/SyEngine/code/u3d/Assets/StreamingAssets/patchs/assets_main.sydb
                string src_version_path = string.Format("{0}{1}", resPath, version_file);  //G:/Workspace/github/SyEngine/code/u3d/Assets/StreamingAssets/patchs/assets_head.cymzq
                bool   pack_change      = GameConfig.Instance.IsPackChange();
                if (pack_change || !File.Exists(db_path) || !File.Exists(version_path))
                {
                    if (Application.platform == RuntimePlatform.Android)
                    {
                        m_version_file_update[pack_name] = true;
                        if (File.Exists(db_path))
                        {
                            File.Delete(db_path);
                        }
                        www = new WWW(src_db_path);
                        yield return(www);

                        if (www.isDone)
                        {
                            File.WriteAllBytes(db_path, www.bytes);
                        }
                        www.Dispose();
                        www = null;
                        yield return(null);

                        if (File.Exists(version_path))
                        {
                            File.Delete(version_path);
                        }
                        www = new WWW(src_version_path);
                        yield return(www);

                        if (www.isDone)
                        {
                            File.WriteAllBytes(version_path, www.bytes);
                        }
                        www.Dispose();
                        www = null;
                        yield return(null);
                    }
                    else
                    {
                        m_version_file_update[pack_name] = true;
                        File.Copy(src_db_path, db_path, true);
                        File.Copy(src_version_path, version_path, true);
                    }
                }
                if (AppConst.IgnoreUpdateState)
                {
                    m_version_file_update[pack_name] = false;
                }
                if (this.m_version_file_update[pack_name])
                {
                    hight_res_update = true;
                }
                #endregion
                yield return(new WaitForEndOfFrame());

                BusinessManager.Instance.SendMessage(ModuleDef.LaunchModule, "SendMessageCommand", "UpdateProgress", (double)(index + 1) * 100.0 / (double)this.m_pack_name.Count);
                num = index + 1;
            }
            www = null;
            Debug.Log("ResUpdateManager@CheckVersionFile: init patchs succeed");
            InitSqlite();
            Debug.Log("init sqlite succeed");
            GameConfig.Instance.WriteVersion();
            yield break;
        }