-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHelper.File2Down.cs
50 lines (46 loc) · 1.31 KB
/
Helper.File2Down.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
42
43
44
45
46
47
48
49
50
namespace Helper
{
internal partial class File2Down
{
public string name;
public string url;
public string remoteName;
public long size;
public string md5;
public string ParsedSize => FileH.ParseSize(size);
public File2Down()
{
name = "";
remoteName = "";
url = "";
size = 0;
md5 = "";
}
public async static Task<File2Down?> BuildAsync(dynamic pkg)
{
File2Down res = new();
try
{
res.url = pkg.url ?? string.Empty;
if (string.IsNullOrEmpty(res.url))
{
throw new ArgumentNullException(nameof(pkg));
}
res.name = FileH.GetName(res.url);
res.md5 = pkg.md5 ?? string.Empty;
res.size = long.Parse((string)pkg.size ?? "0");
res.size = res.size == 0 ? await FileH.GetSizeAsync(res.url) : res.size;
res.remoteName = pkg.remoteName ?? string.Empty;
}
catch
{
return null;
}
return res;
}
public override string ToString()
{
return $"{name} ({ParsedSize})";
}
}
}