private static Dictionary <string, Dictionary <string, FontReplacement> > GetFontReplacementDMFDict(string fname)
        {
            // dist -> mod -> FontReplacement
            Dictionary <string, Dictionary <string, FontReplacement> > dmfr = new Dictionary <string, Dictionary <string, FontReplacement> >();
            List <FontReplacement> list;

            if (_FontReplacements.TryGetValue(fname, out list))
            {
                for (int i = 0; i < list.Count; ++i)
                {
                    var info = list[i];
                    var mod  = info.Mod ?? "";
                    var dist = info.Dist ?? "";
                    // check critical mod
                    var  moddesc       = ResManager.GetDistributeDesc(mod);
                    var  inPackage     = (info.DescAssetPath ?? "").StartsWith("Packages/");
                    bool isMainPackage = inPackage && !CapsModEditor.ShouldTreatPackageAsMod(CapsModEditor.GetPackageName(mod));
                    if (moddesc == null || !moddesc.IsOptional || isMainPackage)
                    {
                        mod = "";
                    }

                    Dictionary <string, FontReplacement> mdict;
                    if (!dmfr.TryGetValue(dist, out mdict))
                    {
                        mdict      = new Dictionary <string, FontReplacement>();
                        dmfr[dist] = mdict;
                    }
                    mdict[mod] = info;
                }
            }
            return(dmfr);
        }
        public static IEnumerator GenerateBuildWorkAsync(Dictionary <string, CapsResBuildWork> result, IList <string> assets, IEditorWorkProgressShower winprog, IList <IResBuilderEx> runOnceExBuilder)
        {
            var logger = new EditorWorkProgressLogger()
            {
                Shower = winprog
            };

            logger.Log("(Start) Generate Build Work.");
            if (winprog != null && AsyncWorkTimer.Check())
            {
                yield return(null);
            }

            if (result == null)
            {
                logger.Log("(Error) You have to provide container to retrive the result.");
                yield break;
            }
            result.Clear();

            if (assets == null)
            {
                logger.Log("(Option) Get All Assets.");
                assets = AssetDatabase.GetAllAssetPaths();
                if (winprog != null && AsyncWorkTimer.Check())
                {
                    yield return(null);
                }
            }

            if (assets != null)
            {
                List <IResBuilderEx> allExBuilders = new List <IResBuilderEx>(ResBuilderEx);
                if (runOnceExBuilder != null)
                {
                    allExBuilders.AddRange(runOnceExBuilder);
                }

                Dictionary <string, Dictionary <string, List <string> > >  mod2build = new Dictionary <string, Dictionary <string, List <string> > >();
                Dictionary <string, Dictionary <string, CapsResManifest> > mod2mani  = new Dictionary <string, Dictionary <string, CapsResManifest> >();
                for (int i = 0; i < assets.Count; ++i)
                {
                    if (winprog != null && AsyncWorkTimer.Check())
                    {
                        yield return(null);
                    }
                    var asset = assets[i];
                    logger.Log(asset);

                    if (string.IsNullOrEmpty(asset))
                    {
                        logger.Log("Empty Path.");
                        continue;
                    }
                    if (System.IO.Directory.Exists(asset))
                    {
                        logger.Log("Folder.");
                        continue;
                    }
                    if (CapsResInfoEditor.IsAssetScript(asset))
                    {
                        logger.Log("Script.");
                        continue;
                    }

                    string mod       = null;
                    string opmod     = null;
                    string dist      = null;
                    string norm      = asset;
                    bool   inPackage = false;
                    if (asset.StartsWith("Assets/Mods/") || (inPackage = asset.StartsWith("Packages/")))
                    {
                        string sub;
                        if (inPackage)
                        {
                            sub = asset.Substring("Packages/".Length);
                        }
                        else
                        {
                            sub = asset.Substring("Assets/Mods/".Length);
                        }
                        var index = sub.IndexOf('/');
                        if (index < 0)
                        {
                            logger.Log("Cannot Parse Module.");
                            continue;
                        }
                        mod = sub.Substring(0, index);
                        if (inPackage)
                        {
                            mod = CapsModEditor.GetPackageModName(mod);
                        }
                        if (string.IsNullOrEmpty(mod))
                        {
                            logger.Log("Empty Module.");
                            continue;
                        }
                        sub = sub.Substring(index + 1);
                        if (!sub.StartsWith("CapsRes/"))
                        {
                            logger.Log("Should Ignore This Asset.");
                            continue;
                        }
                        var  moddesc       = ResManager.GetDistributeDesc(mod);
                        bool isMainPackage = inPackage && !CapsModEditor.ShouldTreatPackageAsMod(CapsModEditor.GetPackageName(mod));
                        if (moddesc == null || moddesc.InMain || isMainPackage)
                        {
                            mod = "";
                            if (moddesc != null && moddesc.IsOptional && !isMainPackage)
                            {
                                opmod = moddesc.Mod;
                            }
                        }

                        sub  = sub.Substring("CapsRes/".Length);
                        norm = sub;
                        if (sub.StartsWith("dist/"))
                        {
                            sub   = sub.Substring("dist/".Length);
                            index = sub.IndexOf('/');
                            if (index > 0)
                            {
                                dist = sub.Substring(0, index);
                                norm = sub.Substring(index + 1);
                            }
                        }
                    }
                    else
                    {
                        if (asset.StartsWith("Assets/CapsRes/"))
                        {
                            mod = "";
                            var sub = asset.Substring("Assets/CapsRes/".Length);
                            norm = sub;
                            if (sub.StartsWith("dist/"))
                            {
                                sub = sub.Substring("dist/".Length);
                                var index = sub.IndexOf('/');
                                if (index > 0)
                                {
                                    dist = sub.Substring(0, index);
                                    norm = sub.Substring(index + 1);
                                }
                            }
                        }
                        else
                        {
                            logger.Log("Should Ignore This Asset.");
                            continue;
                        }
                    }

                    if (string.IsNullOrEmpty(norm))
                    {
                        logger.Log("Normallized Path Empty.");
                        continue;
                    }
                    mod  = mod ?? "";
                    dist = dist ?? "";
                    logger.Log("Mod " + mod + "; Dist " + dist + "; Norm " + norm);

                    Dictionary <string, List <string> > builds;
                    if (!mod2build.TryGetValue(mod, out builds))
                    {
                        builds         = new Dictionary <string, List <string> >();
                        mod2build[mod] = builds;
                    }

                    Dictionary <string, CapsResManifest> manis;
                    if (!mod2mani.TryGetValue(opmod ?? mod, out manis))
                    {
                        manis = new Dictionary <string, CapsResManifest>();
                        mod2mani[opmod ?? mod] = manis;
                    }
                    CapsResManifest mani;
                    if (!manis.TryGetValue(dist, out mani))
                    {
                        mani       = new CapsResManifest();
                        mani.MFlag = opmod ?? mod;
                        mani.DFlag = dist;
                        if (opmod != null)
                        {
                            mani.InMain = true;
                        }
                        manis[dist] = mani;
                    }

                    string bundle          = null;
                    bool   shouldWriteBRef = false;
                    for (int j = 0; j < allExBuilders.Count; ++j)
                    {
                        bundle = allExBuilders[j].FormatBundleName(asset, opmod ?? mod, dist, norm);
                        if (bundle != null)
                        {
                            break;
                        }
                    }
                    if (bundle == null)
                    {
                        bundle = FormatBundleName(asset, opmod ?? mod, dist, norm);
                    }
                    else
                    {
                        shouldWriteBRef = true;
                    }

                    List <string> build;
                    if (!builds.TryGetValue(bundle, out build))
                    {
                        build          = new List <string>();
                        builds[bundle] = build;
                    }
                    build.Add(asset);

                    var node = mani.AddOrGetItem(asset);
                    for (int j = 0; j < allExBuilders.Count; ++j)
                    {
                        if (allExBuilders[j].CreateItem(node))
                        {
                            break;
                        }
                    }
                    if (node.Item == null)
                    {
                        var item = new CapsResManifestItem(node);
                        if (asset.EndsWith(".prefab"))
                        {
                            item.Type = (int)CapsResManifestItemType.Prefab;
                        }
                        else if (asset.EndsWith(".unity"))
                        {
                            item.Type = (int)CapsResManifestItemType.Scene;
                        }
                        else
                        {
                            item.Type = (int)CapsResManifestItemType.Normal;
                        }
                        if (shouldWriteBRef)
                        {
                            item.BRef = bundle;
                        }
                        node.Item = item;
                    }
                    for (int j = 0; j < allExBuilders.Count; ++j)
                    {
                        allExBuilders[j].ModifyItem(node.Item);
                    }
                }

                if (winprog != null && AsyncWorkTimer.Check())
                {
                    yield return(null);
                }
                logger.Log("(Phase) Combine the final result.");

                foreach (var kvpbuild in mod2build)
                {
                    var mod               = kvpbuild.Key;
                    var builds            = kvpbuild.Value;
                    CapsResBuildWork work = new CapsResBuildWork();
                    if (mod == "")
                    {
                        List <CapsResManifest> manis = new List <CapsResManifest>(mod2mani[mod].Values);
                        foreach (var kvpmm in mod2mani)
                        {
                            if (!mod2build.ContainsKey(kvpmm.Key))
                            {
                                manis.AddRange(kvpmm.Value.Values);
                            }
                        }
                        work.Manifests = manis.ToArray();
                    }
                    else
                    {
                        work.Manifests = mod2mani[mod].Values.ToArray();
                    }

                    work.ABs = new AssetBundleBuild[builds.Count];
                    int index = 0;
                    foreach (var kvpbundle in builds)
                    {
                        var bundleName         = kvpbundle.Key;
                        var bundleAssets       = kvpbundle.Value;
                        AssetBundleBuild build = new AssetBundleBuild();
                        build.assetBundleName = kvpbundle.Key;
                        build.assetNames      = kvpbundle.Value.ToArray();
                        for (int j = 0; j < allExBuilders.Count; ++j)
                        {
                            allExBuilders[j].GenerateBuildWork(bundleName, bundleAssets, ref build, work, index);
                        }
                        work.ABs[index++] = build;
                    }

                    result[mod] = work;
                }
            }

            logger.Log("(Done) Generate Build Work.");
        }