Split the download/install logic into multiple files.

This commit is contained in:
Paul Chote
2011-05-18 22:50:38 +12:00
parent c76d2e37dc
commit 91a3aafa67
7 changed files with 290 additions and 234 deletions

View File

@@ -224,31 +224,4 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
new string[] { "cclocal.mix", "speech.mix", "tempicnh.mix", "updatec.mix" }, dest);
}
}
public class Download
{
WebClient wc;
bool cancelled;
public Download(string url, string path, Action<DownloadProgressChangedEventArgs> onProgress, Action<AsyncCompletedEventArgs, bool> onComplete)
{
wc = new WebClient();
wc.Proxy = null;
wc.DownloadProgressChanged += (_,a) => onProgress(a);
wc.DownloadFileCompleted += (_,a) => onComplete(a, cancelled);
Game.OnQuit += () => Cancel();
wc.DownloadFileCompleted += (_,a) => {Game.OnQuit -= () => Cancel();};
wc.DownloadFileAsync(new Uri(url), path);
}
public void Cancel()
{
Game.OnQuit -= () => Cancel();
wc.CancelAsync();
cancelled = true;
}
}
}