DownloadReleases into its own class

This commit is contained in:
Paul Betts
2014-08-08 12:38:50 +02:00
parent 2ec9192ef9
commit 9c50cbc7f4
2 changed files with 14 additions and 3 deletions

View File

@@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@@ -11,13 +12,22 @@ namespace Squirrel
{ {
class DownloadReleases : IEnableLogger class DownloadReleases : IEnableLogger
{ {
public async Task DownloadReleases(IEnumerable<ReleaseEntry> releasesToDownload, Action<int> progress = null) readonly string rootAppDirectory;
public DownloadReleases(string rootAppDirectory)
{
this.rootAppDirectory = rootAppDirectory;
}
public async Task DownloadReleases(string updateUrlOrPath, IEnumerable<ReleaseEntry> releasesToDownload, Action<int> progress = null, IFileDownloader urlDownloader = null)
{ {
progress = progress ?? (_ => { }); progress = progress ?? (_ => { });
urlDownloader = urlDownloader ?? new FileDownloader();
int current = 0; int current = 0;
int toIncrement = (int)(100.0 / releasesToDownload.Count()); int toIncrement = (int)(100.0 / releasesToDownload.Count());
if (isHttpUrl(updateUrlOrPath)) { if (Utility.IsHttpUrl(updateUrlOrPath)) {
await releasesToDownload.ForEachAsync(async x => { await releasesToDownload.ForEachAsync(async x => {
await urlDownloader.DownloadFile( await urlDownloader.DownloadFile(
String.Format("{0}/{1}", updateUrlOrPath, x.Filename), String.Format("{0}/{1}", updateUrlOrPath, x.Filename),

View File

@@ -49,7 +49,8 @@ namespace Squirrel
public Task DownloadReleases(IEnumerable<ReleaseEntry> releasesToDownload, Action<int> progress = null) public Task DownloadReleases(IEnumerable<ReleaseEntry> releasesToDownload, Action<int> progress = null)
{ {
throw new NotImplementedException(); var downloadReleases = new DownloadReleases(rootAppDirectory);
return downloadReleases.DownloadReleases(updateUrlOrPath, releasesToDownload, progress, urlDownloader);
} }
public Task ApplyReleases(UpdateInfo updateInfo, Action<int> progress = null) public Task ApplyReleases(UpdateInfo updateInfo, Action<int> progress = null)