Example #1
0
        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);
                }
            }
        }
Example #2
0
        /// <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, object[]> firstCrcDict, Dictionary <string, object[]> currCrcDict, Dictionary <string, object[]> 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;
            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.CHECK_ASSETBUNDLE_SUFFIX))
                {
                    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, white0, black0, other0, whiteFileList, blackFileList);
                    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, 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);
        }
Example #3
0
        /// <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);
        }
Example #4
0
        /// <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       = EditorUtils.GetAssetTmpPath();// Path.Combine(Application.dataPath, BuildScript.TmpPath);

            EditorUtils.CheckDirectory(tmpPath);

            string assetPath = "Assets/" + EditorUtils.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, EditorUtils.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, EditorUtils.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);
        }