Skip to content

Commit

Permalink
Adjust demo app for showcase progress downloader
Browse files Browse the repository at this point in the history
  • Loading branch information
tekgator committed Dec 2, 2022
1 parent 052c880 commit c076e5a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,13 @@ ResetConsoleColor();

using var fileStream1 = File.Create("./server1.jar");
Progress<ProgressEventArgs> progress = new();
progress.ProgressChanged += (_, progress) => Console.Write($"\rProgress: {progress.ProgressPercentage}% ({progress.BytesTransferred / 1024 / 1024}MB / {progress.TotalBytes / 1024 / 1024}MB) ");
progress.ProgressChanged += (_, e) =>
{
Console.Write($"\rProgress: {e.ProgressPercentage}% ({e.BytesTransferred / 1024 / 1024}MB / {e.TotalBytes / 1024 / 1024}MB) ");
};
await serverJar.GetJar(fileStream1, "servers", "spigot", progress: progress);
await fileStream1.FlushAsync();
Console.WriteLine($"\nDownloaded {fileStream1.Length / 1024 / 1024}MB to {fileStream1.Name}");

// GetJar Method 2
SetConsoleColor(ConsoleColor.White, ConsoleColor.Red);
Expand All @@ -67,6 +72,7 @@ using (var stream = await serverJar.GetJar("servers", "spigot", "1.19.1"))
{
using var fileStream2 = File.Create("./server2.jar");
await stream.CopyToAsync(fileStream2);
Console.WriteLine($"Downloaded {fileStream2.Length / 1024 / 1024}MB to {fileStream2.Name}");
}
```

Expand Down
12 changes: 7 additions & 5 deletions ServerJars.Demo.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,28 +53,30 @@
Console.WriteLine("\nAPI call - GetJar with method 1 (with progress):\n");
ResetConsoleColor();


using var fileStream1 = File.Create("./server1.jar");
Progress<ProgressEventArgs> progress = new();
progress.ProgressChanged += (_, progress) =>
progress.ProgressChanged += (_, e) =>
{
Console.Write($"\rProgress: {progress.ProgressPercentage}% ({progress.BytesTransferred / 1024 / 1024}MB / {progress.TotalBytes / 1024 / 1024}MB) ");
Console.Write($"\rProgress: {e.ProgressPercentage}% ({e.BytesTransferred / 1024 / 1024}MB / {e.TotalBytes / 1024 / 1024}MB) ");
};
await serverJar.GetJar(fileStream1, "servers", "spigot", progress: progress);

await fileStream1.FlushAsync();
Console.WriteLine($"\nDownloaded {fileStream1.Length / 1024 / 1024}MB to {fileStream1.Name}");

// GetJar Method 2
SetConsoleColor(ConsoleColor.White, ConsoleColor.Red);
Console.WriteLine("\n\nAPI call - GetJar method 2:\n");
Console.WriteLine("\nAPI call - GetJar method 2:\n");
ResetConsoleColor();

using (var stream = await serverJar.GetJar("servers", "spigot", "1.19.1"))
{
using var fileStream2 = File.Create("./server2.jar");
await stream.CopyToAsync(fileStream2);
Console.WriteLine($"Downloaded {fileStream2.Length / 1024 / 1024}MB to {fileStream2.Name}");
}



static void SetConsoleColor(ConsoleColor foregroundColor, ConsoleColor? backgroundColor = null)
{
Console.ForegroundColor = foregroundColor;
Expand Down

0 comments on commit c076e5a

Please sign in to comment.