static int ReadInt(IntPtr L) { try { ToLua.CheckArgsCount(L, 1); LuaFramework.ByteBuffer obj = (LuaFramework.ByteBuffer)ToLua.CheckObject <LuaFramework.ByteBuffer>(L, 1); int o = obj.ReadInt(); LuaDLL.lua_pushinteger(L, o); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
IEnumerator OnExtractResource() { Util.Log("------> extract start <------"); string dataPath = Util.DataPath; //数据目录 string resPath = Util.AppContentPath(); //游戏包资源目录 if (!Directory.Exists(dataPath)) { Directory.CreateDirectory(dataPath); } yield return(null); //md5对比 //包内 string aplicationFileMD5 = resPath + AppConst.FinalSingleFileInfoMD5; //包外 string persistentFileMD5 = dataPath + AppConst.FinalSingleFileInfoMD5; string aplicationMd5String = null; string persistentMd5String = null; // 读取文件列表 // string aplicationFileListName = resPath + AppConst.FinalSingleFileInfo; //获取md5? //获取包外 if (File.Exists(persistentFileMD5)) { persistentMd5String = File.ReadAllText(persistentFileMD5); } //包内 WWW www = new WWW(aplicationFileMD5); yield return(www); aplicationMd5String = www.text; www.Dispose(); // md5验证相同,跳过解压 if (persistentMd5String != null && persistentMd5String.Equals(aplicationMd5String)) { StartCoroutine(OnUpdateResource()); yield break; } //md5验证不同或者data目录不存在MD5文件 //读取整个单文件 string inFile = resPath + AppConst.FinalSingleFile; www = new WWW(inFile); yield return(www); //解析文件 ByteBuffer buffer = new ByteBuffer(www.bytes); int idx = 0; int curIndex = 0; int totalCount = buffer.ReadInt(); byte[] wwwByte = www.bytes; NotiConst.MsgProgress msgProgress; for (int i = 0; i < totalCount; i++) { //开始写吧 string outFile = dataPath + buffer.ReadString(); string dir = Path.GetDirectoryName(outFile); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } File.WriteAllBytes(outFile, buffer.ReadBytes()); curIndex++; if (idx++ > 10) // 限制每帧加载4个文件 { idx = 0; msgProgress.progress = (float)curIndex / (float)totalCount; msgProgress.notice = string.Format("正在解压:({0}%)", (int)(msgProgress.progress * 100)); facade.SendMessageCommand(NotiConst.LOADING_PROGRESS, msgProgress); yield return(null); } } buffer.Close(); www.Dispose(); //facade.SendMessageCommand( NotiConst.UPDATE_EXTRACT, "解压完毕(100%)" ); //加载完之后 将包内的md5信息写到包外 File.WriteAllText(persistentFileMD5, aplicationMd5String); //Debug.Log("OnExtractResource Done"); StartCoroutine(OnUpdateResource()); }