static int _CreateLuaFramework_AppConst(IntPtr L) { try { int count = LuaDLL.lua_gettop(L); if (count == 0) { LuaFramework.AppConst obj = new LuaFramework.AppConst(); ToLua.PushObject(L, obj); return(1); } else { return(LuaDLL.luaL_throw(L, "invalid arguments to ctor method: LuaFramework.AppConst.New")); } } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
/// <summary> /// 启动更新下载,这里只是个思路演示,此处可启动线程下载更新 /// </summary> IEnumerator OnUpdateResource() { if (!AppConst.UpdateMode) { OnResourceInited(); yield break; } string dataPath = Util.DataPath; //数据目录 string message = string.Empty; string random = DateTime.Now.ToString("yyyymmddhhmmss"); string listUrl = url + "files.txt?v=" + random; Debug.LogWarning("LoadUpdate---->>>" + listUrl); WWW www = new WWW(listUrl); yield return(www); if (www.error != null) { OnUpdateFailed(string.Empty); ShowNetTip(); yield break; } if (!Directory.Exists(dataPath)) { Directory.CreateDirectory(dataPath); } File.WriteAllBytes(dataPath + "files.txt", www.bytes); string filesText = www.text; string[] files = filesText.Split('\n'); txtInfo.text = "正在检查更新..."; txtPer.text = "0%"; pgsPer.fillAmount = 0; //SetFillAmountPos(0); List <string> needUpdateFiles = new List <string>(); List <int> fileLens = new List <int>(); for (int i = 0; i < files.Length; i++) { if (string.IsNullOrEmpty(files[i])) { continue; } string[] keyValue = files[i].Split('|'); string f = keyValue[0]; string localfile = (dataPath + f).Trim(); string path = Path.GetDirectoryName(localfile); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } // string fileUrl = url + f + "?v=" + random; bool canUpdate = !File.Exists(localfile); if (!canUpdate) { string remoteMd5 = keyValue[1].Trim(); string localMd5 = Util.md5file(localfile); canUpdate = !remoteMd5.Equals(localMd5); if (canUpdate) { File.Delete(localfile); } } if (canUpdate) { //本地缺少文件 int fl = int.Parse(keyValue[2].Trim()); bytesTotal += fl; needUpdateFiles.Add(f); fileLens.Add(fl); // Debug.Log(fileUrl); // message = "downloading>>" + fileUrl; // facade.SendMessageCommand(NotiConst.UPDATE_MESSAGE, message); /* * www = new WWW(fileUrl); yield return www; * if (www.error != null) { * OnUpdateFailed(path); // * yield break; * } * File.WriteAllBytes(localfile, www.bytes); */ //这里都是资源文件,用线程下载 // BeginDownload(fileUrl, localfile); // while (!(IsDownOK(localfile))) { yield return new WaitForEndOfFrame(); } } } if (AppConst.getNetType() == 2) { int needDown = bytesTotal / 1024 / 1024; if (needDown > 0) { ShowUpdateTip(needDown + "MB"); while (!isUpdate) { yield return(new WaitForEndOfFrame()); } } } txtInfo.text = "准备下载更新..."; for (int i = 0; i < needUpdateFiles.Count; i++) { string file = needUpdateFiles[i]; int size = fileLens[i]; string localfile = (dataPath + file).Trim(); string fileUrl = url + file + "?v=" + random; Debug.Log(fileUrl); message = "downloading>>" + fileUrl; facade.SendMessageCommand(NotiConst.UPDATE_MESSAGE, message); www = new WWW(fileUrl); while (!www.isDone) { int loaded = bytesLoaded + (int)(www.progress * size); txtPer.text = (int)((float)loaded / bytesTotal * 100) + "%"; pgsPer.fillAmount = (float)loaded / bytesTotal; //SetFillAmountPos((float)loaded / bytesTotal); txtInfo.text = "正在下载更新...(" + loaded / 1024 + "KB)"; yield return(new WaitForEndOfFrame()); } bytesLoaded += size; if (www.error != null) { OnUpdateFailed(fileUrl); // ShowNetTip(); yield break; } File.WriteAllBytes(localfile, www.bytes); // BeginDownload(fileUrl, localfile); // while (!(IsDownOK(localfile))) { // txtPer.text = (bytesLoaded*100/bytesTotal) + "%"; // pgsPer.fillAmount = (float)bytesLoaded / bytesTotal; // yield return new WaitForEndOfFrame(); // } } yield return(new WaitForEndOfFrame()); message = "更新完成!!"; txtPer.text = "100%"; pgsPer.fillAmount = 1; //SetFillAmountPos(1); AppConst.version = verNum; facade.SendMessageCommand(NotiConst.UPDATE_MESSAGE, message); OnResourceInited(); }
static int _CreateLuaFramework_AppConst(IntPtr L) { try { int count = LuaDLL.lua_gettop(L); if (count == 0) { LuaFramework.AppConst obj = new LuaFramework.AppConst(); ToLua.PushObject(L, obj); return 1; } else { return LuaDLL.luaL_throw(L, "invalid arguments to ctor method: LuaFramework.AppConst.New"); } } catch(Exception e) { return LuaDLL.toluaL_exception(L, e); } }