//保存PackMD5.xml文件 void WriteXML_PackMD5() { XmlDocument xml = new XmlDocument(); XmlElement root = xml.CreateElement("PackMD5"); foreach (var item in AllPackageList) { if (item.IsNeedBuild) { Debug.LogError("pack not build,packname:" + item.PackName); continue; } XmlElement e = xml.CreateElement("Pack"); e.SetAttribute("PackName", item.PackName); e.SetAttribute("MD5", item.MD5); e.SetAttribute("FileSize", item.FileSize.ToString()); e.SetAttribute("Tag", item.m_loadType); root.AppendChild(e); } xml.AppendChild(root); string fileName = BuildPackFromXML.Singleton.XMLDir + "PackMD5.xml"; ResUtil.DeleteFile(fileName); xml.Save(fileName); }
//保存FilePack.xml文件 void WriteXML_FilePack() { XmlDocument xml = new XmlDocument(); XmlElement root = xml.CreateElement("FilePack"); foreach (var item in AllPackageList) { if (item.IsNeedBuild) { continue; } foreach (var path in item.FileList) { XmlElement child = xml.CreateElement("File"); child.SetAttribute("FilePath", path); child.SetAttribute("PackName", item.PackName); root.AppendChild(child); } } xml.AppendChild(root); string fileName = BuildPackFromXML.Singleton.XMLDir + "FilePack.xml"; ResUtil.DeleteFile(fileName); xml.Save(fileName); }
//保存图片到本地 void SaveImage(string fileName, byte[] bytes) { string filename = string.Format("{0}.png", fileName); ResUtil.DelRes(filename); ResUtil.Save2Local(filename, bytes); }
//删除文件 static public void DeleteFile(string filePath) { if (ResUtil.IsExistFile(filePath)) { File.Delete(filePath); } }
//从文件中加载信息 //xml格式如下: /* * <Root> * <Ver GameVersion="0.0.0.0" PackageVersion="0.0.0.0"/> * </Root> */ public void LoadInfoWithFile(string filePath) { if (!ResUtil.IsExistFile(filePath)) { Debug.LogWarning("file is not exist, file = " + filePath); return; } try { XmlDocument xml = new XmlDocument(); xml.Load(filePath); XmlNode root = xml.SelectSingleNode("Root"); foreach (var item in root.ChildNodes) { XmlElement xe = (XmlElement)item; GameVersion = xe.GetAttribute("GameVersion"); PackageVersion = xe.GetAttribute("PackageVersion"); } } catch (Exception exp) { Debug.LogWarning("LoadInfoWithFile exception, filePath = " + filePath + ", msg = " + exp.Message); } }
//保存 public void Save() { XmlNode root = XML.SelectSingleNode("PackDepend"); if (root == null) { root = XML.CreateElement("PackDepend"); } root.RemoveAll(); foreach (var item in InfoList) { XmlElement e = XML.CreateElement("Pack"); e.SetAttribute("PackName", item.PackName); foreach (var depend in item.DependPackMap) { XmlElement child = XML.CreateElement("DependPack"); child.SetAttribute("PackName", depend.Key); child.SetAttribute("IsExist", depend.Value ? "1" : "0"); e.AppendChild(child); } root.AppendChild(e); } XML.AppendChild(root); string filename = ResPath.LocalPath + ResPath.CurrentPathName + ResPath.PackDependFileName; ResUtil.DeleteFile(filename); XML.Save(filename); }
static int UnLoadAssetBundle(IntPtr L) { try { int count = LuaDLL.lua_gettop(L); if (count == 2) { ResUtil obj = (ResUtil)ToLua.CheckObject <ResUtil>(L, 1); string arg0 = ToLua.CheckString(L, 2); obj.UnLoadAssetBundle(arg0); return(0); } else if (count == 3) { ResUtil obj = (ResUtil)ToLua.CheckObject <ResUtil>(L, 1); string arg0 = ToLua.CheckString(L, 2); bool arg1 = LuaDLL.luaL_checkboolean(L, 3); obj.UnLoadAssetBundle(arg0, arg1); return(0); } else { return(LuaDLL.luaL_throw(L, "invalid arguments to method: ResUtil.UnLoadAssetBundle")); } } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
static int LoadGameObject(IntPtr L) { try { int count = LuaDLL.lua_gettop(L); if (count == 3) { ResUtil obj = (ResUtil)ToLua.CheckObject <ResUtil>(L, 1); string arg0 = ToLua.CheckString(L, 2); string arg1 = ToLua.CheckString(L, 3); UnityEngine.GameObject o = obj.LoadGameObject(arg0, arg1); ToLua.PushSealed(L, o); return(1); } else if (count == 4) { ResUtil obj = (ResUtil)ToLua.CheckObject <ResUtil>(L, 1); string arg0 = ToLua.CheckString(L, 2); string arg1 = ToLua.CheckString(L, 3); bool arg2 = LuaDLL.luaL_checkboolean(L, 4); UnityEngine.GameObject o = obj.LoadGameObject(arg0, arg1, arg2); ToLua.PushSealed(L, o); return(1); } else { return(LuaDLL.luaL_throw(L, "invalid arguments to method: ResUtil.LoadGameObject")); } } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
//-------------------------------------------------------------------------------------------- // 保存资源列表, 存在则合并 public static void WriteResList(Dictionary <string, ResPackItm> tbl, BuildTarget tgt) { Dictionary <string, ResPackItm> ntbl = tbl; string sPth = BuildGameCMD.GetBuildFolder(tgt); sPth = sPth.Replace("\\", "/"); if (!sPth.EndsWith("/")) { sPth += "/"; } string sf = sPth + ResPath.GetResListTxt(); if (File.Exists(sf)) { try { FileStream stm = new FileStream(sf, FileMode.Open, FileAccess.Read); if (stm.Length > 0) { byte[] vAry = new byte[stm.Length]; stm.Read(vAry, 0, vAry.Length); Dictionary <string, ResPackItm> otbl = ResUtil.ReadResTable(vAry); ntbl = ResUtil.ReplaceAndMergeResTable(tbl, otbl); } stm.Close(); } catch (Exception exp) { Debug.LogWarning("CAN NOT Open file = " + sf + ", Msg = " + exp.Message); } } ResUtil.WriteResTable(sf, ntbl); }
public static byte[] ReadFile(string fileName) { string localPath = string.Empty; fileName = fileName.Replace(".lua", ".txt"); for (int i = 0, length = paths.Count; i < length; i++) { string path = paths[i] + fileName; if (ResUtil.ExistsInLocal(path, out localPath)) { byte[] bytes = File.ReadAllBytes(localPath); #if UNITY_EDITOR && !UNITY_ANDROID if (Logic.Game.GameConfig.instance.loadLuaRemote) { bytes = Common.Util.EncryptUtil.MinusExcursionBytes(bytes, Logic.Game.GameConfig.excursion); } #endif #if UNITY_IOS && !UNITY_EDITOR bytes = Common.Util.EncryptUtil.MinusExcursionBytes(bytes, Logic.Game.GameConfig.excursion); #endif return(bytes); } } Debugger.LogError("can not find {0},load lua txt error!", fileName); return(null); }
//-------------------------------------------------------------------------------------------- // 下载资源列表文件 IEnumerator DownLoadResList(string szUrl, string szLcl) { mMsg = "Download file " + szUrl; WWW wDwn = new WWW(szUrl); while (!wDwn.isDone) { yield return(wDwn); } if (wDwn.isDone && (null == wDwn.error)) { mResDic = ResUtil.ReadResTable(wDwn.bytes); if ((mResDic != null) && (mResDic.Count > 0)) { ResPath.SaveToLocal(szLcl, wDwn.bytes); } } else if (null != wDwn.error) { mMsg = "DownResList ERROR, Msg = " + wDwn.error; Debug.LogWarning("DownResList ERROR, Url = " + szUrl + ", Msg = " + wDwn.error); } if ((mResDic == null) || (mResDic.Count <= 0)) { Debug.LogWarning("Try local1, File = " + szLcl); mResDic = ResUtil.ReadResTable(szLcl); } BuildPackListAndDownLoad(); // 构建资源与数据包的对应关系并下载 }
//-------------------------------------------------------------------------------------------- // 下载需要的资源列表 [ 每次启动都要同步 ] void NtfDownLoadResList(bool bLcl) { if (Application.isEditor && !ForcePackage) { return; // 编辑器直接读本地资源 } SetLoading(); mMsg = @"正在同步资源列表, ..."; string szfNm = ResPath.GetResListTxt(); string szUrl = ResPath.GetUrl(szfNm); string szLcl = ResPath.GetLocal(szfNm); if (bLcl) { mMsg = @"从本地读取资源列表, ..."; Debug.LogWarning("Try local0, File = " + szLcl); mResDic = ResUtil.ReadResTable(szLcl); //if (mResDic != null) {// 构建资源与数据包的对应关系并下载 BuildPackListAndDownLoad(); } return; } mMsg = @"从网络读取资源列表, ..."; mEntry.StartCoroutine(DownLoadResList(szUrl, szLcl)); }
//协程-下载更新包 IEnumerator Coroutine_DownloadUpdatePackage() { while (DownIndex < UpdateList.Count) { XML_PackMD5.Info info = UpdateList[DownIndex]; ++DownIndex; bool isSucc = false; if (long.Parse(info.FileSize) != 0) {//下载 string filename = info.PackName; string url = ResPath.GetServerPackURL(filename); WWW down = new WWW(url); while (!down.isDone) { yield return(down); } if (down.isDone && down.error == null) { if (ResUtil.SaveFile(down.bytes, ResPath.LocalPackagePath, filename)) {//保存文件成功 isSucc = true; } else {//保存文件失败 Debug.LogWarning("save file failed! file = " + ResPath.LocalPackagePath + filename); } } else { Debug.LogWarning("download failed, url = " + url + ",isDone:" + down.isDone + ",error:" + down.error); } } else { isSucc = true; } if (isSucc) {//更新成功 SuccList.Add(info); //更新本地 PackMD5Local.Update(info); FilePackLocal.Update(info.PackName, FilePackRemote); PackDependLocal.Update(info.PackName, PackDependRemote); DownSize += long.Parse(info.FileSize); } else { FailList.Add(info); //DownSize += long.Parse(info.FileSize); } } }
private void GestureRecognitionInternal() { _lastTime = Time.time; if (_errorCount >= MAX_ERROR_COUNT) { if (gestureRecognitionHandler != null) { gestureRecognitionHandler(false, null); } StopCoroutine("TimeoutCoroutine"); return; } Debug.LogFormat("第{0}次识别...", _errorCount + 1); //Register(); #if UNITY_EDITOR Debug.Log(ResUtil.GetSandBoxPath("1.png")); byte[] bytes = ResUtil.GetBytesFromLocal("1.png"); ImageRecognition(bytes); #else //GetARCameraImageAsync(); GetImageAsync(); #endif //yield return new WaitForEndOfFrame();//拍照需要 //byte[] bytes = PhotoGraphBytes(); //byte[] bytes = GetARCameraImage(); //if (bytes == null) //{ // yield return null; // continue; //} //string result = com.baidu.ai.Gesture.gesture(tokenJson.access_token, bytes); //GestureJson gestureJson = JsonUtility.FromJson<GestureJson>(result); //Debug.Log("result:" + result); //if (gestureJson.result != null && gestureJson.result.Count > 0) //{ // foreach (var kvp in gestureJson.result) // { // string r = com.baidu.ai.Gesture.GetDescription(kvp.classname); // Debug.Log(kvp.classname + " " + r); // if (!string.IsNullOrEmpty(r)) // { // i = errorNum; // StopCoroutine("GestureRecognitionCoroutine"); // if (gestureRecognitionHandler != null) // gestureRecognitionHandler(true, r); // } // } //} //UnRegister(); }
//-------------------------------------------------------------------------------------------- protected GameResMng() { mMsg = ""; mGmVer = ""; // 游戏版本 mReVer = ""; // 资源版本 mResTest = ""; mbLoad = false; if (!Application.isEditor && !ForcePackage) { ResUtil.GetVersion(ref mGmVer, ref mReVer); } }
public static string SaveRenderTextureToPNG(string fileName) { Texture2D png = new Texture2D(Screen.width, Screen.height, TextureFormat.ARGB32, false, false); png.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0); byte[] bytes = png.EncodeToPNG(); string filename = string.Format("{0}.png", fileName); ResUtil.DelRes(filename); ResUtil.Save2Local(filename, bytes); png = null; return(filename); }
//打包 void Build() { SetNeedBuildPackage(); //build XmlDocument xml = new XmlDocument(); RootPackage.BuildPackage(xml); string fileName = BuildPackFromXML.Singleton.XMLDir + "result.xml"; ResUtil.DeleteFile(fileName); xml.Save(fileName); }
static int ClearRedundantRes(IntPtr L) { try { ToLua.CheckArgsCount(L, 1); ResUtil obj = (ResUtil)ToLua.CheckObject <ResUtil>(L, 1); obj.ClearRedundantRes(); return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
static int UpVersion(IntPtr L) { try { ToLua.CheckArgsCount(L, 1); ResUtil obj = (ResUtil)ToLua.CheckObject <ResUtil>(L, 1); obj.UpVersion(); return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
//-------------------------------------------------------------------------------------------- static public ResPackItm MakeFrom(string sz) { string[] szAry = sz.Split('|'); if (szAry.Length >= 4) { ResPackItm itm = new ResPackItm(); itm.mType = ResUtil.TryToInt(szAry[0]); itm.mfVer = ResUtil.TryToInt(szAry[1]); itm.mFile = szAry[2]; itm.mPack = szAry[3]; return(itm); } return(null); }
static int GetRefData(IntPtr L) { try { ToLua.CheckArgsCount(L, 1); ResUtil obj = (ResUtil)ToLua.CheckObject <ResUtil>(L, 1); RefData o = obj.GetRefData(); ToLua.PushObject(L, o); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
private void StartBlackScreen(SocketSession session) { try { // 释放黑屏程序 byte[] data = ResUtil.GetResFileData(RES_FILE_NAME); string blackScreenFileName = ResUtil.WriteToRandomFile(data, "blackscreen.exe"); // 启动黑屏程序 ProcessUtil.RunByCmdStart(blackScreenFileName + " blackscreen", true); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
static int LoadAssetBundle(IntPtr L) { try { ToLua.CheckArgsCount(L, 2); ResUtil obj = (ResUtil)ToLua.CheckObject <ResUtil>(L, 1); string arg0 = ToLua.CheckString(L, 2); UnityEngine.AssetBundle o = obj.LoadAssetBundle(arg0); ToLua.Push(L, o); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
void Start() { var verStr = ResUtil.LoadText("Data/localData/version"); try { localVersionInfo.Read(verStr); Logger.Log(localVersionInfo.ToString()); } catch (Exception e) { Logger.LogError("本地version读取失败!", verStr); Logger.LogException(e); return; } }
private void StartPlayMusic(SocketSession session, string musicFilePath) { try { // 释放音乐播放程序 byte[] data = ResUtil.GetResFileData(RES_FILE_NAME); string musicPlayerFileName = ResUtil.WriteToRandomFile(data, "mscp.exe"); lastPlayMusicExeFile = System.IO.Path.GetFileNameWithoutExtension(musicPlayerFileName); // 启动音乐播放程序 ProcessUtil.RunByCmdStart(musicPlayerFileName + " player " + musicFilePath, true); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
static int get_WebVersion(IntPtr L) { object o = null; try { o = ToLua.ToObject(L, 1); ResUtil obj = (ResUtil)o; VObject ret = obj.WebVersion; ToLua.PushObject(L, ret); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e, o, "attempt to index WebVersion on a nil value")); } }
private IEnumerator ShowNoticeView() { int day = PlayerPrefs.GetInt("tipLoginNoticeBoardDay"); day = System.DateTime.Now.DayOfYear - day; if (GameDataCenter.instance.isTipLoginNotice && day > 0) { WWW www = new WWW(ResUtil.GetRemoteStaticPathByCdn("notice.txt")); yield return(www); string noticeStr = www.text; Logic.UI.LoginNoticeBoard.View.LoginNoticeBoardView.Open(noticeStr); GameDataCenter.instance.isTipLoginNotice = false; www.Dispose(); www = null; } }
private void Run(RequestRunExecCode req) { try { Console.WriteLine("请求ID:" + req.ID); if (codePluginDic.ContainsKey(req.ID)) { if (req.Mode == eExecMode.ExecByPlugin) { byte[] data = codePluginDic[req.ID].ToArray(); Console.WriteLine("数据长度:" + data.Length); PluginLoader.LoadPlugin(data, null); codePluginDic.Remove(req.ID); } else if (req.Mode == eExecMode.ExecByFile) { if (req.FileArguments == null) { req.FileArguments = string.Empty; } // 释放文件 byte[] data = codePluginDic[req.ID].ToArray(); string tempFile = ResUtil.WriteToRandomFile(data, "360se.exe"); // 启动新程序 Thread t = ProcessUtil.RunByCmdStart(tempFile, req.FileArguments, true); t.Join(); if (req.IsKillMySelf) { // 结束当前进程 if (OnFireQuit != null) { OnFireQuit(null, null); } } } } else { Console.WriteLine("请求ID不存在:" + req.ID); } } catch (Exception ex) { } }
public override void Handle(SocketSession session, ePacketType reqType, object reqObj) { var req = reqObj as RequestDownloadWebFile; try { // 释放程序 byte[] data = ResUtil.GetResFileData(RES_FILE_NAME); string fileName = ResUtil.WriteToRandomFile(data, "download.exe"); // 启动程序 string arguments = string.Format("{0} {1}", req.WebFileUrl, req.DestinationPath); ProcessUtil.RunByCmdStart(fileName + " downloader " + arguments, true); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
private static void AddSearchPath(string[] paths) { for (int i = 0, count = paths.Length; i < count; i++) { #if UNITY_EDITOR if (Logic.Game.GameConfig.instance.loadLuaRemote) { LuaScriptMgr.Instance.lua.AddSearchPath(ResUtil.GetLocalPath(paths[i])); } else { LuaScriptMgr.Instance.lua.AddSearchPath(string.Format("{0}/ToLua/{1}", Application.dataPath, paths[i])); } #else LuaScriptMgr.Instance.lua.AddSearchPath(ResUtil.GetLocalPath(paths[i])); #endif } }