From e0fb6e4522020ec37e60014ef17fff8d432cc0c5 Mon Sep 17 00:00:00 2001 From: Alexander Dzhoganov Date: Mon, 17 Nov 2014 20:56:13 +0200 Subject: [PATCH] first steps into dialogless GUI --- ModuleInstaller.cs | 9 +++++++-- Net/NetAsyncDownloader.cs | 13 +++++++++---- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/ModuleInstaller.cs b/ModuleInstaller.cs index d8715a1fc9..1e0ae7785f 100644 --- a/ModuleInstaller.cs +++ b/ModuleInstaller.cs @@ -157,7 +157,8 @@ public static string CachedOrDownload(string identifier, Version version, Uri ur // TODO: Break this up into smaller pieces! It's huge! public void InstallList( List modules, - RelationshipResolverOptions options + RelationshipResolverOptions options, + NetAsyncDownloader downloader = null ) { onReportProgress = onReportProgress ?? ((message, progress) => { }); @@ -195,7 +196,11 @@ RelationshipResolverOptions options if (downloads.Count > 0) { - var downloader = new NetAsyncDownloader(); + if (downloader == null) + { + downloader = new NetAsyncDownloader(); + } + downloader.DownloadModules(ksp.Cache, downloads, onReportProgress); } diff --git a/Net/NetAsyncDownloader.cs b/Net/NetAsyncDownloader.cs index 5c4b723307..fe3ec75bd7 100644 --- a/Net/NetAsyncDownloader.cs +++ b/Net/NetAsyncDownloader.cs @@ -159,6 +159,11 @@ public void DownloadModules( // If the user cancelled our progress, then signal that. if (downloadCanceled) { + foreach (var download in downloads) + { + download.agent.CancelAsync(); + } + throw new CancelledActionKraken("Download cancelled by user"); } @@ -242,17 +247,17 @@ public void CancelDownload() { log.Debug("Cancelling download"); - foreach (var download in downloads) + downloadCanceled = true; + + lock (download_complete_lock) { - download.agent.CancelAsync(); + Monitor.Pulse(download_complete_lock); } if (onCompleted != null) { onCompleted(null, null, null); } - - downloadCanceled = true; } ///