Search in sources :

Example 16 with HybridFile

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();
    }
}
Also used : HybridFileParcelable(com.amaze.filemanager.filesystem.HybridFileParcelable) HybridFile(com.amaze.filemanager.filesystem.HybridFile)

Example 17 with HybridFile

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();
    });
}
Also used : HybridFileParcelable(com.amaze.filemanager.filesystem.HybridFileParcelable) HybridFile(com.amaze.filemanager.filesystem.HybridFile) ArrayList(java.util.ArrayList) MainActivity(com.amaze.filemanager.activities.MainActivity) HybridFile(com.amaze.filemanager.filesystem.HybridFile) File(java.io.File) DeleteTask(com.amaze.filemanager.asynchronous.asynctasks.DeleteTask)

Example 18 with HybridFile

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);
    }
}
Also used : HybridFile(com.amaze.filemanager.filesystem.HybridFile) MalformedURLException(java.net.MalformedURLException) SmbFile(jcifs.smb.SmbFile)

Example 19 with HybridFile

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);
        }
    }
}
Also used : HybridFile(com.amaze.filemanager.filesystem.HybridFile) BufferedInputStream(java.io.BufferedInputStream) GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException) BufferedOutputStream(java.io.BufferedOutputStream)

Example 20 with HybridFile

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;
}
Also used : HybridFile(com.amaze.filemanager.filesystem.HybridFile) ArrayList(java.util.ArrayList)

Aggregations

HybridFile (com.amaze.filemanager.filesystem.HybridFile)22 File (java.io.File)7 ArrayList (java.util.ArrayList)5 Toast (android.widget.Toast)4 HybridFileParcelable (com.amaze.filemanager.filesystem.HybridFileParcelable)4 MainFragment (com.amaze.filemanager.fragments.MainFragment)4 SmbFile (jcifs.smb.SmbFile)4 Intent (android.content.Intent)3 DeleteTask (com.amaze.filemanager.asynchronous.asynctasks.DeleteTask)3 Uri (android.net.Uri)2 MoveFiles (com.amaze.filemanager.asynchronous.asynctasks.MoveFiles)2 CopyService (com.amaze.filemanager.asynchronous.services.CopyService)2 CryptHandler (com.amaze.filemanager.database.CryptHandler)2 CloudPluginException (com.amaze.filemanager.exceptions.CloudPluginException)2 Operations (com.amaze.filemanager.filesystem.Operations)2 RootHelper (com.amaze.filemanager.filesystem.RootHelper)2 OpenMode (com.amaze.filemanager.utils.OpenMode)2 CloudStorage (com.cloudrail.si.interfaces.CloudStorage)2 MalformedURLException (java.net.MalformedURLException)2 Pattern (java.util.regex.Pattern)2