private void UnZipFile() { string fileName = CurDownLoadFileInfo.fileName; if (fileName.EndsWith(".zip")) { string fullPath = URLFactory.GetLocalGameResSavePath(CurDownLoadFileInfo); string unZipToDirectoryPath = URLFactory.GetLocalGameResSaveFolder(CurDownLoadFileInfo.GameName); if (!Directory.Exists(unZipToDirectoryPath)) { Directory.CreateDirectory(unZipToDirectoryPath); } UtilsZipHelper.UnZipFile(fullPath, unZipToDirectoryPath); File.Delete(fullPath); } }
private IEnumerator LoadAssetFromStream() { string checkTagPath = Application.persistentDataPath + "/checkHold.txt"; if (File.Exists(checkTagPath)) { StreamReader tagReader = new StreamReader(checkTagPath); string str = tagReader.ReadLine(); tagReader.Dispose(); bool isNewVersion = AppVersionCompare(Utils.AppVersion(), str); if (isNewVersion) { File.Delete(checkTagPath); string msg = "游戏版本过低,请下载最新安装包进行游戏"; Utils.MessagePopup(msg, UpdateIphonePackage, 1, true, "前往"); } else { CreatTag(); GetAssetServerUrlFromWeb(); } yield break; } yield return(null); _msgText.text = "准备资源文件.."; Utils.Log("准备资源文件.."); string assetname = "/jzsh"; string path = Application.streamingAssetsPath + assetname; #if UNITY_EDITOR path = Application.streamingAssetsPath + assetname; #elif UNITY_ANDROID path = "jar:file://" + Application.dataPath + "!/assets/AssetsList.txt"; #elif UNITY_IPHONE path = Application.streamingAssetsPath + assetname; #endif unZipOk = false; string fullPath = Application.persistentDataPath; string unZipToDirectoryPath = Application.persistentDataPath; if (File.Exists(fullPath)) { File.Delete(fullPath); } #if UNITY_IPHONE || UNITY_EDITOR if (!Directory.Exists(path)) { CreatTag(); GetAssetServerUrlFromWeb(); yield break; } UtilsZipHelper.CopyFileMultiSync(path, fullPath, OnUnZipFileResult); #elif UNITY_ANDROID UnityWebRequest uwr = UnityWebRequest.Get(path); yield return(uwr.SendWebRequest());//读取数据 List <string> assetsList = new List <string>(); if (string.IsNullOrEmpty(uwr.error)) { string data = uwr.downloadHandler.text; uwr.Abort(); int index = -1; while ((index = data.LastIndexOf("jzsh")) != -1) { assetsList.Add(data.Substring(index)); //Utils.Log(assetsList[assetsList.Count - 1]); data = data.Substring(0, index); } path = "jar:file://" + Application.dataPath + "!/assets"; UtilsZipHelper.CopyFileByWebRequest(assetsList, path, fullPath, OnUnZipFileResult); } else { Utils.Log("获取初始包资源列表文件失败:" + uwr.error); uwr.Abort(); CreatTag(); GetAssetServerUrlFromWeb(); } #endif yield return(null); _msgText.text = "开始加载初始化资源..不消耗流量"; Utils.Log(_msgText.text); yield return(null); while (!unZipOk) { _msgText.text = string.Format("已初始化资源...{0}/{1}", UtilsZipHelper.TestCurrentFileNumber, UtilsZipHelper.TestCurrentFileNumberTotal); Utils.Log(_msgText.text); yield return(new WaitForSeconds(0.1f)); } }