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;
}
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);
}
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;
}
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;
}
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));
}
Aggregations