コード例 #1
0
ファイル: SplitPackage.cs プロジェクト: pengjugame/hugula
        /// <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);
        }
コード例 #2
0
ファイル: SplitPackage.cs プロジェクト: zuojiashun/hugula
        /// <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);
        }