Search in sources :

Example 6 with RootFile

use of dev.dworks.apps.anexplorer.root.RootFile in project AnExplorer by 1hakr.

the class RootedStorageProvider method getRootFileForDocId.

private RootFile getRootFileForDocId(String docId) throws FileNotFoundException {
    final int splitIndex = docId.indexOf(':', 1);
    final String tag = docId.substring(0, splitIndex);
    final String path = docId.substring(splitIndex + 1);
    RootInfo root;
    synchronized (mRootsLock) {
        root = mRoots.get(tag);
    }
    if (root == null) {
        throw new FileNotFoundException("No root for " + tag);
    }
    RootFile target = root.path;
    if (target == null) {
        return null;
    }
    target = new RootFile(target.getAbsolutePath() + path);
    return target;
}
Also used : FileNotFoundException(java.io.FileNotFoundException) RootFile(dev.dworks.apps.anexplorer.root.RootFile) Point(android.graphics.Point)

Example 7 with RootFile

use of dev.dworks.apps.anexplorer.root.RootFile in project AnExplorer by 1hakr.

the class RootedStorageProvider method openDocument.

@Override
public ParcelFileDescriptor openDocument(String documentId, String mode, CancellationSignal signal) throws FileNotFoundException {
    final RootFile file = getRootFileForDocId(documentId);
    InputStream is = RootCommands.getFile(file.getPath());
    try {
        return ParcelFileDescriptorUtil.pipeFrom(is);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return ParcelFileDescriptor.open(new File(file.getPath()), ParcelFileDescriptor.MODE_READ_ONLY);
}
Also used : InputStream(java.io.InputStream) IOException(java.io.IOException) RootFile(dev.dworks.apps.anexplorer.root.RootFile) RootFile(dev.dworks.apps.anexplorer.root.RootFile) File(java.io.File)

Example 8 with RootFile

use of dev.dworks.apps.anexplorer.root.RootFile in project AnExplorer by 1hakr.

the class RootedStorageProvider method copyDocument.

@Override
public String copyDocument(String sourceDocumentId, String targetParentDocumentId) throws FileNotFoundException {
    final RootFile before = getRootFileForDocId(sourceDocumentId);
    final RootFile after = getRootFileForDocId(targetParentDocumentId);
    if (!RootCommands.moveCopyRoot(before.getPath(), after.getPath())) {
        throw new IllegalStateException("Failed to copy " + before);
    }
    final String afterDocId = getDocIdForRootFile(after);
    notifyDocumentsChanged(afterDocId);
    return afterDocId;
}
Also used : RootFile(dev.dworks.apps.anexplorer.root.RootFile)

Example 9 with RootFile

use of dev.dworks.apps.anexplorer.root.RootFile in project AnExplorer by 1hakr.

the class RootedStorageProvider method queryChildDocuments.

@Override
public Cursor queryChildDocuments(String parentDocumentId, String[] projection, String sortOrder) throws FileNotFoundException {
    final RootFile parent = getRootFileForDocId(parentDocumentId);
    final MatrixCursor result = new DirectoryCursor(resolveDocumentProjection(projection), parentDocumentId, parent);
    try {
        BufferedReader br = RootCommands.listFiles(parent.getPath());
        if (null != br) {
            Scanner scanner = new Scanner(br);
            while (scanner.hasNextLine()) {
                String line = scanner.nextLine();
                try {
                    includeRootFile(result, null, new RootFile(parent, line));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            scanner.close();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return result;
}
Also used : Scanner(java.util.Scanner) BufferedReader(java.io.BufferedReader) RootFile(dev.dworks.apps.anexplorer.root.RootFile) MatrixCursor(dev.dworks.apps.anexplorer.cursor.MatrixCursor) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 10 with RootFile

use of dev.dworks.apps.anexplorer.root.RootFile in project AnExplorer by 1hakr.

the class RootedStorageProvider method createDocument.

@Override
public String createDocument(String docId, String mimeType, String displayName) throws FileNotFoundException {
    final RootFile parent = getRootFileForDocId(docId);
    if (!parent.isDirectory()) {
        throw new IllegalArgumentException("Parent document isn't a directory");
    }
    File file;
    String path = parent.getPath();
    if (Document.MIME_TYPE_DIR.equals(mimeType)) {
        file = new File(parent.getPath(), displayName);
        if (!RootCommands.createRootdir(path, displayName)) {
            throw new IllegalStateException("Failed to mkdir " + file);
        }
    } else {
        displayName = FileUtils.removeExtension(mimeType, displayName);
        file = new File(path, FileUtils.addExtension(mimeType, displayName));
        // If conflicting file, try adding counter suffix
        int n = 0;
        while (file.exists() && n++ < 32) {
            file = new File(path, FileUtils.addExtension(mimeType, displayName + " (" + n + ")"));
        }
        try {
            if (!RootCommands.createRootFile(path, file.getName())) {
                throw new IllegalStateException("Failed to touch " + file);
            }
        } catch (Exception e) {
            throw new IllegalStateException("Failed to touch " + file + ": " + e);
        }
    }
    notifyDocumentsChanged(docId);
    return getDocIdForRootFile(new RootFile(path, displayName));
}
Also used : RootFile(dev.dworks.apps.anexplorer.root.RootFile) RootFile(dev.dworks.apps.anexplorer.root.RootFile) File(java.io.File) Point(android.graphics.Point) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

RootFile (dev.dworks.apps.anexplorer.root.RootFile)11 FileNotFoundException (java.io.FileNotFoundException)5 IOException (java.io.IOException)4 Point (android.graphics.Point)2 MatrixCursor (dev.dworks.apps.anexplorer.cursor.MatrixCursor)2 BufferedReader (java.io.BufferedReader)2 File (java.io.File)2 Scanner (java.util.Scanner)2 InputStream (java.io.InputStream)1