Esempio n. 1
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, Encoding.Unicode);

            ColumnCount = reader.ReadInt32();
            int rowCount = reader.ReadInt32();

            int[,] offsets   = new int[rowCount, ColumnCount];
            short[,] lengths = new short[rowCount, ColumnCount];

            for (int i = 0; i < rowCount; i++)
            {
                for (int j = 0; j < ColumnCount; j++)
                {
                    offsets[i, j] = reader.ReadInt32();
                    lengths[i, j] = reader.ReadInt16();
                }
            }

            for (int i = 0; i < rowCount; i++)
            {
                LanguageRow row = new LanguageRow(ColumnCount);

                for (int j = 0; j < ColumnCount; j++)
                {
                    stream.Seek(offsets[i, j], SeekOrigin.Begin);

                    row[j] = reader.ReadString(lengths[i, j] * 2, Encoding.Unicode);
                }

                rows.Add(row);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Adds a new row.
        /// </summary>
        /// <returns>The row created.</returns>
        public LanguageRow AddRow()
        {
            LanguageRow row = new LanguageRow(ColumnCount);

            rows.Add(row);

            return(row);
        }
Esempio n. 3
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(LanguageRow row)
        {
            if (!rows.Contains(row))
            {
                throw new ArgumentException("row", "File does not contain the specified row");
            }

            int rowIndex = rows.IndexOf(row);

            RemoveRow(rowIndex);
        }
Esempio n. 4
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, Encoding.Unicode);

            writer.Write(ColumnCount);
            writer.Write(rows.Count);

            long[,] offsets = new long[rows.Count, ColumnCount];

            for (int i = 0; i < rows.Count; i++)
            {
                LanguageRow row = rows[i];

                for (int j = 0; j < ColumnCount; j++)
                {
                    offsets[i, j] = stream.Position;

                    writer.Write(0);
                    writer.Write((short)row[j].Length);
                }
            }

            for (int i = 0; i < rows.Count; i++)
            {
                LanguageRow row = rows[i];

                for (int j = 0; j < ColumnCount; j++)
                {
                    long offset = stream.Position;
                    writer.WriteString(row[j], Encoding.Unicode);

                    long previousPosition = stream.Position;
                    stream.Seek(offsets[i, j], SeekOrigin.Begin);

                    writer.Write((int)offset);

                    stream.Seek(previousPosition, SeekOrigin.Begin);
                }
            }
        }