상속: IClientDBReader
예제 #1
0
        public static IWowClientDBReader GetReader(string file)
        {
            IWowClientDBReader reader;

            var ext = Path.GetExtension(file).ToUpperInvariant();
            if (ext == ".DBC")
                reader = new DBCReader(file);
            else if (ext == ".DB2")
                try
                {
                    reader = new DB2Reader(file);
                }
                catch
                {
                    reader = new DB3Reader(file);
                }
            else if (ext == ".ADB")
                reader = new ADBReader(file);
            else if (ext == ".WDB")
                reader = new WDBReader(file);
            else if (ext == ".STL")
                reader = new STLReader(file);
            else
                throw new InvalidDataException(String.Format("Unknown file type {0}", ext));

            return reader;
        }
예제 #2
0
        public static IWowClientDBReader GetReader(string file)
        {
            IWowClientDBReader reader;

            var ext = Path.GetExtension(file).ToUpperInvariant();

            if (ext == ".DBC")
            {
                reader = new DBCReader(file);
            }
            else if (ext == ".DB2")
            {
                reader = new DB2Reader(file);
            }
            else if (ext == ".ADB")
            {
                reader = new ADBReader(file);
            }
            else if (ext == ".WDB")
            {
                reader = new WDBReader(file);
            }
            else if (ext == ".STL")
            {
                reader = new STLReader(file);
            }
            else
            {
                throw new InvalidDataException(String.Format("Unknown file type {0}", ext));
            }

            return(reader);
        }
예제 #3
0
        public static BaseReader GetReader(string file)
        {
            BaseReader reader = null;

            var ext = Path.GetExtension(file).ToUpperInvariant();

            switch (ext)
            {
            case ".DBC":
                reader = new DBCReader(file);
                break;

            case ".DB2":
                reader = new DB2Reader(file);
                break;

            case ".ADB":
                reader = new ADBReader(file);
                break;

            case ".WDB":
                reader = new WDBReader(file);
                break;

            default:
                throw new InvalidDataException(String.Format("Unknown file type {0}", ext));
            }

            return(reader);
        }
예제 #4
0
        public static IWowClientDBReader GetReader(string file, XmlElement definition)
        {
            IWowClientDBReader reader;

            var ext = Path.GetExtension(file).ToUpperInvariant();

            if (ext == ".DBC")
            {
                reader = new DBCReader(file);
            }
            else if (ext == ".DB2")
            {
                using (var binaryReader = BinaryReaderExtensions.FromFile(file))
                {
                    switch (binaryReader.ReadUInt32())
                    {
                    case DB2Reader.DB2FmtSig:
                    {
                        reader = new DB2Reader(file);
                        break;
                    }

                    case DB3Reader.DB3FmtSig:
                    {
                        reader = new DB2Reader(file);
                        break;
                    }

                    case DB4Reader.DB4FmtSig:
                    {
                        try
                        {
                            reader = new DB4Reader(file);
                        }
                        catch
                        {
                            reader = new DB4SparseReader(file);
                        }
                        break;
                    }

                    case DB5Reader.DB5FmtSig:
                    {
                        try
                        {
                            reader = new DB5Reader(file, definition);
                        }
                        catch
                        {
                            reader = new DB5SparseReader(file);
                        }
                        break;
                    }

                    default:
                        throw new InvalidDataException(string.Format("Unknown file type {0}", ext));
                    }
                }
            }
            else if (ext == ".ADB")
            {
                reader = new ADBReader(file);
            }
            else if (ext == ".WDB")
            {
                reader = new WDBReader(file);
            }
            else if (ext == ".STL")
            {
                reader = new STLReader(file);
            }
            else
            {
                throw new InvalidDataException(String.Format("Unknown file type {0}", ext));
            }

            return(reader);
        }
예제 #5
0
        public static IWowClientDBReader GetReader(string file, XmlElement definition)
        {
            IWowClientDBReader reader;

            var ext = Path.GetExtension(file).ToUpperInvariant();
            if (ext == ".DBC")
                reader = new DBCReader(file);
            else if (ext == ".DB2")
            {
                using (var binaryReader = BinaryReaderExtensions.FromFile(file))
                {
                    switch (binaryReader.ReadUInt32())
                    {
                        case DB2Reader.DB2FmtSig:
                        {
                            reader = new DB2Reader(file);
                            break;
                        }
                        case DB3Reader.DB3FmtSig:
                        {
                            reader = new DB2Reader(file);
                            break;
                        }
                        case DB4Reader.DB4FmtSig:
                        {
                            try
                            {
                                reader = new DB4Reader(file);
                            }
                            catch
                            {
                                reader = new DB4SparseReader(file);
                            }
                            break;
                        }
                        case DB5Reader.DB5FmtSig:
                        {
                            try
                            {
                                reader = new DB5Reader(file, definition);
                            }
                            catch
                            {
                                reader = new DB5SparseReader(file);
                            }
                            break;
                        }
                        default:
                            throw new InvalidDataException(string.Format("Unknown file type {0}", ext));
                    }
                }
            }
            else if (ext == ".ADB")
                reader = new ADBReader(file);
            else if (ext == ".WDB")
                reader = new WDBReader(file);
            else if (ext == ".STL")
                reader = new STLReader(file);
            else
                throw new InvalidDataException(String.Format("Unknown file type {0}", ext));

            return reader;
        }
예제 #6
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            var file = (string)e.Argument;

            try
            {
                var ext = Path.GetExtension(file).ToUpperInvariant();
                if (ext == ".DBC")
                {
                    m_reader = new DBCReader(file);
                }
                else if (ext == ".DB2")
                {
                    m_reader = new DB2Reader(file);
                }
                else if (ext == ".ADB")
                {
                    m_reader = new ADBReader(file);
                }
                else if (ext == ".WDB")
                {
                    m_reader = new WDBReader(file);
                }
                else
                {
                    throw new InvalidDataException(String.Format("Unknown file type {0}", ext));
                }
            }
            catch (Exception ex)
            {
                ShowErrorMessageBox(ex.Message);
                e.Cancel = true;
                return;
            }

            m_fields = m_definition.GetElementsByTagName("field");

            string[] types = new string[m_fields.Count];

            for (var j = 0; j < m_fields.Count; ++j)
            {
                types[j] = m_fields[j].Attributes["type"].Value;
            }

            // hack for *.adb files (because they don't have FieldsCount)
            var notADB = !(m_reader is ADBReader);
            // hack for *.wdb files (because they don't have FieldsCount)
            var notWDB = !(m_reader is WDBReader);

            if (GetFieldsCount(m_fields) != m_reader.FieldsCount && notADB && notWDB)
            {
                var msg = String.Format(CultureInfo.InvariantCulture, "{0} has invalid definition!\nFields count mismatch: got {1}, expected {2}", Path.GetFileName(file), m_fields.Count, m_reader.FieldsCount);
                ShowErrorMessageBox(msg);
                e.Cancel = true;
                return;
            }

            m_dataTable        = new DataTable(Path.GetFileName(file));
            m_dataTable.Locale = CultureInfo.InvariantCulture;

            CreateColumns();                                // Add columns

            CreateIndexes();                                // Add indexes

            for (var i = 0; i < m_reader.RecordsCount; ++i) // Add rows
            {
                var dataRow = m_dataTable.NewRow();

                #region Test
                //var bytes = m_reader.GetRowAsByteArray(i);
                //unsafe
                //{
                //    fixed (void* b = bytes)
                //    {
                //        IntPtr ptr = new IntPtr(b);

                //        int offset = 0;

                //        for (var j = 0; j < m_fields.Count; ++j)    // Add cells
                //        {
                //            switch (types[j])
                //            {
                //                case "long":
                //                    dataRow[j] = *(long*)(ptr + offset);
                //                    offset += 8;
                //                    break;
                //                case "ulong":
                //                    dataRow[j] = *(ulong*)(ptr + offset);
                //                    offset += 8;
                //                    break;
                //                case "int":
                //                    dataRow[j] = *(int*)(ptr + offset);
                //                    offset += 4;
                //                    break;
                //                case "uint":
                //                    dataRow[j] = *(uint*)(ptr + offset);
                //                    offset += 4;
                //                    break;
                //                case "short":
                //                    dataRow[j] = *(short*)(ptr + offset);
                //                    offset += 2;
                //                    break;
                //                case "ushort":
                //                    dataRow[j] = *(ushort*)(ptr + offset);
                //                    offset += 2;
                //                    break;
                //                case "sbyte":
                //                    dataRow[j] = *(sbyte*)(ptr + offset);
                //                    offset += 1;
                //                    break;
                //                case "byte":
                //                    dataRow[j] = *(byte*)(ptr + offset);
                //                    offset += 1;
                //                    break;
                //                case "float":
                //                    dataRow[j] = *(float*)(ptr + offset);
                //                    offset += 4;
                //                    break;
                //                case "double":
                //                    dataRow[j] = *(double*)(ptr + offset);
                //                    offset += 8;
                //                    break;
                //                case "string":
                //                    dataRow[j] = m_reader.StringTable[*(int*)(ptr + offset)];
                //                    offset += 4;
                //                    break;
                //                default:
                //                    throw new Exception(String.Format("Unknown field type {0}!", m_fields[j].Attributes["type"].Value));
                //            }
                //        }
                //    }
                //}
                #endregion
                var br = m_reader[i];

                for (var j = 0; j < m_fields.Count; ++j)    // Add cells
                {
                    switch (types[j])
                    {
                    case "long":
                        dataRow[j] = br.ReadInt64();
                        break;

                    case "ulong":
                        dataRow[j] = br.ReadUInt64();
                        break;

                    case "int":
                        dataRow[j] = br.ReadInt32();
                        break;

                    case "uint":
                        dataRow[j] = br.ReadUInt32();
                        break;

                    case "short":
                        dataRow[j] = br.ReadInt16();
                        break;

                    case "ushort":
                        dataRow[j] = br.ReadUInt16();
                        break;

                    case "sbyte":
                        dataRow[j] = br.ReadSByte();
                        break;

                    case "byte":
                        dataRow[j] = br.ReadByte();
                        break;

                    case "float":
                        dataRow[j] = br.ReadSingle();
                        break;

                    case "double":
                        dataRow[j] = br.ReadDouble();
                        break;

                    case "string":
                        dataRow[j] = m_reader is WDBReader?br.ReadStringNull() : m_reader.StringTable[br.ReadInt32()];

                        break;

                    default:
                        throw new ArgumentException(String.Format(CultureInfo.InvariantCulture, "Unknown field type {0}!", types[j]));
                    }
                }

                m_dataTable.Rows.Add(dataRow);

                int percent = (int)((float)m_dataTable.Rows.Count / (float)m_reader.RecordsCount * 100.0f);
                (sender as BackgroundWorker).ReportProgress(percent);
            }

            if (dataGridView1.InvokeRequired)
            {
                SetDataViewDelegate d = new SetDataViewDelegate(SetDataSource);
                Invoke(d, new object[] { m_dataTable.DefaultView });
            }
            else
            {
                SetDataSource(m_dataTable.DefaultView);
            }

            e.Result = file;
        }