Merge pull request #3903 from Mailaender/gameinit-redundancy

Removed the now redundant per mod Install/DownloadPackagesLogic
This commit is contained in:
Paul Chote
2013-10-12 14:38:13 -07:00
13 changed files with 44 additions and 246 deletions

View File

@@ -19,33 +19,13 @@ namespace OpenRA
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;
}
public static string FormatErrorMessage(Exception e)
{
var ex = e as System.Net.WebException;
if (ex == null) return e.Message;
if (ex == null)
return e.Message;
switch(ex.Status)
switch (ex.Status)
{
case WebExceptionStatus.NameResolutionFailure:
case WebExceptionStatus.Timeout:
@@ -57,5 +37,26 @@ namespace OpenRA
return ex.Message;
}
}
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;
}
}
}