namespace HardwareUtility { using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.IO; using System.Net; using System.Text.RegularExpressions; public partial class frmFirmware : Form { public frmFirmware() { InitializeComponent(); ftpFirmwareList.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize); } public static string GetDirectoryListingRegexForUrl(string url) // get the files in the url directory and list in the textlist { if (url.Equals("http://website/subfolder/")) { return "<a href="\".*\"">(?<name>.*)</a>"; // [Ed. colouriser bug due to \""] } HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { using (StreamReader reader = new StreamReader(response.GetResponseStream())) { string html = reader.ReadToEnd(); Regex regex = new Regex(GetDirectoryListingRegexForUrl(url)); MatchCollection files = regex.Matches(html); if (files.Count > 0) { foreach (Match files in matches) { webFirmwareList.Items.Add(files.Groups[1]); } throw new NotSupportedException(); } } } } private void frmFirmware_Load(object sender, EventArgs e) { // use to get the application directory string appPath = System.IO.Directory.GetCurrentDirectory(); //Get the application directory // Combine the appPath the Firmware dir to create location path string firmwarePath = System.IO.Path.Combine(appPath, "Firmware\\"); listBox1.Items.Clear(); string[] files = Directory.GetFiles(firmwarePath); string[] dirs = Directory.GetDirectories(firmwarePath); foreach (string file in files) { listBox1.Items.Add(Path.GetFileNameWithoutExtension(file)); } } private void okButton_Click_1(object sender, EventArgs e) { this.Close(); } private void downloadButton_Click(object sender, EventArgs e) { // code to copy the new files into the local dir and delete the old file } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)