Skip to content

Commit

Permalink
Local file support - No Spaces allowed
Browse files Browse the repository at this point in the history
  • Loading branch information
JamieSinn committed Feb 22, 2018
1 parent a27f3dc commit 12daff4
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 15 deletions.
3 changes: 2 additions & 1 deletion CSAUSBTool/CSAUSBTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<int, FRCYear> selected = (KeyValuePair<int, FRCYear>) yearSelection.SelectedItem;
selectedYear = selected.Key;
selectedFrc = competitions[selectedYear];
downloadFolder.Text = Directory.GetCurrentDirectory() + @"\" + selectedYear + @"\";
}
Expand Down
2 changes: 1 addition & 1 deletion CSAUSBTool/CSAUSBTool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<PlatformTarget>x86</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
Expand Down
17 changes: 12 additions & 5 deletions CSAUSBTool/ControlSystemsSoftware.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -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);
Expand All @@ -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);
Expand Down
43 changes: 35 additions & 8 deletions CSAUSBTool/FRCYear.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -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;
}
Expand All @@ -69,19 +72,43 @@ public static List<ControlSystemsSoftware> GetWebList(int year)

public static List<ControlSystemsSoftware> GetWebList(string uri)
{
List<ControlSystemsSoftware> ret = new List<ControlSystemsSoftware>();
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<string> lines = data.Split('\n').ToList();
return getFromCSV(lines);
}
}

public static List<ControlSystemsSoftware> GetLocalList(string uri)
{

StreamReader file = new StreamReader(uri);
string line;
List<string> lines = new List<string>();
while ((line = file.ReadLine()) != null)
{
lines.Add(line);
}
return getFromCSV(lines);
}

private static List<ControlSystemsSoftware> getFromCSV(List<string> lines)
{
List<ControlSystemsSoftware> ret = new List<ControlSystemsSoftware>();

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;
}

Expand Down

0 comments on commit 12daff4

Please sign in to comment.