using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.IO;


namespace HatredAsmToCArray
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            String Array = comboBox1.Text + " " + textBox1.Text + "[] = { \n";
            string[] Filtered1 = new string[300];
            ArrayList Entrys = new ArrayList();
            char[] splitter =  { 'd', 'b', 'h' };
            string hex = "0x";
            
            //Lets Make a Good C-Array
            for (int i = 0; i < listBox1.Items.Count; i++)
            {
                Filtered1 = listBox1.Items[i].ToString().Split(splitter, StringSplitOptions.RemoveEmptyEntries);
                Entrys.Add(hex + Filtered1[0].Trim());
            }
            int count = 1;
            for (int i = 0; i < Entrys.Count; i++)
            {

                Array = Array + Entrys[i];
                if (i != Entrys.Count - 1)
                {
                    Array = Array + ",";
                }
                if (count == 12)
                {
                    Array = Array + "\n";
                    count = 0;
                }
                count++;

            }
            Array = Array + "};";
            richTextBox1.Text = Array;

        }

        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                openFileDialog1.ShowDialog();
                TextReader Tr = new StreamReader(openFileDialog1.FileName);
                string lol = "";
                while ((lol = Tr.ReadLine()) != null)
                {
                    listBox1.Items.Add(lol.Trim());
                }
            }
            catch (Exception)
            {
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Made By Soul12 2007\n Greetings: To ALL my homies and the RCE community", "Not All you See is an illusion");
        }

        private void button4_Click(object sender, EventArgs e)
        {
            try
            {
                openFileDialog1.ShowDialog();
                TextReader Tr = new StreamReader(openFileDialog1.FileName);
                string lol = "";
                string[] chars = new string[100];
                char[] splitter = { ' ' };

                while ((lol = Tr.ReadLine()) != null)
                {
                    int j = 0;
                    chars = lol.Split(splitter, StringSplitOptions.RemoveEmptyEntries);
                    while (j < chars.Length)
                    {
                        listBox1.Items.Add(chars[j]);
                        j++;
                    }

                }
            }
            catch (Exception)
            {
            }

        }

        private void button5_Click(object sender, EventArgs e)
        {
            try
            {
                saveFileDialog1.ShowDialog();
                richTextBox1.SaveFile(saveFileDialog1.FileName,RichTextBoxStreamType.PlainText);
            }
            catch (Exception)
            {
            }
        }
    }
}
