namespace SHNDecrypt
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Windows.Forms;

    public class Translator : Form
    {
        private Button btnDo;
        private Button btnOpen;
        private ComboBox cmbLanIndex;
        private ComboBox cmbLanTrans;
        private ComboBox cmbOrIndex;
        private ComboBox cmbOrTrans;
        private IContainer components;
        private frmMain Fmain;
        private GroupBox groupBox1;
        private GroupBox groupBox2;
        private Label label1;
        private Label label2;
        private Label label3;
        private Label label4;
        private Label label5;
        private Label label6;
        private SHNFile language;
        private SHNFile original;
        private TextBox txtDefault;
        private Label txtInfo;

        public Translator(frmMain main)
        {
            this.InitializeComponent();
            this.Fmain = main;
            if (main.file == null)
            {
                base.Close();
            }
            else
            {
                this.original = main.file;
            }
        }

        private void btnDo_Click(object sender, EventArgs e)
        {
            int num = this.getColIndex(this.cmbOrIndex.Items[this.cmbOrIndex.SelectedIndex].ToString(), this.original);
            int num2 = this.getColIndex(this.cmbLanIndex.Items[this.cmbLanIndex.SelectedIndex].ToString(), this.language);
            int num3 = this.getColIndex(this.cmbOrTrans.Items[this.cmbOrTrans.SelectedIndex].ToString(), this.original);
            int num4 = this.getColIndex(this.cmbLanTrans.Items[this.cmbLanTrans.SelectedIndex].ToString(), this.language);
            this.txtInfo.Text = string.Concat(new object[] { "Original sorting by: ", num, ", trans sorting by: ", num2, " toTrans index: ", num3 });
            Dictionary<string, string> dictionary = new Dictionary<string, string>();
            List<string> list = new List<string>();
            lock (this.language)
            {
                for (int j = 0; j < this.language.table.Rows.Count; j++)
                {
                    try
                    {
                        dictionary.Add(this.language.table.Rows[j][num2].ToString(), this.language.table.Rows[j][num4].ToString());
                    }
                    catch (Exception)
                    {
                    }
                }
                foreach (DataRow row in this.original.table.Rows)
                {
                    string key = row[num].ToString();
                    if (dictionary.ContainsKey(key))
                    {
                        row[num3] = dictionary[key];
                    }
                    else
                    {
                        list.Add(key);
                        if (this.txtDefault.Text.ToLower() != "donothing")
                        {
                            row[num3] = this.txtDefault.Text;
                        }
                    }
                }
            }
            string text = "";
            for (int i = 0; i < list.Count; i++)
            {
                text = text + list[i] + "\r\n";
            }
            Clipboard.SetText(text);
            this.Fmain.SQLStatus.Text = "Done translating! " + list.Count + " untranslated set to clipboard";
        }

        private void btnOpen_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog {
                Filter = "SHN File (*.shn)|*.shn",
                Title = "Open language file"
            };
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                this.language = new SHNFile(dialog.FileName);
                this.RefreshColumns();
            }
        }

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

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

        private int getColIndex(string name, SHNFile file)
        {
            for (int i = 0; i < file.table.Columns.Count; i++)
            {
                if (file.table.Columns[i].ColumnName == name)
                {
                    return i;
                }
            }
            return -1;
        }

        private int GetRowByIndex(int ColIndex, string RowID, SHNFile file)
        {
            for (int i = 0; i < file.table.Rows.Count; i++)
            {
                if (file.table.Rows[i][ColIndex].ToString() == RowID)
                {
                    return i;
                }
            }
            return -1;
        }

        private void InitializeComponent()
        {
            ComponentResourceManager manager = new ComponentResourceManager(typeof(Translator));
            this.label1 = new Label();
            this.btnOpen = new Button();
            this.groupBox1 = new GroupBox();
            this.cmbOrTrans = new ComboBox();
            this.label3 = new Label();
            this.cmbOrIndex = new ComboBox();
            this.label2 = new Label();
            this.groupBox2 = new GroupBox();
            this.cmbLanTrans = new ComboBox();
            this.label4 = new Label();
            this.cmbLanIndex = new ComboBox();
            this.label5 = new Label();
            this.btnDo = new Button();
            this.txtInfo = new Label();
            this.label6 = new Label();
            this.txtDefault = new TextBox();
            this.groupBox1.SuspendLayout();
            this.groupBox2.SuspendLayout();
            base.SuspendLayout();
            this.label1.AutoSize = true;
            this.label1.Location = new Point(12, 9);
            this.label1.Name = "label1";
            this.label1.Size = new Size(0xb8, 13);
            this.label1.TabIndex = 0;
            this.label1.Text = "Please open the other language SHN";
            this.btnOpen.Location = new Point(0x11, 0x19);
            this.btnOpen.Name = "btnOpen";
            this.btnOpen.Size = new Size(0x48, 0x1b);
            this.btnOpen.TabIndex = 1;
            this.btnOpen.Text = "Open";
            this.btnOpen.UseVisualStyleBackColor = true;
            this.btnOpen.Click += new EventHandler(this.btnOpen_Click);
            this.groupBox1.Controls.Add(this.cmbOrTrans);
            this.groupBox1.Controls.Add(this.label3);
            this.groupBox1.Controls.Add(this.cmbOrIndex);
            this.groupBox1.Controls.Add(this.label2);
            this.groupBox1.Location = new Point(0x11, 0x3a);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new Size(0xcf, 0x67);
            this.groupBox1.TabIndex = 2;
            this.groupBox1.TabStop = false;
            this.groupBox1.Text = "Original:";
            this.cmbOrTrans.DropDownStyle = ComboBoxStyle.DropDownList;
            this.cmbOrTrans.FormattingEnabled = true;
            this.cmbOrTrans.Location = new Point(0x12, 0x45);
            this.cmbOrTrans.Name = "cmbOrTrans";
            this.cmbOrTrans.Size = new Size(0xb1, 0x15);
            this.cmbOrTrans.TabIndex = 3;
            this.label3.AutoSize = true;
            this.label3.Location = new Point(12, 50);
            this.label3.Name = "label3";
            this.label3.Size = new Size(100, 13);
            this.label3.TabIndex = 2;
            this.label3.Text = "Column to translate:";
            this.cmbOrIndex.DropDownStyle = ComboBoxStyle.DropDownList;
            this.cmbOrIndex.FormattingEnabled = true;
            this.cmbOrIndex.Location = new Point(0x39, 0x11);
            this.cmbOrIndex.Name = "cmbOrIndex";
            this.cmbOrIndex.Size = new Size(100, 0x15);
            this.cmbOrIndex.TabIndex = 1;
            this.cmbOrIndex.SelectedIndexChanged += new EventHandler(this.cmbOrIndex_SelectedIndexChanged);
            this.label2.AutoSize = true;
            this.label2.Location = new Point(12, 0x16);
            this.label2.Name = "label2";
            this.label2.Size = new Size(0x24, 13);
            this.label2.TabIndex = 0;
            this.label2.Text = "Index:";
            this.groupBox2.Controls.Add(this.cmbLanTrans);
            this.groupBox2.Controls.Add(this.label4);
            this.groupBox2.Controls.Add(this.cmbLanIndex);
            this.groupBox2.Controls.Add(this.label5);
            this.groupBox2.Location = new Point(0x110, 0x3a);
            this.groupBox2.Name = "groupBox2";
            this.groupBox2.Size = new Size(0xcf, 0x67);
            this.groupBox2.TabIndex = 3;
            this.groupBox2.TabStop = false;
            this.groupBox2.Text = "Language SHN:";
            this.cmbLanTrans.DropDownStyle = ComboBoxStyle.DropDownList;
            this.cmbLanTrans.FormattingEnabled = true;
            this.cmbLanTrans.Location = new Point(0x12, 0x45);
            this.cmbLanTrans.Name = "cmbLanTrans";
            this.cmbLanTrans.Size = new Size(0xb1, 0x15);
            this.cmbLanTrans.TabIndex = 3;
            this.label4.AutoSize = true;
            this.label4.Location = new Point(12, 50);
            this.label4.Name = "label4";
            this.label4.Size = new Size(0x61, 13);
            this.label4.TabIndex = 2;
            this.label4.Text = "Translation source:";
            this.cmbLanIndex.DropDownStyle = ComboBoxStyle.DropDownList;
            this.cmbLanIndex.FormattingEnabled = true;
            this.cmbLanIndex.Location = new Point(0x39, 0x11);
            this.cmbLanIndex.Name = "cmbLanIndex";
            this.cmbLanIndex.Size = new Size(100, 0x15);
            this.cmbLanIndex.TabIndex = 1;
            this.label5.AutoSize = true;
            this.label5.Location = new Point(12, 0x16);
            this.label5.Name = "label5";
            this.label5.Size = new Size(0x24, 13);
            this.label5.TabIndex = 0;
            this.label5.Text = "Index:";
            this.btnDo.Location = new Point(0xcb, 0xa7);
            this.btnDo.Name = "btnDo";
            this.btnDo.Size = new Size(90, 40);
            this.btnDo.TabIndex = 4;
            this.btnDo.Text = "Translate!";
            this.btnDo.UseVisualStyleBackColor = true;
            this.btnDo.Click += new EventHandler(this.btnDo_Click);
            this.txtInfo.AutoSize = true;
            this.txtInfo.Location = new Point(0x25, 0xe1);
            this.txtInfo.Name = "txtInfo";
            this.txtInfo.Size = new Size(0, 13);
            this.txtInfo.TabIndex = 5;
            this.label6.AutoSize = true;
            this.label6.Location = new Point(0x16, 0xb3);
            this.label6.Name = "label6";
            this.label6.Size = new Size(0x3e, 13);
            this.label6.TabIndex = 6;
            this.label6.Text = "Default Val:";
            this.txtDefault.Location = new Point(90, 0xb0);
            this.txtDefault.Name = "txtDefault";
            this.txtDefault.Size = new Size(0x54, 20);
            this.txtDefault.TabIndex = 7;
            this.txtDefault.Text = "donothing";
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.ClientSize = new Size(0x1ee, 220);
            base.Controls.Add(this.txtDefault);
            base.Controls.Add(this.label6);
            base.Controls.Add(this.txtInfo);
            base.Controls.Add(this.btnDo);
            base.Controls.Add(this.groupBox2);
            base.Controls.Add(this.groupBox1);
            base.Controls.Add(this.btnOpen);
            base.Controls.Add(this.label1);
            base.Icon = (Icon) manager.GetObject("$this.Icon");
            base.MaximizeBox = false;
            base.MinimizeBox = false;
            base.Name = "Translator";
            base.StartPosition = FormStartPosition.CenterParent;
            this.Text = "Translator";
            base.Load += new EventHandler(this.Translator_Load);
            this.groupBox1.ResumeLayout(false);
            this.groupBox1.PerformLayout();
            this.groupBox2.ResumeLayout(false);
            this.groupBox2.PerformLayout();
            base.ResumeLayout(false);
            base.PerformLayout();
        }

        private void RefreshColumns()
        {
            this.cmbOrIndex.Items.Clear();
            this.cmbOrTrans.Items.Clear();
            this.cmbLanTrans.Items.Clear();
            this.cmbLanIndex.Items.Clear();
            for (int i = 0; i < this.original.table.Columns.Count; i++)
            {
                this.cmbOrIndex.Items.Add(this.original.table.Columns[i].ColumnName);
                this.cmbOrTrans.Items.Add(this.original.table.Columns[i].ColumnName);
            }
            for (int j = 0; j < this.language.table.Columns.Count; j++)
            {
                this.cmbLanIndex.Items.Add(this.language.table.Columns[j].ColumnName);
                this.cmbLanTrans.Items.Add(this.language.table.Columns[j].ColumnName);
            }
            this.cmbLanIndex.SelectedIndex = 0;
            this.cmbLanTrans.SelectedIndex = 0;
            this.cmbOrIndex.SelectedIndex = 0;
            this.cmbOrTrans.SelectedIndex = 0;
        }

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

