mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-15 15:48:26 -04:00
Refactor: Cleanup read/write implementations
This commit is contained in:
parent
d4f2e5b752
commit
a5b5809372
@ -165,19 +165,6 @@ public final class Tools {
|
||||
|
||||
getCacioJavaArgs(javaArgList, JREUtils.jreReleaseList.get("JAVA_VERSION").startsWith("1.8.0"));
|
||||
|
||||
/*
|
||||
int mcReleaseDate = Integer.parseInt(versionInfo.releaseTime.substring(0, 10).replace("-", ""));
|
||||
// 13w17a: 20130425
|
||||
// 13w18a: 20130502
|
||||
if (mcReleaseDate < 20130502 && versionInfo.minimumLauncherVersion < 9){
|
||||
ctx.appendlnToLog("AWT-enabled version detected! ("+mcReleaseDate+")");
|
||||
getCacioJavaArgs(javaArgList,false);
|
||||
}else{
|
||||
getCacioJavaArgs(javaArgList,false); // true
|
||||
ctx.appendlnToLog("Headless version detected! ("+mcReleaseDate+")");
|
||||
}
|
||||
*/
|
||||
|
||||
if (versionInfo.logging != null) {
|
||||
String configFile = Tools.DIR_DATA + "/security/" + versionInfo.logging.client.file.id.replace("client", "log4j-rce-patch");
|
||||
if (!new File(configFile).exists()) {
|
||||
@ -375,17 +362,6 @@ public final class Tools {
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
minecraftArgs.add("--width");
|
||||
minecraftArgs.add(Integer.toString(CallbackBridge.windowWidth));
|
||||
minecraftArgs.add("--height");
|
||||
minecraftArgs.add(Integer.toString(CallbackBridge.windowHeight));
|
||||
|
||||
minecraftArgs.add("--fullscreenWidth");
|
||||
minecraftArgs.add(Integer.toString(CallbackBridge.windowWidth));
|
||||
minecraftArgs.add("--fullscreenHeight");
|
||||
minecraftArgs.add(Integer.toString(CallbackBridge.windowHeight));
|
||||
*/
|
||||
|
||||
String[] argsFromJson = JSONUtils.insertJSONValueList(
|
||||
splitAndFilterEmpty(
|
||||
@ -455,26 +431,6 @@ public final class Tools {
|
||||
|
||||
String[] classpath = generateLibClasspath(info);
|
||||
|
||||
// Debug: LWJGL 3 override
|
||||
// File lwjgl2Folder = new File(Tools.MAIN_PATH, "lwjgl2");
|
||||
|
||||
/*
|
||||
File lwjgl3Folder = new File(Tools.MAIN_PATH, "lwjgl3");
|
||||
if (lwjgl3Folder.exists()) {
|
||||
for (File file: lwjgl3Folder.listFiles()) {
|
||||
if (file.getName().endsWith(".jar")) {
|
||||
libStr.append(file.getAbsolutePath() + ":");
|
||||
}
|
||||
}
|
||||
} else if (lwjgl2Folder.exists()) {
|
||||
for (File file: lwjgl2Folder.listFiles()) {
|
||||
if (file.getName().endsWith(".jar")) {
|
||||
libStr.append(file.getAbsolutePath() + ":");
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
if (isClientFirst) {
|
||||
libStr.append(getPatchedFile(actualname));
|
||||
}
|
||||
@ -811,87 +767,16 @@ public final class Tools {
|
||||
}
|
||||
}
|
||||
|
||||
public static String convertStream(InputStream inputStream) throws IOException {
|
||||
return convertStream(inputStream, Charset.forName("UTF-8"));
|
||||
}
|
||||
|
||||
public static String convertStream(InputStream inputStream, Charset charset) throws IOException {
|
||||
StringBuilder out = new StringBuilder();
|
||||
int len;
|
||||
byte[] buf = new byte[512];
|
||||
while((len = inputStream.read(buf))!=-1) {
|
||||
out.append(new String(buf, 0, len, charset));
|
||||
}
|
||||
return out.toString();
|
||||
}
|
||||
|
||||
public static File lastFileModified(String dir) {
|
||||
File fl = new File(dir);
|
||||
|
||||
File[] files = fl.listFiles(File::isFile);
|
||||
if(files == null) {
|
||||
return null;
|
||||
// The patch was a bit wrong...
|
||||
// So, this may be null, why? Because this folder may not exist yet
|
||||
// Or it may not have any files...
|
||||
// Doesn't matter. We must check for that in the crash fragment.
|
||||
}
|
||||
long lastMod = Long.MIN_VALUE;
|
||||
File choice = null;
|
||||
for (File file : files) {
|
||||
if (file.lastModified() > lastMod) {
|
||||
choice = file;
|
||||
lastMod = file.lastModified();
|
||||
}
|
||||
}
|
||||
return choice;
|
||||
}
|
||||
|
||||
|
||||
public static String read(InputStream is) throws IOException {
|
||||
StringBuilder out = new StringBuilder();
|
||||
int len;
|
||||
byte[] buf = new byte[512];
|
||||
while((len = is.read(buf))!=-1) {
|
||||
out.append(new String(buf, 0, len));
|
||||
}
|
||||
return out.toString();
|
||||
return IOUtils.toString(new InputStreamReader(is, StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
public static String read(String path) throws IOException {
|
||||
return read(new FileInputStream(path));
|
||||
}
|
||||
|
||||
public static void write(String path, byte[] content) throws IOException
|
||||
{
|
||||
File outPath = new File(path);
|
||||
outPath.getParentFile().mkdirs();
|
||||
outPath.createNewFile();
|
||||
|
||||
BufferedOutputStream fos = new BufferedOutputStream(new FileOutputStream(path));
|
||||
fos.write(content, 0, content.length);
|
||||
fos.close();
|
||||
return IOUtils.toString(new InputStreamReader(new FileInputStream(path), StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
public static void write(String path, String content) throws IOException {
|
||||
write(path, content.getBytes());
|
||||
}
|
||||
|
||||
public static byte[] loadFromAssetToByte(Context ctx, String inFile) {
|
||||
byte[] buffer = null;
|
||||
|
||||
try {
|
||||
InputStream stream = ctx.getAssets().open(inFile);
|
||||
|
||||
int size = stream.available();
|
||||
buffer = new byte[size];
|
||||
stream.read(buffer);
|
||||
stream.close();
|
||||
} catch (IOException e) {
|
||||
// Handle exceptions here
|
||||
e.printStackTrace();
|
||||
}
|
||||
return buffer;
|
||||
IOUtils.write(content, new FileOutputStream(path));
|
||||
}
|
||||
|
||||
public static void downloadFile(String urlInput, String nameOutput) throws IOException {
|
||||
|
Loading…
x
Reference in New Issue
Block a user