Only use DatatypeConverter as a fallback
Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
This commit is contained in:
parent
8a81aaaa0a
commit
7534eaf006
@ -19,6 +19,8 @@ set(SRC
|
||||
org/prismlauncher/fix/Fixes.java
|
||||
org/prismlauncher/fix/skins/SkinFix.java
|
||||
org/prismlauncher/fix/skins/Handler.java
|
||||
org/prismlauncher/utils/Base64.java
|
||||
org/prismlauncher/utils/JsonParser.java
|
||||
org/prismlauncher/utils/Parameters.java
|
||||
org/prismlauncher/utils/ReflectionUtils.java
|
||||
org/prismlauncher/utils/UrlUtils.java
|
||||
|
@ -43,8 +43,7 @@ import java.net.URLConnection;
|
||||
import java.net.URLStreamHandler;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.bind.DatatypeConverter;
|
||||
|
||||
import org.prismlauncher.utils.Base64;
|
||||
import org.prismlauncher.utils.JsonParser;
|
||||
import org.prismlauncher.utils.UrlUtils;
|
||||
|
||||
@ -115,7 +114,7 @@ final class Handler extends URLStreamHandler {
|
||||
for (Map<String, Object> property : (Iterable<Map<String, Object>>) profile.get("properties")) {
|
||||
if (property.get("name").equals("textures")) {
|
||||
Map<String, Object> result = (Map<String, Object>) JsonParser
|
||||
.parse(new String(DatatypeConverter.parseBase64Binary((String) property.get("value"))));
|
||||
.parse(new String(Base64.decode((String) property.get("value"))));
|
||||
result = (Map<String, Object>) result.get("textures");
|
||||
return result;
|
||||
}
|
||||
|
@ -59,27 +59,10 @@ public final class SkinFix implements Fix, URLStreamHandlerFactory {
|
||||
|
||||
@Override
|
||||
public boolean isApplicable(Parameters params) {
|
||||
if (!isSupported()) {
|
||||
Log.warning("Using Java 8 will probably fix this");
|
||||
Log.warning("Alternatively, turning off legacy skin fix in Settings > Miscellaneous will silence the warnings");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean isSupported() {
|
||||
// check for DatatypeConverter first
|
||||
// most users will just be annoyed by the big stacktrace
|
||||
try {
|
||||
Class.forName("javax.xml.bind.DatatypeConverter");
|
||||
} catch (ClassNotFoundException e) {
|
||||
Log.warning("Cannot find DatatypeConverter - required for skin fix");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!UrlUtils.isSupported()) {
|
||||
Log.warning("Cannot access the necessary Java internals for skin fix");
|
||||
Log.warning("Using an older Java version will probably fix this");
|
||||
Log.warning("Alternatively, turning off legacy skin fix in Settings > Miscellaneous will silence the warnings");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
59
libraries/launcher/org/prismlauncher/utils/Base64.java
Normal file
59
libraries/launcher/org/prismlauncher/utils/Base64.java
Normal file
@ -0,0 +1,59 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
/*
|
||||
* Prism Launcher - Minecraft Launcher
|
||||
* Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me>
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Linking this library statically or dynamically with other modules is
|
||||
* making a combined work based on this library. Thus, the terms and
|
||||
* conditions of the GNU General Public License cover the whole
|
||||
* combination.
|
||||
*
|
||||
* As a special exception, the copyright holders of this library give
|
||||
* you permission to link this library with independent modules to
|
||||
* produce an executable, regardless of the license terms of these
|
||||
* independent modules, and to copy and distribute the resulting
|
||||
* executable under terms of your choice, provided that you also meet,
|
||||
* for each linked independent module, the terms and conditions of the
|
||||
* license of that module. An independent module is a module which is
|
||||
* not derived from or based on this library. If you modify this
|
||||
* library, you may extend this exception to your version of the
|
||||
* library, but you are not obliged to do so. If you do not wish to do
|
||||
* so, delete this exception statement from your version.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.prismlauncher.utils;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import javax.xml.bind.DatatypeConverter;
|
||||
|
||||
public final class Base64 {
|
||||
|
||||
private static boolean legacy;
|
||||
|
||||
public static byte[] decode(String input) {
|
||||
if (!legacy) {
|
||||
try {
|
||||
return java.util.Base64.getDecoder().decode(input.getBytes(StandardCharsets.UTF_8));
|
||||
} catch (NoClassDefFoundError e) {
|
||||
legacy = true;
|
||||
}
|
||||
}
|
||||
|
||||
// support for Java versions < 8
|
||||
return DatatypeConverter.parseBase64Binary(input);
|
||||
}
|
||||
|
||||
}
|
@ -420,7 +420,7 @@ public final class JsonParser {
|
||||
return character() == 'n' && read() == 'u' && read() == 'l' && read() == 'l';
|
||||
}
|
||||
|
||||
public class JsonParseException extends IOException {
|
||||
public static class JsonParseException extends IOException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
@ -50,7 +50,7 @@ import org.prismlauncher.utils.logging.Log;
|
||||
* A utility class for URLs which uses reflection to access hidden methods.
|
||||
* Unfortunately not supported on newer Java versions.
|
||||
*/
|
||||
public class UrlUtils {
|
||||
public final class UrlUtils {
|
||||
|
||||
private static URLStreamHandler http;
|
||||
private static MethodHandle openConnection;
|
||||
|
Loading…
Reference in New Issue
Block a user