use of com.amaze.filemanager.filesystem.HybridFile 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();
}
}
use of com.amaze.filemanager.filesystem.HybridFile in project AmazeFileManager by TeamAmaze.
the class HiddenAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(HiddenViewHolder holder, int position) {
HybridFile file = items.get(position);
holder.txtTitle.setText(file.getName());
String a = file.getReadablePath(file.getPath());
holder.txtDesc.setText(a);
if (hide) {
holder.image.setVisibility(View.GONE);
}
// TODO: move the listeners to the constructor
holder.image.setOnClickListener(view -> {
if (!file.isSmb() && file.isDirectory()) {
ArrayList<HybridFileParcelable> a1 = new ArrayList<>();
HybridFileParcelable baseFile = new HybridFileParcelable(items.get(position).getPath() + "/.nomedia");
baseFile.setMode(OpenMode.FILE);
a1.add(baseFile);
new DeleteTask(context.getActivity().getContentResolver(), c).execute((a1));
}
dataUtils.removeHiddenFile(items.get(position).getPath());
items.remove(items.get(position));
notifyDataSetChanged();
});
holder.row.setOnClickListener(view -> {
materialDialog.dismiss();
new Thread(() -> {
if (file.isDirectory()) {
context.getActivity().runOnUiThread(() -> {
context.loadlist(file.getPath(), false, OpenMode.UNKNOWN);
});
} else {
if (!file.isSmb()) {
context.getActivity().runOnUiThread(() -> {
FileUtils.openFile(new File(file.getPath()), (MainActivity) context.getActivity(), sharedPrefs);
});
}
}
}).start();
});
}
use of com.amaze.filemanager.filesystem.HybridFile in project AmazeFileManager by TeamAmaze.
the class MainFragment method goBackItemClick.
public void goBackItemClick() {
if (openMode == OpenMode.CUSTOM) {
loadlist(home, false, OpenMode.FILE);
return;
}
HybridFile currentFile = new HybridFile(openMode, CURRENT_PATH);
if (!results) {
if (selection) {
adapter.toggleChecked(false);
} else {
if (openMode == OpenMode.SMB) {
try {
if (!CURRENT_PATH.equals(smbPath)) {
String path = (new SmbFile(CURRENT_PATH).getParent());
loadlist((path), true, OpenMode.SMB);
} else
loadlist(home, false, OpenMode.FILE);
} catch (MalformedURLException e) {
e.printStackTrace();
}
} else if (CURRENT_PATH.equals("/") || CURRENT_PATH.equals(OTGUtil.PREFIX_OTG) || CURRENT_PATH.equals(CloudHandler.CLOUD_PREFIX_BOX + "/") || CURRENT_PATH.equals(CloudHandler.CLOUD_PREFIX_DROPBOX + "/") || CURRENT_PATH.equals(CloudHandler.CLOUD_PREFIX_GOOGLE_DRIVE + "/") || CURRENT_PATH.equals(CloudHandler.CLOUD_PREFIX_ONE_DRIVE + "/")) {
getMainActivity().exit();
} else if (FileUtils.canGoBack(getContext(), currentFile)) {
loadlist(currentFile.getParent(getContext()), true, openMode);
} else
getMainActivity().exit();
}
} else {
loadlist(currentFile.getPath(), true, openMode);
}
}
use of com.amaze.filemanager.filesystem.HybridFile in project AmazeFileManager by TeamAmaze.
the class CryptUtil method decrypt.
/**
* Wrapper around handling decryption for directory tree
* @param context
* @param sourceFile the source file to decrypt
* @param targetDirectory the target directory inside which we're going to decrypt
*/
private void decrypt(final Context context, HybridFileParcelable sourceFile, HybridFile targetDirectory) throws GeneralSecurityException, IOException {
if (sourceFile.isDirectory()) {
final HybridFile hFile = new HybridFile(targetDirectory.getMode(), targetDirectory.getPath(), sourceFile.getName().replace(CRYPT_EXTENSION, ""), sourceFile.isDirectory());
FileUtil.mkdirs(context, hFile);
sourceFile.forEachChildrenFile(context, sourceFile.isRoot(), file -> {
try {
decrypt(context, file, hFile);
} catch (IOException | GeneralSecurityException e) {
// throw unchecked exception, no throws needed
throw new IllegalStateException(e);
}
});
} else {
if (!sourceFile.getPath().endsWith(CRYPT_EXTENSION)) {
failedOps.add(sourceFile);
return;
}
BufferedInputStream inputStream = new BufferedInputStream(sourceFile.getInputStream(context), GenericCopyUtil.DEFAULT_BUFFER_SIZE);
HybridFile targetFile = new HybridFile(targetDirectory.getMode(), targetDirectory.getPath(), sourceFile.getName().replace(CRYPT_EXTENSION, ""), sourceFile.isDirectory());
progressHandler.setFileName(sourceFile.getName());
BufferedOutputStream outputStream = new BufferedOutputStream(targetFile.getOutputStream(context), GenericCopyUtil.DEFAULT_BUFFER_SIZE);
if (progressHandler.getCancelled())
return;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
aesDecrypt(inputStream, outputStream);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
rsaDecrypt(context, inputStream, outputStream);
}
}
}
use of com.amaze.filemanager.filesystem.HybridFile in project AmazeFileManager by TeamAmaze.
the class FileUtils method toHybridFileArrayList.
public static ArrayList<HybridFile> toHybridFileArrayList(LinkedList<String> a) {
ArrayList<HybridFile> b = new ArrayList<>();
for (String s : a) {
HybridFile hFile = new HybridFile(OpenMode.UNKNOWN, s);
hFile.generateMode(null);
b.add(hFile);
}
return b;
}
Aggregations