示例#1
0
        /// <summary>
        /// 加载模板
        /// 依赖于FileCache和父节点的FileCache
        /// </summary>
        protected void LoadTemplates()
        {
            if (templateMgr != null)
            {
                Logger.Warning("templateMgr is already loaded. ignored.");
                return;
            }

            templateMgr = new TemplateManager();
            templateMgr.CopyRegisteredFuncs(App.TemplateMgr);

            // load parent mod templates first
            Mod        curMod = this;
            List <Mod> stack  = new List <Mod>();

            while (curMod != null)
            {
                stack.Add(curMod);
                curMod = curMod.parent;
            }

            for (int i = stack.Count - 1; i >= 0; --i)
            {
                // fileCache
                var enumer = stack[i].fileCache.GetEnumerator();
                while (enumer.MoveNext())
                {
                    // 不加载根目录
                    string dir = Path.GetDirectoryName(enumer.Current.Key.Str);
                    if (dir == null || dir == "")
                    {
                        continue;
                    }

                    if (enumer.Current.Key.Str.EndsWith(".bytes", StringComparison.Ordinal))
                    {
                        byte[] bytes = util.File.LoadBin(new FileLoc(enumer.Current.Value, stack[i].ModPath), App.Language, enumer.Current.Key.Str);
                        templateMgr.LoadTemplates(bytes);
                    }
                }

                // language fileCache
                var enumer2 = stack[i].langFileCache.GetEnumerator();
                while (enumer2.MoveNext())
                {
                    if (enumer2.Current.Key.Str.EndsWith(".bytes", StringComparison.Ordinal))
                    {
                        byte[] bytes = util.File.LoadBin(new FileLoc(enumer2.Current.Value, stack[i].ModPath), App.Language, enumer2.Current.Key.Str);
                        templateMgr.LoadTemplates(bytes);
                    }
                }
            }

            templateMgr.LoadFinished();
        }