From d3d6e2786763eb2de0da36d31657364bdff91cf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=9D=E5=A4=8F=E5=90=8C=E5=AD=A6?= <2411829240@qq.com> Date: Mon, 8 May 2023 23:13:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=B8=8B=E8=BD=BD=E9=93=BE?= =?UTF-8?q?=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wohaopa/zeropoint/wrapper/Main.java | 11 ++++--- .../wohaopa/zeropointlanuch/api/Core.java | 2 +- .../wohaopa/zeropointlanuch/main/Main.java | 31 +++++++++++++++---- 3 files changed, 32 insertions(+), 12 deletions(-) diff --git a/Wrapper/src/main/java/com/github/wohaopa/zeropoint/wrapper/Main.java b/Wrapper/src/main/java/com/github/wohaopa/zeropoint/wrapper/Main.java index 4e80fa5..86ada66 100644 --- a/Wrapper/src/main/java/com/github/wohaopa/zeropoint/wrapper/Main.java +++ b/Wrapper/src/main/java/com/github/wohaopa/zeropoint/wrapper/Main.java @@ -5,6 +5,7 @@ import java.lang.reflect.Method; import java.net.HttpURLConnection; import java.net.URL; +import java.nio.file.Files; import java.util.ArrayList; import java.util.List; import java.util.Properties; @@ -36,17 +37,17 @@ public class Main { libDir = new File(userDir, "lib"); File configFile = new File(userDir + "/config.properties"); if (!configFile.exists()) { - config.setProperty("download-url", "http://127.0.0.1/ZeroPointLaunch/Library/"); + config.setProperty("download-url", "http://127.0.0.1/ZeroPointLaunch/"); config.setProperty("check-libraries", "true"); config.setProperty("check-update", "true"); try { - config.store(new FileOutputStream(configFile), null); + config.store(Files.newOutputStream(configFile.toPath()), null); } catch (IOException e) { throw new RuntimeException(e); } } else { try { - config.load(new FileInputStream(configFile)); + config.load(Files.newInputStream(configFile.toPath())); } catch (IOException e) { throw new RuntimeException(e); } @@ -55,7 +56,7 @@ public class Main { public static void main(String[] args) { - zpLaunch=config.getProperty("download-url","http://127.0.0.1/ZeroPointLaunch/Library/"); + zpLaunch = config.getProperty("download-url", "http://127.0.0.1/ZeroPointLaunch/") + "Library/"; if (config.getProperty("check-update", "false").equals("true")) { File newCore = new File(libDir, "ZeroPointLaunch-Core-new.jar"); @@ -90,7 +91,7 @@ public static void main(String[] args) { method.setAccessible(true); method.invoke(null, (Object) args); } catch (ClassNotFoundException e) { - System.out.println("无法加载核心类:com.github.wohaopa.zeropointlanuch.main.Main,可能缺少ZeroPointLaunch-Core.jar"); + System.out.println("无法加载核心类:com.github.wohaopa.zeropointlanuch.main.Main,请重新启动!或者可能缺少ZeroPointLaunch-Core.jar"); throw new RuntimeException(e); } catch (NoSuchMethodException e) { System.out.println("无法加载main方法,请重新下载!"); diff --git a/src/main/java/com/github/wohaopa/zeropointlanuch/api/Core.java b/src/main/java/com/github/wohaopa/zeropointlanuch/api/Core.java index 8e2579c..d8c70ea 100644 --- a/src/main/java/com/github/wohaopa/zeropointlanuch/api/Core.java +++ b/src/main/java/com/github/wohaopa/zeropointlanuch/api/Core.java @@ -32,7 +32,7 @@ public class Core { - public static final String launcherVersion = "内部测试版本"; + public static final String launcherVersion = "0.0.1"; public static boolean dirToolsInit = false; public static void initDirTools(File rootDir) { diff --git a/src/main/java/com/github/wohaopa/zeropointlanuch/main/Main.java b/src/main/java/com/github/wohaopa/zeropointlanuch/main/Main.java index cd80989..a24ac51 100644 --- a/src/main/java/com/github/wohaopa/zeropointlanuch/main/Main.java +++ b/src/main/java/com/github/wohaopa/zeropointlanuch/main/Main.java @@ -23,11 +23,16 @@ import java.io.File; import java.io.IOException; import java.lang.reflect.Field; +import java.nio.file.Files; import java.util.HashMap; import java.util.Map; +import java.util.Properties; import java.util.Scanner; import java.util.concurrent.ExecutionException; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + import cn.hutool.json.JSONObject; import com.github.wohaopa.zeropointlanuch.api.Core; @@ -35,12 +40,9 @@ import com.github.wohaopa.zeropointlanuch.core.Log; import com.github.wohaopa.zeropointlanuch.core.utils.DownloadUtil; import com.github.wohaopa.zeropointlanuch.core.utils.JsonUtil; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; public class Main { - private static final String DOWNLOAD_VERSION_URL = "http://127.0.0.1//ZeroPointLaunch//"; public static Map commands = new HashMap<>(); public static File workDir; @@ -64,15 +66,18 @@ public static void main(String[] args) { private static void init() { - // String rootDirStr = System.getProperty("zpl.rootdir"); - String rootDirStr = "D:\\DevProject\\JavaProject\\ZeroPointLaunch\\Wrapper\\build\\libs\\.GTNH"; + String rootDirStr = System.getProperty("zpl.rootdir"); + // String rootDirStr = + // "D:\\DevProject\\JavaProject\\ZeroPointLaunch\\Wrapper\\build\\libs\\.GTNH"; + if (rootDirStr == null) { rootDirStr = System.getProperty("user.dir") + "/.GTNH"; } workDir = new File(rootDirStr); Core.initDirTools(workDir); // 目录工具初始化 - if (!Core.launcherVersion.equals("内部测试版本")) { + if (!System.getProperty("zpl.skipUpdate") + .equals("true") && !Core.launcherVersion.equals("内部测试版本")) { check_update(); } @@ -81,6 +86,20 @@ private static void init() { } private static void check_update() { + + File configProperties = new File(workDir.getParentFile(), "config.properties"); + if (!configProperties.exists()) return; + Properties properties = new Properties(); + + try { + properties.load(Files.newInputStream(configProperties.toPath())); + } catch (IOException e) { + Log.info("无法加载config.properties,跳过更新检查。"); + return; + } + + String DOWNLOAD_VERSION_URL = properties.getProperty("download-url"); + Logger updateLog = LogManager.getLogger("Update"); Runnable runnable = () -> { File versionFile = new File(DirTools.tmpDir, "version.json");