Skip to content
This repository has been archived by the owner on Sep 7, 2024. It is now read-only.

Commit

Permalink
使用Wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
wohaopa committed Aug 6, 2023
1 parent 8416677 commit 75cfef7
Show file tree
Hide file tree
Showing 14 changed files with 491 additions and 91 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/.gradle/
/.idea/
/.GTNH/
/UI/.GTNH/
/build/
/TestResources/
/*/build/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,24 @@
import java.io.File;
import java.io.IOException;

import com.github.wohaopa.zeropointlanuch.core.download.DownloadProvider;
import com.github.wohaopa.zeropointlanuch.core.tasks.DownloadTask;
import com.github.wohaopa.zeropointlanuch.core.utils.FileUtil;

public class LinkTools {

private static boolean enable;
private static final File fileJar = new File(
ZplDirectory.getWorkDirectory().getParentFile(),
"lib\\MappingTools.jar");
private static final File cmdFile = new File(
ZplDirectory.getWorkDirectory().getParentFile(),
"lib\\MappingTools.bat");
private static final File fileJar = new File(ZplDirectory.getWorkDirectory(), "lib\\MappingTools.jar");
private static final File cmdFile = new File(ZplDirectory.getWorkDirectory(), "lib\\MappingTools.bat");

static {
if (!fileJar.isFile()) Log.warn("无法加载映射工具!");
else {}
if (!fileJar.isFile()) {
try {
new DownloadTask(DownloadProvider.getUrlForFile(fileJar), fileJar, null).call();
} catch (Exception e) {
Log.error("无法下载链接工具!{}", e);
}
}
}

public static void doLink(File file) throws IOException {
Expand All @@ -49,7 +52,7 @@ public static void doLink(File file) throws IOException {
@echo off
cd /d %~dp0
title ZeroPointLauncher
java -jar MappingTools-0.2.0.jar %1
java -jar MappingTools.jar %1
echo Done!
pause>nul
""";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@ public NewSubInstanceTask(File instanceDir, String name, Instance instance, Cons
public Instance call() throws Exception {

if (Instance.containsKey(name)) return Instance.get(name);
accept("正在创建实例:" + name);
Instance.Builder builder = new Instance.Builder(name);
builder.setVersionFile(new File(instanceDir, "version.json"))
.setDepVersion(instance.information.name)
.setLauncher(instance.information.launcher)
.setSharer(instance.information.sharer)
.saveConfig();
accept("完成!");
return builder.build();
}
}
4 changes: 1 addition & 3 deletions Core/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
module ZeroPointLaunch.Core {

requires java.sql;
requires org.apache.commons.compress;
requires cn.hutool.core;
Expand All @@ -17,6 +16,5 @@
exports com.github.wohaopa.zeropointlanuch.core.tasks;
exports com.github.wohaopa.zeropointlanuch.core.launch;
exports com.github.wohaopa.zeropointlanuch.core.tasks.instances;


exports com.github.wohaopa.zeropointlanuch.core.utils;
}
20 changes: 20 additions & 0 deletions Core/src/test/java/test/LogTest.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
/*
* MIT License
* Copyright (c) 2023 初夏同学
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package test;

import com.github.wohaopa.zeropointlanuch.core.Log;
Expand Down
10 changes: 4 additions & 6 deletions Core/src/test/java/test/MicrosoftAuthControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@

import static org.junit.jupiter.api.Assertions.*;

import com.github.wohaopa.zeropointlanuch.core.auth.MicrosoftAuth;

class MicrosoftAuthControllerTest {

public static void main(String[] args) {
// MicrosoftAuth auth = new MicrosoftAuth();
// auth.setCallback(object -> System.out.println(object.getStr("message")));
// auth.test();
// var json = auth.saveInformation();
// MicrosoftAuth auth = new MicrosoftAuth();
// auth.setCallback(object -> System.out.println(object.getStr("message")));
// auth.test();
// var json = auth.saveInformation();
}
}
42 changes: 42 additions & 0 deletions Launcher/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/

### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr
out/
!**/src/main/**/out/
!**/src/test/**/out/

### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/

### VS Code ###
.vscode/

### Mac OS ###
.DS_Store
30 changes: 30 additions & 0 deletions Launcher/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
plugins {
id 'java'
}

group = 'com.github.wohaopa'
version = '0.1.0'

sourceCompatibility = '8'
targetCompatibility = '8'

repositories {
mavenCentral()
}

dependencies {
}

jar {
manifest {
attributes(
'Main-Class': 'com.github.wohaopa.Main'
)
}
}


tasks.register("copyLib", Copy){
from configurations.runtimeClasspath
into "$buildDir/libs"
}
197 changes: 197 additions & 0 deletions Launcher/src/main/java/com/github/wohaopa/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
/*
* MIT License
* Copyright (c) 2023 初夏同学
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package com.github.wohaopa;

import java.io.*;
import java.nio.charset.Charset;
import java.util.*;

public class Main {

public static void main(String[] args) {
System.out.println("ZPL-LauncherWrapper start...");
System.out.println("====================System Information======================");
System.out.println("Java Version: " + System.getProperty("java.version")); // java版本号
System.out.println("Java Vendor: " + System.getProperty("java.vendor")); // Java提供商名称
System.out.println("Java Home: " + System.getProperty("java.home")); // Java,哦,应该是jre目录
System.out.println("Java Class Version: " + System.getProperty("java.class.version")); // Java类版本号
System.out.println("Java Class Path: " + System.getProperty("java.class.path")); // Java类路径
System.out.println("Java Library Path: " + System.getProperty("java.library.path")); // Java lib路径
System.out.println("OS Name: " + System.getProperty("os.name")); // 操作系统名称
System.out.println("OS Arch: " + System.getProperty("os.arch")); // 操作系统的架构
System.out.println("User Dir: " + System.getProperty("user.dir")); // 当前程序所在目录
System.out.println("=============================================================");

String javaPath;
double classVersion = Double.parseDouble(System.getProperty("java.class.version"));
if (classVersion < 61.0) {

System.out.println("Waring: ZeroPointLauncher must run with Java17 or above!");
System.out.println("警告: ZeroPointLauncher 必须使用Java17以上版本运行");
System.out.println("Looking for suitable Java...");
System.out.println("正在寻找符合要求的Java...");
javaPath = getJava17();
if (javaPath == null) {
System.exit(1);
}
System.out.println("Find Java: " + javaPath);
System.out.println("找到Java: " + javaPath);
} else {
javaPath = System.getProperty("java.home") + "\\bin\\java.exe";
}

File launcherConfig = new File("lib\\launcher.config");

List<String> jvmArg = null;
if (launcherConfig.exists()) {
try (FileReader fileReader = new FileReader(launcherConfig)) {
BufferedReader br = new BufferedReader(fileReader);
String str = br.readLine();
jvmArg = Arrays.asList(str.split(" "));

} catch (IOException ignored) {}
}
if (jvmArg == null) {

File libDir = new File("lib");
String jarName = null;
if (libDir.exists()) {
for (String fileName : Objects.requireNonNull(libDir.list())) {
if (fileName.startsWith("UI")) {
jarName = "lib/" + fileName;
break;
}
}
}

if (jarName == null) throw new RuntimeException("未找到");

jvmArg = Arrays.asList(
"--module-path",
".\\lib\\",
"--add-modules",
"javafx.controls,javafx.graphics,javafx.base,com.jfoenix,ZeroPointLaunch.Core",
"--add-opens",
"java.base/java.lang.reflect=com.jfoenix",
"--add-opens",
"java.base/java.lang.reflect=ALL-UNNAMED",
"--add-exports",
"javafx.controls/com.sun.javafx.scene.control.behavior=com.jfoenix",
"--add-exports",
"javafx.controls/com.sun.javafx.scene.control=com.jfoenix",
"-jar",
jarName);
}

ProcessBuilder pb = new ProcessBuilder();
pb.directory(new File(System.getProperty("user.dir")));

List<String> command = new LinkedList<>();
command.add(javaPath);
command.addAll(jvmArg);

pb.command(command);

Process process;
try {
process = pb.start();
} catch (IOException e) {
throw new RuntimeException(e);
}

if (!"true".equals(System.getProperty("launcher.debug"))) return;
try (BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(process.getErrorStream(), Charset.defaultCharset()))) {
String line;
while ((line = bufferedReader.readLine()) != null) {
if (Thread.currentThread().isInterrupted()) {
Thread.currentThread().interrupt();
break;
}

System.out.println(line);
}
} catch (IOException ignored) {}
}

private static String getJava17() {

try {
List<String> res1 = queryRegisterValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft");

List<String> res2 = new LinkedList<>();
for (String str : res1) {
if (str.startsWith("HKEY_LOCAL_MACHINE")) {
res2.addAll(queryRegisterValue(str));
}
}
res2.removeAll(res1);
List<String> res3 = new LinkedList<>();
for (String str : res2) {
if (str.startsWith("HKEY_LOCAL_MACHINE")) {
res3.addAll(queryRegisterValue(str));
}
}
Set<String> res4 = new HashSet<>();
for (String str : res3) {
if (str.startsWith(" JavaHome")) {
res4.add(str.substring(" JavaHome REG_SZ ".length()));
}
}
String res5 = null;
int last = 16;
for (String str : res4) {
String version = str.substring(str.length() - 2);
try {
int tmp = Integer.parseInt(version);
if (tmp > last) {
String tmpStr = str + "\\bin\\java.exe";
File file = new File(tmpStr);
if (file.exists()) {
res5 = tmpStr;
last = tmp;
}
}
} catch (Exception ignored) {}
}

return res5;

} catch (IOException e) {
throw new RuntimeException(e);
}
}

private static List<String> queryRegisterValue(String location) throws IOException {
Process process = Runtime.getRuntime().exec(new String[] { "cmd", "/c", "reg", "query", location });

List<String> res = new LinkedList<>();
try (BufferedReader reader = new BufferedReader(
new InputStreamReader(process.getInputStream(), Charset.defaultCharset()))) {
for (String line; (line = reader.readLine()) != null;) {
if (!line.trim().isEmpty()) {
res.add(line);
}
}
}
return res;
}
}
Loading

0 comments on commit 75cfef7

Please sign in to comment.