Ejemplo n.º 1
0
        /// <summary>
        /// Removes the specified row.
        /// </summary>
        /// <param name="row">The row to remove.</param>
        /// <exception cref="System.ArgumentException">Thrown when the file does not contain the specified row.</exception>
        public void RemoveRow(StringTableRow row)
        {
            if (!rows.Contains(row))
            {
                throw new ArgumentException("row", "File does not contain the specified row");
            }

            int rowIndex = rows.IndexOf(row);

            RemoveRow(rowIndex);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds a new row using the specified key and id.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="id">The id.</param>
        /// <returns>The row created.</returns>
        public StringTableRow AddRow(string key, int id)
        {
            StringTableKey tableKey = new StringTableKey();

            tableKey.Key = key;
            tableKey.ID  = id;

            StringTableRow tableRow = new StringTableRow(LanguageCount);

            keys.Add(tableKey);
            rows.Add(tableRow);

            return(tableRow);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Saves the file to the specified stream.
        /// </summary>
        /// <param name="stream">The stream to save to.</param>
        public override void Save(Stream stream)
        {
            BinaryWriter writer = new BinaryWriter(stream);

            string tableType = TableType.GetAttributeValue <StringTableTypeIdentifierAttribute, string>(x => x.Value);

            writer.Write(tableType);

            writer.Write(rows.Count);

            keys.ForEach(key => {
                writer.Write(key.Key);
                writer.Write(key.ID);
            });

            writer.Write(LanguageCount);

            long languageOffsets = stream.Position;

            for (int i = 0; i < LanguageCount; i++)
            {
                writer.Write(0);
            }

            long[] rowOffsetValues = new long[rows.Count];

            for (int i = 0; i < LanguageCount; i++)
            {
                StringTableLanguage language = (StringTableLanguage)i;

                long rowOffsets = stream.Position;

                for (int j = 0; j < rows.Count; j++)
                {
                    writer.Write(0);
                }

                for (int j = 0; j < rows.Count; j++)
                {
                    StringTableRow row = rows[j];
                    rowOffsetValues[j] = stream.Position;

                    writer.Write(row.GetText(language));

                    if (TableType == StringTableType.Item || TableType == StringTableType.Quest)
                    {
                        writer.Write(row.GetDescription(language));

                        if (TableType == StringTableType.Quest)
                        {
                            writer.Write(row.GetStartMessage(language));
                            writer.Write(row.GetEndMessage(language));
                        }
                    }
                }

                long position = stream.Position;
                stream.Seek(rowOffsets, SeekOrigin.Begin);

                for (int j = 0; j < rowOffsetValues.Length; j++)
                {
                    writer.Write((int)rowOffsetValues[j]);
                }

                stream.Seek(languageOffsets + (i * sizeof(int)), SeekOrigin.Begin);
                writer.Write((int)rowOffsets);

                stream.Seek(position, SeekOrigin.Begin);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Loads the file from the specified stream.
        /// </summary>
        /// <param name="stream">The stream to read from.</param>
        public override void Load(Stream stream)
        {
            BinaryReader reader = new BinaryReader(stream);

            string typeValue = reader.ReadString();

            TableType = GetTableType(typeValue);

            int rowCount = reader.ReadInt32();

            for (int i = 0; i < rowCount; i++)
            {
                StringTableKey key = new StringTableKey();
                key.Key = reader.ReadString();
                key.ID  = reader.ReadInt32();

                keys.Add(key);
            }

            languageCount = reader.ReadInt32();

            for (int j = 0; j < rowCount; j++)
            {
                StringTableRow row = new StringTableRow(languageCount);
                rows.Add(row);
            }

            for (int i = 0; i < languageCount; i++)
            {
                StringTableLanguage language = (StringTableLanguage)i;

                int  languageOffset     = reader.ReadInt32();
                long nextLanguageOffset = stream.Position;

                stream.Seek(languageOffset, SeekOrigin.Begin);

                for (int j = 0; j < rowCount; j++)
                {
                    int  rowOffset     = reader.ReadInt32();
                    long nextRowOffset = stream.Position;

                    stream.Seek(rowOffset, SeekOrigin.Begin);

                    StringTableRow row = rows[j];
                    row.SetText(reader.ReadString(), language);

                    if (TableType == StringTableType.Item || TableType == StringTableType.Quest)
                    {
                        row.SetDescription(reader.ReadString(), language);

                        if (TableType == StringTableType.Quest)
                        {
                            row.SetStartMessage(reader.ReadString(), language);
                            row.SetEndMessage(reader.ReadString(), language);
                        }
                    }

                    if (j < rowCount - 1)
                    {
                        stream.Seek(nextRowOffset, SeekOrigin.Begin);
                    }
                }

                if (i < languageCount - 1)
                {
                    stream.Seek(nextLanguageOffset, SeekOrigin.Begin);
                }
            }
        }