示例#1
0
        private uint LoadPackage(string Filename)
        {
            string PackagePath = Path.GetDirectoryName(Filename);

            ConfigFile PackageConfig = m_ConfigEngine.LoadFile(Filename);

            ConfigElement[] PackageElements = PackageConfig["package"];

            Console.WriteLine("  [{0}] : {1}", PackageElements[0].GetString("id"), PackageElements[0].GetString("name"));
            Console.WriteLine("  - Path: {0}", PackagePath);
            Console.WriteLine();

            ConfigElement[] FileGroups = PackageElements[0].GetSubElements("files");
            if (FileGroups.Length > 0)
            {
                ConfigElement[] PackageFiles = FileGroups[0].GetSubElements("file");
                foreach (ConfigElement PackageFile in PackageFiles)
                {
                    string PackageFilename = PackageFile.GetString("file_Column");
                    string PackageFilePath = Path.Combine(PackagePath, PackageFilename);

                    if (!m_Filenames.Contains(PackageFilePath))
                    {
                        m_Filenames.Add(PackageFilePath);
                    }
                    else
                    {
                        Console.WriteLine("   Note: File \"{0}\" has already been declared in a previous package.", PackageFilePath);
                    }
                }

                return((uint)PackageFiles.Length);
            }

            return(0);
        }
        internal void AddConfig(string Filename)
        {
            ConfigFile ConfigFile = m_Engine.LoadFile(Filename);

            AddConfig(ConfigFile);
        }
示例#3
0
        private void LoadDataFromDBC(string Filename)
        {
            FileInfo DBCInfo = new FileInfo(Filename);

            ConfigFile    DBCLayout     = m_Engine.LoadFile(@"data\dbc_layouts.xml");
            ConfigElement LayoutElement = DBCLayout["layout", DBCInfo.Name];

            if (LayoutElement == null)
            {
                return;
            }

            DataTable DBCTable = m_Data.Tables["data"];

            if (DBCTable == null)
            {
                DBCTable = m_Data.Tables.Add("data");
            }

            DBCTable.BeginLoadData();

            #region Construct Columns

            string          LayoutID       = LayoutElement.GetString("id");
            ConfigElement[] ColumnElements = DBCLayout["column", "id", LayoutID];

            DataColumn PrimaryColumn = null;
            foreach (ConfigElement ColumnElement in ColumnElements)
            {
                Type   ColumnType = typeof(uint);
                string TypeName   = ColumnElement.GetString("type");

                if (TypeName != null)
                {
                    ColumnType = Type.GetType("System." + TypeName, false, true);
                    if (ColumnType == null)
                    {
                        throw new Exception("InvalidTypeException");
                    }
                }

                DataColumn CurrentColumn = DBCTable.Columns.Add(ColumnElement.GetString("name").ToLower(), ColumnType);
                if (ColumnElement.GetBoolean("primarykey"))
                {
                    PrimaryColumn = CurrentColumn;
                }
            }

            if (PrimaryColumn != null)
            {
                DBCTable.PrimaryKey = new DataColumn[1] {
                    PrimaryColumn
                };
            }

            #endregion
            #region Load DBC

            BinaryReader DBCReader = new BinaryReader(File.OpenRead(Filename));
            DBCHeader    Header    = new DBCHeader(DBCReader);

            long   StringTablePos = (Header.RowSize * Header.RowCount) + 20;
            byte[] Buffer         = new byte[Header.RowSize];

            #region Read each Row

            for (int i = 0; i <= Header.RowCount - 1; i++)
            {
                DataRow DBCRow = DBCTable.NewRow();

                DBCReader.Read(Buffer, 0, (int)Header.RowSize);
                long NextRowPosition = DBCReader.BaseStream.Position;

                BinaryReader RowReader = new BinaryReader(new MemoryStream(Buffer));

                foreach (ConfigElement ColumnElement in ColumnElements)
                {
                    string ColumnName = ColumnElement.GetString("name");
                    if (ColumnElement.Exists("position"))
                    {
                        RowReader.BaseStream.Seek((long)ColumnElement.GetUInt64("position"), SeekOrigin.Begin);
                    }

                    Type   ColumnType = typeof(uint);
                    string TypeName   = ColumnElement.GetString("type");

                    if (TypeName != null)
                    {
                        switch (TypeName.ToLower())
                        {
                            #region Type Read Cases
                        case "sbyte":
                            DBCRow[ColumnName] = RowReader.ReadSByte();
                            break;

                        case "byte":
                            DBCRow[ColumnName] = RowReader.ReadByte();
                            break;

                        case "short":
                            DBCRow[ColumnName] = RowReader.ReadInt16();
                            break;

                        case "ushort":
                            DBCRow[ColumnName] = RowReader.ReadUInt16();
                            break;

                        case "int":
                            DBCRow[ColumnName] = RowReader.ReadInt32();
                            break;

                        case "uint":
                            DBCRow[ColumnName] = RowReader.ReadUInt32();
                            break;

                        case "long":
                            DBCRow[ColumnName] = RowReader.ReadInt64();
                            break;

                        case "ulong":
                            DBCRow[ColumnName] = RowReader.ReadUInt64();
                            break;

                        case "float":
                            DBCRow[ColumnName] = RowReader.ReadSingle();
                            break;

                        case "double":
                            DBCRow[ColumnName] = RowReader.ReadDouble();
                            break;

                        case "string":
                            uint StringPos = RowReader.ReadUInt32();
                            DBCReader.BaseStream.Seek(StringTablePos + StringPos, SeekOrigin.Begin);

                            DBCRow[ColumnName] = Utilities.ReadString(DBCReader);

                            DBCReader.BaseStream.Seek(NextRowPosition, SeekOrigin.Begin);
                            break;
                            #endregion
                        }
                    }
                    else
                    {
                        DBCRow[ColumnName] = RowReader.ReadUInt32();
                    }
                }

                RowReader.Close();
                DBCTable.Rows.Add(DBCRow);
            }

            #endregion

            DBCReader.Close();

            #endregion

            DBCTable.EndLoadData();
        }