Skip to content

Commit

Permalink
Merge branch 'feature/log-analyzer' into prs
Browse files Browse the repository at this point in the history
  • Loading branch information
burningtnt committed Oct 7, 2024
2 parents 68af9be + ce47680 commit ecbe402
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 81 deletions.
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 @@ -223,7 +223,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
9 changes: 0 additions & 9 deletions HMCL/src/main/java/org/jackhuang/hmcl/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
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.java.JavaRuntime;
Expand Down Expand Up @@ -72,7 +71,6 @@ public static void main(String[] args) {

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

Launcher.main(args);
}
Expand All @@ -96,13 +94,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
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ public LaunchOptions getLaunchOptions(String version, JavaRuntime 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 @@ -53,6 +53,7 @@
import org.jackhuang.hmcl.util.tree.TarFileTree;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@
import org.jackhuang.hmcl.game.GameDirectoryType;
import org.jackhuang.hmcl.game.HMCLGameRepository;
import org.jackhuang.hmcl.game.ProcessPriority;
import org.jackhuang.hmcl.game.*;
import org.jackhuang.hmcl.game.Version;
import org.jackhuang.hmcl.java.JavaManager;
import org.jackhuang.hmcl.java.JavaRuntime;
import org.jackhuang.hmcl.setting.*;
import org.jackhuang.hmcl.ui.Controllers;
import org.jackhuang.hmcl.ui.FXUtils;
Expand All @@ -48,7 +49,6 @@
import org.jackhuang.hmcl.util.javafx.BindingMapping;
import org.jackhuang.hmcl.util.javafx.SafeStringConverter;
import org.jackhuang.hmcl.util.platform.Architecture;
import org.jackhuang.hmcl.java.JavaRuntime;
import org.jackhuang.hmcl.util.platform.OperatingSystem;
import org.jackhuang.hmcl.util.versioning.GameVersionNumber;

Expand Down Expand Up @@ -457,7 +457,7 @@ public VersionSettingsPage(boolean globalSetting) {
}

private void initialize() {
memoryStatus.set(OperatingSystem.getPhysicalMemoryStatus().orElse(OperatingSystem.PhysicalMemoryStatus.INVALID));
memoryStatus.set(OperatingSystem.getPhysicalMemoryStatus());
enableSpecificSettings.addListener((a, b, newValue) -> {
if (versionId == null) return;

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
*/
package org.jackhuang.hmcl.util.platform;

import org.jackhuang.hmcl.util.KeyValuePairProperties;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
Expand All @@ -28,8 +30,9 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Collections;
import java.util.Locale;
import java.util.Optional;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -118,6 +121,9 @@ public String getJavaExecutable() {
*/
public static final String SYSTEM_VERSION;

public static final String OS_RELEASE_NAME;
public static final String OS_RELEASE_PRETTY_NAME;

public static final Pattern INVALID_RESOURCE_CHARACTERS;
private static final String[] INVALID_RESOURCE_BASENAMES;
private static final String[] INVALID_RESOURCE_FULLNAMES;
Expand All @@ -144,7 +150,7 @@ public String getJavaExecutable() {
}
}
} catch (UnsupportedCharsetException e) {
e.printStackTrace();
e.printStackTrace(System.err);
}
NATIVE_CHARSET = nativeCharset;

Expand Down Expand Up @@ -187,9 +193,24 @@ public String getJavaExecutable() {
SYSTEM_BUILD_NUMBER = -1;
}

TOTAL_MEMORY = getPhysicalMemoryStatus()
.map(physicalMemoryStatus -> (int) (physicalMemoryStatus.getTotal() / 1024 / 1024))
.orElse(1024);
Map<String, String> osRelease = Collections.emptyMap();
if (CURRENT_OS == LINUX || CURRENT_OS == FREEBSD) {
Path osReleaseFile = Paths.get("/etc/os-release");
if (Files.exists(osReleaseFile)) {
try {
osRelease = KeyValuePairProperties.load(osReleaseFile);
} catch (IOException e) {
e.printStackTrace(System.err);
}
}
}
OS_RELEASE_NAME = osRelease.get("NAME");
OS_RELEASE_PRETTY_NAME = osRelease.get("PRETTY_NAME");

PhysicalMemoryStatus physicalMemoryStatus = getPhysicalMemoryStatus();
TOTAL_MEMORY = physicalMemoryStatus != PhysicalMemoryStatus.INVALID
? (int) (physicalMemoryStatus.getTotal() / 1024 / 1024)
: 1024;

SUGGESTED_MEMORY = TOTAL_MEMORY >= 32768 ? 8192 : (int) (Math.round(1.0 * TOTAL_MEMORY / 4.0 / 128.0) * 128);

Expand Down Expand Up @@ -256,7 +277,7 @@ public static boolean isWindows7OrLater() {
}

@SuppressWarnings("deprecation")
public static Optional<PhysicalMemoryStatus> getPhysicalMemoryStatus() {
public static PhysicalMemoryStatus getPhysicalMemoryStatus() {
if (CURRENT_OS == LINUX) {
try {
long free = 0, available = 0, total = 0;
Expand All @@ -277,10 +298,10 @@ public static Optional<PhysicalMemoryStatus> getPhysicalMemoryStatus() {
}
}
if (total > 0) {
return Optional.of(new PhysicalMemoryStatus(total, available > 0 ? available : free));
return new PhysicalMemoryStatus(total, available > 0 ? available : free);
}
} catch (IOException e) {
e.printStackTrace();
e.printStackTrace(System.err);
}
}

Expand All @@ -290,11 +311,11 @@ public static Optional<PhysicalMemoryStatus> getPhysicalMemoryStatus() {
com.sun.management.OperatingSystemMXBean sunBean =
(com.sun.management.OperatingSystemMXBean)
java.lang.management.ManagementFactory.getOperatingSystemMXBean();
return Optional.of(new PhysicalMemoryStatus(sunBean.getTotalPhysicalMemorySize(), sunBean.getFreePhysicalMemorySize()));
return new PhysicalMemoryStatus(sunBean.getTotalPhysicalMemorySize(), sunBean.getFreePhysicalMemorySize());
}
} catch (NoClassDefFoundError ignored) {
}
return Optional.empty();
return PhysicalMemoryStatus.INVALID;
}

@SuppressWarnings("removal")
Expand Down

0 comments on commit ecbe402

Please sign in to comment.