Not all devices work well with streaming
This commit is contained in:
parent
13dad848bd
commit
334beebfeb
@ -49,28 +49,28 @@ public class ProcessRepoZip extends ParallelTask<Void, Object, Boolean> {
|
|||||||
mHandler = new Handler();
|
mHandler = new Handler();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeTopFolder(InputStream in, File output) throws IOException {
|
private void removeTopFolder(File input, File output) throws IOException {
|
||||||
JarInputStream source = new JarInputStream(in);
|
|
||||||
JarOutputStream dest = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(output)));
|
|
||||||
JarEntry entry;
|
JarEntry entry;
|
||||||
String path;
|
try (
|
||||||
while ((entry = source.getNextJarEntry()) != null) {
|
JarInputStream in = new JarInputStream(new BufferedInputStream(new FileInputStream(input)));
|
||||||
// Remove the top directory from the path
|
JarOutputStream out = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(output)))
|
||||||
path = entry.getName().substring(entry.getName().indexOf("/") + 1);
|
) {
|
||||||
// If it's the top folder, ignore it
|
String path;
|
||||||
if (path.isEmpty()) {
|
while ((entry = in.getNextJarEntry()) != null) {
|
||||||
continue;
|
// Remove the top directory from the path
|
||||||
|
path = entry.getName().substring(entry.getName().indexOf("/") + 1);
|
||||||
|
// If it's the top folder, ignore it
|
||||||
|
if (path.isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// Don't include placeholder
|
||||||
|
if (path.equals("system/placeholder")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
out.putNextEntry(new JarEntry(path));
|
||||||
|
Utils.inToOut(in, out);
|
||||||
}
|
}
|
||||||
// Don't include placeholder
|
|
||||||
if (path.equals("system/placeholder")) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
dest.putNextEntry(new JarEntry(path));
|
|
||||||
Utils.inToOut(source, dest);
|
|
||||||
}
|
}
|
||||||
source.close();
|
|
||||||
dest.close();
|
|
||||||
in.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -97,41 +97,37 @@ public class ProcessRepoZip extends ParallelTask<Void, Object, Boolean> {
|
|||||||
break;
|
break;
|
||||||
} while (true);
|
} while (true);
|
||||||
|
|
||||||
InputStream in = new BufferedInputStream(new ProgressInputStream(conn.getInputStream()));
|
|
||||||
|
|
||||||
// Temp files
|
// Temp files
|
||||||
File temp1 = new File(activity.getCacheDir(), "1.zip");
|
File temp1 = new File(activity.getCacheDir(), "1.zip");
|
||||||
File temp2 = new File(temp1.getParentFile(), "2.zip");
|
File temp2 = new File(temp1.getParentFile(), "2.zip");
|
||||||
temp1.getParentFile().mkdir();
|
temp1.getParentFile().mkdir();
|
||||||
|
|
||||||
// First remove top folder in Github source zip, Web -> temp1
|
// First download the zip, Web -> temp1
|
||||||
removeTopFolder(in, temp1);
|
try (
|
||||||
|
InputStream in = new BufferedInputStream(new ProgressInputStream(conn.getInputStream()));
|
||||||
|
OutputStream out = new BufferedOutputStream(new FileOutputStream(temp1))
|
||||||
|
) {
|
||||||
|
Utils.inToOut(in, out);
|
||||||
|
in.close();
|
||||||
|
}
|
||||||
conn.disconnect();
|
conn.disconnect();
|
||||||
|
|
||||||
mHandler.post(() -> {
|
mHandler.post(() -> {
|
||||||
progressDialog.setTitle(R.string.zip_process_title);
|
progressDialog.setTitle(R.string.zip_process_title);
|
||||||
progressDialog.setMessage(getActivity().getString(R.string.zip_process_msg));
|
progressDialog.setMessage(getActivity().getString(R.string.zip_process_msg));
|
||||||
});
|
});
|
||||||
|
|
||||||
// Then sign the zip for the first time, temp1 -> temp2
|
// First remove top folder in Github source zip, temp1 -> temp2
|
||||||
ZipUtils.signZip(temp1, temp2, false);
|
removeTopFolder(temp1, temp2);
|
||||||
|
|
||||||
// Adjust the zip to prevent unzip issues, temp2 -> temp1
|
// Then sign the zip for the first time, temp2 -> temp1
|
||||||
ZipUtils.zipAdjust(temp2.getPath(), temp1.getPath());
|
ZipUtils.signZip(temp2, temp1, false);
|
||||||
|
|
||||||
// Finally, sign the whole zip file again, temp1 -> temp2
|
// Adjust the zip to prevent unzip issues, temp1 -> temp2
|
||||||
ZipUtils.signZip(temp1, temp2, true);
|
ZipUtils.zipAdjust(temp1.getPath(), temp2.getPath());
|
||||||
|
|
||||||
// Write it to the target zip, temp2 -> file
|
// Finally, sign the whole zip file again, temp2 -> target
|
||||||
try (
|
ZipUtils.signZip(temp2, mFile, true);
|
||||||
OutputStream out = new BufferedOutputStream(new FileOutputStream(mFile));
|
|
||||||
InputStream source = new BufferedInputStream(new FileInputStream(temp2))
|
|
||||||
) {
|
|
||||||
byte[] buffer = new byte[4096];
|
|
||||||
int length;
|
|
||||||
while ((length = source.read(buffer)) > 0)
|
|
||||||
out.write(buffer, 0, length);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete temp files
|
// Delete temp files
|
||||||
temp1.delete();
|
temp1.delete();
|
||||||
@ -149,8 +145,8 @@ public class ProcessRepoZip extends ParallelTask<Void, Object, Boolean> {
|
|||||||
Activity activity = getActivity();
|
Activity activity = getActivity();
|
||||||
if (activity == null) return;
|
if (activity == null) return;
|
||||||
progressDialog.dismiss();
|
progressDialog.dismiss();
|
||||||
Uri uri = Uri.fromFile(mFile);
|
|
||||||
if (result) {
|
if (result) {
|
||||||
|
Uri uri = Uri.fromFile(mFile);
|
||||||
if (Shell.rootAccess() && mInstall) {
|
if (Shell.rootAccess() && mInstall) {
|
||||||
Intent intent = new Intent(activity, FlashActivity.class);
|
Intent intent = new Intent(activity, FlashActivity.class);
|
||||||
intent.setData(uri).putExtra(Const.Key.FLASH_ACTION, Const.Value.FLASH_ZIP);
|
intent.setData(uri).putExtra(Const.Key.FLASH_ACTION, Const.Value.FLASH_ZIP);
|
||||||
|
@ -225,13 +225,15 @@ public class Utils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void inToOut(InputStream in, OutputStream out) throws IOException {
|
public static int inToOut(InputStream in, OutputStream out) throws IOException {
|
||||||
int read;
|
int read, total = 0;
|
||||||
byte buffer[] = new byte[4096];
|
byte buffer[] = new byte[4096];
|
||||||
while ((read = in.read(buffer)) > 0) {
|
while ((read = in.read(buffer)) > 0) {
|
||||||
out.write(buffer, 0, read);
|
out.write(buffer, 0, read);
|
||||||
|
total += read;
|
||||||
}
|
}
|
||||||
out.flush();
|
out.flush();
|
||||||
|
return total;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void patchDTBO() {
|
public static void patchDTBO() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user