Skip to content

Commit 463c218

Browse files
committed
🎇 Style: 使用文件命名空间
1 parent 3f612b9 commit 463c218

2 files changed

Lines changed: 316 additions & 318 deletions

File tree

Common.Algorithm.Interop/Environment.cs

Lines changed: 106 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -2,131 +2,130 @@
22

33
#pragma warning disable SYSLIB0014 // 类型或成员已过时
44

5-
namespace Common.Algorithm.Interop
5+
namespace Common.Algorithm.Interop;
6+
7+
public static class Environment
68
{
7-
public static class Environment
9+
10+
/// <summary>
11+
/// 核心文件路径
12+
/// </summary>
13+
public const string DllPath = "./Core/";
14+
15+
/// <summary>
16+
/// 云端 DLL 存储路径
17+
/// </summary>
18+
private static string _cloudUrl = "https://source.catrol.cn/lib/Algorithm/Core/";
19+
20+
/// <summary>
21+
/// 库版本
22+
/// </summary>
23+
private static string _version = "v1.0";
24+
25+
/// <summary>
26+
/// 核心文件文件名
27+
/// </summary>
28+
private static readonly List<string> CoreFiles = new()
829
{
30+
"Math.dll",
31+
"Hash.dll"
32+
};
933

10-
/// <summary>
11-
/// 核心文件路径
12-
/// </summary>
13-
public const string DllPath = "./Core/";
14-
15-
/// <summary>
16-
/// 云端 DLL 存储路径
17-
/// </summary>
18-
private static string _cloudUrl = "https://source.catrol.cn/lib/Algorithm/Core/";
19-
20-
/// <summary>
21-
/// 库版本
22-
/// </summary>
23-
private static string _version = "v1.0";
24-
25-
/// <summary>
26-
/// 核心文件文件名
27-
/// </summary>
28-
private static readonly List<string> CoreFiles = new()
29-
{
30-
"Math.dll",
31-
"Hash.dll"
32-
};
33-
34-
/// <summary>
35-
/// 更新云端存储链接
36-
/// </summary>
37-
/// <param name="url"></param>
38-
public static void UpdateCloudStorageUrl(string url) => _cloudUrl = url;
39-
40-
/// <summary>
41-
/// 更新云端存储版本
42-
/// </summary>
43-
/// <param name="ver"></param>
44-
public static void UpdateCloudStorageVersion(string ver) => _version = ver;
45-
46-
/// <summary>
47-
/// 检查环境是否就绪, 核心文件是否存在
48-
/// </summary>
49-
/// <returns>环境是否就绪</returns>
50-
public static bool CheckEnvironment()
34+
/// <summary>
35+
/// 更新云端存储链接
36+
/// </summary>
37+
/// <param name="url"></param>
38+
public static void UpdateCloudStorageUrl(string url) => _cloudUrl = url;
39+
40+
/// <summary>
41+
/// 更新云端存储版本
42+
/// </summary>
43+
/// <param name="ver"></param>
44+
public static void UpdateCloudStorageVersion(string ver) => _version = ver;
45+
46+
/// <summary>
47+
/// 检查环境是否就绪, 核心文件是否存在
48+
/// </summary>
49+
/// <returns>环境是否就绪</returns>
50+
public static bool CheckEnvironment()
51+
{
52+
foreach (string fn in CoreFiles)
5153
{
52-
foreach (string fn in CoreFiles)
53-
{
54-
if (!File.Exists(Path.GetFullPath($"{DllPath}{fn}")))
55-
return false;
56-
}
57-
return true;
54+
if (!File.Exists(Path.GetFullPath($"{DllPath}{fn}")))
55+
return false;
5856
}
57+
return true;
58+
}
5959

60-
/// <summary>
61-
/// 安装环境
62-
/// <paramref name="im">安装方式</paramref>
63-
/// </summary>
64-
public static void InstallEnvironment(InstallMethod im = InstallMethod.WebClient)
60+
/// <summary>
61+
/// 安装环境
62+
/// <paramref name="im">安装方式</paramref>
63+
/// </summary>
64+
public static void InstallEnvironment(InstallMethod im = InstallMethod.WebClient)
65+
{
66+
if (!Directory.Exists(DllPath))
67+
Directory.CreateDirectory(DllPath);
68+
switch (im)
6569
{
66-
if (!Directory.Exists(DllPath))
67-
Directory.CreateDirectory(DllPath);
68-
switch (im)
69-
{
70-
case InstallMethod.WebClient:
71-
WebClient wc = new();
72-
foreach (string fn in CoreFiles)
70+
case InstallMethod.WebClient:
71+
WebClient wc = new();
72+
foreach (string fn in CoreFiles)
73+
{
74+
if (!File.Exists($"{DllPath}{fn}"))
7375
{
74-
if (!File.Exists($"{DllPath}{fn}"))
75-
{
76-
wc.DownloadFile(
77-
new Uri($"{_cloudUrl}{_version}/{fn}", UriKind.Absolute),
78-
Path.GetFullPath($"{DllPath}{fn}"));
79-
}
76+
wc.DownloadFile(
77+
new Uri($"{_cloudUrl}{_version}/{fn}", UriKind.Absolute),
78+
Path.GetFullPath($"{DllPath}{fn}"));
8079
}
81-
wc.Dispose();
82-
break;
83-
}
80+
}
81+
wc.Dispose();
82+
break;
8483
}
84+
}
8585

86-
/// <summary>
87-
/// 异步安装环境
88-
/// <paramref name="im">异步安装方式</paramref>
89-
/// </summary>
90-
public static async Task InstallEnvironmentAsync(InstallMethodAsync im = InstallMethodAsync.WebClientAsync)
86+
/// <summary>
87+
/// 异步安装环境
88+
/// <paramref name="im">异步安装方式</paramref>
89+
/// </summary>
90+
public static async Task InstallEnvironmentAsync(InstallMethodAsync im = InstallMethodAsync.WebClientAsync)
91+
{
92+
if (!Directory.Exists(DllPath))
93+
Directory.CreateDirectory(DllPath);
94+
switch (im)
9195
{
92-
if (!Directory.Exists(DllPath))
93-
Directory.CreateDirectory(DllPath);
94-
switch (im)
95-
{
96-
case InstallMethodAsync.WebClientAsync:
97-
var wc = new WebClient();
98-
foreach (string fn in CoreFiles)
96+
case InstallMethodAsync.WebClientAsync:
97+
var wc = new WebClient();
98+
foreach (string fn in CoreFiles)
99+
{
100+
if (!File.Exists($"{DllPath}{fn}"))
99101
{
100-
if (!File.Exists($"{DllPath}{fn}"))
101-
{
102-
await wc.DownloadFileTaskAsync(
103-
new Uri($"{_cloudUrl}{_version}/{fn}", UriKind.Absolute),
104-
Path.GetFullPath($"{DllPath}{fn}"));
105-
}
102+
await wc.DownloadFileTaskAsync(
103+
new Uri($"{_cloudUrl}{_version}/{fn}", UriKind.Absolute),
104+
Path.GetFullPath($"{DllPath}{fn}"));
106105
}
107-
wc?.Dispose();
108-
break;
109-
case InstallMethodAsync.Http:
106+
}
107+
wc?.Dispose();
108+
break;
109+
case InstallMethodAsync.Http:
110110

111-
break;
112-
}
111+
break;
113112
}
113+
}
114114

115-
/// <summary>
116-
/// 安装环境下载方式
117-
/// </summary>
118-
public enum InstallMethod
119-
{
120-
WebClient
121-
}
115+
/// <summary>
116+
/// 安装环境下载方式
117+
/// </summary>
118+
public enum InstallMethod
119+
{
120+
WebClient
121+
}
122122

123-
/// <summary>
124-
/// 安装环境下载方式
125-
/// </summary>
126-
public enum InstallMethodAsync
127-
{
128-
WebClientAsync, Http
129-
}
123+
/// <summary>
124+
/// 安装环境下载方式
125+
/// </summary>
126+
public enum InstallMethodAsync
127+
{
128+
WebClientAsync, Http
130129
}
131130
}
132131

0 commit comments

Comments
 (0)