public static void BuildFirstUPK() { // 版本路径 string versionPath = GetVersionBundlePath(); // 资源路径 string assetPath = Replace(string.Format("{0}{1}{2}", versionPath, Path.DirectorySeparatorChar, "first")); // 资源路径 string firstUpkPath = Replace(string.Format("{0}{1}{2}", versionPath, Path.DirectorySeparatorChar, "first_upk")); // upk 资源路径 string UPKPath = Replace(string.Format("{0}{1}{2}", assetPath, Path.DirectorySeparatorChar, "files.upk")); // UPK Info 资源路径 string streamingAssetPath = Replace(string.Format("{0}{1}{2}", Application.dataPath, Path.DirectorySeparatorChar, "StreamingAssets")); string InfoPath = Replace(string.Format("{0}{1}{2}", streamingAssetPath, Path.DirectorySeparatorChar, "first.txt")); // fristFile.txt 路径 string firstFilePath = Replace(string.Format("{0}{1}{2}", assetPath, Path.DirectorySeparatorChar, "first_files.txt")); // file.txt 路径 string filePath = Replace(string.Format("{0}{1}{2}", assetPath, Path.DirectorySeparatorChar, "files.txt")); // first upk dir if (Directory.Exists(firstUpkPath)) { Directory.Delete(firstUpkPath, true); } Directory.CreateDirectory(firstUpkPath); // 开始打包 List <UPKInfo> infoList = new List <UPKInfo>(); var fileData = File.ReadAllText(firstFilePath); var files = ReadFileInfo(fileData); for (int i = 0; i < files.Length; i++) { var file = files[i]; var fs = Replace(Path.Combine(assetPath, file.Path)); FileInfo filesInfo = new FileInfo(fs); UPKInfo filesuinfo = new UPKInfo(); filesuinfo.relativePath = "files.txt"; filesuinfo.absolutePath = filePath; filesuinfo.length = filesInfo.Length; infoList.Add(filesuinfo); } // 打包 UPKEngine.Pack(infoList, UPKPath, InfoPath); RGLog.Debug(" 生成 first upk 包"); }
public static UPKInfo[] Read(string data) { var list = new List <UPKInfo>(); using (var reader = new StringReader(data)) { while (reader.Peek() != -1) { var msg = reader.ReadLine(); if (!string.IsNullOrEmpty(msg)) { var info = new UPKInfo(); info.ParesLine(msg); list.Add(info); } } } return(list.ToArray()); }
/// <summary> /// 生成 streaming upk包 /// </summary> public static void BuildStreamingUPK() { //资源路径 string assetPath = Replace(string.Format("{0}{1}{2}", Application.dataPath, Path.DirectorySeparatorChar, "StreamingAssets")); // UPK 资源路径 string UPKPath = Replace(string.Format("{0}{1}{2}", assetPath, Path.DirectorySeparatorChar, "streaming.upk")); // UPK INFO 资源路径 string InfoPath = Replace(string.Format("{0}{1}{2}", assetPath, Path.DirectorySeparatorChar, "streaming.txt")); // files.txt 路径 string filePath = Replace(string.Format("{0}{1}{2}", assetPath, Path.DirectorySeparatorChar, "files.txt")); //开始打包 List <UPKInfo> infoList = new List <UPKInfo>(); var fileData = File.ReadAllBytes(filePath); var files = ReadFileInfo(filePath); for (int i = 0; i < files.Length; i++) { var file = files[i]; var fs = Replace(Path.Combine(assetPath, file.Path)); FileInfo fileInfo = new FileInfo(fs); UPKInfo uinfo = new UPKInfo(); uinfo.relativePath = file.Path; uinfo.absolutePath = fs; uinfo.length = fileInfo.Length; infoList.Add(uinfo); } // 把files文件也加入 FileInfo filesInfo = new FileInfo(filePath); UPKInfo filesuinfo = new UPKInfo(); filesuinfo.relativePath = "files.txt"; filesuinfo.absolutePath = filePath; filesuinfo.length = filesInfo.Length; infoList.Add(filesuinfo); // 打包 UPKEngine.Pack(infoList, UPKPath, InfoPath); // 删除 streamingAssets 内的其他资源 // 删除文件 string[] streamingFiles = Directory.GetFiles(assetPath); for (int i = 0; i < streamingFiles.Length; i++) { if (!streamingFiles[i].Equals(UPKPath) && !streamingFiles[i].Equals(InfoPath)) { File.Delete(streamingFiles[i]); } } // 删除文件夹 string[] streamingDirs = Directory.GetDirectories(assetPath); for (int i = 0; i < streamingDirs.Length; i++) { Directory.Delete(streamingDirs[i], true); } RGLog.Debug(" 生成 streaming upk 包完成"); }
private IEnumerator UnpackStreamingAsync() { // 包信息 if (Application.platform == RuntimePlatform.Android) { WWW www = new WWW(infoFilePath); yield return(www); if (!string.IsNullOrEmpty(www.error)) { if (i_unpack != null) { i_unpack.OnStreamingError("read streaming upk info www.error = " + www.error); } yield break; } else { infos = UPKInfo.Read(www.text); } } // UPK 文件读取 if (Application.platform == RuntimePlatform.Android) { WWW www = new WWW(upkFilePath); yield return(www); if (!string.IsNullOrEmpty(www.error)) { if (i_unpack != null) { i_unpack.OnStreamingError("read streaming upk www.error = " + www.error); } yield break; } else { File.WriteAllBytes(tempUpkPath, www.bytes); } } else { File.Copy(upkFilePath, tempUpkPath); } yield return(0); // 解压 if (i_unpack != null) { i_unpack.OnStreamingDecompression(); } if (VersionInfo.IsCompression) { bool result = false; Timers.inst.StartCoroutine(WaitThreadRun(() => { RCompress.DecompressFileLZMA(tempUpkPath, tempOutUpkPath); result = true; })); while (!result) { yield return(new WaitForSeconds(0.1f)); } } else { tempOutUpkPath = upkFilePath; } FileStream upkOutStream = new FileStream(tempOutUpkPath, FileMode.Open); if (upkOutStream != null) { // 解包文件 long offset = 0; for (int i = 0; i < infos.Length; i++) { var resPath = Path.Combine(outPath, infos[i].relativePath); var resLen = infos[i].length; var resDir = Path.GetDirectoryName(resPath); if (!Directory.Exists(resDir)) { Directory.CreateDirectory(resDir); } if (File.Exists(resPath)) { File.Delete(resPath); } FileStream outStream = new FileStream(resPath, FileMode.Create); var outData = new byte[resLen]; upkOutStream.Seek(offset, SeekOrigin.Begin); upkOutStream.Read(outData, 0, (int)resLen); outStream.Write(outData, 0, (int)resLen); outStream.Flush(); outStream.Close(); offset += resLen; if (i_unpack != null) { i_unpack.OnStreamingProgress(upkOutStream.Length, offset); } yield return(0); } upkOutStream.Close(); } else { if (i_unpack != null) { i_unpack.OnStreamingError("read streaming upk stream == null"); } } if (i_unpack != null) { i_unpack.OnStreamingFinished(); } // 删除临时文件 if (File.Exists(tempUpkPath)) { File.Delete(tempUpkPath); } if (File.Exists(tempOutUpkPath)) { File.Delete(tempOutUpkPath); } yield break; }