Skip to content

Commit

Permalink
Update tools 0.5.1 -> 0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
Mgazul committed Feb 12, 2025
1 parent cf38b85 commit 626041e
Show file tree
Hide file tree
Showing 12 changed files with 296 additions and 412 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def sharedDeps = {
installer 'com.mohistmc:brigadier:1.20.1'
installer 'com.mohistmc:librariesvault:1.20.1'
installer 'com.mohistmc:json:0.5'
installer 'com.mohistmc:tools:0.5.1'
installer 'com.mohistmc:tools:0.6'
installer "com.mohistmc:eventbus:${EVENTBUS_VERSION}"
installer 'com.ibm.icu:icu4j:71.1' // Forge 1.20.1

Expand Down
6 changes: 3 additions & 3 deletions mohistlauncher/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ repositories {

dependencies {
implementation 'org.jetbrains:annotations:24.1.0'
annotationProcessor 'org.projectlombok:lombok:1.18.30'
compileOnly 'org.projectlombok:lombok:1.18.30'
annotationProcessor 'org.projectlombok:lombok:1.18.36'
compileOnly 'org.projectlombok:lombok:1.18.36'

implementation 'com.mohistmc:yaml:0.8'
implementation 'com.mohistmc:i18n:0.6'
implementation 'com.mohistmc:json:0.5'
implementation 'com.mohistmc:tools:0.5.1'
implementation 'com.mohistmc:tools:0.6'
implementation "cpw.mods:bootstraplauncher:1.1.2"
implementation 'me.tongfei:progressbar:0.10.0'
implementation 'org.jline:jline:3.25.1'
Expand Down
22 changes: 14 additions & 8 deletions mohistlauncher/src/main/java/com/mohistmc/MohistMCStart.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

package com.mohistmc;

import com.mohistmc.action.ZipTree;
import com.mohistmc.action.v_1_20_1;
import com.mohistmc.config.MohistConfigUtil;
import com.mohistmc.feature.AutoDeleteMods;
Expand All @@ -28,12 +27,15 @@
import com.mohistmc.i18n.i18n;
import com.mohistmc.tools.JarTool;
import com.mohistmc.tools.Logo;
import com.mohistmc.tools.MojangEulaUtil;
import com.mohistmc.tools.ZipUtil;
import com.mohistmc.util.DataParser;
import com.mohistmc.util.EulaUtil;
import com.mohistmc.util.MohistModuleManager;
import cpw.mods.bootstraplauncher.BootstrapLauncher;
import java.lang.management.ManagementFactory;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Stream;
Expand Down Expand Up @@ -69,17 +71,21 @@ public static void main(String[] args) throws Exception {
ManagementFactory.getRuntimeMXBean().getName().split("@")[0]
);
if (i18n.isCN()) {
System.out.printf("官方交流QQ群: 570870451%n");
System.out.printf("官网(中国)已开放: https://www.mohistmc.cn/%n");
System.out.printf("爱发电: https://afdian.com/a/MohistMC%n");
System.out.println("+------------------------------------------------------+");
System.out.println("| |");
System.out.println("| 官方交流QQ群: 570870451 |");
System.out.println("| 官网(中国): https://www.mohistmc.cn/ |");
System.out.println("| 爱发电: https://afdian.com/a/MohistMC |");
System.out.println("| |");
System.out.println("+------------------------------------------------------+");
}
}

if (System.getProperty("log4j.configurationFile") == null) {
System.setProperty("log4j.configurationFile", "log4j2_mohist.xml");
}

ZipTree.init();
ZipUtil.getFileContent(MohistMCStart.class.getClassLoader().getResourceAsStream("META-INF/libraries"));
if (MohistConfigUtil.INSTALLATIONFINISHED() && MohistConfigUtil.CHECK_LIBRARIES()) {
DefaultLibraries.run();
}
Expand All @@ -104,12 +110,12 @@ public static void main(String[] args) throws Exception {
}
new MohistModuleManager(DataParser.launchArgs);

if (!EulaUtil.hasAcceptedEULA()) {
if (!MojangEulaUtil.hasAcceptedEULA()) {
System.out.println(i18n.as("eula"));
while (!"true".equals(new Scanner(System.in).nextLine().trim())) {
System.out.println(i18n.as("eula_notrue"));
}
EulaUtil.writeInfos();
MojangEulaUtil.writeInfos(i18n.as("eula.text", "https://account.mojang.com/documents/minecraft_eula") + "\n" + new SimpleDateFormat("yyyy-MM-dd").format(new Date()) + "\neula=true");
}
String[] args_ = Stream.concat(forgeArgs.stream(), mainArgs.stream()).toArray(String[]::new);
BootstrapLauncher.main(args_);
Expand Down
6 changes: 3 additions & 3 deletions mohistlauncher/src/main/java/com/mohistmc/action/Action.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import com.mohistmc.MohistMCStart;
import com.mohistmc.tools.FileUtils;
import com.mohistmc.tools.MD5Util;
import com.mohistmc.tools.SHA256;
import com.mohistmc.util.DataParser;
import com.mohistmc.util.JarLoader;
import java.io.BufferedOutputStream;
Expand Down Expand Up @@ -125,7 +125,7 @@ protected void unmute() {

protected void copyFileFromJar(File file, String pathInJar) {
InputStream is = MohistMCStart.class.getClassLoader().getResourceAsStream(pathInJar);
if (!file.exists() || !MD5Util.get(file).equals(MD5Util.get(is)) || file.length() <= 1) {
if (!file.exists() || !SHA256.is(file, SHA256.as(is)) || file.length() <= 1) {
// Clear old version
File parentfile = file.getParentFile();
if (file.getPath().contains("minecraftforge")) {
Expand All @@ -152,7 +152,7 @@ protected void copyFileFromJar(File file, String pathInJar) {

public boolean checkDependencies() throws IOException {
if (installInfo.exists()) {
String jarmd = MD5Util.get(MohistMCStart.jarTool.getFile());
String jarmd = SHA256.as(MohistMCStart.jarTool.getFile());
List<String> lines = Files.readAllLines(installInfo.toPath());
return lines.size() < 2 || !jarmd.equals(lines.get(1));
}
Expand Down
33 changes: 0 additions & 33 deletions mohistlauncher/src/main/java/com/mohistmc/action/ZipTree.java

This file was deleted.

39 changes: 15 additions & 24 deletions mohistlauncher/src/main/java/com/mohistmc/action/v_1_20_1.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.mohistmc.config.MohistConfigUtil;
import com.mohistmc.tools.FileUtils;
import com.mohistmc.tools.JarTool;
import com.mohistmc.tools.MD5Util;
import com.mohistmc.tools.SHA256;
import com.mohistmc.util.I18n;
import com.mohistmc.util.MohistModuleManager;
import java.io.File;
Expand All @@ -20,15 +20,6 @@ public class v_1_20_1 {

public static final List<String> loadedLibsPaths = new ArrayList<>();

public static void restartServer(List<String> cmd, boolean shutdown) throws Exception {
ProcessBuilder pb = new ProcessBuilder(cmd);
pb.inheritIO().start().waitFor();
Thread.sleep(2000);
if (shutdown) {
System.exit(0);
}
}

public static void run() {
try {
new Install();
Expand Down Expand Up @@ -157,43 +148,43 @@ private void install() throws Exception {
unmute();
}

String storedServerMD5 = null;
String storedMohistMD5 = null;
String serverMD5 = MD5Util.get(serverJar);
String mohistMD5 = MD5Util.get(MohistMCStart.jarTool.getFile());
String storedServerSHA256 = null;
String storedMohistSHA256 = null;
String serverSHA256 = SHA256.as(serverJar);
String mohistSHA256 = SHA256.as(MohistMCStart.jarTool.getFile());

if (installInfo.exists()) {
List<String> infoLines = Files.readAllLines(installInfo.toPath());
if (!infoLines.isEmpty()) {
storedServerMD5 = infoLines.get(0);
storedServerSHA256 = infoLines.get(0);
}
if (infoLines.size() > 1) {
storedMohistMD5 = infoLines.get(1);
storedMohistSHA256 = infoLines.get(1);
}
}

if (!serverJar.exists()
|| storedServerMD5 == null
|| storedMohistMD5 == null
|| !storedServerMD5.equals(serverMD5)
|| !storedMohistMD5.equals(mohistMD5)) {
|| storedServerSHA256 == null
|| storedMohistSHA256 == null
|| !storedServerSHA256.equals(serverSHA256)
|| !storedMohistSHA256.equals(mohistSHA256)) {
mute();
run("net.minecraftforge.binarypatcher.ConsoleTool",
new String[]{"--clean", srg.getPath(), "--output", serverJar.getPath(), "--apply", lzma.getPath()},
stringToUrl(loadedLibsPaths));
unmute();
serverMD5 = MD5Util.get(serverJar);
serverSHA256 = SHA256.as(serverJar);
}

FileWriter fw = new FileWriter(installInfo);
fw.write(serverMD5 + "\n");
fw.write(mohistMD5);
fw.write(serverSHA256 + "\n");
fw.write(mohistSHA256);
fw.close();

System.out.println(I18n.as("installation.finished"));
MohistConfigUtil.yml.set("mohist.installation-finished", true);
MohistConfigUtil.save();
restartServer(launchArgs, true);
JarTool.restartServer(launchArgs, true);
}

protected void libPath() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

package com.mohistmc.libraries;

import com.mohistmc.tools.MD5Util;
import com.mohistmc.tools.SHA256;
import java.io.File;
import lombok.AllArgsConstructor;
import lombok.Data;
Expand All @@ -28,7 +28,7 @@
public class Libraries {

String path;
String md5;
String sha256;
long size;
boolean installer;

Expand All @@ -38,6 +38,6 @@ public static Libraries from(String line) {
}

public static Libraries from(File file) {
return new Libraries(file.getAbsolutePath(), MD5Util.get(file), file.length(), false);
return new Libraries(file.getAbsolutePath(), SHA256.as(file), file.length(), false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
package com.mohistmc.libraries;

import com.mohistmc.MohistMCStart;
import com.mohistmc.tools.MD5Util;
import com.mohistmc.tools.SHA256;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -128,7 +128,7 @@ public void progressBar() {
protected boolean copyFileFromJar(File file, String pathInJar, Libraries lib) {
InputStream is = MohistMCStart.class.getClassLoader().getResourceAsStream(pathInJar);

if (!file.exists() || !MD5Util.get(file).equals(lib.getMd5()) || file.length() <= 1) {
if (!file.exists() || !SHA256.is(is, lib.getSha256()) || file.length() <= 1) {
file.getParentFile().mkdirs();
if (is != null) {
try {
Expand All @@ -148,7 +148,7 @@ protected boolean copyFileFromJar(File file, String pathInJar, Libraries lib) {
public boolean needDownload() {
for (Libraries libraries : allLibraries) {
File lib = new File(parentDirectory, libraries.path);
if (lib.exists() && Objects.equals(MD5Util.get(lib), libraries.md5)) {
if (lib.exists() && SHA256.is(lib, libraries.sha256)) {
continue;
}
need_download.add(libraries);
Expand Down
45 changes: 0 additions & 45 deletions mohistlauncher/src/main/java/com/mohistmc/util/EulaUtil.java

This file was deleted.

37 changes: 0 additions & 37 deletions mohistlauncher/src/main/java/com/mohistmc/util/JarManifests.java

This file was deleted.

Loading

0 comments on commit 626041e

Please sign in to comment.