namespace SHNDecrypt
{
    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.Windows.Forms;

    public class editHeaderInfo : Form
    {
        private Button btnChangeHeader;
        private Button btnClose;
        private Button btnEditCrypt;
        private IContainer components;
        private Label label1;
        private Label label2;
        private Label label3;
        private Label lblAttempt;
        private frmMain main;
        private TextBox txtCryptHeader;
        private TextBox txtHeader;

        public editHeaderInfo(frmMain frmmain)
        {
            this.InitializeComponent();
            this.main = frmmain;
            if (frmmain.file == null)
            {
                base.Close();
            }
            this.LoadInfo();
        }

        private void btnChangeHeader_Click(object sender, EventArgs e)
        {
            try
            {
                this.main.file.Header = uint.Parse(this.txtHeader.Text);
                this.main.SQLStatus.Text = "Header changed!";
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            base.Close();
        }

        private void btnEditCrypt_Click(object sender, EventArgs e)
        {
            try
            {
                this.main.file.SetCryptHeader(this.txtCryptHeader.Text);
                this.LoadInfo();
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void frmEditFileProps_Load(object sender, EventArgs e)
        {
        }

        private void InitializeComponent()
        {
            ComponentResourceManager manager = new ComponentResourceManager(typeof(editHeaderInfo));
            this.label1 = new Label();
            this.txtCryptHeader = new TextBox();
            this.btnEditCrypt = new Button();
            this.label2 = new Label();
            this.txtHeader = new TextBox();
            this.btnChangeHeader = new Button();
            this.btnClose = new Button();
            this.label3 = new Label();
            this.lblAttempt = new Label();
            base.SuspendLayout();
            this.label1.AutoSize = true;
            this.label1.Location = new Point(10, 8);
            this.label1.Name = "label1";
            this.label1.Size = new Size(0x45, 13);
            this.label1.TabIndex = 0;
            this.label1.Text = "CryptHeader:";
            this.txtCryptHeader.Location = new Point(0x10, 0x1a);
            this.txtCryptHeader.Name = "txtCryptHeader";
            this.txtCryptHeader.Size = new Size(0x257, 20);
            this.txtCryptHeader.TabIndex = 1;
            this.btnEditCrypt.Location = new Point(0x26d, 0x19);
            this.btnEditCrypt.Name = "btnEditCrypt";
            this.btnEditCrypt.Size = new Size(0x44, 20);
            this.btnEditCrypt.TabIndex = 2;
            this.btnEditCrypt.Text = "Modify";
            this.btnEditCrypt.UseVisualStyleBackColor = true;
            this.btnEditCrypt.Click += new EventHandler(this.btnEditCrypt_Click);
            this.label2.AutoSize = true;
            this.label2.Location = new Point(13, 0x3e);
            this.label2.Name = "label2";
            this.label2.Size = new Size(0x2d, 13);
            this.label2.TabIndex = 3;
            this.label2.Text = "Header:";
            this.txtHeader.Location = new Point(0x10, 0x4e);
            this.txtHeader.Name = "txtHeader";
            this.txtHeader.RightToLeft = RightToLeft.Yes;
            this.txtHeader.Size = new Size(0x73, 20);
            this.txtHeader.TabIndex = 4;
            this.btnChangeHeader.Location = new Point(0x89, 0x4e);
            this.btnChangeHeader.Name = "btnChangeHeader";
            this.btnChangeHeader.Size = new Size(0x4c, 20);
            this.btnChangeHeader.TabIndex = 5;
            this.btnChangeHeader.Text = "Modify";
            this.btnChangeHeader.UseVisualStyleBackColor = true;
            this.btnChangeHeader.Click += new EventHandler(this.btnChangeHeader_Click);
            this.btnClose.Location = new Point(0x26d, 0x41);
            this.btnClose.Name = "btnClose";
            this.btnClose.Size = new Size(0x44, 0x23);
            this.btnClose.TabIndex = 6;
            this.btnClose.Text = "Close";
            this.btnClose.UseVisualStyleBackColor = true;
            this.btnClose.Click += new EventHandler(this.btnClose_Click);
            this.label3.AutoSize = true;
            this.label3.Location = new Point(0x150, 0x30);
            this.label3.Name = "label3";
            this.label3.Size = new Size(0x117, 13);
            this.label3.TabIndex = 7;
            this.label3.Text = "Please be aware that changing this might corrupt your file!";
            this.lblAttempt.AutoSize = true;
            this.lblAttempt.Location = new Point(0x115, 8);
            this.lblAttempt.Name = "lblAttempt";
            this.lblAttempt.Size = new Size(100, 13);
            this.lblAttempt.TabIndex = 8;
            this.lblAttempt.Text = "Decryption Attempt:";
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.ClientSize = new Size(0x2b6, 110);
            base.Controls.Add(this.lblAttempt);
            base.Controls.Add(this.label3);
            base.Controls.Add(this.btnClose);
            base.Controls.Add(this.btnChangeHeader);
            base.Controls.Add(this.txtHeader);
            base.Controls.Add(this.label2);
            base.Controls.Add(this.btnEditCrypt);
            base.Controls.Add(this.txtCryptHeader);
            base.Controls.Add(this.label1);
            base.Icon = (Icon) manager.GetObject("$this.Icon");
            base.MaximizeBox = false;
            base.MinimizeBox = false;
            base.Name = "frmEditFileProps";
            base.StartPosition = FormStartPosition.CenterScreen;
            this.Text = "Edit File Properties";
            base.Load += new EventHandler(this.frmEditFileProps_Load);
            base.ResumeLayout(false);
            base.PerformLayout();
        }

        private void LoadInfo()
        {
            this.txtCryptHeader.Text = this.main.file.GetCryptString();
            this.txtHeader.Text = this.main.file.Header.ToString();
            try
            {
                this.lblAttempt.Text = "Decryption: " + ToStringFromAscii(this.main.file.CryptHeader);
            }
            catch
            {
            }
        }

        private static string ToStringFromAscii(byte[] bytes)
        {
            char[] chArray = new char[bytes.Length];
            for (int i = 0; i < bytes.Length; i++)
            {
                if ((bytes[i] < 0x20) && (bytes[i] >= 0))
                {
                    chArray[i] = '.';
                }
                else
                {
                    int num2 = bytes[i] & 0xff;
                    chArray[i] = (char) num2;
                }
            }
            return new string(chArray);
        }
    }
}

