Optimize code
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
import org.apache.tools.ant.filters.ReplaceTokens
|
||||
import proguard.gradle.ProGuardTask
|
||||
|
||||
import java.security.MessageDigest
|
||||
import java.util.jar.JarFile
|
||||
import java.util.jar.Pack200
|
||||
@@ -17,9 +20,7 @@ def versionroot = System.getenv("VERSION_ROOT")
|
||||
if (versionroot == null)
|
||||
versionroot = "3.0"
|
||||
|
||||
String mavenGroupId = 'HMCL'
|
||||
String mavenVersion = versionroot + '.' + buildnumber
|
||||
String bundleName = "Hello Minecraft! Launcher"
|
||||
version = mavenVersion
|
||||
|
||||
dependencies {
|
||||
@@ -30,7 +31,7 @@ dependencies {
|
||||
task generateSources(type: Sync) {
|
||||
from 'src/main/java'
|
||||
into "$buildDir/generated-src"
|
||||
filter(org.apache.tools.ant.filters.ReplaceTokens, tokens: [
|
||||
filter(ReplaceTokens, tokens: [
|
||||
'HELLO_MINECRAFT_LAUNCHER_VERSION_FOR_GRADLE_REPLACING': mavenVersion
|
||||
])
|
||||
}
|
||||
@@ -122,7 +123,7 @@ task makePackGZ(dependsOn: jar) doLast {
|
||||
fileEx.append sha1Hex
|
||||
}
|
||||
|
||||
task proguard(type: proguard.gradle.ProGuardTask, dependsOn: jar) {
|
||||
task proguard(type: ProGuardTask, dependsOn: jar) {
|
||||
ext {
|
||||
def re = jar.classifier
|
||||
injar = jar.archivePath
|
||||
|
||||
@@ -17,9 +17,9 @@
|
||||
*/
|
||||
package org.jackhuang.hmcl;
|
||||
|
||||
import org.apache.commons.compress.utils.Charsets;
|
||||
import org.jackhuang.hmcl.util.Logging;
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.io.File;
|
||||
|
||||
public final class Main {
|
||||
|
||||
@@ -42,7 +42,6 @@ public final class HMCLModpackInstallTask extends Task {
|
||||
private final String name;
|
||||
private final HMCLGameRepository repository;
|
||||
private final Modpack modpack;
|
||||
private final File run;
|
||||
private final List<Task> dependencies = new LinkedList<>();
|
||||
private final List<Task> dependents = new LinkedList<>();
|
||||
|
||||
@@ -52,8 +51,8 @@ public final class HMCLModpackInstallTask extends Task {
|
||||
this.zipFile = zipFile;
|
||||
this.name = name;
|
||||
this.modpack = modpack;
|
||||
this.run = repository.getRunDirectory(name);
|
||||
|
||||
File run = repository.getRunDirectory(name);
|
||||
File json = repository.getModpackConfiguration(name);
|
||||
if (repository.hasVersion(name) && !json.exists())
|
||||
throw new IllegalArgumentException("Version " + name + " already exists");
|
||||
|
||||
@@ -63,7 +63,7 @@ public class Settings {
|
||||
|
||||
private final Config SETTINGS = initSettings();
|
||||
|
||||
private Map<String, Account> accounts = new HashMap<>();
|
||||
private final Map<String, Account> accounts = new HashMap<>();
|
||||
|
||||
{
|
||||
loadProxy();
|
||||
@@ -473,7 +473,7 @@ public class Settings {
|
||||
checkProfileMap();
|
||||
|
||||
if (!hasProfile(SETTINGS.getSelectedProfile())) {
|
||||
SETTINGS.setSelectedProfile(getProfileMap().keySet().stream().findFirst().get());
|
||||
getProfileMap().keySet().stream().findFirst().ifPresent(SETTINGS::setSelectedProfile);
|
||||
Schedulers.computation().schedule(this::onProfileChanged);
|
||||
}
|
||||
return getProfile(SETTINGS.getSelectedProfile());
|
||||
|
||||
@@ -34,7 +34,6 @@ import org.jackhuang.hmcl.setting.Accounts;
|
||||
import org.jackhuang.hmcl.setting.Settings;
|
||||
import org.jackhuang.hmcl.setting.Theme;
|
||||
import org.jackhuang.hmcl.task.Schedulers;
|
||||
import org.jackhuang.hmcl.task.Task;
|
||||
import org.jackhuang.hmcl.ui.construct.ComponentList;
|
||||
import org.jackhuang.hmcl.ui.wizard.DecoratorPage;
|
||||
|
||||
|
||||
@@ -45,7 +45,6 @@ import javafx.scene.shape.Rectangle;
|
||||
import javafx.stage.Screen;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.stage.StageStyle;
|
||||
import org.jackhuang.hmcl.Launcher;
|
||||
import org.jackhuang.hmcl.setting.EnumBackgroundImage;
|
||||
import org.jackhuang.hmcl.setting.Settings;
|
||||
import org.jackhuang.hmcl.setting.Theme;
|
||||
|
||||
@@ -28,12 +28,10 @@ import org.jackhuang.hmcl.ui.wizard.WizardPage;
|
||||
import java.util.Map;
|
||||
|
||||
public final class InstallTypePage extends StackPane implements WizardPage {
|
||||
private final WizardController controller;
|
||||
|
||||
@FXML private JFXListView<Object> list;
|
||||
|
||||
public InstallTypePage(WizardController controller) {
|
||||
this.controller = controller;
|
||||
|
||||
FXUtils.loadFXML(this, "/assets/fxml/download/dltype.fxml");
|
||||
list.setOnMouseClicked(e -> {
|
||||
|
||||
@@ -37,8 +37,6 @@ import java.util.Map;
|
||||
|
||||
public class InstallersPage extends StackPane implements WizardPage {
|
||||
private final WizardController controller;
|
||||
private final GameRepository repository;
|
||||
private final DownloadProvider downloadProvider;
|
||||
|
||||
@FXML
|
||||
private VBox list;
|
||||
@@ -72,8 +70,6 @@ public class InstallersPage extends StackPane implements WizardPage {
|
||||
|
||||
public InstallersPage(WizardController controller, GameRepository repository, DownloadProvider downloadProvider) {
|
||||
this.controller = controller;
|
||||
this.repository = repository;
|
||||
this.downloadProvider = downloadProvider;
|
||||
|
||||
FXUtils.loadFXML(this, "/assets/fxml/download/installers.fxml");
|
||||
|
||||
|
||||
@@ -44,11 +44,9 @@ import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public final class VersionsPage extends StackPane implements WizardPage, Refreshable {
|
||||
private final WizardController controller;
|
||||
private final String gameVersion;
|
||||
private final DownloadProvider downloadProvider;
|
||||
private final String libraryId;
|
||||
private final Runnable callback;
|
||||
private final String title;
|
||||
|
||||
@FXML
|
||||
@@ -73,12 +71,10 @@ public final class VersionsPage extends StackPane implements WizardPage, Refresh
|
||||
private TaskExecutor executor;
|
||||
|
||||
public VersionsPage(WizardController controller, String title, String gameVersion, DownloadProvider downloadProvider, String libraryId, Runnable callback) {
|
||||
this.controller = controller;
|
||||
this.title = title;
|
||||
this.gameVersion = gameVersion;
|
||||
this.downloadProvider = downloadProvider;
|
||||
this.libraryId = libraryId;
|
||||
this.callback = callback;
|
||||
this.versionList = downloadProvider.getVersionListById(libraryId);
|
||||
|
||||
FXUtils.loadFXML(this, "/assets/fxml/download/versions.fxml");
|
||||
|
||||
@@ -176,7 +176,7 @@ public class AppDataUpgrader extends IUpgrader {
|
||||
|
||||
@Override
|
||||
public Collection<Task> getDependents() {
|
||||
return Arrays.asList(new FileDownloadTask(downloadLink, tempFile, Proxy.NO_PROXY, hash));
|
||||
return Collections.singleton(new FileDownloadTask(downloadLink, tempFile, Proxy.NO_PROXY, hash));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -79,18 +79,16 @@ public class CrashReporter implements Thread.UncaughtExceptionHandler {
|
||||
THROWABLE_SET.add(stackTrace);
|
||||
|
||||
try {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("---- Hello Minecraft! Crash Report ----\n");
|
||||
builder.append(" Version: " + Launcher.VERSION + "\n");
|
||||
builder.append(" Time: ").append(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())).append("\n");
|
||||
builder.append(" Thread: ").append(t.toString()).append("\n");
|
||||
builder.append("\n Content: \n ");
|
||||
builder.append(stackTrace).append("\n\n");
|
||||
builder.append("-- System Details --\n");
|
||||
builder.append(" Operating System: ").append(System.getProperty("os.name")).append(' ').append(OperatingSystem.SYSTEM_VERSION).append("\n");
|
||||
builder.append(" Java Version: ").append(System.getProperty("java.version")).append(", ").append(System.getProperty("java.vendor")).append("\n");
|
||||
builder.append(" Java VM Version: ").append(System.getProperty("java.vm.name")).append(" (").append(System.getProperty("java.vm.info")).append("), ").append(System.getProperty("java.vm.vendor")).append("\n");
|
||||
String text = builder.toString();
|
||||
String text = "---- Hello Minecraft! Crash Report ----\n" +
|
||||
" Version: " + Launcher.VERSION + "\n" +
|
||||
" Time: " + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) + "\n" +
|
||||
" Thread: " + t.toString() + "\n" +
|
||||
"\n Content: \n " +
|
||||
stackTrace + "\n\n" +
|
||||
"-- System Details --\n" +
|
||||
" Operating System: " + System.getProperty("os.name") + ' ' + OperatingSystem.SYSTEM_VERSION + "\n" +
|
||||
" Java Version: " + System.getProperty("java.version") + ", " + System.getProperty("java.vendor") + "\n" +
|
||||
" Java VM Version: " + System.getProperty("java.vm.name") + " (" + System.getProperty("java.vm.info") + "), " + System.getProperty("java.vm.vendor") + "\n";
|
||||
|
||||
Logging.LOG.log(Level.SEVERE, text);
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
<?import javafx.geometry.Insets?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.image.Image?>
|
||||
<?import javafx.scene.image.ImageView?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
<?import org.jackhuang.hmcl.ui.construct.*?>
|
||||
<?import org.jackhuang.hmcl.ui.*?>
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.jackhuang.hmcl.download.optifine.OptiFineVersionList;
|
||||
*/
|
||||
public class MojangDownloadProvider implements DownloadProvider {
|
||||
|
||||
private boolean isChina;
|
||||
private final boolean isChina;
|
||||
|
||||
public MojangDownloadProvider(boolean isChina) {
|
||||
this.isChina = isChina;
|
||||
|
||||
@@ -47,7 +47,7 @@ public final class ForgeInstallTask extends TaskResult<Version> {
|
||||
private final DefaultDependencyManager dependencyManager;
|
||||
private final Version version;
|
||||
private final File installer = new File("forge-installer.jar").getAbsoluteFile();
|
||||
private ForgeRemoteVersion remote;
|
||||
private final ForgeRemoteVersion remote;
|
||||
private final List<Task> dependents = new LinkedList<>();
|
||||
private final List<Task> dependencies = new LinkedList<>();
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ public final class LiteLoaderInstallTask extends TaskResult<Version> {
|
||||
|
||||
private final DefaultDependencyManager dependencyManager;
|
||||
private final Version version;
|
||||
private LiteLoaderRemoteVersion remote;
|
||||
private final LiteLoaderRemoteVersion remote;
|
||||
private final List<Task> dependents = new LinkedList<>();
|
||||
private final List<Task> dependencies = new LinkedList<>();
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ public final class OptiFineInstallTask extends TaskResult<Version> {
|
||||
|
||||
private final DefaultDependencyManager dependencyManager;
|
||||
private final Version version;
|
||||
private OptiFineRemoteVersion remote;
|
||||
private final OptiFineRemoteVersion remote;
|
||||
private final List<Task> dependents = new LinkedList<>();
|
||||
private final List<Task> dependencies = new LinkedList<>();
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ public class Event {
|
||||
/**
|
||||
* The object on which the Event initially occurred.
|
||||
*/
|
||||
protected transient Object source;
|
||||
protected final transient Object source;
|
||||
|
||||
/**
|
||||
* Constructs a prototypical Event.
|
||||
|
||||
@@ -39,7 +39,7 @@ public final class LibrariesDownloadInfo {
|
||||
|
||||
public LibrariesDownloadInfo(LibraryDownloadInfo artifact, Map<String, LibraryDownloadInfo> classifiers) {
|
||||
this.artifact = artifact;
|
||||
this.classifiers = new HashMap<>(classifiers);
|
||||
this.classifiers = classifiers == null ? null : new HashMap<>(classifiers);
|
||||
}
|
||||
|
||||
public LibraryDownloadInfo getArtifact() {
|
||||
|
||||
@@ -45,7 +45,7 @@ public final class StringArgument implements Argument {
|
||||
@Override
|
||||
public List<String> toString(Map<String, String> keys, Map<String, Boolean> features) {
|
||||
String res = argument;
|
||||
Pattern pattern = Pattern.compile("\\$\\{(.*?)\\}");
|
||||
Pattern pattern = Pattern.compile("\\$\\{(.*?)}");
|
||||
Matcher m = pattern.matcher(argument);
|
||||
while (m.find()) {
|
||||
String entry = m.group();
|
||||
|
||||
@@ -44,23 +44,20 @@ import java.util.Objects;
|
||||
*/
|
||||
public final class MultiMCModpackInstallTask extends Task {
|
||||
|
||||
private final DefaultDependencyManager dependencyManager;
|
||||
private final File zipFile;
|
||||
private final MultiMCInstanceConfiguration manifest;
|
||||
private final String name;
|
||||
private final File run;
|
||||
private final DefaultGameRepository repository;
|
||||
private final List<Task> dependencies = new LinkedList<>();
|
||||
private final List<Task> dependents = new LinkedList<>();
|
||||
|
||||
public MultiMCModpackInstallTask(DefaultDependencyManager dependencyManager, File zipFile, MultiMCInstanceConfiguration manifest, String name) {
|
||||
this.dependencyManager = dependencyManager;
|
||||
this.zipFile = zipFile;
|
||||
this.manifest = manifest;
|
||||
this.name = name;
|
||||
this.repository = dependencyManager.getGameRepository();
|
||||
this.run = repository.getRunDirectory(name);
|
||||
|
||||
File run = repository.getRunDirectory(name);
|
||||
File json = repository.getModpackConfiguration(name);
|
||||
if (repository.hasVersion(name) && !json.exists())
|
||||
throw new IllegalArgumentException("Version " + name + " already exists.");
|
||||
|
||||
@@ -35,9 +35,7 @@ public final class Schedulers {
|
||||
private static synchronized ExecutorService getCachedExecutorService() {
|
||||
if (CACHED_EXECUTOR == null)
|
||||
CACHED_EXECUTOR = new ThreadPoolExecutor(0, Integer.MAX_VALUE,
|
||||
60, TimeUnit.SECONDS, new SynchronousQueue<>(), runnable -> {
|
||||
return Executors.defaultThreadFactory().newThread(runnable);
|
||||
});
|
||||
60, TimeUnit.SECONDS, new SynchronousQueue<>(), Executors.defaultThreadFactory());
|
||||
|
||||
return CACHED_EXECUTOR;
|
||||
}
|
||||
|
||||
@@ -54,8 +54,8 @@ public enum Log4jLevel {
|
||||
public boolean lessOrEqual(Log4jLevel level) {
|
||||
return this.level <= level.level;
|
||||
}
|
||||
public static final Pattern MINECRAFT_LOGGER = Pattern.compile("\\[(?<timestamp>[0-9:]+)\\] \\[[^/]+/(?<level>[^\\]]+)\\]");
|
||||
public static final Pattern MINECRAFT_LOGGER_CATEGORY = Pattern.compile("\\[(?<timestamp>[0-9:]+)\\] \\[[^/]+/(?<level>[^\\]]+)\\] \\[(?<category>[^\\]]+)\\]");
|
||||
public static final Pattern MINECRAFT_LOGGER = Pattern.compile("\\[(?<timestamp>[0-9:]+)] \\[[^/]+/(?<level>[^]]+)]");
|
||||
public static final Pattern MINECRAFT_LOGGER_CATEGORY = Pattern.compile("\\[(?<timestamp>[0-9:]+)] \\[[^/]+/(?<level>[^]]+)] \\[(?<category>[^]]+)]");
|
||||
public static final String JAVA_SYMBOL = "([a-zA-Z_$][a-zA-Z\\d_$]*\\.)+[a-zA-Z_$][a-zA-Z\\d_$]*";
|
||||
|
||||
public static Log4jLevel guessLevel(String line) {
|
||||
|
||||
@@ -20,7 +20,6 @@ package org.jackhuang.hmcl.util;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.text.MessageFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.logging.*;
|
||||
|
||||
Reference in New Issue
Block a user