Skip to content

Commit 6cda75f

Browse files
committed
Merge pull request #297 from sickboy/feature/download-progress-reporting-fix
Fix progress component
2 parents ab68d60 + 4452ae9 commit 6cda75f

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

src/Squirrel/UpdateManager.DownloadReleases.cs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,21 @@ public async Task DownloadReleases(string updateUrlOrPath, IEnumerable<ReleaseEn
2525
urlDownloader = urlDownloader ?? new FileDownloader();
2626
var packagesDirectory = Path.Combine(rootAppDirectory, "packages");
2727

28-
int current = 0;
29-
int toIncrement = (int)(100.0 / releasesToDownload.Count());
28+
double current = 0;
29+
double toIncrement = 100.0 / releasesToDownload.Count();
3030

3131
if (Utility.IsHttpUrl(updateUrlOrPath)) {
3232
// From Internet
3333
await releasesToDownload.ForEachAsync(async x => {
3434
var targetFile = Path.Combine(packagesDirectory, x.Filename);
35-
var component = 0;
35+
double component = 0;
3636
await downloadRelease(updateUrlOrPath, x, urlDownloader, targetFile, p => {
3737
lock (progress) {
38-
if (p == 0) {
39-
if (component <= 0) return;
40-
progress(current -= component);
41-
component = 0;
42-
} else {
43-
progress(current += component += (int) (toIncrement/100.0*p));
44-
}
38+
current -= component;
39+
component = toIncrement / 100.0 * p;
40+
progress((int)Math.Round(current += component));
4541
}
4642
});
47-
4843
});
4944
} else {
5045
// From Disk
@@ -54,9 +49,9 @@ await releasesToDownload.ForEachAsync(x => {
5449
File.Copy(
5550
Path.Combine(updateUrlOrPath, x.Filename),
5651
targetFile,
57-
true);
52+
true);
5853

59-
lock (progress) progress(current += toIncrement);
54+
lock (progress) progress((int)Math.Round(current += toIncrement));
6055
});
6156
}
6257
}

0 commit comments

Comments
 (0)