From 9c50cbc7f4f77cf3ae88e22e19aa7fbe179e4eab Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Fri, 8 Aug 2014 12:38:50 +0200 Subject: [PATCH] DownloadReleases into its own class --- src/Squirrel/UpdateManager.DownloadReleases.cs | 14 ++++++++++++-- src/Squirrel/UpdateManager.cs | 3 ++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/Squirrel/UpdateManager.DownloadReleases.cs b/src/Squirrel/UpdateManager.DownloadReleases.cs index 0f873144..679bc927 100644 --- a/src/Squirrel/UpdateManager.DownloadReleases.cs +++ b/src/Squirrel/UpdateManager.DownloadReleases.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -11,13 +12,22 @@ namespace Squirrel { class DownloadReleases : IEnableLogger { - public async Task DownloadReleases(IEnumerable releasesToDownload, Action progress = null) + readonly string rootAppDirectory; + + public DownloadReleases(string rootAppDirectory) + { + this.rootAppDirectory = rootAppDirectory; + } + + public async Task DownloadReleases(string updateUrlOrPath, IEnumerable releasesToDownload, Action progress = null, IFileDownloader urlDownloader = null) { progress = progress ?? (_ => { }); + urlDownloader = urlDownloader ?? new FileDownloader(); + int current = 0; int toIncrement = (int)(100.0 / releasesToDownload.Count()); - if (isHttpUrl(updateUrlOrPath)) { + if (Utility.IsHttpUrl(updateUrlOrPath)) { await releasesToDownload.ForEachAsync(async x => { await urlDownloader.DownloadFile( String.Format("{0}/{1}", updateUrlOrPath, x.Filename), diff --git a/src/Squirrel/UpdateManager.cs b/src/Squirrel/UpdateManager.cs index 092339ec..a9b35ee6 100644 --- a/src/Squirrel/UpdateManager.cs +++ b/src/Squirrel/UpdateManager.cs @@ -49,7 +49,8 @@ namespace Squirrel public Task DownloadReleases(IEnumerable releasesToDownload, Action progress = null) { - throw new NotImplementedException(); + var downloadReleases = new DownloadReleases(rootAppDirectory); + return downloadReleases.DownloadReleases(updateUrlOrPath, releasesToDownload, progress, urlDownloader); } public Task ApplyReleases(UpdateInfo updateInfo, Action progress = null)