Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Net;
- using System.IO;
- using System.Windows.Forms;
- using System.Diagnostics;
- namespace ESCFlashTool
- {
- public partial class Form1 : Form
- {
- String flashstring;
- String avrdude;
- String c;
- String programmer;
- String p;
- String chip;
- String flash;
- String firmware;
- //flashstring = avrdude+c+programmer+chip+flash+firmware
- public Form1()
- {
- InitializeComponent();
- flashstring = "";
- avrdude = "avrdude.exe";
- c = "-c";
- programmer = "";
- p = "-p";
- chip = "m8";
- flash = "flash:w:";
- firmware = "";
- }
- private void checkBox1_CheckedChanged(object sender, EventArgs e)
- {
- if (checkBox1.CheckState == CheckState.Checked)
- {
- comboBox1.SelectedIndex = comboBox1.Items.Count - 1;
- comboBox1.Enabled = false;
- textBox1.ReadOnly = false;
- textBox1.Text = "";
- }
- else
- {
- comboBox1.SelectedIndex = 0;
- comboBox1.Enabled = true;
- textBox1.ReadOnly = true;
- textBox1.Text = "";
- }
- }
- private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
- {
- if (comboBox1.SelectedIndex == comboBox1.Items.Count - 1) checkBox1.Checked = true;
- else programmer = comboBox1.Items[comboBox1.SelectedIndex].ToString();
- updFlashString();
- }
- private void checkBox2_CheckedChanged(object sender, EventArgs e)
- {
- if (checkBox2.CheckState == CheckState.Checked)
- {
- comboBox3.Enabled = true;
- panel3.Enabled = false;
- }
- else
- {
- panel3.Enabled = true;
- comboBox3.Enabled = false;
- }
- }
- private void button1_Click(object sender, EventArgs e)
- {
- List<string> files = DirectoryListing();
- for (int i = 0; i < files.Count; i++) treeView1.Nodes.Add(files[i]);
- }
- public List<string> DirectoryListing()
- {
- FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://www.tunerspotter.com/");
- request.Method = WebRequestMethods.Ftp.ListDirectory;
- request.Credentials = new NetworkCredential("escfirmware", "Hh314159");
- FtpWebResponse response = (FtpWebResponse)request.GetResponse();
- Stream responseStream = response.GetResponseStream();
- StreamReader reader = new StreamReader(responseStream);
- List<string> result = new List<string>();
- while (!reader.EndOfStream)
- {
- result.Add(reader.ReadLine());
- }
- reader.Close();
- response.Close();
- return result;
- }
- public void Download(string destination)
- {
- FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://www.tunerspotter.com/" + firmware);
- request.Method = WebRequestMethods.Ftp.DownloadFile;
- request.Credentials = new NetworkCredential("escfirmware", "Hh314159");
- FtpWebResponse response = (FtpWebResponse)request.GetResponse();
- Stream responseStream = response.GetResponseStream();
- StreamReader reader = new StreamReader(responseStream);
- StreamWriter writer = new StreamWriter(destination + "\\" + firmware);
- writer.Write(reader.ReadToEnd());
- writer.Close();
- reader.Close();
- response.Close();
- }
- public List<string> DirectoryListing(string folder)
- {
- FtpWebRequest request = (FtpWebRequest)WebRequest.Create("tunerspotter.com" + folder);
- request.Method = WebRequestMethods.Ftp.ListDirectory;
- request.Credentials = new NetworkCredential("escfirmware", "Hh314159");
- FtpWebResponse response = (FtpWebResponse)request.GetResponse();
- Stream responsestream = response.GetResponseStream();
- StreamReader reader = new StreamReader(responsestream);
- List<string> result = new List<string>();
- while (!reader.EndOfStream) result.Add(reader.ReadLine());
- reader.Close();
- response.Close();
- return result;
- }
- private void checkBox3_CheckedChanged(object sender, EventArgs e)
- {
- if (checkBox3.CheckState == CheckState.Checked)
- {
- panel2.Enabled = false;
- treeView1.Enabled = true;
- button1.Enabled = true;
- }
- else
- {
- panel2.Enabled = true;
- treeView1.Enabled = false;
- treeView1.Enabled = false;
- }
- }
- /*
- *
- * String flashstring;
- String avrdude;
- String c;
- String programmer;
- String p;
- String chip;
- String flash;
- String firmware;
- //flashstring = avrdude+c+programmer+chip+flash+firmware
- public Form1()
- {
- InitializeComponent();
- flashstring = "";
- avrdude = "avrdude.exe";
- c = "-c";
- programmer = "";
- p = "-p";
- chip = "m8";
- flash = "flash:w:";
- firmware = "";
- }*/
- private void button2_Click(object sender, EventArgs e)
- {
- try
- {
- textBox4.Text = "";
- System.IO.Directory.SetCurrentDirectory(Application.StartupPath);
- new System.Security.Permissions.FileIOPermission(System.Security.Permissions.FileIOPermissionAccess.AllAccess, Application.StartupPath).Demand();
- Download(Application.StartupPath);
- System.Diagnostics.ProcessStartInfo procStartInfo = new System.Diagnostics.ProcessStartInfo("avrdude.exe", " " + flashstring.Replace(avrdude, "") /*+ " & pause"*/);
- procStartInfo.WorkingDirectory = Application.StartupPath;
- procStartInfo.RedirectStandardOutput = true;
- procStartInfo.RedirectStandardError = true;
- procStartInfo.UseShellExecute = false;
- procStartInfo.CreateNoWindow = true;
- System.Diagnostics.Process proc = new System.Diagnostics.Process();
- proc.StartInfo = procStartInfo;
- proc.EnableRaisingEvents = true;
- proc.Start();
- StreamReader reader = proc.StandardOutput;
- StreamReader errorreader = proc.StandardError;
- textBox4.Text = reader.ReadToEnd();
- textBox4.Text += "\r\n\r\n\r\n________________________________\r\n" + errorreader.ReadToEnd();
- proc.WaitForExit();
- }
- catch (Exception ex)
- {
- textBox4.Text = ex.Message;
- }
- }
- private void updFlashString()
- {
- flashstring = avrdude + " " + c + " " + programmer + " " + p + " " + chip + " " + flash + firmware;
- textBox5.Text = flashstring;
- }
- private void textBox1_TextChanged(object sender, EventArgs e)
- {
- if (checkBox1.CheckState == CheckState.Checked)
- {
- programmer = textBox1.Text;
- updFlashString();
- }
- }
- private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
- {
- firmware = comboBox3.Items[comboBox3.SelectedIndex].ToString();
- updFlashString();
- }
- /*
- *0 tp.hex
- 1 tgy.hex
- 2 tp_nfet.hex
- 3 bs_nfet.hex
- 4 bs.hex
- 5 m40a.hex
- 6 tgy6a.hex
- 7 rct50a.hex
- * */
- private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
- {
- if (comboBox2.SelectedIndex == 0) comboBox3.SelectedIndex = 0;
- if (comboBox2.SelectedIndex == 1) comboBox3.SelectedIndex = 1;
- if (comboBox2.SelectedIndex == 2) comboBox3.SelectedIndex = 0;
- if (comboBox2.SelectedIndex == 3) comboBox3.SelectedIndex = 1;
- if (comboBox2.SelectedIndex == 4) comboBox3.SelectedIndex = 2;
- if (comboBox2.SelectedIndex == 5) comboBox3.SelectedIndex = 3;
- if (comboBox2.SelectedIndex == 6) comboBox3.SelectedIndex = 3;
- if (comboBox2.SelectedIndex == 7) comboBox3.SelectedIndex = 3;
- if (comboBox2.SelectedIndex == 8) comboBox3.SelectedIndex = 4;
- if (comboBox2.SelectedIndex == 10) comboBox3.SelectedIndex = 3;
- if (comboBox2.SelectedIndex == 20) comboBox3.SelectedIndex = 5;
- if (comboBox2.SelectedIndex == 21) comboBox3.SelectedIndex = 6;
- if (comboBox2.SelectedIndex == 22) comboBox3.SelectedIndex = 1;
- if (comboBox2.SelectedIndex == 23) comboBox3.SelectedIndex = 1;
- if (comboBox2.SelectedIndex == 24) comboBox3.SelectedIndex = 1;
- if (comboBox2.SelectedIndex == 25) comboBox3.SelectedIndex = 1;
- if (comboBox2.SelectedIndex == 26) comboBox3.SelectedIndex = 1;
- if (comboBox2.SelectedIndex == 27) comboBox3.SelectedIndex = 1;
- if (comboBox2.SelectedIndex == 28) comboBox3.SelectedIndex = 1;
- if (comboBox2.SelectedIndex == 29) comboBox3.SelectedIndex = 7;
- if (comboBox2.SelectedIndex == 30) comboBox3.SelectedIndex = 1;
- updFlashString();
- }
- private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
- {
- firmware = treeView1.SelectedNode.Text;
- updFlashString();
- }
- private void exitToolStripMenuItem_Click(object sender, EventArgs e)
- {
- Application.Exit();
- }
- private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
- {
- MessageBox.Show("ESC Flash Tool created by chatch15117");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement