22
33import priv .samera2022 .module .*;
44import priv .samera2022 .module .annotation .Command ;
5+ import priv .samera2022 .module .config .ConfigHandler ;
6+ import priv .samera2022 .module .file .FileHandler ;
7+ import priv .samera2022 .module .gadgets .gpt .Connection ;
8+ import priv .samera2022 .module .gadgets .gpt .response .Response ;
9+ import priv .samera2022 .module .gadgets .mc .modpack .ModpackHandler ;
10+ import priv .samera2022 .module .gadgets .mc .modpack .download .Concept ;
11+ import priv .samera2022 .module .gadgets .mc .modpack .download .key .Download ;
512import priv .samera2022 .module .gadgets .quiz .Quiz ;
6- import priv .samera2022 .module .gadgets .web .HttpURLConnection ;
7- import priv .samera2022 .module .gadgets .web .response .Response ;
813
914import javax .swing .*;
1015import javax .swing .text .BadLocationException ;
2227import java .text .SimpleDateFormat ;
2328import java .util .ArrayList ;
2429import java .util .Arrays ;
30+ import java .util .HashMap ;
2531import java .util .Scanner ;
2632
2733import static priv .samera2022 .module .mainFrame .dsdFileContent ;
@@ -222,7 +228,7 @@ public static void openai(ArrayList<String> commands) {
222228 formatter (true , new Mixture <>("请等待,正在请求中......" , FontStyle .blackStyle ));
223229 String content = commands .get (1 );
224230 clearInput ();
225- Response response = HttpURLConnection .question (content );
231+ Response response = Connection .question (content );
226232 formatter (true , new Mixture <>("CompletionTokens: " + response .getUsage ().getCompletionTokens ()
227233 + " " + "Model: " + response .getModel () + " " + "Content: \n " +
228234 response .getChoices ().getMessage ().getContent (), FontStyle .blackStyle ));
@@ -243,51 +249,101 @@ public static void config(ArrayList<String> commands) {
243249 }
244250
245251 @ Command
246- public static void analyze (ArrayList <String > commands ) throws IOException {
247- String path = commands .get (1 );
248- String content = FileHandler .read (path );
249- File file = new File (path );
250- FileInputStream fis = new FileInputStream (file .getAbsolutePath ());
251- byte [] buf = new byte [1024 ];
252- int len ;
253- ByteBuffer bb = ByteBuffer .allocate ((int ) file .length ());
254- // 向内存中写数据
255- while ((len = fis .read (buf )) > -1 ) {
256- bb .put (buf , 0 , len );
257- }
258- fis .close ();
259- // 在控件中显示文件内容,注意文件编码问题
260- InputStreamReader isr = new InputStreamReader (new ByteArrayInputStream (bb .array ()), StandardCharsets .UTF_8 );
261- Scanner sc = new Scanner (isr );
262- int line = 0 ;
263- while (sc .hasNext ()) {
264- line ++;
265- String t = sc .nextLine ();
266- if (t .indexOf ("Thread: " ) == 0 ) {
267- switch (t ) {
268- case "Thread: Render Thread" :
269- formatter (true , new Mixture <>("渲染进程(Render Thread)报错!\n " , FontStyle .darkRedStyle ));
270- if (content .contains ("Optifine" ))
271- formatter (true , new Mixture <>("Optifine已安装!\n " , FontStyle .darkRedStyle ));
272- else
273- formatter (true , new Mixture <>("Optifine未安装。\n " , FontStyle .blackStyle ));
274- break ;
275- case "Thread: Client thread" :
276- formatter (true , new Mixture <>("客户端进程(Client Thread)报错!\n " , FontStyle .blackStyle ));
277- break ;
278- }
252+ public static void analyze (ArrayList <String > commands ) {
253+ try {
254+ String path = commands .get (1 );
255+ String content = FileHandler .read (path );
256+ File file = new File (path );
257+ FileInputStream fis = new FileInputStream (file .getAbsolutePath ());
258+ byte [] buf = new byte [1024 ];
259+ int len ;
260+ ByteBuffer bb = ByteBuffer .allocate ((int ) file .length ());
261+ // 向内存中写数据
262+ while ((len = fis .read (buf )) > -1 ) {
263+ bb .put (buf , 0 , len );
279264 }
280- if (t .contains ("LE" ) || t .contains ("LCHIJE" )) {
281- String [] arr = t .split ("\\ |" );
282- formatter (true , new Mixture <>("\n 异常可能点:" +
283- "\n 模组注册名: " + arr [2 ] + "\n 模组名称: " + arr [4 ], FontStyle .darkRedStyle ),
284- new Mixture <>("\n 分析指示:可能该模组出现异常或存在模组互相冲突\n " +
285- "报错切片如下:\n " + t + "\n " +
286- "该异常位于第" + line + "行" , FontStyle .blackStyle ));
265+ fis .close ();
266+ // 在控件中显示文件内容,注意文件编码问题
267+ InputStreamReader isr = new InputStreamReader (new ByteArrayInputStream (bb .array ()), StandardCharsets .UTF_8 );
268+ Scanner sc = new Scanner (isr );
269+ int line = 0 ;
270+ while (sc .hasNext ()) {
271+ line ++;
272+ String t = sc .nextLine ();
273+ if (t .indexOf ("Thread: " ) == 0 ) {
274+ switch (t ) {
275+ case "Thread: Render Thread" :
276+ formatter (true , new Mixture <>("渲染进程(Render Thread)报错!\n " , FontStyle .darkRedStyle ));
277+ if (content .contains ("Optifine" ))
278+ formatter (true , new Mixture <>("Optifine已安装!\n " , FontStyle .darkRedStyle ));
279+ else
280+ formatter (true , new Mixture <>("Optifine未安装。\n " , FontStyle .blackStyle ));
281+ break ;
282+ case "Thread: Client thread" :
283+ formatter (true , new Mixture <>("客户端进程(Client Thread)报错!\n " , FontStyle .blackStyle ));
284+ break ;
285+ }
286+ }
287+ if (t .contains ("LE" ) || t .contains ("LCHIJE" )) {
288+ String [] arr = t .split ("\\ |" );
289+ formatter (true , new Mixture <>("\n 异常可能点:" +
290+ "\n 模组注册名: " + arr [2 ] + "\n 模组名称: " + arr [4 ], FontStyle .darkRedStyle ),
291+ new Mixture <>("\n 分析指示:可能该模组出现异常或存在模组互相冲突\n " +
292+ "报错切片如下:\n " + t + "\n " +
293+ "该异常位于第" + line + "行" , FontStyle .blackStyle ));
294+ } else if (t .contains ("unable to find valid certification path to requested target" )||t .contains ("PKIX path building failed" )) {
295+ formatter (true , new Mixture <>("\n 异常可能点:Java出现异常。" ,FontStyle .darkRedStyle ), new Mixture <>(
296+ "可能原因(仅供参考):这个问题的根本原因是你安装JDK时,Java\\ jar 1.8.0_141\\ lib\\ ext\\ 里面缺少了一个安全凭证jssecacerts证书文件,通过运行下面类可以生成证书,将生成的证书放在Java\\ jar 1.8.0_141\\ lib\\ ext\\ 这个目录下,重启编译器就可以解决。\n " +
297+ "可能的解决办法:" +
298+ "1. (实践可行)重新安装Java" +
299+ "2. 生成安全证书并放入jre相应路径下,参照网页https://blog.csdn.net/weixin_44519124/article/details/119909354" ,FontStyle .blackStyle ));
300+ }
287301 }
302+ } catch (IOException e ) {
303+ e .printStackTrace ();
288304 }
289305 }
290306
307+ @ Command
308+ public static void downloadModpacks (ArrayList <String > commands ) {
309+ String rawSubCommand = commands .get (1 );
310+ String subCommand = FuzzyMatcher .fuzzyMatch (rawSubCommand , Arrays .asList ("key" ,"browser" ));
311+ if (ConfigHandler .CONFIG .getCf_api_key ()!=null ) {
312+ ModpackHandler .handle (commands .get (2 ),commands .get (3 ),subCommand );
313+ switch (subCommand ) {
314+ case "key" :
315+ //zip在前,目录在后
316+ File [] filesN = new File (commands .get (3 )+"\\ necessary\\ " ).listFiles ();
317+ File [] filesO = new File (commands .get (3 )+"\\ optional\\ " ).listFiles ();
318+ int optionalMods = filesO ==null ? 0 : filesO .length ;
319+ if (filesN != null && filesN .length > 0 ) {
320+ formatter (true ,new Mixture <>("检验中,存在下载内容。" ,FontStyle .blackStyle ));
321+ int mods = priv .samera2022 .module .gadgets .mc .modpack .download .browser .Download .getNum (commands .get (2 ));
322+ if (filesN .length +optionalMods ==mods ) {
323+ formatter (true ,new Mixture <>("模组全部下载完成,共" +mods +"个!" ,FontStyle .greenStyle ));
324+ } else {
325+ formatter (true ,new Mixture <>("模组下载未完成,应有" +mods +"个,实有" +(filesN .length +optionalMods )+"个!" ,FontStyle .greenStyle ));
326+ //TODO 缺失文件输出本地检查以后再写
327+ }
328+ } else {
329+ formatter (true ,new Mixture <>("不存在下载内容,下载失败!" ,FontStyle .darkRedStyle ));
330+ }
331+ if (Download .ERROR_LIST .size ()!=0 ) {
332+ formatter (true ,new Mixture <>("下载未完成,失败文件列表如下所示:" ,FontStyle .darkRedStyle ));
333+ for (HashMap <String ,Object > map : Download .ERROR_LIST ){
334+ formatter (true , new Mixture <>("\n modId: " +map .get (Concept .PROJECT_ID )+"\n fileId: " +map .get (Concept .FILE_ID )+"\n required: " +map .get (Concept .REQUIRED )+"\n --------" ,FontStyle .blackStyle ));
335+ }
336+ }
337+ break ;
338+ case "browser" :
339+ // priv.samera2022.module.gadgets.mc.modpack.download.browser.Download.downloadModpacks(commands.get(2));
340+ break ;
341+ default :
342+ break ;
343+ }
344+ } else priv .samera2022 .module .gadgets .mc .modpack .download .browser .Download .downloadModpacks (commands .get (2 ));
345+ }
346+
291347 private static void clearInput () {
292348 try {
293349 dsdInput .remove (0 , dsdInput .getLength ());
@@ -311,8 +367,9 @@ private static void clearInput() {
311367 * 而这个数组在可变参数的函数中被套上了Mixture<String,Style>的泛型,就可以使用@SafeVarargs提示已经除去了堆污染和泛型错误。
312368 * 简单地来解释,就是 多个抽象元素(具体元素也可以,只不过cast了也一样)->调用可变参数函数->(在可变参数函数中)形成数组,并在这个时候对数组加上泛型cast->警告用@SafeVarargs消除
313369 */
370+
314371 @ SafeVarargs
315- private static void formatter (boolean delete , Mixture <String , Style >... objects ) {
372+ public static void formatter (boolean delete , Mixture <String , Style >... objects ) {
316373 output (objects , delete );
317374 }
318375
0 commit comments