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"); } }
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); }