static void CreateZip() { UnityEngine.Object obj = Selection.activeObject; string setImgPath = AssetDatabase.GetAssetPath(obj); string filepath = Application.dataPath + "/" + setImgPath.Replace("Assets/", ""); var files = FZipTool.ZipDirectory(filepath, FEPath.GetDirectoryName(filepath) + "/", ".meta"); var t = FSaveHandle.Create(FEPath.GetDirectoryName(filepath) + "/version", FFilePath.FP_Abs, FOpenType.OT_Write | FOpenType.OT_Txt); string md5 = FCommonFunction.GetMD5HashFromFile(files); int type = EditorUserBuildSettings.activeBuildTarget != BuildTarget.iOS ? 0 : 1; t.SetContext("{\"version\":" + MyEdior.GetTimeVersion().ToString() + ",\"md5\":\"" + md5 + ",\"type\":\"" + type.ToString() + "\"}"); t.Save(); }
public static void CretatePartPack(bool isMain) { string copyPath = FEPath.GetDirectoryName(SceneManager.STREAMINGPATH.Replace("file://", "")); string newPath = copyPath.Replace("StreamingAssets", "_TempStreamingAssets"); FSaveHandle firstData = FSaveHandle.Create(copyPath + "/" + ResConfig.STREAMINGASSETSCONFIG, FFilePath.FP_Abs); if (!firstData.IsLoad) { Debug.LogError("没找到新配置文件:" + copyPath + "/" + ResConfig.STREAMINGASSETSCONFIG + "操作失败"); return; } BundleManager.StreamConfig firstStreamConfi = new BundleManager.StreamConfig(); firstData.FromObject(firstStreamConfi); MyEdior.DeletFile(newPath); MyEdior.CopyDirectory(copyPath, newPath); AssetDatabase.Refresh(); CreateConfig(newPath, firstStreamConfi, 0); string playFile = ""; string mainPack = copyPath.Replace("Assets/StreamingAssets", "FPartPack/MainPack"); if (isMain) { string copyPack = copyPath.Replace("Assets/StreamingAssets", "FTempCopyPack/Pack_" + DateTime.Now.ToString("MM_dd--HH_mm")); MyEdior.DeletFile(mainPack); FEPath.CreateDirectory(mainPack); EditorUtility.DisplayCancelableProgressBar("备份资源", "正在处理 ", 0.5f); File.Copy(newPath + "/" + ResConfig.STREAMINGASSETSCONFIG, mainPack + "/" + ResConfig.STREAMINGASSETSCONFIG, true); MyEdior.CopyDirectory(copyPath, copyPack + "/StreamingAssets"); File.Copy(newPath + "/" + ResConfig.STREAMINGASSETSCONFIG, copyPack + "/" + ResConfig.STREAMINGASSETSCONFIG, true); FZipTool.ZipDirectory(copyPack, FEPath.GetDirectoryName(copyPack) + "/"); MyEdior.DeletFile(copyPack); EditorUtility.ClearProgressBar(); playFile = mainPack; } else { //加载新配置 string newstreamingPath = newPath + "/" + ResConfig.STREAMINGASSETSCONFIG; FSaveHandle sd = FSaveHandle.Create(newstreamingPath, FFilePath.FP_Abs); if (sd == null) { Debug.LogError("没找到新配置文件:" + ResConfig.STREAMINGASSETSCONFIG + "对比文件失败"); } else { BundleManager.StreamConfig NewStreamConif = new BundleManager.StreamConfig(); sd.FromObject(NewStreamConif); //加载旧配置 string lastStremingPath = copyPath.Replace("Assets/StreamingAssets", "FPartPack/MainPack") + "/" + ResConfig.STREAMINGASSETSCONFIG; sd = FSaveHandle.Create(lastStremingPath, FFilePath.FP_Abs); if (sd == null) { Debug.LogError(lastStremingPath + "文件夹下,没有找到旧的配置文件" + ResConfig.STREAMINGASSETSCONFIG + "对比文件失败"); } else { //曾经变化文件 string changeFile = mainPack + "/" + ResConfig.FCACHEFILE; BundleManager.LegacyPackFile cfiles = new BundleManager.LegacyPackFile(); FSaveHandle cSave = FSaveHandle.Create(changeFile, FFilePath.FP_Abs); if (cSave != null) { cSave.FromObject(cfiles); } BundleManager.StreamConfig LastStreamConif = new BundleManager.StreamConfig(); sd.FromObject(LastStreamConif); if (NewStreamConif.versionId <= LastStreamConif.versionId) { Debug.LogError(ResConfig.STREAMINGASSETSCONFIG + ":新的配置文件versionId比旧配置文件要低,对比文件失败"); } else { //精简文件 for (int i = 0; i < NewStreamConif.fileDatas.Count; i++) { var newData = NewStreamConif.fileDatas[i]; string tempBundleName = newData.fileName; string newMd5 = NewStreamConif.GetMd5(tempBundleName); string lastMd5 = LastStreamConif.GetMd5(tempBundleName); if (cfiles.Files.ContainsKey(newData.fileName))//&& newData.path.Contains("fxlua")) { ScriptsTime.Debug("以前版本有变动的文件:" + newData.path + "==" + tempBundleName); } else if ((newMd5 != lastMd5 || lastMd5 == "")) //&& newData.path.Contains("fxlua")) { //文件有更新 ScriptsTime.Debug("产生新的文件:" + newData.path + "==" + tempBundleName); cfiles.Files[newData.fileName] = 0; string exten = FEPath.GetExtension(newData.fileName); if (exten == ResConfig.ASSETBUNDLESUFFIXES) { cfiles.Bundles[newData.fileName.Replace(ResConfig.FDESASSETBUNDLE + "/", "")] = 1; } } else { string spePath = newPath + "/" + newData.fileName; File.Delete(spePath); } } string cachefile = newPath + "/" + ResConfig.FDESASSETBUNDLE + "/" + ResConfig.FCACHEFILE; cSave = FSaveHandle.Create(cachefile, FFilePath.FP_Abs, FOpenType.OT_Write); cSave.PushObject(cfiles); cSave.Save(); File.Copy(cachefile, changeFile, true); //重新生成压缩文件 int versioin = firstStreamConfi.versionId; CreateConfig(newPath, firstStreamConfi, 1); string partversionFile = ""; if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.iOS) { partversionFile = copyPath.Replace("Assets/StreamingAssets", "FPartPack/" + versioin + "/ios1"); } else { partversionFile = copyPath.Replace("Assets/StreamingAssets", "FPartPack/" + versioin + "/az1"); } MyEdior.DeletFile(partversionFile); MyEdior.CopyDirectory(newPath, partversionFile); var t = FSaveHandle.Create(partversionFile + "/version", FFilePath.FP_Abs, FOpenType.OT_Write | FOpenType.OT_Txt); string md5 = FCommonFunction.GetMD5HashFromFile(partversionFile + "/FAssetbundle.zip"); int type = EditorUserBuildSettings.activeBuildTarget != BuildTarget.iOS ? 0:1; t.SetContext("{\"version\":" + versioin.ToString() + ",\"md5\":\"" + md5 + ",\"type\":\"" + type.ToString() + "\"}"); t.Save(); File.Delete(partversionFile + "/FAssetbundle.zip.meta"); File.Delete(partversionFile + "/FStreamingAssets"); File.Delete(partversionFile + "/FStreamingAssets.meta"); playFile = partversionFile; } } } } MyEdior.DeletFile(newPath); AssetDatabase.Refresh(); if (playFile != "") { System.Diagnostics.Process.Start(playFile); Debug.Log(isMain ? "主包生成完成" : "分包生成完成"); } }
//OperationType 0 解压,1压缩,2不处理 public static void CreateConfig(string stream, BundleManager.StreamConfig copyStream, int OperationType) { long fileSize = 0; string streamTempPath = stream + "/"; string streamingPath = streamTempPath + ResConfig.STREAMINGASSETSCONFIG; EditorUtility.DisplayCancelableProgressBar("打包资源", "正在处理 " + stream, 0.3f); string unKey = ".meta"; if (OperationType == 2) { if (EditorUserBuildSettings.activeBuildTarget != BuildTarget.iOS) { OperationType = 1; unKey = ".meta.delete.unity3d.manifest"; } } if (OperationType != 2) { //插入压缩,解压流程 for (int i = 0; i < mZipFilesName.Count; i++) { string pathFile = streamTempPath + mZipFilesName[i]; string zipDir = FEPath.GetDirectoryName(pathFile) + "/"; if (OperationType == 1) { if (FEPath.Exists(pathFile)) { //string unKey = ".meta";//: ".meta.delete.unity3d.manifest"; string outPath = FZipTool.ZipDirectory(pathFile, zipDir, unKey); //删除压缩前的文件夹 if (unKey == ".meta") { MyEdior.DeletFile(pathFile); } fileSize += new System.IO.FileInfo(outPath).Length / 1024; } } else { pathFile += ResConfig.FZIPNAMEEX; if (File.Exists(pathFile)) { FZipTool.UnZip(pathFile, zipDir, ResConfig.FZIPPASS); //删除解压前的文件夹 File.Delete(pathFile); } } } } AssetDatabase.Refresh(); BundleManager.StreamConfig streamConfig = new BundleManager.StreamConfig(); List <string> fileList = new List <string>(); string keyStream = "/" + FEPath.GetFileNameWithoutExtension(FEPath.GetDirectoryName(streamTempPath)) + "/"; SelectPrefabEditor spe = new SelectPrefabEditor("", keyStream, "", true); for (int i = 0; i < spe.tempAllStrs.Length; i++) { string path = spe.tempAllStrs[i]; if (File.Exists(path) && path.IndexOf(F_NOCOPYSTREAM) == -1 && (path.IndexOf("Assembly-CSharp") == -1)) { int pos = path.IndexOf(keyStream); fileList.Add(path.Substring(pos + keyStream.Length)); } } if (fileList.Count != 0) { for (int index = 0; index < fileList.Count; index++) { string fileName = fileList[index]; var normaFile = new BundleManager.StreamConfig.NormalFile(); int pathPos = fileName.LastIndexOf("/"); string pathFile = ""; if (pathPos != -1) { pathFile = fileName.Substring(0, pathPos); } normaFile.path = pathFile; normaFile.fileName = fileName; normaFile.md5 = FEngineManager.GetMD5HashFromFile(streamTempPath + fileName); normaFile.resType = FEPath.GetExtension(fileName); normaFile.FileType = GetResType(normaFile);// (normaFile.resType == ResConfig.FZIPNAMEEX); streamConfig.fileDatas.Add(normaFile); } } ScriptsTime.Debug("创建StreamingConfig完成"); streamConfig.IsBackDownMicro = copyStream.IsBackDownMicro; streamConfig.versionId = copyStream.versionId; streamConfig.CustomConfig = copyStream.CustomConfig; streamConfig.zipSize = fileSize; FSaveHandle sd = FSaveHandle.Create(streamingPath, FFilePath.FP_Abs, FOpenType.OT_Write); sd.PushObject(streamConfig); sd.Save(); EditorUtility.ClearProgressBar(); }
public static void ApplyMicroPart(bool isMain) { string tempPath = FEPath.GetDirectoryName(SceneManager.STREAMINGPATH.Replace("file://", "")) + "/" + ResConfig.FDESASSETBUNDLE;//打包缓存路径 string microTempPath = FEPath.GetDirectoryName(SceneManager.STREAMINGPATH.Replace("file://", "")).Replace("Assets/StreamingAssets", "FPartPack/Micro/") + ResConfig.FDESASSETBUNDLE; string microPath = FEPath.GetDirectoryName(SceneManager.STREAMINGPATH.Replace("file://", "")).Replace("Assets/StreamingAssets", "FPartPack/Micro/"); MicroFile micros = new MicroFile(); if (isMain) { string zip = microPath + ResConfig.MicroBundleName + ".zip"; if (File.Exists(zip)) { string streamConfig = FEPath.GetDirectoryName(SceneManager.STREAMINGPATH.Replace("file://", "")); FSaveHandle firstData = FSaveHandle.Create(streamConfig + "/" + ResConfig.STREAMINGASSETSCONFIG, FFilePath.FP_Abs); if (!firstData.IsLoad) { Debug.LogError("没找到新配置文件:" + streamConfig + "/" + ResConfig.STREAMINGASSETSCONFIG + "操作失败"); return; } BundleManager.StreamConfig firstStreamConfi = new BundleManager.StreamConfig(); firstData.FromObject(firstStreamConfi); if (!string.IsNullOrEmpty(firstStreamConfi.microMD5)) { Debug.LogError("已经是微端包,无需重复生成"); return; } EditorUtility.DisplayCancelableProgressBar("微端生成中", "正在处理... ", 0); List <string> changeFiles = new List <string>(); FZipTool.UnZip(zip, FEPath.GetDirectoryName(zip), ResConfig.FZIPPASS); AssetDatabase.Refresh(); FSaveHandle msave = FSaveHandle.Create(microTempPath + "/" + ResConfig.MicroBundleName, FFilePath.FP_Abs, FOpenType.OT_Txt); if (msave.IsLoad) { msave.FromObject(micros); for (int i = 0; i < micros.datas.Count; i++) { var data = micros.datas[i]; EditorUtility.DisplayCancelableProgressBar("微端生成中", "正在处理:" + data.bundleName, i / (float)micros.datas.Count); var realyPath = tempPath + "/" + data.bundleName; if (File.Exists(realyPath)) { var md5 = FEngineManager.GetMD5HashFromFile(realyPath); if (data.md5 == md5) { File.Delete(realyPath); changeFiles.Add(data.bundleName); } } else { Debug.LogError("文件拷贝失败:" + realyPath); } } //更改配置文件 firstStreamConfi.microMD5 = FEngineManager.GetMD5HashFromFile(zip); firstStreamConfi.microsFiles = changeFiles; firstStreamConfi.zipSize = new System.IO.FileInfo(zip).Length / 1024; firstData.PushObject(firstStreamConfi); firstData.Save(); Debug.Log("微端生成成功"); EditorUtility.ClearProgressBar(); } else { Debug.LogError(ResConfig.MicroBundleName + "微端资源列表没有找到"); } } else { Debug.LogError("微端资源文件没有找到"); } } else { //读取配置文件 FSaveHandle sd = FSaveHandle.Create(Application.dataPath + "/" + ResConfig.NOPACKPATH, FFilePath.FP_Abs, FOpenType.OT_Binary); if (sd.IsLoad) { List <string> haveMicros = new List <string>(); EditorScripts.NoPackAsset nopack = new EditorScripts.NoPackAsset(); sd.FromObject(nopack); EditorUtility.DisplayCancelableProgressBar("微端资源处理", "正在处理... ", 0); for (int i = 0; i < nopack.mlist.Length; i++) { var data = nopack.mlist[i]; if (PackFileEditor.IsHaveSameWinType(data.type, (int)PackType.micro)) { EditorUtility.DisplayCancelableProgressBar("微端资源处理", "正在处理:" + data.bunldName, i / (float)nopack.mlist.Length); //拷贝文件到微端 var realyPath = tempPath + "/" + data.bunldName; if (File.Exists(realyPath)) { if (!haveMicros.Contains(data.bunldName)) { haveMicros.Add(data.bunldName); MicroFile.Data md = new MicroFile.Data(); md.bundleName = data.bunldName; md.md5 = FEngineManager.GetMD5HashFromFile(realyPath); micros.datas.Add(md); var copyPath = microTempPath + "/" + data.bunldName; string dir = FEPath.GetDirectoryName(copyPath); if (!FEPath.Exists(dir)) { FEPath.CreateDirectory(dir); } if (File.Exists(copyPath)) { File.Copy(realyPath, copyPath, true); } else { File.Copy(realyPath, copyPath); } } } else { Debug.LogError("文件拷贝失败:" + realyPath); } } } FSaveHandle msave = FSaveHandle.Create(microTempPath + "/" + ResConfig.MicroBundleName, FFilePath.FP_Abs, FOpenType.OT_Txt | FOpenType.OT_Write); msave.PushObject(micros); msave.Save(); EditorUtility.DisplayCancelableProgressBar("微端资源处理", "压缩文件中", 0.3f); //打成微包 FZipTool.ZipDirectory(microTempPath, microPath, ".meta.delete", ResConfig.MicroBundleName); //删除压缩前的文件夹 EditorUtility.ClearProgressBar(); string beiFen = FEPath.GetDirectoryName(SceneManager.STREAMINGPATH.Replace("file://", "")); string copyPack = beiFen.Replace("Assets/StreamingAssets", "FTempCopyPack/Micro_" + DateTime.Now.ToString("MM_dd--HH_mm") + ".zip"); FEPath.CreateDirectory(FEPath.GetDirectoryName(copyPack)); File.Copy(microPath + "/" + ResConfig.MicroBundleName + ".zip", copyPack); Debug.Log("微端文件生成成功"); AssetDatabase.Refresh(); System.Diagnostics.Process.Start(microPath + "/"); } else { Debug.LogError(Application.dataPath + "/" + ResConfig.NOPACKPATH + "没有找到配置文件"); } } MyEdior.DeletFile(microTempPath); }