use of com.amaze.filemanager.filesystem.HybridFileParcelable in project AmazeFileManager by TeamAmaze.
the class LoadFilesListTask method listApks.
private ArrayList<LayoutElementParcelable> listApks() {
ArrayList<LayoutElementParcelable> songs = new ArrayList<>();
final String[] projection = { MediaStore.Files.FileColumns.DATA };
Cursor cursor = c.getContentResolver().query(MediaStore.Files.getContentUri("external"), projection, null, null, null);
if (cursor.getCount() > 0 && cursor.moveToFirst()) {
do {
String path = cursor.getString(cursor.getColumnIndex(MediaStore.Files.FileColumns.DATA));
if (path != null && path.endsWith(".apk")) {
HybridFileParcelable strings = RootHelper.generateBaseFile(new File(path), showHiddenFiles);
if (strings != null) {
LayoutElementParcelable parcelable = createListParcelables(strings);
if (parcelable != null)
songs.add(parcelable);
}
}
} while (cursor.moveToNext());
}
cursor.close();
return songs;
}
use of com.amaze.filemanager.filesystem.HybridFileParcelable in project AmazeFileManager by TeamAmaze.
the class MoveFiles method onPostExecute.
@Override
public void onPostExecute(Boolean movedCorrectly) {
if (movedCorrectly) {
if (mainFrag != null && mainFrag.getCurrentPath().equals(paths.get(0))) {
// mainFrag.updateList();
Intent intent = new Intent(MainActivity.KEY_INTENT_LOAD_LIST);
intent.putExtra(MainActivity.KEY_INTENT_LOAD_LIST_FILE, paths.get(0));
context.sendBroadcast(intent);
}
for (int i = 0; i < paths.size(); i++) {
for (HybridFileParcelable f : files.get(i)) {
FileUtils.scanFile(f.getPath(), context);
FileUtils.scanFile(paths.get(i) + "/" + f.getName(), context);
}
}
// updating encrypted db entry if any encrypted file was moved
AppConfig.runInBackground(() -> {
for (int i = 0; i < paths.size(); i++) {
for (HybridFileParcelable file : files.get(i)) {
if (file.getName().endsWith(CryptUtil.CRYPT_EXTENSION)) {
try {
CryptHandler cryptHandler = new CryptHandler(context);
EncryptedEntry oldEntry = cryptHandler.findEntry(file.getPath());
EncryptedEntry newEntry = new EncryptedEntry();
newEntry.setId(oldEntry.getId());
newEntry.setPassword(oldEntry.getPassword());
newEntry.setPath(paths.get(i) + "/" + file.getName());
cryptHandler.updateEntry(oldEntry, newEntry);
} catch (Exception e) {
e.printStackTrace();
// couldn't change the entry, leave it alone
}
}
}
}
});
} else {
for (int i = 0; i < paths.size(); i++) {
Intent intent = new Intent(context, CopyService.class);
intent.putExtra(CopyService.TAG_COPY_SOURCES, files.get(i));
intent.putExtra(CopyService.TAG_COPY_TARGET, paths.get(i));
intent.putExtra(CopyService.TAG_COPY_MOVE, true);
intent.putExtra(CopyService.TAG_COPY_OPEN_MODE, mode.ordinal());
ServiceWatcherUtil.runService(context, intent);
}
}
}
use of com.amaze.filemanager.filesystem.HybridFileParcelable in project AmazeFileManager by TeamAmaze.
the class PrepareCopyTask method checkConflicts.
private ArrayList<HybridFileParcelable> checkConflicts(final ArrayList<HybridFileParcelable> filesToCopy, HybridFile destination) {
final ArrayList<HybridFileParcelable> conflictingFiles = new ArrayList<>();
destination.forEachChildrenFile(context, rootMode, new OnFileFound() {
@Override
public void onFileFound(HybridFileParcelable file) {
for (HybridFileParcelable j : filesToCopy) {
if (file.getName().equals((j).getName())) {
conflictingFiles.add(j);
}
}
}
});
return conflictingFiles;
}
use of com.amaze.filemanager.filesystem.HybridFileParcelable in project AmazeFileManager by TeamAmaze.
the class ReadFileTask method doInBackground.
@Override
protected ReturnedValues doInBackground(Void... params) {
StringBuilder stringBuilder = new StringBuilder();
try {
InputStream inputStream = null;
switch(fileAbstraction.scheme) {
case EditableFileAbstraction.SCHEME_CONTENT:
if (fileAbstraction.uri == null)
throw new NullPointerException("Something went really wrong!");
inputStream = contentResolver.openInputStream(fileAbstraction.uri);
break;
case EditableFileAbstraction.SCHEME_FILE:
final HybridFileParcelable hybridFileParcelable = fileAbstraction.hybridFileParcelable;
if (hybridFileParcelable == null)
throw new NullPointerException("Something went really wrong!");
File file = hybridFileParcelable.getFile();
if (!file.canWrite() && isRootExplorer) {
// try loading stream associated using root
try {
cachedFile = new File(externalCacheDir, hybridFileParcelable.getName());
// creating a cache file
RootUtils.copy(hybridFileParcelable.getPath(), cachedFile.getPath());
inputStream = new FileInputStream(cachedFile);
} catch (ShellNotRunningException e) {
e.printStackTrace();
inputStream = null;
} catch (FileNotFoundException e) {
e.printStackTrace();
inputStream = null;
}
} else if (file.canRead()) {
// readable file in filesystem
try {
inputStream = new FileInputStream(hybridFileParcelable.getPath());
} catch (FileNotFoundException e) {
inputStream = null;
}
}
break;
default:
throw new IllegalArgumentException("The scheme for '" + fileAbstraction.scheme + "' cannot be processed!");
}
if (inputStream == null)
throw new StreamNotFoundException();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
String buffer;
while ((buffer = bufferedReader.readLine()) != null) {
stringBuilder.append(buffer).append("\n");
}
inputStream.close();
bufferedReader.close();
} catch (StreamNotFoundException e) {
e.printStackTrace();
return new ReturnedValues(EXCEPTION_STREAM_NOT_FOUND);
} catch (IOException e) {
e.printStackTrace();
return new ReturnedValues(EXCEPTION_IO);
}
return new ReturnedValues(stringBuilder.toString(), cachedFile);
}
use of com.amaze.filemanager.filesystem.HybridFileParcelable in project AmazeFileManager by TeamAmaze.
the class CopyService method checkFiles.
// check if copy is successful
// avoid using the method as there is no way to know when we would be returning from command callbacks
// rather confirm from the command result itself, inside it's callback
boolean checkFiles(HybridFile hFile1, HybridFile hFile2) throws ShellNotRunningException {
if (RootHelper.isDirectory(hFile1.getPath(), isRootExplorer, 5)) {
if (RootHelper.fileExists(hFile2.getPath()))
return false;
ArrayList<HybridFileParcelable> baseFiles = RootHelper.getFilesList(hFile1.getPath(), true, true, null);
if (baseFiles.size() > 0) {
boolean b = true;
for (HybridFileParcelable baseFile : baseFiles) {
if (!checkFiles(new HybridFile(baseFile.getMode(), baseFile.getPath()), new HybridFile(hFile2.getMode(), hFile2.getPath() + "/" + (baseFile.getName()))))
b = false;
}
return b;
}
return RootHelper.fileExists(hFile2.getPath());
} else {
ArrayList<HybridFileParcelable> baseFiles = RootHelper.getFilesList(hFile1.getParent(), true, true, null);
int i = -1;
int index = -1;
for (HybridFileParcelable b : baseFiles) {
i++;
if (b.getPath().equals(hFile1.getPath())) {
index = i;
break;
}
}
ArrayList<HybridFileParcelable> baseFiles1 = RootHelper.getFilesList(hFile1.getParent(), true, true, null);
int i1 = -1;
int index1 = -1;
for (HybridFileParcelable b : baseFiles1) {
i1++;
if (b.getPath().equals(hFile1.getPath())) {
index1 = i1;
break;
}
}
return baseFiles.get(index).getSize() == baseFiles1.get(index1).getSize();
}
}
Aggregations