cleanup
This commit is contained in:
@@ -25,6 +25,7 @@ import org.jackhuang.hmcl.auth.yggdrasil.YggdrasilService;
|
||||
import org.jackhuang.hmcl.auth.yggdrasil.YggdrasilSession;
|
||||
import org.jackhuang.hmcl.game.Arguments;
|
||||
import org.jackhuang.hmcl.task.GetTask;
|
||||
import org.jackhuang.hmcl.util.Charsets;
|
||||
import org.jackhuang.hmcl.util.ExceptionalSupplier;
|
||||
import org.jackhuang.hmcl.util.Lang;
|
||||
import org.jackhuang.hmcl.util.NetworkUtils;
|
||||
@@ -68,7 +69,7 @@ public class AuthlibInjectorAccount extends YggdrasilAccount {
|
||||
Arguments arguments = Arguments.addJVMArguments(null, arg);
|
||||
|
||||
if (flag.get())
|
||||
arguments = Arguments.addJVMArguments(arguments, "-Dorg.to2mbn.authlibinjector.config.prefetched=" + new String(Base64.getEncoder().encode(getTask.getResult().getBytes())));
|
||||
arguments = Arguments.addJVMArguments(arguments, "-Dorg.to2mbn.authlibinjector.config.prefetched=" + new String(Base64.getEncoder().encode(getTask.getResult().getBytes()), Charsets.UTF_8));
|
||||
|
||||
return info.setArguments(arguments);
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -77,6 +77,6 @@ public class RemoteVersion<T> implements Comparable<RemoteVersion<T>> {
|
||||
@Override
|
||||
public int compareTo(RemoteVersion<T> o) {
|
||||
// newer versions are smaller than older versions
|
||||
return -VersionNumber.asVersion(selfVersion).compareTo(VersionNumber.asVersion(o.selfVersion));
|
||||
return VersionNumber.asVersion(o.selfVersion).compareTo(VersionNumber.asVersion(selfVersion));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ public final class GameVersionList extends VersionList<GameRemoteVersionTag> {
|
||||
|
||||
@Override
|
||||
public int compareTo(RemoteVersion<GameRemoteVersionTag> o) {
|
||||
return -getTag().getTime().compareTo(o.getTag().getTime());
|
||||
return o.getTag().getTime().compareTo(getTag().getTime());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,16 +17,47 @@
|
||||
*/
|
||||
package org.jackhuang.hmcl.event;
|
||||
|
||||
import java.util.EventObject;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class Event extends EventObject {
|
||||
public class Event {
|
||||
|
||||
/**
|
||||
* The object on which the Event initially occurred.
|
||||
*/
|
||||
protected transient Object source;
|
||||
|
||||
/**
|
||||
* Constructs a prototypical Event.
|
||||
*
|
||||
* @param source The object on which the Event initially occurred.
|
||||
* @throws NullPointerException if source is null.
|
||||
*/
|
||||
public Event(Object source) {
|
||||
super(source);
|
||||
Objects.requireNonNull(source);
|
||||
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
/**
|
||||
* The object on which the Event initially occurred.
|
||||
*
|
||||
* @return The object on which the Event initially occurred.
|
||||
*/
|
||||
public Object getSource() {
|
||||
return source;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a String representation of this Event.
|
||||
*
|
||||
* @return A a String representation of this Event.
|
||||
*/
|
||||
public String toString() {
|
||||
return getClass().getName() + "[source=" + source + "]";
|
||||
}
|
||||
|
||||
private boolean canceled;
|
||||
|
||||
@@ -30,6 +30,7 @@ import java.io.IOException;
|
||||
import java.io.InterruptedIOException;
|
||||
import java.io.PipedInputStream;
|
||||
import java.io.PipedOutputStream;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
@@ -114,6 +115,8 @@ final class Log4jHandler extends Thread {
|
||||
|
||||
private class Log4jHandlerImpl extends DefaultHandler {
|
||||
|
||||
private final SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss");
|
||||
|
||||
private String date = "", thread = "", logger = "";
|
||||
private StringBuilder message;
|
||||
private Log4jLevel level;
|
||||
@@ -124,8 +127,8 @@ final class Log4jHandler extends Thread {
|
||||
switch (localName) {
|
||||
case "log4j_Event":
|
||||
message = new StringBuilder();
|
||||
Date d = new Date(Long.valueOf(attributes.getValue("timestamp")));
|
||||
date = Constants.DEFAULT_DATE_FORMAT.format(d);
|
||||
Date d = new Date(Long.parseLong(attributes.getValue("timestamp")));
|
||||
date = format.format(d);
|
||||
try {
|
||||
level = Log4jLevel.valueOf(attributes.getValue("level"));
|
||||
} catch (IllegalArgumentException e) {
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.jackhuang.hmcl.util.Logging;
|
||||
import org.jackhuang.hmcl.util.StringUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -125,6 +126,16 @@ public final class ModInfo implements Comparable<ModInfo> {
|
||||
return getFileName().compareTo(o.getFileName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return obj instanceof ModInfo && Objects.equals(getFileName(), ((ModInfo) obj).getFileName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(getFileName());
|
||||
}
|
||||
|
||||
public static boolean isFileMod(File file) {
|
||||
String name = file.getName();
|
||||
if (isDisabled(file))
|
||||
|
||||
@@ -126,10 +126,7 @@ public class FileDownloadTask extends Task {
|
||||
if (repeat > 0) {
|
||||
FailedEvent<URL> event = new FailedEvent<>(this, repeat, currentURL);
|
||||
onFailed.fireEvent(event);
|
||||
if (!currentURL.equals(event.getNewResult())) {
|
||||
Logging.LOG.log(Level.FINE, "Switch from {0} to {1}", new Object[] { currentURL, event.getNewResult() });
|
||||
currentURL = event.getNewResult();
|
||||
}
|
||||
currentURL = event.getNewResult();
|
||||
}
|
||||
if (Thread.interrupted()) {
|
||||
Thread.currentThread().interrupt();
|
||||
|
||||
@@ -19,10 +19,7 @@ package org.jackhuang.hmcl.task;
|
||||
|
||||
import org.jackhuang.hmcl.util.ExceptionalRunnable;
|
||||
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@@ -84,8 +81,9 @@ class SchedulerImpl extends Scheduler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException {
|
||||
latch.await(timeout, unit);
|
||||
public Void get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
|
||||
if (!latch.await(timeout, unit))
|
||||
throw new TimeoutException();
|
||||
return getImpl();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -52,8 +52,6 @@ public final class Constants {
|
||||
public static final String DEFAULT_VERSION_DOWNLOAD_URL = "http://s3.amazonaws.com/Minecraft.Download/versions/";
|
||||
public static final String DEFAULT_INDEX_URL = "http://s3.amazonaws.com/Minecraft.Download/indexes/";
|
||||
|
||||
public static final SimpleDateFormat DEFAULT_DATE_FORMAT = new SimpleDateFormat("HH:mm:ss");
|
||||
|
||||
public static Consumer<Runnable> UI_THREAD_SCHEDULER = s -> Schedulers.computation().schedule(s::run);
|
||||
|
||||
public static final Consumer<Runnable> SWING_UI_THREAD_SCHEDULER = s -> {
|
||||
|
||||
@@ -107,14 +107,14 @@ public final class JavaVersion implements Serializable {
|
||||
try {
|
||||
Process process = new ProcessBuilder(actualFile.getAbsolutePath(), "-version").start();
|
||||
process.waitFor();
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
Matcher m = REGEX.matcher(line);
|
||||
if (m.find())
|
||||
version = m.group("version");
|
||||
if (line.contains("64-Bit"))
|
||||
platform = Platform.BIT_64;
|
||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getErrorStream()))) {
|
||||
for (String line; (line = reader.readLine()) != null; ) {
|
||||
Matcher m = REGEX.matcher(line);
|
||||
if (m.find())
|
||||
version = m.group("version");
|
||||
if (line.contains("64-Bit"))
|
||||
platform = Platform.BIT_64;
|
||||
}
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
throw new IOException("Interrupted scanning the java version.", e);
|
||||
@@ -217,11 +217,11 @@ public final class JavaVersion implements Serializable {
|
||||
Process process = Runtime.getRuntime().exec(cmd);
|
||||
process.waitFor();
|
||||
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null)
|
||||
if (line.startsWith(location) && !line.equals(location))
|
||||
res.add(line);
|
||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
|
||||
for (String line; (line = reader.readLine()) != null; )
|
||||
if (line.startsWith(location) && !line.equals(location))
|
||||
res.add(line);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -241,22 +241,22 @@ public final class JavaVersion implements Serializable {
|
||||
Process process = Runtime.getRuntime().exec(cmd);
|
||||
process.waitFor();
|
||||
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null)
|
||||
if (StringUtils.isNotBlank(line)) {
|
||||
if (last && line.trim().startsWith(name)) {
|
||||
int begins = line.indexOf(name);
|
||||
if (begins > 0) {
|
||||
String s2 = line.substring(begins + name.length());
|
||||
begins = s2.indexOf("REG_SZ");
|
||||
if (begins > 0)
|
||||
return s2.substring(begins + "REG_SZ".length()).trim();
|
||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
|
||||
for (String line; (line = reader.readLine()) != null; )
|
||||
if (StringUtils.isNotBlank(line)) {
|
||||
if (last && line.trim().startsWith(name)) {
|
||||
int begins = line.indexOf(name);
|
||||
if (begins > 0) {
|
||||
String s2 = line.substring(begins + name.length());
|
||||
begins = s2.indexOf("REG_SZ");
|
||||
if (begins > 0)
|
||||
return s2.substring(begins + "REG_SZ".length()).trim();
|
||||
}
|
||||
}
|
||||
if (location.equals(line.trim()))
|
||||
last = true;
|
||||
}
|
||||
if (location.equals(line.trim()))
|
||||
last = true;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,6 +47,11 @@ public final class Lang {
|
||||
return map;
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
public static <T> List<T> immutableListOf(T... elements) {
|
||||
return Collections.unmodifiableList(Arrays.asList(elements));
|
||||
}
|
||||
|
||||
public static <K, V> V computeIfAbsent(Map<K, V> map, K key, Supplier<V> computingFunction) {
|
||||
V value = map.get(key);
|
||||
if (value == null) {
|
||||
|
||||
@@ -21,6 +21,7 @@ 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.*;
|
||||
|
||||
@@ -55,10 +56,11 @@ public final class Logging {
|
||||
static final class DefaultFormatter extends Formatter {
|
||||
|
||||
static final DefaultFormatter INSTANCE = new DefaultFormatter();
|
||||
private final SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss");
|
||||
|
||||
@Override
|
||||
public String format(LogRecord record) {
|
||||
String date = Constants.DEFAULT_DATE_FORMAT.format(new Date(record.getMillis()));
|
||||
String date = format.format(new Date(record.getMillis()));
|
||||
String log = String.format("[%s] [%s.%s/%s] %s%n",
|
||||
date, record.getSourceClassName(), record.getSourceMethodName(),
|
||||
record.getLevel().getName(), MessageFormat.format(record.getMessage(), record.getParameters())
|
||||
|
||||
Reference in New Issue
Block a user