Advertisement
Guest User

Untitled

a guest
Jan 20th, 2012
1,226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 10.35 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Net;
  9. using System.IO;
  10. using System.Windows.Forms;
  11. using System.Diagnostics;
  12.  
  13. namespace ESCFlashTool
  14. {
  15.     public partial class Form1 : Form
  16.     {
  17.         String flashstring;
  18.         String avrdude;
  19.         String c;
  20.         String programmer;
  21.         String p;
  22.         String chip;
  23.         String flash;
  24.         String firmware;
  25.         //flashstring = avrdude+c+programmer+chip+flash+firmware
  26.         public Form1()
  27.         {
  28.             InitializeComponent();
  29.             flashstring = "";
  30.             avrdude = "avrdude.exe";
  31.             c = "-c";
  32.             programmer = "";
  33.             p = "-p";
  34.             chip = "m8";
  35.             flash = "flash:w:";
  36.             firmware = "";
  37.         }
  38.  
  39.         private void checkBox1_CheckedChanged(object sender, EventArgs e)
  40.         {
  41.             if (checkBox1.CheckState == CheckState.Checked)
  42.             {
  43.                 comboBox1.SelectedIndex = comboBox1.Items.Count - 1;
  44.                 comboBox1.Enabled = false;
  45.                 textBox1.ReadOnly = false;
  46.                 textBox1.Text = "";
  47.             }
  48.             else
  49.             {
  50.                 comboBox1.SelectedIndex = 0;
  51.                 comboBox1.Enabled = true;
  52.                 textBox1.ReadOnly = true;
  53.                 textBox1.Text = "";
  54.             }
  55.         }
  56.  
  57.         private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
  58.         {
  59.             if (comboBox1.SelectedIndex == comboBox1.Items.Count - 1) checkBox1.Checked = true;
  60.             else programmer = comboBox1.Items[comboBox1.SelectedIndex].ToString();
  61.             updFlashString();
  62.         }
  63.  
  64.         private void checkBox2_CheckedChanged(object sender, EventArgs e)
  65.         {
  66.             if (checkBox2.CheckState == CheckState.Checked)
  67.             {
  68.                 comboBox3.Enabled = true;
  69.                 panel3.Enabled = false;
  70.             }
  71.             else
  72.             {
  73.                 panel3.Enabled = true;
  74.                 comboBox3.Enabled = false;
  75.             }
  76.         }
  77.  
  78.         private void button1_Click(object sender, EventArgs e)
  79.         {
  80.             List<string> files = DirectoryListing();
  81.             for (int i = 0; i < files.Count; i++) treeView1.Nodes.Add(files[i]);
  82.         }
  83.  
  84.         public List<string> DirectoryListing()
  85.         {
  86.             FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://www.tunerspotter.com/");
  87.             request.Method = WebRequestMethods.Ftp.ListDirectory;
  88.             request.Credentials = new NetworkCredential("escfirmware", "Hh314159");
  89.             FtpWebResponse response = (FtpWebResponse)request.GetResponse();
  90.             Stream responseStream = response.GetResponseStream();
  91.             StreamReader reader = new StreamReader(responseStream);
  92.  
  93.             List<string> result = new List<string>();
  94.  
  95.             while (!reader.EndOfStream)
  96.             {
  97.                 result.Add(reader.ReadLine());
  98.             }
  99.             reader.Close();
  100.             response.Close();
  101.             return result;
  102.         }
  103.  
  104.         public void Download(string destination)
  105.         {
  106.             FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://www.tunerspotter.com/" + firmware);
  107.             request.Method = WebRequestMethods.Ftp.DownloadFile;
  108.             request.Credentials = new NetworkCredential("escfirmware", "Hh314159");
  109.             FtpWebResponse response = (FtpWebResponse)request.GetResponse();
  110.             Stream responseStream = response.GetResponseStream();
  111.             StreamReader reader = new StreamReader(responseStream);
  112.  
  113.             StreamWriter writer = new StreamWriter(destination + "\\" + firmware);
  114.             writer.Write(reader.ReadToEnd());
  115.  
  116.             writer.Close();
  117.             reader.Close();
  118.             response.Close();
  119.         }
  120.  
  121.         public List<string> DirectoryListing(string folder)
  122.         {
  123.             FtpWebRequest request = (FtpWebRequest)WebRequest.Create("tunerspotter.com" + folder);
  124.             request.Method = WebRequestMethods.Ftp.ListDirectory;
  125.             request.Credentials = new NetworkCredential("escfirmware", "Hh314159");
  126.             FtpWebResponse response = (FtpWebResponse)request.GetResponse();
  127.             Stream responsestream = response.GetResponseStream();
  128.             StreamReader reader = new StreamReader(responsestream);
  129.  
  130.             List<string> result = new List<string>();
  131.  
  132.             while (!reader.EndOfStream) result.Add(reader.ReadLine());
  133.             reader.Close();
  134.             response.Close();
  135.             return result;
  136.         }
  137.  
  138.         private void checkBox3_CheckedChanged(object sender, EventArgs e)
  139.         {
  140.             if (checkBox3.CheckState == CheckState.Checked)
  141.             {
  142.                 panel2.Enabled = false;
  143.                 treeView1.Enabled = true;
  144.                 button1.Enabled = true;
  145.             }
  146.             else
  147.             {
  148.                 panel2.Enabled = true;
  149.                 treeView1.Enabled = false;
  150.                 treeView1.Enabled = false;
  151.             }
  152.         }
  153.  
  154.         /*
  155.          *
  156.          * String flashstring;
  157.         String avrdude;
  158.         String c;
  159.         String programmer;
  160.         String p;
  161.         String chip;
  162.         String flash;
  163.         String firmware;
  164.         //flashstring = avrdude+c+programmer+chip+flash+firmware
  165.         public Form1()
  166.         {
  167.             InitializeComponent();
  168.             flashstring = "";
  169.             avrdude = "avrdude.exe";
  170.             c = "-c";
  171.             programmer = "";
  172.             p = "-p";
  173.             chip = "m8";
  174.             flash = "flash:w:";
  175.             firmware = "";
  176.         }*/
  177.  
  178.         private void button2_Click(object sender, EventArgs e)
  179.         {
  180.             try
  181.             {
  182.                 textBox4.Text = "";
  183.                 System.IO.Directory.SetCurrentDirectory(Application.StartupPath);
  184.                 new System.Security.Permissions.FileIOPermission(System.Security.Permissions.FileIOPermissionAccess.AllAccess, Application.StartupPath).Demand();
  185.                 Download(Application.StartupPath);
  186.                 System.Diagnostics.ProcessStartInfo procStartInfo = new System.Diagnostics.ProcessStartInfo("avrdude.exe", " " + flashstring.Replace(avrdude, "") /*+ " & pause"*/);
  187.                 procStartInfo.WorkingDirectory = Application.StartupPath;
  188.                 procStartInfo.RedirectStandardOutput = true;
  189.                 procStartInfo.RedirectStandardError = true;
  190.                 procStartInfo.UseShellExecute = false;
  191.                 procStartInfo.CreateNoWindow = true;
  192.                 System.Diagnostics.Process proc = new System.Diagnostics.Process();
  193.                 proc.StartInfo = procStartInfo;
  194.                 proc.EnableRaisingEvents = true;
  195.                 proc.Start();
  196.                 StreamReader reader = proc.StandardOutput;
  197.                 StreamReader errorreader = proc.StandardError;
  198.                 textBox4.Text = reader.ReadToEnd();
  199.                 textBox4.Text += "\r\n\r\n\r\n________________________________\r\n" + errorreader.ReadToEnd();
  200.  
  201.                 proc.WaitForExit();
  202.             }
  203.             catch (Exception ex)
  204.             {
  205.                 textBox4.Text = ex.Message;
  206.             }
  207.         }
  208.  
  209.         private void updFlashString()
  210.         {
  211.             flashstring = avrdude + " " + c + " " + programmer + " " + p + " " + chip + " " + flash + firmware;
  212.             textBox5.Text = flashstring;
  213.         }
  214.  
  215.         private void textBox1_TextChanged(object sender, EventArgs e)
  216.         {
  217.             if (checkBox1.CheckState == CheckState.Checked)
  218.             {
  219.                 programmer = textBox1.Text;
  220.                 updFlashString();
  221.             }
  222.         }
  223.  
  224.         private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
  225.         {
  226.             firmware = comboBox3.Items[comboBox3.SelectedIndex].ToString();
  227.             updFlashString();
  228.         }
  229.         /*
  230.          *0 tp.hex
  231. 1 tgy.hex
  232. 2 tp_nfet.hex
  233. 3 bs_nfet.hex
  234. 4 bs.hex
  235. 5 m40a.hex
  236. 6 tgy6a.hex
  237. 7 rct50a.hex
  238.          * */
  239.         private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
  240.         {
  241.             if (comboBox2.SelectedIndex == 0) comboBox3.SelectedIndex = 0;
  242.             if (comboBox2.SelectedIndex == 1) comboBox3.SelectedIndex = 1;
  243.             if (comboBox2.SelectedIndex == 2) comboBox3.SelectedIndex = 0;
  244.             if (comboBox2.SelectedIndex == 3) comboBox3.SelectedIndex = 1;
  245.             if (comboBox2.SelectedIndex == 4) comboBox3.SelectedIndex = 2;
  246.             if (comboBox2.SelectedIndex == 5) comboBox3.SelectedIndex = 3;
  247.             if (comboBox2.SelectedIndex == 6) comboBox3.SelectedIndex = 3;
  248.             if (comboBox2.SelectedIndex == 7) comboBox3.SelectedIndex = 3;
  249.             if (comboBox2.SelectedIndex == 8) comboBox3.SelectedIndex = 4;
  250.             if (comboBox2.SelectedIndex == 10) comboBox3.SelectedIndex = 3;
  251.             if (comboBox2.SelectedIndex == 20) comboBox3.SelectedIndex = 5;
  252.             if (comboBox2.SelectedIndex == 21) comboBox3.SelectedIndex = 6;
  253.             if (comboBox2.SelectedIndex == 22) comboBox3.SelectedIndex = 1;
  254.             if (comboBox2.SelectedIndex == 23) comboBox3.SelectedIndex = 1;
  255.             if (comboBox2.SelectedIndex == 24) comboBox3.SelectedIndex = 1;
  256.             if (comboBox2.SelectedIndex == 25) comboBox3.SelectedIndex = 1;
  257.             if (comboBox2.SelectedIndex == 26) comboBox3.SelectedIndex = 1;
  258.             if (comboBox2.SelectedIndex == 27) comboBox3.SelectedIndex = 1;
  259.             if (comboBox2.SelectedIndex == 28) comboBox3.SelectedIndex = 1;
  260.             if (comboBox2.SelectedIndex == 29) comboBox3.SelectedIndex = 7;
  261.             if (comboBox2.SelectedIndex == 30) comboBox3.SelectedIndex = 1;
  262.  
  263.  
  264.  
  265.             updFlashString();
  266.         }
  267.  
  268.         private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
  269.         {
  270.             firmware = treeView1.SelectedNode.Text;
  271.             updFlashString();
  272.         }
  273.  
  274.         private void exitToolStripMenuItem_Click(object sender, EventArgs e)
  275.         {
  276.             Application.Exit();
  277.         }
  278.  
  279.         private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
  280.         {
  281.             MessageBox.Show("ESC Flash Tool created by chatch15117");
  282.         }
  283.     }
  284. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement