Fix crash when canceling download, fix a runtime warning in osx.
This commit is contained in:
@@ -49,9 +49,9 @@
|
|||||||
|
|
||||||
- (void)launchFilePicker:(NSArray *)args
|
- (void)launchFilePicker:(NSArray *)args
|
||||||
{
|
{
|
||||||
hide_menubar_if_necessary();
|
|
||||||
[NSApp activateIgnoringOtherApps:YES];
|
[NSApp activateIgnoringOtherApps:YES];
|
||||||
|
hide_menubar_if_necessary();
|
||||||
|
|
||||||
NSOpenPanel *op = [NSOpenPanel openPanel];
|
NSOpenPanel *op = [NSOpenPanel openPanel];
|
||||||
[op setLevel:CGShieldingWindowLevel()];
|
[op setLevel:CGShieldingWindowLevel()];
|
||||||
[op setAllowsMultipleSelection:NO];
|
[op setAllowsMultipleSelection:NO];
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -89,18 +89,21 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
|
|||||||
|
|
||||||
// TODO: Download to a temp location or the support dir
|
// TODO: Download to a temp location or the support dir
|
||||||
var file = Info.PackageName;
|
var file = Info.PackageName;
|
||||||
|
|
||||||
var dl = DownloadUrl(Info.PackageURL, file,
|
var dl = new Download(Info.PackageURL, file,
|
||||||
i => {
|
i => {
|
||||||
status.GetText = () => "Downloading {1}/{2} kB ({0}%)".F(i.ProgressPercentage, i.BytesReceived/1024, i.TotalBytesToReceive/1024);
|
status.GetText = () => "Downloading {1}/{2} kB ({0}%)".F(i.ProgressPercentage, i.BytesReceived/1024, i.TotalBytesToReceive/1024);
|
||||||
progress.Percentage = i.ProgressPercentage;
|
progress.Percentage = i.ProgressPercentage;
|
||||||
},
|
},
|
||||||
|
(i, cancelled) => {
|
||||||
System.Console.WriteLine("here");
|
System.Console.WriteLine("here");
|
||||||
if (i.Error != null)
|
if (i.Error != null)
|
||||||
|
{
|
||||||
System.Console.WriteLine("here2");
|
System.Console.WriteLine("here2");
|
||||||
ShowDownloadError(i.Error.Message);
|
ShowDownloadError(i.Error.Message);
|
||||||
}
|
}
|
||||||
else if (!cancelled)
|
else if (!cancelled)
|
||||||
|
{
|
||||||
System.Console.WriteLine("here3");
|
System.Console.WriteLine("here3");
|
||||||
// Automatically extract
|
// Automatically extract
|
||||||
status.GetText = () => "Extracting...";
|
status.GetText = () => "Extracting...";
|
||||||
@@ -120,8 +123,8 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
window.GetWidget("CANCEL").OnMouseUp = mi => { dl.CancelAsync(); ShowInstallMethodDialog(); return true; };
|
window.GetWidget("CANCEL").OnMouseUp = mi => { dl.Cancel(); ShowInstallMethodDialog(); return true; };
|
||||||
window.GetWidget("RETRY").OnMouseUp = mi => { dl.Cancel(); ShowDownloadDialog(); return true; };
|
window.GetWidget("RETRY").OnMouseUp = mi => { dl.Cancel(); ShowDownloadDialog(); return true; };
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,17 +141,33 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
|
|||||||
Widget.RootWidget.Children.Remove(widget);
|
Widget.RootWidget.Children.Remove(widget);
|
||||||
Widget.OpenWindow("MAINMENU_BG");
|
Widget.OpenWindow("MAINMENU_BG");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// General support methods
|
||||||
public class Download
|
public class Download
|
||||||
{
|
{
|
||||||
WebClient wc = new WebClient();
|
WebClient wc;
|
||||||
wc.Proxy = null;
|
bool cancelled;
|
||||||
|
|
||||||
wc.DownloadProgressChanged += onProgress;
|
public Download(string url, string path, Action<DownloadProgressChangedEventArgs> onProgress, Action<AsyncCompletedEventArgs, bool> onComplete)
|
||||||
wc.DownloadFileCompleted += onComplete;
|
{
|
||||||
wc.DownloadFileCompleted += (_,a) => {Game.OnQuit -= () => wc.CancelAsync();};
|
wc = new WebClient();
|
||||||
wc.DownloadFileAsync(new Uri(url), path);
|
wc.Proxy = null;
|
||||||
Game.OnQuit += () => wc.CancelAsync();
|
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user