Exemplo n.º 1
0
        public virtual bool LoadFromStream(Stream stream)
        {
            FStyle.States.Include(HCState.hosLoading);
            try
            {
                stream.Position = 0;
                LoadSectionProcHandler vEvent = delegate(ushort aFileVersion)
                {
                    byte vByte = 0;
                    vByte = (byte)stream.ReadByte();  // 节数量
                    // 各节数据
                    FSections[0].LoadFromStream(stream, FStyle, aFileVersion);
                    for (int i = 1; i <= vByte - 1; i++)
                    {
                        HCSection vSection = NewDefaultSection();
                        vSection.LoadFromStream(stream, FStyle, aFileVersion);
                        FSections.Add(vSection);
                    }
                };

                DoLoadFromStream(stream, FStyle, vEvent);
            }
            finally
            {
                FStyle.States.Exclude(HCState.hosLoading);
            }

            return(true);
        }
Exemplo n.º 2
0
        private void DoLoadFromStream(Stream stream, HCStyle style, LoadSectionProcHandler loadSectionProc)
        {
            stream.Position = 0;
            string vFileExt     = "";
            ushort vFileVersion = 0;
            byte   vLang        = 0;

            HC._LoadFileFormatAndVersion(stream, ref vFileExt, ref vFileVersion, ref vLang);
            if (vFileExt != HC.HC_EXT)
            {
                throw new Exception("加载失败,不是" + HC.HC_EXT + "文件!");
            }

            if (vFileVersion > HC.HC_FileVersionInt)
            {
                throw new Exception("加载失败,当前编辑器最高支持版本为"
                                    + HC.HC_FileVersionInt.ToString() + "的文件,无法打开版本为" + vFileVersion.ToString() + "的文件!");
            }

            DoLoadStreamBefor(stream, vFileVersion);    // 触发加载前事件
            style.LoadFromStream(stream, vFileVersion); // 加载样式表
            loadSectionProc(vFileVersion);              // 加载节数量、节数据
            DoLoadStreamAfter(stream, vFileVersion);
        }