diff --git a/src/main/java/org/cubewhy/celestial/Celestial.java b/src/main/java/org/cubewhy/celestial/Celestial.java index 073f74d9..8a713457 100644 --- a/src/main/java/org/cubewhy/celestial/Celestial.java +++ b/src/main/java/org/cubewhy/celestial/Celestial.java @@ -3,6 +3,7 @@ import com.formdev.flatlaf.FlatDarkLaf; import com.formdev.flatlaf.FlatLightLaf; import com.formdev.flatlaf.IntelliJTheme; +import com.formdev.flatlaf.json.Json; import com.google.gson.*; import joptsimple.OptionParser; import joptsimple.OptionSet; @@ -221,11 +222,24 @@ private static void initConfig() { resize.addProperty("width", 854); resize.addProperty("height", 480); + JsonObject addon = new JsonObject(); + // weave + JsonObject weave = new JsonObject(); + weave.addProperty("enable", false); + weave.addProperty("check-update", true); + addon.add("weave", weave); + // lccn + JsonObject lunarcn = new JsonObject(); + lunarcn.addProperty("enable", false); + lunarcn.addProperty("check-update", true); + addon.add("lunarcn", lunarcn); + config.initValue("jre", "") // leave empty if you want to use the default one .initValue("language", "zh") // en, zh .initValue("installation-dir", new File(configDir, "game").getPath()) .initValue("game-dir", getMinecraftFolder().getPath()) // the minecraft folder .initValue("game", (JsonElement) null) + .initValue("addon", addon) .initValue("ram", 4096) .initValue("max-threads", Runtime.getRuntime().availableProcessors()) // recommend: same as your CPU core .initValue("api", "https://api.lunarclient.top") // only support the LunarCN api, Moonsworth's looks like shit :( diff --git a/src/main/java/org/cubewhy/celestial/event/impl/FileDownloadEvent.java b/src/main/java/org/cubewhy/celestial/event/impl/FileDownloadEvent.java new file mode 100644 index 00000000..47634eba --- /dev/null +++ b/src/main/java/org/cubewhy/celestial/event/impl/FileDownloadEvent.java @@ -0,0 +1,27 @@ +/* + * Celestial Launcher + * License under GPLv3 + * Do NOT remove this note if you want to copy this file. + */ + +package org.cubewhy.celestial.event.impl; + +import org.cubewhy.celestial.event.Event; + +import java.io.File; + +public class FileDownloadEvent extends Event { + + public final File file; + public final Type type; + + public enum Type { + START, + SUCCESS, FALURE; + } + + public FileDownloadEvent(File file, Type type) { + this.file = file; + this.type = type; + } +} diff --git a/src/main/java/org/cubewhy/celestial/files/DownloadManager.java b/src/main/java/org/cubewhy/celestial/files/DownloadManager.java index 6650f932..083f9b2c 100644 --- a/src/main/java/org/cubewhy/celestial/files/DownloadManager.java +++ b/src/main/java/org/cubewhy/celestial/files/DownloadManager.java @@ -4,6 +4,7 @@ import lombok.extern.slf4j.Slf4j; import okhttp3.Response; import org.apache.commons.io.FileUtils; +import org.cubewhy.celestial.event.impl.FileDownloadEvent; import org.cubewhy.celestial.utils.RequestUtils; import org.jetbrains.annotations.NotNull; @@ -77,9 +78,11 @@ public static boolean download(URL url, @NotNull File file, String sha1) throws return true; } } + new FileDownloadEvent(file, FileDownloadEvent.Type.START).call(); log.info("Downloading " + url + " to " + file); try (Response response = RequestUtils.get(url).execute()) { if (!response.isSuccessful() || response.body() == null) { + new FileDownloadEvent(file, FileDownloadEvent.Type.FALURE).call(); return false; } byte[] bytes = response.body().bytes(); @@ -87,8 +90,13 @@ public static boolean download(URL url, @NotNull File file, String sha1) throws } statusBar.setText("Download " + file.getName() + " success."); if (sha1 != null) { - return SecureUtil.sha1(file).equals(sha1); + boolean result = SecureUtil.sha1(file).equals(sha1); + if (!result) { + new FileDownloadEvent(file, FileDownloadEvent.Type.FALURE).call(); + } + return result; } + new FileDownloadEvent(file, FileDownloadEvent.Type.SUCCESS).call(); return true; } diff --git a/src/main/java/org/cubewhy/celestial/game/addon/WeaveMod.java b/src/main/java/org/cubewhy/celestial/game/addon/WeaveMod.java index f6ceaed1..5de6976b 100644 --- a/src/main/java/org/cubewhy/celestial/game/addon/WeaveMod.java +++ b/src/main/java/org/cubewhy/celestial/game/addon/WeaveMod.java @@ -18,8 +18,11 @@ import java.util.List; import java.util.Objects; +import static org.cubewhy.celestial.Celestial.config; + @Getter public class WeaveMod extends BaseAddon { + public static final String build = "Weave-MC/Weave-Loader"; // https://github.com//releases/latest public static final File modFolder = new File(System.getProperty("user.home"), ".weave/mods"); private final File file;