C
C#6mo ago
Remaetanju

Forms ProgressBar with MegaApiClient download

using thoses resources: https://gpailler.github.io/MegaApiClient/articles/samples.html https://gpailler.github.io/MegaApiClient/articles/faq.html => download a file hosted by mega & show a forms progress bar - the download is NOT ASYNC - c# 6.0 the download works i'm not sure how to adapt the progress bar system from mega to a windowsforms progress bar

internal static class Program
{
private const string packurl = "https://mega.nz/file/R1pgBAAI#CDFU6xx9EwCEZJ1Z0vKfl_o9DNtPBNjllpuAVZ38nn4";
[STAThread]
static void Main()
{
ApplicationConfiguration.Initialize();
// downloaded zip name
string LCGamePath = "F:\\Games\\Steam\\steamapps\\common\\Lethal Company";
string packname = "MedalCompany.zip";
// setupprogress bar
ProgressBar pBar1 = new();
// Display the ProgressBar control.
if (pBar1 == null)
return;
pBar1.Visible = true;
// Set Minimum to 1 to represent the first file being copied.
pBar1.Minimum = 1;
// Set Maximum to the total number of files to copy.
pBar1.Maximum = 100;
// Set the initial value of the ProgressBar.
pBar1.Value = 1;
// Set the Step property to a value of 1 to represent each file being copied.
pBar1.Step = 1;
// MegaApi Anonymous login
MegaApiClient client = new MegaApiClient();
client.LoginAnonymous();
Uri fileLink = new Uri(packurl);
INode node = client.GetNodeFromLink(fileLink);

void performstep()
{
pBar1.PerformStep();
pBar1.Show();
}
using (var downloadStream = client.Download(node))
using (var progressionStream = new ProgressionStream(downloadStream, x => performstep()))

using (var fileStream = new FileStream(LCGamePath + "\\" + packname, FileMode.Create))
{ progressionStream.CopyTo(fileStream);
}
client.Logout();
}
}

internal static class Program
{
private const string packurl = "https://mega.nz/file/R1pgBAAI#CDFU6xx9EwCEZJ1Z0vKfl_o9DNtPBNjllpuAVZ38nn4";
[STAThread]
static void Main()
{
ApplicationConfiguration.Initialize();
// downloaded zip name
string LCGamePath = "F:\\Games\\Steam\\steamapps\\common\\Lethal Company";
string packname = "MedalCompany.zip";
// setupprogress bar
ProgressBar pBar1 = new();
// Display the ProgressBar control.
if (pBar1 == null)
return;
pBar1.Visible = true;
// Set Minimum to 1 to represent the first file being copied.
pBar1.Minimum = 1;
// Set Maximum to the total number of files to copy.
pBar1.Maximum = 100;
// Set the initial value of the ProgressBar.
pBar1.Value = 1;
// Set the Step property to a value of 1 to represent each file being copied.
pBar1.Step = 1;
// MegaApi Anonymous login
MegaApiClient client = new MegaApiClient();
client.LoginAnonymous();
Uri fileLink = new Uri(packurl);
INode node = client.GetNodeFromLink(fileLink);

void performstep()
{
pBar1.PerformStep();
pBar1.Show();
}
using (var downloadStream = client.Download(node))
using (var progressionStream = new ProgressionStream(downloadStream, x => performstep()))

using (var fileStream = new FileStream(LCGamePath + "\\" + packname, FileMode.Create))
{ progressionStream.CopyTo(fileStream);
}
client.Logout();
}
}
3 Replies
Remaetanju
Remaetanju6mo ago
Its probably impossible for a noob to understand anything to progressbar
Remaetanju
Remaetanju6mo ago
Remaetanju
Remaetanju6mo ago
MegaApiClient client = new MegaApiClient();
client.LoginAnonymous();
Uri fileLink = new Uri(packurl);

INode node = client.GetNodeFromLink(fileLink);
using (var downloadStream = client.Download(node))
using (var progressionStream = new ProgressionStream(downloadStream, x => HERE.button1_Click())) /* <=== CLICK ON BUTTON INSTEAD OF ConsoleWriteLine
(NOT SURE THIS WORKS?)
*/
using (var fileStream = new FileStream(LCGamePath + "\\" + packname, FileMode.Create))
{
progressionStream.CopyTo(fileStream);
}

client.Logout();
MegaApiClient client = new MegaApiClient();
client.LoginAnonymous();
Uri fileLink = new Uri(packurl);

INode node = client.GetNodeFromLink(fileLink);
using (var downloadStream = client.Download(node))
using (var progressionStream = new ProgressionStream(downloadStream, x => HERE.button1_Click())) /* <=== CLICK ON BUTTON INSTEAD OF ConsoleWriteLine
(NOT SURE THIS WORKS?)
*/
using (var fileStream = new FileStream(LCGamePath + "\\" + packname, FileMode.Create))
{
progressionStream.CopyTo(fileStream);
}

client.Logout();
now with the code upper the object HERE is of type Form1, and i run it before the snippet and then give his public button_1click()