Skip to content
This repository has been archived by the owner on Jul 9, 2024. It is now read-only.

Commit

Permalink
Backend: Fixed poor download code calling.
Browse files Browse the repository at this point in the history
Might fix hang issue reported by a few.
  • Loading branch information
Helios747 committed Nov 18, 2015
1 parent 671670c commit 3536009
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 41 deletions.
58 changes: 25 additions & 33 deletions DolphinBisectTool/Backend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Backend
// Follow this format: (Major).0
public static string s_major_version = "4.0";
bool m_download_complete = false;
List<int> m_build_list = new List<int>();
public List<int> m_build_list = new List<int>();
MainWindow m_form;

public Backend()
Expand Down Expand Up @@ -92,39 +92,31 @@ public void SetSettings(int first, int second, string path, MainWindow f)
m_form = f;
}

public void DownloadBuildList(MainWindow form)
public void new_DownloadBuildList()
{
using (WebClient client = new WebClient())
client.DownloadFile(new Uri("https://dl.dolphin-emu.org/builds/"),
"buildindex");
}

public void new_ProcessBuildList()
{
List<int> result = new List<int>();
using (var client = new WebClient())
{
client.DownloadFileAsync(new Uri("https://dl.dolphin-emu.org/builds/"),
"buildindex");
Regex regex = new Regex(@"(?<=dolphin-master-" + s_major_version + @"-)(\d{1,4})(?=-x64.7z)");

client.DownloadProgressChanged += (s, e) =>
using (StreamReader reader = new StreamReader("buildindex"))
{
string current_line;
while ((current_line = reader.ReadLine()) != null)
{
form.ChangeProgressBar(e.ProgressPercentage, "Downloading build index");
};
int stripped_build_num;
int.TryParse(regex.Match(current_line).Value, out stripped_build_num);
if (stripped_build_num != 0)
result.Add(stripped_build_num);
}

client.DownloadFileCompleted += (s, e) =>
{
Regex regex = new Regex(@"(?<=dolphin-master-" + s_major_version + @"-)(\d{1,4})(?=-x64.7z)");

using (var reader = new StreamReader("buildindex"))
{
string currentLine;
while ((currentLine = reader.ReadLine()) != null)
{
int stripped_build_num;
int.TryParse(regex.Match(currentLine).Value, out stripped_build_num);
if (stripped_build_num != 0)
result.Add(stripped_build_num);
}

result.Sort();
m_build_list = result;
form.PopulateComboBoxes(result);
}
};
result.Sort();
m_build_list = result;
}
}

Expand All @@ -142,23 +134,23 @@ private void DownloadBuild(string url, int index)
{
}

using (var client = new WebClient())
using (WebClient client = new WebClient())
{
client.DownloadFileAsync(new Uri(url), "dolphin.7z");

client.DownloadProgressChanged += (s, e) =>
{
m_form.ChangeProgressBar(e.ProgressPercentage, "Downloading build " +
m_build_list.ElementAt(index));
m_build_list.ElementAt(index));
};

client.DownloadFileCompleted += (s, e) =>
{
// Known Bug: Sometimes the label doesn't get updated before it extracts and
// launches. I want to blame this meh-level 7z lib blocking something.
m_form.ChangeProgressBar(0, "Extracting and launching");
SevenZipExtractor DolphinZip = new SevenZipExtractor(@"dolphin.7z");
DolphinZip.ExtractArchive("dolphin");
SevenZipExtractor dolphin_zip = new SevenZipExtractor(@"dolphin.7z");
dolphin_zip.ExtractArchive("dolphin");
m_download_complete = true;
};
}
Expand Down
30 changes: 23 additions & 7 deletions DolphinBisectTool/MainWindow.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows.Forms;

namespace DolphinBisectTool
Expand All @@ -11,8 +12,26 @@ public partial class MainWindow : Form
public MainWindow()
{
InitializeComponent();
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
m_backend.DownloadBuildList(this);
FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;

download_label.Text = "Downloading build index";
download_label.Visible = true;

BackgroundWorker bw = new BackgroundWorker();
bw.DoWork += PostLoadTasks;
bw.RunWorkerCompleted += PostLoadTasksCompleted;
bw.RunWorkerAsync();
}

private void PostLoadTasks(object sender, DoWorkEventArgs e)
{
m_backend.new_DownloadBuildList();
m_backend.new_ProcessBuildList();
}

private void PostLoadTasksCompleted(object sender, RunWorkerCompletedEventArgs e)
{
PopulateComboBoxes(m_backend.m_build_list);
}

private void btnBrowse_Click(object sender, EventArgs e)
Expand Down Expand Up @@ -86,10 +105,6 @@ public void ChangeProgressBar(int v, string t)
{
if (v != 100)
{
// Known bug - Downloading build index doesn't update progress bar
// properly. Reason for this I believe is because the WebClient doesn't
// know how large the file is.

download_bar.Visible = true;
download_label.Text = t;
download_label.Visible = true;
Expand All @@ -102,7 +117,7 @@ public void ChangeProgressBar(int v, string t)
}
}

public void PopulateComboBoxes(List<int> l)
private void PopulateComboBoxes(List<int> l)
{
foreach (int i in l)
{
Expand All @@ -127,6 +142,7 @@ private void EnableUI()
start_button.Enabled = true;
radio_development.Enabled = true;
radio_stable.Enabled = true;
download_label.Visible = false;
}

private void rbFirstStable_CheckedChanged(object sender, EventArgs e)
Expand Down
2 changes: 1 addition & 1 deletion DolphinBisectTool/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ static void Main()
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainWindow());
}
}
}
}

0 comments on commit 3536009

Please sign in to comment.