forked from GeyserMC/Geyser
Another android fix (#1575)
* Fix en_us hash reading on Android (again) * Fix hash generation methods for Android
This commit is contained in:
parent
9ed3197191
commit
881e7a051c
2 changed files with 25 additions and 9 deletions
|
@ -34,10 +34,7 @@ import org.reflections.Reflections;
|
||||||
import org.reflections.serializers.XmlSerializer;
|
import org.reflections.serializers.XmlSerializer;
|
||||||
import org.reflections.util.ConfigurationBuilder;
|
import org.reflections.util.ConfigurationBuilder;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.*;
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
|
@ -168,7 +165,7 @@ public class FileUtils {
|
||||||
byte[] sha256;
|
byte[] sha256;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
sha256 = MessageDigest.getInstance("SHA-256").digest(Files.readAllBytes(file.toPath()));
|
sha256 = MessageDigest.getInstance("SHA-256").digest(readAllBytes(file));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException("Could not calculate pack hash", e);
|
throw new RuntimeException("Could not calculate pack hash", e);
|
||||||
}
|
}
|
||||||
|
@ -186,7 +183,7 @@ public class FileUtils {
|
||||||
byte[] sha1;
|
byte[] sha1;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
sha1 = MessageDigest.getInstance("SHA-1").digest(Files.readAllBytes(file.toPath()));
|
sha1 = MessageDigest.getInstance("SHA-1").digest(readAllBytes(file));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException("Could not calculate pack hash", e);
|
throw new RuntimeException("Could not calculate pack hash", e);
|
||||||
}
|
}
|
||||||
|
@ -210,4 +207,22 @@ public class FileUtils {
|
||||||
|
|
||||||
return reflections;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -140,9 +140,10 @@ public class LocaleUtils {
|
||||||
|
|
||||||
if (locale.equals("en_us")) {
|
if (locale.equals("en_us")) {
|
||||||
try {
|
try {
|
||||||
Path hashFile = GeyserConnector.getInstance().getBootstrap().getConfigFolder().resolve("locales/en_us.hash");
|
File hashFile = GeyserConnector.getInstance().getBootstrap().getConfigFolder().resolve("locales/en_us.hash").toFile();
|
||||||
if (hashFile.toFile().exists()) {
|
if (hashFile.exists()) {
|
||||||
curHash = String.join("", Files.readAllLines(hashFile));
|
BufferedReader br = new BufferedReader(new FileReader(hashFile));
|
||||||
|
curHash = br.readLine().trim();
|
||||||
}
|
}
|
||||||
} catch (IOException ignored) { }
|
} catch (IOException ignored) { }
|
||||||
targetHash = clientJarInfo.getSha1();
|
targetHash = clientJarInfo.getSha1();
|
||||||
|
|
Loading…
Reference in a new issue