Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/official/main' into featur…
Browse files Browse the repository at this point in the history
…e/refactor-hmclauncher

# Conflicts:
#	HMCLauncher/HMCL/main.cpp
  • Loading branch information
burningtnt committed Nov 1, 2024
2 parents b7c7ceb + 3bf5204 commit ce87c91
Show file tree
Hide file tree
Showing 224 changed files with 12,758 additions and 5,873 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug-report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ body:
value: |
提交前请确认:
* 该问题确实是 **HMCL 的错误**,而**不是 Minecraft 非正常退出**,如果你的 Minecraft 非正常退出,请前往 [QQ 群](https://docs.hmcl.net/groups.html)/[Discord 频道](https://discord.gg/jVvC7HfM6U) 中获取帮助。
* 你的启动器版本是**最新的快照版本**,可以点击 [此处](https://github.com/burningtnt/HMCL-Snapshot-Update/raw/master/datas/HMCL-dev.jar) 下载最新快照版本。
* 你的启动器版本是**最新的快照版本**,可以点击 [此处](https://zkitefly.github.io/HMCL-Snapshot-Update/) 下载最新快照版本。
如果你的问题并不属于上述两类,你可以选取另一种 Issue 类型,或者直接前往 [QQ 群](https://docs.hmcl.net/groups.html)/[Discord 频道](https://discord.gg/jVvC7HfM6U) 中获取帮助。

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ jobs:

steps:
- uses: actions/checkout@v4
- name: Set up JDK 11
- name: Set up JDK 8
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: '11'
java-version: 8
java-package: 'jdk+fx'
- name: Build with Gradle
run: ./gradlew build --no-daemon
Expand Down
62 changes: 57 additions & 5 deletions HMCL/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,6 @@ tasks.processResources {
from(sourceSets["java11"].output)
}
dependsOn(tasks["java11Classes"])

into("assets") {
from(project.layout.buildDirectory.file("openjfx-dependencies.json"))
}
dependsOn(rootProject.tasks["generateOpenJFXDependencies"])
}

val makeExecutables = tasks.create("makeExecutables") {
Expand All @@ -208,11 +203,68 @@ tasks.build {
dependsOn(makeExecutables)
}

fun parseToolOptions(options: String?): List<String> {
if (options == null)
return listOf()

val builder = StringBuilder()
val result = mutableListOf<String>()

var offset = 0

loop@ while (offset < options.length) {
val ch = options[offset]
if (Character.isWhitespace(ch)) {
if (builder.isNotEmpty()) {
result += builder.toString()
builder.clear()
}

while (offset < options.length && Character.isWhitespace(options[offset])) {
offset++
}

continue@loop
}

if (ch == '\'' || ch == '"') {
offset++

while (offset < options.length) {
val ch2 = options[offset++]
if (ch2 != ch) {
builder.append(ch2)
} else {
continue@loop
}
}

throw GradleException("Unmatched quote in $options")
}

builder.append(ch)
offset++
}

if (builder.isNotEmpty()) {
result += builder.toString()
}

return result
}

tasks.create<JavaExec>("run") {
dependsOn(tasks.jar)

group = "application"

classpath = files(jarPath)
workingDir = rootProject.rootDir

val vmOptions = parseToolOptions(System.getenv("HMCL_JAVA_OPTS"))
jvmArgs(vmOptions)

doFirst {
logger.quiet("HMCL_JAVA_OPTS: $vmOptions")
}
}
4 changes: 3 additions & 1 deletion HMCL/src/main/java/org/jackhuang/hmcl/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,9 @@ public static void main(String[] args) {

try {
LOG.info("*** " + Metadata.TITLE + " ***");
LOG.info("Operating System: " + OperatingSystem.SYSTEM_NAME + ' ' + OperatingSystem.SYSTEM_VERSION);
LOG.info("Operating System: " + (OperatingSystem.OS_RELEASE_PRETTY_NAME == null
? OperatingSystem.SYSTEM_NAME + ' ' + OperatingSystem.SYSTEM_VERSION
: OperatingSystem.OS_RELEASE_PRETTY_NAME + " (" + OperatingSystem.SYSTEM_NAME + ' ' + OperatingSystem.SYSTEM_VERSION + ')'));
LOG.info("System Architecture: " + Architecture.SYSTEM_ARCH_NAME);
LOG.info("Java Architecture: " + Architecture.CURRENT_ARCH_NAME);
LOG.info("Java Version: " + System.getProperty("java.version") + ", " + System.getProperty("java.vendor"));
Expand Down
13 changes: 2 additions & 11 deletions HMCL/src/main/java/org/jackhuang/hmcl/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@
import javafx.application.Platform;
import javafx.scene.control.Alert;
import org.jackhuang.hmcl.ui.AwtUtils;
import org.jackhuang.hmcl.util.FractureiserDetector;
import org.jackhuang.hmcl.util.SelfDependencyPatcher;
import org.jackhuang.hmcl.ui.SwingUtils;
import org.jackhuang.hmcl.util.platform.JavaVersion;
import org.jackhuang.hmcl.java.JavaRuntime;
import org.jackhuang.hmcl.util.platform.OperatingSystem;

import javax.net.ssl.HttpsURLConnection;
Expand Down Expand Up @@ -61,7 +60,7 @@ public static void main(String[] args) {

checkDirectoryPath();

if (JavaVersion.CURRENT_JAVA.getParsedVersion() < 9)
if (JavaRuntime.CURRENT_VERSION < 9)
// This environment check will take ~300ms
thread(Main::fixLetsEncrypt, "CA Certificate Check", true);

Expand All @@ -70,7 +69,6 @@ public static void main(String[] args) {

checkJavaFX();
verifyJavaFX();
detectFractureiser();

Launcher.main(args);
}
Expand All @@ -94,13 +92,6 @@ private static void checkDirectoryPath() {
}
}

private static void detectFractureiser() {
if (FractureiserDetector.detect()) {
LOG.error("Detected that this computer is infected by fractureiser");
showErrorAndExit(i18n("fatal.fractureiser"));
}
}

private static void checkJavaFX() {
try {
SelfDependencyPatcher.patch();
Expand Down
86 changes: 0 additions & 86 deletions HMCL/src/main/java/org/jackhuang/hmcl/countly/Countly.java

This file was deleted.

56 changes: 0 additions & 56 deletions HMCL/src/main/java/org/jackhuang/hmcl/countly/CrashReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,25 @@
import org.jackhuang.hmcl.util.platform.Architecture;
import org.jackhuang.hmcl.util.platform.OperatingSystem;

import java.io.File;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Map;

import static org.jackhuang.hmcl.util.Lang.mapOf;
import static org.jackhuang.hmcl.util.Pair.pair;
import static org.jackhuang.hmcl.util.logging.Logger.LOG;

public class CrashReport {

private final Thread thread;
private final Throwable throwable;
private final String stackTrace;

private boolean nonFatal;

public CrashReport(Thread thread, Throwable throwable) {
this.thread = thread;
this.throwable = throwable;
stackTrace = StringUtils.getStackTrace(throwable);
nonFatal = false;
}

public Throwable getThrowable() {
return this.throwable;
}

public CrashReport setNonFatal() {
nonFatal = true;
return this;
}

public boolean shouldBeReport() {
if (!stackTrace.contains("org.jackhuang"))
return false;
Expand All @@ -48,23 +34,6 @@ public boolean shouldBeReport() {
return true;
}

public Map<String, Object> getMetrics(long runningTime) {
return mapOf(
pair("_run", runningTime),
pair("_app_version", Metadata.VERSION),
pair("_os", OperatingSystem.SYSTEM_NAME),
pair("_os_version", OperatingSystem.SYSTEM_VERSION),
pair("_disk_current", getDiskAvailable()),
pair("_disk_total", getDiskTotal()),
pair("_ram_current", getMemoryAvailable()),
pair("_ram_total", Runtime.getRuntime().maxMemory() / BYTES_IN_MB),
pair("_error", stackTrace),
pair("_logs", LOG.getLogs()),
pair("_name", throwable.getLocalizedMessage()),
pair("_nonfatal", nonFatal)
);
}

public String getDisplayText() {
return "---- Hello Minecraft! Crash Report ----\n" +
" Version: " + Metadata.VERSION + "\n" +
Expand All @@ -82,29 +51,4 @@ public String getDisplayText() {
" JVM Total Memory: " + Runtime.getRuntime().totalMemory() + "\n" +
" JVM Free Memory: " + Runtime.getRuntime().freeMemory() + "\n";
}

private static final Long BYTES_IN_MB = 1024L * 1024;

private static long getMemoryAvailable() {
Long total = Runtime.getRuntime().totalMemory();
Long availMem = Runtime.getRuntime().freeMemory();
return (total - availMem) / BYTES_IN_MB;
}

private static long getDiskAvailable() {
long total = 0, free = 0;
for (File f : File.listRoots()) {
total += f.getTotalSpace();
free += f.getUsableSpace();
}
return (total - free) / BYTES_IN_MB;
}

private static long getDiskTotal() {
long total = 0;
for (File f : File.listRoots()) {
total += f.getTotalSpace();
}
return total / BYTES_IN_MB;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import org.jackhuang.hmcl.util.StringUtils;
import org.jackhuang.hmcl.util.gson.JsonUtils;
import org.jackhuang.hmcl.util.io.FileUtils;
import org.jackhuang.hmcl.util.platform.JavaVersion;
import org.jackhuang.hmcl.java.JavaRuntime;
import org.jackhuang.hmcl.util.platform.OperatingSystem;
import org.jackhuang.hmcl.util.versioning.VersionNumber;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -383,7 +383,7 @@ public void globalizeVersionSetting(String id) {
vs.setUsesGlobal(true);
}

public LaunchOptions getLaunchOptions(String version, JavaVersion javaVersion, File gameDir, List<String> javaAgents, boolean makeLaunchScript) {
public LaunchOptions getLaunchOptions(String version, JavaRuntime javaVersion, File gameDir, List<String> javaAgents, boolean makeLaunchScript) {
VersionSetting vs = getVersionSetting(version);

LaunchOptions.Builder builder = new LaunchOptions.Builder()
Expand All @@ -396,7 +396,7 @@ public LaunchOptions getLaunchOptions(String version, JavaVersion javaVersion, F
.setOverrideJavaArguments(StringUtils.tokenize(vs.getJavaArgs()))
.setMaxMemory(vs.isNoJVMArgs() && vs.isAutoMemory() ? null : (int)(getAllocatedMemory(
vs.getMaxMemory() * 1024L * 1024L,
OperatingSystem.getPhysicalMemoryStatus().orElse(OperatingSystem.PhysicalMemoryStatus.INVALID).getAvailable(),
OperatingSystem.getPhysicalMemoryStatus().getAvailable(),
vs.isAutoMemory()
) / 1024 / 1024))
.setMinMemory(vs.getMinMemory())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package org.jackhuang.hmcl.game;

import com.google.gson.JsonParseException;
import com.google.gson.reflect.TypeToken;
import org.jackhuang.hmcl.download.DefaultDependencyManager;
import org.jackhuang.hmcl.download.LibraryAnalyzer;
import org.jackhuang.hmcl.mod.MinecraftInstanceTask;
Expand Down Expand Up @@ -67,8 +66,7 @@ public HMCLModpackInstallTask(Profile profile, File zipFile, Modpack modpack, St
ModpackConfiguration<Modpack> config = null;
try {
if (json.exists()) {
config = JsonUtils.GSON.fromJson(FileUtils.readText(json), new TypeToken<ModpackConfiguration<Modpack>>() {
}.getType());
config = JsonUtils.GSON.fromJson(FileUtils.readText(json), ModpackConfiguration.typeOf(Modpack.class));

if (!HMCLModpackProvider.INSTANCE.getName().equals(config.getType()))
throw new IllegalArgumentException("Version " + name + " is not a HMCL modpack. Cannot update this version.");
Expand Down
Loading

0 comments on commit ce87c91

Please sign in to comment.