Esempio n. 1
0
 public void Write(SHNWriter writer)
 {
     if (this.ColumnName.StartsWith("Undefined"))
     {
         writer.WritePaddedString(" ", 48);
     }
     else
     {
         writer.WritePaddedString(this.ColumnName, 48);
     }
     writer.Write((uint)this.TypeByte);
     writer.Write((uint)this.Length);
 }
Esempio n. 2
0
 private void WriteRows(SHNWriter writer)
 {
     foreach (DataRow row in base.Rows)
     {
         int CurPos = (int)writer.BaseStream.Position;
         short unkLength = 0;
         writer.Write((short)0);     // Row Length
         for (int colIndex = 0; colIndex < base.Columns.Count; ++colIndex)
         {
             SHNColumn column = (SHNColumn)base.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((Single)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:
                     string tmp = (string)row[colIndex];
                     unkLength += (short)tmp.Length;
                     writer.WritePaddedString(tmp, tmp.Length + 1);
                     break;
             }
         }
         int LastPos = (int)writer.BaseStream.Position;
         writer.Seek(CurPos, SeekOrigin.Begin);
         writer.Write((short)(DefaultRecordLength + unkLength));     // Update Row Length
         writer.Seek(LastPos, SeekOrigin.Begin);
     }
 }
Esempio n. 3
0
 private void WriteColumns(SHNWriter writer)
 {
     for (int i = 0; i < base.Columns.Count; ++i)
     {
         ((SHNColumn)base.Columns[i]).Write(writer);
     }
 }
Esempio n. 4
0
        private void InternalSave(string path)
        {
            try
            {
                isSaving = true;
                UpdateDefaultRecordLength();
                byte[] content;
                using (MemoryStream encrypted = new MemoryStream())
                {
                    SHNWriter writer = new SHNWriter(encrypted);
                    writer.Write(this.Header);
                    writer.Write((uint)this.Rows.Count);
                    writer.Write(this.DefaultRecordLength);
                    writer.Write((uint)this.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 (FileStream final = File.Create(path))
                {
                    BinaryWriter writer = new BinaryWriter(final);
                    writer.Write(CryptHeader);
                    writer.Write((int)(content.Length + 36));
                    writer.Write(content);
                }

                this.FileName = path;
                if (OnSaveFinished != null)
                    OnSaveFinished.Invoke(this);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString() + ex.StackTrace);
                if (OnSaveError != null)
                    OnSaveError.Invoke(this, ex.ToString());
            }
            finally
            {
                isSaving = false;
            }
        }