Skip to content

Commit 2b6de0d

Browse files
committed
💾 Feat: Improved InstallEnvironment Method
1 parent 29dc01e commit 2b6de0d

1 file changed

Lines changed: 59 additions & 12 deletions

File tree

Algorithm.Interop/Environment.cs

Lines changed: 59 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,23 +52,70 @@ public static bool CheckEnvironment()
5252

5353
/// <summary>
5454
/// 安装环境
55+
/// <paramref name="im">安装方式</paramref>
5556
/// </summary>
56-
public static void InstallEnvironment()
57+
public static void InstallEnvironment(InstallMethod im = InstallMethod.WebClient)
5758
{
58-
WebClient wc = new();
59-
foreach (string fn in CoreFiles)
59+
if(!Directory.Exists(dll_path))
60+
Directory.CreateDirectory(dll_path);
61+
switch (im)
6062
{
61-
if (!File.Exists($"{dll_path}{fn}"))
62-
{
63-
new Thread(() =>
63+
case InstallMethod.WebClient:
64+
WebClient wc = new();
65+
foreach (string fn in CoreFiles)
6466
{
65-
wc.DownloadFile(
66-
new Uri($"{cloudUrl}{version}/{fn}", UriKind.Absolute),
67-
Path.GetFullPath($"{dll_path}{fn}"));
68-
}).Start();
69-
}
67+
if (!File.Exists($"{dll_path}{fn}"))
68+
{
69+
wc.DownloadFile(
70+
new Uri($"{cloudUrl}{version}/{fn}", UriKind.Absolute),
71+
Path.GetFullPath($"{dll_path}{fn}"));
72+
}
73+
}
74+
wc.Dispose();
75+
break;
7076
}
71-
wc.Dispose();
77+
}
78+
79+
/// <summary>
80+
/// 异步安装环境
81+
/// <paramref name="im">异步安装方式</paramref>
82+
/// </summary>
83+
public static async Task InstallEnvironment(InstallMethodAsync im = InstallMethodAsync.WebClientAsync)
84+
{
85+
if (!Directory.Exists(dll_path))
86+
Directory.CreateDirectory(dll_path);
87+
switch (im)
88+
{
89+
case InstallMethodAsync.WebClientAsync:
90+
var wc = new WebClient();
91+
foreach (string fn in CoreFiles)
92+
{
93+
if (!File.Exists($"{dll_path}{fn}"))
94+
{
95+
await wc.DownloadFileTaskAsync(
96+
new Uri($"{cloudUrl}{version}/{fn}", UriKind.Absolute),
97+
Path.GetFullPath($"{dll_path}{fn}"));
98+
}
99+
}
100+
wc?.Dispose();
101+
break;
102+
case InstallMethodAsync.Http:
103+
104+
break;
105+
}
106+
}
107+
108+
/// <summary>
109+
/// 安装环境下载方式
110+
/// </summary>
111+
public enum InstallMethod
112+
{
113+
WebClient
114+
}
115+
116+
public enum InstallMethodAsync
117+
{
118+
WebClientAsync, Http
72119
}
73120
}
74121
}

0 commit comments

Comments
 (0)