diff --git a/README.md b/README.md index 34f57c3c6..99dbea869 100644 --- a/README.md +++ b/README.md @@ -6,9 +6,3 @@ I use Java 8 features, which requires Jack compiler and that's only available 2. ### libbusybox.so Static BusyBox binary by @yashdsaraf Link and source: http://forum.xda-developers.com/showthread.php?t=3348543 - -### libzip.so -Static ndk-built info-zip -NDK makefiles: https://github.com/cloudchou/ndkzip -Info-Zip source: https://sourceforge.net/projects/infozip/ -bzip2 source: http://www.bzip.org/ diff --git a/app/src/main/java/com/topjohnwu/magisk/adapters/ReposAdapter.java b/app/src/main/java/com/topjohnwu/magisk/adapters/ReposAdapter.java index 7709da6bb..a84b20b57 100644 --- a/app/src/main/java/com/topjohnwu/magisk/adapters/ReposAdapter.java +++ b/app/src/main/java/com/topjohnwu/magisk/adapters/ReposAdapter.java @@ -23,11 +23,13 @@ import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.module.Repo; import com.topjohnwu.magisk.receivers.DownloadReceiver; import com.topjohnwu.magisk.utils.Async; -import com.topjohnwu.magisk.utils.Shell; import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.magisk.utils.WebWindow; +import com.topjohnwu.magisk.utils.ZipUtils; -import java.io.File; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; import java.util.List; import butterknife.BindView; @@ -102,30 +104,15 @@ public class ReposAdapter extends RecyclerView.Adapter new DownloadReceiver() { @Override public void task(Uri uri) { - new Async.FlashZIP(context, uri, mFilename) { - /* - * !!! This method is now depreciated, will be replaced with new method !!! - */ - @Override - protected void preProcessing() throws Throwable { - File file = new File(mUri.getPath()); - Shell.sh( - "PATH=" + context.getApplicationInfo().dataDir + "/tools:$PATH", - "cd " + file.getParent(), - "mkdir git", - "unzip -o " + file + " -d git", - "mv git/* install", - "cd install", - "rm -rf system/placeholder", - "chmod 644 $(find . -type f)", - "chmod 755 $(find . -type d)", - "rm -rf ../install.zip ../git", - "zip -r ../install.zip *", - "rm -rf ../install" - ); - mUri = Uri.fromFile(new File(file.getParent() + "/install.zip")); - } - }.exec(); + try { + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + InputStream in = mContext.getContentResolver().openInputStream(uri); + ZipUtils.removeTopFolder(in, buffer); + buffer.writeTo(mContext.getContentResolver().openOutputStream(uri)); + } catch (IOException e) { + return; + } + new Async.FlashZIP(mContext, uri, mFilename).exec(); } }, repo.getZipUrl(), diff --git a/app/src/main/java/com/topjohnwu/magisk/receivers/DownloadReceiver.java b/app/src/main/java/com/topjohnwu/magisk/receivers/DownloadReceiver.java index 1c432c40b..841f91456 100644 --- a/app/src/main/java/com/topjohnwu/magisk/receivers/DownloadReceiver.java +++ b/app/src/main/java/com/topjohnwu/magisk/receivers/DownloadReceiver.java @@ -40,6 +40,7 @@ public abstract class DownloadReceiver extends BroadcastReceiver { } context.unregisterReceiver(this); } + c.close(); } } diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/Async.java b/app/src/main/java/com/topjohnwu/magisk/utils/Async.java index 7ef2da6a5..e6777c47f 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/Async.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/Async.java @@ -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; diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/ZipUtils.java b/app/src/main/java/com/topjohnwu/magisk/utils/ZipUtils.java new file mode 100644 index 000000000..f69f8041a --- /dev/null +++ b/app/src/main/java/com/topjohnwu/magisk/utils/ZipUtils.java @@ -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!"); + } + } +} diff --git a/app/src/main/jniLibs/armeabi/libzip.so b/app/src/main/jniLibs/armeabi/libzip.so deleted file mode 100644 index b6b53eec7..000000000 Binary files a/app/src/main/jniLibs/armeabi/libzip.so and /dev/null differ diff --git a/app/src/main/jniLibs/x86/libzip.so b/app/src/main/jniLibs/x86/libzip.so deleted file mode 100644 index e38ca0e27..000000000 Binary files a/app/src/main/jniLibs/x86/libzip.so and /dev/null differ