-
Notifications
You must be signed in to change notification settings - Fork 5
/
AppxLocation.cs
38 lines (33 loc) · 1.21 KB
/
AppxLocation.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
using System;
using System.IO;
using System.Net;
using System.Threading.Tasks;
namespace MicrosoftStoreDownloader
{
public class AppxLocation
{
public string Name;
public string URL;
public DateTime ExpireTime;
public string SHA1;
public string PackageName;
public Version Version;
public string Architecture;
public async Task<string> DownloadAsync(Action<DownloadProgressChangedEventArgs> callback = null)
{
if (ExpireTime < DateTime.Now)
{
throw new InvalidOperationException("The download link has expired");
}
string path = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
// Create a new WebClient instance.
using (WebClient myWebClient = new WebClient())
{
myWebClient.DownloadProgressChanged += (sender, args) => callback?.Invoke(args);
// Download the Web resource and save it into the current filesystem folder.
await myWebClient.DownloadFileTaskAsync(new Uri(URL), Path.Combine(path, Name));
}
return Path.Combine(path, Name);
}
}
}