mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-11-16 01:33:10 +00:00
Process zip with Java
This commit is contained in:
@@ -60,7 +60,6 @@ public class Async {
|
||||
protected Void doInBackground(Void... voids) {
|
||||
String toolPath = mInfo.dataDir + "/tools";
|
||||
String busybox = mInfo.dataDir + "/lib/libbusybox.so";
|
||||
String zip = mInfo.dataDir + "/lib/libzip.so";
|
||||
if (!Utils.itemExist(false, toolPath)) {
|
||||
Shell.sh(
|
||||
"mkdir " + toolPath,
|
||||
@@ -70,8 +69,7 @@ public class Async {
|
||||
"for tool in $(./busybox --list); do",
|
||||
"ln -s " + busybox + " $tool",
|
||||
"done",
|
||||
"rm -f su sh",
|
||||
"ln -s " + zip + " zip"
|
||||
"rm -f su sh"
|
||||
);
|
||||
}
|
||||
return null;
|
||||
|
||||
40
app/src/main/java/com/topjohnwu/magisk/utils/ZipUtils.java
Normal file
40
app/src/main/java/com/topjohnwu/magisk/utils/ZipUtils.java
Normal file
@@ -0,0 +1,40 @@
|
||||
package com.topjohnwu.magisk.utils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
public class ZipUtils {
|
||||
|
||||
public static void removeTopFolder(InputStream in, OutputStream out) {
|
||||
try {
|
||||
ZipInputStream source = new ZipInputStream(in);
|
||||
ZipOutputStream dest = new ZipOutputStream(out);
|
||||
ZipEntry entry;
|
||||
String path;
|
||||
int size;
|
||||
byte buffer[] = new byte[2048];
|
||||
while ((entry = source.getNextEntry()) != null) {
|
||||
// Remove the top directory from the path
|
||||
path = entry.toString().substring(entry.toString().indexOf("/") + 1);
|
||||
// If it's the top folder, ignore it
|
||||
if (path.isEmpty())
|
||||
continue;
|
||||
// Don't include placeholder
|
||||
if (path.contains("system/placeholder"))
|
||||
continue;
|
||||
dest.putNextEntry(new ZipEntry(path));
|
||||
while((size = source.read(buffer, 0, 2048)) != -1)
|
||||
dest.write(buffer, 0, size);
|
||||
}
|
||||
source.close();
|
||||
dest.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
Logger.dev("ZipUtils: removeTopFolder IO error!");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user