Beispiel #1
0
        /// <summary>
        /// 本地文件crc强制校验,
        ///
        /// 1 如果校验列表没值不通过。
        /// 1 文件不存在不通过。
        /// 1 校验列表值为0通过。
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public static bool CheckLocalFileCrc(string path, out uint fileCrc)
        {
            fileCrc = 0;
            if (path.StartsWith(Common.HTTP_STRING))
            {
                return(true);
            }

            string crcKey    = CUtils.GetAssetBundleName(path);
            bool   ck        = false;
            uint   sourceCrc = 0;

            if (crc32Dic.TryGetValue(crcKey, out sourceCrc)) //存在校验值
            {
                if (sourceCrc == 0)                          //原始为0表示不校验
                {
                    if (path.StartsWith(Application.persistentDataPath) && !File.Exists(path))
                    {
                        ck = false;
                    }
                    else
                    {
                        ck = true;
                    }
                }
                else
                {
                    string key = CUtils.GetUDKey(path);
                    uint   checkedCrc;
                    if (crcFileChecked.TryGetValue(key, out checkedCrc) && checkedCrc != 0) //如果存在
                    {
                        fileCrc = checkedCrc;
                    }
                    else
                    {
                        uint fileSize = 0;
                        fileCrc             = GetLocalFileCrc(path, out fileSize); //读取文件crc
                        crcFileChecked[key] = fileCrc;                             //保存文件crc
                        HashSet <string> checkMap = null;
                        if (crcKeyCheckedFileMap.TryGetValue(crcKey, out checkMap))
                        {
                            checkMap.Add(key);
                        }
                        else
                        {
                            checkMap = new HashSet <string>();
                            checkMap.Add(key);
                            crcKeyCheckedFileMap.Add(crcKey, checkMap);
                        }
                    }
                    ck = sourceCrc == fileCrc;//校验
                }
                //Debug.LogWarning(string.Format("sourceCrc{0},filecrc{1},ck{2},path{3},crcKey{4}", sourceCrc, fileCrc, ck, path, crcKey));
            }
            else
            {
                ck = false;
            }
            return(ck);
        }
Beispiel #2
0
        /// <summary>
        /// 文件crc
        /// 1 如果校验列表没值并且文件存在返回false
        /// 2 如果校验列表没值并且文件不存在返回true
        /// </summary>
        /// <param name="path"></param>
        /// <param name="fileCrc"></param>
        /// <returns></returns>
        public static bool CheckLocalFileWeakCrc(string path, out uint fileCrc)
        {
            string crcKey    = CUtils.GetAssetBundleName(path);
            bool   ck        = false;
            uint   sourceCrc = 0;

            fileCrc = GetLocalFileCrc(path);                 //读取文件crc

            if (crc32Dic.TryGetValue(crcKey, out sourceCrc)) //存在校验值
            {
                ck = sourceCrc == fileCrc;                   //校验
            }
            else
            {
                ck = fileCrc == 0;
            }
            return(ck);
        }
Beispiel #3
0
        /// <summary>
        /// Builds the asset bundles update A.
        /// </summary>
        public static void buildAssetBundlesUpdateAB()
        {
            EditorUtility.DisplayProgressBar("Generate FileList", "loading bundle manifest", 1 / 2);
            AssetDatabase.Refresh();
            string readPath = BuildScript.GetFileStreamingOutAssetsPath();//+"\\";
            var    u3dList  = getAllChildFiles(readPath, @"\.meta$|\.manifest$|\.DS_Store$", null, false);

            Debug.Log("all ab count = " + u3dList.Count);
            List <string> assets = new List <string>();

            foreach (var s in u3dList)
            {
                string ab = CUtils.GetAssetBundleName(s); //s.Replace(readPath, "").Replace("/", "").Replace("\\", "");
                //            Debug.Log(ab);
                assets.Add(ab);
            }

            EditorUtility.ClearProgressBar();
            BuildScript.GenerateAssetBundlesUpdateFile(assets.ToArray());
        }
Beispiel #4
0
    public void CUtilsGetAssetBundleName()
    {
        string url, name;

        url  = "extends/ex_ui_bottom.u3d?adsdf=sdfdfa&dafsd"; //lastFileIndex23,lastDotIndex20,lastQueIndex0
        name = CUtils.GetAssetBundleName(url);
        Debug.Log(".............." + name);
        Assert.AreEqual(name, "extends/ex_ui_bottom.u3d");

        url  = CUtils.GetRealStreamingAssetsPath() + "/extends/ex_ui_bottom?as=1d2%dfd3";
        name = CUtils.GetAssetBundleName(url);
        Debug.Log(".............." + name);
        Assert.AreEqual(name, "extends/ex_ui_bottom");

        url  = "ex_ui_bottom.u3d?as=1d2%dfd3";
        name = CUtils.GetAssetBundleName(url);
        Debug.Log(".............." + name);
        Assert.AreNotEqual(name, url);

        url  = "ex_ui_bottom";
        name = CUtils.GetAssetBundleName(url);
        Debug.Log(".............." + name);
        Assert.AreEqual(name, "ex_ui_bottom");

        url  = CUtils.GetRealStreamingAssetsPath() + "/ex_ui_bottom.u3d";
        name = CUtils.GetAssetBundleName(url);
        Debug.Log(".............." + name);
        Assert.AreEqual(name, "ex_ui_bottom.u3d");

        url  = CUtils.platform;
        name = CUtils.GetAssetBundleName(url);
        Debug.Log(".............." + name);
        Assert.AreEqual(name, url);

        url  = CUtils.GetRealStreamingAssetsPath() + "/" + CUtils.platform;
        name = CUtils.GetAssetBundleName(url);
        Debug.Log(".............." + name);
        Assert.AreEqual(name, CUtils.platform);
    }
Beispiel #5
0
        /// <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);
        }
Beispiel #6
0
        /// <summary>
        /// 本地文件crc强制校验,
        ///
        /// 1 如果校验列表没值不通过。
        /// 1 文件不存在不通过。
        /// 1 校验列表值为0通过。
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public static bool CheckLocalFileCrc(string path, out uint fileCrc)
        {
            fileCrc = 0;
            if (path.StartsWith(Common.HTTP_STRING))
            {
                return(true);
            }

            string crcKey    = CUtils.GetAssetBundleName(path);
            bool   ck        = false;
            uint   sourceCrc = 0;
            bool   fromcache = false;

            if (crc32Dic.TryGetValue(crcKey, out sourceCrc)) //存在校验值
            {
                if (sourceCrc == 0)                          //原始为0表示不校验
                {
                    if (path.StartsWith(Application.persistentDataPath) && !File.Exists(path))
                    {
                        ck = false;
                    }
                    else
                    {
                        ck = true;
                    }
                }
                else
                {
                    string key = CUtils.GetUDKey(path);
                    uint   checkedCrc;
                    if (crcFileChecked.TryGetValue(key, out checkedCrc) && checkedCrc != 0) //如果存在
                    {
                        fileCrc   = checkedCrc;
                        fromcache = true;
                    }
                    else
                    {
                        uint fileSize = 0;
                        fileCrc             = GetLocalFileCrc(path, out fileSize); //读取文件crc
                        crcFileChecked[key] = fileCrc;                             //保存文件crc
                    }
                    ck = sourceCrc == fileCrc;                                     //校验
                }
#if HUGULA_LOADER_DEBUG
                if (ck)
                {
                    Debug.LogFormat(" 0.0. crc <color=#00ff00>sourceCrc({0}==filecrc{1}),return {2},path{3},crcKey{4},from cache={5}</color>", sourceCrc, fileCrc, ck, path, crcKey, fromcache);
                }
                else
                {
                    Debug.LogFormat(" 0.0. crc <color=#ffff00>sourceCrc({0}!=filecrc{1}),return {2},path{3},crcKey{4}from cache={5}</color>", sourceCrc, fileCrc, ck, path, crcKey, fromcache);
                }
#endif
            }
            else if (!beginCheck)
            {
                if (path.StartsWith(Application.persistentDataPath) && !File.Exists(path))
                {
                    ck = false;
                }
                else
                {
                    ck = true;
                }
            }
            else
            {
                ck = false;
            }
            return(ck);
        }
Beispiel #7
0
        /// <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);
        }
Beispiel #8
0
        public static void GenerateAssetBundlesMd5Mapping(string[] allAssets)
        {
            string info = "Generate AssetBundles Md5Mapping ";

            EditorUtility.DisplayProgressBar("GenerateAssetBundlesMd5Mapping", info, 0);
            AssetImporter import  = null;
            float         i       = 0;
            float         allLen  = allAssets.Length;
            string        name    = "";
            string        nameMd5 = "";
            StringBuilder sb      = new StringBuilder();

            sb.AppendLine("return {");
            foreach (string path in allAssets)
            {
                import = AssetImporter.GetAtPath(path);
                if (import != null && string.IsNullOrEmpty(import.assetBundleName) == false)
                {
                    Object s = AssetDatabase.LoadAssetAtPath(path, typeof(Object));
                    name = s.name.ToLower();

                    string line = string.Empty;
                    if (string.IsNullOrEmpty(import.assetBundleVariant))
                    {
                        line = "[\"" + import.assetBundleName + "\"] = { name = \"" + name + "\", path = \"" + path + "\"},";
                    }
                    else
                    {
                        line = "[\"" + import.assetBundleName + "." + import.assetBundleVariant + "\"] = { name = \"" + name + "\", path = \"" + path + "\"},";
                    }

                    sb.AppendLine(line);
                    if (name.Contains(" "))
                    {
                        Debug.LogWarning(name + " contains space");
                    }
                }
                else
                {
                    //Debug.LogWarning(path + " import not exist");
                }
                EditorUtility.DisplayProgressBar("Generate AssetBundles Md5Mapping", info + "=>" + i.ToString() + "/" + allLen.ToString(), i / allLen);

                i++;
            }

            string[] spceil = new string[] { CUtils.platform, Common.CONFIG_CSV_NAME, Common.CRC32_FILELIST_NAME, Common.CRC32_VER_FILENAME };
            foreach (string p in spceil)
            {
                name    = CUtils.GetAssetBundleName(p);
                nameMd5 = CUtils.GetRightFileName(name);
                string line = "[\"" + nameMd5 + "\"] ={ name = \"" + name + "\", path = \"" + p + "\" },";
                sb.AppendLine(line);
            }

            sb.AppendLine("}");
            string tmpPath = Path.Combine(Application.dataPath, TmpPath);

            ExportResources.CheckDirectory(tmpPath);
            EditorUtility.DisplayProgressBar("Generate AssetBundles Md5Mapping", "write file to Assets/" + TmpPath + "Md5Mapping.txt", 0.99f);

            string outPath = Path.Combine(tmpPath, "md5mapping.txt");

            Debug.Log("write to path=" + outPath);
            using (StreamWriter sr = new StreamWriter(outPath, false))
            {
                sr.Write(sb.ToString());
            }

            EditorUtility.ClearProgressBar();
            Debug.Log(info + " Complete! Assets/" + TmpPath + "md5mapping.txt");
        }
Beispiel #9
0
        /// <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();
                }
            }
        }
Beispiel #10
0
        /// <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);
        }
Beispiel #11
0
    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();
    }
Beispiel #12
0
        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);
        }
Beispiel #13
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, 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);
        }
Beispiel #14
0
    /// <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);
    }