Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the ability to unpack .pack files #3121

Merged
merged 1 commit into from
Apr 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ private boolean installRuntimeAutomatically(AssetManager am, boolean otherRuntim
if(rt_version == null) return false;
if(!rt_version.equals(current_rt_version)) { //If we already have an integrated one installed, check if it's up-to-date
try {
MultiRTUtils.installRuntimeNamedBinpack(am.open("components/jre/universal.tar.xz"), am.open("components/jre/bin-" + archAsString(Tools.DEVICE_ARCHITECTURE) + ".tar.xz"), "Internal", rt_version,
MultiRTUtils.installRuntimeNamedBinpack(getApplicationInfo().nativeLibraryDir, am.open("components/jre/universal.tar.xz"), am.open("components/jre/bin-" + archAsString(Tools.DEVICE_ARCHITECTURE) + ".tar.xz"), "Internal", rt_version,
(resid, vararg) -> runOnUiThread(()->{if(startupTextView!=null)startupTextView.setText(getString(resid,vararg));}));
MultiRTUtils.postPrepare(PojavLoginActivity.this,"Internal");
return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package net.kdt.pojavlaunch.multirt;

import static org.apache.commons.io.FileUtils.listFiles;

import android.content.Context;
import android.system.Os;
import android.util.Log;
Expand All @@ -21,6 +23,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;

Expand Down Expand Up @@ -103,7 +106,7 @@ public static void postPrepare(Context ctx, String name) throws IOException {
copyDummyNativeLib(ctx,"libawt_xawt.so", dest, libFolder);
}

public static Runtime installRuntimeNamedBinpack(InputStream universalFileInputStream, InputStream platformBinsInputStream, String name, String binpackVersion, RuntimeProgressReporter thingy) throws IOException {
public static Runtime installRuntimeNamedBinpack(String nativeLibDir, InputStream universalFileInputStream, InputStream platformBinsInputStream, String name, String binpackVersion, RuntimeProgressReporter thingy) throws IOException {
File dest = new File(RUNTIME_FOLDER,"/"+name);
if(dest.exists()) FileUtils.deleteDirectory(dest);
dest.mkdirs();
Expand All @@ -113,10 +116,14 @@ public static Runtime installRuntimeNamedBinpack(InputStream universalFileInputS
FileOutputStream fos = new FileOutputStream(binpack_verfile);
fos.write(binpackVersion.getBytes());
fos.close();

unpack200(nativeLibDir,RUNTIME_FOLDER + "/" + name);

sCache.remove(name); // Force reread
return read(name);
}


public static String __internal__readBinpackVersion(String name) {
File binpack_verfile = new File(RUNTIME_FOLDER,"/"+name+"/pojav_version");
try {
Expand Down Expand Up @@ -188,6 +195,28 @@ public static Runtime read(String name) {
return returnRuntime;
}

/**
* Unpacks all .pack files into .jar
* @param nativeLibraryDir The native lib path, required to execute the unpack200 binary
* @param runtimePath The path to the runtime to walk into
*/
private static void unpack200(String nativeLibraryDir, String runtimePath) {
File basePath = new File(runtimePath);
Collection<File> files = listFiles(basePath, new String[]{"pack"}, true);

File workdir = new File(nativeLibraryDir);

ProcessBuilder processBuilder = new ProcessBuilder().directory(workdir);
for(File jarFile : files){
try{
Process process = processBuilder.command("./unpack200.so", "-r", jarFile.getAbsolutePath(), jarFile.getAbsolutePath().replace(".pack", "")).start();
process.waitFor();
}catch (InterruptedException | IOException e) {
Log.e("MULTIRT", "Failed to unpack the runtime !");
}
}
}

private static void copyDummyNativeLib(Context ctx, String name, File dest, String libFolder) throws IOException {
File fileLib = new File(dest, "/"+libFolder + "/" + name);
fileLib.delete();
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.