getAllChildFiles() 공개 정적인 메소드

public static getAllChildFiles ( string path, string suffix = "lua", List files = null, bool isMatch = true ) : List
path string
suffix string
files List
isMatch bool
리턴 List
예제 #1
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);
        }
예제 #2
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);
        }
예제 #3
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);
        }