void LoadLib() { if (!bLoodLib) { bLoodLib = true; } else { return; } LoadSolutionLib(); var enData = FileAccessManager.LoadBytes(FileName); if (enData != null) { //var sw = new System.Diagnostics.Stopwatch(); //sw.Start(); var deData = DESCrypto.Decrypt(enData, Number); //sw.Stop(); deData = Utils.UnpackMemory(deData); //Debug.LogInfo("Decrypt time: " + sw.ElapsedMilliseconds); var ass = System.Reflection.Assembly.Load(deData); //动态库的名称 //gameObject.AddComponent(ass.GetType("TestUI")); if (ass.GetType("MogoInitialize") != null) { gameObject.AddComponent(ass.GetType("MogoInitialize")); } else { Debug.LogError("---------------Reflection MogoInitialize Failed------------------------"); } //gameObject.AddComponent(ass.GetType("TestUI")); if (Application.platform == RuntimePlatform.Android && SystemSwitch.UsePlatformSDK) { IsRunOnAndroid = true; if (ass.GetType("AndroidSdkManager") != null) { gameObject.AddComponent(ass.GetType("AndroidSdkManager")); } else { Debug.LogError("---------------Reflection AndroidSdkManager Failed------------------------"); } //IsRunOnAndroid = false; } else { gameObject.AddComponent(ass.GetType("PlatformSdkManager")); IsRunOnAndroid = false; } } else { Debug.LogError("Missing MogoLib."); } }
IEnumerator StartInit(Action onStart, Action <int> progress) { onStart(); StartCoroutine(NoticeManager.Instance.DownloadNotice()); progress(10); yield return(null); if (gameObject.GetComponent <LoadResources>() == null) { gameObject.AddComponent(SystemSwitch.ReleaseMode ? typeof(LoadAssetBundlesMainAsset) : typeof(LoadResources)); } if (SystemSwitch.ReleaseMode) { ResourceManager.LoadMetaOfMeta( () => { List <string> shaders = new List <string>(); if (Directory.Exists(Path.Combine(SystemConfig.ResourceFolder, "Resources/Shader"))) { shaders = FileAccessManager.GetFileNamesByDirectory("Resources/Shader"); shaders = (from s in shaders let r = System.IO.Path.GetFileName(s).ReplaceFirst(SystemConfig.ASSET_FILE_EXTENSION, String.Empty) where r.EndsWith(".shader", StringComparison.CurrentCultureIgnoreCase) select r).ToList(); } else { shaders = ResourceIndexInfo.Instance.GetFileNamesByDirectory("Resources/Shader"); shaders = (from s in shaders let r = Mogo.Util.Utils.GetStreamPath(s) where r.EndsWith(".shader", StringComparison.CurrentCultureIgnoreCase) select r).ToList(); } AssetCacheMgr.GetResources(shaders.ToArray(), null); StartCoroutine(AfterInit(progress)); }, (index, total) => { if (total == 0) { return; } var proc = ((40 - 10) * index / total) + 10; Driver.Invoke(() => { progress(proc); }); } ); } else { StartCoroutine(AfterInit(progress)); } }
void LoadSolutionLib() { var index = 0; var resName = FileName + index; while (FileAccessManager.IsFileExist(resName)) { Debug.Log("load: " + resName); var enData = FileAccessManager.LoadBytes(resName); if (enData != null) { var deData = DESCrypto.Decrypt(enData, Number); deData = Utils.UnpackMemory(deData); System.Reflection.Assembly.Load(deData); } index++; resName = FileName + index; } }
private void DownDownloadPackageList(Action <bool> fileDecompress, string packageUrl, List <KeyValuePair <String, String> > downloadList, Action <int, int, string> taskProgress, Action <int, long, long> progress, Action finished, Action <Exception> error) { var allTask = new List <DownloadTask>(); //收集downloadlist,生成所有下载任务 for (int i = 0; i < downloadList.Count; i++) { LoggerHelper.Debug("收集数据包,生成任务:" + i); KeyValuePair <String, String> kvp = downloadList[i]; LoggerHelper.Debug("下载文件名:" + kvp.Value); String localFile = String.Concat(SystemConfig.ResourceFolder, kvp.Value); Action OnDownloadFinished = () => { LoggerHelper.Debug("下载完成,进入完成回调"); LoggerHelper.Debug("本地文件:" + File.Exists(localFile)); if (File.Exists(localFile)) { FileAccessManager.DecompressFile(localFile); } LoggerHelper.Debug("解压完成,保存版本信息到version.xml"); if (File.Exists(localFile)) { File.Delete(localFile); } LocalVersion.ResouceVersionInfo = new VersionCodeInfo(kvp.Key); SaveVersion(LocalVersion); //if (taskProgress != null) // taskProgress(downloadList.Count, i + 1); }; String fileUrl = String.Concat(packageUrl, kvp.Value); var task = new DownloadTask { FileName = localFile, Url = fileUrl, Finished = OnDownloadFinished, Error = error, TotalProgress = progress }; //task.Error = erroract; string fileNoEXtension = kvp.Value;// task.FileName.LastIndexOf('/') != 0 ? task.FileName.Substring(task.FileName.LastIndexOf('/') + 1) : task.FileName; LoggerHelper.Debug(task.FileName + "::fileNoEXtension::" + fileNoEXtension); if (ServerVersion.PackageMD5Dic.ContainsKey(fileNoEXtension)) { task.MD5 = ServerVersion.PackageMD5Dic[fileNoEXtension]; allTask.Add(task); } else { error(new Exception("down pkg not exit :" + fileNoEXtension)); return; //LoggerHelper.Error("down pkg not exit :" + fileNoEXtension); } } //全部下载完成的回调 Action AllFinished = () => { LoggerHelper.Debug("更新包全部下载完成"); finished(); }; //添加taskProgress的回调 Action <int, int, string> TaskProgress = (total, current, filename) => { if (taskProgress != null) { taskProgress(total, current, filename); } }; //添加文件解压的回调函数 Action <bool> filedecompress = (decompress) => { if (fileDecompress != null) { fileDecompress(decompress); } }; //所有任务收集好了,开启下载 LoggerHelper.Debug("所有任务收集好了,开启下载"); DownloadMgr.Instance.tasks = allTask; DownloadMgr.Instance.AllDownloadFinished = AllFinished; DownloadMgr.Instance.TaskProgress = TaskProgress; DownloadMgr.Instance.FileDecompress = filedecompress; DownloadMgr.Instance.CheckDownLoadList(); }
// Use this for initialization void Start() { FileAccessManager.ZipFile(Application.dataPath + "/Plugin/network.dll", Application.dataPath + "/Plugin/"); }
private void DownDownloadPackageList(Action <bool> fileDecompress, string packageUrl, List <KeyValuePair <string, string> > downloadList, Action <int, int, string> taskProgress, Action <int, long, long> progress, Action finished, Action <Exception> error) { List <DownloadTask> list = new List <DownloadTask>(); for (int i = 0; i < downloadList.Count; i++) { LoggerHelper.Debug("收集数据包,生成任务:" + i, true, 0); KeyValuePair <string, string> kvp = downloadList[i]; LoggerHelper.Debug("下载文件名:" + kvp.Value, true, 0); string localFile = SystemConfig.ResourceFolder + kvp.Value; Action action = delegate { LoggerHelper.Debug("下载完成,进入完成回调", true, 0); LoggerHelper.Debug("本地文件:" + File.Exists(localFile), true, 0); if (File.Exists(localFile)) { FileAccessManager.DecompressFile(localFile); } LoggerHelper.Debug("解压完成,保存版本信息到version.xml", true, 0); if (File.Exists(localFile)) { File.Delete(localFile); } this.LocalVersion.ResouceVersionInfo = new VersionCodeInfo(kvp.Key); this.SaveVersion(this.LocalVersion); }; string str = packageUrl + kvp.Value; DownloadTask item = new DownloadTask { FileName = localFile, Url = str, Finished = action, Error = error, TotalProgress = progress }; string key = kvp.Value; LoggerHelper.Debug(item.FileName + "::fileNoEXtension::" + key, true, 0); if (this.ServerVersion.PackageMD5Dic.ContainsKey(key)) { item.MD5 = this.ServerVersion.PackageMD5Dic[key]; list.Add(item); } else { error(new Exception("down pkg not exit :" + key)); return; } } Action action2 = delegate { LoggerHelper.Debug("更新包全部下载完成", true, 0); finished(); }; Action <int, int, string> action3 = delegate(int total, int current, string filename) { if (taskProgress != null) { taskProgress(total, current, filename); } }; Action <bool> action4 = delegate(bool decompress) { if (fileDecompress != null) { fileDecompress(decompress); } }; LoggerHelper.Debug("所有任务收集好了,开启下载", true, 0); DownloadMgr.Instance.tasks = list; DownloadMgr.Instance.AllDownloadFinished = action2; DownloadMgr.Instance.TaskProgress = action3; DownloadMgr.Instance.FileDecompress = action4; DownloadMgr.Instance.CheckDownLoadList(); }
private void DownloadPackageList(Action <bool> fileDecompress, string packageUrl, List <KeyValuePair <String, String> > downloadList, Action <int, int, string> taskProgress, Action <int, long, long> progress, Action finished, Action <Exception> error) { //下载列表 List <DownloadTask> allTasks = new List <DownloadTask>(); for (int i = 0; i < downloadList.Count; i++) { KeyValuePair <string, string> kvp = downloadList[i]; string localFile = string.Concat(SystemConfig.ResourceFolder, kvp.Value);//dataPath+"/Resources/"+文件名 //下载完成之后回调委托 Action OnDownloadFinished = () => { //进行解压,以后再来 if (File.Exists(localFile)) { //开始解压文件 FileAccessManager.DecompressFile(localFile); } if (File.Exists(localFile)) { File.Delete(localFile); } //更新本地版本信息 LocalVersion.ResourceVersionCodeInfo = new VersionCodeInfo(kvp.Key); //保存版本信息 SaveVersion(LocalVersion); }; string fileUrl = string.Concat(packageUrl, kvp.Value);//"http://127.0.0.1/LOLGameDemo/LOLPackage/"+文件名 //初始化任务 var task = new DownloadTask { FileName = localFile, //dataPath+"/Resources/"+文件名 Url = fileUrl, //下载url Finished = OnDownloadFinished, //解压更新版本信息 Error = error, TotalProgress = progress }; string fileNameNoExtension = kvp.Value; if (ServerVersion.PackageMd5Dic.ContainsKey(fileNameNoExtension)) { task.MD5 = ServerVersion.PackageMd5Dic[fileNameNoExtension]; allTasks.Add(task); } else { error(new Exception("下载包不存在:" + fileNameNoExtension)); return; } } //全部任务下载完成回调 Action AllFinished = () => { Debug.Log("全部下载完成"); finished(); }; //添加taskProgress的回调 Action <int, int, string> TaskProgress = (total, current, filename) => { if (taskProgress != null) { taskProgress(total, current, filename); } }; //添加文件解压的回调函数 Action <bool> filedecompress = (decompress) => { if (fileDecompress != null) { fileDecompress(decompress); } }; DownloadMgr.Instance.Tasks = allTasks; DownloadMgr.Instance.AllDownloadFinished = AllFinished; DownloadMgr.Instance.TaskProgress = TaskProgress; DownloadMgr.Instance.FileDecompress = filedecompress; DownloadMgr.Instance.CheckDownloadList(); }