예제 #1
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.Message + ex.StackTrace);
                if (OnSaveError != null)
                {
                    OnSaveError.Invoke(this, ex.Message);
                }
            }
            finally
            {
                isSaving = false;
            }
        }
예제 #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;
            }
        }