add missing pack200utils
This commit is contained in:
parent
cd716216dc
commit
18c73219fa
|
@ -30,6 +30,8 @@ dependencies {
|
|||
implementation 'com.github.marschall:zipfilesystem-standalone:1.0.1'
|
||||
implementation 'org.nanohttpd:nanohttpd:2.3.1'
|
||||
implementation 'com.github.steveice10:opennbt:1.4'
|
||||
implementation 'org.tukaani:xz:1.8'
|
||||
implementation 'commons-io:commons-io:2.11.0'
|
||||
implementation 'org.apache.commons:commons-lang3:3.12.0'
|
||||
implementation 'org.apache.commons:commons-compress:1.21'
|
||||
implementation 'com.moandjiezana.toml:toml4j:0.7.2'
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
package com.tungsten.fclcore.constant;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
public class FCLPath {
|
||||
|
||||
public static String NATIVE_LIB_DIR;
|
||||
|
||||
public static void loadPaths(Context context) {
|
||||
NATIVE_LIB_DIR = context.getApplicationInfo().nativeLibraryDir;
|
||||
}
|
||||
|
||||
}
|
|
@ -4,6 +4,7 @@ import static com.tungsten.fclcore.util.DigestUtils.digest;
|
|||
import static com.tungsten.fclcore.util.Hex.encodeHex;
|
||||
import static com.tungsten.fclcore.util.Logging.LOG;
|
||||
|
||||
import com.tungsten.fclcore.constant.FCLPath;
|
||||
import com.tungsten.fclcore.download.AbstractDependencyManager;
|
||||
import com.tungsten.fclcore.download.ArtifactMalformedException;
|
||||
import com.tungsten.fclcore.download.DefaultCacheRepository;
|
||||
|
@ -11,10 +12,13 @@ import com.tungsten.fclcore.game.Library;
|
|||
import com.tungsten.fclcore.task.DownloadException;
|
||||
import com.tungsten.fclcore.task.FileDownloadTask;
|
||||
import com.tungsten.fclcore.task.Task;
|
||||
import com.tungsten.fclcore.util.Pack200Utils;
|
||||
import com.tungsten.fclcore.util.io.FileUtils;
|
||||
import com.tungsten.fclcore.util.io.IOUtils;
|
||||
import com.tungsten.fclcore.util.io.NetworkUtils;
|
||||
|
||||
import org.tukaani.xz.XZInputStream;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
@ -27,7 +31,6 @@ import java.util.jar.JarInputStream;
|
|||
import java.util.jar.JarOutputStream;
|
||||
import java.util.logging.Level;
|
||||
|
||||
// Todo : fix
|
||||
public class LibraryDownloadTask extends Task<Void> {
|
||||
private FileDownloadTask task;
|
||||
protected final File jar;
|
||||
|
@ -108,7 +111,7 @@ public class LibraryDownloadTask extends Task<Void> {
|
|||
}
|
||||
}
|
||||
|
||||
if (Pack200Utils.isSupported() && testURLExistence(url)) {
|
||||
if (testURLExistence(url)) {
|
||||
List<URL> urls = dependencyManager.getDownloadProvider().injectURLWithCandidates(url + ".pack.xz");
|
||||
task = new FileDownloadTask(urls, xzFile, null);
|
||||
task.setCacheRepository(cacheRepository);
|
||||
|
@ -243,7 +246,7 @@ public class LibraryDownloadTask extends Task<Void> {
|
|||
}
|
||||
|
||||
try (FileOutputStream jarBytes = new FileOutputStream(dest); JarOutputStream jos = new JarOutputStream(jarBytes)) {
|
||||
Pack200Utils.unpack(temp.toFile(), jos);
|
||||
Pack200Utils.unpack(FCLPath.NATIVE_LIB_DIR, temp.toAbsolutePath().toString(), dest.getAbsolutePath());
|
||||
|
||||
JarEntry checksumsFile = new JarEntry("checksums.sha1");
|
||||
checksumsFile.setTime(0L);
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
package com.tungsten.fclcore.util;
|
||||
|
||||
import static org.apache.commons.io.FileUtils.listFiles;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class Pack200Utils {
|
||||
|
||||
/**
|
||||
* Unpacks all .pack files into .jar
|
||||
* @param nativeLibraryDir The native lib path, required to execute the unpack200 binary
|
||||
* @param dir The path of the directory which contains .pack file
|
||||
*/
|
||||
private static void unpack(String nativeLibraryDir, String dir) {
|
||||
File basePath = new File(dir);
|
||||
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("./libunpack200.so", "-r", jarFile.getAbsolutePath(), jarFile.getAbsolutePath().replace(".pack", "")).start();
|
||||
process.waitFor();
|
||||
} catch (InterruptedException | IOException e) {
|
||||
Logging.LOG.log(Level.WARNING, "Failed to unpack files in " + dir + " Error: " + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unpacks .pack files into .jar
|
||||
* @param in Input file path
|
||||
* @param out Output file path
|
||||
*/
|
||||
public static void unpack(String nativeLibraryDir, String in, String out) {
|
||||
try {
|
||||
File workdir = new File(nativeLibraryDir);
|
||||
ProcessBuilder processBuilder = new ProcessBuilder().directory(workdir);
|
||||
Process process = processBuilder.command("./libunpack200.so", "-r", in, out).start();
|
||||
process.waitFor();
|
||||
} catch (InterruptedException | IOException e) {
|
||||
Logging.LOG.log(Level.WARNING, "Failed to unpack file: " + in + " Error: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue