Fix-up previous commit.

pull/140/head
Fox2Code 2 years ago
parent 0026388f65
commit faf3e3caab

@ -83,14 +83,16 @@ public enum NotificationType implements NotificationTypeCst {
try {
boolean needPatch;
try (ZipFile zipFile = new ZipFile(d)) {
needPatch = zipFile.getEntry("module.prop") == null;
needPatch = zipFile.getEntry("module.prop") == null &&
zipFile.getEntry("anykernel.sh") == null;
}
if (needPatch) {
Files.patchModuleSimple(Files.read(d),
new FileOutputStream(d));
}
try (ZipFile zipFile = new ZipFile(d)) {
needPatch = zipFile.getEntry("module.prop") == null;
needPatch = zipFile.getEntry("module.prop") == null &&
zipFile.getEntry("anykernel.sh") == null;
}
if (needPatch) {
if (d.exists() && !d.delete())

@ -122,18 +122,17 @@ public class InstallerActivity extends CompatActivity {
this.getWindow().setFlags( // Note: Doesn't require WAKELOCK permission
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
final File moduleFile = urlMode ? null : new File(target);
this.progressIndicator.setVisibility(View.VISIBLE);
this.installerTerminal.addLine("- Downloading " + name);
if (urlMode) this.installerTerminal.addLine("- Downloading " + name);
new Thread(() -> {
File moduleCache = this.toDelete = urlMode ?
new File(this.moduleCache, "module.zip") : moduleFile;
if (moduleCache.exists() && !moduleCache.delete() &&
new File(this.moduleCache, "module.zip") : new File(target);
if (urlMode && moduleCache.exists() && !moduleCache.delete() &&
!new SuFile(moduleCache.getAbsolutePath()).delete())
Log.e(TAG, "Failed to delete module cache");
String errMessage = "Failed to download module zip";
try {
Log.i(TAG, "Downloading: " + target);
Log.i(TAG, (urlMode ? "Downloading: " : "Loading: ") + target);
byte[] rawModule = urlMode ? Http.doHttpGet(target, (progress, max, done) -> {
if (max <= 0 && this.progressIndicator.isIndeterminate())
return;
@ -142,7 +141,7 @@ public class InstallerActivity extends CompatActivity {
this.progressIndicator.setMax(max);
this.progressIndicator.setProgressCompat(progress, true);
});
}) : Files.readSU(moduleFile);
}) : Files.readSU(moduleCache);
this.runOnUiThread(() -> {
this.progressIndicator.setVisibility(View.GONE);
this.progressIndicator.setIndeterminate(true);

@ -1,6 +1,7 @@
package com.fox2code.mmm.utils;
import android.os.Build;
import android.util.Log;
import androidx.annotation.NonNull;
@ -45,6 +46,11 @@ public class Files {
}
public static byte[] readSU(File file) throws IOException {
if (file.isFile() && file.canRead()) {
try { // Read as app if su not required
return read(file);
} catch (IOException ignored) {}
}
try (InputStream inputStream = SuFileInputStream.open(file)) {
return readAllBytes(inputStream);
}

@ -371,6 +371,7 @@ public class IntentHelper {
}
outputStream = new FileOutputStream(destination);
Files.copy(inputStream, outputStream);
Log.d(TAG, "File saved at " + destination);
success = true;
} catch (Exception e) {
Log.e(TAG, "failed copy of " + uri, e);

Loading…
Cancel
Save