|
1 | 1 | package me.dreamvoid.miraimc.internal;
|
2 | 2 |
|
3 | 3 | import me.dreamvoid.miraimc.MiraiMCConfig;
|
| 4 | +import me.dreamvoid.miraimc.MiraiMCPlugin; |
4 | 5 | import me.dreamvoid.miraimc.internal.webapi.Info;
|
5 | 6 | import me.dreamvoid.miraimc.internal.webapi.Version;
|
| 7 | +import org.eclipse.aether.artifact.DefaultArtifact; |
| 8 | +import org.eclipse.aether.graph.Dependency; |
| 9 | +import org.eclipse.aether.repository.RemoteRepository; |
6 | 10 | import org.xml.sax.SAXException;
|
7 | 11 |
|
8 | 12 | import javax.xml.parsers.ParserConfigurationException;
|
9 |
| -import java.io.BufferedWriter; |
10 |
| -import java.io.File; |
11 |
| -import java.io.FileWriter; |
12 | 13 | import java.io.IOException;
|
13 |
| -import java.nio.charset.StandardCharsets; |
14 |
| -import java.nio.file.Files; |
15 |
| - |
16 |
| -import static me.dreamvoid.miraimc.internal.loader.LibraryLoader.*; |
17 | 14 |
|
18 | 15 | public class MiraiLoader {
|
| 16 | + private static final RemoteRepository mavenCentral = new RemoteRepository.Builder("central","default", MiraiMCConfig.General.MavenRepoUrl).build(); |
19 | 17 | /**
|
20 | 18 | * 加载最新版Mirai Core
|
21 | 19 | */
|
22 | 20 | public static void loadMiraiCore() throws RuntimeException, IOException, ParserConfigurationException, SAXException {
|
23 |
| - loadMiraiCore(getLibraryVersionMaven("net.mamoe", "mirai-core-all", MiraiMCConfig.General.MavenRepoUrl.replace("http://","https://"),"release")); |
| 21 | + loadMiraiCore("latest"); |
24 | 22 | }
|
25 | 23 |
|
26 | 24 | public static String getStableVersion() {
|
@@ -67,43 +65,6 @@ public static String getStableVersion(String PluginVersion) {
|
67 | 65 | * @param version 版本
|
68 | 66 | */
|
69 | 67 | public static void loadMiraiCore(String version) throws RuntimeException, IOException, ParserConfigurationException, SAXException {
|
70 |
| - if(version.equalsIgnoreCase("latest")){ |
71 |
| - version = getLibraryVersionMaven("net.mamoe", "mirai-core-all", MiraiMCConfig.General.MavenRepoUrl.replace("http://","https://"),"release"); |
72 |
| - } |
73 |
| - |
74 |
| - // 文件夹 |
75 |
| - File LibrariesDir = new File(Utils.getMiraiDir(),"libs"); |
76 |
| - if(!LibrariesDir.exists() && !LibrariesDir.mkdirs()) { |
77 |
| - throw new RuntimeException("Failed to create " + LibrariesDir.getPath()); |
78 |
| - } |
79 |
| - |
80 |
| - File writeName = new File(new File(MiraiMCConfig.PluginDir, "cache"), "core-ver"); |
81 |
| - if(!writeName.getParentFile().exists() && !writeName.getParentFile().mkdirs()) { |
82 |
| - throw new RuntimeException("Failed to create " + writeName.getParentFile().getPath()); |
83 |
| - } |
84 |
| - |
85 |
| - try { |
86 |
| - loadJarMaven("net.mamoe", "mirai-core-all", version, "-all", MiraiMCConfig.General.MavenRepoUrl.replace("http://","https://"), LibrariesDir); |
87 |
| - try (FileWriter writer = new FileWriter(writeName); |
88 |
| - BufferedWriter out = new BufferedWriter(writer) |
89 |
| - ) { |
90 |
| - out.write(version); |
91 |
| - out.flush(); |
92 |
| - } |
93 |
| - } catch (Exception e) { |
94 |
| - Utils.getLogger().warning("Unable to download mirai core from remote server, try to use local core. ("+e+")"); |
95 |
| - if(writeName.exists()) { |
96 |
| - String content = new String(Files.readAllBytes(writeName.toPath()), StandardCharsets.UTF_8); |
97 |
| - if(!content.equals("")){ |
98 |
| - String name = "mirai-core-all" + "-" + content + ".jar"; // 文件名 |
99 |
| - File coreFile = new File(LibrariesDir, name); |
100 |
| - loadJarLocal(coreFile); |
101 |
| - } else { |
102 |
| - Utils.getLogger().warning("Unable to use local core."); |
103 |
| - } |
104 |
| - } else { |
105 |
| - Utils.getLogger().warning("No local core found."); |
106 |
| - } |
107 |
| - } |
| 68 | + MiraiMCPlugin.getPlatform().getLibraryLoader().loadLibraryMaven(mavenCentral, new Dependency(new DefaultArtifact("net.mamoe:mirai-core-all:" + (version.equalsIgnoreCase("latest") ? MiraiMCPlugin.getPlatform().getLibraryLoader().getLibraryVersion(mavenCentral, "net.mamoe", "mirai-core-all") : version)), null)); |
108 | 69 | }
|
109 | 70 | }
|
0 commit comments