Skip to content

Commit

Permalink
Medium improvements
Browse files Browse the repository at this point in the history
Async download list + improved status and logging output
  • Loading branch information
TylerVigario committed Jul 19, 2017
1 parent bfae4de commit 16a0c1a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 23 deletions.
44 changes: 23 additions & 21 deletions Download Free MS eBooks/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,23 @@ public MainForm()
private void MainForm_Load(object sender, EventArgs e)
{
wClient = new WebClient();
//
urls = downloadBookList();
if (urls == null)
{
return;
}
//
objectListView1.SetObjects(urls);
}

private List<Download> downloadBookList()
{
string temp;
wClient.DownloadStringCompleted += WClient_DownloadStringCompleted;
//
try
{
temp = wClient.DownloadString("https://drive.google.com/uc?export=download&id=0B-ULAF28Y63jY00wZEtWSmRTUWM");
wClient.DownloadStringAsync(new Uri("https://drive.google.com/uc?export=download&id=0B-ULAF28Y63jY00wZEtWSmRTUWM"));
}
catch (WebException)
{
MessageBox.Show("File list URL is down. Look for update from developer of this software.");
return null;
return;
}
//
string[] lines = temp.Split(new string[] { "\r\n", "\t\t" }, StringSplitOptions.None);
List<Download> urls = new List<Download>();
}

private void WClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
string[] lines = e.Result.Split(new string[] { "\r\n", "\t\t" }, StringSplitOptions.None);
urls = new List<Download>();
//
foreach (string line in lines)
{
Expand All @@ -67,12 +58,13 @@ private List<Download> downloadBookList()
}
catch (UriFormatException)
{
toolStripStatusLabel1.Text = "Invalid URL: " + parts[0];
LogLostFile(parts[0]);
}
}
}
//
return urls;
objectListView1.SetObjects(urls);
}

private void button1_Click(object sender, EventArgs e)
Expand All @@ -99,6 +91,7 @@ private void button1_Click(object sender, EventArgs e)
}
catch(WebException)
{
toolStripStatusLabel1.Text = "Error downloading: " + downloads[0].Name;
LogLostFile(downloads[0].URL.ToString());
}
//
Expand All @@ -107,6 +100,12 @@ private void button1_Click(object sender, EventArgs e)

private void WClient_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
if (e.Error != null)
{
toolStripStatusLabel1.Text = "Error downloading: " + downloads[0].Name;
LogLostFile(downloads[0].URL.ToString());
}
//
toolStripProgressBar1.PerformStep();
//
if (downloads.Count > 0)
Expand All @@ -119,6 +118,7 @@ private void WClient_DownloadFileCompleted(object sender, AsyncCompletedEventArg
}
catch (WebException)
{
toolStripStatusLabel1.Text = "Error downloading: " + downloads[0].Name;
LogLostFile(downloads[0].URL.ToString());
}
//
Expand All @@ -135,8 +135,10 @@ private void LogLostFile(string report)
{
if (!logYet)
{
File.AppendAllText(Application.StartupPath + "\\errors.log", " ======== Download Free MS eBooks v1.1 ========" + Environment.NewLine);
File.AppendAllText(Application.StartupPath + "\\errors.log", " == " + DateTime.Now.ToString() + Environment.NewLine);
File.AppendAllText(Application.StartupPath + "\\errors.log", "===========================================================" + Environment.NewLine);
File.AppendAllText(Application.StartupPath + "\\errors.log", " ======== Download Free MS eBooks v" + Application.ProductVersion + " ========" + Environment.NewLine);
File.AppendAllText(Application.StartupPath + "\\errors.log", " ======== " + DateTime.Now.ToString() + " ========" + Environment.NewLine);
File.AppendAllText(Application.StartupPath + "\\errors.log", "===========================================================" + Environment.NewLine);
logYet = true;
}
//
Expand Down
4 changes: 2 additions & 2 deletions Download Free MS eBooks/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.0.0")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyVersion("0.2.0.0")]
[assembly: AssemblyFileVersion("0.2.0.0")]

0 comments on commit 16a0c1a

Please sign in to comment.