Skip to content

Commit

Permalink
Merge pull request #297 from sickboy/feature/download-progress-report…
Browse files Browse the repository at this point in the history
…ing-fix

Fix progress component
  • Loading branch information
anaisbetts committed Apr 6, 2015
2 parents ab68d60 + 4452ae9 commit 6cda75f
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions src/Squirrel/UpdateManager.DownloadReleases.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,21 @@ public async Task DownloadReleases(string updateUrlOrPath, IEnumerable<ReleaseEn
urlDownloader = urlDownloader ?? new FileDownloader();
var packagesDirectory = Path.Combine(rootAppDirectory, "packages");

int current = 0;
int toIncrement = (int)(100.0 / releasesToDownload.Count());
double current = 0;
double toIncrement = 100.0 / releasesToDownload.Count();

if (Utility.IsHttpUrl(updateUrlOrPath)) {
// From Internet
await releasesToDownload.ForEachAsync(async x => {
var targetFile = Path.Combine(packagesDirectory, x.Filename);
var component = 0;
double component = 0;
await downloadRelease(updateUrlOrPath, x, urlDownloader, targetFile, p => {
lock (progress) {
if (p == 0) {
if (component <= 0) return;
progress(current -= component);
component = 0;
} else {
progress(current += component += (int) (toIncrement/100.0*p));
}
current -= component;
component = toIncrement / 100.0 * p;
progress((int)Math.Round(current += component));
}
});

});
} else {
// From Disk
Expand All @@ -54,9 +49,9 @@ await releasesToDownload.ForEachAsync(x => {
File.Copy(
Path.Combine(updateUrlOrPath, x.Filename),
targetFile,
true);
true);

lock (progress) progress(current += toIncrement);
lock (progress) progress((int)Math.Round(current += toIncrement));
});
}
}
Expand Down

0 comments on commit 6cda75f

Please sign in to comment.