/// <summary> /// load assetbundle /// </summary> public void LoadBundle(LuaFunction onLoadedFn) { string luaPath = Path.Combine(CUtils.GetRealPersistentDataPath(), CUtils.GetRightFileName(Common.LUA_ASSETBUNDLE_FILENAME));// CUtils.GetAssetFullPath(Common.LUA_ASSETBUNDLE_FILENAME); uint crc = 0; if (CrcCheck.CheckLocalFileCrc(luaPath, out crc)) { if (loadPersistentCoroutine != null) { StopCoroutine(loadPersistentCoroutine); } loadPersistentCoroutine = StartCoroutine(DecryptLuaBundle(luaPath, false, onLoadedFn)); } else { if (crc != 0) { Debug.LogWarningFormat("luabundle crc check error! lua_crc=" + crc.ToString() + " source_crc =" + CrcCheck.GetCrc(CUtils.GetAssetBundleName(luaPath))); } if (onLoadedFn != null) { onLoadedFn.call(); } } }
public CrcCheck getCrcChecker() { if (null == g_AppCrc) { g_AppCrc = new CrcCheck(16, 0x1021, false, 0, 0x00, 2); } return(g_AppCrc); }
private void AddCrcOnHeader(PacketHeader pHeader) { byte[] data = FrameSerializer.BitPacking.GetByteBuffer(); int crcByteLength = CrcCheck.HashSize / 8; CrcCheck.ComputeHash(data, crcByteLength, data.Length - crcByteLength); pHeader.Crc = (uint)CrcHelper.FromBigEndian(CrcCheck.Hash, CrcCheck.HashSize); pHeader.EndSerialize(FrameSerializer); }
/// <summary> /// Creates the streaming crc list. /// </summary> /// <param name="sb">Sb.</param> public static uint CreateStreamingCrcList(StringBuilder sb, string outPath = null) { var crc32filename = CUtils.GetAssetName(Common.CRC32_FILELIST_NAME); string tmpPath = BuildScript.GetAssetTmpPath();// Path.Combine(Application.dataPath, BuildScript.TmpPath); ExportResources.CheckDirectory(tmpPath); string assetPath = "Assets/" + BuildScript.TmpPath + crc32filename + ".txt"; EditorUtility.DisplayProgressBar("Generate streaming crc file list", "write file to " + assetPath, 0.99f); string outTmpPath = Path.Combine(tmpPath, crc32filename + ".txt"); using (StreamWriter sr = new StreamWriter(outTmpPath, false)) { sr.Write(sb.ToString()); } // //打包到streaming path AssetDatabase.Refresh(); string crc32outfilename = CUtils.GetRightFileName(Common.CRC32_FILELIST_NAME); Debug.Log("write to path=" + outPath); Debug.Log(sb.ToString()); //读取crc string abPath = string.Empty; if (string.IsNullOrEmpty(outPath)) { abPath = Path.Combine(CUtils.realStreamingAssetsPath, crc32outfilename); } else { abPath = Path.Combine(outPath, crc32outfilename); } BuildScript.BuildABs(new string[] { assetPath }, outPath, crc32outfilename, BuildAssetBundleOptions.DeterministicAssetBundle); CrcCheck.Clear(); uint fileCrc = CrcCheck.GetLocalFileCrc(abPath); EditorUtility.ClearProgressBar(); Debug.Log("Crc file list assetbunle build complate! " + fileCrc.ToString() + abPath); if (!string.IsNullOrEmpty(outPath)) { string newName = Path.Combine(outPath, CUtils.InsertAssetBundleName(crc32outfilename, "_" + fileCrc.ToString())); FileInfo finfo = new FileInfo(abPath); finfo.MoveTo(newName); Debug.Log(" change name to " + newName); } return(fileCrc); }
//读取streamingAssets path里面的abinfo private static void ReadAssetToABInfos(string[] allBundles, FileManifest streamingManifest) { string title = "create crc list content "; var allABInfos = new List <ABInfo>(); float i = 0; float allLen = allBundles.Length; //忽略列表 Dictionary <string, bool> ignore = new Dictionary <string, bool>(); ignore.Add(CUtils.GetRightFileName(Common.CRC32_FILELIST_NAME), true); ignore.Add(CUtils.GetRightFileName(Common.CRC32_VER_FILENAME), true); ignore.Add(CUtils.GetRightFileName(CUtils.platform), true); string extension; foreach (var str in allBundles) { string url = Path.Combine(Application.dataPath, str); uint outCrc = 0; uint fileLen = 0; string abName = str.Replace("\\", "/"); string key = EditorUtils.GetAssetBundleName(abName); //后缀替换 extension = System.IO.Path.GetExtension(key); if (extension.Equals(Common.DOT_BYTES))//lua { key = key.Replace(extension, Common.CHECK_ASSETBUNDLE_SUFFIX); } if (!ignore.ContainsKey(key)) { outCrc = CrcCheck.GetLocalFileCrc(url, out fileLen); var extendsABinfo = streamingManifest.GetABInfo(key); if (extendsABinfo == null) { extendsABinfo = new ABInfo(key, outCrc, fileLen, 0); streamingManifest.Add(extendsABinfo); } extendsABinfo.priority = 0; extendsABinfo.crc32 = outCrc; extendsABinfo.size = fileLen; extendsABinfo.assetPath = str; allABInfos.Add(extendsABinfo); } EditorUtility.DisplayProgressBar(title, title + "=>" + i.ToString() + "/" + allLen.ToString(), i / allLen); i++; } EditorUtility.ClearProgressBar(); }
private void ClculateCheck() { byte[] data; string str = textBoxMainEdit.Text; str = str.Replace(" ", ""); try { if (radioBtnAsciiMode.Checked == false) { data = ConvertArray.AsciiToHex(str.ToArray()); } else { data = ConvertArray.CharToByte(str.ToArray()); } } catch (ArgumentOutOfRangeException) { textBoxResult.Text = "OutOfRange"; return; } switch (comboBoxVerifyMode.SelectedIndex) { case 0: textBoxResult.Text = SumCheck.GetCheck(data).ToString("X2"); break; case 1: textBoxResult.Text = XorCheck.GetCheck(data).ToString("X2"); break; case 2: textBoxResult.Text = LrcCheck.GetCheck(data).ToString("X2"); break; case 3: textBoxResult.Text = CrcCheck.GetCheck(data).ToString("X2"); break; case 4: textBoxResult.Text = "Not Implemented"; break; default: textBoxResult.Text = "ERROR"; break; } }
public List <IPacket> Receive(byte[] pData) { FrameSerializer.BitPacking = BitPacker.FromArray(pData); uint crcValue = FrameSerializer.BitPacking.ReadValue(CrcCheck.HashSize); // CRC #if TRACE_LOG Log("Read CRC : " + crcValue + " (" + CrcCheck.HashSize + "Bits)"); #endif dCrcParameters.Check = crcValue; byte[] dataCrcCalculation = FrameSerializer.BitPacking.GetByteBuffer(); if (CrcCheck.IsRight(dataCrcCalculation)) { CurrentSequence = (ushort)FrameSerializer.BitPacking.ReadValue(SEQUENCE_SIZE); // Sequence #if TRACE_LOG Log("Read Sequence : " + Sequence + " (" + SEQUENCE_SIZE + "Bits)"); #endif Debug.Assert(!Program.StopOnSequence.HasValue || CurrentSequence != Program.StopOnSequence.Value); List <IPacket> result = new List <IPacket>(); int id = 0; // Read the packets until an error occur or if the BitLenght is less than a byte. // This is because when the data are sent they are always rounded at the superior byte and the end of a packet is filled with 0's. while (FrameSerializer.BitPacking.BitLength >= 8 && !FrameSerializer.Error) { #if TRACE_LOG Log("Packet ID : "); #endif FrameSerializer.Serialize(ref id, 0, dFactory.Count() - 1); // Packet ID IPacket packet = dFactory.CreateInstance <IPacket>(id); packet.Header = new PacketHeader(crcValue, CurrentSequence); #if TRACE_LOG Log("Packet Data : "); #endif if (packet.Serialize(FrameSerializer)) // Data { result.Add(packet); } } return(result); } else { #if TRACE_LOG Log("Refused packet !"); #endif } return(null); }
/// <summary> /// Creates the streaming crc list. /// </summary> /// <param name="sb">Sb.</param> public static uint CreateStreamingCrcList(FileManifest sb, string fileListName, bool firstExists = false, bool copyToResFolder = false) { sb.appNumVersion = CodeVersion.APP_NUMBER; var crc32filename = CUtils.GetAssetName(fileListName); string tmpPath = BuildScript.GetAssetTmpPath();// Path.Combine(Application.dataPath, BuildScript.TmpPath); ExportResources.CheckDirectory(tmpPath); string assetPath = "Assets/" + BuildScript.TmpPath + crc32filename + ".asset"; EditorUtility.DisplayProgressBar("Generate streaming crc file list", "write file to " + assetPath, 0.99f); AssetDatabase.CreateAsset(sb, assetPath); string crc32outfilename = CUtils.GetRightFileName(fileListName); // Debug.Log("write to path=" + outPath); //读取crc string abPath = string.Empty; string resOutPath = null; uint fileSize = 0; uint fileCrc = 0; if (copyToResFolder) { resOutPath = tmpPath;//Path.Combine(tmpPath, ResFolderName); //Path.Combine(SplitPackage.UpdateOutPath, ResFolderName); abPath = Path.Combine(resOutPath, crc32outfilename); BuildScript.BuildABs(new string[] { assetPath }, resOutPath, crc32outfilename, DefaultBuildAssetBundleOptions); fileCrc = CrcCheck.GetLocalFileCrc(abPath, out fileSize); //copy crc list FileInfo finfo = new FileInfo(abPath); var resType = HugulaSetting.instance.backupResType; if (resType == CopyResType.VerResFolder) { string verPath = Path.Combine(UpdateOutVersionPath, ResFolderName);//特定版本资源目录用于资源备份 string newName = Path.Combine(verPath, InsertAssetBundleName(crc32outfilename, "_" + fileCrc.ToString())); FileHelper.CheckCreateFilePathDirectory(newName); if (File.Exists(newName)) { File.Delete(newName); } finfo.CopyTo(newName); } if (resType == CopyResType.OneResFolder) { string updateOutPath = Path.Combine(UpdateOutPath, ResFolderName);//总的资源目录 string newName = Path.Combine(updateOutPath, InsertAssetBundleName(crc32outfilename, "_" + fileCrc.ToString())); FileHelper.CheckCreateFilePathDirectory(newName); if (File.Exists(newName)) { File.Delete(newName); } finfo.CopyTo(newName); } } else { abPath = Path.Combine(CUtils.realStreamingAssetsPath, crc32outfilename); BuildScript.BuildABs(new string[] { assetPath }, null, crc32outfilename, DefaultBuildAssetBundleOptions); fileCrc = CrcCheck.GetLocalFileCrc(abPath, out fileSize); } // CrcCheck.Clear(); //copy first crc list if (!firstExists && File.Exists(abPath)) //如果没有首包 copy first package { string crc32FirstOutName = CUtils.InsertAssetBundleName(crc32outfilename, "_v" + CodeVersion.CODE_VERSION.ToString()); string destFirst = Path.Combine(UpdateOutPath, crc32FirstOutName); Debug.LogFormat("abpath={0},destFirst={1}:", abPath, destFirst); File.Copy(abPath, destFirst, true); } EditorUtility.ClearProgressBar(); // File.Delete(assetPath); Debug.Log("Crc file list assetbunle build complate! " + fileCrc.ToString() + abPath); return(fileCrc); }
/// <summary> /// 2 Creates the content of the crc list. /// </summary> /// <returns>The crc list content.</returns> /// <param name="allBundles">All bundles.</param> /// <param name="manualFileList">manual file list.</param> public static List <ABInfo>[] CreateCrcListContent(string[] allBundles, FileManifest firstCrcDict, FileManifest streamingManifest, FileManifest manualFileList) { string title = "create crc list content "; List <ABInfo>[] abInfoArray = new List <ABInfo> [2]; var diffManifest = new List <ABInfo>(); abInfoArray[0] = diffManifest; float i = 0; float allLen = allBundles.Length; //忽略列表 Dictionary <string, bool> ignore = new Dictionary <string, bool>(); ignore.Add(CUtils.GetRightFileName(Common.CRC32_FILELIST_NAME), true); ignore.Add(CUtils.GetRightFileName(Common.CRC32_VER_FILENAME), true); ignore.Add(CUtils.GetRightFileName(CUtils.platform), true); string extension; foreach (var str in allBundles) { string url = Path.Combine(Application.dataPath, str); uint outCrc = 0; uint fileLen = 0; string abName = str.Replace("\\", "/"); string key = BuildScript.GetAssetBundleName(abName); //后缀替换 extension = System.IO.Path.GetExtension(key); if (string.IsNullOrEmpty(extension)) { key = key + Common.CHECK_ASSETBUNDLE_SUFFIX; } else if (extension.Equals(Common.DOT_BYTES)) { key = key.Replace(extension, Common.CHECK_ASSETBUNDLE_SUFFIX); } if (!ignore.ContainsKey(key)) { outCrc = CrcCheck.GetLocalFileCrc(url, out fileLen); var extendsABinfo = streamingManifest.GetABInfo(key); if (extendsABinfo == null) { extendsABinfo = new ABInfo(key, outCrc, fileLen, 0); streamingManifest.Add(extendsABinfo); } extendsABinfo.crc32 = outCrc; extendsABinfo.size = fileLen; extendsABinfo.assetPath = str; if (firstCrcDict != null) { ABInfo localFirstInfo = null; if (!firstCrcDict.CheckABCrc(extendsABinfo)) { var newAbinfo = extendsABinfo.Clone(); newAbinfo.assetPath = str; diffManifest.Add(newAbinfo); } else if ((localFirstInfo = firstCrcDict.GetABInfo(extendsABinfo.abName)) != null && !extendsABinfo.EqualsDependencies(localFirstInfo)) //dependencies change { var newAbinfo = extendsABinfo.Clone(); newAbinfo.assetPath = str; diffManifest.Add(newAbinfo); } } } EditorUtility.DisplayProgressBar(title, title + "=>" + i.ToString() + "/" + allLen.ToString(), i / allLen); i++; } // CrcCheck.Clear(); EditorUtility.ClearProgressBar(); return(abInfoArray); }
/// <summary> /// 1 读取首包,找出忽略文件 /// </summary> /// <param name="ignoreFiles">Ignore files.</param> public static bool ReadFirst(out FileManifest firstCrcDict, out FileManifest streamingManifest, FileManifest extensionFileManifest) { // string title = "read first crc file list"; bool firstExists = false; firstCrcDict = null; HugulaExtensionFolderEditor.instance = null; string readPath = Path.Combine(FirstOutReleasePath, CUtils.platform); string firstFileName = CUtils.InsertAssetBundleName(CUtils.GetRightFileName(Common.CRC32_FILELIST_NAME), "_v" + CodeVersion.CODE_VERSION.ToString()); readPath = Path.Combine(readPath, firstFileName); Debug.Log(readPath); //check tmp directory if (!Directory.Exists("Assets/Tmp")) { Directory.CreateDirectory("Assets/Tmp"); } // extensionFileManifest.Clear(); //读取首包 WWW abload = new WWW("file://" + readPath); if (string.IsNullOrEmpty(abload.error) && abload.assetBundle != null) { var ab = abload.assetBundle; Object[] assets = ab.LoadAllAssets(); foreach (Object o in assets) { if (o is FileManifest) { firstCrcDict = o as FileManifest; firstExists = true; firstCrcDict.WriteToFile("Assets/Tmp/firstManifest.txt"); Debug.Log(firstCrcDict.Count); } } ab.Unload(false); } else { Debug.LogWarning(abload.error + "no frist packeage in " + readPath); } abload.Dispose(); //读取本地AB包AssetBundleManifest var fileListName = Common.CRC32_FILELIST_NAME; var url = CUtils.PathCombine(CUtils.GetRealStreamingAssetsPath(), CUtils.GetRightFileName(fileListName)); Debug.Log(url); // url = CUtils.GetAndroidABLoadPath(url); AssetBundle assetbundle = AssetBundle.LoadFromFile(url); var assets1 = assetbundle.LoadAllAssets <FileManifest>(); uint len = 0; var crc32 = CrcCheck.GetLocalFileCrc(url, out len); var streamingManifest1 = assets1[0]; assetbundle.Unload(false); streamingManifest = streamingManifest1; streamingManifest1.crc32 = crc32; Debug.Log(streamingManifest1.appNumVersion); Debug.Log(streamingManifest1.crc32); //读取忽略扩展包 System.Action <string, int> AddExtensionFileManifest = (string ab, int priority1) => { var abinfo = streamingManifest1.GetABInfo(ab); if (abinfo == null) { abinfo = new ABInfo(ab, 0, 0, priority1); streamingManifest1.Add(abinfo); } abinfo.priority = priority1; extensionFileManifest.Add(abinfo); }; //读取忽略别名后缀 // priority = FileManifestOptions.StreamingAssetsPriority; // var inclusionVariants = HugulaSetting.instance.inclusionVariants; // var allVariants = HugulaSetting.instance.allVariants; // string pattern = ""; // string sp = ""; // foreach (var s in allVariants) // { // if (!inclusionVariants.Contains(s)) // { // pattern += sp + @"\." + s + "$"; // sp = "|"; // } // } // if (!string.IsNullOrEmpty(pattern)) // { // // Debug.Log(pattern); // var u3dList = ExportResources.getAllChildFiles(dinfo.FullName, pattern, null, true); // foreach (var s in u3dList) // { // priority++; // string ab = CUtils.GetAssetBundleName(s); // ab = ab.Replace("\\", "/"); // AddExtensionFileManifest(ab, priority); // } // } //读取手动加载排除资源 string firstStreamingPath = CUtils.realStreamingAssetsPath; DirectoryInfo dinfo = new DirectoryInfo(firstStreamingPath); var dircs = dinfo.GetDirectories(); var priority = FileManifestOptions.ManualPriority; Debug.LogFormat("ManualPriority.priority={0}", priority); foreach (var dir in dircs) { var u3dList = ExportResources.getAllChildFiles(dir.FullName, @"\.meta$|\.manifest$|\.DS_Store$", null, false); foreach (var s in u3dList) { priority++; string ab = CUtils.GetAssetBundleName(s); ab = ab.Replace("\\", "/"); AddExtensionFileManifest(ab, priority); } } //读取首包排除资源 var firstLoadFiles = HugulaExtensionFolderEditor.instance.FirstLoadFiles; priority = FileManifestOptions.FirstLoadPriority; Debug.LogFormat("FirstLoadPriority.priority={0}", priority); var needLoadFirst = false; foreach (var s in firstLoadFiles) { var ab = CUtils.GetRightFileName(s); priority++; AddExtensionFileManifest(ab, priority); needLoadFirst = true; } if (!HugulaSetting.instance.spliteExtensionFolder) { needLoadFirst = false; } streamingManifest.hasFirstLoad = needLoadFirst; // AssetDatabase.SaveAssets(); //读取自动下载资源 var extensionFiles = HugulaExtensionFolderEditor.instance.ExtensionFiles; priority = FileManifestOptions.AutoHotPriority; Debug.LogFormat("AutoHotPriority.priority={0}", priority); foreach (var s in extensionFiles) { var ab = CUtils.GetRightFileName(s); priority++; AddExtensionFileManifest(ab, priority); } streamingManifest.WriteToFile("Assets/Tmp/streamingManifest0.txt"); extensionFileManifest.WriteToFile("Assets/Tmp/manualFileList0.txt"); EditorUtility.ClearProgressBar(); return(firstExists); }
/// <summary> /// 1 读取首包,找出忽略文件 /// </summary> /// <param name="ignoreFiles">Ignore files.</param> public static bool ReadFirst(string[] allBundles, out FileManifest firstCrcDict, out FileManifest streamingManifest, FileManifest extensionFileManifest) { // string title = "read first crc file list"; bool firstExists = false; firstCrcDict = null; HugulaExtensionFolderEditor.instance = null; string readPath = Path.Combine(FirstOutReleasePath, CUtils.platform); string firstFileName = CUtils.InsertAssetBundleName(CUtils.GetRightFileName(Common.CRC32_FILELIST_NAME), "_v" + CodeVersion.CODE_VERSION.ToString()); readPath = Path.Combine(readPath, firstFileName); Debug.Log(readPath); //check tmp directory if (!Directory.Exists("Assets/Tmp")) { Directory.CreateDirectory("Assets/Tmp"); } // extensionFileManifest.Clear(); //读取首包 WWW abload = new WWW("file://" + readPath); if (string.IsNullOrEmpty(abload.error) && abload.assetBundle != null) { var ab = abload.assetBundle; Object[] assets = ab.LoadAllAssets(); foreach (Object o in assets) { if (o is FileManifest) { firstCrcDict = o as FileManifest; firstExists = true; firstCrcDict.WriteToFile("Assets/Tmp/firstPackageManifest.txt"); Debug.Log(firstCrcDict.Count); } } ab.Unload(false); } else { Debug.LogWarning(abload.error + "no frist packeage in " + readPath); } abload.Dispose(); //读取本地AB包AssetBundleManifest var fileListName = Common.CRC32_FILELIST_NAME; var url = CUtils.PathCombine(CUtils.GetRealStreamingAssetsPath(), CUtils.GetRightFileName(fileListName)); AssetBundle assetbundle = AssetBundle.LoadFromFile(url); var assets1 = assetbundle.LoadAllAssets <FileManifest>(); uint len = 0; var crc32 = CrcCheck.GetLocalFileCrc(url, out len); var streamingManifest1 = assets1[0]; assetbundle.Unload(false); // streamingManifest = streamingManifest1; streamingManifest1.crc32 = crc32; Debug.Log(streamingManifest1.appNumVersion); Debug.Log(streamingManifest1.crc32); //读取assetbundle的crc和size ReadAssetToABInfos(allBundles, streamingManifest1); if (!HugulaSetting.instance.spliteExtensionFolder)//如果不分离文件 { streamingManifest = streamingManifest1; streamingManifest.hasFirstLoad = false; streamingManifest.WriteToFile("Assets/Tmp/StreamingAssetsManifest.txt"); extensionFileManifest.WriteToFile("Assets/Tmp/ExtensionFileManifest.txt"); return(firstExists); } //读取忽略扩展包 System.Action <string, int> AddExtensionFileManifest = (string ab, int priority1) => { var abinfo = streamingManifest1.GetABInfo(ab); if (abinfo == null) { Debug.LogWarningFormat("the file {0} is not exists. please check ExtenionFolder.txt", ab); // abinfo = new ABInfo(ab, 0, 0, priority1); // streamingManifest1.Add(abinfo); return; } abinfo.priority = priority1; extensionFileManifest.Add(abinfo); }; string firstStreamingPath = CUtils.realStreamingAssetsPath; var needLoadFirst = false; var onlyInclusionFiles = HugulaExtensionFolderEditor.instance.OnlyInclusionFiles;//只包涵 var onlyInclusionRightFiles = new List <string>(); foreach (var f in onlyInclusionFiles) { onlyInclusionRightFiles.Add(CUtils.GetRightFileName(f)); } var firstPriority = FileManifestOptions.FirstLoadPriority; var firstLoadFiles = HugulaExtensionFolderEditor.instance.FirstLoadFiles;//读取首包资源 var firstLoadRightFiles = new List <string>(); foreach (var f in firstLoadFiles) { firstLoadRightFiles.Add(CUtils.GetRightFileName(f)); } var manualPriority = FileManifestOptions.ManualPriority; var extensionFiles = HugulaExtensionFolderEditor.instance.ExtensionFiles;//读取扩展文件资源 var extensionRightFiles = new List <string>(); foreach (var f in extensionFiles) { extensionRightFiles.Add(CUtils.GetRightFileName(f)); } var autoPriority = FileManifestOptions.AutoHotPriority; Dictionary <int, int> priorityDic = new Dictionary <int, int>(); priorityDic[firstPriority] = firstPriority; priorityDic[manualPriority] = manualPriority; priorityDic[autoPriority] = autoPriority; priorityDic[FileManifestOptions.StreamingAssetsPriority] = FileManifestOptions.StreamingAssetsPriority; //streamingAssets目录下的文件夹默认为手动加载 DirectoryInfo dinfo = new DirectoryInfo(firstStreamingPath); var dircs = dinfo.GetDirectories(); foreach (var dir in dircs) { var u3dList = EditorUtils.getAllChildFiles(dir.FullName, @"\.meta$|\.manifest$|\.DS_Store$", null, false); foreach (var s in u3dList) { string ab = CUtils.GetAssetBundleName(s); ab = ab.Replace("\\", "/"); extensionRightFiles.Add(ab); } } var allAbInfos = streamingManifest1.allAbInfo; bool shouldInclude = false; bool elseShouldInAutoHot = onlyInclusionRightFiles.Count > 0 && false; bool elseShouldInFirst = onlyInclusionRightFiles.Count > 0; foreach (var abInfo in allAbInfos) { shouldInclude = onlyInclusionRightFiles.Contains(abInfo.abName); if (!shouldInclude && firstLoadRightFiles.Contains(abInfo.abName))//首次启动加载包 { priorityDic[firstPriority]++; AddExtensionFileManifest(abInfo.abName, priorityDic[firstPriority]); needLoadFirst = true; } else if (!shouldInclude && extensionRightFiles.Contains(abInfo.abName)) //手动加载 { priorityDic[manualPriority]++; AddExtensionFileManifest(abInfo.abName, priorityDic[manualPriority]); } else if (!shouldInclude && elseShouldInAutoHot) //放入自动热更新包 { priorityDic[autoPriority]++; AddExtensionFileManifest(abInfo.abName, priorityDic[autoPriority]); } else if (!shouldInclude && elseShouldInFirst) { priorityDic[firstPriority]++; AddExtensionFileManifest(abInfo.abName, priorityDic[firstPriority]); needLoadFirst = true; } } if (!HugulaSetting.instance.spliteExtensionFolder) { needLoadFirst = false; } streamingManifest = streamingManifest1; streamingManifest.hasFirstLoad = needLoadFirst; streamingManifest.WriteToFile("Assets/Tmp/StreamingAssetsManifest.txt"); extensionFileManifest.WriteToFile("Assets/Tmp/ExtensionFileManifest.txt"); EditorUtility.ClearProgressBar(); return(firstExists); }
/// <summary> /// 2 Creates the content of the crc list. /// </summary> /// <returns>The crc list content.</returns> /// <param name="allBundles">All bundles.</param> /// <param name="whiteFileList">White file list.</param> /// <param name="blackFileList">Black file list.</param> public static StringBuilder[] CreateCrcListContent(string[] allBundles, Dictionary <string, uint[]> firstCrcDict, Dictionary <string, uint[]> currCrcDict, Dictionary <string, uint[]> diffCrcDict, HashSet <string> whiteFileList, HashSet <string> blackFileList) { string title = "create crc list content "; StringBuilder[] sbs = new StringBuilder[2]; sbs[0] = new StringBuilder(); sbs[1] = new StringBuilder(); //var selected = string.Empty; float i = 0; float allLen = allBundles.Length; //group 0 white,black,other var white0 = new StringBuilder(); var black0 = new StringBuilder(); var other0 = new StringBuilder(); //group 1 white,black,other var white1 = new StringBuilder(); var black1 = new StringBuilder(); var other1 = new StringBuilder(); //忽略列表 Dictionary <string, bool> ignore = new Dictionary <string, bool>(); ignore.Add(CUtils.GetRightFileName(Common.CRC32_FILELIST_NAME), true); ignore.Add(CUtils.GetRightFileName(Common.CRC32_VER_FILENAME), true); CrcCheck.Clear(); filterSB getCurrSB = (string key, StringBuilder white, StringBuilder black, StringBuilder other, HashSet <string> whiteList, HashSet <string> blackList) => { if (whiteList.Contains(key)) { return(white); } else if (blackList.Contains(key)) { return(black); } else { return(other); } }; StringBuilder currSb; foreach (var str in allBundles) { string url = Path.Combine(CUtils.GetRealStreamingAssetsPath(), str); uint outCrc = 0; uint fileLen = 0; string abName = str.Replace("\\", "/"); string key = CUtils.GetAssetBundleName(abName); if (!ignore.ContainsKey(key)) { outCrc = CrcCheck.GetLocalFileCrc(url, out fileLen); currCrcDict.Add(key, new uint[] { outCrc, fileLen }); currSb = getCurrSB(key, white0, black0, other0, whiteFileList, blackFileList); currSb.AppendLine("[\"" + key + "\"] = {" + outCrc + "," + fileLen + "},"); uint[] fCrc = null; if (firstCrcDict.TryGetValue(key, out fCrc) == false || fCrc[0] != outCrc)//如果不一样 { diffCrcDict.Add(key, new uint[] { outCrc, fileLen }); // Debug.LogFormat("need update abName = {0} = {1} = {2}",abName,key,outCrc); currSb = getCurrSB(key, white1, black1, other1, whiteFileList, blackFileList); currSb.AppendLine("[\"" + key + "\"] = {" + outCrc + "," + fileLen + "},"); } } EditorUtility.DisplayProgressBar(title, title + "=>" + i.ToString() + "/" + allLen.ToString(), i / allLen); i++; } sbs[0].Append("return {"); sbs[0].AppendLine("[\"white\"] = { "); sbs[0].AppendLine(white0.ToString() + "},"); sbs[0].AppendLine("[\"black\"] = { "); sbs[0].AppendLine(black0.ToString() + "},"); sbs[0].AppendLine("[\"other\"] = { "); sbs[0].AppendLine(other0.ToString() + "}"); sbs[0].AppendLine("}"); sbs[1].Append("return {"); sbs[1].AppendLine("[\"white\"] = { "); sbs[1].AppendLine(white1.ToString() + "},"); sbs[1].AppendLine("[\"black\"] = { "); sbs[1].AppendLine(black1.ToString() + "},"); sbs[1].AppendLine("[\"other\"] = { "); sbs[1].AppendLine(other1.ToString() + "}"); sbs[1].AppendLine("}"); CrcCheck.Clear(); EditorUtility.ClearProgressBar(); return(sbs); }
/// <summary> /// Creates the streaming crc list. /// </summary> /// <param name="sb">Sb.</param> public static uint CreateStreamingCrcList(StringBuilder sb, bool firstExists = false, string outPath = null) { var crc32filename = CUtils.GetAssetName(Common.CRC32_FILELIST_NAME); string tmpPath = BuildScript.GetAssetTmpPath();// Path.Combine(Application.dataPath, BuildScript.TmpPath); ExportResources.CheckDirectory(tmpPath); string assetPath = "Assets/" + BuildScript.TmpPath + crc32filename + ".asset"; EditorUtility.DisplayProgressBar("Generate streaming crc file list", "write file to " + assetPath, 0.99f); string outTmpPath = Path.Combine(tmpPath, crc32filename + ".lua"); using (StreamWriter sr = new StreamWriter(outTmpPath, false)) { sr.Write(sb.ToString()); } // //打包到streaming path AssetDatabase.Refresh(); BytesAsset ba = ScriptableObject.CreateInstance(typeof(BytesAsset)) as BytesAsset; ba.bytes = File.ReadAllBytes(outTmpPath); AssetDatabase.CreateAsset(ba, assetPath); string crc32outfilename = CUtils.GetRightFileName(Common.CRC32_FILELIST_NAME); Debug.Log("write to path=" + outPath); Debug.Log(sb.ToString()); //读取crc string abPath = string.Empty; string resOutPath = null; if (string.IsNullOrEmpty(outPath)) { abPath = Path.Combine(CUtils.realStreamingAssetsPath, crc32outfilename); } else { resOutPath = Path.Combine(outPath, ResFolderName); ExportResources.CheckDirectory(resOutPath); abPath = Path.Combine(resOutPath, crc32outfilename); } BuildScript.BuildABs(new string[] { assetPath }, resOutPath, crc32outfilename, BuildAssetBundleOptions.DeterministicAssetBundle); CrcCheck.Clear(); uint fileSize = 0; uint fileCrc = CrcCheck.GetLocalFileCrc(abPath, out fileSize); EditorUtility.ClearProgressBar(); Debug.Log("Crc file list assetbunle build complate! " + fileCrc.ToString() + abPath); if (!string.IsNullOrEmpty(outPath)) { string newName = Path.Combine(resOutPath, CUtils.InsertAssetBundleName(crc32outfilename, "_" + fileCrc.ToString())); if (File.Exists(newName)) { File.Delete(newName); } FileInfo finfo = new FileInfo(abPath); if (!firstExists) //如果没有首包 { string destFirst = Path.Combine(outPath, crc32outfilename); Debug.Log("destFirst:" + destFirst); File.Copy(abPath, destFirst, true); // finfo.CopyTo(destFirst); } finfo.MoveTo(newName); Debug.Log(" change name to " + newName); } return(fileCrc); }
/// <summary> /// 2 Creates the content of the crc list. /// </summary> /// <returns>The crc list content.</returns> /// <param name="allBundles">All bundles.</param> /// <param name="manualFileList">manual file list.</param> public static StringBuilder[] CreateCrcListContent(string[] allBundles, Dictionary <string, object[]> firstCrcDict, Dictionary <string, object[]> currCrcDict, Dictionary <string, object[]> diffCrcDict, HashSet <string> manualFileList) { string title = "create crc list content "; StringBuilder[] sbs = new StringBuilder[2]; sbs[0] = new StringBuilder(); sbs[1] = new StringBuilder(); //var selected = string.Empty; float i = 0; float allLen = allBundles.Length; //group 0 manual,normal var manual0 = new StringBuilder(); var normal0 = new StringBuilder(); //group 1 manual,normal var manual1 = new StringBuilder(); var normal1 = new StringBuilder(); //忽略列表 Dictionary <string, bool> ignore = new Dictionary <string, bool>(); ignore.Add(CUtils.GetRightFileName(Common.CRC32_FILELIST_NAME), true); ignore.Add(CUtils.GetRightFileName(Common.CRC32_VER_FILENAME), true); CrcCheck.Clear(); filterSB getCurrSB = (string key, StringBuilder manual, StringBuilder normal, HashSet <string> manualList) => { if (manualList.Contains(key)) { return(manual); } else { return(normal); } }; StringBuilder currSb; string extension; foreach (var str in allBundles) { string url = Path.Combine(Application.dataPath, str); uint outCrc = 0; uint fileLen = 0; string abName = str.Replace("\\", "/"); string key = BuildScript.GetAssetBundleName(abName); //后缀替换 extension = System.IO.Path.GetExtension(key); if (!string.IsNullOrEmpty(extension) && extension.Equals(Common.DOT_BYTES)) { key = key.Replace(extension, Common.CHECK_ASSETBUNDLE_SUFFIX); } if (!ignore.ContainsKey(key)) { outCrc = CrcCheck.GetLocalFileCrc(url, out fileLen); currCrcDict[key] = new object[] { outCrc, fileLen, str }; currSb = getCurrSB(key, manual0, normal0, manualFileList); currSb.AppendLine("[\"" + key + "\"] = {" + outCrc + "," + fileLen + "},"); object[] fCrc = null; if (firstCrcDict.TryGetValue(key, out fCrc) == false || (uint)fCrc[0] != outCrc)//如果不一样 { diffCrcDict[key] = new object[] { outCrc, fileLen, str }; // Debug.LogFormat("need update abName = {0} = {1} = {2}",abName,key,outCrc); currSb = getCurrSB(key, manual1, normal1, manualFileList); currSb.AppendLine("[\"" + key + "\"] = {" + outCrc + "," + fileLen + "},"); } } EditorUtility.DisplayProgressBar(title, title + "=>" + i.ToString() + "/" + allLen.ToString(), i / allLen); i++; } sbs[0].Append("return {"); sbs[0].AppendLine("[\"manual\"] = { "); sbs[0].AppendLine(manual0.ToString() + "},"); sbs[0].AppendLine("[\"normal\"] = { "); sbs[0].AppendLine(normal0.ToString() + "}"); sbs[0].AppendLine("}"); sbs[1].Append("return {"); sbs[1].AppendLine("[\"manual\"] = { "); sbs[1].AppendLine(manual1.ToString() + "},"); sbs[1].AppendLine("[\"normal\"] = { "); sbs[1].AppendLine(normal1.ToString() + "}"); sbs[1].AppendLine("}"); CrcCheck.Clear(); EditorUtility.ClearProgressBar(); return(sbs); }
/// <summary> /// 1 读取首包,找出忽略文件 /// </summary> /// <param name="ignoreFiles">Ignore files.</param> public static bool ReadFirst(Dictionary <string, uint> firstCrcDict, HashSet <string> whiteFileList, HashSet <string> blackFileList) { string title = "read first crc file list"; CrcCheck.Clear(); bool firstExists = false; string readPath = Path.Combine(GetFirstOutPath(), CUtils.GetAssetPath("")); readPath = Path.Combine(readPath, CUtils.GetRightFileName(Common.CRC32_FILELIST_NAME)); Debug.Log(readPath); whiteFileList.Clear(); blackFileList.Clear(); WWW abload = new WWW("file://" + readPath); if (string.IsNullOrEmpty(abload.error) && abload.assetBundle != null) { var ab = abload.assetBundle; TextAsset ta = ab.LoadAllAssets <TextAsset>()[0]; //ta.text Debug.Log(ta); string context = ta.text; string[] split = context.Split('\n'); System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(@"\[""(.+)""\]\s+=\s+(\d+)"); float j = 1; float l = split.Length; foreach (var line in split) { System.Text.RegularExpressions.Match match = regex.Match(line); if (match.Success) { //Debug.Log(match.Groups[1].Value + " " + match.Groups[2].Value); // CrcCheck.Add (match.Groups [1].Value, System.Convert.ToUInt32 (match.Groups [2].Value)); firstCrcDict.Add(match.Groups[1].Value, System.Convert.ToUInt32(match.Groups[2].Value)); } //Debug.Log(line); EditorUtility.DisplayProgressBar(title, "read first crc => " + j.ToString() + "/" + l.ToString(), j / l); j++; } ab.Unload(true); firstExists = true; } else { Debug.LogWarning(abload.error + "no frist packeage in " + readPath); } abload.Dispose(); //读取忽略扩展包 string firstStreamingPath = CUtils.realStreamingAssetsPath; DirectoryInfo dinfo = new DirectoryInfo(firstStreamingPath); var dircs = dinfo.GetDirectories(); foreach (var dir in dircs) { var u3dList = ExportResources.getAllChildFiles(dir.FullName, @"\.meta$|\.manifest$|\.DS_Store$", null, false); List <string> assets = new List <string>(); foreach (var s in u3dList) { string ab = CUtils.GetAssetBundleName(s); ab = ab.Replace("\\", "/"); blackFileList.Add(ab); Debug.Log("extends folder:" + ab); } } //从网络读取白名单列表 todo EditorUtility.ClearProgressBar(); return(firstExists); }
public static void GenerateAssetBundlesUpdateFile(string[] allBundles) { string title = "Generate Update File "; string info = "Compute crc32"; EditorUtility.DisplayProgressBar(title, info, 0.1f); #region 读取首包 CrcCheck.Clear(); bool firstExists = false; DirectoryInfo firstDir = new DirectoryInfo(Application.dataPath); string firstPath = Path.Combine(firstDir.Parent.Parent.FullName, Common.FirstOutPath); string readPath = Path.Combine(firstPath, CUtils.GetAssetPath("")); readPath = Path.Combine(readPath, CUtils.GetRightFileName(Common.CRC32_FILELIST_NAME)); Debug.Log(readPath); WWW abload = new WWW("file://" + readPath); if (string.IsNullOrEmpty(abload.error) && abload.assetBundle != null) { var ab = abload.assetBundle; TextAsset ta = ab.LoadAllAssets <TextAsset>()[0]; //ta.text Debug.Log(ta); string context = ta.text; string[] split = context.Split('\n'); System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(@"\[""(.+)""\]\s+=\s+(\d+)"); float j = 1; float l = split.Length; foreach (var line in split) { System.Text.RegularExpressions.Match match = regex.Match(line); if (match.Success) { //Debug.Log(match.Groups[1].Value + " " + match.Groups[2].Value); CrcCheck.Add(match.Groups[1].Value, System.Convert.ToUInt32(match.Groups[2].Value)); } //Debug.Log(line); EditorUtility.DisplayProgressBar(title, "read first crc => " + j.ToString() + "/" + l.ToString(), j / l); j++; } ab.Unload(true); firstExists = true; } else { Debug.LogWarning(abload.error + "no frist packeage in " + readPath); } abload.Dispose(); #endregion #region 生成校验列表 Dictionary <string, uint> updateList = new Dictionary <string, uint>(); StringBuilder sb = new StringBuilder(); sb.AppendLine("return {"); var selected = string.Empty; float i = 0; float allLen = allBundles.Length; //忽略列表 Dictionary <string, bool> ignore = new Dictionary <string, bool>(); ignore.Add(CUtils.GetRightFileName(Common.CRC32_FILELIST_NAME), true); ignore.Add(CUtils.GetRightFileName(Common.CRC32_VER_FILENAME), true); foreach (var str in allBundles) { string url = Path.Combine(CUtils.GetRealStreamingAssetsPath(), str); uint outCrc = 0; Debug.Log(str); string abName = str.Replace("\\", "/"); string key = CUtils.GetAssetBundleName(abName); if (!ignore.ContainsKey(key) && CrcCheck.CheckLocalFileWeakCrc(url, out outCrc) == false) //如果不一致需要更新 { updateList.Add(abName, outCrc); //记录导出记录 sb.AppendLine("[\"" + key + "\"] = " + outCrc + ","); } EditorUtility.DisplayProgressBar(title, info + "=>" + i.ToString() + "/" + allLen.ToString(), i / allLen); i++; } sb.AppendLine("}"); //Debug.Log (sb.ToString ()); CrcCheck.Clear(); //输出到临时目录 var crc32filename = CUtils.GetAssetName(Common.CRC32_FILELIST_NAME); string tmpPath = Path.Combine(Application.dataPath, TmpPath); ExportResources.CheckDirectory(tmpPath); string assetPath = "Assets/" + TmpPath + crc32filename + ".txt"; EditorUtility.DisplayProgressBar("Generate file list", "write file to " + assetPath, 0.99f); string outPath = Path.Combine(tmpPath, crc32filename + ".txt"); Debug.Log("write to path=" + outPath); using (StreamWriter sr = new StreamWriter(outPath, false)) { sr.Write(sb.ToString()); } // //打包到streaming path AssetDatabase.Refresh(); string crc32outfilename = CUtils.GetRightFileName(Common.CRC32_FILELIST_NAME); //(fileCrc32ListName + ".u3d"); BuildScript.BuildABs(new string[] { assetPath }, null, crc32outfilename, BuildAssetBundleOptions.DeterministicAssetBundle); string topath = Path.Combine(GetOutPutPath(), crc32outfilename); Debug.Log(info + " assetbunle build complate! " + topath); #endregion #region 生成版本号 //生成版本号码 string crc32Path = "file://" + Path.Combine(CUtils.GetRealStreamingAssetsPath(), CUtils.GetRightFileName(Common.CRC32_FILELIST_NAME)); //CUtils.GetAssetFullPath (fileCrc32ListName+".u3d"); WWW loaderVer = new WWW(crc32Path); if (!string.IsNullOrEmpty(loaderVer.error)) { Debug.LogError(loaderVer.error); return; } uint crcVer = Crc32.Compute(loaderVer.bytes); loaderVer.Dispose(); tmpPath = CUtils.GetRealStreamingAssetsPath();//Path.Combine (Application.streamingAssetsPath, CUtils.GetAssetPath("")); outPath = Path.Combine(tmpPath, CUtils.GetRightFileName(Common.CRC32_VER_FILENAME)); Debug.Log("verion to path=" + outPath); //json 化version{ code,crc32,version} StringBuilder verJson = new StringBuilder(); verJson.Append("{"); verJson.Append(@"""code"":" + CodeVersion.CODE_VERSION + ","); verJson.Append(@"""crc32"":" + crcVer.ToString() + ","); verJson.Append(@"""time"":" + CUtils.ConvertDateTimeInt(System.DateTime.Now) + ""); verJson.Append("}"); using (StreamWriter sr = new StreamWriter(outPath, false)) { sr.Write(verJson.ToString()); } Debug.Log(info + " Complete! ver=" + crcVer.ToString() + " path " + outPath); BuildScript.BuildAssetBundles(); #endregion #region copy更新文件导出 if (updateList.Count > 0) { info = "copy updated file "; string updateOutPath = Path.Combine(firstPath, CUtils.GetAssetPath("") + System.DateTime.Now.ToString("_yyyy-MM-dd_HH-mm")); DirectoryInfo outDic = new DirectoryInfo(updateOutPath); if (outDic.Exists) { outDic.Delete(); } outDic.Create(); if (!firstExists) { updateList.Clear(); //如果没有首包,只导出校验文件。 } updateList.Add(CUtils.GetRightFileName(Common.CRC32_VER_FILENAME), 0); updateList.Add(CUtils.GetRightFileName(Common.CRC32_FILELIST_NAME), crcVer); string sourcePath; string outfilePath; i = 1; allLen = updateList.Count; string key = ""; foreach (var k in updateList) { key = CUtils.GetAssetBundleName(k.Key); sourcePath = Path.Combine(CUtils.GetRealStreamingAssetsPath(), k.Key); if (k.Value != 0) { if (key.Equals(CUtils.platformFloder)) { key = key + "_" + k.Value.ToString() + "." + Common.ASSETBUNDLE_SUFFIX; } else { key = CUtils.InsertAssetBundleName(key, "_" + k.Value.ToString());// } } outfilePath = Path.Combine(updateOutPath, key); FileHelper.CheckCreateFilePathDirectory(outfilePath); File.Copy(sourcePath, outfilePath, true);// source code copy EditorUtility.DisplayProgressBar(title, info + "=>" + i.ToString() + "/" + allLen.ToString(), i / allLen); i++; } Debug.Log(" copy file complete!"); } #endregion EditorUtility.ClearProgressBar(); }
private static void CopyFileToSplitFolder(Dictionary <string, object[]> updateList) { string updateOutPath = Path.Combine(UpdateOutPath, ResFolderName);//总的资源目录 ExportResources.CheckDirectory(updateOutPath); string updateOutVersionPath = Path.Combine(UpdateOutVersionPath, ResFolderName);//特定版本资源目录用于资源备份 ExportResources.CheckDirectory(updateOutVersionPath); int allLen = updateList.Count; int i = 0; EditorUtility.DisplayProgressBar("Copy Change AssetBundle File", "copy file to " + updateOutPath, 0.09f); string sourcePath; string outfilePath, outfileVerionPath; string key, extension; uint crc = 0; StringBuilder erro = new StringBuilder(); foreach (var k in updateList) { key = k.Key; //CUtils.GetAssetBundleName(k.Key); sourcePath = Path.Combine(Application.dataPath, k.Value[2].ToString()); if (!File.Exists(sourcePath)) // { string e = string.Format("copy file ({0}) not Exists ", sourcePath); Debug.LogError(e); erro.AppendLine(e); continue; } extension = System.IO.Path.GetExtension(key); crc = (uint)k.Value[0]; if (crc != 0) { if (string.IsNullOrEmpty(extension)) { key = key + "_" + crc.ToString() + Common.CHECK_ASSETBUNDLE_SUFFIX; } else if (extension != Common.CHECK_ASSETBUNDLE_SUFFIX) { key = key.Replace(extension, Common.CHECK_ASSETBUNDLE_SUFFIX); key = CUtils.InsertAssetBundleName(key, "_" + crc.ToString());// } else { key = CUtils.InsertAssetBundleName(key, "_" + crc.ToString()); // } } outfilePath = Path.Combine(updateOutPath, key); outfileVerionPath = Path.Combine(updateOutVersionPath, key); FileHelper.CheckCreateFilePathDirectory(outfilePath); // FileHelper.CheckCreateFilePathDirectory(outfileVerionPath); File.Copy(sourcePath, outfilePath, true);// source code copy // File.Copy(sourcePath, outfileVerionPath, true);// source code copy //check file crc uint filelen = 0; var copyFileCrc = CrcCheck.GetLocalFileCrc(outfilePath, out filelen); if (copyFileCrc != crc) { string e = string.Format("crc(source{0}!=copy{1}),path={2}", crc, copyFileCrc, outfilePath); Debug.LogError(e); erro.AppendLine(e); } EditorUtility.DisplayProgressBar("copy file to split folder " + updateOutPath, " copy file =>" + i.ToString() + "/" + allLen.ToString(), i / allLen); i++; } Debug.Log(" copy file complete!"); EditorUtility.ClearProgressBar(); string errContent = erro.ToString(); if (!string.IsNullOrEmpty(errContent)) { string tmpPath = BuildScript.GetAssetTmpPath(); ExportResources.CheckDirectory(tmpPath); string outPath = Path.Combine(tmpPath, "error.txt"); Debug.Log("write to path=" + outPath); using (StreamWriter sr = new StreamWriter(outPath, true)) { sr.WriteLine(" Error : " + System.DateTime.Now.ToString()); sr.Write(errContent); } } }
public const string ResFolderName = EditorCommon.ResFolderName; //"res"; #region public /// <summary> /// 1 读取首包,找出忽略文件 /// </summary> /// <param name="ignoreFiles">Ignore files.</param> public static bool ReadFirst(Dictionary <string, object[]> firstCrcDict, HashSet <string> whiteFileList, HashSet <string> blackFileList) { string title = "read first crc file list"; CrcCheck.Clear(); bool firstExists = false; string readPath = Path.Combine(GetFirstOutPath(), CUtils.platform); readPath = Path.Combine(readPath, CUtils.GetRightFileName(Common.CRC32_FILELIST_NAME)); Debug.Log(readPath); whiteFileList.Clear(); blackFileList.Clear(); WWW abload = new WWW("file://" + readPath); if (string.IsNullOrEmpty(abload.error) && abload.assetBundle != null) { var ab = abload.assetBundle; Object[] assets = ab.LoadAllAssets(); BytesAsset ba; foreach (Object o in assets) { ba = o as BytesAsset; if (ba != null) { byte[] bytes = ba.bytes; string context = LuaHelper.GetUTF8String(bytes); Debug.Log(context); string[] split = context.Split('\n'); System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(@"\[""(.+)""\]\s+=\s+{(\d+),(\d+)}"); float j = 1; float l = split.Length; foreach (var line in split) { System.Text.RegularExpressions.Match match = regex.Match(line); if (match.Success) { //Debug.Log(match.Groups[1].Value + " " + match.Groups[2].Value); // CrcCheck.Add (match.Groups [1].Value, System.Convert.ToUInt32 (match.Groups [2].Value)); object[] val = new object[] { System.Convert.ToUInt32(match.Groups[2].Value), System.Convert.ToUInt32(match.Groups[3].Value) }; firstCrcDict[match.Groups[1].Value] = val; } //Debug.Log(line); EditorUtility.DisplayProgressBar(title, "read first crc => " + j.ToString() + "/" + l.ToString(), j / l); j++; } firstExists = true; } } ab.Unload(true); } else { Debug.LogWarning(abload.error + "no frist packeage in " + readPath); } abload.Dispose(); #if HUGULA_WEB_MODE string[] whitelist = new string[] { CUtils.GetRightFileName(Common.CRC32_FILELIST_NAME), CUtils.GetRightFileName(Common.CRC32_VER_FILENAME), CUtils.GetRightFileName(Common.LUA_ASSETBUNDLE_FILENAME), CUtils.platformFloder }; foreach (var kv in whitelist) { whiteFileList.Add(kv); } #else //读取忽略扩展包 bool spExtFolder = HugulaSetting.instance.spliteExtensionFolder; if (spExtFolder) { string firstStreamingPath = CUtils.realStreamingAssetsPath; DirectoryInfo dinfo = new DirectoryInfo(firstStreamingPath); var dircs = dinfo.GetDirectories(); foreach (var dir in dircs) { var u3dList = ExportResources.getAllChildFiles(dir.FullName, @"\.meta$|\.manifest$|\.DS_Store$", null, false); //List<string> assets = new List<string>(); foreach (var s in u3dList) { string ab = CUtils.GetAssetBundleName(s); ab = ab.Replace("\\", "/"); blackFileList.Add(ab); Debug.Log("extends folder:" + ab); } } } else { Debug.Log("extends folder is close ,spliteExtensionFolder=" + spExtFolder); } #endif //从网络读取白名单列表 todo EditorUtility.ClearProgressBar(); return(firstExists); }
private static void CopyFileToSplitFolder(Dictionary <string, ABInfo> updateList) { string updateOutPath = Path.Combine(UpdateOutPath, ResFolderName); //总的资源目录 // ExportResources.CheckDirectory(updateOutPath); string verPath = Path.Combine(UpdateOutVersionPath, ResFolderName); //特定版本资源目录用于资源备份 // ExportResources.CheckDirectory(verPath); int allLen = updateList.Count; int i = 0; Debug.LogFormat("CopyFileToSplitFolder.Count = {0}", updateList.Count); EditorUtility.DisplayProgressBar("Copy Change AssetBundle File", "copy file to " + updateOutPath + updateList.Count, 0.09f); string sourcePath; string outfilePath, outfileVerionPath; string key, extension; uint crc = 0; StringBuilder erro = new StringBuilder(); foreach (var k in updateList) { key = k.Key;//CUtils.GetAssetBundleName(k.Key); Debug.LogFormat(" update file = {0},{1},{2};", k.Key, k.Value.abName, k.Value.assetPath); sourcePath = Path.Combine(Application.dataPath, k.Value.assetPath); if (string.IsNullOrEmpty(k.Value.assetPath)) { continue; } if (!File.Exists(sourcePath)) // { string e = string.Format("copy file ({0}) not Exists ", sourcePath); Debug.LogWarning(e); erro.AppendLine(e); continue; } extension = System.IO.Path.GetExtension(key); crc = (uint)k.Value.crc32; if (crc != 0) { if (string.IsNullOrEmpty(extension)) { key = InsertAssetBundleName(key + Common.CHECK_ASSETBUNDLE_SUFFIX, "_" + crc.ToString()); } else if (extension == Common.DOT_BYTES) { key = key.Replace(extension, Common.CHECK_ASSETBUNDLE_SUFFIX); key = InsertAssetBundleName(key, "_" + crc.ToString());// } else { key = InsertAssetBundleName(key, "_" + crc.ToString());// } } outfilePath = Path.Combine(updateOutPath, key); outfileVerionPath = Path.Combine(verPath, key); // Debug.LogFormat("{0} copy to {1}", outfilePath, outfileVerionPath); // uint filelen = 0; uint copyFileCrc = 0; var resType = HugulaSetting.instance.backupResType; if (resType == CopyResType.VerResFolder) { FileHelper.CheckCreateFilePathDirectory(outfileVerionPath); File.Copy(sourcePath, outfileVerionPath, true);// copy to v{d}/res folder copyFileCrc = CrcCheck.GetLocalFileCrc(outfileVerionPath, out filelen); } if (resType == CopyResType.OneResFolder) { FileHelper.CheckCreateFilePathDirectory(outfilePath); File.Copy(sourcePath, outfilePath, true);// copy to /res folder copyFileCrc = CrcCheck.GetLocalFileCrc(outfilePath, out filelen); } //check file crc if (copyFileCrc != crc) { string e = string.Format("crc(source{0}!=copy{1}),path={2}", crc, copyFileCrc, outfilePath); Debug.LogError(e); erro.AppendLine(e); } EditorUtility.DisplayProgressBar("copy file to split folder " + updateOutPath, " copy file =>" + i.ToString() + "/" + allLen.ToString(), i / allLen); i++; } Debug.Log(" copy file complete!"); EditorUtility.ClearProgressBar(); string errContent = erro.ToString(); if (!string.IsNullOrEmpty(errContent)) { string tmpPath = BuildScript.GetAssetTmpPath(); ExportResources.CheckDirectory(tmpPath); string outPath = Path.Combine(tmpPath, "error.txt"); Debug.Log("write to path=" + outPath); using (StreamWriter sr = new StreamWriter(outPath, true)) { sr.WriteLine(" Error : " + System.DateTime.Now.ToString()); sr.Write(errContent); } } }
/// <summary> /// 1 读取首包,找出忽略文件 /// </summary> /// <param name="ignoreFiles">Ignore files.</param> public static bool ReadFirst(Dictionary <string, object[]> firstCrcDict, HashSet <string> manualFileList) { string title = "read first crc file list"; CrcCheck.Clear(); bool firstExists = false; string readPath = Path.Combine(FirstOutReleasePath, CUtils.platform); string firstFileName = CUtils.InsertAssetBundleName(CUtils.GetRightFileName(Common.CRC32_FILELIST_NAME), "_v" + CodeVersion.CODE_VERSION.ToString()); readPath = Path.Combine(readPath, firstFileName); Debug.Log(readPath); manualFileList.Clear(); //读取首包 WWW abload = new WWW("file://" + readPath); if (string.IsNullOrEmpty(abload.error) && abload.assetBundle != null) { var ab = abload.assetBundle; Object[] assets = ab.LoadAllAssets(); BytesAsset ba; foreach (Object o in assets) { ba = o as BytesAsset; if (ba != null) { byte[] bytes = ba.bytes; string context = LuaHelper.GetUTF8String(bytes); Debug.Log(context); string[] split = context.Split('\n'); System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(@"\[""(.+)""\]\s+=\s+{(\d+),(\d+)}"); float j = 1; float l = split.Length; foreach (var line in split) { System.Text.RegularExpressions.Match match = regex.Match(line); if (match.Success) { //Debug.Log(match.Groups[1].Value + " " + match.Groups[2].Value); object[] val = new object[] { System.Convert.ToUInt32(match.Groups[2].Value), System.Convert.ToUInt32(match.Groups[3].Value) }; firstCrcDict[match.Groups[1].Value] = val; } //Debug.Log(line); EditorUtility.DisplayProgressBar(title, "read first crc => " + j.ToString() + "/" + l.ToString(), j / l); j++; } firstExists = true; } } ab.Unload(true); } else { Debug.LogWarning(abload.error + "no frist packeage in " + readPath); } abload.Dispose(); //读取忽略扩展包 string firstStreamingPath = CUtils.realStreamingAssetsPath; //读取忽略扩展文件夹 DirectoryInfo dinfo = new DirectoryInfo(firstStreamingPath); var dircs = dinfo.GetDirectories(); foreach (var dir in dircs) { var u3dList = ExportResources.getAllChildFiles(dir.FullName, @"\.meta$|\.manifest$|\.DS_Store$", null, false); foreach (var s in u3dList) { string ab = CUtils.GetAssetBundleName(s); ab = ab.Replace("\\", "/"); manualFileList.Add(ab); Debug.Log("extends folder:" + ab); } } //读取忽略别名后缀 var inclusionVariants = HugulaSetting.instance.inclusionVariants; var allVariants = HugulaSetting.instance.allVariants; string pattern = ""; string sp = ""; foreach (var s in allVariants) { if (!inclusionVariants.Contains(s)) { pattern += sp + @"\." + s + "$"; sp = "|"; } } if (!string.IsNullOrEmpty(pattern)) { Debug.Log(pattern); var u3dList = ExportResources.getAllChildFiles(dinfo.FullName, pattern, null, true); foreach (var s in u3dList) { string ab = CUtils.GetAssetBundleName(s); ab = ab.Replace("\\", "/"); manualFileList.Add(ab); Debug.Log("inclusionVariants " + ab); } } var extensionFiles = HugulaExtensionFolderEditor.instance.ExtensionFiles; foreach (var s in extensionFiles) { var extName = CUtils.GetRightFileName(s); manualFileList.Add(extName); Debug.LogFormat("extensionFile:{0},md5={1}.", s, extName); } //从网络读取扩展加载列表 todo EditorUtility.ClearProgressBar(); return(firstExists); }
/// <summary> /// Creates the streaming crc list. /// </summary> /// <param name="sb">Sb.</param> public static uint CreateStreamingCrcList(StringBuilder sb, bool firstExists = false, bool copyToResFolder = false) { var crc32filename = CUtils.GetAssetName(Common.CRC32_FILELIST_NAME); string tmpPath = BuildScript.GetAssetTmpPath();// Path.Combine(Application.dataPath, BuildScript.TmpPath); ExportResources.CheckDirectory(tmpPath); string assetPath = "Assets/" + BuildScript.TmpPath + crc32filename + ".asset"; EditorUtility.DisplayProgressBar("Generate streaming crc file list", "write file to " + assetPath, 0.99f); string outTmpPath = Path.Combine(tmpPath, crc32filename + ".lua"); using (StreamWriter sr = new StreamWriter(outTmpPath, false)) { sr.Write(sb.ToString()); } // //打包到streaming path AssetDatabase.Refresh(); BytesAsset ba = ScriptableObject.CreateInstance(typeof(BytesAsset)) as BytesAsset; ba.bytes = File.ReadAllBytes(outTmpPath); AssetDatabase.CreateAsset(ba, assetPath); string crc32outfilename = CUtils.GetRightFileName(Common.CRC32_FILELIST_NAME); // Debug.Log("write to path=" + outPath); Debug.Log(sb.ToString()); //读取crc string abPath = string.Empty; string resOutPath = null; uint fileSize = 0; uint fileCrc = 0; if (copyToResFolder) { resOutPath = tmpPath;//Path.Combine(tmpPath, ResFolderName); //Path.Combine(SplitPackage.UpdateOutPath, ResFolderName); abPath = Path.Combine(resOutPath, crc32outfilename); BuildScript.BuildABs(new string[] { assetPath }, resOutPath, crc32outfilename, BuildAssetBundleOptions.DeterministicAssetBundle); fileCrc = CrcCheck.GetLocalFileCrc(abPath, out fileSize); //copy first crc list string crc32FirstOutName = CUtils.InsertAssetBundleName(crc32outfilename, "_v" + CodeVersion.CODE_VERSION.ToString()); if (!firstExists) //如果没有首包 copy first package { string destFirst = Path.Combine(UpdateOutPath, crc32FirstOutName); Debug.Log("destFirst:" + destFirst); File.Copy(abPath, destFirst, true); } //copy crc list FileInfo finfo = new FileInfo(abPath); var resType = HugulaSetting.instance.backupResType; if (resType == CopyResType.VerResFolder) { string verPath = Path.Combine(UpdateOutVersionPath, ResFolderName);//特定版本资源目录用于资源备份 string newName = Path.Combine(verPath, InsertAssetBundleName(crc32outfilename, "_" + fileCrc.ToString())); FileHelper.CheckCreateFilePathDirectory(newName); if (File.Exists(newName)) { File.Delete(newName); } finfo.CopyTo(newName); } if (resType == CopyResType.OneResFolder) { string updateOutPath = Path.Combine(UpdateOutPath, ResFolderName);//总的资源目录 string newName = Path.Combine(updateOutPath, InsertAssetBundleName(crc32outfilename, "_" + fileCrc.ToString())); FileHelper.CheckCreateFilePathDirectory(newName); if (File.Exists(newName)) { File.Delete(newName); } finfo.CopyTo(newName); } } else { abPath = Path.Combine(CUtils.realStreamingAssetsPath, crc32outfilename); BuildScript.BuildABs(new string[] { assetPath }, null, crc32outfilename, BuildAssetBundleOptions.DeterministicAssetBundle); fileCrc = CrcCheck.GetLocalFileCrc(abPath, out fileSize); } CrcCheck.Clear(); EditorUtility.ClearProgressBar(); Debug.Log("Crc file list assetbunle build complate! " + fileCrc.ToString() + abPath); return(fileCrc); }