Beispiel #1
0
        MetaClass CreateMetaClass(System.Type type)
        {
            var cname = RttiHelper.GetTypeSaveString(type);

            var klass = new MetaClass();

            klass.MetaType = type;
            var csIdx    = cname.IndexOf('|');
            var fileName = cname;

            if (csIdx >= 0)
            {
                fileName = cname.Substring(csIdx + 1);
            }
            klass.ClassName = RName.GetRName(MetaDirectory.Name + "/" + fileName);

            MetaData curVer = new MetaData();

            curVer.BuildMetaData(type);

            Hash64 hash = klass.GetFolderHash();
            string dir  = klass.ClassName.GetDirectory() + hash.ToString();

            if (EngineNS.CEngine.Instance.FileManager.DirectoryExists(dir))
            {
                bool hasRedirection = false;
                klass.LoadXnd(out hasRedirection);
#if PWindow
                //if (hasRedirection)
                //    klass.Save2Xnd(false);
#endif
                MetaData data = klass.FindMetaData(curVer.MetaHash);
                if (data == null)
                {
                    klass.RegMetaData(curVer.MetaHash, curVer);
                    var xnd = IO.XndHolder.NewXNDHolder();
                    curVer.Save2Xnd(xnd.Node);
                    IO.XndHolder.SaveXND(dir + "/" + curVer.MetaHash + ".MetaData", xnd);
                }
            }
            else
            {
                CEngine.Instance.FileManager.CreateDirectory(dir);

                var sw = new System.IO.StreamWriter(dir + "/typename.txt", false);
                sw.WriteLine(cname);
                sw.Close();

                klass.RegMetaData(curVer.MetaHash, curVer);
                var xnd = IO.XndHolder.NewXNDHolder();
                curVer.Save2Xnd(xnd.Node);
                IO.XndHolder.SaveXND(dir + "/" + curVer.MetaHash + ".MetaData", xnd);
            }

            klass.CurrentVersion = curVer;
            Klasses.Add(cname, klass);

            return(klass);
        }
Beispiel #2
0
        public void LoadMetaClasses()
        {
            var t1   = Support.Time.HighPrecision_GetTickCount();
            var dirs = CEngine.Instance.FileManager.GetDirectories(MetaDirectory.Address);

            if (dirs == null)
            {
                Profiler.Log.WriteLine(Profiler.ELogTag.Error, "MetaData", $"MetaDirectory.Address is null:{MetaDirectory.Address}");
                return;
            }
            foreach (var i in dirs)
            {
                if (false == CEngine.Instance.FileManager.FileExists(i + "/typename.txt"))
                {
                    continue;
                }

                //System.IO.StreamReader sr = new System.IO.StreamReader(i + "/typename.txt", System.Text.Encoding.ASCII);
                //string className = sr.ReadLine();
                //sr.Close();

                byte[] bytes     = IO.FileManager.ReadFile(i + "/typename.txt");
                string className = System.Text.Encoding.ASCII.GetString(bytes);
                className = className.Replace("\r\n", "");

                ///////////////////////////////////////////////////////////////////
                //if (className.Contains("enginecore"))
                //{
                //    using (var sw = new System.IO.StreamWriter(i + "/typename.txt", false, System.Text.Encoding.ASCII))
                //    {
                //        className = className.Replace("enginecore", "EngineCore");
                //        sw.WriteLine(className);
                //    }
                //}
                //if (className.Contains("Common|EngineCore"))
                //{
                //    using (var sw = new System.IO.StreamWriter(i + "/typename.txt", false, System.Text.Encoding.ASCII))
                //    {
                //        className = className.Replace("Common|EngineCore", "Client|EngineCore");
                //        sw.WriteLine(className);
                //    }
                //}
                ///////////////////////////////////////////////////////////////////
                bool isRedirection;
                var  type = RttiHelper.GetTypeFromSaveString(className, out isRedirection);
                if (type == null)
                {
                    continue;
                }

                if (CIPlatform.Instance.PlayMode != CIPlatform.enPlayMode.Game)
                {
                    var noUsedFile = i + "/" + type.FullName + ".noused";
                    if (CEngine.Instance.FileManager.FileExists(noUsedFile) == false)
                    {
                        CEngine.Instance.FileManager.CreateFile(noUsedFile);
                    }
                }

                MetaClass klass = new MetaClass();
                klass.MetaType = type;
                var csIdx   = className.IndexOf('|');
                var fileStr = className;
                if (csIdx >= 0)
                {
                    fileStr = className.Substring(csIdx + 1);
                }
                klass.ClassName = RName.GetRName(MetaDirectory.Name + "/" + fileStr);
                bool hasRedirection = false;
                klass.LoadXnd(out hasRedirection);
#if PWindow
                //if (hasRedirection)
                //    klass.Save2Xnd(false);
#endif

                // 重定向后由于原来的类型已不存在,不再进行当前版本的处理
                if (!isRedirection)
                {
                    MetaData curVer = new MetaData();
                    curVer.BuildMetaData(type);

                    MetaData data = klass.FindMetaData(curVer.MetaHash);
                    if (data == null)
                    {
                        klass.RegMetaData(curVer.MetaHash, curVer);

#if PWindow
                        var xnd = IO.XndHolder.NewXNDHolder();
                        curVer.Save2Xnd(xnd.Node);
                        var hash = klass.GetFolderHash();
                        var file = klass.ClassName.GetRootFolder() + "MetaClasses/" + hash.ToString() + "/" + curVer.MetaHash + ".MetaData";
                        IO.XndHolder.SaveXND(file, xnd);
                        klass.CurrentVersion = curVer;
#endif
                    }
                    else
                    {
                        klass.CurrentVersion = data;
                    }
                }

                Klasses.Add(className, klass);
            }

            var t2 = Support.Time.HighPrecision_GetTickCount();
            Profiler.Log.WriteLine(Profiler.ELogTag.Info, "MetaData", $"LoadMetaClasses Time:{t2-t1}");
            //MetaDatas.Clear();
            //foreach (var i in Klasses)
            //{
            //    foreach (var j in i.Value.Metas)
            //    {
            //        MetaDatas.Add(j.Key, j.Value);
            //    }
            //}
        }