From 12daff4a35d8b18ba8507cf536d3bb6abdb6e64d Mon Sep 17 00:00:00 2001 From: Jamie Sinn Date: Wed, 21 Feb 2018 20:59:12 -0500 Subject: [PATCH] Local file support - No Spaces allowed --- CSAUSBTool/CSAUSBTool.cs | 3 +- CSAUSBTool/CSAUSBTool.csproj | 2 +- CSAUSBTool/ControlSystemsSoftware.cs | 17 +++++++---- CSAUSBTool/FRCYear.cs | 43 ++++++++++++++++++++++------ 4 files changed, 50 insertions(+), 15 deletions(-) diff --git a/CSAUSBTool/CSAUSBTool.cs b/CSAUSBTool/CSAUSBTool.cs index 259e522..43bc971 100644 --- a/CSAUSBTool/CSAUSBTool.cs +++ b/CSAUSBTool/CSAUSBTool.cs @@ -44,7 +44,8 @@ private void yearSelection_SelectedIndexChanged(object sender, EventArgs e) { if (yearSelection.SelectedItem.ToString().Equals("")) return; - selectedYear = int.Parse((string) yearSelection.SelectedItem); + KeyValuePair selected = (KeyValuePair) yearSelection.SelectedItem; + selectedYear = selected.Key; selectedFrc = competitions[selectedYear]; downloadFolder.Text = Directory.GetCurrentDirectory() + @"\" + selectedYear + @"\"; } diff --git a/CSAUSBTool/CSAUSBTool.csproj b/CSAUSBTool/CSAUSBTool.csproj index 242eb87..a629b31 100644 --- a/CSAUSBTool/CSAUSBTool.csproj +++ b/CSAUSBTool/CSAUSBTool.csproj @@ -41,7 +41,7 @@ 4 - AnyCPU + x86 pdbonly true bin\Release\ diff --git a/CSAUSBTool/ControlSystemsSoftware.cs b/CSAUSBTool/ControlSystemsSoftware.cs index 82668dd..21d17cd 100644 --- a/CSAUSBTool/ControlSystemsSoftware.cs +++ b/CSAUSBTool/ControlSystemsSoftware.cs @@ -1,14 +1,10 @@ using System; -using System.Collections.Generic; -using System.ComponentModel; using System.IO; using System.Linq; using System.Net; using System.Security.Cryptography; using System.IO.Compression; -using System.Text; using System.Threading; -using System.Threading.Tasks; namespace CSAUSBTool { @@ -35,10 +31,16 @@ public ControlSystemsSoftware(string name, string fileName, string url, string h public void Download(string path, DownloadProgressChangedEventHandler progress, bool async) { if (FileName == "") return; + if (Uri.ToString().StartsWith("local:")) + { + CopyLocal(Uri.ToString().Replace("local:", ""), path); + return; + } + using (WebClient client = new WebClient()) { client.DownloadProgressChanged += progress; - + client.DownloadFileCompleted += (sender, eventargs) => { Console.Out.WriteLine("Download finished for: " + Name); @@ -55,6 +57,11 @@ public void Download(string path, DownloadProgressChangedEventHandler progress, } } + public void CopyLocal(string sourcePath, string destPath) + { + File.Copy(sourcePath, destPath + @"\" + FileName); + } + public bool IsValid(string path) { string calc = CalculateMd5(path + @"\" + FileName); diff --git a/CSAUSBTool/FRCYear.cs b/CSAUSBTool/FRCYear.cs index 5b897fb..169dfc6 100644 --- a/CSAUSBTool/FRCYear.cs +++ b/CSAUSBTool/FRCYear.cs @@ -36,9 +36,11 @@ public void Download(string path, DownloadProgressChangedEventHandler progress, Console.Out.WriteLine(soft.FileName + " already exists in target directory, skipping."); continue; } + Console.Out.WriteLine("MD5 Hash for " + soft.FileName + " was not equal to the given hash. Redownloading."); } + soft.Download(path, progress, async); } } @@ -57,6 +59,7 @@ public void BuildISO(string sourcepath, string outputPath, ToolStripProgressBar progress.ProgressBar.Value += 100 / Software.Count; builder.AddFile(soft.FileName, sourcepath + @"\" + soft.FileName); } + builder.Build(outputPath + @"\" + builder.VolumeIdentifier + ".iso"); progress.ProgressBar.Value = 100; } @@ -69,19 +72,43 @@ public static List GetWebList(int year) public static List GetWebList(string uri) { - List ret = new List(); + if (uri.StartsWith("local:")) + { + return GetLocalList(uri.Replace("local:", "")); + } using (WebClient client = new WebClient()) { string data = client.DownloadString(new Uri(uri)); - string[] lines = data.Split('\n'); - foreach (var line in lines) - { - if (line.Equals("") || line.StartsWith("#")) continue; - string[] args = line.Split(','); - ret.Add(new ControlSystemsSoftware(args[0], args[1], args[2], args[3], bool.Parse(args[4]))); - } + List lines = data.Split('\n').ToList(); + return getFromCSV(lines); + } + } + + public static List GetLocalList(string uri) + { + + StreamReader file = new StreamReader(uri); + string line; + List lines = new List(); + while ((line = file.ReadLine()) != null) + { + lines.Add(line); } + return getFromCSV(lines); + } + + private static List getFromCSV(List lines) + { + List ret = new List(); + + foreach (string line in lines) + { + if (line.Equals("") || line.StartsWith("#")) continue; + string[] args = line.Split(','); + ret.Add(new ControlSystemsSoftware(args[0], args[1], args[2], args[3], bool.Parse(args[4]))); + } + return ret; }