diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/Logging.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/util/Logging.java index 97e08346a..156bb508d 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/Logging.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/util/Logging.java @@ -25,10 +25,8 @@ import java.io.UnsupportedEncodingException; import java.nio.file.Files; import java.nio.file.Path; import java.text.MessageFormat; +import java.util.Arrays; import java.util.Date; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; import java.util.logging.*; /** @@ -41,20 +39,20 @@ public final class Logging { public static final Logger LOG = Logger.getLogger("HMCL"); private static final ByteArrayOutputStream storedLogs = new ByteArrayOutputStream(IOUtils.DEFAULT_BUFFER_SIZE); - private static final ConcurrentMap forbiddenTokens = new ConcurrentHashMap<>(); + private static volatile String[] accessTokens = new String[0]; - public static void registerForbiddenToken(String token, String replacement) { - forbiddenTokens.put(token, replacement); - } + public static synchronized void registerAccessToken(String token) { + final String[] oldAccessTokens = accessTokens; + final String[] newAccessTokens = Arrays.copyOf(oldAccessTokens, oldAccessTokens.length + 1); - public static void registerAccessToken(String accessToken) { - registerForbiddenToken(accessToken, ""); + newAccessTokens[oldAccessTokens.length] = token; + + accessTokens = newAccessTokens; } public static String filterForbiddenToken(String message) { - for (Map.Entry entry : forbiddenTokens.entrySet()) { - message = message.replace(entry.getKey(), entry.getValue()); - } + for (String token : accessTokens) + message = message.replace(token, ""); return message; } diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/ReflectionHelper.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/util/ReflectionHelper.java index f7df44843..ee4baf62d 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/ReflectionHelper.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/util/ReflectionHelper.java @@ -17,9 +17,6 @@ */ package org.jackhuang.hmcl.util; -import java.lang.reflect.AccessibleObject; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.util.function.Predicate; /** @@ -30,20 +27,6 @@ public final class ReflectionHelper { private ReflectionHelper() { } - private static Method accessible0; - - static { - try { - accessible0 = AccessibleObject.class.getDeclaredMethod("setAccessible0", boolean.class); - accessible0.setAccessible(true); - } catch (Throwable ignored) { - } - } - - public static void setAccessible(AccessibleObject obj) throws InvocationTargetException, IllegalAccessException { - accessible0.invoke(obj, true); - } - /** * Get caller, this method is caller sensitive. * diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/Result.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/util/Result.java deleted file mode 100644 index f56325930..000000000 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/Result.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Hello Minecraft! Launcher - * Copyright (C) 2021 huangyuhui and contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.jackhuang.hmcl.util; - -import java.util.Objects; - -public abstract class Result { - - public T get() { - throw new IllegalStateException("TriState not ok"); - } - - public boolean isOK() { - return false; - } - - public boolean isError() { - return false; - } - - public static Result ok(T result) { - return new OK<>(Objects.requireNonNull(result)); - } - - @SuppressWarnings("unchecked") - public static Result error() { - return (Result) Error.INSTANCE; - } - - private static class OK extends Result { - private final T result; - - public OK(T result) { - this.result = result; - } - - @Override - public T get() { - return result; - } - } - - private static class Error extends Result { - public static final Error INSTANCE = new Error<>(); - - @Override - public boolean isError() { - return true; - } - } - -} diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/gson/GsonSerializerHelper.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/util/gson/GsonSerializerHelper.java deleted file mode 100644 index bc2844586..000000000 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/gson/GsonSerializerHelper.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Hello Minecraft! Launcher - * Copyright (C) 2021 huangyuhui and contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.jackhuang.hmcl.util.gson; - -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonSerializer; - -public abstract class GsonSerializerHelper implements JsonSerializer, JsonDeserializer { - - protected static void add(JsonObject object, String property, JsonElement value) { - if (value == null) return; - object.add(property, value); - } - -} diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/gson/UUIDTypeAdapter.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/util/gson/UUIDTypeAdapter.java index 97ee90fdd..7415b2d07 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/gson/UUIDTypeAdapter.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/util/gson/UUIDTypeAdapter.java @@ -24,6 +24,7 @@ import com.google.gson.stream.JsonWriter; import java.io.IOException; import java.util.UUID; +import java.util.regex.Pattern; /** * @@ -51,8 +52,10 @@ public final class UUIDTypeAdapter extends TypeAdapter { return value.toString().replace("-", ""); } + private static final Pattern regex = Pattern.compile("(\\w{8})(\\w{4})(\\w{4})(\\w{4})(\\w{12})"); + public static UUID fromString(String input) { - return UUID.fromString(input.replaceFirst("(\\w{8})(\\w{4})(\\w{4})(\\w{4})(\\w{12})", "$1-$2-$3-$4-$5")); + return UUID.fromString(regex.matcher(input).replaceFirst("$1-$2-$3-$4-$5")); } } diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/platform/Architecture.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/util/platform/Architecture.java index c73c8bfce..1358b3904 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/platform/Architecture.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/util/platform/Architecture.java @@ -69,12 +69,6 @@ public enum Architecture { this.bits = bits; } - Architecture(Bits bits, String displayName, String identifier) { - this.checkedName = identifier; - this.displayName = displayName; - this.bits = bits; - } - public Bits getBits() { return bits; }