static void UpkPackGeneral(BuildTarget target) { if (!ConfigurationController.Instance.BuildAssetBundle && !ConfigurationController.Instance.BuildSceneAsBundle) { return; } var folderPath = GetTargetPath(target); if (Directory.Exists(folderPath)) { UpkPack.PackFolder(folderPath, folderPath + "../" + target.ToString() + ".upk", true); string tmpFile = ExecutePrepareEarlyBundlePath(target); var paths = File.ReadAllLines(tmpFile); if (paths != null && paths.Length > 0) { foreach (var path in paths) { var oldFolderName = Path.GetFileName(path); var oldVersion = oldFolderName.Substring(oldFolderName.LastIndexOf("_") + 1); var comparePath = Path.Combine(path, target.ToString()); bool hasComparePath = false; if (!string.IsNullOrEmpty(comparePath) && Directory.Exists(comparePath)) { if (!comparePath.EndsWith("/")) { comparePath += "/"; } hasComparePath = true; } UpkPack.PackFolder(folderPath, folderPath + "../" + target.ToString() + "_" + oldVersion + ".upk", true, delegate(FileInfo fileInfo) { if (hasComparePath) { var compareFile = fileInfo.FullName.Replace(folderPath, comparePath); if (File.Exists(compareFile)) { if (MiscUtils.GetMD5HashFromFile(compareFile) == MiscUtils.GetMD5HashFromFile(fileInfo.FullName)) { return(true); } } } return(false); }); } } AssetDatabase.Refresh(); File.Delete(tmpFile); } }
public static string ExportAsGzip(bool withEx) { string root = Path.GetFullPath(Application.dataPath + "/../../../"); // 获取本工程中git忽略的文件列表 List <string> gitIgnores = GetGitIgnores(root); if (gitIgnores == null) { return(""); } try { // 解析Framework配置文件 var configurations = ParseFrameworkConfiguration(root + "framework/framework.conf"); string version = configurations["version"][0]; var foldersCopyAll = configurations["folders_copy_all"]; var ignores = new List <string>(); var ignoresEx = new List <string>(); if (configurations.ContainsKey("ignore_public")) { ignores.AddRange(configurations["ignore_public"]); ignoresEx.AddRange(configurations["ignore_public"]); } if (configurations.ContainsKey("ignore_framework")) { ignores.AddRange(configurations["ignore_framework"]); } if (configurations.ContainsKey("ignore_framework_ex")) { ignoresEx.AddRange(configurations["ignore_framework_ex"]); } string fileMap = ""; bool hasRecordFileMap = false; UpkPack.Ignored ignoreFunc = (FileInfo fileInfo) => { bool ex = withEx && hasRecordFileMap; var relativePath = fileInfo.FullName.Replace(root, "").Replace('\\', '/'); // 过滤所有不在Framework文件夹中的文件 if (!IsInFrameworkFolder(relativePath, foldersCopyAll, ex)) { return(true); } // 过滤.gitignore中忽略的文件 if (IsIgnored(relativePath, gitIgnores)) { return(true); } // 过滤.frameworkignore中忽略的文件 if (IsIgnored(relativePath, ex ? ignoresEx : ignores)) { return(true); } // 过滤非本版本的文件地图文件 if (IsInvalidFileMap(relativePath, version)) { return(true); } if (!hasRecordFileMap) { fileMap += relativePath + "\n"; } return(false); }; // 记录文件地图 UpkPack.TraverseFolder(root, false, ignoreFunc); var fileMapPath = Path.Combine(root, "framework/filemap/" + GetFileMapName(version)); CheckCreateDirectory(fileMapPath); File.WriteAllText(fileMapPath, fileMap); hasRecordFileMap = true; // 合并为upk var upkPath = Path.Combine(root, "framework/output/v" + version + (withEx ? "_ex" : "") + ".upk"); CheckCreateDirectory(upkPath); UpkPack.PackFolder(root, upkPath, false, ignoreFunc); // 压缩为gzip var gzipPath = Path.Combine(root, "framework/output/v" + version + (withEx ? "_ex" : "") + ".upk.gz"); CheckCreateDirectory(gzipPath); File.WriteAllBytes(gzipPath, GZipUtil.Zip(File.ReadAllBytes(upkPath))); File.Delete(upkPath); return(gzipPath); } catch (System.Exception e) { Debug.LogError(e.Message + "\n" + e.StackTrace); return(""); } }