예제 #1
0
        public void Write(SHNWriter writer)
        {
            if (ColumnName.StartsWith("Undefined"))
            {
                writer.WritePaddedString(" ", 48);
            }
            else
            {
                writer.WritePaddedString(ColumnName, 48);
            }

            writer.Write((uint)TypeByte);
            writer.Write((uint)Length);
        }
예제 #2
0
        private void InternalSave(string path)
        {
            try
            {
                isSaving = true;
                UpdateDefaultRecordLength();
                byte[] content;
                using (var encrypted = new MemoryStream())
                {
                    var writer = new SHNWriter(encrypted);
                    writer.Write(Header);
                    writer.Write((uint)Rows.Count);
                    writer.Write(DefaultRecordLength);
                    writer.Write((uint)Columns.Count);
                    WriteColumns(writer);
                    WriteRows(writer);
                    content = new byte[encrypted.Length];
                    encrypted.Seek(0, SeekOrigin.Begin);
                    encrypted.Read(content, 0, content.Length);
                }

                FileCrypto.Crypt(content, 0, content.Length);
                using (var final = File.Create(path))
                {
                    var writer = new BinaryWriter(final);
                    writer.Write(CryptHeader);
                    writer.Write(content.Length + 36);
                    writer.Write(content);
                }

                FileName = path;
                OnSaveFinished?.Invoke(this);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex + ex.StackTrace);
                OnSaveError?.Invoke(this, ex.ToString());
            }
            finally
            {
                isSaving = false;
            }
        }
예제 #3
0
        private void WriteRows(SHNWriter writer)
        {
            foreach (DataRow row in Rows)
            {
                var   CurPos    = (int)writer.BaseStream.Position;
                short unkLength = 0;
                writer.Write((short)0);  // Row Length
                for (var colIndex = 0; colIndex < Columns.Count; ++colIndex)
                {
                    var column = (ShnColumn)Columns[colIndex];
                    switch (column.TypeByte)
                    {
                    case 1:
                    case 12:
                    case 16:
                        writer.Write((byte)row[colIndex]);
                        break;

                    case 2:
                        writer.Write((ushort)row[colIndex]);
                        break;

                    case 3:
                    case 11:
                    case 18:
                    case 27:
                        writer.Write((uint)row[colIndex]);
                        break;

                    case 5:
                        writer.Write((float)row[colIndex]);
                        break;

                    case 9:
                    case 24:
                        writer.WritePaddedString((string)row[colIndex], column.Length);
                        break;

                    case 13:
                    case 21:
                        writer.Write((short)row[colIndex]);
                        break;

                    case 20:
                        writer.Write((sbyte)row[colIndex]);
                        break;

                    case 22:
                        writer.Write((int)row[colIndex]);
                        break;

                    case 26:
                        var tmp = (string)row[colIndex];
                        unkLength += (short)tmp.Length;
                        writer.WritePaddedString(tmp, tmp.Length + 1);
                        break;
                    }
                }

                var LastPos = (int)writer.BaseStream.Position;
                writer.Seek(CurPos, SeekOrigin.Begin);
                writer.Write((short)(DefaultRecordLength + unkLength));  // Update Row Length
                writer.Seek(LastPos, SeekOrigin.Begin);
            }
        }