Example #1
0
 private void _Set(ref ulong value)
 {
     if (this.m_CurrentColumn >= this.m_PreprocessData.m_ColumnCount)
     {
         ToolFunctions.LogError(string.Concat(new object[] { "table[", this.m_FileName, "] id[", this.m_CurrentID, "] line[", this.m_CurrentLine, "], column[", this.m_CurrentColumn, "], max column count[", this.m_PreprocessData.m_ColumnCount, "]" }));
         this._EndParseColumn();
     }
     else if (!this._CheckColumnType(EM_TYPE_COLUMN.UINT64))
     {
         this._EndParseColumn();
     }
     else
     {
         string str = this._GetSubString(this.m_ReadBuffer, 0, this.m_ReadBuffer.Length, this.m_PreprocessData.m_Data[this.m_CurrentLine].m_ColumnField[this.m_CurrentColumn]);
         if (string.IsNullOrEmpty(str))
         {
             ToolFunctions.LogError(string.Concat(new object[] { "table[", this.m_FileName, "] id[", this.m_CurrentID, " has invalid value in line[", this.m_CurrentLine, "] and column[", this.m_CurrentColumn, "]" }));
             this._EndParseColumn();
         }
         else
         {
             value = StringUtils.StringToULong(str);
             this._EndParseColumn();
         }
     }
 }
Example #2
0
        private void _ReadLine()
        {
            List <ByteSection> list = null;

            for (int i = 0; i < TABLE_LINE_SEPARATOR.Length; i++)
            {
                list = _SeparateString(this.m_ReadBuffer, 0, this.m_ReadBuffer.Length, TABLE_LINE_SEPARATOR[i], true);
                if (list.Count >= 2)
                {
                    break;
                }
            }
            if ((list == null) || (list.Count < 2))
            {
                ToolFunctions.LogError(string.Concat(new object[] { "table [", this.m_FileName, "], line count[", list.Count, "]" }));
            }
            else
            {
                int                num2        = 0;
                ByteSection        section     = list[num2];
                ByteSection        section2    = list[num2];
                List <ByteSection> columnField = _SeparateString(this.m_ReadBuffer, section.m_SectionBeginPos, section2.m_SectionLength, "\t", false);
                this.m_PreprocessData.m_ColumnName  = new TableLine(list[num2], columnField);
                this.m_PreprocessData.m_ColumnCount = this.m_PreprocessData.m_ColumnName.m_ColumnField.Count;
                num2++;
                ByteSection        section3 = list[num2];
                ByteSection        section4 = list[num2];
                List <ByteSection> list3    = _SeparateString(this.m_ReadBuffer, section3.m_SectionBeginPos, section4.m_SectionLength, "\t", false);
                this.m_PreprocessData.m_ColumnType = new TableLine(list[num2], list3);
                int count = this.m_PreprocessData.m_ColumnType.m_ColumnField.Count;
                if (count != this.m_PreprocessData.m_ColumnCount)
                {
                    ToolFunctions.LogError(string.Concat(new object[] { this.m_FileName, " ColumnNameCount[", this.m_PreprocessData.m_ColumnCount, "], ColumnTypeCount[", count, "]" }));
                }
                else
                {
                    num2++;
                    this.m_PreprocessData.m_Data = new List <TableLine>();
                    while (num2 < list.Count)
                    {
                        ByteSection section5 = list[num2];
                        if (this.m_ReadBuffer[section5.m_SectionBeginPos] != 0x23)
                        {
                            ByteSection        section6 = list[num2];
                            ByteSection        section7 = list[num2];
                            List <ByteSection> list4    = _SeparateString(this.m_ReadBuffer, section6.m_SectionBeginPos, section7.m_SectionLength, "\t", false);
                            if (list4.Count != this.m_PreprocessData.m_ColumnCount)
                            {
                                ToolFunctions.LogError(string.Concat(new object[] { this.m_FileName, " ColumnNameCount[", this.m_PreprocessData.m_ColumnCount, "], ColumnCount of line[", num2, "] is [", list4.Count, "]" }));
                            }
                            else
                            {
                                this.m_PreprocessData.m_Data.Add(new TableLine(list[num2], list4));
                            }
                        }
                        num2++;
                    }
                }
            }
        }
Example #3
0
 public T GetRowByIndex(int index)
 {
     if ((index >= 0) && (index < this.m_Count))
     {
         return(this.m_Rows[index]);
     }
     ToolFunctions.LogException(new Exception(this.m_FileName + " can't find row! row index = " + index));
     return(null);
 }
Example #4
0
 private bool _CheckColumnType(EM_TYPE_COLUMN columnType)
 {
     // Debug.Log(m_ColumnTypes[m_CurrentColumn]);
     if (this.m_IsCheckColumn && (this.m_ColumnTypes[this.m_CurrentColumn] != columnType))
     {
         ToolFunctions.LogError(string.Concat(new object[] { "table [", this.m_FileName, "], line [", this.m_CurrentLine, "] column [", this.m_CurrentColumn, "] isn't match! in struct TableRow : [", COLUMN_TYPE_TO_STRING[(int)columnType], "] in .tab file : [", COLUMN_TYPE_TO_STRING[(int)this.m_ColumnTypes[this.m_CurrentColumn]], "]" }));
         return(false);
     }
     return(true);
 }
Example #5
0
 /// <summary>
 /// 使用数据表
 /// </summary>
 /// <param name="tableName">表名</param>
 /// <param name="isEncrypt">是否加密</param>
 /// <returns></returns>
 public static MemoryStream ReadTable(string tableName, bool isEncrypt = false)
 {
     try{
         MemoryStream buffer = ReadFileByBytes(tableName);
         return(buffer);
     }catch (Exception e)
     {
         ToolFunctions.LogException(e);
         return(new MemoryStream());
     }
 }
Example #6
0
 private string _GetSubString(byte[] sourceString, int off, int length, int sectionPos, int sectionLength)
 {
     if ((sectionPos < off) || ((sectionPos + sectionLength) > (off + length)))
     {
         ToolFunctions.LogError(string.Concat(new object[] { "SourceString:[", sourceString, "], Off:[", off, "], Length:[", length, "], StringSectionBegin:[", sectionPos, "], StringSectionLength:[", sectionLength, "]" }));
         return(null);
     }
     if (sectionLength <= 0)
     {
         return(string.Empty);
     }
     return(Encoding.UTF8.GetString(sourceString, sectionPos, sectionLength));
 }
Example #7
0
 private void _SaveColumnTypes()
 {
     // 类型数组
     this.m_ColumnTypes = new EM_TYPE_COLUMN[this.GetColumnCount()];
     for (int i = 0; i < this.m_PreprocessData.m_ColumnName.m_ColumnField.Count; i++)
     {
         this.m_ColumnTypes[i] = this._ParseColumnType(this.m_PreprocessData.m_ColumnType.m_ColumnField[i]);
         if ((this.m_ColumnTypes[i] <= EM_TYPE_COLUMN.INVALID) || (this.m_ColumnTypes[i] >= EM_TYPE_COLUMN.COUNT))
         {
             ToolFunctions.LogError(string.Concat(new object[] { "table [", this.m_FileName, "] invalid column type = [", this.m_PreprocessData.m_ColumnType.m_ColumnField[i], "]in column[", i, "]" }));
         }
     }
 }
Example #8
0
        private T Row(int ID)
        {
            if (((this.m_LastIndex >= 0) && (this.m_LastIndex < this.m_Count)) && (this.m_Rows[this.m_LastIndex].GetIndex() == ID))
            {
                return(this.m_Rows[this.m_LastIndex]);
            }
            int index = this.BinarySearch(0, this.m_Count - 1, ID);

            if (index < 0)
            {
                ToolFunctions.LogException(new Exception(this.m_FileName + " can't find row! rowID = " + ID));
                return(null);
            }
            this.m_LastIndex = index;
            return(this.m_Rows[index]);
        }
Example #9
0
        public bool Load(string fileName)
        {
            this.CleanBeforeReload();
            this.m_FileName = fileName;
            if (string.IsNullOrEmpty(this.m_FileName))
            {
                return(false);
            }
            TableSerializer s = new TableSerializer();

            s.SetCheckColumn(true);
            if (!s.OpenRead(fileName))
            {
                ToolFunctions.LogError(fileName + "Open Read Table Failed.");
                return(false);
            }
            //
            s.PreprocessTable();
            int lineCount = s.GetLineCount();

            if (lineCount <= 0)
            {
                return(false);
            }
            this.m_Rows = new T[lineCount];
            for (int i = 0; i < lineCount; i++)
            {
                this.m_Rows[i] = Activator.CreateInstance <T>();
            }
            this.m_Count = 0;
            while (this.m_Count < lineCount)
            {
                s.SetCurrentLine(this.m_Count);
                this.m_Rows[this.m_Count].MapData(s);
                if ((this.m_Count > 0) && (this.m_Rows[this.m_Count].GetIndex() <= this.m_Rows[this.m_Count - 1].GetIndex()))
                {
                    ToolFunctions.LogError(string.Concat(new object[] { fileName, ": the id of rows is out of order(), lien[", this.m_Count, "]" }));
                    return(false);
                }
                this.m_Count++;
            }
            this.SetColumnNames(s.GetColumnNames(), s.GetColumnCount());
            s.Close();
            return(true);
        }
Example #10
0
 private void SetColumnNames(string[] columnNames, int columnCount)
 {
     if ((columnNames != null) && (columnCount > 0))
     {
         for (int i = 0; i < columnCount; i++)
         {
             if (columnNames[i] == null)
             {
                 break;
             }
             if (this.m_ColumnNameMap.ContainsKey(columnNames[i]))
             {
                 ToolFunctions.LogError(this.m_FileName + string.Concat(new object[] { "duplicate columnName = ", columnNames[i], " new columnCount = ", i + 1, " old columnCount = ", this.m_ColumnNameMap[columnNames[i]] + 1 }));
                 break;
             }
             this.m_ColumnNameMap.Add(columnNames[i], i);
         }
     }
 }
Example #11
0
 private void _Set(ref string[] value)
 {
     if (this.m_CurrentColumn >= this.m_PreprocessData.m_ColumnCount)
     {
         ToolFunctions.LogError(string.Concat(new object[] { "table[", this.m_FileName, "] id[", this.m_CurrentID, "] line[", this.m_CurrentLine, "], column[", this.m_CurrentColumn, "], max column count[", this.m_PreprocessData.m_ColumnCount, "]" }));
         this._EndParseColumn();
     }
     else if (!this._CheckColumnType(EM_TYPE_COLUMN.STRING_ARRAY))
     {
         this._EndParseColumn();
     }
     else
     {
         string str = this._GetSubString(this.m_ReadBuffer, 0, this.m_ReadBuffer.Length, this.m_PreprocessData.m_Data[this.m_CurrentLine].m_ColumnField[this.m_CurrentColumn]);
         if (str == null)
         {
             ToolFunctions.LogError(string.Concat(new object[] { "table[", this.m_FileName, "] id[", this.m_CurrentID, " has invalid value in line[", this.m_CurrentLine, "] and column[", this.m_CurrentColumn, "]" }));
             this._EndParseColumn();
         }
         else
         {
             if (("-1" == str) || string.IsNullOrEmpty(str))
             {
                 value = new string[0];
             }
             else
             {
                 string[] strArray = str.Split("|".ToCharArray());
                 value = new string[strArray.Length];
                 for (int i = 0; i < strArray.Length; i++)
                 {
                     if (string.IsNullOrEmpty(strArray[i]))
                     {
                         ToolFunctions.LogError(string.Concat(new object[] { "table[", this.m_FileName, "] id[", this.m_CurrentID, " has invalid value in line[", this.m_CurrentLine, "] and column[", this.m_CurrentColumn, "]" }));
                     }
                     value[i] = strArray[i];
                 }
             }
             this._EndParseColumn();
         }
     }
 }