mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-05-08 00:36:49 +00:00
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() {
|
) : DownloadSubject() {
|
||||||
|
|
||||||
override val url: String get() = magisk.link
|
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>,
|
private val console: MutableList<String>,
|
||||||
logs: MutableList<String>,
|
logs: MutableList<String>,
|
||||||
private val resultListener: FlashResultListener
|
private val resultListener: FlashResultListener
|
||||||
) : MagiskInstaller(console, logs, file) {
|
) : MagiskInstaller(console, logs) {
|
||||||
|
|
||||||
override fun onResult(success: Boolean) {
|
override fun onResult(success: Boolean) {
|
||||||
if (success) {
|
if (success) {
|
||||||
|
@ -4,11 +4,13 @@ import android.net.Uri;
|
|||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
|
import androidx.annotation.MainThread;
|
||||||
|
import androidx.annotation.WorkerThread;
|
||||||
|
|
||||||
import com.topjohnwu.magisk.App;
|
import com.topjohnwu.magisk.App;
|
||||||
import com.topjohnwu.magisk.Const;
|
import com.topjohnwu.magisk.Const;
|
||||||
import com.topjohnwu.magisk.Info;
|
import com.topjohnwu.magisk.Info;
|
||||||
import com.topjohnwu.magisk.utils.Utils;
|
import com.topjohnwu.magisk.utils.Utils;
|
||||||
import com.topjohnwu.net.DownloadProgressListener;
|
|
||||||
import com.topjohnwu.net.Networking;
|
import com.topjohnwu.net.Networking;
|
||||||
import com.topjohnwu.signing.SignBoot;
|
import com.topjohnwu.signing.SignBoot;
|
||||||
import com.topjohnwu.superuser.Shell;
|
import com.topjohnwu.superuser.Shell;
|
||||||
@ -38,55 +40,28 @@ import java.util.List;
|
|||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
import java.util.zip.ZipInputStream;
|
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 {
|
public abstract class MagiskInstaller {
|
||||||
|
|
||||||
protected String srcBoot;
|
protected String srcBoot;
|
||||||
protected File destFile;
|
protected File destFile;
|
||||||
protected File installDir;
|
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> console;
|
||||||
private final List<String> logs;
|
private final List<String> logs;
|
||||||
private boolean isTar = false;
|
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() {
|
protected MagiskInstaller() {
|
||||||
console = NOPList.getInstance();
|
console = NOPList.getInstance();
|
||||||
logs = 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;
|
console = out;
|
||||||
logs = err;
|
logs = err;
|
||||||
installDir = new File(App.deContext.getFilesDir().getParent(), "install");
|
installDir = new File(App.deContext.getFilesDir().getParent(), "install");
|
||||||
Shell.sh("rm -rf " + installDir).exec();
|
Shell.sh("rm -rf " + installDir).exec();
|
||||||
installDir.mkdirs();
|
installDir.mkdirs();
|
||||||
preDownloadedFile = magisk;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean findImage() {
|
protected boolean findImage() {
|
||||||
@ -128,27 +103,9 @@ public abstract class MagiskInstaller {
|
|||||||
|
|
||||||
console.add("- Device platform: " + Build.CPU_ABI);
|
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 {
|
try {
|
||||||
ZipInputStream zi = new ZipInputStream(new BufferedInputStream(
|
ZipInputStream zi = new ZipInputStream(new BufferedInputStream(
|
||||||
new FileInputStream(zip), (int) zip.length()));
|
new FileInputStream(zipFile), (int) zipFile.length()));
|
||||||
ZipEntry ze;
|
ZipEntry ze;
|
||||||
while ((ze = zi.getNextEntry()) != null) {
|
while ((ze = zi.getNextEntry()) != null) {
|
||||||
if (ze.isDirectory())
|
if (ze.isDirectory())
|
||||||
|
@ -3,11 +3,14 @@ package com.topjohnwu.magisk.view.dialogs
|
|||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.app.ProgressDialog
|
import android.app.ProgressDialog
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
|
import com.topjohnwu.magisk.Info
|
||||||
import com.topjohnwu.magisk.R
|
import com.topjohnwu.magisk.R
|
||||||
import com.topjohnwu.magisk.tasks.MagiskInstaller
|
import com.topjohnwu.magisk.tasks.MagiskInstaller
|
||||||
import com.topjohnwu.magisk.utils.Utils
|
import com.topjohnwu.magisk.utils.Utils
|
||||||
import com.topjohnwu.magisk.utils.reboot
|
import com.topjohnwu.magisk.utils.reboot
|
||||||
|
import com.topjohnwu.net.Networking
|
||||||
import com.topjohnwu.superuser.Shell
|
import com.topjohnwu.superuser.Shell
|
||||||
|
import com.topjohnwu.superuser.ShellUtils
|
||||||
import com.topjohnwu.superuser.internal.UiThreadHandler
|
import com.topjohnwu.superuser.internal.UiThreadHandler
|
||||||
import com.topjohnwu.superuser.io.SuFile
|
import com.topjohnwu.superuser.io.SuFile
|
||||||
|
|
||||||
@ -25,6 +28,8 @@ class EnvFixDialog(activity: Activity) : CustomAlertDialog(activity) {
|
|||||||
override fun operations(): Boolean {
|
override fun operations(): Boolean {
|
||||||
installDir = SuFile("/data/adb/magisk")
|
installDir = SuFile("/data/adb/magisk")
|
||||||
Shell.su("rm -rf /data/adb/magisk/*").exec()
|
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
|
return extractZip() && Shell.su("fix_env").exec().isSuccess
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user