static int GetFileMD5(IntPtr L) { try { ToLua.CheckArgsCount(L, 1); string arg0 = ToLua.CheckString(L, 1); string o = NTGResourceController.GetFileMD5(arg0); LuaDLL.lua_pushstring(L, o); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
private IEnumerator doUpdateResources() { if (!NTGApplicationConfig.ResourceUpdateEnabled) { StartGameManager(); yield break; } LuaCall("UpdateResourceAPI", "ShowUpdateInfo", UpdateResourcePanelApi, 1, 0); string dataPath = NTGResourceController.DataPath; //数据目录 string url = NTGApplicationConfig.ResourceUpdateUrl_Android; if (Application.platform == RuntimePlatform.IPhonePlayer || Application.platform == RuntimePlatform.OSXEditor) { url = NTGApplicationConfig.ResourceUpdateUrl_IOS; } WWW www = new WWW(url + "files.txt"); yield return(www); if (www.error != null) { Debug.LogError("Update Resources Failed! :" + www.error.ToString()); StartGameManager(); yield break; } var updateUrls = new ArrayList(); var updateFiles = new ArrayList(); File.WriteAllBytes(dataPath + "files.txt", www.bytes); string[] files = www.text.Split('\n'); for (int i = 0; i < files.Length; i++) { var file = files[i]; if (string.IsNullOrEmpty(file)) { continue; } string[] keyValue = file.Split('|'); string filename = keyValue[0]; string localfile = (dataPath + filename).Trim(); string path = Path.GetDirectoryName(localfile); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string fileUrl = url + filename; bool needUpdate = !File.Exists(localfile); if (!needUpdate) { string remoteMd5 = keyValue[1].Trim(); string localMd5 = NTGResourceController.GetFileMD5(localfile); needUpdate = !remoteMd5.Equals(localMd5); } if (needUpdate) { updateUrls.Add(fileUrl); updateFiles.Add(localfile); } } LuaCall("UpdateResourceAPI", "ShowUpdateInfo", UpdateResourcePanelApi, 2, 0); LuaCall("UpdateResourceAPI", "GetLoadingData", UpdateResourcePanelApi, 0, 0); for (int i = 0; i < updateFiles.Count; i++) { File.Delete((string)updateFiles[i]); var downloader = new NTGResourceController.FileDownloder(); Debug.Log("Updating File:>" + updateUrls[i]); //LuaCall("UpdateResourceAPI", "DebugText", UpdateResourcePanelApi, "下载:" + keyValue[0]); downloader.DownloadFile((string)updateUrls[i], (string)updateFiles[i]); while (!downloader.DownloadComplete) { yield return(null); LuaCall("UpdateResourceAPI", "GetLoadingData", UpdateResourcePanelApi, downloader.DownloadingSpeed, ((float)i) / updateUrls.Count); } LuaCall("UpdateResourceAPI", "GetLoadingData", UpdateResourcePanelApi, downloader.DownloadingSpeed, ((float)i + 1) / updateUrls.Count); yield return(null); } StartGameManager(); }
/// <summary> /// 生成绑定素材 /// </summary> public static void BuildAssetResource(BuildTarget target, bool isWin) { string dataPath = NTGResourceController.DataPath; if (Directory.Exists(dataPath)) { Directory.Delete(dataPath, true); } string assetfile = string.Empty; //素材文件名 string resPath = AppDataPath + "/StreamingAssets/"; if (!Directory.Exists(resPath)) { Directory.CreateDirectory(resPath); } BuildPipeline.BuildAssetBundles(resPath, BuildAssetBundleOptions.None, target); string luaPath = resPath + "/lua/"; //----------复制Lua文件---------------- if (Directory.Exists(luaPath)) { Directory.Delete(luaPath, true); } Directory.CreateDirectory(luaPath); paths.Clear(); files.Clear(); string luaDataPath = Application.dataPath + "/Lua/".ToLower(); Recursive(luaDataPath); int n = 0; foreach (string f in files) { if (f.EndsWith(".meta")) { continue; } string newfile = f.Replace(luaDataPath, ""); string newpath = luaPath + newfile; string path = Path.GetDirectoryName(newpath); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } if (File.Exists(newpath)) { File.Delete(newpath); } if (NTGApplicationConfig.LuaEncode) { UpdateProgress(n++, files.Count, newpath); EncodeLuaFile(f, newpath, isWin); } else { File.Copy(f, newpath, true); } } paths.Clear(); files.Clear(); luaDataPath = Application.dataPath + "/ToLua/Lua/".ToLower(); Recursive(luaDataPath); n = 0; foreach (string f in files) { if (f.EndsWith(".meta")) { continue; } string newfile = f.Replace(luaDataPath, ""); string newpath = luaPath + newfile; string path = Path.GetDirectoryName(newpath); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } if (File.Exists(newpath)) { File.Delete(newpath); } if (NTGApplicationConfig.LuaEncode) { UpdateProgress(n++, files.Count, newpath); EncodeLuaFile(f, newpath, isWin); } else { File.Copy(f, newpath, true); } } EditorUtility.ClearProgressBar(); ///----------------------创建文件列表----------------------- string newFilePath = resPath + "/files.txt"; if (File.Exists(newFilePath)) { File.Delete(newFilePath); } paths.Clear(); files.Clear(); Recursive(resPath); FileStream fs = new FileStream(newFilePath, FileMode.CreateNew); StreamWriter sw = new StreamWriter(fs); for (int i = 0; i < files.Count; i++) { string file = files[i]; string ext = Path.GetExtension(file); if (file.EndsWith(".meta") || file.Contains(".DS_Store")) { continue; } string md5 = NTGResourceController.GetFileMD5(file); string value = file.Replace(resPath, string.Empty); sw.WriteLine(value + "|" + md5); } sw.Close(); fs.Close(); AssetDatabase.Refresh(); }