Skip to content

Commit

Permalink
Increase Download Progress Prompt #5
Browse files Browse the repository at this point in the history
  • Loading branch information
Manu098vm authored Oct 10, 2024
2 parents eb0746a + b70c300 commit 65e690e
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions SwitchGiftDataManager.WinForm/MgdbForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,31 @@ private async Task DownloadRepoMGDB()
Directory.CreateDirectory(path);

var zipPath = Path.Combine(path, "tmp.zip");
using (var response = await client.GetAsync(url))
using (var response = await client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead))
{
var totalBytes = response.Content.Headers.ContentLength ?? 0;
using (var content = await response.Content.ReadAsStreamAsync())
using (var stream = new FileStream(zipPath, FileMode.Create, FileAccess.Write, FileShare.None))
{
using (var stream = new FileStream(zipPath, FileMode.Create, FileAccess.Write, FileShare.None))
var buffer = new byte[8192];
int bytesRead;
long totalRead = 0;
while ((bytesRead = await content.ReadAsync(buffer, 0, buffer.Length)) > 0)
{
await content.CopyToAsync(stream);
await stream.WriteAsync(buffer, 0, bytesRead);
totalRead += bytesRead;
// Calculate and display progress
if (totalBytes > 0)
{
double progressPercentage = (double)totalRead / totalBytes * 100;
// Update UI or log progress here
lblMessage.Text = $"Download progress: {progressPercentage:F2}%";
}
}
}
}


ZipFile.ExtractToDirectory(zipPath, path);
File.Delete(zipPath);

Expand Down

0 comments on commit 65e690e

Please sign in to comment.