1+ using System . Net ;
2+ using System . Runtime . InteropServices ;
13using ClassIsland . Core ;
24using ClassIsland . Core . Abstractions ;
35using ClassIsland . Core . Abstractions . Services ;
911using Microsoft . Extensions . DependencyInjection ;
1012using Microsoft . Extensions . Hosting ;
1113using SuperAutoIsland . Controls . ActionSettingsControls ;
12- using SuperAutoIsland . Interface ;
13- using SuperAutoIsland . Interface . MetaData ;
14- using SuperAutoIsland . Interface . MetaData . ArgsType ;
1514using SuperAutoIsland . Interface . Services ;
1615using SuperAutoIsland . Server ;
1716using SuperAutoIsland . Services ;
@@ -36,10 +35,79 @@ public class Plugin : PluginBase
3635 public override void Initialize ( HostBuilderContext context , IServiceCollection services )
3736 {
3837 // ascii 字符画后续再补
39-
38+
4039 _logger . Info ( "欢迎使用 SuperAutoIsland" ) ;
4140 _logger . Info ( "初期化中..." ) ;
4241
42+ _logger . Info ( "检查并补全 ClearScripts 中..." ) ;
43+ ClearScriptPackages . Initialize ( ) ;
44+
45+ string platform ;
46+ if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
47+ {
48+ platform = "win" ;
49+ }
50+ else if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Linux ) )
51+ {
52+ platform = "linux" ;
53+ }
54+ else if ( RuntimeInformation . IsOSPlatform ( OSPlatform . OSX ) )
55+ {
56+ platform = "osx" ;
57+ }
58+ else
59+ {
60+ _logger . Error ( "未知平台,退出 SuperAutoIsland." ) ;
61+ return ;
62+ }
63+
64+ string arch ;
65+ switch ( RuntimeInformation . ProcessArchitecture )
66+ {
67+ case Architecture . X86 :
68+ arch = "x86" ;
69+ break ;
70+ case Architecture . X64 :
71+ arch = "x64" ;
72+ break ;
73+ case Architecture . Arm64 :
74+ arch = "arm64" ;
75+ break ;
76+ case Architecture . Arm :
77+ case Architecture . Wasm :
78+ case Architecture . S390x :
79+ case Architecture . LoongArch64 :
80+ case Architecture . Armv6 :
81+ case Architecture . Ppc64le :
82+ default :
83+ _logger . Error ( "未知架构,退出 SuperAutoIsland." ) ;
84+ return ;
85+ }
86+
87+ var target = $ "{ platform } -{ arch } ";
88+ var packageInfo = ClearScriptPackages . Infos [ target ] ;
89+ var packagePath = $ "{ Info . PluginFolderPath } /runtimes/{ target } /native/{ packageInfo . FileName } ";
90+
91+ if ( ! File . Exists ( packagePath ) )
92+ {
93+ _logger . Info ( "不存在依赖库!开始下载..." ) ;
94+
95+ // 已过时
96+ // using var web = new WebClient();
97+ // web.DownloadFile(packageInfo.Url, packagePath);
98+
99+ var httpClient = new HttpClient ( ) ;
100+ using var response = httpClient . GetAsync ( packageInfo . Url ) . Result ;
101+ using var fs = File . Create ( packagePath ) ;
102+ response . Content . CopyToAsync ( fs ) . Wait ( ) ;
103+
104+ _logger . Info ( "依赖库下载完毕!" ) ;
105+ }
106+ else
107+ {
108+ _logger . Info ( "存在依赖库!继续执行" ) ;
109+ }
110+
43111 _logger . Info ( "加载配置..." ) ;
44112 GlobalConstants . PluginFolder = Info . PluginFolderPath ;
45113 GlobalConstants . PluginConfigFolder = PluginConfigFolder ;
@@ -86,6 +154,9 @@ public override void Initialize(HostBuilderContext context, IServiceCollection s
86154
87155 AppBase . Current . AppStopping += ( _ , _ ) =>
88156 {
157+ var blocklyRunner = IAppHost . GetService < BlocklyRunner > ( ) ;
158+ blocklyRunner . Dispose ( ) ;
159+
89160 var server = IAppHost . GetService < ISaiServer > ( ) ;
90161 server . Shutdown ( ) ;
91162 _logger . Info ( "已尝试关闭,3 秒后将会强行关闭 SuperAutoIsland.Server ..." ) ;
0 commit comments