mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-08 11:25:46 -04:00
清理 OperatingSystem (#3925)
This commit is contained in:
parent
0900ad3e5a
commit
c5f56eb5c4
@ -296,7 +296,7 @@ public final class Launcher extends Application {
|
||||
Controllers.getStage().close();
|
||||
Schedulers.shutdown();
|
||||
Controllers.shutdown();
|
||||
Lang.executeDelayed(OperatingSystem::forceGC, TimeUnit.SECONDS, 5, true);
|
||||
Lang.executeDelayed(System::gc, TimeUnit.SECONDS, 5, true);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -41,6 +41,7 @@ import org.jackhuang.hmcl.util.versioning.GameVersionNumber;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.*;
|
||||
import java.util.*;
|
||||
@ -411,7 +412,7 @@ public final class JavaManager {
|
||||
|
||||
// Search in PATH.
|
||||
if (System.getenv("PATH") != null) {
|
||||
String[] paths = System.getenv("PATH").split(OperatingSystem.PATH_SEPARATOR);
|
||||
String[] paths = System.getenv("PATH").split(File.pathSeparator);
|
||||
for (String path : paths) {
|
||||
try {
|
||||
tryAddJavaExecutable(javaRuntimes, Paths.get(path, OperatingSystem.CURRENT_OS.getJavaExecutable()));
|
||||
@ -421,7 +422,7 @@ public final class JavaManager {
|
||||
}
|
||||
|
||||
if (System.getenv("HMCL_JRES") != null) {
|
||||
String[] paths = System.getenv("HMCL_JRES").split(OperatingSystem.PATH_SEPARATOR);
|
||||
String[] paths = System.getenv("HMCL_JRES").split(File.pathSeparator);
|
||||
for (String path : paths) {
|
||||
try {
|
||||
tryAddJavaHome(javaRuntimes, Paths.get(path));
|
||||
|
@ -265,7 +265,7 @@ public class GameCrashWindow extends Stage {
|
||||
Path logFile = Paths.get("minecraft-exported-crash-info-" + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH-mm-ss")) + ".zip").toAbsolutePath();
|
||||
|
||||
CompletableFuture.supplyAsync(() ->
|
||||
logs.stream().map(Log::getLog).collect(Collectors.joining(OperatingSystem.LINE_SEPARATOR)))
|
||||
logs.stream().map(Log::getLog).collect(Collectors.joining("\n")))
|
||||
.thenComposeAsync(logs ->
|
||||
LogExporter.exportLogs(logFile, repository, launchOptions.getVersionName(), logs, new CommandBuilder().addAll(managedProcess.getCommands()).toString()))
|
||||
.handleAsync((result, exception) -> {
|
||||
|
@ -41,7 +41,6 @@ import org.jackhuang.hmcl.util.io.CompressingUtils;
|
||||
import org.jackhuang.hmcl.util.io.FileUtils;
|
||||
import org.jackhuang.hmcl.util.platform.CommandBuilder;
|
||||
import org.jackhuang.hmcl.java.JavaRuntime;
|
||||
import org.jackhuang.hmcl.util.platform.OperatingSystem;
|
||||
import org.jackhuang.hmcl.util.platform.SystemUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@ -140,7 +139,7 @@ public class ForgeNewInstallTask extends Task<Version> {
|
||||
classpath.add(file.toString());
|
||||
}
|
||||
classpath.add(jar.toString());
|
||||
command.add(String.join(OperatingSystem.PATH_SEPARATOR, classpath));
|
||||
command.add(String.join(File.pathSeparator, classpath));
|
||||
|
||||
command.add(mainClass);
|
||||
|
||||
|
@ -37,7 +37,6 @@ import org.jackhuang.hmcl.util.io.CompressingUtils;
|
||||
import org.jackhuang.hmcl.util.io.FileUtils;
|
||||
import org.jackhuang.hmcl.util.platform.CommandBuilder;
|
||||
import org.jackhuang.hmcl.java.JavaRuntime;
|
||||
import org.jackhuang.hmcl.util.platform.OperatingSystem;
|
||||
import org.jackhuang.hmcl.util.platform.SystemUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@ -136,7 +135,7 @@ public class NeoForgeOldInstallTask extends Task<Version> {
|
||||
classpath.add(file.toString());
|
||||
}
|
||||
classpath.add(jar.toString());
|
||||
command.add(String.join(OperatingSystem.PATH_SEPARATOR, classpath));
|
||||
command.add(String.join(File.pathSeparator, classpath));
|
||||
|
||||
command.add(mainClass);
|
||||
|
||||
|
@ -255,7 +255,7 @@ public class DefaultLauncher extends Launcher {
|
||||
// Provided Minecraft arguments
|
||||
Path gameAssets = repository.getActualAssetDirectory(version.getId(), version.getAssetIndex().getId());
|
||||
Map<String, String> configuration = getConfigurations();
|
||||
configuration.put("${classpath}", String.join(OperatingSystem.PATH_SEPARATOR, classpath));
|
||||
configuration.put("${classpath}", String.join(File.pathSeparator, classpath));
|
||||
configuration.put("${game_assets}", gameAssets.toAbsolutePath().toString());
|
||||
configuration.put("${assets_root}", gameAssets.toAbsolutePath().toString());
|
||||
|
||||
@ -434,7 +434,7 @@ public class DefaultLauncher extends Launcher {
|
||||
pair("${resolution_width}", options.getWidth().toString()),
|
||||
pair("${resolution_height}", options.getHeight().toString()),
|
||||
pair("${library_directory}", repository.getLibrariesDirectory(version).getAbsolutePath()),
|
||||
pair("${classpath_separator}", OperatingSystem.PATH_SEPARATOR),
|
||||
pair("${classpath_separator}", File.pathSeparator),
|
||||
pair("${primary_jar}", repository.getVersionJar(version).getAbsolutePath()),
|
||||
pair("${language}", Locale.getDefault().toString()),
|
||||
|
||||
@ -444,7 +444,7 @@ public class DefaultLauncher extends Launcher {
|
||||
// when we propose this placeholder.
|
||||
pair("${libraries_directory}", repository.getLibrariesDirectory(version).getAbsolutePath()),
|
||||
// file_separator is used in -DignoreList
|
||||
pair("${file_separator}", OperatingSystem.FILE_SEPARATOR),
|
||||
pair("${file_separator}", File.separator),
|
||||
pair("${primary_jar_name}", FileUtils.getName(repository.getVersionJar(version).toPath()))
|
||||
);
|
||||
}
|
||||
|
@ -17,8 +17,6 @@
|
||||
*/
|
||||
package org.jackhuang.hmcl.util;
|
||||
|
||||
import org.jackhuang.hmcl.util.platform.OperatingSystem;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.util.*;
|
||||
@ -42,7 +40,7 @@ public final class StringUtils {
|
||||
public static String getStackTrace(StackTraceElement[] elements) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (StackTraceElement element : elements)
|
||||
builder.append("\tat ").append(element).append(OperatingSystem.LINE_SEPARATOR);
|
||||
builder.append("\tat ").append(element).append(System.lineSeparator());
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,6 @@ import org.jackhuang.hmcl.util.platform.windows.Kernel32;
|
||||
import org.jackhuang.hmcl.util.platform.windows.WinTypes;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.Charset;
|
||||
@ -85,10 +84,6 @@ public enum OperatingSystem {
|
||||
*/
|
||||
public static final OperatingSystem CURRENT_OS = parseOSName(System.getProperty("os.name"));
|
||||
|
||||
public static final String PATH_SEPARATOR = File.pathSeparator;
|
||||
public static final String FILE_SEPARATOR = File.separator;
|
||||
public static final String LINE_SEPARATOR = System.lineSeparator();
|
||||
|
||||
/**
|
||||
* The system default charset.
|
||||
*/
|
||||
@ -296,16 +291,6 @@ public enum OperatingSystem {
|
||||
return IS_WINDOWS_7_OR_LATER;
|
||||
}
|
||||
|
||||
@SuppressWarnings("removal")
|
||||
public static void forceGC() {
|
||||
System.gc();
|
||||
try {
|
||||
System.runFinalization();
|
||||
System.gc();
|
||||
} catch (NoSuchMethodError ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
public static Path getWorkingDirectory(String folder) {
|
||||
String home = System.getProperty("user.home", ".");
|
||||
switch (OperatingSystem.CURRENT_OS) {
|
||||
|
@ -47,7 +47,7 @@ public final class SystemUtils {
|
||||
return null;
|
||||
|
||||
try {
|
||||
for (String item : path.split(OperatingSystem.PATH_SEPARATOR)) {
|
||||
for (String item : path.split(File.pathSeparator)) {
|
||||
try {
|
||||
Path program = Paths.get(item, command);
|
||||
if (Files.isExecutable(program))
|
||||
|
Loading…
x
Reference in New Issue
Block a user