Enhance booting (#2531)
* Enhance booting * Delete @Booting * Rollback OperatingSystem * Delete Booting * cleanup * Update FractureiserDetector --------- Co-authored-by: Glavo <zjx001202@gmail.com>
This commit is contained in:
@@ -272,7 +272,7 @@ public final class Launcher extends Application {
|
|||||||
LOG.info("Java Home: " + System.getProperty("java.home"));
|
LOG.info("Java Home: " + System.getProperty("java.home"));
|
||||||
LOG.info("Current Directory: " + System.getProperty("user.dir"));
|
LOG.info("Current Directory: " + System.getProperty("user.dir"));
|
||||||
LOG.info("HMCL Directory: " + Metadata.HMCL_DIRECTORY);
|
LOG.info("HMCL Directory: " + Metadata.HMCL_DIRECTORY);
|
||||||
LOG.info("HMCL Jar Path: " + JarUtils.thisJar().map(it -> it.toAbsolutePath().toString()).orElse("Not Found"));
|
LOG.info("HMCL Jar Path: " + Lang.requireNonNullElse(JarUtils.thisJarPath(), "Not Found"));
|
||||||
LOG.info("Memory: " + Runtime.getRuntime().maxMemory() / 1024 / 1024 + "MB");
|
LOG.info("Memory: " + Runtime.getRuntime().maxMemory() / 1024 / 1024 + "MB");
|
||||||
LOG.info("Physical memory: " + OperatingSystem.TOTAL_MEMORY + " MB");
|
LOG.info("Physical memory: " + OperatingSystem.TOTAL_MEMORY + " MB");
|
||||||
LOG.info("Metaspace: " + ManagementFactory.getMemoryPoolMXBeans().stream()
|
LOG.info("Metaspace: " + ManagementFactory.getMemoryPoolMXBeans().stream()
|
||||||
|
|||||||
@@ -163,7 +163,7 @@ public final class Main {
|
|||||||
SwingUtils.showWarningDialog(message);
|
SwingUtils.showWarningDialog(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void fixLetsEncrypt() {
|
private static void fixLetsEncrypt() {
|
||||||
try {
|
try {
|
||||||
KeyStore defaultKeyStore = KeyStore.getInstance(KeyStore.getDefaultType());
|
KeyStore defaultKeyStore = KeyStore.getInstance(KeyStore.getDefaultType());
|
||||||
Path ksPath = Paths.get(System.getProperty("java.home"), "lib", "security", "cacerts");
|
Path ksPath = Paths.get(System.getProperty("java.home"), "lib", "security", "cacerts");
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ public final class ConfigHolder {
|
|||||||
return ownerChanged;
|
return ownerChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized static void init() throws IOException {
|
public static void init() throws IOException {
|
||||||
if (configInstance != null) {
|
if (configInstance != null) {
|
||||||
throw new IllegalStateException("Configuration is already loaded");
|
throw new IllegalStateException("Configuration is already loaded");
|
||||||
}
|
}
|
||||||
@@ -121,7 +121,7 @@ public final class ConfigHolder {
|
|||||||
private static Path locateConfig() {
|
private static Path locateConfig() {
|
||||||
Path exePath = Paths.get("").toAbsolutePath();
|
Path exePath = Paths.get("").toAbsolutePath();
|
||||||
try {
|
try {
|
||||||
Path jarPath = JarUtils.thisJar().orElse(null);
|
Path jarPath = JarUtils.thisJarPath();
|
||||||
if (jarPath != null && Files.isRegularFile(jarPath) && Files.isWritable(jarPath)) {
|
if (jarPath != null && Files.isRegularFile(jarPath) && Files.isWritable(jarPath)) {
|
||||||
jarPath = jarPath.getParent();
|
jarPath = jarPath.getParent();
|
||||||
exePath = jarPath;
|
exePath = jarPath;
|
||||||
|
|||||||
@@ -68,8 +68,8 @@ public final class ExportWizardProvider implements WizardProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Task<?> exportWithLauncher(String modpackType, ModpackExportInfo exportInfo, File modpackFile) {
|
private Task<?> exportWithLauncher(String modpackType, ModpackExportInfo exportInfo, File modpackFile) {
|
||||||
Optional<Path> launcherJar = JarUtils.thisJar();
|
Path launcherJar = JarUtils.thisJarPath();
|
||||||
boolean packWithLauncher = exportInfo.isPackWithLauncher() && launcherJar.isPresent();
|
boolean packWithLauncher = exportInfo.isPackWithLauncher() && launcherJar != null;
|
||||||
return new Task<Object>() {
|
return new Task<Object>() {
|
||||||
File tempModpack;
|
File tempModpack;
|
||||||
Task<?> exportTask;
|
Task<?> exportTask;
|
||||||
@@ -141,7 +141,7 @@ public final class ExportWizardProvider implements WizardProvider {
|
|||||||
if (background_gif.isFile())
|
if (background_gif.isFile())
|
||||||
zip.putFile(background_gif, "background.gif");
|
zip.putFile(background_gif, "background.gif");
|
||||||
|
|
||||||
zip.putFile(launcherJar.get(), launcherJar.get().getFileName().toString());
|
zip.putFile(launcherJar, launcherJar.getFileName().toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ public final class ModpackInfoPage extends Control implements WizardPage {
|
|||||||
launchArguments.set(versionSetting.getMinecraftArgs());
|
launchArguments.set(versionSetting.getMinecraftArgs());
|
||||||
javaArguments.set(versionSetting.getJavaArgs());
|
javaArguments.set(versionSetting.getJavaArgs());
|
||||||
|
|
||||||
canIncludeLauncher = JarUtils.thisJar().isPresent();
|
canIncludeLauncher = JarUtils.thisJarPath() != null;
|
||||||
|
|
||||||
next.set(e -> onNext());
|
next.set(e -> onNext());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -142,7 +142,10 @@ public final class IntegrityChecker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void verifySelf() throws IOException {
|
private static void verifySelf() throws IOException {
|
||||||
Path self = JarUtils.thisJar().orElseThrow(() -> new IOException("Failed to find current HMCL location"));
|
Path self = JarUtils.thisJarPath();
|
||||||
|
if (self == null) {
|
||||||
|
throw new IOException("Failed to find current HMCL location");
|
||||||
|
}
|
||||||
requireVerifiedJar(self);
|
requireVerifiedJar(self);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -186,7 +186,11 @@ public final class UpdateHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static Path getCurrentLocation() throws IOException {
|
private static Path getCurrentLocation() throws IOException {
|
||||||
return JarUtils.thisJar().orElseThrow(() -> new IOException("Failed to find current HMCL location"));
|
Path path = JarUtils.thisJarPath();
|
||||||
|
if (path == null) {
|
||||||
|
throw new IOException("Failed to find current HMCL location");
|
||||||
|
}
|
||||||
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ==== support for old versions ===
|
// ==== support for old versions ===
|
||||||
@@ -226,10 +230,10 @@ public final class UpdateHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isFirstLaunchAfterUpgrade() {
|
private static boolean isFirstLaunchAfterUpgrade() {
|
||||||
Optional<Path> currentPath = JarUtils.thisJar();
|
Path currentPath = JarUtils.thisJarPath();
|
||||||
if (currentPath.isPresent()) {
|
if (currentPath != null) {
|
||||||
Path updated = Metadata.HMCL_DIRECTORY.resolve("HMCL-" + Metadata.VERSION + ".jar");
|
Path updated = Metadata.HMCL_DIRECTORY.resolve("HMCL-" + Metadata.VERSION + ".jar");
|
||||||
if (currentPath.get().toAbsolutePath().equals(updated.toAbsolutePath())) {
|
if (currentPath.equals(updated.toAbsolutePath())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -253,5 +257,4 @@ public final class UpdateHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// ====
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import org.jackhuang.hmcl.util.platform.OperatingSystem;
|
|||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see <a href="https://github.com/fractureiser-investigation/fractureiser">fractureiser-investigation/fractureiser</a>
|
* @see <a href="https://github.com/fractureiser-investigation/fractureiser">fractureiser-investigation/fractureiser</a>
|
||||||
@@ -15,41 +14,44 @@ public final class FractureiserDetector {
|
|||||||
private FractureiserDetector() {
|
private FractureiserDetector() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final class FractureiserException extends Exception {
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean detect() {
|
public static boolean detect() {
|
||||||
try {
|
try {
|
||||||
ArrayList<Path> badPaths = new ArrayList<>();
|
|
||||||
|
|
||||||
if (OperatingSystem.CURRENT_OS == OperatingSystem.WINDOWS) {
|
if (OperatingSystem.CURRENT_OS == OperatingSystem.WINDOWS) {
|
||||||
Path appdata = Paths.get(System.getProperty("user.home"), "AppData");
|
Path appdata = Paths.get(System.getProperty("user.home"), "AppData");
|
||||||
if (Files.isDirectory(appdata)) {
|
if (Files.isDirectory(appdata)) {
|
||||||
badPaths.add(appdata.resolve("Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\run.bat"));
|
check(appdata.resolve("Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\run.bat"));
|
||||||
|
|
||||||
Path falseEdgePath = appdata.resolve("Local\\Microsoft Edge");
|
Path falseEdgePath = appdata.resolve("Local\\Microsoft Edge");
|
||||||
if (Files.exists(falseEdgePath)) {
|
if (Files.exists(falseEdgePath)) {
|
||||||
badPaths.add(falseEdgePath.resolve(".ref"));
|
check(falseEdgePath.resolve(".ref"));
|
||||||
badPaths.add(falseEdgePath.resolve("client.jar"));
|
check(falseEdgePath.resolve("client.jar"));
|
||||||
badPaths.add(falseEdgePath.resolve("lib.dll"));
|
check(falseEdgePath.resolve("lib.dll"));
|
||||||
badPaths.add(falseEdgePath.resolve("libWebGL64.jar"));
|
check(falseEdgePath.resolve("libWebGL64.jar"));
|
||||||
badPaths.add(falseEdgePath.resolve("run.bat"));
|
check(falseEdgePath.resolve("run.bat"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (OperatingSystem.CURRENT_OS == OperatingSystem.LINUX) {
|
} else if (OperatingSystem.CURRENT_OS == OperatingSystem.LINUX) {
|
||||||
Path dataDir = Paths.get(System.getProperty("user.home"), ".config", ".data");
|
Path dataDir = Paths.get(System.getProperty("user.home"), ".config", ".data");
|
||||||
if (Files.exists(dataDir)) {
|
if (Files.exists(dataDir)) {
|
||||||
badPaths.add(dataDir.resolve(".ref"));
|
check(dataDir.resolve(".ref"));
|
||||||
badPaths.add(dataDir.resolve("client.jar"));
|
check(dataDir.resolve("client.jar"));
|
||||||
badPaths.add(dataDir.resolve("lib.jar"));
|
check(dataDir.resolve("lib.jar"));
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Path badPath : badPaths) {
|
|
||||||
if (Files.isRegularFile(badPath)) {
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (FractureiserException e) {
|
||||||
|
return true;
|
||||||
} catch (Throwable ignored) {
|
} catch (Throwable ignored) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void check(Path path) throws FractureiserException {
|
||||||
|
if (Files.isRegularFile(path)) {
|
||||||
|
throw new FractureiserException();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,13 +17,15 @@
|
|||||||
*/
|
*/
|
||||||
package org.jackhuang.hmcl.util.io;
|
package org.jackhuang.hmcl.util.io;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.nio.file.FileSystemNotFoundException;
|
import java.nio.file.FileSystemNotFoundException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.Optional;
|
import java.security.CodeSource;
|
||||||
import java.util.jar.JarFile;
|
import java.util.jar.JarFile;
|
||||||
import java.util.jar.Manifest;
|
import java.util.jar.Manifest;
|
||||||
|
|
||||||
@@ -31,26 +33,40 @@ public final class JarUtils {
|
|||||||
private JarUtils() {
|
private JarUtils() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
|
private static final Path THIS_JAR;
|
||||||
private static final Optional<Path> THIS_JAR;
|
|
||||||
|
|
||||||
private static final Manifest manifest;
|
private static final Manifest manifest;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
THIS_JAR = Optional.ofNullable(JarUtils.class.getProtectionDomain().getCodeSource())
|
CodeSource cs = JarUtils.class.getProtectionDomain().getCodeSource();
|
||||||
.map(codeSource -> {
|
if (cs == null) {
|
||||||
try {
|
THIS_JAR = null;
|
||||||
return Paths.get(codeSource.getLocation().toURI());
|
manifest = new Manifest();
|
||||||
} catch (FileSystemNotFoundException | IllegalArgumentException | URISyntaxException e) {
|
} else {
|
||||||
return null;
|
Path path;
|
||||||
}
|
try {
|
||||||
})
|
path = Paths.get(cs.getLocation().toURI()).toAbsolutePath();
|
||||||
.filter(Files::isRegularFile);
|
} catch (FileSystemNotFoundException | IllegalArgumentException | URISyntaxException e) {
|
||||||
|
path = null;
|
||||||
manifest = THIS_JAR.flatMap(JarUtils::getManifest).orElseGet(Manifest::new);
|
}
|
||||||
|
if (path == null || !Files.isRegularFile(path)) {
|
||||||
|
THIS_JAR = null;
|
||||||
|
manifest = new Manifest();
|
||||||
|
} else {
|
||||||
|
THIS_JAR = path;
|
||||||
|
Manifest mn;
|
||||||
|
try (JarFile file = new JarFile(path.toFile())) {
|
||||||
|
mn = file.getManifest();
|
||||||
|
} catch (IOException e) {
|
||||||
|
mn = new Manifest();
|
||||||
|
}
|
||||||
|
manifest = mn;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Optional<Path> thisJar() {
|
@Nullable
|
||||||
|
public static Path thisJarPath() {
|
||||||
return THIS_JAR;
|
return THIS_JAR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,12 +74,4 @@ public final class JarUtils {
|
|||||||
String value = manifest.getMainAttributes().getValue(name);
|
String value = manifest.getMainAttributes().getValue(name);
|
||||||
return value != null ? value : defaultValue;
|
return value != null ? value : defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Optional<Manifest> getManifest(Path jar) {
|
|
||||||
try (JarFile file = new JarFile(jar.toFile())) {
|
|
||||||
return Optional.ofNullable(file.getManifest());
|
|
||||||
} catch (IOException e) {
|
|
||||||
return Optional.empty();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -176,8 +176,7 @@ public enum OperatingSystem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TOTAL_MEMORY = getPhysicalMemoryStatus()
|
TOTAL_MEMORY = getPhysicalMemoryStatus()
|
||||||
.map(PhysicalMemoryStatus::getTotal)
|
.map(physicalMemoryStatus -> (int) (physicalMemoryStatus.getTotal() / 1024 / 1024))
|
||||||
.map(bytes -> (int) (bytes / 1024 / 1024))
|
|
||||||
.orElse(1024);
|
.orElse(1024);
|
||||||
|
|
||||||
SUGGESTED_MEMORY = TOTAL_MEMORY >= 32768 ? 8192 : (int) (Math.round(1.0 * TOTAL_MEMORY / 4.0 / 128.0) * 128);
|
SUGGESTED_MEMORY = TOTAL_MEMORY >= 32768 ? 8192 : (int) (Math.round(1.0 * TOTAL_MEMORY / 4.0 / 128.0) * 128);
|
||||||
|
|||||||
Reference in New Issue
Block a user