Search in sources :

Example 6 with CompressedObjectParcelable

use of com.amaze.filemanager.adapters.data.CompressedObjectParcelable in project AmazeFileManager by TeamAmaze.

the class ZipHelperTask method addElements.

@Override
void addElements(ArrayList<CompressedObjectParcelable> elements) {
    try {
        ArrayList<CompressedObjectParcelable> wholelist = new ArrayList<>();
        if (new File(fileLocation.getPath()).canRead()) {
            ZipFile zipfile = new ZipFile(fileLocation.getPath());
            for (Enumeration e = zipfile.entries(); e.hasMoreElements(); ) {
                ZipEntry entry = (ZipEntry) e.nextElement();
                wholelist.add(new CompressedObjectParcelable(entry.getName(), entry.getTime(), entry.getSize(), entry.isDirectory()));
            }
        } else {
            ZipInputStream zipfile1 = new ZipInputStream(context.get().getContentResolver().openInputStream(fileLocation));
            for (ZipEntry entry = zipfile1.getNextEntry(); entry != null; entry = zipfile1.getNextEntry()) {
                wholelist.add(new CompressedObjectParcelable(entry.getName(), entry.getTime(), entry.getSize(), entry.isDirectory()));
            }
        }
        ArrayList<String> strings = new ArrayList<>();
        for (CompressedObjectParcelable entry : wholelist) {
            File file = new File(entry.name);
            if (relativeDirectory == null || relativeDirectory.trim().length() == 0) {
                String y = entry.name;
                if (y.startsWith("/"))
                    y = y.substring(1, y.length());
                if (file.getParent() == null || file.getParent().length() == 0 || file.getParent().equals("/")) {
                    if (!strings.contains(y)) {
                        elements.add(new CompressedObjectParcelable(y, entry.date, entry.size, entry.directory));
                        strings.add(y);
                    }
                } else {
                    String path = y.substring(0, y.indexOf("/") + 1);
                    if (!strings.contains(path)) {
                        CompressedObjectParcelable zipObj = new CompressedObjectParcelable(path, entry.date, entry.size, true);
                        strings.add(path);
                        elements.add(zipObj);
                    }
                }
            } else {
                String y = entry.name;
                if (entry.name.startsWith("/"))
                    y = y.substring(1, y.length());
                if (file.getParent() != null && (file.getParent().equals(relativeDirectory) || file.getParent().equals("/" + relativeDirectory))) {
                    if (!strings.contains(y)) {
                        elements.add(new CompressedObjectParcelable(y, entry.date, entry.size, entry.directory));
                        strings.add(y);
                    }
                } else {
                    if (y.startsWith(relativeDirectory + "/") && y.length() > relativeDirectory.length() + 1) {
                        String path1 = y.substring(relativeDirectory.length() + 1, y.length());
                        int index = relativeDirectory.length() + 1 + path1.indexOf("/");
                        String path = y.substring(0, index + 1);
                        if (!strings.contains(path)) {
                            CompressedObjectParcelable zipObj = new CompressedObjectParcelable(y.substring(0, index + 1), entry.date, entry.size, true);
                            strings.add(path);
                            elements.add(zipObj);
                        }
                    }
                }
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : CompressedObjectParcelable(com.amaze.filemanager.adapters.data.CompressedObjectParcelable) ZipInputStream(java.util.zip.ZipInputStream) Enumeration(java.util.Enumeration) ZipFile(java.util.zip.ZipFile) ZipEntry(java.util.zip.ZipEntry) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Aggregations

CompressedObjectParcelable (com.amaze.filemanager.adapters.data.CompressedObjectParcelable)6 IOException (java.io.IOException)4 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 TarArchiveEntry (org.apache.commons.compress.archivers.tar.TarArchiveEntry)2 TarArchiveInputStream (org.apache.commons.compress.archivers.tar.TarArchiveInputStream)2 GradientDrawable (android.graphics.drawable.GradientDrawable)1 AppBarLayout (android.support.design.widget.AppBarLayout)1 CompressedExplorerAdapter (com.amaze.filemanager.adapters.CompressedExplorerAdapter)1 HybridFileParcelable (com.amaze.filemanager.filesystem.HybridFileParcelable)1 CircleGradientDrawable (com.amaze.filemanager.ui.views.CircleGradientDrawable)1 DividerItemDecoration (com.amaze.filemanager.ui.views.DividerItemDecoration)1 FastScroller (com.amaze.filemanager.ui.views.FastScroller)1 Archive (com.github.junrar.Archive)1 RarException (com.github.junrar.exception.RarException)1 FileHeader (com.github.junrar.rarfile.FileHeader)1 ArrayList (java.util.ArrayList)1 Enumeration (java.util.Enumeration)1 ZipEntry (java.util.zip.ZipEntry)1 ZipFile (java.util.zip.ZipFile)1