forked from brianmiller/phvalheim-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Downloader.cs
41 lines (38 loc) · 1.54 KB
/
Downloader.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System.Net;
namespace PhValheim.Downloader
{
class PhValheim
{
public static async void Go(Uri remoteFile,string localFile, string worldName)
{
using (var client = new WebClient())
using (var completedSignal = new AutoResetEvent(false))
{
client.DownloadFileCompleted += (s, e) =>
{;
// log the error if one occurred
if (e.Error != null)
{
Console.WriteLine(" ERROR: " + e.Error.Message);
// log inner exception if one occurred
if (e.Error.InnerException != null)
{
Console.WriteLine(" ERROR: " + e.Error.InnerException.Message);
}
}
else
{
Console.WriteLine(" Download complete.");
}
completedSignal.Set();
};
client.DownloadProgressChanged += (s, e) => Console.Write($"\r Downloading world files for '" + worldName + "': " + e.ProgressPercentage + "%" );
//Console.WriteLine("\n");
//Console.WriteLine(" Downloading world files for '" + worldName + "'... to "+ localFile + " from " + remoteFile);
client.DownloadFileAsync(remoteFile, localFile);
completedSignal.WaitOne();
}
Console.WriteLine("\n");
}
}
}