private static int LoadGlobalSetting(IntPtr L) { int result; try { ToLua.CheckArgsCount(L, 0); User_Config.LoadGlobalSetting(); result = 0; } catch (Exception e) { result = LuaDLL.toluaL_exception(L, e, null); } return(result); }
void LoadConfig() { // first check local config exists or not string content = string.Empty; if (!AppConst.DebugMode && !Directory.Exists(Util.DataPath)) { Directory.CreateDirectory(Util.DataPath); } string config_path = Util.DataPath + "/config.txt"; if (FileManager.FileExist(config_path)) { content = FileManager.ReadFileString(config_path); } else { TextAsset obj = Resources.Load <TextAsset>("config"); #if UNITY_EDITOR if (obj == null) { File.Copy("Assets/config.txt.example", "Assets/Resources/config.txt", true); UnityEditor.AssetDatabase.Refresh(); obj = Resources.Load <TextAsset>("config"); } #else if (obj == null) { MessageBox.Show(UpdateTips.NO_CONFIG_VIA_MOBLIEPLATFORM, (int)MessageBox.Style.OkOnly, (go) => { Application.Quit(); }); } #endif content = obj.text; #if !UNITY_EDITOR FileManager.WriteFile(config_path, content); #endif } // load config User_Config.LoadConfig(content); User_Config.LoadGlobalSetting(); #if UNITY_IOS && !UNITY_EDITOR // iphone 6及以下强行设置为流畅 否则可能出现内存问题闪退 try { string deviceVersion = SystemInfo.deviceModel; Debug.Log(deviceVersion); if (!string.IsNullOrEmpty(deviceVersion)) { string[] tmps = deviceVersion.Split(','); Debug.Assert(tmps.Length == 2); int iVer = Convert.ToInt32(tmps[0].Substring(tmps[0].Length - 1, 1)); if (iVer < 7 || (iVer == 7 && tmps[1].Equals("iPhone7,2"))) { Debug.Log("iphone version < iphone6, set quality to 0"); User_Config.quality = 0; } } } catch (Exception e) { Debug.LogException(e); } #endif }
/// <summary> /// 释放本地的整包资源 /// </summary> /// <returns></returns> public IEnumerator OnExtractResources() { ThreadManager threadMgr = AppFacade.Instance.GetManager <ThreadManager>(); if (extractStartTime == 0) { extractStartTime = Time.realtimeSinceStartup; } if (extractErrorCount >= 3) { MessageBox.Show(LanguageTips.READ_FILES_ERROR_QUIT, (result) => { Application.Quit(); }); yield break; } extractFiles.Clear(); #if UNITY_EDITOR PlayerPrefs.DeleteAll(); #else if (Application.platform == RuntimePlatform.WindowsPlayer) { PlayerPrefs.DeleteAll(); } #endif string dataPath = Util.DataPath; //数据目录 string resPath = Path.Combine(Util.StreamingAssetsPath(), LuaConst.osDir); //游戏包资源目录 if (Application.platform != RuntimePlatform.WindowsPlayer) { if (Directory.Exists(dataPath)) { Directory.Delete(dataPath, true); } Directory.CreateDirectory(dataPath); } // 解压前先重新加载一次config,防止覆盖安装config文件不能更改的问题 TextAsset obj = Resources.Load <TextAsset>("config"); if (obj == null) { MessageBox.Show(LanguageTips.NO_CONFIG_VIA_MOBLIEPLATFORM, (result) => { Application.Quit(); }); } string config_path = Util.DataPath + "/config.txt"; if (File.Exists(config_path)) { File.Delete(config_path); } FileManager.WriteFile(config_path, obj.text); User_Config.ResetConfig(obj.text); User_Config.LoadGlobalSetting(); string splitFile = Path.Combine(resPath, "split.txt"); WWW www = new WWW(splitFile); yield return(www); if (www.isDone && www.text == "1") { LuaHelper.GetGameManager().downloadAll = true; } if (www != null) { www.Dispose(); } if (LuaHelper.GetGameManager().downloadAll) { onExtractComplete(null); yield break; } yield return(Yielders.EndOfFrame); string infile = Path.Combine(resPath, "packlist.txt"); string content = string.Empty; // Debug.Log(infile); www = new WWW(infile); yield return(www); if (www.isDone) { content = www.text; } www.Dispose(); yield return(Yielders.EndOfFrame); //释放所有文件到数据目录 string[] files = content.Split('\n'); #if UNITY_IOS extractLeftFiles.AddRange(files); curSingleStreamingIndex = 0; totalSingleStreamingCount = files.Length; bar.UpdateProgress(0); if (extractLeftFiles.Count > 0) { bar.SetMessage(LanguageTips.READ_FILES); } LuaHelper.GetGameManager().StartCoroutine(ExtractOneByOne()); #else int curStreamingIndex = 0; int totalStreamingCount = files.Length; string outfile = string.Empty; List <LocalExtractExecutor> les = new List <LocalExtractExecutor>(); bar.SetMessage(LanguageTips.READ_FILES); for (int i = 0; i < files.Length; ++i) { var file = files[i].Trim(); curStreamingIndex++; var percent1 = (float)curStreamingIndex / (float)totalStreamingCount; bar.SetMessage(string.Format("{0}: {1}%", LanguageTips.READ_FILES, (percent1 * 100).ToString("f0"))); bar.UpdateProgress(percent1); if (string.IsNullOrEmpty(file)) { continue; } string[] fs = file.Split('|'); infile = Path.Combine(resPath, fs[0]); // outfile = dataPath + fs[0]; string srcMd5 = fs[1].Trim(); Debug.Assert(fs.Length == 2, "read packlist.txt error:" + file); bool isBinFile = outfile.CustomEndsWith(".bin"); //文件被非法删除,Bin文件无法确认存在,只能直接再释放一次 var tempMd5 = string.Format("{0}_md5", fs[0]); if (isBinFile || !File.Exists(outfile)) { PlayerPrefs.DeleteKey(fs[0]); PlayerPrefs.DeleteKey(tempMd5); } if (srcMd5 == PlayerPrefs.GetString(tempMd5)) { if (isBinFile) { totalExtractCount++; } continue; } WWW streamingWWW = new WWW(infile); yield return(streamingWWW); if (streamingWWW.error != null) { Debug.LogError(infile); continue; } if (streamingWWW.isDone) { string dir = Path.GetDirectoryName(outfile); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } if (isBinFile) { LocalExtractExecutor lee = new LocalExtractExecutor(); lee.LocalPath = dataPath; lee.FileName = fs[0]; lee.SrcMD5 = srcMd5; lee.FileBytes = streamingWWW.bytes; lee.OnComplete = OnUpdateChangeStatus; totalExtractCount++; les.Add(lee); extractFiles.Add(fs[0]); } else { File.WriteAllBytes(outfile, streamingWWW.bytes); PlayerPrefs.SetInt(fs[0], 1); PlayerPrefs.SetString(tempMd5, srcMd5); if (curStreamingIndex % 3 == 0) //每写入3个文件后保存记录,减少IO { PlayerPrefs.Save(); } // Debugger.Log("正在解包文件:>" + infile) ; } } streamingWWW.Dispose(); } yield return(Yielders.EndOfFrame); //启动多线程解压 // Debugger.Log("MaxThreadCount:" + maxThreadCount); bar.UpdateProgress(0); if (les.Count > 0) { bar.SetMessage(LanguageTips.EXTRACT_PACKAGE); threadMgr.PoolScheduler.StartASyncThreads(les.ToArray(), onExtractComplete, onExtractDone, maxThreadCount); } else { onExtractComplete(null); } #endif }