Directly download to magisk.zip for flashing
This commit is contained in:
parent
63c5e00d86
commit
746a1d8d59
@ -31,7 +31,11 @@ sealed class DownloadSubject : Parcelable {
|
||||
) : DownloadSubject() {
|
||||
|
||||
override val url: String get() = magisk.link
|
||||
override val fileName get() = "Magisk-v${magisk.version}(${magisk.versionCode}).zip"
|
||||
override val fileName get() =
|
||||
if (configuration is Configuration.Flash)
|
||||
"magisk.zip"
|
||||
else
|
||||
"Magisk-v${magisk.version}(${magisk.versionCode}).zip"
|
||||
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,7 @@ sealed class Patching(
|
||||
private val console: MutableList<String>,
|
||||
logs: MutableList<String>,
|
||||
private val resultListener: FlashResultListener
|
||||
) : MagiskInstaller(console, logs, file) {
|
||||
) : MagiskInstaller(console, logs) {
|
||||
|
||||
override fun onResult(success: Boolean) {
|
||||
if (success) {
|
||||
|
@ -4,11 +4,13 @@ import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.annotation.MainThread;
|
||||
import androidx.annotation.WorkerThread;
|
||||
|
||||
import com.topjohnwu.magisk.App;
|
||||
import com.topjohnwu.magisk.Const;
|
||||
import com.topjohnwu.magisk.Info;
|
||||
import com.topjohnwu.magisk.utils.Utils;
|
||||
import com.topjohnwu.net.DownloadProgressListener;
|
||||
import com.topjohnwu.net.Networking;
|
||||
import com.topjohnwu.signing.SignBoot;
|
||||
import com.topjohnwu.superuser.Shell;
|
||||
@ -38,55 +40,28 @@ import java.util.List;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
import androidx.annotation.MainThread;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.WorkerThread;
|
||||
|
||||
public abstract class MagiskInstaller {
|
||||
|
||||
protected String srcBoot;
|
||||
protected File destFile;
|
||||
protected File installDir;
|
||||
protected File zipFile = new File(App.self.getCacheDir(), "magisk.zip");
|
||||
|
||||
@Nullable
|
||||
private final Uri preDownloadedFile;
|
||||
private final List<String> console;
|
||||
private final List<String> logs;
|
||||
private boolean isTar = false;
|
||||
|
||||
private class ProgressLog implements DownloadProgressListener {
|
||||
|
||||
private int prev = -1;
|
||||
private int location;
|
||||
|
||||
@Override
|
||||
public void onProgress(long bytesDownloaded, long totalBytes) {
|
||||
if (prev < 0) {
|
||||
location = console.size();
|
||||
console.add("... 0%");
|
||||
}
|
||||
int curr = (int) (100 * bytesDownloaded / totalBytes);
|
||||
if (prev != curr) {
|
||||
prev = curr;
|
||||
console.set(location, "... " + prev + "%");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected MagiskInstaller() {
|
||||
console = NOPList.getInstance();
|
||||
logs = NOPList.getInstance();
|
||||
preDownloadedFile = null;
|
||||
}
|
||||
|
||||
public MagiskInstaller(List<String> out, List<String> err, @NonNull Uri magisk) {
|
||||
public MagiskInstaller(List<String> out, List<String> err) {
|
||||
console = out;
|
||||
logs = err;
|
||||
installDir = new File(App.deContext.getFilesDir().getParent(), "install");
|
||||
Shell.sh("rm -rf " + installDir).exec();
|
||||
installDir.mkdirs();
|
||||
preDownloadedFile = magisk;
|
||||
}
|
||||
|
||||
protected boolean findImage() {
|
||||
@ -128,27 +103,9 @@ public abstract class MagiskInstaller {
|
||||
|
||||
console.add("- Device platform: " + Build.CPU_ABI);
|
||||
|
||||
File zip = new File(App.self.getCacheDir(), "magisk.zip");
|
||||
if (preDownloadedFile != null) {
|
||||
console.add("- Using already downloaded file");
|
||||
|
||||
InstallerHelper.copyFileTo(preDownloadedFile, zip);
|
||||
} else {
|
||||
console.add("- Using legacy download method");
|
||||
|
||||
if (!ShellUtils.checkSum("MD5", zip, Info.remote.getMagisk().getHash())) {
|
||||
console.add("- Downloading zip");
|
||||
Networking.get(Info.remote.getMagisk().getLink())
|
||||
.setDownloadProgressListener(new ProgressLog())
|
||||
.execForFile(zip);
|
||||
} else {
|
||||
console.add("- Existing zip found");
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
ZipInputStream zi = new ZipInputStream(new BufferedInputStream(
|
||||
new FileInputStream(zip), (int) zip.length()));
|
||||
new FileInputStream(zipFile), (int) zipFile.length()));
|
||||
ZipEntry ze;
|
||||
while ((ze = zi.getNextEntry()) != null) {
|
||||
if (ze.isDirectory())
|
||||
|
@ -3,11 +3,14 @@ package com.topjohnwu.magisk.view.dialogs
|
||||
import android.app.Activity
|
||||
import android.app.ProgressDialog
|
||||
import android.widget.Toast
|
||||
import com.topjohnwu.magisk.Info
|
||||
import com.topjohnwu.magisk.R
|
||||
import com.topjohnwu.magisk.tasks.MagiskInstaller
|
||||
import com.topjohnwu.magisk.utils.Utils
|
||||
import com.topjohnwu.magisk.utils.reboot
|
||||
import com.topjohnwu.net.Networking
|
||||
import com.topjohnwu.superuser.Shell
|
||||
import com.topjohnwu.superuser.ShellUtils
|
||||
import com.topjohnwu.superuser.internal.UiThreadHandler
|
||||
import com.topjohnwu.superuser.io.SuFile
|
||||
|
||||
@ -25,6 +28,8 @@ class EnvFixDialog(activity: Activity) : CustomAlertDialog(activity) {
|
||||
override fun operations(): Boolean {
|
||||
installDir = SuFile("/data/adb/magisk")
|
||||
Shell.su("rm -rf /data/adb/magisk/*").exec()
|
||||
if (!ShellUtils.checkSum("MD5", zipFile, Info.remote.magisk.hash))
|
||||
Networking.get(Info.remote.magisk.link).execForFile(zipFile)
|
||||
return extractZip() && Shell.su("fix_env").exec().isSuccess
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user