3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-27 00:23:03 +01:00

Another android fix (#1575)

* Fix en_us hash reading on Android (again)

* Fix hash generation methods for Android
Dieser Commit ist enthalten in:
rtm516 2020-11-22 10:40:53 +00:00 committet von GitHub
Ursprung 9ed3197191
Commit 881e7a051c
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
2 geänderte Dateien mit 25 neuen und 9 gelöschten Zeilen

Datei anzeigen

@ -34,10 +34,7 @@ import org.reflections.Reflections;
import org.reflections.serializers.XmlSerializer;
import org.reflections.util.ConfigurationBuilder;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.*;
import java.net.URL;
import java.nio.file.Files;
import java.security.MessageDigest;
@ -168,7 +165,7 @@ public class FileUtils {
byte[] sha256;
try {
sha256 = MessageDigest.getInstance("SHA-256").digest(Files.readAllBytes(file.toPath()));
sha256 = MessageDigest.getInstance("SHA-256").digest(readAllBytes(file));
} catch (Exception e) {
throw new RuntimeException("Could not calculate pack hash", e);
}
@ -186,7 +183,7 @@ public class FileUtils {
byte[] sha1;
try {
sha1 = MessageDigest.getInstance("SHA-1").digest(Files.readAllBytes(file.toPath()));
sha1 = MessageDigest.getInstance("SHA-1").digest(readAllBytes(file));
} catch (Exception e) {
throw new RuntimeException("Could not calculate pack hash", e);
}
@ -210,4 +207,22 @@ public class FileUtils {
return reflections;
}
/**
* An android compatible version of {@link Files#readAllBytes}
*
* @param file File to read bytes of
* @return The byte array of the file
*/
public static byte[] readAllBytes(File file) {
int size = (int) file.length();
byte[] bytes = new byte[size];
try {
BufferedInputStream buf = new BufferedInputStream(new FileInputStream(file));
buf.read(bytes, 0, bytes.length);
buf.close();
} catch (IOException ignored) { }
return bytes;
}
}

Datei anzeigen

@ -140,9 +140,10 @@ public class LocaleUtils {
if (locale.equals("en_us")) {
try {
Path hashFile = GeyserConnector.getInstance().getBootstrap().getConfigFolder().resolve("locales/en_us.hash");
if (hashFile.toFile().exists()) {
curHash = String.join("", Files.readAllLines(hashFile));
File hashFile = GeyserConnector.getInstance().getBootstrap().getConfigFolder().resolve("locales/en_us.hash").toFile();
if (hashFile.exists()) {
BufferedReader br = new BufferedReader(new FileReader(hashFile));
curHash = br.readLine().trim();
}
} catch (IOException ignored) { }
targetHash = clientJarInfo.getSha1();