public static void Patch(string platform) { var p = Application.dataPath + DevCacheDirectory + platform + AssetBundlePath.kSlash + AssetBundlePath.kPackCfg; var jsonData = File.ReadAllText(p); var cfg = new PackageCfg(); EditorJsonUtility.FromJsonOverwrite(jsonData, cfg); var tmpDir = Application.dataPath + "/tempDir"; if (Directory.Exists(tmpDir)) { Directory.Delete(tmpDir, true); } var patchCfg = new PackageCfg(); patchCfg.PatchVersion = PackEditorWin.GetCfg().PatchVersion; var parentPath = Application.dataPath + DevCacheDirectory + platform; var codePatchFile = parentPath + AssetBundlePath.kSlash + AssetBundlePath.kCodePatchFile; if (File.Exists(codePatchFile)) { cfg.Files.Add(new FileCfg(CommonTool.CalFileMD5(codePatchFile), AssetBundlePath.kCodePatchFile)); } for (int i = 0; i < cfg.Files.Count; ++i) { var f = cfg.Files[i]; var md5 = CommonTool.CalFileMD5(parentPath + AssetBundlePath.kSlash + f.Path); if (Path.GetExtension(f.Path) == AssetBundleMgr.instance.kPatchFileExt || md5 != f.MD5 && Path.GetExtension(f.Path) != AssetBundlePath.kPackCfgSuffix) { patchCfg.Files.Add(new FileCfg(md5, f.Path)); var t = tmpDir + AssetBundlePath.kSlash + f.Path; if (!Directory.Exists(Path.GetDirectoryName(t))) { Directory.CreateDirectory(Path.GetDirectoryName(t)); } File.Copy(parentPath + AssetBundlePath.kSlash + f.Path, t); } } if (patchCfg.Files.Count != 0) { using (var sw = File.CreateText(tmpDir + AssetBundlePath.kSlash + AssetBundlePath.kPatchCfg)) { sw.Write(EditorJsonUtility.ToJson(patchCfg)); } ZipHelper.ZipDirectoryDirect(tmpDir, Application.dataPath + DiffPatchDirectory + platform + AssetBundlePath.kPatchZipRes); TimeLogger.LogYellow(platform + "差异包生成成功"); if (Directory.Exists(tmpDir)) { Directory.Delete(tmpDir, true); } } else { Debug.LogError("no different patch"); } }
public static void GeneratePackageCfg(string directoryPath) { var root = Path.GetFileNameWithoutExtension(directoryPath).ToLower(); var packEditorCfg = PackEditorWin.GetCfg(); var packCfg = new PackageCfg(); packCfg.CurVersion = packEditorCfg.CurVersion; packCfg.PatchVersion = packEditorCfg.PatchVersion; packCfg.ForceUpdateVersion = packEditorCfg.ForceUpdateVersion; TraverseDirectory(directoryPath, packCfg, root); var filePath = directoryPath + AssetBundlePath.kSlash + AssetBundlePath.kPackCfg; if (File.Exists(filePath)) { File.Delete(filePath); } using (var sw = File.CreateText(filePath)) { sw.Write(EditorJsonUtility.ToJson(packCfg)); } }
public static void PackUncompressAndroidAB() { EditorUtility.DisplayProgressBar("", "", 0); DeleteDirectoryChild(Application.streamingAssetsPath); //Resources本地文件 var p = "Assets/Resources/" + AssetBundlePath.kVersionCfg; if (File.Exists(p)) { File.Delete(p); } var d = ScriptableObject.CreateInstance <VersionCfg>(); var editorCfg = PackEditorWin.GetCfg(); d.CurVersion = editorCfg.CurVersion; AssetDatabase.CreateAsset(d, p); AssetDatabase.SaveAssets(); //android var path = Application.dataPath + DevCacheDirectory + AssetBundlePath.kAndroid; var codeFilePath = path + AssetBundlePath.kSlash + AssetBundlePath.kCodePatchFile; if (File.Exists(codeFilePath)) { File.Delete(codeFilePath); } GeneratePackageCfg(path); ZipHelper.ZipDirectoryDirect(path, Application.streamingAssetsPath + AssetBundlePath.kSlash + AssetBundlePath.kAndroidZipRes); //windows path = Application.dataPath + DevCacheDirectory + AssetBundlePath.kWindows; codeFilePath = path + AssetBundlePath.kSlash + AssetBundlePath.kCodePatchFile; if (File.Exists(codeFilePath)) { File.Delete(codeFilePath); } GeneratePackageCfg(path); ZipHelper.ZipDirectoryDirect(path, Application.streamingAssetsPath + AssetBundlePath.kSlash + AssetBundlePath.kWindowsZipRes); EditorUtility.ClearProgressBar(); TimeLogger.LogYellow("压缩完成"); AssetDatabase.Refresh(); }