-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnvironment.cs
More file actions
121 lines (108 loc) · 3.56 KB
/
Environment.cs
File metadata and controls
121 lines (108 loc) · 3.56 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
using System.Net;
#pragma warning disable SYSLIB0014 // 类型或成员已过时
namespace Algorithm.Interop
{
public class Environment
{
/// <summary>
/// 核心文件路径
/// </summary>
public const string dll_path = "./Core/";
/// <summary>
/// 云端 DLL 存储路径
/// </summary>
public const string cloudUrl = "https://source.catrol.cn/lib/Algorithm/Core/";
/// <summary>
/// 库版本
/// </summary>
public const string version = "v1.0";
/// <summary>
/// 核心文件文件名
/// </summary>
private readonly static List<string> CoreFiles = new()
{
"Math.dll",
"Hash.dll"
};
/// <summary>
/// 检查环境是否就绪, 核心文件是否存在
/// </summary>
/// <returns>环境是否就绪</returns>
public static bool CheckEnvironment()
{
foreach (string fn in CoreFiles)
{
if (!File.Exists(Path.GetFullPath($"{dll_path}{fn}")))
return false;
}
return true;
}
/// <summary>
/// 安装环境
/// <paramref name="im">安装方式</paramref>
/// </summary>
public static void InstallEnvironment(InstallMethod im = InstallMethod.WebClient)
{
if(!Directory.Exists(dll_path))
Directory.CreateDirectory(dll_path);
switch (im)
{
case InstallMethod.WebClient:
WebClient wc = new();
foreach (string fn in CoreFiles)
{
if (!File.Exists($"{dll_path}{fn}"))
{
wc.DownloadFile(
new Uri($"{cloudUrl}{version}/{fn}", UriKind.Absolute),
Path.GetFullPath($"{dll_path}{fn}"));
}
}
wc.Dispose();
break;
}
}
/// <summary>
/// 异步安装环境
/// <paramref name="im">异步安装方式</paramref>
/// </summary>
public static async Task InstallEnvironmentAsync(InstallMethodAsync im = InstallMethodAsync.WebClientAsync)
{
if (!Directory.Exists(dll_path))
Directory.CreateDirectory(dll_path);
switch (im)
{
case InstallMethodAsync.WebClientAsync:
var wc = new WebClient();
foreach (string fn in CoreFiles)
{
if (!File.Exists($"{dll_path}{fn}"))
{
await wc.DownloadFileTaskAsync(
new Uri($"{cloudUrl}{version}/{fn}", UriKind.Absolute),
Path.GetFullPath($"{dll_path}{fn}"));
}
}
wc?.Dispose();
break;
case InstallMethodAsync.Http:
break;
}
}
/// <summary>
/// 安装环境下载方式
/// </summary>
public enum InstallMethod
{
WebClient
}
/// <summary>
/// 安装环境下载方式
/// </summary>
public enum InstallMethodAsync
{
WebClientAsync, Http
}
}
}
#pragma warning restore SYSLIB0014 // 类型或成员已过时