Fix read archive file

This commit is contained in:
NekoInverter committed 2020-04-03 11:41:40 +08:00
1 parent d2e3d125bb
commit 4be5a0d0ed
5 files changed
+27 -10

No files matched your search

@@ -34,7 +34,7 @@ import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.collection.LruCache;
import com.getkeepsafe.relinker.ReLinker;
import com.hippo.a7zip.A7Zip;
import com.hippo.beerbelly.SimpleDiskCache;
import com.hippo.conaco.Conaco;
import com.hippo.content.RecordingApplication;
@@ -275,7 +275,7 @@ public class EhApplication extends RecordingApplication {
EhEngine.initialize();
BitmapUtils.initialize(this);
Image.initialize(this);
ReLinker.loadLibrary(this, "a7zip-extract-lite");
A7Zip.initialize(this);
if (EhDB.needMerge()) {
EhDB.mergeOldDB(this);
@@ -16,12 +16,13 @@
package com.hippo.ehviewer.gallery;
import androidx.annotation.NonNull;
import com.hippo.a7zip.ArchiveException;
import com.hippo.a7zip.InArchive;
import com.hippo.a7zip.InStream;
import com.hippo.a7zip.PropID;
import com.hippo.a7zip.PropType;
import com.hippo.a7zip.SequentialOutStream;
import com.hippo.a7zip.SeekableInputStream;
import com.hippo.unifile.UniRandomAccessFile;
import java.io.Closeable;
@@ -48,7 +49,7 @@ class A7ZipArchive implements Closeable {
}
static A7ZipArchive create(UniRandomAccessFile file) throws ArchiveException {
InStream store = new UniRandomAccessFileInStream(file);
SeekableInputStream store = new UniRandomAccessFileInStream(file);
InArchive archive = InArchive.open(store);
if ((archive.getArchivePropertyType(PropID.ENCRYPTED) == PropType.BOOL && archive.getArchiveBooleanProperty(PropID.ENCRYPTED))
|| (archive.getArchivePropertyType(PropID.SOLID) == PropType.BOOL && archive.getArchiveBooleanProperty(PropID.SOLID))
@@ -102,8 +103,9 @@ class A7ZipArchive implements Closeable {
}
}
private static class UniRandomAccessFileInStream implements InStream {
private static class UniRandomAccessFileInStream extends SeekableInputStream {
private final byte[] scratch = new byte[8];
private UniRandomAccessFile file;
public UniRandomAccessFileInStream(UniRandomAccessFile file) {
@@ -125,6 +127,16 @@ class A7ZipArchive implements Closeable {
return file.length();
}
@Override
public int read() throws IOException {
return (file.read(scratch, 0, 1) != -1) ? scratch[0] & 0xff : -1;
}
@Override
public int read(@NonNull byte[] b) throws IOException {
return file.read(b, 0, b.length);
}
@Override
public int read(byte[] b, int off, int len) throws IOException {
return file.read(b, off, len);
@@ -136,7 +148,7 @@ class A7ZipArchive implements Closeable {
}
}
private static class OutputStreamSequentialOutStream implements SequentialOutStream {
private static class OutputStreamSequentialOutStream extends OutputStream {
private OutputStream stream;
@@ -144,6 +156,11 @@ class A7ZipArchive implements Closeable {
this.stream = stream;
}
@Override
public void write(int b) throws IOException {
stream.write(b);
}
@Override
public void write(byte[] b, int off, int len) throws IOException {
stream.write(b, off, len);
@@ -66,7 +66,7 @@ public class ArchiveGalleryProvider extends GalleryProvider2 {
private String error;
public ArchiveGalleryProvider(Context context, Uri uri) {
file = UniFile.fromUri(context, uri);
file = UniFile.fromMediaUri(context, uri);
}
@Override
@@ -195,6 +195,7 @@ public class GalleryActivity extends EhActivity implements SeekBar.OnSeekBarChan
} else if (Intent.ACTION_VIEW.equals(mAction)) {
if (mUri != null) {
// Only support zip now
grantUriPermission(BuildConfig.APPLICATION_ID, mUri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
mGalleryProvider = new ArchiveGalleryProvider(this, mUri);
}
}